Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

[wgsl-in] Indexing into matrices must be done beyond pointers #945

Closed
Gordon-F opened this issue Jun 3, 2021 · 3 comments
Closed

[wgsl-in] Indexing into matrices must be done beyond pointers #945

Gordon-F opened this issue Jun 3, 2021 · 3 comments

Comments

@Gordon-F
Copy link
Collaborator

Gordon-F commented Jun 3, 2021

Found in #943

Original code:

// AUTHOR: enfipy
// ISSUE: #210
// FIX: #898
#version 450

layout(location = 0) in vec3 Vertex_Position;
layout(location = 1) in vec3 Vertex_Normal;
layout(location = 2) in vec2 Vertex_Uv;

layout(location = 0) out vec3 v_Position;
layout(location = 1) out vec3 v_Normal;
layout(location = 2) out vec2 v_Uv;

layout(set = 0, binding = 0) uniform Camera {
    mat4 ViewProj;
};

layout(set = 2, binding = 0) uniform Transform {
    mat4 Model;
};

void main() {
    v_Normal = (Model * vec4(Vertex_Normal, 1.0)).xyz;
    v_Normal = mat3(Model) * Vertex_Normal;
    v_Position = (Model * vec4(Vertex_Position, 1.0)).xyz;
    v_Uv = Vertex_Uv;
    gl_Position = ViewProj * vec4(v_Position, 1.0);
}

Consumed wgsl:

[[block]]
struct Camera {
    ViewProj: mat4x4<f32>;
};

[[block]]
struct Transform {
    Model: mat4x4<f32>;
};

struct VertexOutput {
    [[location(0), interpolate(perspective)]] member: vec3<f32>;
    [[location(1), interpolate(perspective)]] member1: vec3<f32>;
    [[location(2), interpolate(perspective)]] member2: vec2<f32>;
    [[builtin(position)]] member3: vec4<f32>;
};

var<private> Vertex_Position: vec3<f32>;
var<private> Vertex_Normal: vec3<f32>;
var<private> Vertex_Uv: vec2<f32>;
var<private> v_Position: vec3<f32>;
var<private> v_Normal: vec3<f32>;
var<private> v_Uv: vec2<f32>;
[[group(0), binding(0)]]
var<uniform> global: Camera;
[[group(2), binding(0)]]
var<uniform> global1: Transform;
var<private> gl_Position: vec4<f32>;

fn main() {
    let _e3: vec3<f32> = Vertex_Normal;
    let _e17: mat4x4<f32> = global1.Model;
    let _e20: vec4<f32> = (_e17 * vec4<f32>(_e3, 1.0));
    v_Normal = vec3<f32>(_e20.x, _e20.y, _e20.z);
    v_Normal = (mat3x3<f32>(_e17[0].xyz, _e17[1].xyz, _e17[2].xyz) * _e3);
    let _e35: vec4<f32> = (_e17 * vec4<f32>(Vertex_Position, 1.0));
    v_Position = vec3<f32>(_e35.x, _e35.y, _e35.z);
    v_Uv = Vertex_Uv;
    gl_Position = (global.ViewProj * vec4<f32>(v_Position, 1.0));
    return;
}

[[stage(vertex)]]
fn main1([[location(0), interpolate(perspective)]] param: vec3<f32>, [[location(1), interpolate(perspective)]] param1: vec3<f32>, [[location(2), interpolate(perspective)]] param2: vec2<f32>) -> VertexOutput {
    Vertex_Position = param;
    Vertex_Normal = param1;
    Vertex_Uv = param2;
    main();
    return VertexOutput(v_Position, v_Normal, v_Uv, gl_Position);
}

Error when parsing:

Running `target/debug/naga tests/out/210-bevy-shader-vert.wgsl`
error: Invalid access into expression [12], indexed: false
@kvark kvark added area: back-end Outputs of shader conversion kind: bug Something isn't working lang: WGSL WebGPU shading language labels Jun 3, 2021
@JCapucho JCapucho added area: front-end Input formats for conversion and removed area: back-end Outputs of shader conversion labels Jun 3, 2021
@JCapucho JCapucho changed the title [wgsl-out] Invalid access into expression [wgsl-in] Indexing into matrices must be done beyond pointers Jun 3, 2021
@kvark kvark removed area: front-end Input formats for conversion kind: bug Something isn't working lang: WGSL WebGPU shading language labels Jun 3, 2021
@kvark
Copy link
Member

kvark commented Jun 3, 2021

Removing the tags, since this matches the WGSL design in #945

@Frizi
Copy link
Contributor

Frizi commented Jun 15, 2021

This reported validation error no longer happens under #973 for this shader.

@JCapucho
Copy link
Collaborator

I see no reason to keep this opened, since the original issue is fixed and the shader has no additional errors, closing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants