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

Matrix alignment mismatch with push constants #1208

Closed
chlobes opened this issue Jun 24, 2019 · 3 comments
Closed

Matrix alignment mismatch with push constants #1208

chlobes opened this issue Jun 24, 2019 · 3 comments

Comments

@chlobes
Copy link

chlobes commented Jun 24, 2019

  • Version of vulkano: 0.12.0 and 0.11.1
  • OS: Arch Linux
  • GPU: Geforce GTX 1050 Ti
  • GPU Driver: "NVIDIA Unified Driver for all Supported NVIDIA GPUs"
#version 450
//fragment shader

layout(push_constant) uniform PushConstants {
    mat3 m;
} pc;

out layout(location = 0) out vec4 target;

void main() {
    target = pc.m * vec3(0.0, 1.0, 1.0);
    //results in a black screen when identity matrix is used, because the identity matrix is instead read as [[1, 0, 0], [1, 0, 0], [1, 0, 0]]
}

Issue

Rust packs the matrix too tightly, as an [[f32; 3]; 3], with no gaps between elements, whereas the gpu expects an [[f32; 4]; 3], where the last element of each [f32; 4] is dummy data.
This means that the gpu will read m[1] as [m[1][1], m[1][2], m[2][0]] and m[2] as [m[2][2], m[3][0], m[3][1]] (out of bounds array accesses, potential UB as well as being incorrect?), m[0] will be read normally.

@Azorlogh
Copy link

Azorlogh commented Dec 8, 2019

I can confirm this on my machine, I just encountered this problem :
Version of vulkano: 0.13.0 & 0.16.0
OS: Windows 10 x64
GPU: Geforce GT 650M

@LeonMatthes
Copy link
Contributor

Hi, I'm also experiencing this issue at the moment with vulkano 0.29

@marc0246
Copy link
Contributor

marc0246 commented Jul 7, 2023

This has been fixed in #2132.

@marc0246 marc0246 closed this as completed Jul 7, 2023
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