Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
caxieyou opened this issue Aug 2, 2022 · 5 comments
Closed

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

caxieyou opened this issue Aug 2, 2022 · 5 comments

Comments

@caxieyou
Copy link

caxieyou commented Aug 2, 2022

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!!!!

@mikialex
Copy link

mikialex commented Aug 3, 2022

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.

@cwfitzgerald
Copy link
Member

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

@caxieyou
Copy link
Author

caxieyou commented Aug 3, 2022

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

so this could be somthing which will implement later?

@cwfitzgerald
Copy link
Member

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

@teoxoy
Copy link
Member

teoxoy commented Nov 4, 2022

closing as duplicate of #1829

@teoxoy teoxoy closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants