-
-
Notifications
You must be signed in to change notification settings - Fork 444
Description
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
Metadata
Metadata
Assignees
Labels
Type
Projects
Status