-
Notifications
You must be signed in to change notification settings - Fork 51
Closed
Labels
has resolutionIssue is resolved, just needs to be doneIssue is resolved, just needs to be done
Description
Many of the descriptors in WebGPU have default values, and more importantly default values which are not 0 and so a simple memset
or zero initialization is not appropriate.
An example of what does not work
WGPUTextureDataLayout TextureDataLayout = {0};
TextureDataLayout.bytesPerRow = 512;
In this case rowsPerImage = 0
instead of WGPU_COPY_STRIDE_UNDEFINED
.
Therefore, I propose adding default initialization defines to webgpu.h
. While it is possible for each user to create their own, there are some benefits to implementing this in webgpu.h
:
- Adding fields later with default values to descriptors does not introduce undefined behavior in existing code.
- It is possible to change default values later without breaking existing code (while
WGPU_COPY_STRIDE_UNDEFINED
fixes this, many defaults do not have a define as they are simply 0). - One source of truth
One way to implement this is to add defines for each descriptor:
#define WGPUTextureDataLayout_DEFAULT { NULL, 0, WGPU_COPY_STRIDE_UNDEFINED, WGPU_COPY_STRIDE_UNDEFINED }
This would allow users to write:
WGPUTextureDataLayout TextureDataLayout = WGPUTextureDataLayout_DEFAULT;
TextureDataLayout.bytesPerRow = 512;
TODO list:
- Don't forget to write compile tests for these! Add tests that instantiate macros #240
eliemichel
Metadata
Metadata
Assignees
Labels
has resolutionIssue is resolved, just needs to be doneIssue is resolved, just needs to be done