Skip to content

Implement support for WebGPU viewFormats in surface configuration #22961

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 4 commits into from
Nov 20, 2024
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
17 changes: 12 additions & 5 deletions src/library_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,8 @@ var LibraryWebGPU = {
if (viewFormatCount) {
var viewFormatsPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUTextureDescriptor.viewFormats, '*') }}};
// 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]; });
desc['viewFormats'] = Array.from({{{ makeHEAPView('32', 'viewFormatsPtr', 'viewFormatsPtr + viewFormatCount * 4') }}},
format => WebGPU.TextureFormat[format]);
}

var device = WebGPU.mgrDevice.get(deviceId);
Expand Down Expand Up @@ -2766,9 +2766,6 @@ var LibraryWebGPU = {
var context = WebGPU.mgrSurface.get(surfaceId);

#if ASSERTIONS
var viewFormatCount = {{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.viewFormatCount) }}};
var viewFormats = {{{ makeGetValue('config', C_STRUCTS.WGPUSurfaceConfiguration.viewFormats, '*') }}};
assert(viewFormatCount === 0 && viewFormats === 0, "TODO: Support viewFormats.");
assert({{{ gpu.PresentMode.Fifo }}} ===
{{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.presentMode) }}});
#endif
Expand All @@ -2794,6 +2791,16 @@ var LibraryWebGPU = {
"alphaMode": WebGPU.AlphaMode[
{{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.alphaMode) }}}],
};

var viewFormatCount = {{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.viewFormatCount) }}};

if (viewFormatCount) {
var viewFormats = {{{ makeGetValue('config', C_STRUCTS.WGPUSurfaceConfiguration.viewFormats, '*') }}};
// viewFormats pointer to an array of TextureFormat which is an enum of size uint32_t
configuration['viewFormats'] = Array.from({{{ makeHEAPView('32', 'viewFormats', 'viewFormats + viewFormatCount * 4') }}},
format => WebGPU.TextureFormat[format]);
}

context.configure(configuration);
},

Expand Down
Loading