Skip to content

Commit 29b0eaa

Browse files
authored
WebGPU WASM64: Fix requiredFeatures, and test viewFormats (#21078)
* add comment and fix requiredFeatures too * Add test for viewFormats Confirmed `browser64.test_webgpu_basic_rendering` fails without the fix. ``` EMTEST_BROWSER='/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --enable-experimental-webassembly-features' test/runner.py browser64.test_webgpu_basic_rendering ```
1 parent 900aee0 commit 29b0eaa

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/library_webgpu.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* To test this, run the following tests:
1818
* - test/runner.py other.test_webgpu_compiletest
19-
* - EMTEST_BROWSERS="/path/to/chrome --user-data-dir=chromeuserdata --enable-unsafe-webgpu" \
19+
* - EMTEST_BROWSER="/path/to/chrome --user-data-dir=chromeuserdata --enable-unsafe-webgpu" \
2020
* test/runner.py browser.test_webgpu_basic_rendering
2121
* (requires WebGPU to be available - otherwise the test will skip itself and pass)
2222
*/
@@ -921,7 +921,8 @@ var LibraryWebGPU = {
921921
var viewFormatCount = {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureDescriptor.viewFormatCount) }}};
922922
if (viewFormatCount) {
923923
var viewFormatsPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUTextureDescriptor.viewFormats, '*') }}};
924-
desc["viewFormats"] = Array.from({{{ makeHEAPView(`32`, 'viewFormatsPtr', `viewFormatsPtr + viewFormatCount * 4`) }}},
924+
// viewFormatsPtr pointer to an array of TextureFormat which is an enum of size uint32_t
925+
desc["viewFormats"] = Array.from({{{ makeHEAPView('32', 'viewFormatsPtr', `viewFormatsPtr + viewFormatCount * 4`) }}},
925926
function(format) { return WebGPU.TextureFormat[format]; });
926927
}
927928

@@ -2516,7 +2517,7 @@ var LibraryWebGPU = {
25162517
var requiredFeaturesCount = {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUDeviceDescriptor.requiredFeaturesCount) }}};
25172518
if (requiredFeaturesCount) {
25182519
var requiredFeaturesPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUDeviceDescriptor.requiredFeatures, '*') }}};
2519-
desc["requiredFeatures"] = Array.from({{{ makeHEAPView(`${POINTER_BITS}`, 'requiredFeaturesPtr', `requiredFeaturesPtr + requiredFeaturesCount * ${POINTER_SIZE}`) }}},
2520+
desc["requiredFeatures"] = Array.from({{{ makeHEAPView('32', 'requiredFeaturesPtr', `requiredFeaturesPtr + requiredFeaturesCount * ${POINTER_SIZE}`) }}},
25202521
(feature) => WebGPU.FeatureName[feature]);
25212522
}
25222523
var requiredLimitsPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUDeviceDescriptor.requiredLimits, '*') }}};

test/webgpu_basic_rendering.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <webgpu/webgpu_cpp.h>
99

1010
#undef NDEBUG
11+
#include <array>
1112
#include <cassert>
1213
#include <cstdio>
1314
#include <cstdlib>
@@ -309,6 +310,13 @@ void doRenderTest() {
309310
descriptor.usage = wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc;
310311
descriptor.size = {1, 1, 1};
311312
descriptor.format = wgpu::TextureFormat::BGRA8Unorm;
313+
314+
// Test for viewFormats binding
315+
std::array<wgpu::TextureFormat, 2> viewFormats =
316+
{ wgpu::TextureFormat::BGRA8Unorm, wgpu::TextureFormat::BGRA8Unorm };
317+
descriptor.viewFormatCount = viewFormats.size();
318+
descriptor.viewFormats = viewFormats.data();
319+
312320
readbackTexture = device.CreateTexture(&descriptor);
313321
}
314322
wgpu::Texture depthTexture;

0 commit comments

Comments
 (0)