Skip to content

Fix for gh issue: 21031, use proper size for WGPUTextureFormat #21034

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/library_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ var LibraryWebGPU = {
var viewFormatCount = {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureDescriptor.viewFormatCount) }}};
if (viewFormatCount) {
var viewFormatsPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUTextureDescriptor.viewFormats, '*') }}};
desc["viewFormats"] = Array.from({{{ makeHEAPView(`${POINTER_BITS}`, 'viewFormatsPtr', `viewFormatsPtr + viewFormatCount * ${POINTER_SIZE}`) }}},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find, thank you! Glad to find that these bindings work in wasm64 at all :)

We have the same problem in

desc["requiredFeatures"] = Array.from({{{ makeHEAPView(`${POINTER_BITS}`, 'requiredFeaturesPtr', `requiredFeaturesPtr + requiredFeaturesCount * ${POINTER_SIZE}`) }}},
which takes WGPUFeatureName which is 32-bit.

desc["viewFormats"] = Array.from({{{ makeHEAPView(`32`, 'viewFormatsPtr', `viewFormatsPtr + viewFormatCount * 4`) }}},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a comment along the lines of // viewFormatsPtr pointer to an array of TextureFormat which is an enum of size uint32_t

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: testing, I think we could patch a test into this existing test:

wgpu::TextureDescriptor descriptor{};

         wgpu::TextureDescriptor descriptor{};
         descriptor.usage = wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc;
         descriptor.size = {1, 1, 1};
         descriptor.format = wgpu::TextureFormat::BGRA8Unorm;
+        // Test for viewFormats binding
+        std::array<wgpu::TextureFormat, 2> viewFormats =
+            { wgpu::TextureFormat::BGRA8Unorm, wgpu::TextureFormat::BGRA8Unorm };
+        descriptor.viewFormatCount = viewFormats.size();
+        descriptor.viewFormats = viewFormats.data();
         readbackTexture = device.CreateTexture(&descriptor);

or something like that. The resulting JS call will be:

// before bugfix, throws TypeError:
d.createTexture({ size: [4, 4], usage: GPUTextureUsage.COPY_SRC, format: 'bgra8unorm',
    viewFormats: [undefined, undefined /* or possibly something else due to buffer overrun */] });
// after bugfix, OK:
d.createTexture({ size: [4, 4], usage: GPUTextureUsage.COPY_SRC, format: 'bgra8unorm',
    viewFormats: ['bgra8unorm', 'bgra8unorm'] });

Unfortunately it wouldn't be quite so easy to test the requiredFeatures one.

function(format) { return WebGPU.TextureFormat[format]; });
}

Expand Down