Rust-GPU / Rust-GPU/rust-gpu

Nalgebra vector fails to be recongized

Open
#247 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
3.4k
Forks
125
PR merge metrics
No merged PRs in 30d

Description

I tried using nalgebra (no-std) for types in shaders, but the simplest shaders fails to compile.

use nalgebra::Vector4;
use spirv_std::spirv;

#[allow(dead_code)]
#[spirv(fragment)]
pub fn main_fs(output: &mut Vector4<f32>) {
	*output = Vector4::new(1.0, 0.0, 0.0, 1.0);
}

#[allow(dead_code)]
#[spirv(vertex)]
pub fn main_vs(
	#[spirv(vertex_index)] vert_id: i32,
	#[spirv(position, invariant)] out_pos: &mut Vector4<f32>,
) {
	*out_pos = Vector4::new(
		(vert_id - 1) as f32,
		((vert_id & 1) * 2 - 1) as f32,
		0.0,
		1.0,
	);
}

Is the module I am trying to compile, and the error received is:

  error: [VUID-Position-Position-04321] According to the Vulkan spec BuiltIn Position variable needs to be a 4-component 32-bit float vector. ID <3> (OpVariable) is not a float vector.
    |
    = note: module `/home/marios/proj/hestia_vk/target/spirv-builder/spirv-unknown-vulkan1.2/release/deps/shaders.spvs/mesh-main_vs.spv`

  warning: an unknown error occurred
    |
    = note: spirv-opt failed, leaving as unoptimized
    = note: module `/home/marios/proj/hestia_vk/target/spirv-builder/spirv-unknown-vulkan1.2/release/deps/shaders.spvs/mesh-main_vs.spv`

  error: error:0:0 - [VUID-Position-Position-04321] According to the Vulkan spec BuiltIn Position variable needs to be a 4-component 32-bit float vector. ID <3> (OpVariable) is not a float vector.
           %50 = OpInBoundsAccessChain %_ptr_Output__arr_float_uint_4 %out_pos %uint_0 %uint_0 %uint_0
    |
    = note: spirv-val failed

If I comment out the main_vs function all is well.

It seems like the Vector4 type isnt being interpreted as a [f32;4]

I am wondering if this is because of the underlying type: pub struct ArrayStorage<T, const R: usize, const C: usize>(pub [[T; R]; C]);

It evaluates with R=4, C=1, making the inner type [[f32; 4],1]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal shader entry points main_vs and main_fs and reproduce the Vulkan validation failure using nalgebra::Vector4. Inspect the generated mesh-main_vs.spv and its Position variable to determine whether the vector representation is emitted correctly; done means the shader validates with main_vs enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.