Implement vkCreateDescriptorSetLayout

This commit is contained in:
msiglreith 2018-01-06 18:20:19 +01:00
parent b9d6309c67
commit 33e263cd58
3 changed files with 81 additions and 10 deletions

View file

@ -1,4 +1,4 @@
use hal::{adapter, buffer, format, image, memory, window}; use hal::{adapter, buffer, format, image, memory, pso, window};
use std::mem; use std::mem;
@ -272,6 +272,57 @@ pub fn memory_properties_from_hal(properties: memory::Properties) -> VkMemoryPro
flags flags
} }
pub fn map_descriptor_type(ty: VkDescriptorType) -> pso::DescriptorType {
use super::VkDescriptorType::*;
match ty {
VK_DESCRIPTOR_TYPE_SAMPLER => pso::DescriptorType::Sampler,
VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE => pso::DescriptorType::SampledImage,
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE => pso::DescriptorType::StorageImage,
VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER => pso::DescriptorType::UniformTexelBuffer,
VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER => pso::DescriptorType::StorageTexelBuffer,
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER => pso::DescriptorType::UniformBuffer,
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER => pso::DescriptorType::StorageBuffer,
VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT => pso::DescriptorType::InputAttachment,
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER |
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC |
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC => unimplemented!(),
_ => panic!("Unexpected descriptor type: {:?}", ty),
}
}
pub fn map_stage_flags(stages: VkShaderStageFlags) -> pso::ShaderStageFlags {
let mut flags = pso::ShaderStageFlags::empty();
if stages & VkShaderStageFlagBits::VK_SHADER_STAGE_VERTEX_BIT as u32 != 0 {
flags |= pso::ShaderStageFlags::VERTEX;
}
if stages & VkShaderStageFlagBits::VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT as u32 != 0 {
flags |= pso::ShaderStageFlags::HULL;
}
if stages & VkShaderStageFlagBits::VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT as u32 != 0 {
flags |= pso::ShaderStageFlags::DOMAIN;
}
if stages & VkShaderStageFlagBits::VK_SHADER_STAGE_GEOMETRY_BIT as u32 != 0 {
flags |= pso::ShaderStageFlags::GEOMETRY;
}
if stages & VkShaderStageFlagBits::VK_SHADER_STAGE_FRAGMENT_BIT as u32 != 0 {
flags |= pso::ShaderStageFlags::FRAGMENT;
}
if stages & VkShaderStageFlagBits::VK_SHADER_STAGE_COMPUTE_BIT as u32 != 0 {
flags |= pso::ShaderStageFlags::COMPUTE;
}
if stages & VkShaderStageFlagBits::VK_SHADER_STAGE_ALL_GRAPHICS as u32 != 0 {
flags |= pso::ShaderStageFlags::GRAPHICS;
}
if stages & VkShaderStageFlagBits::VK_SHADER_STAGE_ALL as u32 != 0 {
flags |= pso::ShaderStageFlags::ALL;
}
flags
}
pub fn map_err_device_creation(err: adapter::DeviceCreationError) -> VkResult { pub fn map_err_device_creation(err: adapter::DeviceCreationError) -> VkResult {
use hal::adapter::DeviceCreationError::*; use hal::adapter::DeviceCreationError::*;

View file

@ -1,3 +1,4 @@
use hal::pso;
use hal::{Device, Instance, PhysicalDevice, QueueFamily, Surface}; use hal::{Device, Instance, PhysicalDevice, QueueFamily, Surface};
use std::ffi::CString; use std::ffi::CString;
@ -904,12 +905,36 @@ pub extern "C" fn gfxDestroySampler(
} }
#[inline] #[inline]
pub extern "C" fn gfxCreateDescriptorSetLayout( pub extern "C" fn gfxCreateDescriptorSetLayout(
device: VkDevice, gpu: VkDevice,
pCreateInfo: *const VkDescriptorSetLayoutCreateInfo, pCreateInfo: *const VkDescriptorSetLayoutCreateInfo,
pAllocator: *const VkAllocationCallbacks, _pAllocator: *const VkAllocationCallbacks,
pSetLayout: *mut VkDescriptorSetLayout, pSetLayout: *mut VkDescriptorSetLayout,
) -> VkResult { ) -> VkResult {
unimplemented!() let info = unsafe { &*pCreateInfo };
let layout_bindings = unsafe {
slice::from_raw_parts(info.pBindings, info.bindingCount as _)
};
let bindings = layout_bindings
.iter()
.map(|binding| {
assert!(binding.pImmutableSamplers.is_null()); // TODO
pso::DescriptorSetLayoutBinding {
binding: binding.binding as _,
ty: conv::map_descriptor_type(binding.descriptorType),
count: binding.descriptorCount as _,
stage_flags: conv::map_stage_flags(binding.stageFlags),
}
})
.collect::<Vec<_>>();
let set_layout = gpu.device
.create_descriptor_set_layout(&bindings);
unsafe { *pSetLayout = Handle::new(set_layout); }
VkResult::VK_SUCCESS
} }
#[inline] #[inline]
pub extern "C" fn gfxDestroyDescriptorSetLayout( pub extern "C" fn gfxDestroyDescriptorSetLayout(

View file

@ -30,6 +30,7 @@ pub type VkDevice = Handle<hal::Gpu<B>>;
pub type VkCommandPool = Handle<<B as hal::Backend>::CommandPool>; pub type VkCommandPool = Handle<<B as hal::Backend>::CommandPool>;
pub type VkCommandBuffer = Handle<<B as hal::Backend>::CommandBuffer>; pub type VkCommandBuffer = Handle<<B as hal::Backend>::CommandBuffer>;
pub type VkDeviceMemory = Handle<<B as hal::Backend>::Memory>; pub type VkDeviceMemory = Handle<<B as hal::Backend>::Memory>;
pub type VkDescriptorSetLayout = Handle<<B as hal::Backend>::DescriptorSetLayout>;
pub enum Image<B: hal::Backend> { pub enum Image<B: hal::Backend> {
Image(B::Image), Image(B::Image),
@ -572,12 +573,6 @@ pub struct VkPipeline_T {
pub type VkPipeline = *mut VkPipeline_T; pub type VkPipeline = *mut VkPipeline_T;
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct VkDescriptorSetLayout_T {
_unused: [u8; 0],
}
pub type VkDescriptorSetLayout = *mut VkDescriptorSetLayout_T;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct VkSampler_T { pub struct VkSampler_T {
_unused: [u8; 0], _unused: [u8; 0],
} }