Skip to content

Associate DXGI function parameters and struct fields with the corresponding enum type - #1757

Merged
Mike Battista (mikebattista) merged 5 commits into
microsoft:mainfrom
MarijnS95:dxgi
May 6, 2024
Merged

Mike Battista (mikebattista) merged 5 commits into
microsoft:mainfrom
MarijnS95:dxgi

Conversation

@MarijnS95

@MarijnS95 Marijn Suijten (MarijnS95) commented Dec 8, 2023 •

Copy link
Copy Markdown
Contributor

These are more convenient and descriptive to use than plain UINTs.

@MarijnS95

Marijn Suijten (MarijnS95) commented Dec 8, 2023 •

Copy link
Copy Markdown
Contributor Author

Before merging this, maybe we should do a bigger pass over this namespace and check some more UINT APIs, though I haven't come across many obvious ones just yet (in an existing codebase).

@MarijnS95 Marijn Suijten (MarijnS95) changed the title Annotate two DXGI getters with the right enum type Annotate DXGI function parameters and struct fields with the right enum type Dec 8, 2023
@MarijnS95

Marijn Suijten (MarijnS95) commented Dec 8, 2023 •

Copy link
Copy Markdown
Contributor Author

This is basically a followup of #1583 where I should have checked for more types (even ones on the same struct of a different version...). Found a few more, in the Dxgi namespace by searching for *flags: u32 and *mut u32 in windows-rs. Only the following "types" are loose constants instead of associated enums, and cannot be used to better type the function signatures.

https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/dxgi-present
https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgisurface-map
https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/dxgi-enum-modes


Curiously in the linked PR we had to annotate these via [AssociatedEnum("…")]. Same here for struct fields and UINTs passed by value, but not for * UINTs passed as pointer... Is that expected?

@riverar

Copy link
Copy Markdown
Collaborator

I think these are the remaining items that need conversion?

IDXGIOutput3::CheckOverlaySupport::pFlags=DXGI_OVERLAY_SUPPORT_FLAG
IDXGIOutput4::CheckOverlayColorSpaceSupport::pFlags=DXGI_OVERLAY_COLOR_SPACE_SUPPORT_FLAG
IDXGIOutput6::CheckHardwareCompositionSupport::pFlags=DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAGS

@MarijnS95

Copy link
Copy Markdown
Contributor Author

Rafael Rivera (@riverar) don't forget about:

IDXGISwapChain3::CheckColorSpaceSupport::pColorSpaceSupport=DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG

Those four are the only pointer params in this PR.

@riverar

Rafael Rivera (riverar) commented Jan 6, 2024 •

Copy link
Copy Markdown
Collaborator

Right, just looking for you to fix up these last four?

-IDXGIOutput3::CheckOverlaySupport::pFlags=DXGI_OVERLAY_SUPPORT_FLAG
+IDXGIOutput3::CheckOverlaySupport::pFlags=[AssociatedEnum(DXGI_OVERLAY_SUPPORT_FLAG)]

