From e36f873adce6460f2757f25c6665143d17c07523 Mon Sep 17 00:00:00 2001 From: Jan Krassnigg <> Date: Tue, 19 Nov 2024 08:24:15 +0100 Subject: [PATCH 1/4] Implement support for WebGPU viewFormats in surface configuration --- src/library_webgpu.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/library_webgpu.js b/src/library_webgpu.js index 87fba60acce5e..f0bb5d25f1615 100644 --- a/src/library_webgpu.js +++ b/src/library_webgpu.js @@ -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 @@ -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`) }}}, + function(format) { return WebGPU.TextureFormat[format]; }); + } + context.configure(configuration); }, From 66f7bdf7e5f1b6c74750451908af6e8ce6190432 Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Tue, 19 Nov 2024 15:21:05 -0800 Subject: [PATCH 2/4] Apply suggestions from code review --- src/library_webgpu.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/library_webgpu.js b/src/library_webgpu.js index f0bb5d25f1615..4d91c458167d1 100644 --- a/src/library_webgpu.js +++ b/src/library_webgpu.js @@ -2797,8 +2797,8 @@ var LibraryWebGPU = { 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`) }}}, - function(format) { return WebGPU.TextureFormat[format]; }); + configuration['viewFormats'] = Array.from({{{ makeHEAPView('32', 'viewFormats', `viewFormats + viewFormatCount * 4`) }}}, + format => WebGPU.TextureFormat[format]); } context.configure(configuration); From 0292f84ddacb6b67967e9d9ea2f2a4fb3dcba3a8 Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Tue, 19 Nov 2024 15:21:53 -0800 Subject: [PATCH 3/4] Apply suggestions from code review --- src/library_webgpu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library_webgpu.js b/src/library_webgpu.js index 4d91c458167d1..64b2936aaa50c 100644 --- a/src/library_webgpu.js +++ b/src/library_webgpu.js @@ -2797,7 +2797,7 @@ var LibraryWebGPU = { 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`) }}}, + configuration['viewFormats'] = Array.from({{{ makeHEAPView('32', 'viewFormats', 'viewFormats + viewFormatCount * 4') }}}, format => WebGPU.TextureFormat[format]); } From b92a0d0e37c8d5c62bde4f7cb34c09be4424e97f Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Tue, 19 Nov 2024 15:24:57 -0800 Subject: [PATCH 4/4] update the old instance of this code too --- src/library_webgpu.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/library_webgpu.js b/src/library_webgpu.js index 64b2936aaa50c..c98c0f8a009a6 100644 --- a/src/library_webgpu.js +++ b/src/library_webgpu.js @@ -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);