vulkan: use descriptor buffers if available
This commit is contained in:
parent
a45ae2ba03
commit
a1c5c05e36
10 changed files with 476 additions and 59 deletions
|
|
@ -1,8 +1,9 @@
|
|||
use {
|
||||
crate::gfx_apis::vulkan::{device::VulkanDevice, sampler::VulkanSampler, VulkanError},
|
||||
arrayvec::ArrayVec,
|
||||
ash::vk::{
|
||||
DescriptorSetLayout, DescriptorSetLayoutBinding, DescriptorSetLayoutCreateFlags,
|
||||
DescriptorSetLayoutCreateInfo, DescriptorType, ShaderStageFlags,
|
||||
DescriptorSetLayoutCreateInfo, DescriptorType, DeviceSize, ShaderStageFlags,
|
||||
},
|
||||
std::{rc::Rc, slice},
|
||||
};
|
||||
|
|
@ -10,7 +11,10 @@ use {
|
|||
pub(super) struct VulkanDescriptorSetLayout {
|
||||
pub(super) device: Rc<VulkanDevice>,
|
||||
pub(super) layout: DescriptorSetLayout,
|
||||
pub(super) _sampler: Rc<VulkanSampler>,
|
||||
pub(super) size: DeviceSize,
|
||||
pub(super) offsets: ArrayVec<DeviceSize, 1>,
|
||||
pub(super) _sampler: Option<Rc<VulkanSampler>>,
|
||||
pub(super) has_sampler: bool,
|
||||
}
|
||||
|
||||
impl Drop for VulkanDescriptorSetLayout {
|
||||
|
|
@ -25,7 +29,7 @@ impl Drop for VulkanDescriptorSetLayout {
|
|||
|
||||
impl VulkanDevice {
|
||||
pub(super) fn create_descriptor_set_layout(
|
||||
&self,
|
||||
self: &Rc<Self>,
|
||||
sampler: &Rc<VulkanSampler>,
|
||||
) -> Result<Rc<VulkanDescriptorSetLayout>, VulkanError> {
|
||||
let immutable_sampler = [sampler.sampler];
|
||||
|
|
@ -34,15 +38,34 @@ impl VulkanDevice {
|
|||
.immutable_samplers(&immutable_sampler)
|
||||
.descriptor_count(1)
|
||||
.descriptor_type(DescriptorType::COMBINED_IMAGE_SAMPLER);
|
||||
let mut flags = DescriptorSetLayoutCreateFlags::empty();
|
||||
if self.descriptor_buffer.is_some() {
|
||||
flags |= DescriptorSetLayoutCreateFlags::DESCRIPTOR_BUFFER_EXT;
|
||||
} else {
|
||||
flags |= DescriptorSetLayoutCreateFlags::PUSH_DESCRIPTOR_KHR;
|
||||
}
|
||||
let create_info = DescriptorSetLayoutCreateInfo::default()
|
||||
.bindings(slice::from_ref(&binding))
|
||||
.flags(DescriptorSetLayoutCreateFlags::PUSH_DESCRIPTOR_KHR);
|
||||
.flags(flags);
|
||||
let layout = unsafe { self.device.create_descriptor_set_layout(&create_info, None) };
|
||||
let layout = layout.map_err(VulkanError::CreateDescriptorSetLayout)?;
|
||||
let mut size = 0;
|
||||
let mut offsets = ArrayVec::new();
|
||||
if let Some(db) = &self.descriptor_buffer {
|
||||
size = unsafe { db.get_descriptor_set_layout_size(layout) };
|
||||
size =
|
||||
(size + self.descriptor_buffer_offset_mask) & !self.descriptor_buffer_offset_mask;
|
||||
unsafe {
|
||||
offsets.push(db.get_descriptor_set_layout_binding_offset(layout, 0));
|
||||
}
|
||||
}
|
||||
Ok(Rc::new(VulkanDescriptorSetLayout {
|
||||
device: sampler.device.clone(),
|
||||
device: self.clone(),
|
||||
layout,
|
||||
_sampler: sampler.clone(),
|
||||
size,
|
||||
offsets,
|
||||
_sampler: Some(sampler.clone()),
|
||||
has_sampler: true,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue