#Custom Vertex shader

11 messages · Page 1 of 1 (latest)

ember apex
#

The error messages of wgsl scripts are very cryptic. I'm struggling to figure out what this thing is upset with.

Here's my attempt to write a function:

fn extract_unsigned(word: u32, width: u32, offset: u32) -> f32 {
    var element = (word >> offset) & (!0 >> (32u - width));
    return f32(element);
}

And here's my error.

2022-11-22T07:06:53.000595Z ERROR naga::valid::expression: Left: Binary { op: ShiftRight, left: [17], right: [19] } of type Scalar { kind: Uint, width: 4 }    
2022-11-22T07:06:53.000610Z ERROR naga::valid::expression: Right: Binary { op: ShiftRight, left: [22], right: [24] } of type Scalar { kind: Sint, width: 4 }    
2022-11-22T07:06:53.000654Z ERROR bevy_render::render_resource::pipeline_cache: failed to process shader: 
error: Function [7] 'extract_unsigned' is invalid
    ┌─ wgsl:214:1
    │  
214 │ ╭ fn extract_unsigned(word: u32, width: u32, offset: u32) -> f32 {
215 │ │     var element = (word >> offset) & (!0 >> (32u - width));
    │ │                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ naga::Expression [26]
216 │ │     return f32(element);
    │ ╰────────────────────────^ naga::Function [7]
    │  
    = Expression [26] is invalid
    = Operation And can't work with [20] and [25]

I seem to have three errors here.
Let's start with the first. Is this thing upset with my bit shift operations? They seem pretty normal to me.

river birch
#

Seems like the heart of the complaint is a type mismatch (unsigned vs signed int), possibly between !0 and (32u - width)

#

The rest seems related

#

big asterisk on "seems" because that error message is utter insanity

daring geyser
#

it might be the !, in wgsl ~ is negation

ember apex
#

Oh, right, that might explain it. Let me try.

#

Got it! Seems it was a combination of errors.

fn extract_unsigned(word: u32, width: u32, offset: u32) -> f32 {
    var element = (word >> offset) & (~0u >> (32u - width));
    return f32(element);
}
#

I remember the 32u was giving me a type mismatch error before so I added the u and it started working.
I'm not sure why it it didn't give me a sensical error message with the inverted one.

#

Thank you so much for the assistance. I knew it would be simple but I don't have the intuition for this shader language yet.
Also... there's a pretty stark lack of documentation.

daring geyser
ember apex
#

Yeah, that's what I've been using.