1

Naga validate this snippet:

    [[group(0), binding(0)]] var output :
    texture_storage_2d<rgba8unorm,write>;
    
    [[stage(compute), workgroup_size(1)]]
    fn main() {
        textureStore(output, vec2<i32>(10,10), vec4<f32>(10.,5.,100.,200.));
    }

Replacing rgba8unorm with rgba8uint makes naga throwing an error.

Entry point main at Compute is invalid:     The value [9] can not be stored
    Generating SPIR-V output requires validation to succeed, and it failed in a previous step

I tried different combinations of scalar with vec4<> in textureStore: i32,u32,f32 but no luck.

Question is: How can I use the builtin function textureStore() with texture_storage_2d<rgba8uint,write> instead of texture_storage_2d<rgba8unorm,write> ?

EDIT: Following Dan answer I tried the following

[[group(0), binding(0)]] var output :
    texture_storage_2d<rgba8uint,write>;
    
    [[stage(compute), workgroup_size(1)]]
    fn main() {
        textureStore(output, vec2<i32>(10,10), vec4<u32>(10u,5u,10u,20u));
    } 

It works!

I tried and failed with textureStore(output, vec2(10,10), vec4(10,5,10,20)); I forgot the u in 10u,5u, etc...

Thanks.

Jokari
  • 43
  • 3
  • By the way, wgpu has just released version 0.12 that has massively better shader error messages. (It does have some breaking changes though, fyi.) – Dan Dec 19 '21 at 22:57
  • Exactly what I was thinking: Error messages are somewhat cryptic. The 0.12 version will be very helpful. Thanks. – Jokari Dec 20 '21 at 08:51

1 Answers1

0

To store in a rgba8uint, you need to use the type vec4<u32>. See here for the corresponding type for each texture storage. If that's not working, you may have a different problem. (Are you passing in 10. etc to the vec4<u32>? It should be 10u. Wgsl is very strict about types.)

Dan
  • 12,409
  • 3
  • 50
  • 87
  • You are absolutely right. Even for integer you have to be explicit in this case: You have to write `10u` and not just `10`... Thanks a lot. – Jokari Dec 17 '21 at 21:23