-
Notifications
You must be signed in to change notification settings - Fork 195
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
Forbid local variable shadowing in WGSL #1044
Comments
Checking this locally, I'm seeing:
WGSL doesn't allow shadowing local variables. We just need to detect this. |
This doesn't seem to be the cause of the original error. I've removed all name shadowing that I can find, and I still get a similar error. |
Are you trying this on Naga directly? What do you get now, exactly, on the output? |
I updated Naga to the latest commit 2 days ago. The code I'm using is: #include shaders.util.globals
#include shaders.util.light
[[block]]
struct Locals {
m: mat4x4<f32>;
};
[[group(1), binding(0)]] var<uniform> locals: Locals;
struct VertexIn {
[[location(0)]] pos: vec3<f32>;
[[location(1)]] norm: vec3<f32>;
[[location(2)]] uv: vec2<f32>;
};
struct VertexOut {
[[builtin(position)]] pos: vec4<f32>;
[[location(0)]] norm: vec3<f32>;
[[location(1)]] uv: vec2<f32>;
[[location(2)]] wpos: vec3<f32>;
};
[[stage(vertex)]]
fn vs_main(vert: VertexIn) -> VertexOut {
let wpos = locals.m * vec4<f32>(vert.pos, 1.0);
return VertexOut(
globals.vp * wpos,
vert.norm,
vert.uv,
wpos.xyz,
);
}
[[group(1), binding(1)]] var color_texture: texture_2d<f32>;
[[group(1), binding(2)]] var color_sampler: sampler;
[[stage(fragment)]]
fn fs_main(frag: VertexOut) -> [[location(0)]] vec4<f32> {
let albedo = textureSample(color_texture, color_sampler, frag.uv).rgb;
return vec4<f32>(illuminate(frag.wpos, normalize(frag.norm), albedo, 0.5, 1.0), 1.0);
} (Ignore the The error we're getting on Mac OS is as follows:
|
Looks like the backend is adding the padding to this structure and failing to take it into account. This is related to gpuweb/gpuweb#1792 (comment) |
I can confirm this is the case. After switching the fields to all be |
@zesterer the subject, body, and the labels on this issue are totally different from what you are now facing. Would you mind filing a separate issue? |
Sure. I'll mostly copy the text of my recent comment. |
I've opened #1081 to track this latter issue. |
This is still broken:
|
Fixes gfx-rs#1745: Support out-of-order module scope declarations in WGSL Fixes gfx-rs#1044: Forbid local variable shadowing in WGSL Fixes gfx-rs#2076: [wgsl-in] no error for duplicated type definition Fixes gfx-rs#2071: Global item does not support 'const' Fixes gfx-rs#2105: [wgsl-in] Type aliases for a vecN<T> doesn't work when constructing vec from a single argument Fixes gfx-rs#1775: Referencing a function without a return type yields an unknown identifier error. Fixes gfx-rs#2089: Error span reported on the declaration of a variable instead of its use Fixes gfx-rs#1996: [wgsl-in] Confusing error: "expected unsigned/signed integer literal, found '1'" Separate parsing from lowering by generating an AST, which desugars as much as possible down to something like Naga IR. The AST is then used to resolve identifiers while lowering to Naga IR. Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com> Co-authored-by: Jim Blandy <jimb@red-bean.com>
This is actually generated by wgpu, but the error seems to be a mistranslation by naga.
(I've made an attempt at formatting the error such that it's a little more intelligible)
The original offending shader (written in wgsl, translated to spir-v also with naga, although possibly with a slightly different version) is as follows:
Unfortunately, I'm not the owner of the Mac in question, so my ability to reduce this to a minimal example is limited.
However, based on the error message produced by Metal (
VertexOut {_e52 * metal::float4(metal::float3(_e44.pos.xy, _e49), 1.0), _e44.uv, _e44.pos}
), it looks like the error occurs in the instantiation of theVertexOut
structure in the vertex shader, here:The text was updated successfully, but these errors were encountered: