wgpu icon indicating copy to clipboard operation
wgpu copied to clipboard

Shader validation fail using textureLoad with unexpected type from naga

Open ygdrasil-io opened this issue 1 year ago • 2 comments

Description While loading a shader, i got the error :

wgpu uncaptured error:
Validation Error

Caused by:
    In wgpuDeviceCreateShaderModule
    
Shader validation error: 
    ┌─ :119:26
    │
119 │       let probabilites = textureLoad(texture, coord, level);
    │                          ^^^^^^^^^^^ naga::Expression [63]


    Entry point simulate at Compute is invalid
    Expression [63] is invalid
    Image sample or level-of-detail index's type of [62] is not an integer scalar

The message is not really clear to me but, i think it tell me that level is not a integer. This var is a u32 which is correct according to the specification : https://www.w3.org/TR/WGSL/#textureload

Repro steps call the rust equivalent of wgpuDeviceCreateShaderModule with the following shader : https://raw.githubusercontent.com/wgpu4k/wgpu4k/56fa04c130dac55f96d61edb3376072a0584bb64/examples/common/src/commonMain/kotlin/io.ygdrasil.wgpu.examples/scenes/shader/vertex/ParticlesShader.kt

Expected vs observed behavior Should not throw an error.

Platform Only tested on MacOS AArch64 and Ubuntu AArch64 with latest version of wgpu-native. The error is also on latest Firefox Nightly, but not on Chrome.

ygdrasil-io avatar Mar 25 '24 01:03 ygdrasil-io

I think this should've been fixed by https://github.com/gfx-rs/wgpu/issues/4521, but looks like it didn't fully address the problem.

JMS55 avatar Mar 27 '24 19:03 JMS55

It seems the validator is currently only accepting signed integers for the level parm.

https://github.com/gfx-rs/wgpu/blob/b34219ca214caea2af86dbb64a2a2b613ea5198c/naga/src/valid/expression.rs#L622

teoxoy avatar Mar 28 '24 16:03 teoxoy

It seems this problem is also still occurring when doing textureLoad(texture, position, sample_index) when sample_index is a u32 and sampling a multisampled texture. (Ex: from @builtin(sample_index)). I'm on wgpu/naga version 23.0.0.

(Error message: "Image sample or level-of-detail index's type of [1] is not an integer scalar")

jmeurice avatar Nov 15 '24 15:11 jmeurice

The error changed a bit, but the error is still here on v24 :

Caused by:
  In wgpuDeviceCreateShaderModule
    
Shader validation error: Entry point simulate at Compute is invalid
    ┌─ :119:26
    │
119 │       let probabilites = textureLoad(texture, coord, level);
    │                          ^^^^^^^^^^^ naga::Expression [62]
    │
    = Expression [62] is invalid
    = Image sample or level-of-detail index's type of [61] is not an integer scalar

ygdrasil-io avatar Feb 05 '25 00:02 ygdrasil-io