Refine more lifetimes

This commit is contained in:
hodasemi 2024-03-29 08:43:44 +01:00
parent c9b4dfc164
commit 913d25cd82
11 changed files with 328 additions and 387 deletions

View file

@ -37,9 +37,9 @@ pub struct AccelerationStructureBuilder {
} }
impl AccelerationStructureBuilder { impl AccelerationStructureBuilder {
pub fn add_instance<'a>( pub fn add_instance<'device>(
mut self, mut self,
blas: &AccelerationStructure<'a>, blas: &AccelerationStructure<'device>,
transform: Option<Matrix4<f32>>, transform: Option<Matrix4<f32>>,
instance_flags: impl Into<VkGeometryInstanceFlagBitsKHR>, instance_flags: impl Into<VkGeometryInstanceFlagBitsKHR>,
) -> Self { ) -> Self {
@ -122,11 +122,11 @@ impl AccelerationStructureBuilder {
self self
} }
pub fn build<'a>( pub fn build<'device, 'pipeline, 'cbuffer>(
self, self,
device: &'a Device, device: &'device Device,
recorder: &mut CommandBufferRecorder<'_, '_>, recorder: &mut CommandBufferRecorder<'device, 'pipeline, 'cbuffer>,
) -> Result<AccelerationStructure<'a>> { ) -> Result<AccelerationStructure<'device>> {
let build_flags = VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR let build_flags = VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR
| VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR; | VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR;
@ -270,21 +270,21 @@ impl AccelerationStructureBuilder {
} }
} }
pub struct AccelerationStructure<'a> { pub struct AccelerationStructure<'device> {
device: &'a Device, device: &'device Device,
acceleration_structure: VkAccelerationStructureKHR, acceleration_structure: VkAccelerationStructureKHR,
result_buffer: Buffer<'a, RawBuffer>, result_buffer: Buffer<'device, RawBuffer>,
scratch_buffer: Mutex<Buffer<'a, RawBuffer>>, scratch_buffer: Mutex<Buffer<'device, RawBuffer>>,
update_scratch_buffer_size: VkDeviceSize, update_scratch_buffer_size: VkDeviceSize,
generation_data: AccelerationStructureGenerationData<'a>, generation_data: AccelerationStructureGenerationData<'device>,
build_flags: VkBuildAccelerationStructureFlagBitsKHR, build_flags: VkBuildAccelerationStructureFlagBitsKHR,
} }
impl<'a> AccelerationStructure<'a> { impl<'device> AccelerationStructure<'device> {
pub fn bottom_level() -> AccelerationStructureBuilder { pub fn bottom_level() -> AccelerationStructureBuilder {
AccelerationStructureBuilder { AccelerationStructureBuilder {
flags: 0.into(), flags: 0.into(),
@ -303,7 +303,7 @@ impl<'a> AccelerationStructure<'a> {
} }
} }
pub fn result_buffer(&self) -> &Buffer<'a, RawBuffer> { pub fn result_buffer(&self) -> &Buffer<'device, RawBuffer> {
&self.result_buffer &self.result_buffer
} }
@ -313,7 +313,10 @@ impl<'a> AccelerationStructure<'a> {
) )
} }
pub fn update(&self, buffer_recorder: &mut CommandBufferRecorder<'_, '_>) -> Result<()> { pub fn update<'pipeline, 'cbuffer>(
&self,
buffer_recorder: &mut CommandBufferRecorder<'device, 'pipeline, 'cbuffer>,
) -> Result<()> {
*self.scratch_buffer.lock().unwrap() = Self::create_scratch_buffer( *self.scratch_buffer.lock().unwrap() = Self::create_scratch_buffer(
&self.device, &self.device,
self.update_scratch_buffer_size, self.update_scratch_buffer_size,
@ -330,9 +333,9 @@ impl<'a> AccelerationStructure<'a> {
) )
} }
fn generate( fn generate<'pipeline, 'cbuffer>(
&self, &self,
buffer_recorder: &mut CommandBufferRecorder<'_, '_>, buffer_recorder: &mut CommandBufferRecorder<'device, 'pipeline, 'cbuffer>,
src: VkAccelerationStructureKHR, src: VkAccelerationStructureKHR,
mode: VkBuildAccelerationStructureModeKHR, mode: VkBuildAccelerationStructureModeKHR,
) -> Result<()> { ) -> Result<()> {
@ -390,10 +393,10 @@ impl<'a> AccelerationStructure<'a> {
#[inline] #[inline]
fn create_scratch_buffer( fn create_scratch_buffer(
device: &'a Device, device: &'device Device,
size: VkDeviceSize, size: VkDeviceSize,
alignment: VkDeviceSize, alignment: VkDeviceSize,
) -> Result<Buffer<'a, RawBuffer>> { ) -> Result<Buffer<'device, RawBuffer>> {
Buffer::builder() Buffer::builder()
.set_usage( .set_usage(
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
@ -418,11 +421,11 @@ impl_vk_handle!(
acceleration_structure acceleration_structure
); );
enum AccelerationStructureGenerationData<'a> { enum AccelerationStructureGenerationData<'device> {
TopLevel( TopLevel(
Vec<VkAccelerationStructureInstanceKHR>, Vec<VkAccelerationStructureInstanceKHR>,
VkAccelerationStructureGeometryKHR, VkAccelerationStructureGeometryKHR,
Buffer<'a, VkAccelerationStructureInstanceKHR>, Buffer<'device, VkAccelerationStructureInstanceKHR>,
), ),
BottomLevel( BottomLevel(
Vec<VkAccelerationStructureGeometryKHR>, Vec<VkAccelerationStructureGeometryKHR>,
@ -430,26 +433,26 @@ enum AccelerationStructureGenerationData<'a> {
), ),
} }
impl<'a> impl<'device>
From<( From<(
Vec<VkAccelerationStructureInstanceKHR>, Vec<VkAccelerationStructureInstanceKHR>,
VkAccelerationStructureGeometryKHR, VkAccelerationStructureGeometryKHR,
Buffer<'a, VkAccelerationStructureInstanceKHR>, Buffer<'device, VkAccelerationStructureInstanceKHR>,
)> for AccelerationStructureGenerationData<'a> )> for AccelerationStructureGenerationData<'device>
{ {
fn from( fn from(
(instances, geometry, buffer): ( (instances, geometry, buffer): (
Vec<VkAccelerationStructureInstanceKHR>, Vec<VkAccelerationStructureInstanceKHR>,
VkAccelerationStructureGeometryKHR, VkAccelerationStructureGeometryKHR,
Buffer<'a, VkAccelerationStructureInstanceKHR>, Buffer<'device, VkAccelerationStructureInstanceKHR>,
), ),
) -> Self { ) -> Self {
Self::TopLevel(instances, geometry, buffer) Self::TopLevel(instances, geometry, buffer)
} }
} }
impl<'a> From<(Vec<VkAccelerationStructureGeometryKHR>, Vec<u32>)> impl<'device> From<(Vec<VkAccelerationStructureGeometryKHR>, Vec<u32>)>
for AccelerationStructureGenerationData<'a> for AccelerationStructureGenerationData<'device>
{ {
fn from( fn from(
(geometries, primitive_counts): (Vec<VkAccelerationStructureGeometryKHR>, Vec<u32>), (geometries, primitive_counts): (Vec<VkAccelerationStructureGeometryKHR>, Vec<u32>),

View file

@ -121,11 +121,11 @@ impl<'a, T: ReprC + Clone + Send + Sync + 'static> BufferBuilder<'a, T> {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct Buffer<'a, T: ReprC> { pub struct Buffer<'device, T: ReprC> {
device: &'a Device, device: &'device Device,
buffer: VkBuffer, buffer: VkBuffer,
memory: Memory<'a, T>, memory: Memory<'device, T>,
_usage: VkBufferUsageFlagBits, _usage: VkBufferUsageFlagBits,
@ -133,7 +133,7 @@ pub struct Buffer<'a, T: ReprC> {
size: VkDeviceSize, size: VkDeviceSize,
} }
impl<'a, T: ReprC + Clone + Send + Sync + 'static> Buffer<'a, T> { impl<'device, T: ReprC + Clone + Send + Sync + 'static> Buffer<'device, T> {
pub fn fill(&self, data: &[T]) -> Result<()> { pub fn fill(&self, data: &[T]) -> Result<()> {
let mut buffer_map = self.map(data.len() as VkDeviceSize)?; let mut buffer_map = self.map(data.len() as VkDeviceSize)?;
@ -150,13 +150,13 @@ impl<'a, T: ReprC + Clone + Send + Sync + 'static> Buffer<'a, T> {
self.memory.map(self.size) self.memory.map(self.size)
} }
pub fn into_device_local<'b>( pub fn into_device_local<'pipeline, 'cbuffer>(
&self, &self,
buffer_recorder: &mut CommandBufferRecorder<'a, 'b>, buffer_recorder: &mut CommandBufferRecorder<'device, 'pipeline, 'cbuffer>,
access_mask: impl Into<VkAccessFlagBits>, access_mask: impl Into<VkAccessFlagBits>,
stage: impl Into<VkPipelineStageFlagBits>, stage: impl Into<VkPipelineStageFlagBits>,
usage: impl Into<VkBufferUsageFlagBits>, usage: impl Into<VkBufferUsageFlagBits>,
) -> Result<Buffer<'a, T>> { ) -> Result<Buffer<'device, T>> {
let new_usage = usage.into() | VK_BUFFER_USAGE_TRANSFER_DST_BIT; let new_usage = usage.into() | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
let device_local_buffer = Buffer::builder() let device_local_buffer = Buffer::builder()

View file

@ -6,7 +6,6 @@ use crate::prelude::*;
use anyhow::Result; use anyhow::Result;
use std::any::Any;
use std::sync::Mutex; use std::sync::Mutex;
pub struct QueryEnable { pub struct QueryEnable {
@ -53,36 +52,33 @@ impl CommandBufferBuilder {
buffer: command_buffer, buffer: command_buffer,
calls: 0, calls: 0,
stored_handles: Vec::new(),
}) })
} }
} }
#[derive(Debug)] #[derive(Debug)]
pub struct CommandBuffer<'a> { pub struct CommandBuffer<'device> {
device: &'a Device, device: &'device Device,
pool: CommandPool<'a>, pool: CommandPool<'device>,
buffer: VkCommandBuffer, buffer: VkCommandBuffer,
calls: usize, calls: usize,
stored_handles: Vec<&'a (dyn Any + Send + Sync)>,
} }
#[derive(Debug)] #[derive(Debug)]
pub struct CommandBufferRecorder<'a, 'b> { pub struct CommandBufferRecorder<'device, 'pipeline, 'cbuffer> {
device: &'a Device, device: &'device Device,
sub_pass: u32, sub_pass: u32,
pipeline: Option<&'a Pipeline<'a>>, pipeline: Option<&'pipeline Pipeline<'device>>,
calls: &'b mut usize, calls: &'cbuffer mut usize,
buffer: VkCommandBuffer, buffer: VkCommandBuffer,
handles_lock: &'b mut Vec<&'a (dyn Any + Send + Sync)>,
} }
impl_vk_handle!(CommandBuffer<'a>, VkCommandBuffer, buffer); impl_vk_handle!(CommandBuffer<'a>, VkCommandBuffer, buffer);
impl<'a> CommandBuffer<'a> { impl<'device> CommandBuffer<'device> {
pub fn new_primary() -> CommandBufferBuilder { pub fn new_primary() -> CommandBufferBuilder {
CommandBufferBuilder { CommandBufferBuilder {
buffer_level: VK_COMMAND_BUFFER_LEVEL_PRIMARY, buffer_level: VK_COMMAND_BUFFER_LEVEL_PRIMARY,
@ -105,17 +101,12 @@ impl<'a> CommandBuffer<'a> {
self.calls self.calls
} }
pub fn begin<'b>( pub fn begin<'pipeline, 'cbuffer>(
&'a mut self, &'cbuffer mut self,
begin_info: VkCommandBufferBeginInfo, begin_info: VkCommandBufferBeginInfo,
) -> Result<CommandBufferRecorder<'a, 'b>> ) -> Result<CommandBufferRecorder<'device, 'pipeline, 'cbuffer>> {
where
'b: 'a,
'a: 'b,
{
self.device.begin_command_buffer(self.buffer, &begin_info)?; self.device.begin_command_buffer(self.buffer, &begin_info)?;
self.stored_handles.clear();
self.calls = 0; self.calls = 0;
Ok(CommandBufferRecorder { Ok(CommandBufferRecorder {
@ -125,7 +116,6 @@ impl<'a> CommandBuffer<'a> {
calls: &mut self.calls, calls: &mut self.calls,
buffer: self.buffer, buffer: self.buffer,
handles_lock: &mut self.stored_handles,
}) })
} }
@ -162,10 +152,10 @@ impl<'a> CommandBuffer<'a> {
} }
} }
pub fn inheritance_info( pub fn inheritance_info<'image>(
render_pass: Option<&RenderPass<'a>>, render_pass: Option<&RenderPass<'device>>,
sub_pass: Option<u32>, sub_pass: Option<u32>,
framebuffer: Option<&Framebuffer<'a>>, framebuffer: Option<&Framebuffer<'device, 'image>>,
query_enable: Option<QueryEnable>, query_enable: Option<QueryEnable>,
) -> VkCommandBufferInheritanceInfo { ) -> VkCommandBufferInheritanceInfo {
let mut info = VkCommandBufferInheritanceInfo::new( let mut info = VkCommandBufferInheritanceInfo::new(
@ -188,9 +178,12 @@ impl<'a> CommandBuffer<'a> {
} }
} }
impl<'a, 'b> CommandBufferRecorder<'a, 'b> { impl<'handle, 'me, 'device, 'pipeline, 'cbuffer> CommandBufferRecorder<'device, 'pipeline, 'cbuffer>
where
'handle: 'me,
{
pub fn pipeline_barrier( pub fn pipeline_barrier(
&mut self, &'me mut self,
src_stage_mask: impl Into<VkPipelineStageFlagBits>, src_stage_mask: impl Into<VkPipelineStageFlagBits>,
dst_stage_mask: impl Into<VkPipelineStageFlagBits>, dst_stage_mask: impl Into<VkPipelineStageFlagBits>,
dependency_flags: impl Into<VkDependencyFlagBits>, dependency_flags: impl Into<VkDependencyFlagBits>,
@ -212,7 +205,7 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn memory_barrier( pub fn memory_barrier(
&mut self, &'me mut self,
src_access_mask: impl Into<VkAccessFlagBits>, src_access_mask: impl Into<VkAccessFlagBits>,
src_stage: VkPipelineStageFlags, src_stage: VkPipelineStageFlags,
dst_access_mask: impl Into<VkAccessFlagBits>, dst_access_mask: impl Into<VkAccessFlagBits>,
@ -229,17 +222,13 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn buffer_barrier<T: ReprC + Send + Sync + 'static>( pub fn buffer_barrier<T: ReprC + Send + Sync + 'static>(
&'a mut self, &'me mut self,
buffer: &'b Buffer<'a, T>, buffer: &'handle Buffer<'device, T>,
src_access_mask: impl Into<VkAccessFlagBits>, src_access_mask: impl Into<VkAccessFlagBits>,
src_stage: impl Into<VkPipelineStageFlagBits>, src_stage: impl Into<VkPipelineStageFlagBits>,
dst_access_mask: impl Into<VkAccessFlagBits>, dst_access_mask: impl Into<VkAccessFlagBits>,
dst_stage: impl Into<VkPipelineStageFlagBits>, dst_stage: impl Into<VkPipelineStageFlagBits>,
) where ) {
'b: 'a,
{
self.handles_lock.push(buffer);
self.pipeline_barrier( self.pipeline_barrier(
src_stage, src_stage,
dst_stage, dst_stage,
@ -259,18 +248,18 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn image_barrier( pub fn image_barrier(
&mut self, &'me mut self,
image: &Image<'a>, image: &'handle Image<'device>,
old_image_layout: VkImageLayout, old_image_layout: VkImageLayout,
src_stage: impl Into<VkPipelineStageFlagBits>, src_stage: impl Into<VkPipelineStageFlagBits>,
new_image_layout: VkImageLayout, new_image_layout: VkImageLayout,
dst_stage: impl Into<VkPipelineStageFlagBits>, dst_stage: impl Into<VkPipelineStageFlagBits>,
) { ) where
'handle: 'me,
{
let src_access_mask = Image::src_layout_to_access(old_image_layout); let src_access_mask = Image::src_layout_to_access(old_image_layout);
let dst_access_mask = Image::dst_layout_to_access(new_image_layout); let dst_access_mask = Image::dst_layout_to_access(new_image_layout);
self.handles_lock.push(image);
self.pipeline_barrier( self.pipeline_barrier(
src_stage, src_stage,
dst_stage, dst_stage,
@ -293,16 +282,14 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn image_barrier_auto_stage( pub fn image_barrier_auto_stage(
&mut self, &'me mut self,
image: &Image<'a>, image: &'handle Image<'device>,
old_image_layout: VkImageLayout, old_image_layout: VkImageLayout,
new_image_layout: VkImageLayout, new_image_layout: VkImageLayout,
) { ) {
let src_access_mask = Image::src_layout_to_access(old_image_layout); let src_access_mask = Image::src_layout_to_access(old_image_layout);
let dst_access_mask = Image::dst_layout_to_access(new_image_layout); let dst_access_mask = Image::dst_layout_to_access(new_image_layout);
self.handles_lock.push(image);
self.pipeline_barrier( self.pipeline_barrier(
CommandBuffer::access_to_stage(src_access_mask), CommandBuffer::access_to_stage(src_access_mask),
CommandBuffer::access_to_stage(dst_access_mask), CommandBuffer::access_to_stage(dst_access_mask),
@ -325,7 +312,7 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn begin_render_pass( pub fn begin_render_pass(
&mut self, &'me mut self,
renderpass_begin_info: VkRenderPassBeginInfo, renderpass_begin_info: VkRenderPassBeginInfo,
subpass_contents: VkSubpassContents, subpass_contents: VkSubpassContents,
) { ) {
@ -335,16 +322,13 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
.cmd_begin_render_pass(self.buffer, &renderpass_begin_info, subpass_contents); .cmd_begin_render_pass(self.buffer, &renderpass_begin_info, subpass_contents);
} }
pub fn begin_render_pass_full( pub fn begin_render_pass_full<'image>(
&mut self, &'me mut self,
render_pass: &RenderPass<'a>, render_pass: &'handle RenderPass<'device>,
framebuffer: &Framebuffer<'a>, framebuffer: &'handle Framebuffer<'device, 'image>,
clear_values: &[VkClearValue], clear_values: &[VkClearValue],
subpass_contents: VkSubpassContents, subpass_contents: VkSubpassContents,
) { ) {
self.handles_lock.push(render_pass.clone());
self.handles_lock.push(framebuffer.clone());
self.sub_pass = 0; self.sub_pass = 0;
let render_pass_begin_info = VkRenderPassBeginInfo::new( let render_pass_begin_info = VkRenderPassBeginInfo::new(
@ -364,18 +348,16 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
.cmd_begin_render_pass(self.buffer, &render_pass_begin_info, subpass_contents); .cmd_begin_render_pass(self.buffer, &render_pass_begin_info, subpass_contents);
} }
pub fn next_subpass(&mut self, subpass_contents: VkSubpassContents) { pub fn next_subpass(&'me mut self, subpass_contents: VkSubpassContents) {
self.sub_pass += 1; self.sub_pass += 1;
self.device.cmd_next_subpass(self.buffer, subpass_contents); self.device.cmd_next_subpass(self.buffer, subpass_contents);
} }
pub fn end_render_pass(&self) { pub fn end_render_pass(&'me self) {
self.device.cmd_end_render_pass(self.buffer); self.device.cmd_end_render_pass(self.buffer);
} }
pub fn bind_pipeline(&mut self, pipeline: &Pipeline<'a>) -> Result<()> { pub fn bind_pipeline(&'me mut self, pipeline: &'pipeline Pipeline<'device>) -> Result<()> {
self.handles_lock.push(pipeline);
match pipeline.pipeline_type() { match pipeline.pipeline_type() {
PipelineType::Graphics => { PipelineType::Graphics => {
debug_assert_eq!(self.sub_pass, pipeline.sub_pass()); debug_assert_eq!(self.sub_pass, pipeline.sub_pass());
@ -398,12 +380,15 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
), ),
} }
self.pipeline = Some(pipeline.clone()); self.pipeline = Some(pipeline);
Ok(()) Ok(())
} }
pub fn execute_commands(&self, command_buffers: &[&impl VkHandle<VkCommandBuffer>]) { pub fn execute_commands(
&'me mut self,
command_buffers: &[&'handle impl VkHandle<VkCommandBuffer>],
) {
*self.calls += 1; *self.calls += 1;
let buffers: Vec<VkCommandBuffer> = let buffers: Vec<VkCommandBuffer> =
@ -413,7 +398,10 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
.cmd_execute_commands(self.buffer, buffers.as_slice()); .cmd_execute_commands(self.buffer, buffers.as_slice());
} }
pub fn bind_descriptor_sets_minimal(&mut self, descriptor_sets: &[&DescriptorSet<'a>]) { pub fn bind_descriptor_sets_minimal<'a>(
&'me mut self,
descriptor_sets: &[&'handle DescriptorSet<'device, 'a>],
) {
*self.calls += 1; *self.calls += 1;
let (pipeline_bind_point, vk_layout) = { let (pipeline_bind_point, vk_layout) = {
@ -433,11 +421,7 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
let vk_descriptor_sets: Vec<VkDescriptorSet> = descriptor_sets let vk_descriptor_sets: Vec<VkDescriptorSet> = descriptor_sets
.iter() .iter()
.map(|ds: &&DescriptorSet<'a>| { .map(|ds: &&DescriptorSet<'device, 'a>| ds.vk_handle())
self.handles_lock.push((*ds).clone());
ds.vk_handle()
})
.collect(); .collect();
self.device.cmd_bind_descriptor_sets( self.device.cmd_bind_descriptor_sets(
@ -450,28 +434,25 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
); );
} }
pub fn bind_vertex_buffer<T: ReprC + Send + Sync + 'static>(&mut self, buffer: &Buffer<'a, T>) { pub fn bind_vertex_buffer<T: ReprC + Send + Sync + 'static>(
&'me mut self,
buffer: &'handle Buffer<'device, T>,
) {
*self.calls += 1; *self.calls += 1;
self.handles_lock.push(buffer);
self.device self.device
.cmd_bind_vertex_buffers(self.buffer, 0, &[buffer.vk_handle()], &[0]); .cmd_bind_vertex_buffers(self.buffer, 0, &[buffer.vk_handle()], &[0]);
} }
pub fn bind_vertex_buffers_minimal<T: ReprC + Send + Sync + 'static>( pub fn bind_vertex_buffers_minimal<T: ReprC + Send + Sync + 'static>(
&mut self, &'me mut self,
buffers: &[&Buffer<'a, T>], buffers: &[&'handle Buffer<'device, T>],
) { ) {
*self.calls += 1; *self.calls += 1;
let vk_buffers: Vec<VkBuffer> = buffers let vk_buffers: Vec<VkBuffer> = buffers
.iter() .iter()
.map(|b: &&Buffer<'a, T>| { .map(|b: &&Buffer<'device, T>| b.vk_handle())
self.handles_lock.push((*b).clone());
b.vk_handle()
})
.collect(); .collect();
let offsets = vec![0; vk_buffers.len()]; let offsets = vec![0; vk_buffers.len()];
@ -485,29 +466,27 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn bind_index_buffer<T: ReprC + Send + Sync + 'static>( pub fn bind_index_buffer<T: ReprC + Send + Sync + 'static>(
&mut self, &'me mut self,
buffer: &Buffer<'a, T>, buffer: &'handle Buffer<'device, T>,
offset: VkDeviceSize, offset: VkDeviceSize,
index_type: VkIndexType, index_type: VkIndexType,
) { ) {
*self.calls += 1; *self.calls += 1;
self.handles_lock.push(buffer);
self.device self.device
.cmd_bind_index_buffer(self.buffer, buffer.vk_handle(), offset, index_type); .cmd_bind_index_buffer(self.buffer, buffer.vk_handle(), offset, index_type);
} }
pub fn set_viewport(&self, viewports: &[VkViewport]) { pub fn set_viewport(&'me self, viewports: &[VkViewport]) {
self.device.cmd_set_viewport(self.buffer, 0, viewports); self.device.cmd_set_viewport(self.buffer, 0, viewports);
} }
pub fn set_scissor(&self, scissors: &[VkRect2D]) { pub fn set_scissor(&'me self, scissors: &[VkRect2D]) {
self.device.cmd_set_scissor(self.buffer, 0, scissors); self.device.cmd_set_scissor(self.buffer, 0, scissors);
} }
pub fn draw( pub fn draw(
&self, &'me mut self,
vertex_count: u32, vertex_count: u32,
instance_count: u32, instance_count: u32,
first_vertex: u32, first_vertex: u32,
@ -524,14 +503,14 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
); );
} }
pub fn draw_complete_single_instance(&self, vertex_count: u32) { pub fn draw_complete_single_instance(&'me mut self, vertex_count: u32) {
*self.calls += 1; *self.calls += 1;
self.device.cmd_draw(self.buffer, vertex_count, 1, 0, 0); self.device.cmd_draw(self.buffer, vertex_count, 1, 0, 0);
} }
pub fn draw_indexed( pub fn draw_indexed(
&self, &'me mut self,
index_count: u32, index_count: u32,
instance_count: u32, instance_count: u32,
first_index: u32, first_index: u32,
@ -550,14 +529,18 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
); );
} }
pub fn draw_indexed_complete_single_instance(&self, index_count: u32) { pub fn draw_indexed_complete_single_instance(&'me mut self, index_count: u32) {
*self.calls += 1; *self.calls += 1;
self.device self.device
.cmd_draw_indexed(self.buffer, index_count, 1, 0, 0, 0); .cmd_draw_indexed(self.buffer, index_count, 1, 0, 0, 0);
} }
pub fn push_constants<U>(&self, stage_flags: impl Into<VkShaderStageFlagBits>, data: &U) { pub fn push_constants<U>(
&'me mut self,
stage_flags: impl Into<VkShaderStageFlagBits>,
data: &U,
) {
*self.calls += 1; *self.calls += 1;
let pipeline = match &self.pipeline { let pipeline = match &self.pipeline {
@ -572,16 +555,14 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn set_image_layout( pub fn set_image_layout(
&mut self, &'me mut self,
image: &Image<'a>, image: &'handle Image<'device>,
new_image_layout: VkImageLayout, new_image_layout: VkImageLayout,
subresource_range: VkImageSubresourceRange, subresource_range: VkImageSubresourceRange,
) { ) {
let src_access = Image::src_layout_to_access(image.image_layout()); let src_access = Image::src_layout_to_access(image.image_layout());
let dst_access = Image::dst_layout_to_access(new_image_layout); let dst_access = Image::dst_layout_to_access(new_image_layout);
self.handles_lock.push(image);
self.pipeline_barrier( self.pipeline_barrier(
CommandBuffer::access_to_stage(src_access), CommandBuffer::access_to_stage(src_access),
CommandBuffer::access_to_stage(dst_access), CommandBuffer::access_to_stage(dst_access),
@ -603,12 +584,14 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
image.set_image_layout(new_image_layout); image.set_image_layout(new_image_layout);
} }
pub fn set_full_image_layout(&mut self, image: &Image<'a>, new_image_layout: VkImageLayout) { pub fn set_full_image_layout(
&'me mut self,
image: &'handle Image<'device>,
new_image_layout: VkImageLayout,
) {
let src_access = Image::src_layout_to_access(image.image_layout()); let src_access = Image::src_layout_to_access(image.image_layout());
let dst_access = Image::dst_layout_to_access(new_image_layout); let dst_access = Image::dst_layout_to_access(new_image_layout);
self.handles_lock.push(image);
self.pipeline_barrier( self.pipeline_barrier(
CommandBuffer::access_to_stage(src_access), CommandBuffer::access_to_stage(src_access),
CommandBuffer::access_to_stage(dst_access), CommandBuffer::access_to_stage(dst_access),
@ -631,63 +614,60 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
// TODO: // TODO:
pub fn set_line_width(&self) { pub fn set_line_width(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn set_depth_bias(&self) { pub fn set_depth_bias(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn set_blend_constants(&self) { pub fn set_blend_constants(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn set_depth_bounds(&self) { pub fn set_depth_bounds(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn set_stencil_compare_mask(&self) { pub fn set_stencil_compare_mask(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn set_stencil_write_mask(&self) { pub fn set_stencil_write_mask(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn set_stencil_reference(&self) { pub fn set_stencil_reference(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn draw_indirect(&self) { pub fn draw_indirect(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn draw_indexed_indirect(&self) { pub fn draw_indexed_indirect(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn dispatch(&self, x: u32, y: u32, z: u32) { pub fn dispatch(&'me mut self, x: u32, y: u32, z: u32) {
*self.calls += 1; *self.calls += 1;
self.device.cmd_dispatch(self.buffer, x, y, z); self.device.cmd_dispatch(self.buffer, x, y, z);
} }
pub fn dispatch_indirect(&self) { pub fn dispatch_indirect(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn copy_buffer<T: ReprC + Send + Sync + 'static, U: ReprC + Send + Sync + 'static>( pub fn copy_buffer<T: ReprC + Send + Sync + 'static, U: ReprC + Send + Sync + 'static>(
&mut self, &'me mut self,
src_buffer: &Buffer<'a, T>, src_buffer: &'handle Buffer<'device, T>,
dst_buffer: &Buffer<'a, U>, dst_buffer: &'handle Buffer<'device, U>,
regions: &[VkBufferCopy], regions: &[VkBufferCopy],
) { ) {
*self.calls += 1; *self.calls += 1;
self.handles_lock.push(src_buffer);
self.handles_lock.push(dst_buffer);
self.device.cmd_copy_buffer( self.device.cmd_copy_buffer(
self.buffer, self.buffer,
src_buffer.vk_handle(), src_buffer.vk_handle(),
@ -697,18 +677,15 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn copy_image( pub fn copy_image(
&mut self, &'me mut self,
src_image: &Image<'a>, src_image: &'handle Image<'device>,
dst_image: &Image<'a>, dst_image: &'handle Image<'device>,
src_layout: VkImageLayout, src_layout: VkImageLayout,
dst_layout: VkImageLayout, dst_layout: VkImageLayout,
regions: &[VkImageCopy], regions: &[VkImageCopy],
) { ) {
*self.calls += 1; *self.calls += 1;
self.handles_lock.push(src_image);
self.handles_lock.push(dst_image);
self.device.cmd_copy_image( self.device.cmd_copy_image(
self.buffer, self.buffer,
src_image.vk_handle(), src_image.vk_handle(),
@ -720,14 +697,11 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn blit_complete( pub fn blit_complete(
&mut self, &'me mut self,
src_image: &Image<'a>, src_image: &'handle Image<'device>,
dst_image: &Image<'a>, dst_image: &'handle Image<'device>,
filter: VkFilter, filter: VkFilter,
) { ) {
self.handles_lock.push(src_image);
self.handles_lock.push(dst_image);
let image_blit = VkImageBlit { let image_blit = VkImageBlit {
srcSubresource: src_image.full_resource_layers(), srcSubresource: src_image.full_resource_layers(),
srcOffsets: [ srcOffsets: [
@ -760,9 +734,9 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn blit_image( pub fn blit_image(
&mut self, &'me mut self,
src_image: &Image<'a>, src_image: &'handle Image<'device>,
dst_image: &Image<'a>, dst_image: &'handle Image<'device>,
src_layout: VkImageLayout, src_layout: VkImageLayout,
dst_layout: VkImageLayout, dst_layout: VkImageLayout,
regions: &[VkImageBlit], regions: &[VkImageBlit],
@ -770,9 +744,6 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
) { ) {
*self.calls += 1; *self.calls += 1;
self.handles_lock.push(src_image);
self.handles_lock.push(dst_image);
self.device.cmd_blit_image( self.device.cmd_blit_image(
self.buffer, self.buffer,
src_image.vk_handle(), src_image.vk_handle(),
@ -785,17 +756,14 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn copy_buffer_to_image<T: ReprC + Send + Sync + 'static>( pub fn copy_buffer_to_image<T: ReprC + Send + Sync + 'static>(
&mut self, &'me mut self,
src_buffer: &Buffer<'a, T>, src_buffer: &'handle Buffer<'device, T>,
dst_image: &Image<'a>, dst_image: &'handle Image<'device>,
image_layout: VkImageLayout, image_layout: VkImageLayout,
regions: &[VkBufferImageCopy], regions: &[VkBufferImageCopy],
) { ) {
*self.calls += 1; *self.calls += 1;
self.handles_lock.push(src_buffer);
self.handles_lock.push(dst_image);
self.device.cmd_copy_buffer_to_image( self.device.cmd_copy_buffer_to_image(
self.buffer, self.buffer,
src_buffer.vk_handle(), src_buffer.vk_handle(),
@ -806,17 +774,14 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn copy_image_to_buffer<T: ReprC + Send + Sync + 'static>( pub fn copy_image_to_buffer<T: ReprC + Send + Sync + 'static>(
&mut self, &'me mut self,
src_image: &Image<'a>, src_image: &'handle Image<'device>,
image_layout: VkImageLayout, image_layout: VkImageLayout,
dst_buffer: &Buffer<'a, T>, dst_buffer: &'handle Buffer<'device, T>,
regions: &[VkBufferImageCopy], regions: &[VkBufferImageCopy],
) { ) {
*self.calls += 1; *self.calls += 1;
self.handles_lock.push(src_image);
self.handles_lock.push(dst_buffer);
self.device.cmd_copy_image_to_buffer( self.device.cmd_copy_image_to_buffer(
self.buffer, self.buffer,
src_image.vk_handle(), src_image.vk_handle(),
@ -826,19 +791,21 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
) )
} }
pub fn update_buffer(&self) { pub fn update_buffer(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn fill_buffer(&self) { pub fn fill_buffer(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn clear_color_image(&mut self, image: &Image<'a>, clear_color: VkClearColorValue) { pub fn clear_color_image(
&'me mut self,
image: &Image<'device>,
clear_color: VkClearColorValue,
) {
*self.calls += 1; *self.calls += 1;
self.handles_lock.push(image);
self.device.cmd_clear_color_image( self.device.cmd_clear_color_image(
self.buffer, self.buffer,
image.vk_handle(), image.vk_handle(),
@ -848,25 +815,22 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
); );
} }
pub fn clear_depth_stencil_image(&self) { pub fn clear_depth_stencil_image(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn clear_attachments(&self) { pub fn clear_attachments(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn resolve_image( pub fn resolve_image(
&mut self, &'me mut self,
src_image: &Image<'a>, src_image: &'handle Image<'device>,
dst_image: &Image<'a>, dst_image: &'handle Image<'device>,
regions: &[VkImageResolve], regions: &[VkImageResolve],
) { ) {
*self.calls += 1; *self.calls += 1;
self.handles_lock.push(src_image);
self.handles_lock.push(dst_image);
self.device.cmd_resolve_image( self.device.cmd_resolve_image(
self.buffer, self.buffer,
src_image.vk_handle(), src_image.vk_handle(),
@ -877,61 +841,61 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
); );
} }
pub fn set_event(&self) { pub fn set_event(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn reset_event(&self) { pub fn reset_event(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn wait_events(&self) { pub fn wait_events(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn begin_query(&self) { pub fn begin_query(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn end_query(&self) { pub fn end_query(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn reset_query_pool(&self) { pub fn reset_query_pool(&'me self) {
unimplemented!(); unimplemented!();
} }
pub fn write_timestamp( pub fn write_timestamp(
&mut self, &'me mut self,
query_pool: &QueryPool, query_pool: &'handle QueryPool,
query: u32, query: u32,
pipeline_stage: impl Into<VkPipelineStageFlagBits>, pipeline_stage: impl Into<VkPipelineStageFlagBits>,
) { ) {
*self.calls += 1; *self.calls += 1;
self.handles_lock.push(query_pool);
self.device self.device
.cmd_write_timestamp(self.buffer, pipeline_stage, query_pool.vk_handle(), query); .cmd_write_timestamp(self.buffer, pipeline_stage, query_pool.vk_handle(), query);
} }
pub fn copy_query_pool_results(&self) { pub fn copy_query_pool_results(&'me self) {
unimplemented!(); unimplemented!();
} }
} }
impl<'a, 'b> CommandBufferRecorder<'a, 'b> { impl<'me, 'handle, 'device, 'pipeline, 'cbuffer> CommandBufferRecorder<'device, 'pipeline, 'cbuffer>
where
'handle: 'me,
{
pub fn build_acceleration_structure_indirect( pub fn build_acceleration_structure_indirect(
&mut self, &'me mut self,
infos: &[VkAccelerationStructureBuildGeometryInfoKHR], infos: &[VkAccelerationStructureBuildGeometryInfoKHR],
indirect_buffers: &[Buffer<'a, impl ReprC + Send + Sync + 'static>], indirect_buffers: &[Buffer<'device, impl ReprC + Send + Sync + 'static>],
indirect_strides: &[u32], indirect_strides: &[u32],
max_primitive_counts: &[&u32], max_primitive_counts: &[&u32],
) { ) {
let mut device_addresses: Vec<VkDeviceAddress> = Vec::with_capacity(indirect_buffers.len()); let mut device_addresses: Vec<VkDeviceAddress> = Vec::with_capacity(indirect_buffers.len());
for indirect_buffer in indirect_buffers.iter() { for indirect_buffer in indirect_buffers.iter() {
self.handles_lock.push(indirect_buffer);
device_addresses.push(indirect_buffer.device_address().into()); device_addresses.push(indirect_buffer.device_address().into());
} }
@ -945,7 +909,7 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn build_acceleration_structures( pub fn build_acceleration_structures(
&self, &'me self,
infos: &[VkAccelerationStructureBuildGeometryInfoKHR], infos: &[VkAccelerationStructureBuildGeometryInfoKHR],
range_infos: &[&[VkAccelerationStructureBuildRangeInfoKHR]], range_infos: &[&[VkAccelerationStructureBuildRangeInfoKHR]],
) { ) {
@ -954,14 +918,11 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn copy_acceleration_structure( pub fn copy_acceleration_structure(
&mut self, &'me mut self,
src: &AccelerationStructure<'a>, src: &'handle AccelerationStructure<'device>,
dst: &AccelerationStructure<'a>, dst: &'handle AccelerationStructure<'device>,
mode: VkCopyAccelerationStructureModeKHR, mode: VkCopyAccelerationStructureModeKHR,
) { ) {
self.handles_lock.push(src);
self.handles_lock.push(dst);
let info = VkCopyAccelerationStructureInfoKHR::new(src.vk_handle(), dst.vk_handle(), mode); let info = VkCopyAccelerationStructureInfoKHR::new(src.vk_handle(), dst.vk_handle(), mode);
self.device self.device
@ -969,13 +930,11 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn copy_acceleration_structure_to_memory( pub fn copy_acceleration_structure_to_memory(
&mut self, &'me mut self,
src: &AccelerationStructure<'a>, src: &'handle AccelerationStructure<'device>,
dst: VkDeviceOrHostAddressKHR, dst: VkDeviceOrHostAddressKHR,
mode: VkCopyAccelerationStructureModeKHR, mode: VkCopyAccelerationStructureModeKHR,
) { ) {
self.handles_lock.push(src);
let info = VkCopyAccelerationStructureToMemoryInfoKHR::new(src.vk_handle(), dst, mode); let info = VkCopyAccelerationStructureToMemoryInfoKHR::new(src.vk_handle(), dst, mode);
self.device self.device
@ -983,13 +942,11 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn copy_memory_to_acceleration_structure( pub fn copy_memory_to_acceleration_structure(
&mut self, &'me mut self,
src: VkDeviceOrHostAddressConstKHR, src: VkDeviceOrHostAddressConstKHR,
dst: &AccelerationStructure<'a>, dst: &'handle AccelerationStructure<'device>,
mode: VkCopyAccelerationStructureModeKHR, mode: VkCopyAccelerationStructureModeKHR,
) { ) {
self.handles_lock.push(dst);
let info = VkCopyMemoryToAccelerationStructureInfoKHR::new(src, dst.vk_handle(), mode); let info = VkCopyMemoryToAccelerationStructureInfoKHR::new(src, dst.vk_handle(), mode);
self.device self.device
@ -997,12 +954,10 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn trace_rays_indirect( pub fn trace_rays_indirect(
&mut self, &'me mut self,
sbt: ShaderBindingTable<'a>, sbt: &'handle ShaderBindingTable<'device>,
buffer: Buffer<'a, impl ReprC + Send + Sync + 'static>, buffer: &'handle Buffer<'device, impl ReprC + Send + Sync + 'static>,
) { ) {
self.handles_lock.push(&buffer);
self.device.cmd_trace_rays_indirect( self.device.cmd_trace_rays_indirect(
self.buffer, self.buffer,
sbt.raygen_shader_binding_table(), sbt.raygen_shader_binding_table(),
@ -1013,7 +968,13 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
) )
} }
pub fn trace_rays(&self, sbt: &ShaderBindingTable<'a>, width: u32, height: u32, depth: u32) { pub fn trace_rays(
&'me self,
sbt: &'handle ShaderBindingTable<'device>,
width: u32,
height: u32,
depth: u32,
) {
self.device.cmd_trace_rays( self.device.cmd_trace_rays(
self.buffer, self.buffer,
sbt.raygen_shader_binding_table(), sbt.raygen_shader_binding_table(),
@ -1027,20 +988,15 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
pub fn write_acceleration_structure_properties( pub fn write_acceleration_structure_properties(
&mut self, &'me mut self,
acceleration_structures: &[&AccelerationStructure<'a>], acceleration_structures: &[&'handle AccelerationStructure<'device>],
query_type: VkQueryType, query_type: VkQueryType,
query_pool: &QueryPool, query_pool: &'handle QueryPool,
first_query: u32, first_query: u32,
) { ) {
self.handles_lock.push(query_pool);
let as_handles: Vec<VkAccelerationStructureKHR> = acceleration_structures let as_handles: Vec<VkAccelerationStructureKHR> = acceleration_structures
.iter() .iter()
.map(|a| { .map(|a| a.vk_handle())
self.handles_lock.push((*a).clone());
a.vk_handle()
})
.collect(); .collect();
self.device.cmd_write_acceleration_structure_properties( self.device.cmd_write_acceleration_structure_properties(
@ -1053,20 +1009,20 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
} }
} }
impl<'a> VulkanDevice for CommandBuffer<'a> { impl<'device> VulkanDevice for CommandBuffer<'device> {
fn device(&self) -> &Device { fn device(&self) -> &'device Device {
&self.device &self.device
} }
} }
impl<'a> Drop for CommandBuffer<'a> { impl<'device> Drop for CommandBuffer<'device> {
fn drop(&mut self) { fn drop(&mut self) {
self.device self.device
.free_command_buffers(self.pool.vk_handle(), &[self.buffer]); .free_command_buffers(self.pool.vk_handle(), &[self.buffer]);
} }
} }
impl<'a, 'b> Drop for CommandBufferRecorder<'a, 'b> { impl<'device, 'pipeline, 'cbuffer> Drop for CommandBufferRecorder<'device, 'pipeline, 'cbuffer> {
fn drop(&mut self) { fn drop(&mut self) {
self.device.end_command_buffer(self.buffer).unwrap() self.device.end_command_buffer(self.buffer).unwrap()
} }

View file

@ -67,14 +67,14 @@ impl<'a> DescriptorPoolBuilder<'a> {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct DescriptorPool<'a> { pub struct DescriptorPool<'device> {
device: &'a Device, device: &'device Device,
descriptor_pool: VkDescriptorPool, descriptor_pool: VkDescriptorPool,
pub(crate) descriptor_set_layout: &'a DescriptorSetLayout<'a>, pub(crate) descriptor_set_layout: &'device DescriptorSetLayout<'device>,
} }
impl<'a> DescriptorPool<'a> { impl<'device> DescriptorPool<'device> {
pub fn builder() -> DescriptorPoolBuilder<'a> { pub fn builder() -> DescriptorPoolBuilder<'device> {
DescriptorPoolBuilder { DescriptorPoolBuilder {
layout: None, layout: None,
descriptor_count: 1, descriptor_count: 1,
@ -87,7 +87,7 @@ impl<'a> DescriptorPool<'a> {
.reset_descriptor_pool(self.descriptor_pool, VK_DESCRIPTOR_POOL_RESET_NULL_BIT) .reset_descriptor_pool(self.descriptor_pool, VK_DESCRIPTOR_POOL_RESET_NULL_BIT)
} }
pub fn prepare_set(&self) -> DescriptorSetBuilder<'a> { pub fn prepare_set(&'device self) -> DescriptorSetBuilder<'device> {
DescriptorSet::builder(self.device, self) DescriptorSet::builder(self.device, self)
} }
} }

View file

@ -2,17 +2,15 @@ use crate::prelude::*;
use anyhow::Result; use anyhow::Result;
use std::any::Any; use std::marker::PhantomData;
use std::collections::HashMap;
use std::slice; use std::slice;
use std::sync::Mutex;
#[derive(Debug)] #[derive(Debug)]
pub struct DescriptorWrite<'a> { pub struct DescriptorWrite<'handle> {
lifetime: &'handle PhantomData<()>,
binding: u32, binding: u32,
descriptor_type: VkDescriptorType, descriptor_type: VkDescriptorType,
inner: InnerWrite, inner: InnerWrite,
handles: Vec<&'a (dyn Any + Send + Sync)>,
} }
#[derive(Debug)] #[derive(Debug)]
@ -27,10 +25,10 @@ enum InnerWrite {
), ),
} }
impl<'a> DescriptorWrite<'a> { impl<'device, 'handle> DescriptorWrite<'handle> {
pub fn uniform_buffers<T: ReprC + Send + Sync + 'static>( pub fn uniform_buffers<T: ReprC + Send + Sync + 'static>(
binding: u32, binding: u32,
buffers: &[&Buffer<'a, T>], buffers: &[&'handle Buffer<'device, T>],
) -> Self { ) -> Self {
DescriptorWrite { DescriptorWrite {
binding, binding,
@ -45,16 +43,13 @@ impl<'a> DescriptorWrite<'a> {
}) })
.collect(), .collect(),
), ),
handles: buffers lifetime: &PhantomData,
.iter()
.map(|b| (*b) as &'a (dyn Any + Send + Sync))
.collect(),
} }
} }
pub fn storage_buffers<T: ReprC + Send + Sync + 'static>( pub fn storage_buffers<T: ReprC + Send + Sync + 'static>(
binding: u32, binding: u32,
buffers: &[&Buffer<'a, T>], buffers: &[&'handle Buffer<'device, T>],
) -> Self { ) -> Self {
DescriptorWrite { DescriptorWrite {
binding, binding,
@ -69,14 +64,11 @@ impl<'a> DescriptorWrite<'a> {
}) })
.collect(), .collect(),
), ),
handles: buffers lifetime: &PhantomData,
.iter()
.map(|b| (*b) as &'a (dyn Any + Send + Sync))
.collect(),
} }
} }
pub fn combined_samplers(binding: u32, images: &[&'a Image<'a>]) -> Self { pub fn combined_samplers(binding: u32, images: &[&'handle Image<'device>]) -> Self {
DescriptorWrite { DescriptorWrite {
binding, binding,
descriptor_type: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, descriptor_type: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
@ -94,14 +86,11 @@ impl<'a> DescriptorWrite<'a> {
}) })
.collect(), .collect(),
), ),
handles: images lifetime: &PhantomData,
.iter()
.map(|i| (*i).clone() as &'a (dyn Any + Send + Sync))
.collect(),
} }
} }
pub fn storage_images(binding: u32, images: &[&'a Image<'a>]) -> Self { pub fn storage_images(binding: u32, images: &[&'handle Image<'device>]) -> Self {
DescriptorWrite { DescriptorWrite {
binding, binding,
descriptor_type: VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, descriptor_type: VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
@ -115,14 +104,11 @@ impl<'a> DescriptorWrite<'a> {
}) })
.collect(), .collect(),
), ),
handles: images lifetime: &PhantomData,
.iter()
.map(|i| (*i).clone() as &'a (dyn Any + Send + Sync))
.collect(),
} }
} }
pub fn input_attachments(binding: u32, images: &[&'a Image<'a>]) -> Self { pub fn input_attachments(binding: u32, images: &[&'handle Image<'device>]) -> Self {
DescriptorWrite { DescriptorWrite {
binding, binding,
descriptor_type: VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, descriptor_type: VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
@ -136,16 +122,13 @@ impl<'a> DescriptorWrite<'a> {
}) })
.collect(), .collect(),
), ),
handles: images lifetime: &PhantomData,
.iter()
.map(|i| (*i) as &'a (dyn Any + Send + Sync))
.collect(),
} }
} }
pub fn acceleration_structures( pub fn acceleration_structures(
binding: u32, binding: u32,
acceleration_structures: &[&AccelerationStructure<'a>], acceleration_structures: &[&'handle AccelerationStructure<'device>],
) -> Self { ) -> Self {
let vk_as: Vec<VkAccelerationStructureKHR> = acceleration_structures let vk_as: Vec<VkAccelerationStructureKHR> = acceleration_structures
.iter() .iter()
@ -159,10 +142,7 @@ impl<'a> DescriptorWrite<'a> {
VkWriteDescriptorSetAccelerationStructureKHR::default(), VkWriteDescriptorSetAccelerationStructureKHR::default(),
vk_as, vk_as,
)), )),
handles: acceleration_structures lifetime: &PhantomData,
.iter()
.map(|a| (*a) as &'a (dyn Any + Send + Sync))
.collect(),
}; };
if let InnerWrite::AS((vk_write_as, vk_as)) = &mut write.inner { if let InnerWrite::AS((vk_write_as, vk_as)) = &mut write.inner {
@ -212,7 +192,7 @@ impl<'a> DescriptorSetBuilder<'a> {
self self
} }
pub fn allocate(mut self) -> Result<DescriptorSet<'a>> { pub fn allocate<'handle>(mut self) -> Result<DescriptorSet<'a, 'handle>> {
let layout = self.descriptor_pool.vk_handle(); let layout = self.descriptor_pool.vk_handle();
let mut descriptor_set_ci = VkDescriptorSetAllocateInfo::new( let mut descriptor_set_ci = VkDescriptorSetAllocateInfo::new(
@ -233,25 +213,25 @@ impl<'a> DescriptorSetBuilder<'a> {
pool: self.descriptor_pool, pool: self.descriptor_pool,
descriptor_set, descriptor_set,
handles: Mutex::new(HashMap::new()), lifetimes: &PhantomData,
}) })
} }
} }
#[derive(Debug)] #[derive(Debug)]
pub struct DescriptorSet<'a> { pub struct DescriptorSet<'device, 'handle> {
device: &'a Device, device: &'device Device,
pool: &'a DescriptorPool<'a>, pool: &'device DescriptorPool<'device>,
descriptor_set: VkDescriptorSet, descriptor_set: VkDescriptorSet,
handles: Mutex<HashMap<u32, Vec<&'a (dyn Any + Send + Sync)>>>, lifetimes: &'handle PhantomData<()>,
} }
impl<'a> DescriptorSet<'a> { impl<'device, 'handle> DescriptorSet<'device, 'handle> {
pub(crate) fn builder( pub(crate) fn builder(
device: &'a Device, device: &'device Device,
descriptor_pool: &'a DescriptorPool<'a>, descriptor_pool: &'device DescriptorPool<'device>,
) -> DescriptorSetBuilder<'a> { ) -> DescriptorSetBuilder<'device> {
DescriptorSetBuilder { DescriptorSetBuilder {
device, device,
descriptor_pool, descriptor_pool,
@ -263,7 +243,7 @@ impl<'a> DescriptorSet<'a> {
} }
// TODO: add update function for VkCopyDescriptorSet // TODO: add update function for VkCopyDescriptorSet
pub fn update(&self, writes: &[DescriptorWrite<'a>]) -> Result<()> { pub fn update(&self, writes: &[DescriptorWrite<'handle>]) -> Result<()> {
debug_assert!(!writes.is_empty()); debug_assert!(!writes.is_empty());
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
@ -278,7 +258,6 @@ impl<'a> DescriptorSet<'a> {
} }
let mut vk_writes = Vec::new(); let mut vk_writes = Vec::new();
let mut handles_lock = self.handles.lock().unwrap();
for write in writes { for write in writes {
let mut write_desc = VkWriteDescriptorSet::new( let mut write_desc = VkWriteDescriptorSet::new(
@ -291,13 +270,6 @@ impl<'a> DescriptorSet<'a> {
write.vk_write(&mut write_desc); write.vk_write(&mut write_desc);
vk_writes.push(write_desc); vk_writes.push(write_desc);
match handles_lock.get_mut(&write.binding) {
Some(val) => *val = write.handles.clone(),
None => {
handles_lock.insert(write.binding, write.handles.clone());
}
}
} }
self.device self.device
@ -307,27 +279,31 @@ impl<'a> DescriptorSet<'a> {
} }
} }
impl<'a> VulkanDevice for DescriptorSet<'a> { impl<'device, 'handle> VulkanDevice for DescriptorSet<'device, 'handle> {
fn device(&self) -> &Device { fn device(&self) -> &Device {
&self.device &self.device
} }
} }
impl_vk_handle!(DescriptorSet<'a>, VkDescriptorSet, descriptor_set); impl_vk_handle!(
DescriptorSet<'device, 'handle>,
VkDescriptorSet,
descriptor_set
);
impl<'a> VkHandle<VkDescriptorSetLayout> for DescriptorSet<'a> { impl<'device, 'handle> VkHandle<VkDescriptorSetLayout> for DescriptorSet<'device, 'handle> {
fn vk_handle(&self) -> VkDescriptorSetLayout { fn vk_handle(&self) -> VkDescriptorSetLayout {
self.pool.vk_handle() self.pool.vk_handle()
} }
} }
impl<'a> VkHandle<VkDescriptorSetLayout> for &'a DescriptorSet<'a> { impl<'a, 'device, 'handle> VkHandle<VkDescriptorSetLayout> for &'a DescriptorSet<'device, 'handle> {
fn vk_handle(&self) -> VkDescriptorSetLayout { fn vk_handle(&self) -> VkDescriptorSetLayout {
self.pool.vk_handle() self.pool.vk_handle()
} }
} }
impl<'a> Drop for DescriptorSet<'a> { impl<'device, 'handle> Drop for DescriptorSet<'device, 'handle> {
fn drop(&mut self) { fn drop(&mut self) {
if let Err(error) = self if let Err(error) = self
.device .device
@ -363,7 +339,7 @@ mod test {
.set_descriptor_set_count(DESCRIPTOR_COUNT) .set_descriptor_set_count(DESCRIPTOR_COUNT)
.build(&device)?; .build(&device)?;
let descriptors: Vec<DescriptorSet<'_>> = (0..DESCRIPTOR_COUNT) let descriptors: Vec<DescriptorSet<'_, '_>> = (0..DESCRIPTOR_COUNT)
.map(|_| { .map(|_| {
let set = descriptor_pool.prepare_set().allocate(); let set = descriptor_pool.prepare_set().allocate();

View file

@ -2,22 +2,22 @@ use crate::prelude::*;
use anyhow::Result; use anyhow::Result;
pub struct FramebufferBuilder<'a, 'b> { pub struct FramebufferBuilder<'device, 'renderpass, 'image> {
render_pass: Option<&'b RenderPass<'a>>, render_pass: Option<&'renderpass RenderPass<'device>>,
attachments: Vec<&'a Image<'a>>, attachments: Vec<&'image Image<'device>>,
width: u32, width: u32,
height: u32, height: u32,
layers: u32, layers: u32,
} }
impl<'a, 'b> FramebufferBuilder<'a, 'b> { impl<'device, 'renderpass, 'image> FramebufferBuilder<'device, 'renderpass, 'image> {
pub fn set_render_pass(mut self, render_pass: &'b RenderPass<'a>) -> Self { pub fn set_render_pass(mut self, render_pass: &'renderpass RenderPass<'device>) -> Self {
self.render_pass = Some(render_pass); self.render_pass = Some(render_pass);
self self
} }
pub fn add_attachment(mut self, image: &'a Image<'a>) -> Self { pub fn add_attachment(mut self, image: &'image Image<'device>) -> Self {
self.attachments.push(image); self.attachments.push(image);
self self
@ -41,7 +41,7 @@ impl<'a, 'b> FramebufferBuilder<'a, 'b> {
self self
} }
pub fn build(mut self, device: &'a Device) -> Result<Framebuffer<'a>> { pub fn build(mut self, device: &'device Device) -> Result<Framebuffer<'device, 'image>> {
if self.attachments.is_empty() { if self.attachments.is_empty() {
panic!("no attachments added!"); panic!("no attachments added!");
} }
@ -90,17 +90,17 @@ impl<'a, 'b> FramebufferBuilder<'a, 'b> {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct Framebuffer<'a> { pub struct Framebuffer<'device, 'image> {
device: &'a Device, device: &'device Device,
framebuffer: VkFramebuffer, framebuffer: VkFramebuffer,
images: Vec<&'a Image<'a>>, images: Vec<&'image Image<'device>>,
width: u32, width: u32,
height: u32, height: u32,
} }
impl<'a> Framebuffer<'a> { impl<'device, 'image> Framebuffer<'device, 'image> {
pub fn builder<'b>() -> FramebufferBuilder<'a, 'b> { pub fn builder<'renderpass>() -> FramebufferBuilder<'device, 'renderpass, 'image> {
FramebufferBuilder { FramebufferBuilder {
render_pass: None, render_pass: None,
attachments: Vec::new(), attachments: Vec::new(),
@ -118,11 +118,11 @@ impl<'a> Framebuffer<'a> {
self.height self.height
} }
pub fn attachments(&self) -> &[&'a Image<'a>] { pub fn attachments(&self) -> &[&'image Image<'device>] {
&self.images &self.images
} }
pub fn image(&self, index: usize) -> &Image<'a> { pub fn image(&self, index: usize) -> &Image<'device> {
&self.images[index] &self.images[index]
} }
@ -131,15 +131,15 @@ impl<'a> Framebuffer<'a> {
} }
} }
impl<'a> VulkanDevice for Framebuffer<'a> { impl<'device, 'image> VulkanDevice for Framebuffer<'device, 'image> {
fn device(&self) -> &Device { fn device(&self) -> &Device {
&self.device &self.device
} }
} }
impl_vk_handle!(Framebuffer<'a>, VkFramebuffer, framebuffer); impl_vk_handle!(Framebuffer<'device, 'image>, VkFramebuffer, framebuffer);
impl<'a> Drop for Framebuffer<'a> { impl<'device, 'image> Drop for Framebuffer<'device, 'image> {
fn drop(&mut self) { fn drop(&mut self) {
self.device.destroy_framebuffer(self.framebuffer); self.device.destroy_framebuffer(self.framebuffer);
} }

View file

@ -385,7 +385,7 @@ impl<'a> ImageBuilder<'a> {
fn create_from_source( fn create_from_source(
device: &'a Device, device: &'a Device,
queue: &Mutex<Queue<'a>>, queue: &'a Mutex<Queue<'a>>,
info: &ImageCreateInfo<'a>, info: &ImageCreateInfo<'a>,
sampler: Option<Arc<Sampler>>, sampler: Option<Arc<Sampler>>,
mut view_ci: VkImageViewCreateInfo, mut view_ci: VkImageViewCreateInfo,
@ -400,8 +400,8 @@ impl<'a> ImageBuilder<'a> {
let image_view = device.create_image_view(&view_ci)?; let image_view = device.create_image_view(&view_ci)?;
Ok(Image { Ok(Image {
device: device.clone(), device,
queue: queue.clone(), queue,
image, image,
image_view, image_view,
@ -448,7 +448,7 @@ impl<'a> ImageBuilder<'a> {
fn optimize_fill( fn optimize_fill(
device: &'a Device, device: &'a Device,
queue: &Mutex<Queue<'a>>, queue: &'a Mutex<Queue<'a>>,
data: &[RawBuffer], data: &[RawBuffer],
image: &Image<'a>, image: &Image<'a>,
) -> Result<()> { ) -> Result<()> {
@ -952,14 +952,14 @@ fn into_layout<'a>(image: &Image<'a>, layout: VkImageLayout) -> Result<()> {
fn copy_buffer_to_image<'a, T: ReprC + Send + Sync + 'static>( fn copy_buffer_to_image<'a, T: ReprC + Send + Sync + 'static>(
image: &Image<'a>, image: &Image<'a>,
device: &'a Device, device: &'a Device,
queue: &Mutex<Queue<'a>>, queue: &'a Mutex<Queue<'a>>,
buffer: &Buffer<'a, T>, buffer: &Buffer<'a, T>,
) -> Result<()> ) -> Result<()>
where where
T: Copy, T: Copy,
{ {
// create a new command buffer // create a new command buffer
let mut command_buffer = CommandBuffer::new_primary().build(device.clone(), queue.clone())?; let mut command_buffer = CommandBuffer::new_primary().build(device, queue)?;
{ {
// begin recording into this command buffer // begin recording into this command buffer
@ -1046,7 +1046,7 @@ where
fn copy_images_to_imagearray<'a>( fn copy_images_to_imagearray<'a>(
device: &'a Device, device: &'a Device,
queue: &Mutex<Queue<'a>>, queue: &'a Mutex<Queue<'a>>,
image_array: &Image<'a>, image_array: &Image<'a>,
images: &[Image<'a>], images: &[Image<'a>],
) -> Result<()> { ) -> Result<()> {
@ -1118,10 +1118,10 @@ fn copy_images_to_imagearray<'a>(
Ok(()) Ok(())
} }
fn copy_image_to_image<'a>( fn copy_image_to_image<'device, 'pipeline, 'cbuffer>(
buffer_recorder: &mut CommandBufferRecorder<'_, '_>, buffer_recorder: &mut CommandBufferRecorder<'device, 'pipeline, 'cbuffer>,
src_image: &Image<'a>, src_image: &Image<'device>,
dst_image: &Image<'a>, dst_image: &Image<'device>,
mip_level: u32, mip_level: u32,
dst_layer: u32, dst_layer: u32,
) { ) {
@ -1180,9 +1180,9 @@ fn copy_image_to_image<'a>(
); );
} }
fn blit_mip_maps<'a>( fn blit_mip_maps<'device, 'pipeline, 'cbuffer>(
buffer_recorder: &mut CommandBufferRecorder<'_, '_>, buffer_recorder: &mut CommandBufferRecorder<'device, 'pipeline, 'cbuffer>,
image: &Image<'a>, image: &Image<'device>,
target_image_layout: VkImageLayout, target_image_layout: VkImageLayout,
) { ) {
let mut mip_width = image.width(); let mut mip_width = image.width();

View file

@ -12,8 +12,8 @@ pub(crate) struct ShaderBindingTableBuilder {
hit_group_entries: Vec<ShaderBindingTableEntry>, hit_group_entries: Vec<ShaderBindingTableEntry>,
} }
pub struct ShaderBindingTable<'a> { pub struct ShaderBindingTable<'device> {
_sbt_buffer: Buffer<'a, RawBuffer>, _sbt_buffer: Buffer<'device, RawBuffer>,
raygen_shader_binding_table: VkStridedDeviceAddressRegionKHR, raygen_shader_binding_table: VkStridedDeviceAddressRegionKHR,
miss_shader_binding_table: VkStridedDeviceAddressRegionKHR, miss_shader_binding_table: VkStridedDeviceAddressRegionKHR,
@ -21,7 +21,7 @@ pub struct ShaderBindingTable<'a> {
callable_shader_binding_table: VkStridedDeviceAddressRegionKHR, callable_shader_binding_table: VkStridedDeviceAddressRegionKHR,
} }
impl<'a> ShaderBindingTable<'a> { impl<'device> ShaderBindingTable<'device> {
pub fn raygen_shader_binding_table(&self) -> &VkStridedDeviceAddressRegionKHR { pub fn raygen_shader_binding_table(&self) -> &VkStridedDeviceAddressRegionKHR {
&self.raygen_shader_binding_table &self.raygen_shader_binding_table
} }
@ -39,7 +39,7 @@ impl<'a> ShaderBindingTable<'a> {
} }
fn create( fn create(
sbt_buffer: Buffer<'a, RawBuffer>, sbt_buffer: Buffer<'device, RawBuffer>,
ray_gen_entry_size: VkDeviceSize, ray_gen_entry_size: VkDeviceSize,
ray_gen_entry_count: VkDeviceSize, ray_gen_entry_count: VkDeviceSize,
miss_offset: VkDeviceSize, miss_offset: VkDeviceSize,

View file

@ -5,25 +5,28 @@ use std::sync::atomic::{AtomicU32, AtomicUsize, Ordering::SeqCst};
pub mod sub_pass; pub mod sub_pass;
use sub_pass::{AttachmentInfo, AttachmentInfoUsage, SubPass}; use sub_pass::{AttachmentInfo, AttachmentInfoUsage, SubPass};
pub struct RenderTargetBuilder<'a> { pub struct RenderTargetBuilder<'device, 'image> {
old_render_target: Option<RenderTarget<'a>>, old_render_target: Option<RenderTarget<'device, 'image>>,
sub_passes: Vec<SubPass<'a>>, sub_passes: Vec<SubPass<'device>>,
} }
impl<'a> RenderTargetBuilder<'a> { impl<'device, 'image> RenderTargetBuilder<'device, 'image> {
pub fn add_sub_pass(mut self, sub_pass: SubPass<'a>) -> Self { pub fn add_sub_pass(mut self, sub_pass: SubPass<'device>) -> Self {
self.sub_passes.push(sub_pass); self.sub_passes.push(sub_pass);
self self
} }
pub fn preserve_old_render_pass(mut self, render_target: RenderTarget<'a>) -> Self { pub fn preserve_old_render_pass(
mut self,
render_target: RenderTarget<'device, 'image>,
) -> Self {
self.old_render_target = Some(render_target); self.old_render_target = Some(render_target);
self self
} }
pub fn build(self, device: &'a Device) -> Result<RenderTarget<'a>> { pub fn build(self, device: &'device Device) -> Result<RenderTarget<'device, 'image>> {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
{ {
// sub passes must not be empty // sub passes must not be empty
@ -182,10 +185,10 @@ impl<'a> RenderTargetBuilder<'a> {
}) })
} }
fn create_framebuffers<'b>( fn create_framebuffers<'handle>(
render_pass: &'b RenderPass<'a>, render_pass: &'handle RenderPass<'device>,
sub_passes: &'b [SubPass<'a>], sub_passes: &'handle [SubPass<'device>],
) -> Result<Vec<Framebuffer<'a>>> { ) -> Result<Vec<Framebuffer<'device, 'image>>> {
let extent = sub_passes[0].extent(); let extent = sub_passes[0].extent();
(0..Self::max_images(sub_passes)) (0..Self::max_images(sub_passes))
@ -208,7 +211,7 @@ impl<'a> RenderTargetBuilder<'a> {
} }
#[inline] #[inline]
fn max_images(sub_passes: &[SubPass<'a>]) -> usize { fn max_images(sub_passes: &[SubPass<'device>]) -> usize {
let mut max_images = 0; let mut max_images = 0;
for sub_pass in sub_passes.iter() { for sub_pass in sub_passes.iter() {
@ -218,7 +221,10 @@ impl<'a> RenderTargetBuilder<'a> {
max_images max_images
} }
fn verify_setups(old_sub_passes: &[SubPass<'a>], new_sub_passes: &[SubPass<'a>]) -> bool { fn verify_setups(
old_sub_passes: &[SubPass<'device>],
new_sub_passes: &[SubPass<'device>],
) -> bool {
if old_sub_passes.len() != new_sub_passes.len() { if old_sub_passes.len() != new_sub_passes.len() {
return false; return false;
} }
@ -233,9 +239,9 @@ impl<'a> RenderTargetBuilder<'a> {
} }
#[inline] #[inline]
fn map_attachment<'b, F>(&'b self, mut f: F) fn map_attachment<'handle, F>(&'handle self, mut f: F)
where where
F: FnMut(&'b AttachmentInfo<'a>) -> (), F: FnMut(&'handle AttachmentInfo<'device>) -> (),
{ {
for sub_pass in self.sub_passes.iter() { for sub_pass in self.sub_passes.iter() {
for attachment in sub_pass.attachments().iter() { for attachment in sub_pass.attachments().iter() {
@ -257,36 +263,36 @@ struct SubPassAttachmentReferences {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct RenderTarget<'a> { pub struct RenderTarget<'device, 'image> {
render_pass: RenderPass<'a>, render_pass: RenderPass<'device>,
framebuffers: Vec<Framebuffer<'a>>, framebuffers: Vec<Framebuffer<'device, 'image>>,
clear_values: Vec<VkClearValue>, clear_values: Vec<VkClearValue>,
extent: VkExtent2D, extent: VkExtent2D,
sub_passes: Vec<SubPass<'a>>, sub_passes: Vec<SubPass<'device>>,
current_subpass: AtomicU32, current_subpass: AtomicU32,
framebuffer_index: AtomicUsize, framebuffer_index: AtomicUsize,
} }
impl<'a> RenderTarget<'a> { impl<'device, 'image> RenderTarget<'device, 'image> {
pub fn builder() -> RenderTargetBuilder<'a> { pub fn builder() -> RenderTargetBuilder<'device, 'image> {
RenderTargetBuilder { RenderTargetBuilder {
old_render_target: None, old_render_target: None,
sub_passes: Vec::new(), sub_passes: Vec::new(),
} }
} }
pub fn render_pass(&self) -> &RenderPass<'a> { pub fn render_pass(&self) -> &RenderPass<'device> {
&self.render_pass &self.render_pass
} }
pub fn framebuffer(&self, index: usize) -> &Framebuffer<'a> { pub fn framebuffer(&self, index: usize) -> &Framebuffer<'device, 'image> {
&self.framebuffers[index] &self.framebuffers[index]
} }
pub fn sub_pass(&self, index: usize) -> &SubPass<'a> { pub fn sub_pass(&self, index: usize) -> &SubPass<'device> {
&self.sub_passes[index] &self.sub_passes[index]
} }
@ -309,7 +315,7 @@ impl<'a> RenderTarget<'a> {
pub fn begin( pub fn begin(
&self, &self,
buffer_recorder: &mut CommandBufferRecorder<'_, '_>, buffer_recorder: &mut CommandBufferRecorder<'device, '_, '_>,
subpass_content: VkSubpassContents, subpass_content: VkSubpassContents,
framebuffer_index: usize, framebuffer_index: usize,
) { ) {
@ -331,14 +337,14 @@ impl<'a> RenderTarget<'a> {
pub fn next_subpass( pub fn next_subpass(
&self, &self,
buffer_recorder: &mut CommandBufferRecorder<'_, '_>, buffer_recorder: &mut CommandBufferRecorder<'device, '_, '_>,
subpass_content: VkSubpassContents, subpass_content: VkSubpassContents,
) { ) {
buffer_recorder.next_subpass(subpass_content); buffer_recorder.next_subpass(subpass_content);
self.current_subpass.fetch_add(1, SeqCst); self.current_subpass.fetch_add(1, SeqCst);
} }
pub fn end(&self, buffer_recorder: &mut CommandBufferRecorder<'_, '_>) { pub fn end(&self, buffer_recorder: &mut CommandBufferRecorder<'device, '_, '_>) {
debug_assert_eq!( debug_assert_eq!(
self.current_subpass.load(SeqCst) as usize, self.current_subpass.load(SeqCst) as usize,
self.sub_passes.len() - 1 self.sub_passes.len() - 1

View file

@ -411,12 +411,12 @@ pub enum AttachmentInfoUsage {
} }
#[derive(Debug)] #[derive(Debug)]
pub enum AttachmentInfoImages<'a> { pub enum AttachmentInfoImages<'device> {
Owned(Vec<Image<'a>>), Owned(Vec<Image<'device>>),
Ref(Vec<&'a Image<'a>>), Ref(Vec<&'device Image<'device>>),
} }
impl<'a> AttachmentInfoImages<'a> { impl<'device> AttachmentInfoImages<'device> {
fn len(&self) -> usize { fn len(&self) -> usize {
match self { match self {
AttachmentInfoImages::Owned(v) => v.len(), AttachmentInfoImages::Owned(v) => v.len(),
@ -432,20 +432,20 @@ impl<'a> AttachmentInfoImages<'a> {
} }
} }
impl<'a> From<Vec<Image<'a>>> for AttachmentInfoImages<'a> { impl<'device> From<Vec<Image<'device>>> for AttachmentInfoImages<'device> {
fn from(value: Vec<Image<'a>>) -> Self { fn from(value: Vec<Image<'device>>) -> Self {
Self::Owned(value) Self::Owned(value)
} }
} }
impl<'a> From<Vec<&'a Image<'a>>> for AttachmentInfoImages<'a> { impl<'device> From<Vec<&'device Image<'device>>> for AttachmentInfoImages<'device> {
fn from(value: Vec<&'a Image<'a>>) -> Self { fn from(value: Vec<&'device Image<'device>>) -> Self {
Self::Ref(value) Self::Ref(value)
} }
} }
impl<'a> Index<usize> for AttachmentInfoImages<'a> { impl<'device> Index<usize> for AttachmentInfoImages<'device> {
type Output = Image<'a>; type Output = Image<'device>;
fn index(&self, index: usize) -> &Self::Output { fn index(&self, index: usize) -> &Self::Output {
match self { match self {
@ -484,17 +484,17 @@ impl<'a> AttachmentInfo<'a> {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct SubPass<'a> { pub struct SubPass<'device> {
extent: VkExtent2D, extent: VkExtent2D,
input_info: Option<InputAttachmentInfo>, input_info: Option<InputAttachmentInfo>,
attachments: Vec<AttachmentInfo<'a>>, attachments: Vec<AttachmentInfo<'device>>,
output_usage: VkAccessFlagBits, output_usage: VkAccessFlagBits,
} }
impl<'a> SubPass<'a> { impl<'device> SubPass<'device> {
pub fn builder<'b>(width: u32, height: u32) -> SubPassBuilder<'a, 'b> { pub fn builder<'b>(width: u32, height: u32) -> SubPassBuilder<'device, 'b> {
SubPassBuilder { SubPassBuilder {
width, width,
height, height,
@ -526,7 +526,7 @@ impl<'a> SubPass<'a> {
self.extent self.extent
} }
pub fn attachments(&self) -> &[AttachmentInfo<'a>] { pub fn attachments(&self) -> &[AttachmentInfo<'device>] {
&self.attachments &self.attachments
} }

View file

@ -4,24 +4,24 @@ use anyhow::Result;
use std::sync::Mutex; use std::sync::Mutex;
use std::time::Duration; use std::time::Duration;
pub struct SingleSubmit<'a, F, T> pub struct SingleSubmit<'device, 'a, F, T>
where where
F: FnOnce(&mut CommandBufferRecorder<'_, '_>) -> Result<T>, F: FnOnce(&mut CommandBufferRecorder<'device, '_, '_>) -> Result<T>,
{ {
command_buffer: &'a mut CommandBuffer<'a>, command_buffer: &'a mut CommandBuffer<'device>,
queue: &'a Mutex<Queue<'a>>, queue: &'a Mutex<Queue<'device>>,
f: F, f: F,
timeout: Option<Duration>, timeout: Option<Duration>,
} }
impl<'a, F, T> SingleSubmit<'a, F, T> impl<'device, 'a, F, T> SingleSubmit<'device, 'a, F, T>
where where
F: FnOnce(&mut CommandBufferRecorder<'_, '_>) -> Result<T>, F: FnOnce(&mut CommandBufferRecorder<'device, '_, '_>) -> Result<T>,
{ {
pub fn builder( pub fn builder(
command_buffer: &'a mut CommandBuffer<'a>, command_buffer: &'a mut CommandBuffer<'device>,
queue: &'a Mutex<Queue<'a>>, queue: &'a Mutex<Queue<'device>>,
f: F, f: F,
) -> Self { ) -> Self {
SingleSubmit { SingleSubmit {
@ -39,7 +39,7 @@ where
self self
} }
pub fn submit(mut self) -> Result<T> { pub fn submit(self) -> Result<T> {
let result = { let result = {
let mut buffer_recorder = self.command_buffer.begin(VkCommandBufferBeginInfo::new( let mut buffer_recorder = self.command_buffer.begin(VkCommandBufferBeginInfo::new(
VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,