naga icon indicating copy to clipboard operation
naga copied to clipboard

is "- 1" can be considered as const Expressions?

Open caxieyou opened this issue 1 year ago • 4 comments

so i was testing the textureSample function, https://www.w3.org/TR/WGSL/#texturesample

I notice that the

fn textureSample(t: texture_2d, s: sampler, coords: vec2, offset: vec2) -> vec4 usage,

the last offset: vec2 is consider to be the const expression, according to here https://www.w3.org/TR/WGSL/#const-expr

so if i want to use like textureSample(_, _, _, off) is gonna be wrong (off is a vec2 parameter), make sense.

but if i use like textureSample(_, _, _, vec2(- 1, - 1)) (there is a space between '-' and '1') it's still wrong, I am not sure why the space can cause an issue.

The reason why this "space" is a problem to me is: using Rust, most of the time you need to use macro.

the token stream will automatically separate "-1" to "- 1", same as “()” to “( )”, “!a” to "! a"

so I am wondering if anyone wants to combine the wgls with rust macro, this textureSample's offset will be a problem?

any ideas?

thanks!!!!

caxieyou avatar Aug 02 '22 12:08 caxieyou

The current implementation uses the core::num::i32::from_str_radix to parse an int in the tokenization stage, which doesn't allow any space between the preceding '-' and number literals. I think for const int literals, this limitation is ok. The real question is wgsl seems not to support the const operator (like this minus unary case) as a const expression at all.

mikialex avatar Aug 03 '22 05:08 mikialex

Note this is expected, we haven't implemented any of the const stuff yet

cwfitzgerald avatar Aug 03 '22 06:08 cwfitzgerald

Note this is expected, we haven't implemented any of the const stuff yet

so this could be somthing which will implement later?

caxieyou avatar Aug 03 '22 06:08 caxieyou

Yeah, we'll need to eventually to be conformant.

cwfitzgerald avatar Aug 03 '22 06:08 cwfitzgerald

closing as duplicate of #1829

teoxoy avatar Nov 04 '22 10:11 teoxoy