vulkano-rs / vulkano

Safe and rich Rust wrapper around the Vulkan API
Apache License 2.0
4.45k stars 435 forks source link

pipeline creation error #2523

Closed Delfi1 closed 4 months ago

Delfi1 commented 4 months ago

I can't figure out why the graphics pipeline isn't being created.

Error:

called `Result::unwrap()` on an `Err` value: a validation error occurred

Caused by:
    create_info.vertex_input_state: `attributes[0].format` takes up two locations, but `attributes` also contains a description for location 1

Vertex shader:

#version 450
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 color;

layout(location = 0) out vec3 out_color;

void main() {
    gl_Position = vec4(position, 1.0);
    out_color = color;
}

Pipeline:

let vs = shader.vertex.entry_point("main").unwrap();
let fs = shader.fragment.entry_point("main").unwrap();

let vertex_input_state = Vertex::per_vertex()
    .definition(&vs.info().input_interface)
    .unwrap();
let stages = [
    PipelineShaderStageCreateInfo::new(vs),
    PipelineShaderStageCreateInfo::new(fs),
];
let layout = PipelineLayout::new(
    self.vctx.device.clone(),
    PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages)
        .into_pipeline_layout_create_info(self.vctx.device.clone())
        .unwrap(),
)
.unwrap();

let subpass = Subpass::from(render_pass, 0).unwrap();
let extent = fctx.extent_f32();

GraphicsPipeline::new(
    self.vctx.device.clone(),
    None,
    GraphicsPipelineCreateInfo {
        stages: stages.into_iter().collect(),
        vertex_input_state: Some(vertex_input_state),
        input_assembly_state: Some(InputAssemblyState::default()),
        viewport_state: Some(ViewportState {
            viewports: [Viewport {
                offset: [0.0, 0.0],
                extent,
                depth_range: 0.0..=1.0,
            }]
            .into_iter()
            .collect(),
            ..Default::default()
        }),
        rasterization_state: Some(RasterizationState::default()),
        multisample_state: Some(MultisampleState::default()),
        color_blend_state: Some(ColorBlendState::with_attachment_states(
            subpass.num_color_attachments(),
            ColorBlendAttachmentState::default(),
        )),
        subpass: Some(subpass.into()),
        ..GraphicsPipelineCreateInfo::layout(layout)
    }
)
.unwrap()
marc0246 commented 4 months ago

May I see the definition of Vertex?

Delfi1 commented 4 months ago

May I see the definition of Vertex?

pub use vulkano::pipeline::graphics::vertex_input::Vertex as VulkanoVertex;

#[derive(Debug, Clone, BufferContents, VulkanoVertex)]
#[repr(C)]
pub struct Vertex {
    #[format(R64G64B64_SFLOAT)]
    pub position: [f64; 3],
    #[format(R64G64B64_SFLOAT)]
    pub color: [f64; 3],
}
marc0246 commented 4 months ago

That's the wrong vertex format, it should be R32G32B32_SFLOAT.

Delfi1 commented 4 months ago

That's the wrong vertex format, it should be R32G32B32_SFLOAT.

OH THAKS I've been at it for 5 hours, thank you!!!!

marc0246 commented 4 months ago

I forgot to mention that you need to change it from f64 to f32 as well, to match the format and shader.

Delfi1 commented 4 months ago

I forgot to mention that you need to change it from f64 to f32 as well, to match the format and shader.

Yeah. I changed it right away as I realized my mistake.