-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Fix for gh issue: 21031, use proper size for WGPUTextureFormat #21034
Conversation
Fix for emscripten-core#21031 - Use proper size for WGPUTextureFormat U64 -> U32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@kainino0x would it be hard to add tests for this?
@@ -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}`) }}}, | |||
desc["viewFormats"] = Array.from({{{ makeHEAPView(`32`, 'viewFormatsPtr', `viewFormatsPtr + viewFormatCount * 4`) }}}, |
There was a problem hiding this comment.
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
@@ -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}`) }}}, |
There was a problem hiding this comment.
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
emscripten/src/library_webgpu.js
Line 2501 in 4765f9c
desc["requiredFeatures"] = Array.from({{{ makeHEAPView(`${POINTER_BITS}`, 'requiredFeaturesPtr', `requiredFeaturesPtr + requiredFeaturesCount * ${POINTER_SIZE}`) }}}, |
@@ -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}`) }}}, | |||
desc["viewFormats"] = Array.from({{{ makeHEAPView(`32`, 'viewFormatsPtr', `viewFormatsPtr + viewFormatCount * 4`) }}}, |
There was a problem hiding this comment.
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:
emscripten/test/webgpu_basic_rendering.cpp
Line 308 in 4765f9c
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.
I've addressed the remaining work in #21078 |
Fix for #21031