diff --git a/src/library_webgpu.js b/src/library_webgpu.js index 87fba60acce5e..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); @@ -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') }}}, + format => WebGPU.TextureFormat[format]); + } + context.configure(configuration); },