-IDXGIOutput4::CheckOverlayColorSpaceSupport::pFlags=DXGI_OVERLAY_COLOR_SPACE_SUPPORT_FLAG
+IDXGIOutput4::CheckOverlayColorSpaceSupport::pFlags=[AssociatedEnum(DXGI_OVERLAY_COLOR_SPACE_SUPPORT_FLAG)

-IDXGIOutput6::CheckHardwareCompositionSupport::pFlags=DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAGS
+IDXGIOutput6::CheckHardwareCompositionSupport::pFlags=[AssociatedEnum(DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAGS)

-IDXGISwapChain3::CheckColorSpaceSupport::pColorSpaceSupport=DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG
+IDXGISwapChain3::CheckColorSpaceSupport::pColorSpaceSupport=[AssociatedEnum(DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG)

Edit: Just saw the last one hiding in there. Added above.

@MarijnS95

Copy link
Copy Markdown
Contributor Author

Rafael Rivera (@riverar) so that means there's a definitive yes on annotating pointer types?

@riverar

Copy link
Copy Markdown
Collaborator

Yup, lets do it 🚀

@MarijnS95 Marijn Suijten (MarijnS95) changed the title Annotate DXGI function parameters and struct fields with the right enum type Associate DXGI function parameters and struct fields with the corresponding enum type Jan 7, 2024
@MarijnS95

Copy link
Copy Markdown
Contributor Author

Rafael Rivera (@riverar) done! Would you please make sure that I've covered every remaining untyped UINT enum in the DXGI bindings?

Perhaps we should seek for the same patterns in D3D12?

@MarijnS95

Copy link
Copy Markdown
Contributor Author

#1757 (comment) if you run into any of these: maybe we can turn the constants into enums?

@MarijnS95

Copy link
Copy Markdown
Contributor Author

Rafael Rivera (@riverar) I'll rebase this when you or Mike Battista (@mikebattista) have reviewed it and are ready to merge it, to prevent constant force-pushes. Looking forward to the heads-up, thanks!

@MarijnS95

Copy link
Copy Markdown
Contributor Author

Looks like it will also be advantageous to mark some of these types, like DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG with [Flags] attribute :)

@MarijnS95

Marijn Suijten (MarijnS95) commented Jan 17, 2024 •

Copy link
Copy Markdown
Contributor Author

Only the following "types" are loose constants instead of associated enums, and cannot be used to better type the function signatures.

https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/dxgi-present
https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgisurface-map
https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/dxgi-enum-modes

Since I ran into enums.json recently, I figured I should just introduce them.

Again, please help me check that I've caught mostly everything!

Documentation annotations are missing though, should those be included as well?

Comment thread generation/WinSDK/enums.json Resolved
Comment thread scripts/ChangesSinceLastRelease.txt Resolved
Comment thread generation/WinSDK/enums.json Resolved
Comment thread generation/WinSDK/enums.json Resolved
Comment thread generation/WinSDK/enums.json Resolved
Comment thread generation/WinSDK/enums.json Resolved
Comment thread generation/WinSDK/enums.json Resolved
Comment thread generation/WinSDK/enums.json Resolved
Comment thread generation/WinSDK/enums.json Resolved
Comment thread generation/WinSDK/enums.json Resolved
Comment thread generation/WinSDK/enums.json Resolved
@MarijnS95

Copy link
Copy Markdown
Contributor Author

Thanks for the review Rafael Rivera (@riverar)! Mike Battista (@mikebattista) let me know when this is ready to be merged, so that I can solve the conflicts with ChangesSinceLastRelease.txt.

@mikebattista
Mike Battista (mikebattista) dismissed stale reviews from Rafael Rivera (riverar) and themself via 372c4b8 May 6, 2024 15:54
@mikebattista
Mike Battista (mikebattista) merged commit 2e09958 into microsoft:main May 6, 2024
@mikebattista

Copy link
Copy Markdown
Contributor

Merged. Thanks!

@MarijnS95 Marijn Suijten (MarijnS95) changed the title Associate DXGI function parameters and struct fields with the corresponding enum type Associate DXGI function parameters and struct fields with the corresponding enum type May 16, 2024
--with-attribute
DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAGS=Flags
DXGI_OFFER_RESOURCE_FLAGS=Flags
DXGI_OUTDUPL_FLAG=Flags

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag has one DXGI_OUTDUPL_COMPOSITED_UI_CAPTURE_ONLY = 1 constant, but I couldn't find in what API it is supposed to be used. Only the constructor for output duplication has as Flags field that "should always be zero":

https://learn.microsoft.com/en-us/windows/win32/api/dxgi1_5/nf-dxgi1_5-idxgioutput5-duplicateoutput1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a question for the DX repo. Suspect this is was meant to stay internal. But a real world example from OS components verifies your claim: pObject->DuplicateOutput1(device, DXGI_OUTDUPL_COMPOSITED_UI_CAPTURE_ONLY, ...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, in that case the documentation should be updated too.

What's the desired way to assign the enum, emitter.settings.rsp or listing it in enums.json?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we prefer enums.json these days!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rafael Rivera (@riverar) that might mean we could move more of the --with-attribute here - with explicit reassignments in emitter.settings.rsp - and consolidate them into enums.json?

Looks like there's also --enumMakeFlags in emitter.settings.rsp doing a similar thing 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But a real world example from OS components verifies your claim: pObject->DuplicateOutput1(device, DXGI_OUTDUPL_COMPOSITED_UI_CAPTURE_ONLY, ...)

Rafael Rivera (@riverar) where'd you find this example?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bcastdvruserservice.dll!Windows::Media::Capture::Internal::DDACapture::AcquireOutputDuplication (26217.5000), reverse engineered 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted the question at microsoft/DirectX-Headers#128, let's see.

Marijn Suijten (MarijnS95) added a commit to MarijnS95/win32metadata that referenced this pull request May 17, 2024
Even though my previous contribution in microsoft#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.
Marijn Suijten (MarijnS95) added a commit to MarijnS95/win32metadata that referenced this pull request Jul 3, 2024
Even though my previous contribution in microsoft#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.
Marijn Suijten (MarijnS95) added a commit to MarijnS95/win32metadata that referenced this pull request Aug 29, 2024
Even though my previous contribution in microsoft#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.
Marijn Suijten (MarijnS95) added a commit to MarijnS95/win32metadata that referenced this pull request Aug 29, 2024
Even though my previous contribution in microsoft#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.
Marijn Suijten (MarijnS95) added a commit to MarijnS95/win32metadata that referenced this pull request Oct 16, 2025
Even though my previous contribution in microsoft#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants