pub(crate) mod vs_draw {
use std::{sync::Arc, borrow::Cow, ffi::CStr};
use vulkano::{pipeline::shader::{ShaderModule, GraphicsShaderType, ShaderInterfaceDef, ShaderInterfaceDefEntry, GraphicsEntryPoint}, OomError, device::Device, format::Format, descriptor::{descriptor::{ShaderStages, DescriptorDesc, DescriptorDescTy, DescriptorBufferDesc}, pipeline_layout::{PipelineLayoutDesc, PipelineLayoutDescPcRange}}};
const SPIRV: &'static [u8] = &*include_bytes!("./spv_precompiles/vs_draw.spv");
pub mod ty {
#[repr(C)]
pub struct Camera{
pub to_view: [[f32; 4]; 4], pub view_to_screen: [[f32; 4]; 4], }
#[repr(C)]
pub struct World{
pub object_to: [[f32; 4]; 4], }
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct VertInput;
unsafe impl ShaderInterfaceDef for VertInput {
type Iter = VertInputIter;
fn elements(&self) -> VertInputIter {
VertInputIter(0)
}
}
#[derive(Debug, Copy, Clone)]
pub struct VertInputIter(u16);
impl Iterator for VertInputIter {
type Item = ShaderInterfaceDefEntry;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.0 == 2 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32B32Sfloat,
name: Some(Cow::Borrowed("position")),
});
} else if self.0 == 1 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 1..2,
format: Format::R32G32B32Sfloat,
name: Some(Cow::Borrowed("normal")),
});
} else if self.0 == 0 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 2..3,
format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("texture_index")),
});
}
None
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = (3 - self.0) as usize;
(len, Some(len))
}
}
impl ExactSizeIterator for VertInputIter {}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct VertOutput;
unsafe impl ShaderInterfaceDef for VertOutput {
type Iter = VertOutputIter;
fn elements(&self) -> VertOutputIter {
VertOutputIter(0)
}
}
#[derive(Debug, Copy, Clone)]
pub struct VertOutputIter(u16);
impl Iterator for VertOutputIter {
type Item = ShaderInterfaceDefEntry;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.0 == 2 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32B32Sfloat,
name: Some(Cow::Borrowed("v_normal")),
});
} else if self.0 == 1 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 1..2,
format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("v_texture_index")),
});
} else if self.0 == 0 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 2..3,
format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("v_camspace_xy")),
});
}
None
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = (3 - self.0) as usize;
(len, Some(len))
}
}
impl ExactSizeIterator for VertOutputIter {}
#[derive(Debug, Copy, Clone)]
pub struct VertLayout(ShaderStages);
unsafe impl PipelineLayoutDesc for VertLayout {
fn num_sets(&self) -> usize {
2
}
fn num_bindings_in_set(&self, _set: usize) -> Option<usize> {
Some(1)
}
fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
if set == 0 && binding == 0 {
Some(DescriptorDesc {
ty: DescriptorDescTy::Buffer(
DescriptorBufferDesc{
dynamic: None,
storage: false
}
),
array_count: 1,
stages: ShaderStages{
vertex: true,
..ShaderStages::none()
},
readonly: true
})
} else if set == 1 && binding == 0 {
Some(DescriptorDesc {
ty: DescriptorDescTy::Buffer(
DescriptorBufferDesc{
dynamic: None,
storage: false
}
),
array_count: 1,
stages: ShaderStages{
vertex: true,
..ShaderStages::none()
},
readonly: true
})
} else {
None
}
}
fn num_push_constants_ranges(&self) -> usize {
0
}
fn push_constants_range(&self, _num: usize) -> Option<PipelineLayoutDescPcRange> {
None
}
}
pub struct Shader {
module: Arc<ShaderModule>
}
impl Shader {
pub fn load(device: Arc<Device>) -> Result<Self, OomError> {
Ok(Shader{ module: unsafe { ShaderModule::new(device.clone(), &SPIRV) }? })
}
pub fn main_entry_point(&self) -> GraphicsEntryPoint<(), VertInput, VertOutput, VertLayout> {
unsafe{
self.module.graphics_entry_point(
CStr::from_bytes_with_nul_unchecked(b"main\0"),
VertInput,
VertOutput,
VertLayout(ShaderStages {
vertex: true,
..ShaderStages::none()
}),
GraphicsShaderType::Vertex,
)
}
}
}
}
pub(crate) mod fs_draw {
use std::{borrow::Cow, sync::Arc, ffi::CStr};
use vulkano::{pipeline::shader::{ShaderInterfaceDef, ShaderInterfaceDefEntry, ShaderModule, GraphicsEntryPoint, GraphicsShaderType}, format::Format, descriptor::{descriptor::{ShaderStages, DescriptorDesc, DescriptorDescTy, DescriptorBufferDesc, DescriptorImageDesc, DescriptorImageDescDimensions, DescriptorImageDescArray}, pipeline_layout::{PipelineLayoutDesc, PipelineLayoutDescPcRange}}, device::Device, OomError};
const SPIRV: &'static [u8] = &*include_bytes!("./spv_precompiles/fs_draw.spv");
pub mod ty {
#[repr(C)]
#[derive(Clone)]
pub struct Material { pub diffuse: [f32; 4],
pub ambient: [f32; 4],
pub specular: [f32; 4],
pub other: [f32; 4],
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FragInput;
unsafe impl ShaderInterfaceDef for FragInput {
type Iter = FragInputIter;
fn elements(&self) -> FragInputIter {
FragInputIter(0)
}
}
#[derive(Debug, Copy, Clone)]
pub struct FragInputIter(u16);
impl Iterator for FragInputIter {
type Item = ShaderInterfaceDefEntry;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.0 == 2 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 2..3,
format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("v_camspace_xy")),
});
} else if self.0 == 1 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 1..2,
format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("v_texture_index")),
});
} else if self.0 == 0 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32B32Sfloat,
name: Some(Cow::Borrowed("v_normal")),
});
}
None
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = (3 - self.0) as usize;
(len, Some(len))
}
}
impl ExactSizeIterator for FragInputIter {}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FragOutput;
unsafe impl ShaderInterfaceDef for FragOutput {
type Iter = FragOutputIter;
fn elements(&self) -> FragOutputIter {
FragOutputIter(0)
}
}
#[derive(Debug, Copy, Clone)]
pub struct FragOutputIter(u16);
impl Iterator for FragOutputIter {
type Item = ShaderInterfaceDefEntry;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.0 == 3 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("f_normals")),
});
} else if self.0 == 2 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 1..2,
format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("f_diffuse")),
});
} else if self.0 == 1 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 2..3,
format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("f_ambient")),
});
} else if self.0 == 0 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 3..4,
format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("f_specular")),
});
}
None
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = (4 - self.0) as usize;
(len, Some(len))
}
}
impl ExactSizeIterator for FragOutputIter {}
#[derive(Debug, Copy, Clone)]
pub struct FragLayout(ShaderStages);
unsafe impl PipelineLayoutDesc for FragLayout {
fn num_sets(&self) -> usize {
3
}
fn num_bindings_in_set(&self, set: usize) -> Option<usize> {
if set == 2 {
Some(5)
} else {
None
}
}
fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
if set == 2 && binding == 0 {
return Some(DescriptorDesc {
ty: DescriptorDescTy::Buffer(
DescriptorBufferDesc{
dynamic: None,
storage: false
}
),
array_count: 1,
stages: ShaderStages{
fragment: true,
..ShaderStages::none()
},
readonly: false
});
} else if set == 2 && (binding >= 1 || binding <= 4) {
return Some(DescriptorDesc {
ty: DescriptorDescTy::CombinedImageSampler(DescriptorImageDesc{
sampled: true,
dimensions: DescriptorImageDescDimensions::TwoDimensional,
format: None,
multisampled: false,
array_layers: DescriptorImageDescArray::NonArrayed,
}),
array_count: 1,
stages: ShaderStages{
fragment: true,
..ShaderStages::none()
},
readonly: true
});
}
None
}
fn num_push_constants_ranges(&self) -> usize {
0
}
fn push_constants_range(&self, _num: usize) -> Option<PipelineLayoutDescPcRange> {
None
}
}
pub struct Shader {
module: Arc<ShaderModule>
}
impl Shader {
pub fn load(device: Arc<Device>) -> Result<Self, OomError> {
Ok(Shader{ module: unsafe { ShaderModule::new(device.clone(), &SPIRV) }? })
}
pub fn main_entry_point(&self) -> GraphicsEntryPoint<(), FragInput, FragOutput, FragLayout> {
unsafe{
self.module.graphics_entry_point(
CStr::from_bytes_with_nul_unchecked(b"main\0"),
FragInput,
FragOutput,
FragLayout(ShaderStages {
fragment: true,
..ShaderStages::none()
}),
GraphicsShaderType::Fragment,
)
}
}
}
}
pub(crate) mod vs_lighting {
use std::{sync::Arc, borrow::Cow, ffi::CStr};
use vulkano::{pipeline::shader::{ShaderModule, GraphicsShaderType, ShaderInterfaceDef, ShaderInterfaceDefEntry, GraphicsEntryPoint}, OomError, device::Device, format::Format, descriptor::{descriptor::{ShaderStages, DescriptorDesc}, pipeline_layout::{PipelineLayoutDesc, PipelineLayoutDescPcRange}}};
const SPIRV: &'static [u8] = &*include_bytes!("./spv_precompiles/vs_lighting.spv");
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct VertInput;
unsafe impl ShaderInterfaceDef for VertInput {
type Iter = VertInputIter;
fn elements(&self) -> VertInputIter {
VertInputIter(0)
}
}
#[derive(Debug, Copy, Clone)]
pub struct VertInputIter(u16);
impl Iterator for VertInputIter {
type Item = ShaderInterfaceDefEntry;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.0 == 0 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32Sfloat,
name: Some(Cow::Borrowed("position")),
});
}
None
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = (1 - self.0) as usize;
(len, Some(len))
}
}
impl ExactSizeIterator for VertInputIter {}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct VertOutput;
unsafe impl ShaderInterfaceDef for VertOutput {
type Iter = VertOutputIter;
fn elements(&self) -> VertOutputIter {
VertOutputIter(0)
}
}
#[derive(Debug, Copy, Clone)]
pub struct VertOutputIter(u16);
impl Iterator for VertOutputIter {
type Item = ShaderInterfaceDefEntry;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
None
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}
impl ExactSizeIterator for VertOutputIter {}
#[derive(Debug, Copy, Clone)]
pub struct VertLayout(ShaderStages);
unsafe impl PipelineLayoutDesc for VertLayout {
fn num_sets(&self) -> usize {
0
}
fn num_bindings_in_set(&self, _set: usize) -> Option<usize> {
None
}
fn descriptor(&self, _set: usize, _binding: usize) -> Option<DescriptorDesc> {
None
}
fn num_push_constants_ranges(&self) -> usize {
0
}
fn push_constants_range(&self, _num: usize) -> Option<PipelineLayoutDescPcRange> {
None
}
}
pub struct Shader {
module: Arc<ShaderModule>
}
impl Shader {
pub fn load(device: Arc<Device>) -> Result<Self, OomError> {
Ok(Shader{ module: unsafe { ShaderModule::new(device.clone(), &SPIRV) }? })
}
pub fn main_entry_point(&self) -> GraphicsEntryPoint<(), VertInput, VertOutput, VertLayout> {
unsafe{
self.module.graphics_entry_point(
CStr::from_bytes_with_nul_unchecked(b"main\0"),
VertInput,
VertOutput,
VertLayout(ShaderStages {
vertex: true,
..ShaderStages::none()
}),
GraphicsShaderType::Vertex,
)
}
}
}
}
pub(crate) mod fs_lighting_point {
use std::{borrow::Cow, sync::Arc, ffi::CStr};
use vulkano::{pipeline::shader::{ShaderInterfaceDef, ShaderInterfaceDefEntry, ShaderModule, GraphicsEntryPoint, GraphicsShaderType}, format::Format, descriptor::{descriptor::{ShaderStages, DescriptorDesc, DescriptorDescTy, DescriptorImageDescArray}, pipeline_layout::{PipelineLayoutDesc, PipelineLayoutDescPcRange}}, device::Device, OomError};
const SPIRV: &'static [u8] = &*include_bytes!("./spv_precompiles/fs_lighting_point.spv");
pub mod ty {
#[repr(C)]
pub struct PushConstants {
pub screen_to_camera: [[f32; 4]; 4],
pub color: [f32; 4],
pub position_camera_space: [f32; 4]
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FragInput;
unsafe impl ShaderInterfaceDef for FragInput {
type Iter = FragInputIter;
fn elements(&self) -> FragInputIter {
FragInputIter(0)
}
}
#[derive(Debug, Copy, Clone)]
pub struct FragInputIter(u16);
impl Iterator for FragInputIter {
type Item = ShaderInterfaceDefEntry;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
None
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}
impl ExactSizeIterator for FragInputIter {}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FragOutput;
unsafe impl ShaderInterfaceDef for FragOutput {
type Iter = FragOutputIter;
fn elements(&self) -> FragOutputIter {
FragOutputIter(0)
}
}
#[derive(Debug, Copy, Clone)]
pub struct FragOutputIter(u16);
impl Iterator for FragOutputIter {
type Item = ShaderInterfaceDefEntry;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.0 == 0 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("f_color")),
});
}
None
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = (1 - self.0) as usize;
(len, Some(len))
}
}
impl ExactSizeIterator for FragOutputIter {}
#[derive(Debug, Copy, Clone)]
pub struct FragLayout(ShaderStages);
unsafe impl PipelineLayoutDesc for FragLayout {
fn num_sets(&self) -> usize {
1
}
fn num_bindings_in_set(&self, _set: usize) -> Option<usize> {
Some(4)
}
fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
if set == 0 && binding == 0 {
return Some(DescriptorDesc {
ty: DescriptorDescTy::InputAttachment{
multisampled: false,
array_layers: DescriptorImageDescArray::NonArrayed,
},
array_count: 1,
stages: ShaderStages{
fragment: true,
..ShaderStages::none()
},
readonly: true
});
} else if set == 0 && binding <= 3 {
return Some(DescriptorDesc {
ty: DescriptorDescTy::InputAttachment{
multisampled: false,
array_layers: DescriptorImageDescArray::NonArrayed,
},
array_count: 1,
stages: ShaderStages{
fragment: true,
..ShaderStages::none()
},
readonly: true
});
} else {
return None;
}
}
fn num_push_constants_ranges(&self) -> usize {
1
}
fn push_constants_range(&self, _num: usize) -> Option<PipelineLayoutDescPcRange> {
Some(
PipelineLayoutDescPcRange{
offset: 0,
size: 96,
stages: ShaderStages{
fragment: true,
..ShaderStages::none()
},
}
)
}
}
pub struct Shader {
module: Arc<ShaderModule>
}
impl Shader {
pub fn load(device: Arc<Device>) -> Result<Self, OomError> {
Ok(Shader{ module: unsafe { ShaderModule::new(device.clone(), &SPIRV) }? })
}
pub fn main_entry_point(&self) -> GraphicsEntryPoint<(), FragInput, FragOutput, FragLayout> {
unsafe{
self.module.graphics_entry_point(
CStr::from_bytes_with_nul_unchecked(b"main\0"),
FragInput,
FragOutput,
FragLayout(ShaderStages {
fragment: true,
..ShaderStages::none()
}),
GraphicsShaderType::Fragment,
)
}
}
}
}
pub(crate) mod fs_lighting_directional {
use std::{borrow::Cow, sync::Arc, ffi::CStr};
use vulkano::{pipeline::shader::{ShaderInterfaceDef, ShaderInterfaceDefEntry, ShaderModule, GraphicsEntryPoint, GraphicsShaderType}, format::Format, descriptor::{descriptor::{ShaderStages, DescriptorDesc, DescriptorDescTy, DescriptorImageDescArray}, pipeline_layout::{PipelineLayoutDesc, PipelineLayoutDescPcRange}}, device::Device, OomError};
const SPIRV: &'static [u8] = &*include_bytes!("./spv_precompiles/fs_lighting_directional.spv");
pub mod ty {
#[repr(C)]
pub struct PushConstants {
pub color: [f32; 4],
pub direction: [f32; 4]
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FragInput;
unsafe impl ShaderInterfaceDef for FragInput {
type Iter = FragInputIter;
fn elements(&self) -> FragInputIter {
FragInputIter(0)
}
}
#[derive(Debug, Copy, Clone)]
pub struct FragInputIter(u16);
impl Iterator for FragInputIter {
type Item = ShaderInterfaceDefEntry;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
None
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}
impl ExactSizeIterator for FragInputIter {}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FragOutput;
unsafe impl ShaderInterfaceDef for FragOutput {
type Iter = FragOutputIter;
fn elements(&self) -> FragOutputIter {
FragOutputIter(0)
}
}
#[derive(Debug, Copy, Clone)]
pub struct FragOutputIter(u16);
impl Iterator for FragOutputIter {
type Item = ShaderInterfaceDefEntry;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.0 == 0 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("f_color")),
});
}
None
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = (1 - self.0) as usize;
(len, Some(len))
}
}
impl ExactSizeIterator for FragOutputIter {}
#[derive(Debug, Copy, Clone)]
pub struct FragLayout(ShaderStages);
unsafe impl PipelineLayoutDesc for FragLayout {
fn num_sets(&self) -> usize {
1
}
fn num_bindings_in_set(&self, _set: usize) -> Option<usize> {
Some(2)
}
fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
if set == 0 && binding == 0 {
return Some(DescriptorDesc {
ty: DescriptorDescTy::InputAttachment{
multisampled: false,
array_layers: DescriptorImageDescArray::NonArrayed,
},
array_count: 1,
stages: ShaderStages{
fragment: true,
..ShaderStages::none()
},
readonly: true
});
} else if set == 0 && binding == 1 {
return Some(DescriptorDesc {
ty: DescriptorDescTy::InputAttachment{
multisampled: false,
array_layers: DescriptorImageDescArray::NonArrayed,
},
array_count: 1,
stages: ShaderStages{
fragment: true,
..ShaderStages::none()
},
readonly: true
});
} else {
return None;
}
}
fn num_push_constants_ranges(&self) -> usize {
1
}
fn push_constants_range(&self, _num: usize) -> Option<PipelineLayoutDescPcRange> {
Some(
PipelineLayoutDescPcRange{
offset: 0,
size: 32,
stages: ShaderStages{
fragment: true,
..ShaderStages::none()
},
}
)
}
}
pub struct Shader {
module: Arc<ShaderModule>
}
impl Shader {
pub fn load(device: Arc<Device>) -> Result<Self, OomError> {
Ok(Shader{ module: unsafe { ShaderModule::new(device.clone(), &SPIRV) }? })
}
pub fn main_entry_point(&self) -> GraphicsEntryPoint<(), FragInput, FragOutput, FragLayout> {
unsafe{
self.module.graphics_entry_point(
CStr::from_bytes_with_nul_unchecked(b"main\0"),
FragInput,
FragOutput,
FragLayout(ShaderStages {
fragment: true,
..ShaderStages::none()
}),
GraphicsShaderType::Fragment,
)
}
}
}
}
pub(crate) mod fs_lighting_ambient {
use std::{borrow::Cow, sync::Arc, ffi::CStr};
use vulkano::{pipeline::shader::{ShaderInterfaceDef, ShaderInterfaceDefEntry, ShaderModule, GraphicsEntryPoint, GraphicsShaderType}, format::Format, descriptor::{descriptor::{ShaderStages, DescriptorDesc, DescriptorDescTy, DescriptorImageDescArray}, pipeline_layout::{PipelineLayoutDesc, PipelineLayoutDescPcRange}}, device::Device, OomError};
const SPIRV: &'static [u8] = &*include_bytes!("./spv_precompiles/fs_lighting_ambient.spv");
pub mod ty {
#[repr(C)]
pub struct PushConstants {
pub color: [f32; 4]
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FragInput;
unsafe impl ShaderInterfaceDef for FragInput {
type Iter = FragInputIter;
fn elements(&self) -> FragInputIter {
FragInputIter(0)
}
}
#[derive(Debug, Copy, Clone)]
pub struct FragInputIter(u16);
impl Iterator for FragInputIter {
type Item = ShaderInterfaceDefEntry;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
None
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}
impl ExactSizeIterator for FragInputIter {}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FragOutput;
unsafe impl ShaderInterfaceDef for FragOutput {
type Iter = FragOutputIter;
fn elements(&self) -> FragOutputIter {
FragOutputIter(0)
}
}
#[derive(Debug, Copy, Clone)]
pub struct FragOutputIter(u16);
impl Iterator for FragOutputIter {
type Item = ShaderInterfaceDefEntry;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.0 == 0 {
self.0 += 1;
return Some(ShaderInterfaceDefEntry {
location: 0..1,
format: Format::R32G32B32A32Sfloat,
name: Some(Cow::Borrowed("f_color")),
});
}
None
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = (1 - self.0) as usize;
(len, Some(len))
}
}
impl ExactSizeIterator for FragOutputIter {}
#[derive(Debug, Copy, Clone)]
pub struct FragLayout(ShaderStages);
unsafe impl PipelineLayoutDesc for FragLayout {
fn num_sets(&self) -> usize {
1
}
fn num_bindings_in_set(&self, _set: usize) -> Option<usize> {
Some(3)
}
fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
if set == 0 && binding == 0 {
return Some(DescriptorDesc {
ty: DescriptorDescTy::InputAttachment{
multisampled: false,
array_layers: DescriptorImageDescArray::NonArrayed,
},
array_count: 1,
stages: ShaderStages{
fragment: true,
..ShaderStages::none()
},
readonly: true
});
} else if set == 0 && binding <= 2 {
return Some(DescriptorDesc {
ty: DescriptorDescTy::InputAttachment{
multisampled: false,
array_layers: DescriptorImageDescArray::NonArrayed,
},
array_count: 1,
stages: ShaderStages{
fragment: true,
..ShaderStages::none()
},
readonly: true
});
} else {
return None;
}
}
fn num_push_constants_ranges(&self) -> usize {
1
}
fn push_constants_range(&self, _num: usize) -> Option<PipelineLayoutDescPcRange> {
Some(
PipelineLayoutDescPcRange{
offset: 0,
size: 16,
stages: ShaderStages{
fragment: true,
..ShaderStages::none()
},
}
)
}
}
pub struct Shader {
module: Arc<ShaderModule>
}
impl Shader {
pub fn load(device: Arc<Device>) -> Result<Self, OomError> {
Ok(Shader{ module: unsafe { ShaderModule::new(device.clone(), &SPIRV) }? })
}
pub fn main_entry_point(&self) -> GraphicsEntryPoint<(), FragInput, FragOutput, FragLayout> {
unsafe{
self.module.graphics_entry_point(
CStr::from_bytes_with_nul_unchecked(b"main\0"),
FragInput,
FragOutput,
FragLayout(ShaderStages {
fragment: true,
..ShaderStages::none()
}),
GraphicsShaderType::Fragment,
)
}
}
}
}