move projection matrix to push constants

ecs
q3k 2020-03-14 17:32:05 +01:00
parent 792409145d
commit 9c217bd83c
4 changed files with 14 additions and 28 deletions

View File

@ -1,7 +1,7 @@
// vim: set ft=glsl: // vim: set ft=glsl:
#version 450 #version 450
layout(binding = 0) uniform UniformBufferObject { layout(push_constant) uniform UniformBufferObject {
mat4 model; mat4 model;
} ubo; } ubo;

View File

@ -198,14 +198,14 @@ impl<WT: 'static + Send + Sync> Instance<WT> {
let ubo = data::UniformBufferObject { let ubo = data::UniformBufferObject {
model: proj.clone() * view.clone() * d.get_transform(), model: proj.clone() * view.clone() * d.get_transform(),
}; };
let ub = self.uniform_pool.as_ref().unwrap().next(ubo.clone()).unwrap(); //let ub = self.uniform_pool.as_ref().unwrap().next(ubo.clone()).unwrap();
let ds = self.pipeline.as_mut().unwrap().make_descriptor_set(Box::new(ub)); //let ds = self.pipeline.as_mut().unwrap().make_descriptor_set(Box::new(ub));
let pipeline = self.pipeline.as_ref().unwrap().get_pipeline(); let pipeline = self.pipeline.as_ref().unwrap().get_pipeline();
c = c.draw_indexed(pipeline, &vc::DynamicState::none(), c = c.draw_indexed(pipeline, &vc::DynamicState::none(),
vec![vbuffer.clone()], vec![vbuffer.clone()],
ibuffer.clone(), ibuffer.clone(),
ds, (),
()).unwrap(); ubo).unwrap();
} }

View File

@ -4,6 +4,7 @@ use std::sync::Arc;
use vulkano::buffer as vb; use vulkano::buffer as vb;
use vulkano::descriptor::descriptor as vdD; use vulkano::descriptor::descriptor as vdD;
use vulkano::descriptor::descriptor_set as vdd; use vulkano::descriptor::descriptor_set as vdd;
use vulkano::descriptor::pipeline_layout as vdp;
use vulkano::device as vd; use vulkano::device as vd;
use vulkano::format::Format; use vulkano::format::Format;
use vulkano::framebuffer as vf; use vulkano::framebuffer as vf;
@ -53,14 +54,11 @@ impl Forward {
name: Some(Cow::Borrowed("fragColor")), name: Some(Cow::Borrowed("fragColor")),
} }
], ],
uniforms: vec![ uniforms: vec![],
vdD::DescriptorDesc { push_constants: vec![
ty: vdD::DescriptorDescTy::Buffer(vdD::DescriptorBufferDesc { vdp::PipelineLayoutDescPcRange {
dynamic: Some(false), offset: 0,
storage: false, size: 64usize,
}),
array_count: 1,
readonly: true,
stages: vdD::ShaderStages { stages: vdD::ShaderStages {
vertex: true, vertex: true,
..vdD::ShaderStages::none() ..vdD::ShaderStages::none()
@ -85,6 +83,7 @@ impl Forward {
} }
], ],
uniforms: vec![], uniforms: vec![],
push_constants: vec![],
}.load_into(device.clone()).expect("could not load fragment shader"); }.load_into(device.clone()).expect("could not load fragment shader");
let dimensions = [viewport_dimensions[0] as f32, viewport_dimensions[1] as f32]; let dimensions = [viewport_dimensions[0] as f32, viewport_dimensions[1] as f32];

View File

@ -16,6 +16,7 @@ pub struct ShaderDefinition {
pub inputs: Vec<vps::ShaderInterfaceDefEntry>, pub inputs: Vec<vps::ShaderInterfaceDefEntry>,
pub outputs: Vec<vps::ShaderInterfaceDefEntry>, pub outputs: Vec<vps::ShaderInterfaceDefEntry>,
pub uniforms: Vec<vdd::DescriptorDesc>, pub uniforms: Vec<vdd::DescriptorDesc>,
pub push_constants: Vec<vdp::PipelineLayoutDescPcRange>,
} }
impl ShaderDefinition { impl ShaderDefinition {
@ -56,7 +57,7 @@ impl LoadedShader {
} }
fn layout(&self) -> RuntimeShaderLayout { fn layout(&self) -> RuntimeShaderLayout {
RuntimeShaderLayout{ descs: vec![self.def.uniforms.clone()], push_constants: vec![], } RuntimeShaderLayout{ descs: vec![self.def.uniforms.clone()], push_constants: self.def.push_constants.clone(), }
} }
pub fn entry_point<'a, S>(&'a self) -> vps::GraphicsEntryPoint<'a, S, ShaderInterface, ShaderInterface, RuntimeShaderLayout> { pub fn entry_point<'a, S>(&'a self) -> vps::GraphicsEntryPoint<'a, S, ShaderInterface, ShaderInterface, RuntimeShaderLayout> {
@ -104,20 +105,6 @@ unsafe impl vdp::PipelineLayoutDesc for RuntimeShaderLayout {
} }
Some(self.push_constants[0].clone()) Some(self.push_constants[0].clone())
} }
//fn num_push_constants_ranges(&self) -> usize { 1 }
//fn push_constants_range(&self, num: usize) -> Option<vdp::PipelineLayoutDescPcRange> {
// match num {
// 0 => Some(vdp::PipelineLayoutDescPcRange {
// offset: 0,
// size: 64usize,
// stages: vdd::ShaderStages {
// vertex: true,
// ..vdd::ShaderStages::none()
// },
// }),
// _ => None,
// }
//}
} }
pub struct ShaderInterface { pub struct ShaderInterface {