-
Notifications
You must be signed in to change notification settings - Fork 120
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
Feature request: use get/set to deal with bitfields. #1392
Comments
Looks like the Win32 metadata doesn't capture the bit fields. Will transfer for their comment. |
+1 on this. Looking at the DirectStorage API we have: struct DSTORAGE_REQUEST_OPTIONS {
DSTORAGE_COMPRESSION_FORMAT CompressionFormat : 8;
DSTORAGE_REQUEST_SOURCE_TYPE SourceType : 1;
DSTORAGE_REQUEST_DESTINATION_TYPE DestinationType : 7;
UINT64 Reserved : 48;
}; Which turns into: // Microsoft.Direct3D.DirectStorage.DSTORAGE_REQUEST_OPTIONS
public struct DSTORAGE_REQUEST_OPTIONS
{
public byte _bitfield1;
public ulong _bitfield2;
} (Yes, |
@tannergooding / @sotteson1 / @chenss3 is this a clangsharp problem or a win32metadata infrastructure problem? |
Looks like a win32metadata problem. ClangSharp supports generating get/set properties for bitfields, see for example my TerraFX.Interop.Windows project: https://source.terrafx.dev/#TerraFX.Interop.Windows/DirectX/headers/d3d12/D3D12_RAYTRACING_INSTANCE_DESC.cs,636021ab7f8d0bcd I don't see anything on the ClangSharp site that would be causing this to be filtered out. That being said, it's also worth noting that win32metadata explicitly passes In the above you'll note that there is an |
Below is the output without The helper properties aren't emitted in the winmd. I'm not sure where in the pipeline it's getting dropped but isn't code like this unsupported in the metadata anyway? Can ClangSharp do a better job with handling this rather than just emitting public unsafe partial struct D3D12_RAYTRACING_INSTANCE_DESC
{
[NativeTypeName("FLOAT[3][4]")]
public fixed float Transform[3 * 4];
public uint _bitfield1;
[NativeTypeName("uint : 24")]
public uint InstanceID
{
get
{
return _bitfield1 & 0xFFFFFFu;
}
set
{
_bitfield1 = (_bitfield1 & ~0xFFFFFFu) | (value & 0xFFFFFFu);
}
}
[NativeTypeName("uint : 8")]
public uint InstanceMask
{
get
{
return (_bitfield1 >> 24) & 0xFFu;
}
set
{
_bitfield1 = (_bitfield1 & ~(0xFFu << 24)) | ((value & 0xFFu) << 24);
}
}
public uint _bitfield2;
[NativeTypeName("uint : 24")]
public uint InstanceContributionToHitGroupIndex
{
get
{
return _bitfield2 & 0xFFFFFFu;
}
set
{
_bitfield2 = (_bitfield2 & ~0xFFFFFFu) | (value & 0xFFFFFFu);
}
}
[NativeTypeName("uint : 8")]
public uint Flags
{
get
{
return (_bitfield2 >> 24) & 0xFFu;
}
set
{
_bitfield2 = (_bitfield2 & ~(0xFFu << 24)) | ((value & 0xFFu) << 24);
}
}
[NativeTypeName("D3D12_GPU_VIRTUAL_ADDRESS")]
public ulong AccelerationStructure;
} |
Unsure myself. Does winmd trim or otherwise drop function bodies?
What are you envisioning? ClangSharp could potentially emit some information such as That would allow this to work without win32metadata needing to expose the properties as well. Tooling would need to understand such attributes and generate properties or equivalent themselves. |
I see the C# syntax walker visiting the property now in the debugger, but it's not being emitted in the winmd. I'll play with it a bit more but I suspect it's not supported for the same reason inline functions aren't supported in metadata.
Yes something like that would be ideal. Either we just plumb through your attribute so that projections can implement their own helpers, or we can easily detect that attribute in our tooling and adapt it to our needs without having to try and cross-reference with the helper properties. |
If you could log an issue on dotnet/clangsharp, I'll include this in the features I plan on getting done for the v16.0 release. |
Done. Thanks! |
* Updated to ClangSharp 16.0. * Feature request: use get/set to deal with bitfields. Fixed #1392. * Updated the baseline. * Documented NativeBitfield. * Fixed formatting bug. * Lowercased Name.
Motivation
struct in cpp:
struct in rust:
code in cpp
code in rust
I think it is a bug-prone way.
Could we use get/set to deal with bitfields.
accord with rust's safe philosophy.
Drawbacks
No response
Rationale and alternatives
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: