Skip to content

WebGPU WASM64: Fix requiredFeatures, and test viewFormats #21078

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
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions src/library_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* To test this, run the following tests:
* - test/runner.py other.test_webgpu_compiletest
* - EMTEST_BROWSERS="/path/to/chrome --user-data-dir=chromeuserdata --enable-unsafe-webgpu" \
* - EMTEST_BROWSER="/path/to/chrome --user-data-dir=chromeuserdata --enable-unsafe-webgpu" \
* test/runner.py browser.test_webgpu_basic_rendering
* (requires WebGPU to be available - otherwise the test will skip itself and pass)
*/
Expand Down Expand Up @@ -921,7 +921,8 @@ 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(`32`, 'viewFormatsPtr', `viewFormatsPtr + viewFormatCount * 4`) }}},
// viewFormatsPtr pointer to an array of TextureFormat which is an enum of size uint32_t
desc["viewFormats"] = Array.from({{{ makeHEAPView('32', 'viewFormatsPtr', `viewFormatsPtr + viewFormatCount * 4`) }}},
function(format) { return WebGPU.TextureFormat[format]; });
}

Expand Down Expand Up @@ -2516,7 +2517,7 @@ var LibraryWebGPU = {
var requiredFeaturesCount = {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUDeviceDescriptor.requiredFeaturesCount) }}};
if (requiredFeaturesCount) {
var requiredFeaturesPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUDeviceDescriptor.requiredFeatures, '*') }}};
desc["requiredFeatures"] = Array.from({{{ makeHEAPView(`${POINTER_BITS}`, 'requiredFeaturesPtr', `requiredFeaturesPtr + requiredFeaturesCount * ${POINTER_SIZE}`) }}},
desc["requiredFeatures"] = Array.from({{{ makeHEAPView('32', 'requiredFeaturesPtr', `requiredFeaturesPtr + requiredFeaturesCount * ${POINTER_SIZE}`) }}},
(feature) => WebGPU.FeatureName[feature]);
}
var requiredLimitsPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUDeviceDescriptor.requiredLimits, '*') }}};
Expand Down
8 changes: 8 additions & 0 deletions test/webgpu_basic_rendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <webgpu/webgpu_cpp.h>

#undef NDEBUG
#include <array>
#include <cassert>
#include <cstdio>
#include <cstdlib>
Expand Down Expand Up @@ -309,6 +310,13 @@ void doRenderTest() {
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);
}
wgpu::Texture depthTexture;
Expand Down