unhardcode shader descriptor layout
parent
b1fef79ead
commit
792409145d
|
@ -2,6 +2,7 @@ use std::borrow::Cow;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use vulkano::buffer as vb;
|
use vulkano::buffer as vb;
|
||||||
|
use vulkano::descriptor::descriptor as vdD;
|
||||||
use vulkano::descriptor::descriptor_set as vdd;
|
use vulkano::descriptor::descriptor_set as vdd;
|
||||||
use vulkano::device as vd;
|
use vulkano::device as vd;
|
||||||
use vulkano::format::Format;
|
use vulkano::format::Format;
|
||||||
|
@ -37,11 +38,34 @@ impl Forward {
|
||||||
name: "forward_vert.spv".to_string(),
|
name: "forward_vert.spv".to_string(),
|
||||||
ty: vps::GraphicsShaderType::Vertex,
|
ty: vps::GraphicsShaderType::Vertex,
|
||||||
inputs: vec![
|
inputs: vec![
|
||||||
vps::ShaderInterfaceDefEntry { location: 0..1, format: Format::R32G32B32Sfloat, name: Some(Cow::Borrowed("pos")) },
|
vps::ShaderInterfaceDefEntry {
|
||||||
vps::ShaderInterfaceDefEntry { location: 1..2, format: Format::R32G32B32Sfloat, name: Some(Cow::Borrowed("color")) },
|
location: 0..1, format: Format::R32G32B32Sfloat,
|
||||||
|
name: Some(Cow::Borrowed("pos")),
|
||||||
|
},
|
||||||
|
vps::ShaderInterfaceDefEntry {
|
||||||
|
location: 1..2, format: Format::R32G32B32Sfloat,
|
||||||
|
name: Some(Cow::Borrowed("color")),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
outputs: vec![
|
outputs: vec![
|
||||||
vps::ShaderInterfaceDefEntry { location: 0..1, format: Format::R32G32B32Sfloat, name: Some(Cow::Borrowed("fragColor")) }
|
vps::ShaderInterfaceDefEntry {
|
||||||
|
location: 0..1, format: Format::R32G32B32Sfloat,
|
||||||
|
name: Some(Cow::Borrowed("fragColor")),
|
||||||
|
}
|
||||||
|
],
|
||||||
|
uniforms: vec![
|
||||||
|
vdD::DescriptorDesc {
|
||||||
|
ty: vdD::DescriptorDescTy::Buffer(vdD::DescriptorBufferDesc {
|
||||||
|
dynamic: Some(false),
|
||||||
|
storage: false,
|
||||||
|
}),
|
||||||
|
array_count: 1,
|
||||||
|
readonly: true,
|
||||||
|
stages: vdD::ShaderStages {
|
||||||
|
vertex: true,
|
||||||
|
..vdD::ShaderStages::none()
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}.load_into(device.clone()).expect("could not load vertex shader");
|
}.load_into(device.clone()).expect("could not load vertex shader");
|
||||||
|
|
||||||
|
@ -49,11 +73,18 @@ impl Forward {
|
||||||
name: "forward_frag.spv".to_string(),
|
name: "forward_frag.spv".to_string(),
|
||||||
ty: vps::GraphicsShaderType::Fragment,
|
ty: vps::GraphicsShaderType::Fragment,
|
||||||
inputs: vec![
|
inputs: vec![
|
||||||
vps::ShaderInterfaceDefEntry { location: 0..1, format: Format::R32G32B32Sfloat, name: Some(Cow::Borrowed("fragColor")) }
|
vps::ShaderInterfaceDefEntry {
|
||||||
|
location: 0..1, format: Format::R32G32B32Sfloat,
|
||||||
|
name: Some(Cow::Borrowed("fragColor")),
|
||||||
|
}
|
||||||
],
|
],
|
||||||
outputs: vec![
|
outputs: vec![
|
||||||
vps::ShaderInterfaceDefEntry { location: 0..1, format: Format::R32G32B32A32Sfloat, name: Some(Cow::Borrowed("outColor")) }
|
vps::ShaderInterfaceDefEntry {
|
||||||
|
location: 0..1, format: Format::R32G32B32A32Sfloat,
|
||||||
|
name: Some(Cow::Borrowed("outColor")),
|
||||||
|
}
|
||||||
],
|
],
|
||||||
|
uniforms: 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];
|
||||||
|
|
|
@ -15,6 +15,7 @@ pub struct ShaderDefinition {
|
||||||
pub ty: vps::GraphicsShaderType,
|
pub ty: vps::GraphicsShaderType,
|
||||||
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>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShaderDefinition {
|
impl ShaderDefinition {
|
||||||
|
@ -55,27 +56,7 @@ impl LoadedShader {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout(&self) -> RuntimeShaderLayout {
|
fn layout(&self) -> RuntimeShaderLayout {
|
||||||
let sets = vec![
|
RuntimeShaderLayout{ descs: vec![self.def.uniforms.clone()], push_constants: vec![], }
|
||||||
vec![
|
|
||||||
vdd::DescriptorDesc {
|
|
||||||
ty: vdd::DescriptorDescTy::Buffer(vdd::DescriptorBufferDesc {
|
|
||||||
dynamic: Some(false),
|
|
||||||
storage: false,
|
|
||||||
}),
|
|
||||||
array_count: 1,
|
|
||||||
readonly: true,
|
|
||||||
stages: vdd::ShaderStages {
|
|
||||||
vertex: true,
|
|
||||||
..vdd::ShaderStages::none()
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
];
|
|
||||||
match self.def.ty {
|
|
||||||
vps::GraphicsShaderType::Vertex => RuntimeShaderLayout::vertex(sets.clone()),
|
|
||||||
vps::GraphicsShaderType::Fragment => RuntimeShaderLayout::fragment(sets.clone()),
|
|
||||||
_ => panic!("unknown shader type")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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> {
|
||||||
|
@ -95,48 +76,34 @@ impl LoadedShader {
|
||||||
|
|
||||||
#[derive (Debug, Clone)]
|
#[derive (Debug, Clone)]
|
||||||
pub struct RuntimeShaderLayout {
|
pub struct RuntimeShaderLayout {
|
||||||
sets: Vec<Vec<vdd::DescriptorDesc>>,
|
descs: Vec<Vec<vdd::DescriptorDesc>>,
|
||||||
|
push_constants: Vec<vdp::PipelineLayoutDescPcRange>,
|
||||||
vertex: bool,
|
|
||||||
fragment: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RuntimeShaderLayout {
|
|
||||||
fn vertex(sets: Vec<Vec<vdd::DescriptorDesc>>) -> RuntimeShaderLayout {
|
|
||||||
RuntimeShaderLayout {
|
|
||||||
sets,
|
|
||||||
vertex: true,
|
|
||||||
fragment: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn fragment(sets: Vec<Vec<vdd::DescriptorDesc>>) -> RuntimeShaderLayout {
|
|
||||||
RuntimeShaderLayout {
|
|
||||||
sets,
|
|
||||||
vertex: false,
|
|
||||||
fragment: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl vdp::PipelineLayoutDesc for RuntimeShaderLayout {
|
unsafe impl vdp::PipelineLayoutDesc for RuntimeShaderLayout {
|
||||||
fn num_sets(&self) -> usize { self.sets.len() }
|
fn num_sets(&self) -> usize { self.descs.len() }
|
||||||
fn num_bindings_in_set(&self, set: usize) -> Option<usize> {
|
fn num_bindings_in_set(&self, set: usize) -> Option<usize> {
|
||||||
if set >= self.sets.len() {
|
if set >= self.descs.len() {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
Some(self.sets[set].len())
|
Some(self.descs[set].len())
|
||||||
}
|
}
|
||||||
fn descriptor(&self, set: usize, binding: usize) -> Option<vdd::DescriptorDesc> {
|
fn descriptor(&self, set: usize, binding: usize) -> Option<vdd::DescriptorDesc> {
|
||||||
if set >= self.sets.len() {
|
if set >= self.descs.len() {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
if binding >= self.sets[set].len() {
|
if binding >= self.descs[set].len() {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
Some(self.sets[set][binding].clone())
|
Some(self.descs[set][binding].clone())
|
||||||
|
}
|
||||||
|
fn num_push_constants_ranges(&self) -> usize { self.push_constants.len() }
|
||||||
|
fn push_constants_range(&self, num: usize) -> Option<vdp::PipelineLayoutDescPcRange> {
|
||||||
|
if num >= self.push_constants.len() {
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
Some(self.push_constants[0].clone())
|
||||||
}
|
}
|
||||||
fn num_push_constants_ranges(&self) -> usize { 0 }
|
|
||||||
fn push_constants_range(&self, _num: usize) -> Option<vdp::PipelineLayoutDescPcRange> { None }
|
|
||||||
//fn num_push_constants_ranges(&self) -> usize { 1 }
|
//fn num_push_constants_ranges(&self) -> usize { 1 }
|
||||||
//fn push_constants_range(&self, num: usize) -> Option<vdp::PipelineLayoutDescPcRange> {
|
//fn push_constants_range(&self, num: usize) -> Option<vdp::PipelineLayoutDescPcRange> {
|
||||||
// match num {
|
// match num {
|
||||||
|
|
Loading…
Reference in New Issue