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

Accessing array inside of vertex shader causes bad data on Vulkan. #2018

Closed
StarArawn opened this issue Aug 1, 2022 · 1 comment
Closed

Comments

@StarArawn
Copy link

StarArawn commented Aug 1, 2022

Here is the WGPU cube shader modified to cause the error:

struct VertexOutput {
    @location(0) tex_coord: vec2<f32>,
    @builtin(position) position: vec4<f32>,
};

@group(0)
@binding(0)
var<uniform> transform: mat4x4<f32>;

@vertex
fn vs_main(
    @location(0) position: vec4<f32>,
    @location(1) tex_coord: vec2<f32>,
) -> VertexOutput {
    var result: VertexOutput;
    result.tex_coord = tex_coord;
    var positions: array<vec4<f32>, 1> = array<vec4<f32>, 1>(
        vec4(position.x + 1.0, position.y, position.z, position.w),
    );
    var index = 0u;
    result.position = transform * positions[index];
    return result;
}

@group(0)
@binding(1)
var r_color: texture_2d<u32>;

@fragment
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
    let tex = textureLoad(r_color, vec2<i32>(vertex.tex_coord * 256.0), 0);
    let v = f32(tex.x) / 255.0;
    return vec4<f32>(1.0 - (v * 5.0), 1.0 - (v * 15.0), 1.0 - (v * 50.0), 1.0);
}

@fragment
fn fs_wire(vertex: VertexOutput) -> @location(0) vec4<f32> {
    return vec4<f32>(0.0, 0.5, 0.0, 0.5);
}

This issue appears to only happen for dynamic indexing. Using 0 directly in the array lookup works fine. I think this is a regression? Because at some point I was able to do this without issue. This works on DX12 and Metal it is only broken on vulkan.

@StarArawn
Copy link
Author

Another user wasn't able to reproduce the same results. I updated my drivers and it seems to work correctly now. I was on geforce drivers: 511.79 and now I am on 516.59. I'm guessing this was a driver bug? Feel free to close the issue.

@cwfitzgerald cwfitzgerald closed this as not planned Won't fix, can't repro, duplicate, stale Aug 2, 2022
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

2 participants