gpuweb / cts

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

Fix texel data test #3675

Closed Jiawei-Shao closed 5 months ago

Jiawei-Shao commented 5 months ago

Issue: #


Requirements for PR author:

Requirements for reviewer sign-off:

When landing this PR, be sure to make any necessary issue status updates.

Jiawei-Shao commented 5 months ago

Hi @Kangz and @jzm-intel ,

This PR is far from being mature enough but I'd like to discuss how to test the data conversion about texel data, and it seems the current way in the CTS is incorrect.

PTAL, thanks!

jzm-intel commented 5 months ago

Currently the WebGPU spec said

If the format has the -srgb suffix, then sRGB conversions from gamma to linear and vice versa are applied during the reading and writing of color values in the shader.

Since the sRGB conversions are heavily non-linear, we should expect the result floats end up within some certain error boundary, like the case we seen for WGSL tests.

Jiawei suggested that current PR follows the accuracy requirement of D3D spec, which might be reasonable. It seems that Vulkan spec only refers to the conversions formula, didn't mention the accuracy; and the Metal spec (7.7.7 Conversion Rules for sRGBA and sBGRA Textures, P285) said the same accuracy requirement

The precision of the above conversion must ensure that the delta between the resulting infinitely precise floating point value when converting result back to an unnormalized sRGB value but without rounding to an 8-bit unsigned integer value (call it r) and the original sRGB 8-bit unsigned integer color value (call it rorig) is <= 0.5

However, this seems like a gap in the WebGPU spec, not specifying the accuracy of such conversions. Maybe working group shall discuss this?

And another concern I have is, currently the WebGPU spec also said that

WebGPU does not provide color management. All values within WebGPU (such as texture elements) are raw numeric values, not color-managed color values.

WebGPU does interface with color-managed outputs (via GPUCanvasConfiguration) and inputs (via copyExternalImageToTexture() and importExternalTexture()). Thus, color conversion must be performed between the WebGPU numeric values and the external color values. Each such interface point locally defines an encoding (color space, transfer function, and alpha premultiplication) in which the WebGPU numeric values are to be interpreted.

Does this description conflict?

Kangz commented 5 months ago

Though I think we should get @kainino0x to take a look as well.

This doesn't conflict with the color space handling of GPUCanvasContext and friends because it is the responsibility of the rest of the Web platform to define these color spaces. rgba8unorm-srgb and bgra8unorm-srgb are part of the "number computations" of WebGPU and should work correctly.

kainino0x commented 5 months ago

This doesn't conflict with the color space handling of GPUCanvasContext and friends because it is the responsibility of the rest of the Web platform to define these color spaces. rgba8unorm-srgb and bgra8unorm-srgb are part of the "number computations" of WebGPU and should work correctly.

Right. For example:

(This is a useful explanation. I will file a bug to put it in the spec. https://github.com/gpuweb/gpuweb/issues/4587)

jzm-intel commented 5 months ago

Thanks @Kangz and @kainino0x for the explanations!