gpuweb / gpuweb

Where the GPU for the Web work happens!
https://webgpu.io
Other
4.82k stars 318 forks source link

HLSL requires the number of samples for a MS texture as part of the type? #1445

Closed ben-clayton closed 3 years ago

ben-clayton commented 3 years ago

According to https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-type:

Multisampled objects (Texture2DMS and Texture2DMSArray) require the texture size to be explicitly stated and expressed as the number of samples. Object2 [<Type, Samples>] Name;

Later it gives an example:

Texture2DMS <float4, 128> MyMSTex;

However, WGSL does not currently include the number of samples in the texture_multisampled_* types.

It seems that DXC actually treats the number of samples argument as optional, but it's I've not found any documentation to explain what omitting the number of samples means.

The DXIL output for Texture2DMS<float4> and Texture2DMS<float4, 8> is clearly different, so it seems this information is being preserved by DXC.

If the number of samples is required to function properly, we may need to change the spec to include this as part of the type, or we'll have to inject this information into the shader at pipeline creation time.

Microsoft folks - are you able to provide any information on whether this template argument is required, and what the behaviour is if omitted?

dj2 commented 3 years ago

@pow2clk @RafaelCintron

kvark commented 3 years ago

It's definitely not required for correctness. We've been running MSAA-enabled workloads with SPIRV-Cross translation for a while, and SPIR-V doesn't carry the number of samples, so the generated HLSL does neither. The question is more of whether or not there is any (performance) advantage in specifying the sample count in there.

magcius commented 3 years ago

It's required for Shader Model 4.0 (D3D10), but not Shader Model 5.0+ (D3D11+).

ben-clayton commented 3 years ago

Thank you both. It certainly sounds like this is a non-issue then. Closing.