gpuweb / cts

WebGPU Conformance Test Suite
https://gpuweb.github.io/cts/
BSD 3-Clause "New" or "Revised" License
121 stars 72 forks source link

Some expectations in web_platform,copyToTexture, are unexpected #3767

Closed mwyrzykowski closed 2 weeks ago

mwyrzykowski commented 4 weeks ago

In the following CTS test: https://gpuweb.github.io/cts/standalone/?q=webgpu:web_platform,copyToTexture,ImageBitmap:from_ImageData:alpha=%22none%22;orientation=%22none%22;colorSpaceConversion=%22none%22;srcFlipYInCopy=true;dstFormat=%22rgba8unorm%22;dstPremultiplied=true

, I see a failure running locally on ToT WebKit:

 act. colors == R,G,B,A:  0.600000,0.600000,0.600000,1.00000  0.600000,0.600000,0.600000,1.00000
 exp. colors == R,G,B,A: 0.600000,0.600000,0.600000,0.600000 0.600000,0.600000,0.600000,0.600000

but if dstPremultiplied=true, why is the expected result 0.6 for alpha? After premultiplying the alpha channel by its alpha channel, the result should always be 1.

Or do I misunderstand the behavior here and the alpha channel should be left unmodified? That would seem unexpected.

mwyrzykowski commented 4 weeks ago

cc @shaoboyan , do you know if this is expected?

kainino0x commented 2 weeks ago

Premultiplication only applies to the RGB channels. I assume the test case you mentioned is SemitransparentWhite: { R: 1.0, G: 1.0, B: 1.0, A: 0.6 } That's written as unpremultiplied, equal to CSS color(srgb 1.0 1.0 1.0 / 0.6). When premultiplied it should be represented as [0.6, 0.6, 0.6, 0.6]. If you premultiply all channels you'd get [0.6, 0.6, 0.6, 0.36] though, not [0.6, 0.6, 0.6, 1.0].

The canvas spec has some examples as well as a brief explanation of what R/G/B/A mean in unpremultiplied vs premultiplied colors. https://html.spec.whatwg.org/multipage/canvas.html#premultiplied-alpha-and-the-2d-rendering-context

mwyrzykowski commented 2 weeks ago

Indeed, nothing to see here, closing this one out as expected. Sorry for the noise!

kainino0x commented 2 weeks ago

No worries, happy to provide pointers!