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

Erroneous association of outputs when code is in a single spirv file. #137

Open
Makogan opened this issue Apr 4, 2024 · 2 comments
Open

Comments

@Makogan
Copy link

Makogan commented Apr 4, 2024

I am using rust gpu to compile shaders. rust-gpu generates a single spirv for all stages. I am having the following issue I have this shader:

#![deny(warnings)]

mod shared;

extern crate spirv_std;
extern crate bytemuck;

use shared::glam::{Vec4, Vec3};
use spirv_std::spirv;

#[spirv(fragment)]
// pub fn main_fs(next_pos: Vec4, output: &mut Vec4)
pub fn main_fs(output: &mut Vec4)
{
    // *output = Vec4::new(1.0, 0.0001 * next_pos.x, 0.0, 1.0);
    *output = Vec4::new(1.0, 0.0001, 0.0, 1.0);
}

#[spirv(vertex)]
pub fn main_vs(
    #[spirv(vertex_index)] vert_id: i32,
    #[spirv(uniform, descriptor_set = 1, binding = 0)] toggle: &u32,
    #[spirv(position, invariant)] out_pos: &mut Vec4,
    position: Vec3,
    offset_bind2: Vec3,
    n_pos: &mut Vec4,
) {
    *out_pos = Vec4::new(
        (vert_id - 1) as f32 + (position.x + offset_bind2.x) * 0.000001,
        ((vert_id & 1) * 2 - 1) as f32,
        0.0,
        if *toggle == 0 { 1.0 } else { 0.0 },
    );

    *n_pos = *out_pos;
}

I am then parsing the generated spirv with spirq:

 Variable::Output { name, location, ty } =>
                    {
                        if entry_point.exec_model != ExecutionModel::Fragment
                        {
                            continue;
                        }

                        println!("{:?}", ty);
                        println!("{:?}", name);
                        println!("{:?}", entry_point.exec_model);
                        attachment_outputs.push(parse_fragment_output(&ty));
                    }

Which is printing:

Vector(VectorType { scalar_ty: Float { bits: 32 }, nscalar: 4 })
Some("output")
Fragment
Vector(VectorType { scalar_ty: Float { bits: 32 }, nscalar: 4 })
Some("n_pos")
Fragment

So it seems that spirq is assigning all outputs from all shader stages to each entry point, instead of just those defined for that entry point alone.

@PENGUINLIONG
Copy link
Owner

Did you call ReflectConfig::ref_all_rscs() with true when you start the reflection? If so, it ought to be binding interfaces to all the entry points. If not then it is confirmed a bug and I can work on this one.

@PENGUINLIONG
Copy link
Owner

Could you upload an compiled artifact for example? Tried it a little bit but I found it difficult to make spirv-std compiling.

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

2 participants