vk: pipeline layout stuff
also ringbuffer fixes
This commit is contained in:
parent
e7351207cf
commit
2baeae494d
|
@ -531,6 +531,7 @@ where
|
|||
SemanticsErrorKind::InvalidBinding(binding),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(TextureData {
|
||||
id: texture.id,
|
||||
name: &texture.name,
|
||||
|
|
|
@ -11,7 +11,7 @@ use librashader_reflect::reflect::ReflectShader;
|
|||
use librashader_reflect::reflect::semantics::{Semantic, ShaderSemantics, TextureSemantics, UniformBinding, UniformSemantic, UniqueSemantics};
|
||||
use librashader_runtime::uniforms::UniformStorage;
|
||||
use crate::error;
|
||||
use crate::filter_pass::FilterPass;
|
||||
use crate::filter_pass::{FilterPass, PipelineDescriptors};
|
||||
|
||||
pub struct Vulkan {
|
||||
physical_device: vk::PhysicalDevice,
|
||||
|
@ -134,6 +134,7 @@ impl FilterChainVulkan {
|
|||
fn init_passes(
|
||||
passes: Vec<ShaderPassMeta>,
|
||||
semantics: &ShaderSemantics,
|
||||
images: u32,
|
||||
) -> error::Result<Box<[FilterPass]>> {
|
||||
let mut filters = Vec::new();
|
||||
|
||||
|
@ -156,6 +157,7 @@ impl FilterChainVulkan {
|
|||
);
|
||||
|
||||
let mut uniform_bindings = FxHashMap::default();
|
||||
|
||||
for param in reflection.meta.parameter_meta.values() {
|
||||
uniform_bindings.insert(UniformBinding::Parameter(param.id.clone()), param.offset);
|
||||
}
|
||||
|
@ -168,6 +170,10 @@ impl FilterChainVulkan {
|
|||
uniform_bindings.insert(UniformBinding::TextureSize(*semantics), param.offset);
|
||||
}
|
||||
|
||||
let mut pipeline = PipelineDescriptors::new(images);
|
||||
pipeline.add_ubo_binding(reflection.ubo.as_ref());
|
||||
pipeline.add_texture_bindings(reflection.meta.texture_meta.values());
|
||||
// shader_vulkan 1927 (pipeline_layout)
|
||||
filters.push(FilterPass {
|
||||
compiled: spirv_words,
|
||||
uniform_storage,
|
||||
|
|
|
@ -2,8 +2,9 @@ use rustc_hash::FxHashMap;
|
|||
use librashader_preprocess::ShaderSource;
|
||||
use librashader_presets::ShaderPassConfig;
|
||||
use librashader_reflect::back::ShaderCompilerOutput;
|
||||
use librashader_reflect::reflect::semantics::{MemberOffset, UniformBinding};
|
||||
use librashader_reflect::reflect::semantics::{BindingStage, MemberOffset, TextureBinding, UboReflection, UniformBinding};
|
||||
use librashader_runtime::uniforms::UniformStorage;
|
||||
use ash::vk;
|
||||
|
||||
pub struct FilterPass {
|
||||
pub(crate) compiled: ShaderCompilerOutput<Vec<u32>>,
|
||||
|
@ -12,3 +13,70 @@ pub struct FilterPass {
|
|||
pub source: ShaderSource,
|
||||
pub config: ShaderPassConfig,
|
||||
}
|
||||
|
||||
pub struct PipelineDescriptors {
|
||||
pub replicas: u32,
|
||||
pub layout_bindings: Vec<vk::DescriptorSetLayoutBinding>,
|
||||
pub pool_sizes: Vec<vk::DescriptorPoolSize>
|
||||
}
|
||||
|
||||
impl PipelineDescriptors {
|
||||
pub fn new(duplicates: u32) -> Self {
|
||||
Self {
|
||||
replicas: duplicates,
|
||||
layout_bindings: vec![],
|
||||
pool_sizes: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_ubo_binding(&mut self, ubo_meta: Option<&UboReflection>) {
|
||||
if let Some(ubo_meta) = ubo_meta && !ubo_meta.stage_mask.is_empty() {
|
||||
let mut ubo_mask = vk::ShaderStageFlags::default();
|
||||
if ubo_meta.stage_mask.contains(BindingStage::VERTEX) {
|
||||
ubo_mask |= vk::ShaderStageFlags::VERTEX;
|
||||
}
|
||||
if ubo_meta.stage_mask.contains(BindingStage::FRAGMENT) {
|
||||
ubo_mask |= vk::ShaderStageFlags::FRAGMENT;
|
||||
}
|
||||
|
||||
self.layout_bindings.push(vk::DescriptorSetLayoutBinding {
|
||||
binding: ubo_meta.binding,
|
||||
descriptor_type: vk::DescriptorType::UNIFORM_BUFFER,
|
||||
descriptor_count: 1,
|
||||
stage_flags: ubo_mask,
|
||||
p_immutable_samplers: std::ptr::null(),
|
||||
});
|
||||
|
||||
self.pool_sizes.push(vk::DescriptorPoolSize {
|
||||
ty: vk::DescriptorType::UNIFORM_BUFFER,
|
||||
descriptor_count: self.replicas,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_texture_bindings<'a>(&mut self, textures: impl Iterator<Item = &'a TextureBinding>) {
|
||||
let mut texture_mask = vk::ShaderStageFlags::FRAGMENT;
|
||||
for texture in textures {
|
||||
self.layout_bindings.push(vk::DescriptorSetLayoutBinding {
|
||||
binding: texture.binding,
|
||||
descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER,
|
||||
descriptor_count: 1,
|
||||
stage_flags: texture_mask,
|
||||
p_immutable_samplers: std::ptr::null(),
|
||||
});
|
||||
|
||||
self.pool_sizes.push(vk::DescriptorPoolSize {
|
||||
ty: vk::DescriptorType::COMBINED_IMAGE_SAMPLER,
|
||||
descriptor_count: self.replicas,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn binding_count(&self) -> usize {
|
||||
self.layout_bindings.len()
|
||||
}
|
||||
|
||||
pub fn bindings(&self) -> &[vk::DescriptorSetLayoutBinding] {
|
||||
self.layout_bindings.as_ref()
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
#![feature(let_chains)]
|
||||
|
||||
mod hello_triangle;
|
||||
mod filter_chain;
|
||||
|
|
|
@ -79,16 +79,6 @@ impl<T> BoxRingBuffer<T>
|
|||
index: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a borrow to all the items in this ring buffer.
|
||||
pub fn items(&self) -> &[T; SIZE] {
|
||||
&self.items
|
||||
}
|
||||
|
||||
/// Get a mutable borrow to all the items in this ring buffer.
|
||||
pub fn items_mut(&mut self) -> &mut [T; SIZE] {
|
||||
&mut self.items
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -100,10 +90,12 @@ impl<T> BoxRingBuffer<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get a borrow to all the items in this ring buffer.
|
||||
pub fn items(&self) -> &[T] {
|
||||
&self.items
|
||||
}
|
||||
|
||||
/// Get a mutable borrow to all the items in this ring buffer.
|
||||
pub fn items_mut(&mut self) -> &mut [T] {
|
||||
&mut self.items
|
||||
}
|
||||
|
@ -126,7 +118,7 @@ impl<T> RingBuffer<T> for BoxRingBuffer<T> {
|
|||
|
||||
fn next(&mut self) {
|
||||
self.index += 1;
|
||||
if self.index >= SIZE {
|
||||
if self.index >= self.items.len() {
|
||||
self.index = 0
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue