-
Notifications
You must be signed in to change notification settings - Fork 904
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
error X3504: literal loop terminated early due to out of bounds array access #4381
Comments
Thanks for filing! This is ultimately an issue on our end, as this is valid wgsl, but the HLSL compiler isn't happy with the output. That being said the loop on line 209 indexes the vector out of bounds, it indexes it at 1, 2, 3, 4 and 4 isn't a in-bounds index into a vec4. If you were to keep those in bounds, it should compile. |
Yes, it compiles now. Sorry for the inconvenience. I didn't catch it because I guess Vulkan just ignores it... (at least now someone searching for it should find this ;) ) |
Could we get a reduced version of the test case here? Here's the loop @cwfitzgerald called out at line 209:
This could be a problem for us. If that's what's going on, then Naga may just have to accept that HLSL will reject shaders that we pass, because it analyzes them more thoroughly. |
@TobTobXX Would you be able to put together a reduced version of the test case, based on the loop at line 209? |
I think a simple example would be an explicit |
We already detect this:
That elicits:
|
But, for example, Naga validates this and I suspect the HLSL compiler will reject it:
|
Yes, as @jimblandy has guessed, this shader does work on Linux, but doesn't on Windows (tested): let foo = vec4<f32>(0.1, 0.2, 0.3, -0.6);
[[stage(vertex)]]
fn vs_main(
[[builtin(vertex_index)]] in_vertex_index: u32,
) -> [[builtin(position)]] vec4<f32> {
let x = f32(1 - i32(in_vertex_index)) * 0.5;
let y = f32(i32(in_vertex_index & 1u) * 2 - 1) * 0.5;
return vec4<f32>(x, y, 0.0, 1.0);
}
[[stage(fragment)]]
fn fs_main() -> [[location(0)]] vec4<f32> {
var sum = 0.0;
// Note the off-by-one error
for (var i = 0; i < 5; i=i+1) {
sum = sum + foo[i];
}
return vec4<f32>(1.0, sum, 1.0, 1.0);
}
|
Unless @kvark has some clever way out for us, I think that leaves us at
|
This only seems to be an issue with FXC. DXC seems to compile it just fine. |
@jimblandy according to the WGSL spec this should work though. Implementing the OOB behavior above would fix the issue. |
The OOB behavior is already implemented, actually. We're just being over-eager about detecting errors at compile time. |
Hi there, I wrote this wgpu application on Linux (Wayland) and it worked just fine. Now that someone wanted to compile it on Windows, it doesn't work:
noisy log output
(note that this is not the stderr output, since Windows shell SUUUCKS to copy-paste from. But stderr doesn't have more infos.)
Here's the important part (I think, line breaks and indentation mine):
This is the shader I used: shader.wgsl (pls don't laugh. I know these aglorithms can be done better, but I had to do it without copy-pasting.)
And this is a link to the project source. It's just standart
cargo run
, in case anyone wants to try: sources.tar.gz.Is there a way to work around this?
The text was updated successfully, but these errors were encountered: