diff --git a/res/shaders/vertex.vert b/res/shaders/vertex.vert index 3adb319..ec483f7 100644 --- a/res/shaders/vertex.vert +++ b/res/shaders/vertex.vert @@ -1 +1 @@ -#version 450 layout (location = 0) in vec2 position; layout (location = 1) in vec3 color; layout (location = 0) out vec3 fragColor; void main() { gl_Position = vec4(position, 0.0, 1.0); fragColor = color; } \ No newline at end of file +#version 450 layout (location = 0) in vec2 position; layout (location = 1) in vec3 color; layout (location = 0) out vec3 fragColor; layout (set = 0, binding = 0) uniform MVP_Data { mat4 model; mat4 view; mat4 projection; } uniforms; void main() { gl_Position = vec4(position, 0.0, 1.0); fragColor = color; } \ No newline at end of file diff --git a/src/renderer/pipelines/triangle_pipeline.rs b/src/renderer/pipelines/triangle_pipeline.rs index 77d1092..1423b8f 100644 --- a/src/renderer/pipelines/triangle_pipeline.rs +++ b/src/renderer/pipelines/triangle_pipeline.rs @@ -1,5 +1,9 @@ +use std::collections::BTreeMap; use std::error::Error; use std::sync::Arc; +use vulkano::descriptor_set::layout::{ + DescriptorSetLayoutBinding, DescriptorSetLayoutCreateInfo, DescriptorType, +}; use vulkano::device::Device; use vulkano::pipeline::graphics::color_blend::{ColorBlendAttachmentState, ColorBlendState}; use vulkano::pipeline::graphics::input_assembly::InputAssemblyState; @@ -9,11 +13,11 @@ use vulkano::pipeline::graphics::subpass::PipelineRenderingCreateInfo; use vulkano::pipeline::graphics::vertex_input::{Vertex, VertexDefinition}; use vulkano::pipeline::graphics::viewport::ViewportState; use vulkano::pipeline::graphics::GraphicsPipelineCreateInfo; -use vulkano::pipeline::layout::PipelineDescriptorSetLayoutCreateInfo; +use vulkano::pipeline::layout::{PipelineDescriptorSetLayoutCreateInfo, PipelineLayoutCreateFlags}; use vulkano::pipeline::{ DynamicState, GraphicsPipeline, PipelineLayout, PipelineShaderStageCreateInfo, }; -use vulkano::shader::EntryPoint; +use vulkano::shader::{EntryPoint, ShaderStages}; use vulkano::swapchain::Swapchain; use crate::renderer::Vertex2D; @@ -46,8 +50,23 @@ pub fn create_triangle_pipeline( PipelineShaderStageCreateInfo::new(fs), ]; - let create_info = PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages) - .into_pipeline_layout_create_info(device.clone())?; + let mut bindings = BTreeMap::::new(); + let mut descriptor_set_layout_binding = + DescriptorSetLayoutBinding::descriptor_type(DescriptorType::UniformBufferDynamic); + descriptor_set_layout_binding.stages = ShaderStages::VERTEX; + bindings.insert(0, descriptor_set_layout_binding); + + let descriptor_set_layout = DescriptorSetLayoutCreateInfo { + bindings, + ..Default::default() + }; + + let create_info = PipelineDescriptorSetLayoutCreateInfo { + set_layouts: vec![descriptor_set_layout], + flags: PipelineLayoutCreateFlags::default(), + push_constant_ranges: vec![], + } + .into_pipeline_layout_create_info(device.clone())?; let layout = PipelineLayout::new(device.clone(), create_info)?; @@ -82,11 +101,11 @@ pub fn create_triangle_pipeline( fn load_shaders(device: &Arc) -> Result<(EntryPoint, EntryPoint), Box> { let vs = shaders::vs::load(device.clone())? .entry_point("main") - .ok_or(format!("Failed find main entry point of vertex shader"))?; + .ok_or("Failed find main entry point of vertex shader".to_string())?; let fs = shaders::fs::load(device.clone())? .entry_point("main") - .ok_or(format!("Failed find main entry point of fragment shader"))?; + .ok_or("Failed find main entry point of fragment shader".to_string())?; Ok((vs, fs)) }