Skip to content
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

WebGPU wrong size for bool #1593

Closed
EmilSV opened this issue Jul 28, 2023 · 6 comments · Fixed by #1675
Closed

WebGPU wrong size for bool #1593

EmilSV opened this issue Jul 28, 2023 · 6 comments · Fixed by #1675
Labels
Milestone

Comments

@EmilSV
Copy link

EmilSV commented Jul 28, 2023

Summary

silk uses bool32 for booleans in WebGPU i have done some tests and using bool32 leads to wrong field offset for RenderBundleEncoderDescriptor and maybe other struct.

Steps to reproduce

  • API: WebGPU

Her are two program that you can compare to see the problem
C

#include <stdio.h>
#include "webgpu.h"

int main()
{
	printf("sizeof  WGPURenderBundleEncoderDescriptor %i \n", (int)sizeof(WGPURenderBundleEncoderDescriptor));
	printf("nextInChain %i \n", (int)offsetof(WGPURenderBundleEncoderDescriptor, nextInChain));
	printf("label %i \n", (int)offsetof(WGPURenderBundleEncoderDescriptor, label));
	printf("colorFormatsCount %i \n", (int)offsetof(WGPURenderBundleEncoderDescriptor, colorFormatsCount));
	printf("colorFormats %i \n", (int)offsetof(WGPURenderBundleEncoderDescriptor, colorFormats));
	printf("depthStencilFormat %i \n", (int)offsetof(WGPURenderBundleEncoderDescriptor, depthStencilFormat));
	printf("sampleCount %i \n", (int)offsetof(WGPURenderBundleEncoderDescriptor, sampleCount));
	printf("depthReadOnly %i \n", (int)offsetof(WGPURenderBundleEncoderDescriptor, depthReadOnly));
	printf("stencilReadOnly %i \n", (int)offsetof(WGPURenderBundleEncoderDescriptor, stencilReadOnly));
}

result:
sizeof WGPURenderBundleEncoderDescriptor 48
nextInChain 0
label 8
colorFormatsCount 16
colorFormats 24
depthStencilFormat 32
sampleCount 36
depthReadOnly 40
stencilReadOnly 41

C#

using Silk.NET.WebGPU;

unsafe
{
    RenderBundleEncoderDescriptor value = default;
    Console.WriteLine($"RenderBundleEncoderDescriptor sizeOf: {sizeof(RenderBundleEncoderDescriptor)}");
    Console.WriteLine($"NextInChain :{(int)((byte*)&value.NextInChain - (byte*)&value)}");
    Console.WriteLine($"Label :{(int)((byte*)&value.Label - (byte*)&value)}");
    Console.WriteLine($"ColorFormatsCount :{(int)((byte*)&value.ColorFormatsCount - (byte*)&value)}");
    Console.WriteLine($"ColorFormats :{(int)((byte*)&value.ColorFormats - (byte*)&value)}");
    Console.WriteLine($"DepthStencilFormat :{(int)((byte*)&value.DepthStencilFormat - (byte*)&value)}");
    Console.WriteLine($"SampleCount :{(int)((byte*)&value.SampleCount - (byte*)&value)}");
    Console.WriteLine($"DepthReadOnly :{(int)((byte*)&value.DepthReadOnly - (byte*)&value)}");
    Console.WriteLine($"StencilReadOnly :{(int)((byte*)&value.StencilReadOnly - (byte*)&value)}");
}

Console.WriteLine();

unsafe
{
    RenderBundleEncoderDescriptorBool8 value = default;
    Console.WriteLine($"RenderBundleEncoderDescriptorBool8 sizeOf: {sizeof(RenderBundleEncoderDescriptorBool8)}");
    Console.WriteLine($"NextInChain :{(int)((byte*)&value.NextInChain - (byte*)&value)}");
    Console.WriteLine($"Label :{(int)((byte*)&value.Label - (byte*)&value)}");
    Console.WriteLine($"ColorFormatsCount :{(int)((byte*)&value.ColorFormatsCount - (byte*)&value)}");
    Console.WriteLine($"ColorFormats :{(int)((byte*)&value.ColorFormats - (byte*)&value)}");
    Console.WriteLine($"DepthStencilFormat :{(int)((byte*)&value.DepthStencilFormat - (byte*)&value)}");
    Console.WriteLine($"SampleCount :{(int)((byte*)&value.SampleCount - (byte*)&value)}");
    Console.WriteLine($"DepthReadOnly :{(int)((byte*)&value.DepthReadOnly - (byte*)&value)}");
    Console.WriteLine($"StencilReadOnly :{(int)((byte*)&value.StencilReadOnly - (byte*)&value)}");
}

public unsafe struct RenderBundleEncoderDescriptorBool8
{
    public ChainedStruct* NextInChain;
    public byte* Label;
    public uint ColorFormatsCount;
    public TextureFormat* ColorFormats;
    public TextureFormat DepthStencilFormat;
    public uint SampleCount;
    public bool DepthReadOnly;
    public bool StencilReadOnly;
}

result:
RenderBundleEncoderDescriptor sizeOf: 48
NextInChain :0
Label :8
ColorFormatsCount :16
ColorFormats :24
DepthStencilFormat :32
SampleCount :36
DepthReadOnly :40
StencilReadOnly :44

RenderBundleEncoderDescriptorBool8 sizeOf: 48
NextInChain :0
Label :8
ColorFormatsCount :16
ColorFormats :24
DepthStencilFormat :32
SampleCount :36
DepthReadOnly :40
StencilReadOnly :41

@EmilSV EmilSV added the bug Something isn't working label Jul 28, 2023
@Beyley
Copy link
Contributor

Beyley commented Jul 28, 2023

Is this still a problem on the latest master builds? Use the experimental nuget feed to get the latest release

This is likely coming about due to the use of stdbool in webgpu.h

@EmilSV
Copy link
Author

EmilSV commented Jul 31, 2023

I have tried the experimental nuget feed now it did not fix the problem. I don't know how silks binding generation tools works but the "generator.json" file has "$include.dxTypeMap": "build/dx_typemap.json" inside the webgpu typeMaps.

@Beyley
Copy link
Contributor

Beyley commented Aug 3, 2023

looks like movement is happening to remove the stdbool.h dependency, see webgpu-native/webgpu-headers#84
asked for an ETA, pending response
if the upstream fix is going to be soon-ish, then we'll block 2.18 until its pushed

@Beyley
Copy link
Contributor

Beyley commented Aug 8, 2023

merged upstream, we just need to wait for wgpu-native to update now

@Perksey
Copy link
Member

Perksey commented Sep 10, 2023

@Beyley are we go for 2.18 here? upstream has been closed.

@Beyley
Copy link
Contributor

Beyley commented Sep 10, 2023

@Beyley are we go for 2.18 here? upstream has been closed.

wgpu-native has had no movement for updating, so our options for WebGPU right now are:
a) stay on the current 2.17.1 known-broken version of WebGPU (anything that uses bools is marshalled wrong)
b) update wgpu-native ourselves (i tried but im really bad at rust so couldnt get too far)
c) leave our wgpu-native binary packages as known-broken and add Dawn binary packages
d) fix the bool marshalling problem, and stay on old WebGPU until wgpu-native updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants