Skip to content

Commit ac509d8

Browse files
committed
dxgi: Override enum (flags) ABI type to UINT when used in structures
Even though my previous contribution in #1757 added `AssociatedEnum` annotations to both function parameters and structure fields for some enum types, language bindings like windows-rs can only generate ABI conversions for parameters (and return types) inside functions when there's a mismatch (untyped enums are assumed to be `INT`, whereas structures and functions usually use `UINT` instead of the enum name). There is no place for this in `repr(C)` structs (in Rust), requiring us to get more creative to use the original `UINT` ABI while still replacing the field type with that of the relevant self-descriptive enum type. Instead, move these (also rather disconnected) annotations and references on those enums and their respective fields to `enums.json`, where we can set the `AssociatedEnum` attribute at once in a more coherent way while above all allowing us to override the enum/flags ABI type to match how it's used by the APIs in function parameters and struct fields.
1 parent 17452d6 commit ac509d8

File tree

3 files changed

+61
-21
lines changed

3 files changed

+61
-21
lines changed

generation/WinSDK/Partitions/Dxgi/settings.rsp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ _D3DCOLORVALUE
1313
<IncludeRoot>/um/dxprogrammablecapture.h
1414
--namespace
1515
Windows.Win32.Graphics.Dxgi
16-
--with-attribute
17-
DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAGS=Flags
18-
DXGI_OFFER_RESOURCE_FLAGS=Flags
19-
DXGI_OUTDUPL_FLAG=Flags
20-
DXGI_OVERLAY_COLOR_SPACE_SUPPORT_FLAG=Flags
21-
DXGI_OVERLAY_SUPPORT_FLAG=Flags
22-
DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG=Flags
23-
DXGI_SWAP_CHAIN_FLAG=Flags
16+
--with-type
17+
DXGI_OUTDUPL_FLAG=uint
18+
DXGI_SWAP_CHAIN_FLAG=uint
19+
DXGI_ADAPTER_FLAG=uint

generation/WinSDK/emitter.settings.rsp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ DETACH_VIRTUAL_DISK_FLAG
5151
DRAWPROGRESSFLAGS
5252
DXGI_ADAPTER_FLAG
5353
DXGI_DEBUG_RLO_FLAGS
54+
DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAGS
55+
DXGI_OFFER_RESOURCE_FLAGS
56+
DXGI_OUTDUPL_FLAG
57+
DXGI_OVERLAY_COLOR_SPACE_SUPPORT_FLAG
58+
DXGI_OVERLAY_SUPPORT_FLAG
59+
DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG
60+
DXGI_SWAP_CHAIN_FLAG
5461
EXPAND_VIRTUAL_DISK_FLAG
5562
FILEOPENDIALOGOPTIONS
5663
FORK_VIRTUAL_DISK_FLAG
@@ -1824,29 +1831,30 @@ GetFileVersionInfoSizeA=[CanReturnMultipleSuccessValues]
18241831
GetFileVersionInfoSizeW=[CanReturnMultipleSuccessValues]
18251832
CertCreateCertificateContext=[CanReturnMultipleSuccessValues]
18261833
DeviceIoControl::lpOverlapped=[In][Out][Optional][Retained]
1827-
DXGI_ADAPTER_DESC1::Flags=[AssociatedEnum("DXGI_ADAPTER_FLAG")]
1828-
DXGI_ADAPTER_DESC2::Flags=[AssociatedEnum("DXGI_ADAPTER_FLAG")]
1829-
DXGI_DECODE_SWAP_CHAIN_DESC::Flags=[AssociatedEnum("DXGI_SWAP_CHAIN_FLAG")]
1830-
DXGI_SWAP_CHAIN_DESC::Flags=[AssociatedEnum("DXGI_SWAP_CHAIN_FLAG")]
1831-
DXGI_SWAP_CHAIN_DESC1::Flags=[AssociatedEnum("DXGI_SWAP_CHAIN_FLAG")]
1832-
IDXGIDevice4::OfferResources1::Flags=[AssociatedEnum("DXGI_OFFER_RESOURCE_FLAGS")]
1833-
IDXGIOutput3::CheckOverlaySupport::pFlags=[AssociatedEnum("DXGI_OVERLAY_SUPPORT_FLAG")]
1834-
IDXGIOutput4::CheckOverlayColorSpaceSupport::pFlags=[AssociatedEnum("DXGI_OVERLAY_COLOR_SPACE_SUPPORT_FLAG")]
1835-
IDXGIOutput6::CheckHardwareCompositionSupport::pFlags=[AssociatedEnum("DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAGS")]
1836-
IDXGISwapChain::ResizeBuffers::SwapChainFlags=[AssociatedEnum("DXGI_SWAP_CHAIN_FLAG")]
1837-
IDXGISwapChain3::CheckColorSpaceSupport::pColorSpaceSupport=[AssociatedEnum("DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG")]
1838-
IDXGISwapChain3::ResizeBuffers1::SwapChainFlags=[AssociatedEnum("DXGI_SWAP_CHAIN_FLAG")]
1834+
DXGI_ADAPTER_DESC1::Flags=DXGI_ADAPTER_FLAG
1835+
DXGI_ADAPTER_DESC2::Flags=DXGI_ADAPTER_FLAG
1836+
DXGI_DECODE_SWAP_CHAIN_DESC::Flags=DXGI_SWAP_CHAIN_FLAG
1837+
DXGI_SWAP_CHAIN_DESC::Flags=DXGI_SWAP_CHAIN_FLAG
1838+
DXGI_SWAP_CHAIN_DESC1::Flags=DXGI_SWAP_CHAIN_FLAG
18391839
IDXGIAdapter::GetDesc::pDesc=[RetVal]
18401840
IDXGIAdapter1::GetDesc1::pDesc=[RetVal]
18411841
IDXGIAdapter2::GetDesc2::pDesc=[RetVal]
18421842
IDXGIAdapter4::GetDesc3::pDesc=[RetVal]
1843+
IDXGIDevice4::OfferResources1::Flags=[AssociatedEnum("DXGI_OFFER_RESOURCE_FLAGS")]
18431844
IDXGIOutput::GetDesc::pDesc=[RetVal]
1845+
IDXGIOutput3::CheckOverlaySupport::pFlags=[AssociatedEnum("DXGI_OVERLAY_SUPPORT_FLAG")]
1846+
IDXGIOutput4::CheckOverlayColorSpaceSupport::pFlags=[AssociatedEnum("DXGI_OVERLAY_COLOR_SPACE_SUPPORT_FLAG")]
1847+
IDXGIOutput5::DuplicateOutput1::Flags=DXGI_OUTDUPL_FLAG
1848+
IDXGIOutput6::CheckHardwareCompositionSupport::pFlags=[AssociatedEnum("DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAGS")]
18441849
IDXGIOutput6::GetDesc1::pDesc=[RetVal]
18451850
IDXGIOutputDuplication::GetDesc::pDesc=[RetVal]
18461851
IDXGISurface::GetDesc::pDesc=[RetVal]
18471852
IDXGISwapChain::GetDesc::pDesc=[RetVal]
1853+
IDXGISwapChain::ResizeBuffers::SwapChainFlags=DXGI_SWAP_CHAIN_FLAG
18481854
IDXGISwapChain1::GetDesc1::pDesc=[RetVal]
18491855
IDXGISwapChain1::GetFullscreenDesc::pDesc=[RetVal]
1856+
IDXGISwapChain3::CheckColorSpaceSupport::pColorSpaceSupport=[AssociatedEnum("DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG")]
1857+
IDXGISwapChain3::ResizeBuffers1::SwapChainFlags=DXGI_SWAP_CHAIN_FLAG
18501858
LPWPUCLOSEEVENT::hEvent=WSAEVENT
18511859
LPWPUCREATEEVENT::return=WSAEVENT
18521860
LPWPURESETEVENT::hEvent=WSAEVENT
@@ -1869,4 +1877,4 @@ IPropertyStoreCapabilities::IsPropertyWritable=[CanReturnMultipleSuccessValues]
18691877
MFCreateAttributes::ppMFAttributes=[ComOutPtr]
18701878
StartServiceCtrlDispatcherA::lpServiceStartTable=[NativeArrayInfo]
18711879
StartServiceCtrlDispatcherW::lpServiceStartTable=[NativeArrayInfo]
1872-
PMPRADMINCONNECTIONHANGUPNOTIFICATION3::param3=RAS_CONNECTION_3*
1880+
PMPRADMINCONNECTIONHANGUPNOTIFICATION3::param3=RAS_CONNECTION_3*

scripts/ChangesSinceLastRelease.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,39 @@ Windows.Win32.System.LibraryLoader.Apis.QueryOptionalDelayLoadedAPI added
2929
# Correct PMPRADMINCONNECTIONHANGUPNOTIFICATION3 parameter 4
3030
Windows.Win32.NetworkManagement.Rras.PMPRADMINCONNECTIONHANGUPNOTIFICATION3.Invoke : param3 : [In] => [In,Out]
3131
Windows.Win32.NetworkManagement.Rras.PMPRADMINCONNECTIONHANGUPNOTIFICATION3.Invoke : param3...RAS_CONNECTION_3 => RAS_CONNECTION_3*
32+
# dxgi: Override enum (flags) ABI type to UINT when used in structures
33+
Windows.Win32.Graphics.Dxgi.DXGI_ADAPTER_DESC1.Flags : [AssociatedEnum(DXGI_ADAPTER_FLAG)] =>
34+
Windows.Win32.Graphics.Dxgi.DXGI_ADAPTER_DESC1.Flags...System.UInt32 => Windows.Win32.Graphics.Dxgi.DXGI_ADAPTER_FLAG
35+
Windows.Win32.Graphics.Dxgi.DXGI_ADAPTER_DESC2.Flags : [AssociatedEnum(DXGI_ADAPTER_FLAG)] =>
36+
Windows.Win32.Graphics.Dxgi.DXGI_ADAPTER_DESC2.Flags...System.UInt32 => Windows.Win32.Graphics.Dxgi.DXGI_ADAPTER_FLAG
37+
Windows.Win32.Graphics.Dxgi.DXGI_ADAPTER_FLAG.DXGI_ADAPTER_FLAG_NONE value init changed Int32->UInt32
38+
Windows.Win32.Graphics.Dxgi.DXGI_ADAPTER_FLAG.DXGI_ADAPTER_FLAG_REMOTE value init changed Int32->UInt32
39+
Windows.Win32.Graphics.Dxgi.DXGI_ADAPTER_FLAG.DXGI_ADAPTER_FLAG_SOFTWARE value init changed Int32->UInt32
40+
Windows.Win32.Graphics.Dxgi.DXGI_ADAPTER_FLAG.value__...System.Int32 => System.UInt32
41+
Windows.Win32.Graphics.Dxgi.DXGI_DECODE_SWAP_CHAIN_DESC.Flags : [AssociatedEnum(DXGI_SWAP_CHAIN_FLAG)] =>
42+
Windows.Win32.Graphics.Dxgi.DXGI_DECODE_SWAP_CHAIN_DESC.Flags...System.UInt32 => Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG
43+
Windows.Win32.Graphics.Dxgi.DXGI_OUTDUPL_FLAG.DXGI_OUTDUPL_COMPOSITED_UI_CAPTURE_ONLY value init changed Int32->UInt32
44+
Windows.Win32.Graphics.Dxgi.DXGI_OUTDUPL_FLAG.value__...System.Int32 => System.UInt32
45+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_DESC.Flags : [AssociatedEnum(DXGI_SWAP_CHAIN_FLAG)] =>
46+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_DESC.Flags...System.UInt32 => Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG
47+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_DESC1.Flags : [AssociatedEnum(DXGI_SWAP_CHAIN_FLAG)] =>
48+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_DESC1.Flags...System.UInt32 => Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG
49+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH value init changed Int32->UInt32
50+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING value init changed Int32->UInt32
51+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_DISPLAY_ONLY value init changed Int32->UInt32
52+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_FOREGROUND_LAYER value init changed Int32->UInt32
53+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT value init changed Int32->UInt32
54+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_FULLSCREEN_VIDEO value init changed Int32->UInt32
55+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE value init changed Int32->UInt32
56+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_HW_PROTECTED value init changed Int32->UInt32
57+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_NONPREROTATED value init changed Int32->UInt32
58+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_RESTRICT_SHARED_RESOURCE_DRIVER value init changed Int32->UInt32
59+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_RESTRICTED_CONTENT value init changed Int32->UInt32
60+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_RESTRICTED_TO_ALL_HOLOGRAPHIC_DISPLAYS value init changed Int32->UInt32
61+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_YUV_VIDEO value init changed Int32->UInt32
62+
Windows.Win32.Graphics.Dxgi.DXGI_SWAP_CHAIN_FLAG.value__...System.Int32 => System.UInt32
63+
Windows.Win32.Graphics.Dxgi.IDXGIOutput5.DuplicateOutput1 : Flags...UInt32 => DXGI_OUTDUPL_FLAG
64+
Windows.Win32.Graphics.Dxgi.IDXGISwapChain.ResizeBuffers : SwapChainFlags : [AssociatedEnum(DXGI_SWAP_CHAIN_FLAG),In] => [In]
65+
Windows.Win32.Graphics.Dxgi.IDXGISwapChain.ResizeBuffers : SwapChainFlags...UInt32 => DXGI_SWAP_CHAIN_FLAG
66+
Windows.Win32.Graphics.Dxgi.IDXGISwapChain3.ResizeBuffers1 : SwapChainFlags : [AssociatedEnum(DXGI_SWAP_CHAIN_FLAG),In] => [In]
67+
Windows.Win32.Graphics.Dxgi.IDXGISwapChain3.ResizeBuffers1 : SwapChainFlags...UInt32 => DXGI_SWAP_CHAIN_FLAG

0 commit comments

Comments
 (0)