37: HAL update for descriptor sets r=msiglreith a=kvark
This commit is contained in:
bors[bot] 2018-02-28 16:39:41 +00:00
commit 9cc6abe45f
3 changed files with 177 additions and 115 deletions

View file

@ -17,14 +17,14 @@ log = "0.4"
[dependencies.gfx-hal] [dependencies.gfx-hal]
git = "https://github.com/gfx-rs/gfx" git = "https://github.com/gfx-rs/gfx"
rev = "14a0d6c0976cdbc882a6f63bced18a9b2bf13f5f" rev = "070e0cee47ae6f0c395a3402fd6f889c1315ef3e"
[dependencies.gfx-backend-vulkan] [dependencies.gfx-backend-vulkan]
git = "https://github.com/gfx-rs/gfx" git = "https://github.com/gfx-rs/gfx"
rev = "14a0d6c0976cdbc882a6f63bced18a9b2bf13f5f" rev = "070e0cee47ae6f0c395a3402fd6f889c1315ef3e"
optional = true optional = true
[target.'cfg(windows)'.dependencies.gfx-backend-dx12] [target.'cfg(windows)'.dependencies.gfx-backend-dx12]
git = "https://github.com/gfx-rs/gfx" git = "https://github.com/gfx-rs/gfx"
rev = "14a0d6c0976cdbc882a6f63bced18a9b2bf13f5f" rev = "070e0cee47ae6f0c395a3402fd6f889c1315ef3e"
optional = true optional = true

View file

@ -83,7 +83,7 @@ pub fn map_format(format: VkFormat) -> Option<format::Format> {
} }
} }
pub fn extent2d_from_hal(extent: window::Extent2d) -> VkExtent2D { pub fn extent2d_from_hal(extent: window::Extent2D) -> VkExtent2D {
VkExtent2D { VkExtent2D {
width: extent.width, width: extent.width,
height: extent.height, height: extent.height,
@ -136,16 +136,16 @@ pub fn map_subresource_range(subresource: VkImageSubresourceRange) -> image::Sub
} }
} }
fn map_aspect(aspects: VkImageAspectFlags) -> format::AspectFlags { fn map_aspect(aspects: VkImageAspectFlags) -> format::Aspects {
let mut flags = format::AspectFlags::empty(); let mut flags = format::Aspects::empty();
if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_COLOR_BIT as u32 != 0 { if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_COLOR_BIT as u32 != 0 {
flags |= format::AspectFlags::COLOR; flags |= format::Aspects::COLOR;
} }
if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_DEPTH_BIT as u32 != 0 { if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_DEPTH_BIT as u32 != 0 {
flags |= format::AspectFlags::DEPTH; flags |= format::Aspects::DEPTH;
} }
if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_STENCIL_BIT as u32 != 0 { if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_STENCIL_BIT as u32 != 0 {
flags |= format::AspectFlags::DEPTH; flags |= format::Aspects::DEPTH;
} }
if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_METADATA_BIT as u32 != 0 { if aspects & VkImageAspectFlagBits::VK_IMAGE_ASPECT_METADATA_BIT as u32 != 0 {
unimplemented!() unimplemented!()
@ -595,8 +595,8 @@ pub fn map_wrap_mode(mode: VkSamplerAddressMode) -> image::WrapMode {
} }
} }
pub fn map_offset(extent: VkOffset3D) -> command::Offset { pub fn map_offset(extent: VkOffset3D) -> image::Offset {
command::Offset { image::Offset {
x: extent.x, x: extent.x,
y: extent.y, y: extent.y,
z: extent.z, z: extent.z,

View file

@ -134,7 +134,7 @@ pub extern "C" fn gfxGetPhysicalDeviceFeatures(
adapter: VkPhysicalDevice, adapter: VkPhysicalDevice,
pFeatures: *mut VkPhysicalDeviceFeatures, pFeatures: *mut VkPhysicalDeviceFeatures,
) { ) {
let features = adapter.physical_device.get_features(); let features = adapter.physical_device.features();
// TODO: fill in information // TODO: fill in information
} }
@ -167,7 +167,7 @@ pub extern "C" fn gfxGetPhysicalDeviceProperties(
pProperties: *mut VkPhysicalDeviceProperties, pProperties: *mut VkPhysicalDeviceProperties,
) { ) {
let adapter_info = &adapter.info; let adapter_info = &adapter.info;
let limits = adapter.physical_device.get_limits(); let limits = adapter.physical_device.limits();
let (major, minor, patch) = VERSION; let (major, minor, patch) = VERSION;
let device_name = { let device_name = {
@ -1741,15 +1741,23 @@ pub extern "C" fn gfxUpdateDescriptorSets(
descriptorCopyCount: u32, descriptorCopyCount: u32,
pDescriptorCopies: *const VkCopyDescriptorSet, pDescriptorCopies: *const VkCopyDescriptorSet,
) { ) {
assert_eq!(descriptorCopyCount, 0); // TODO //TODO: use `SmallVec` aggressively
let writes = unsafe { //TEMP: find a cleaner and faster way to provide those
// currently we have to allocate vectors and `transmute` lifetimes :()
// yeah, this is super crappy, and not crabby at all
let mut samplers = Vec::new();
let mut images = Vec::new();
let mut texel_buffers = Vec::new();
let mut buffers = Vec::new();
let mut combined_image_samplers = Vec::new();
let mut writes: Vec<pso::DescriptorSetWrite<B, Range<_>>> = Vec::new();
let write_infos = unsafe {
slice::from_raw_parts(pDescriptorWrites, descriptorWriteCount as _) slice::from_raw_parts(pDescriptorWrites, descriptorWriteCount as _)
}; };
let writes = writes for write in write_infos {
.iter()
.map(|write| {
fn map_buffer_info(buffer_info: &[VkDescriptorBufferInfo]) -> Vec<(&<B as Backend>::Buffer, Range<u64>)> { fn map_buffer_info(buffer_info: &[VkDescriptorBufferInfo]) -> Vec<(&<B as Backend>::Buffer, Range<u64>)> {
buffer_info buffer_info
.into_iter() .into_iter()
@ -1780,70 +1788,102 @@ pub extern "C" fn gfxUpdateDescriptorSets(
let ty = conv::map_descriptor_type(write.descriptorType); let ty = conv::map_descriptor_type(write.descriptorType);
let desc_write = match ty { let desc_write = match ty {
pso::DescriptorType::Sampler => pso::DescriptorWrite::Sampler( pso::DescriptorType::Sampler => {
image_info samplers.push(image_info
.into_iter() .into_iter()
.map(|image| &*image.sampler) .map(|image| &*image.sampler)
.collect() .collect::<Vec<_>>()
), );
pso::DescriptorType::SampledImage => pso::DescriptorWrite::SampledImage( pso::DescriptorWrite::Sampler(unsafe { mem::transmute(samplers.last().unwrap().as_slice()) })
image_info }
pso::DescriptorType::SampledImage => {
images.push(image_info
.into_iter() .into_iter()
.map(|image| (&*image.imageView, conv::map_image_layout(image.imageLayout))) .map(|image| (&*image.imageView, conv::map_image_layout(image.imageLayout)))
.collect() .collect::<Vec<_>>()
), );
pso::DescriptorType::StorageImage => pso::DescriptorWrite::StorageImage( pso::DescriptorWrite::SampledImage(unsafe { mem::transmute(images.last().unwrap().as_slice()) })
image_info }
pso::DescriptorType::StorageImage => {
images.push(image_info
.into_iter() .into_iter()
.map(|image| (&*image.imageView, conv::map_image_layout(image.imageLayout))) .map(|image| (&*image.imageView, conv::map_image_layout(image.imageLayout)))
.collect() .collect::<Vec<_>>()
), );
pso::DescriptorType::UniformTexelBuffer => pso::DescriptorWrite::UniformTexelBuffer( pso::DescriptorWrite::StorageImage(unsafe { mem::transmute(images.last().unwrap().as_slice()) })
texel_buffer_views }
pso::DescriptorType::UniformTexelBuffer => {
texel_buffers.push(texel_buffer_views
.into_iter() .into_iter()
.map(|view| &**view) .map(|view| &**view)
.collect() .collect::<Vec<_>>()
), );
pso::DescriptorType::StorageTexelBuffer => pso::DescriptorWrite::StorageTexelBuffer( pso::DescriptorWrite::UniformTexelBuffer(unsafe { mem::transmute(texel_buffers.last().unwrap().as_slice()) })
texel_buffer_views }
pso::DescriptorType::StorageTexelBuffer => {
texel_buffers.push(texel_buffer_views
.into_iter() .into_iter()
.map(|view| &**view) .map(|view| &**view)
.collect() .collect::<Vec<_>>()
), );
pso::DescriptorType::UniformBuffer => pso::DescriptorWrite::UniformBuffer( pso::DescriptorWrite::StorageTexelBuffer(unsafe { mem::transmute(texel_buffers.last().unwrap().as_slice()) })
map_buffer_info(buffer_info) }
), pso::DescriptorType::UniformBuffer => {
pso::DescriptorType::StorageBuffer => pso::DescriptorWrite::StorageBuffer( buffers.push(map_buffer_info(buffer_info));
map_buffer_info(buffer_info) pso::DescriptorWrite::UniformBuffer(unsafe { mem::transmute(buffers.last().unwrap().as_slice()) })
), }
pso::DescriptorType::InputAttachment => pso::DescriptorWrite::InputAttachment( pso::DescriptorType::StorageBuffer => {
image_info buffers.push(map_buffer_info(buffer_info));
pso::DescriptorWrite::StorageBuffer(unsafe { mem::transmute(buffers.last().unwrap().as_slice()) })
}
pso::DescriptorType::InputAttachment => {
images.push(image_info
.into_iter() .into_iter()
.map(|image| (&*image.imageView, conv::map_image_layout(image.imageLayout))) .map(|image| (&*image.imageView, conv::map_image_layout(image.imageLayout)))
.collect() .collect::<Vec<_>>()
), );
pso::DescriptorType::CombinedImageSampler => pso::DescriptorWrite::CombinedImageSampler( pso::DescriptorWrite::InputAttachment(unsafe { mem::transmute(images.last().unwrap().as_slice()) })
image_info }
pso::DescriptorType::CombinedImageSampler => {
combined_image_samplers.push(image_info
.into_iter() .into_iter()
.map(|image| ( .map(|image| (
&*image.sampler, &*image.sampler,
&*image.imageView, &*image.imageView,
conv::map_image_layout(image.imageLayout), conv::map_image_layout(image.imageLayout),
)) ))
.collect() .collect::<Vec<_>>()
), );
pso::DescriptorWrite::CombinedImageSampler(unsafe { mem::transmute(combined_image_samplers.last().unwrap().as_slice()) })
}
}; };
pso::DescriptorSetWrite { writes.push(pso::DescriptorSetWrite {
set: &*write.dstSet, set: &*write.dstSet,
binding: write.dstBinding as _, binding: write.dstBinding as _,
array_offset: write.dstArrayElement as _, array_offset: write.dstArrayElement as _,
write: desc_write, write: desc_write,
});
} }
})
.collect::<Vec<_>>();
gpu.device.update_descriptor_sets(&writes); let copies = unsafe {
slice::from_raw_parts(pDescriptorCopies, descriptorCopyCount as _)
}
.iter()
.map(|copy| {
pso::DescriptorSetCopy {
src_set: &*copy.srcSet,
src_binding: copy.srcBinding as _,
src_array_offset: copy.srcArrayElement as _,
dst_set: &*copy.dstSet,
dst_binding: copy.dstBinding as _,
dst_array_offset: copy.dstArrayElement as _,
count: copy.descriptorCount as _,
}
});
gpu.device.write_descriptor_sets(writes);
gpu.device.copy_descriptor_sets(copies);
} }
#[inline] #[inline]
pub extern "C" fn gfxCreateFramebuffer( pub extern "C" fn gfxCreateFramebuffer(
@ -2056,7 +2096,7 @@ pub extern "C" fn gfxDestroyRenderPass(
renderPass: VkRenderPass, renderPass: VkRenderPass,
_pAllocator: *const VkAllocationCallbacks, _pAllocator: *const VkAllocationCallbacks,
) { ) {
gpu.device.destroy_renderpass(*renderPass.unwrap()); gpu.device.destroy_render_pass(*renderPass.unwrap());
} }
#[inline] #[inline]
pub extern "C" fn gfxGetRenderAreaGranularity( pub extern "C" fn gfxGetRenderAreaGranularity(
@ -2633,14 +2673,34 @@ pub extern "C" fn gfxCmdPipelineBarrier(
mut commandBuffer: VkCommandBuffer, mut commandBuffer: VkCommandBuffer,
srcStageMask: VkPipelineStageFlags, srcStageMask: VkPipelineStageFlags,
dstStageMask: VkPipelineStageFlags, dstStageMask: VkPipelineStageFlags,
_dependencyFlags: VkDependencyFlags, dependencyFlags: VkDependencyFlags,
_memoryBarrierCount: u32, memoryBarrierCount: u32,
_pMemoryBarriers: *const VkMemoryBarrier, pMemoryBarriers: *const VkMemoryBarrier,
bufferMemoryBarrierCount: u32, bufferMemoryBarrierCount: u32,
pBufferMemoryBarriers: *const VkBufferMemoryBarrier, pBufferMemoryBarriers: *const VkBufferMemoryBarrier,
imageMemoryBarrierCount: u32, imageMemoryBarrierCount: u32,
pImageMemoryBarriers: *const VkImageMemoryBarrier, pImageMemoryBarriers: *const VkImageMemoryBarrier,
) { ) {
let global_barriers = unsafe {
slice::from_raw_parts(pMemoryBarriers, memoryBarrierCount as _)
}
.iter()
.flat_map(|b| {
let buf = conv::map_buffer_access(b.srcAccessMask) .. conv::map_buffer_access(b.dstAccessMask);
let buf_bar = if !buf.start.is_empty() || !buf.end.is_empty() {
Some(memory::Barrier::AllBuffers(buf))
} else {
None
};
let img = conv::map_image_access(b.srcAccessMask) .. conv::map_image_access(b.dstAccessMask);
let img_bar = if !img.start.is_empty() || !img.end.is_empty() {
Some(memory::Barrier::AllImages(img))
} else {
None
};
buf_bar.into_iter().chain(img_bar)
});
let buffer_barriers = unsafe { let buffer_barriers = unsafe {
slice::from_raw_parts(pBufferMemoryBarriers, bufferMemoryBarrierCount as _) slice::from_raw_parts(pBufferMemoryBarriers, bufferMemoryBarrierCount as _)
} }
@ -2652,6 +2712,7 @@ pub extern "C" fn gfxCmdPipelineBarrier(
Buffer::Unbound(_) => panic!("Bound buffer is needed here!"), Buffer::Unbound(_) => panic!("Bound buffer is needed here!"),
}, },
}); });
let image_barriers = unsafe { let image_barriers = unsafe {
slice::from_raw_parts(pImageMemoryBarriers, imageMemoryBarrierCount as _) slice::from_raw_parts(pImageMemoryBarriers, imageMemoryBarrierCount as _)
} }
@ -2669,7 +2730,8 @@ pub extern "C" fn gfxCmdPipelineBarrier(
commandBuffer.pipeline_barrier( commandBuffer.pipeline_barrier(
conv::map_pipeline_stage_flags(srcStageMask) .. conv::map_pipeline_stage_flags(dstStageMask), conv::map_pipeline_stage_flags(srcStageMask) .. conv::map_pipeline_stage_flags(dstStageMask),
buffer_barriers.chain(image_barriers), memory::Dependencies::from_bits(dependencyFlags as _).unwrap_or(memory::Dependencies::empty()),
global_barriers.chain(buffer_barriers).chain(image_barriers),
); );
} }
#[inline] #[inline]
@ -2755,7 +2817,7 @@ pub extern "C" fn gfxCmdBeginRenderPass(
}; };
let contents = conv::map_subpass_contents(contents); let contents = conv::map_subpass_contents(contents);
commandBuffer.begin_renderpass_raw( commandBuffer.begin_render_pass_raw(
&*info.renderPass, &*info.renderPass,
&*info.framebuffer, &*info.framebuffer,
render_area, render_area,
@ -2769,7 +2831,7 @@ pub extern "C" fn gfxCmdNextSubpass(commandBuffer: VkCommandBuffer, contents: Vk
} }
#[inline] #[inline]
pub extern "C" fn gfxCmdEndRenderPass(mut commandBuffer: VkCommandBuffer) { pub extern "C" fn gfxCmdEndRenderPass(mut commandBuffer: VkCommandBuffer) {
commandBuffer.end_renderpass(); commandBuffer.end_render_pass();
} }
#[inline] #[inline]
pub extern "C" fn gfxCmdExecuteCommands( pub extern "C" fn gfxCmdExecuteCommands(