Skip to content

Commit

Permalink
WebGPU: support Premultiplied canvas output (#22494)
Browse files Browse the repository at this point in the history
(Note the default HTML template page's canvas has a black background, so
the difference is not visible there.)

Fixes #22491
  • Loading branch information
kainino0x authored Sep 3, 2024
1 parent 4036606 commit c82a307
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/library_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ wgpu${type}Release: (id) => WebGPU.mgr${type}.release(id),`;
CompositeAlphaMode: {
Auto: 0,
Opaque: 1,
Premultiplied: 2,
},
CreatePipelineAsyncStatus: {
Success: 0,
Expand Down Expand Up @@ -437,6 +438,11 @@ var LibraryWebGPU = {
'repeat',
'mirror-repeat',
],
AlphaMode: [
undefined, // "Auto" uses the default (which is always opaque according to the spec's IDL)
'opaque',
'premultiplied',
],
BlendFactor: [
undefined,
'zero',
Expand Down Expand Up @@ -2753,10 +2759,6 @@ var LibraryWebGPU = {
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.");
var alphaMode = {{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.alphaMode) }}};
assert(alphaMode === {{{ gpu.CompositeAlphaMode.Auto }}} ||
alphaMode === {{{ gpu.CompositeAlphaMode.Opaque }}},
"TODO: Support WGPUCompositeAlphaMode_Premultiplied.");
assert({{{ gpu.PresentMode.Fifo }}} ===
{{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.presentMode) }}});
#endif
Expand All @@ -2779,7 +2781,8 @@ var LibraryWebGPU = {
"format": WebGPU.TextureFormat[
{{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.format) }}}],
"usage": {{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.usage) }}},
"alphaMode": "opaque",
"alphaMode": WebGPU.AlphaMode[
{{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.alphaMode) }}}],
};
context.configure(configuration);
},
Expand Down

0 comments on commit c82a307

Please sign in to comment.