-
Notifications
You must be signed in to change notification settings - Fork 141
dxgi: Override enum (flags) ABI type to UINT when used in structures #1911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@riverar since you pointed this out to me in microsoft/windows-rs#3044 (comment), can you or @mikebattista help me with this? As can be seen in the changelog in this PR, nothing is changing, presumably because the scraper already "has" an Fortunately there seems to be a |
6f9d8b1 to
30f360f
Compare
|
@riverar any suggestion on the above? I'd love to get this finished :) |
30f360f to
ac509d8
Compare
| IDXGIAdapter1::GetDesc1::pDesc=[RetVal] | ||
| IDXGIAdapter2::GetDesc2::pDesc=[RetVal] | ||
| IDXGIAdapter4::GetDesc3::pDesc=[RetVal] | ||
| IDXGIDevice4::OfferResources1::Flags=[AssociatedEnum("DXGI_OFFER_RESOURCE_FLAGS")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do folks think, should we proactively convert other enum types - that aren't used in structs just yet - to uint as well to use them as a direct type instead of via AssociatedEnum?
@kennykerr we've seen it before in microsoft/windows-rs#3111 that AssociatedEnum like this cause impl wrappers to borrow instead of pass by (cheaply copyable) value. Is that something you have on your radar to fix in windows-rs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do folks think, should we proactively convert other
enumtypes - that aren't used in structs just yet - touintas well to use them as a direct type instead of viaAssociatedEnum?
I've just pushed this and regenerated windows-rs at MarijnS95/windows-rs@fbd504a. Notable takeaways:
AssociatedEnumdoesn't seem to work for to[out]pointers, for exampleCheckHardwareCompositionSupport()was still returningu32but now finally returnsDXGI_HARDWARE_COMPOSITION_SUPPORT_FLAGS;- All
flags: &borrows on_Impltraits are gone, and now passed by values; - (less relevant: less internal conversions; raw function signatures now use the underlying flags type more early).
|
I'll have to re-familiarize myself with the context here, but one correction is that |
ac509d8 to
283d9e6
Compare
|
@riverar the contxt here is microsoft/windows-rs#3044 (comment) and our conversation following it. I don't think you ever replied to my final request for clarification though, but this PR is implementing point 2. fwiw. |
|
Right, these are typedef
enum DXGI_ADAPTER_FLAG
{
DXGI_ADAPTER_FLAG_NONE = 0,
DXGI_ADAPTER_FLAG_REMOTE = 1,
DXGI_ADAPTER_FLAG_SOFTWARE = 2,
DXGI_ADAPTER_FLAG_FORCE_DWORD = 0xffffffff
} DXGI_ADAPTER_FLAG; |
|
@riverar but also microsoft/DirectX-Headers#128 (comment). Instead of only discussing ABI here, can we come up with any solution that allows us to have correct |
|
So this PR appears to be trying to do two things:
|
We emit the original types (from the headers) and a helpful attribute to help bridge the mismatch as shown above. I think there's enough information in metadata for projections to handle this. I believe Rust can emit a function that accepts |
|
@riverar for 2. no that is not correct. For the new Rust already emits functions that take As a side-note, while reworking this PR, I found the following assignments which are also mutating ABI: There are probably more. |
Ah, yup, I misread the diff. Will scribble that out in the original post.
Looks like that's a known limitation at this time (see microsoft/windows-rs#2797). Now that newer v61 metadata has been incorporated into windows-rs, feel free to put in an enhancement request for this. It may help your request to point out that this metadata now contains associated enums on out params as such: unsafe HRESULT CheckOverlayColorSpaceSupport(
[In] DXGI_FORMAT Format,
[In] DXGI_COLOR_SPACE_TYPE ColorSpace,
[In] IUnknown pConcernedDevice,
[AssociatedEnum("DXGI_OVERLAY_SUPPORT_FLAG"),Out] uint* pFlags); // <---
I like the idea of keeping settings in their respective partitions. If that’s not working, we can investigate, but it’s not essential. Just choose one that works, and we can refine it later. For now, it’s just confusing chatter.
I have called the police, thanks. Looks like that was missed as part of this effort #1572. We can fix that in a separate PR too. |
I have already done this a long time ago, but it was closed.
Wasn't there a compile-time error for this in the past? |
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.
283d9e6 to
beb35d8
Compare
CC @riverar
Even though my previous contribution in #1757 added
AssociatedEnumannotations 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 beINT, whereas structures and functions usually useUINTinstead of the enum name). There is no place for this inrepr(C)structs (in Rust), requiring us to get more creative to use the originalUINTABI while still replacing the field type with that of the relevant self-descriptive enum type.Also,EDIT: Factored out to #1981.DXGI_OUTDUPL_FLAGis now used as the type forIDXGIOutput5::DupliucateOutput1::Flags. The documentation asDXGI_OUTDUPL_COMPOSITED_UI_CAPTURE_ONLYis a valid value. This is now corrected at microsoft/DirectX-Headers#128.TODO
This is my attempt at solving #1757 (comment) and microsoft/windows-rs#3044 (comment), but as is obvious from the changes since the last release it is not working yet. Unlike other enums that I added to
enums.jsonwith for exampleautoPopulate, none of these configs appear to be working. Any obvious thing that I'm doing wrong?Then:
--with-attribute) to useenums.json(I skipped all those that are only used in function parameters)?UINTas well (e.g. to preempt being used instructs later on)?