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 {
pub fn add_instance<'a>(
pub fn add_instance<'device>(
mut self,
blas: &AccelerationStructure<'a>,
blas: &AccelerationStructure<'device>,
transform: Option<Matrix4<f32>>,
instance_flags: impl Into<VkGeometryInstanceFlagBitsKHR>,
) -> Self {
@ -122,11 +122,11 @@ impl AccelerationStructureBuilder {
self
}
pub fn build<'a>(
pub fn build<'device, 'pipeline, 'cbuffer>(
self,
device: &'a Device,
recorder: &mut CommandBufferRecorder<'_, '_>,
) -> Result<AccelerationStructure<'a>> {
device: &'device Device,
recorder: &mut CommandBufferRecorder<'device, 'pipeline, 'cbuffer>,
) -> Result<AccelerationStructure<'device>> {
let build_flags = VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR
| VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR;
@ -270,21 +270,21 @@ impl AccelerationStructureBuilder {
}
}
pub struct AccelerationStructure<'a> {
device: &'a Device,
pub struct AccelerationStructure<'device> {
device: &'device Device,
acceleration_structure: VkAccelerationStructureKHR,
result_buffer: Buffer<'a, RawBuffer>,
scratch_buffer: Mutex<Buffer<'a, RawBuffer>>,
result_buffer: Buffer<'device, RawBuffer>,
scratch_buffer: Mutex<Buffer<'device, RawBuffer>>,
update_scratch_buffer_size: VkDeviceSize,
generation_data: AccelerationStructureGenerationData<'a>,
generation_data: AccelerationStructureGenerationData<'device>,
build_flags: VkBuildAccelerationStructureFlagBitsKHR,
}
impl<'a> AccelerationStructure<'a> {
impl<'device> AccelerationStructure<'device> {
pub fn bottom_level() -> AccelerationStructureBuilder {
AccelerationStructureBuilder {
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
}
@ -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.device,
self.update_scratch_buffer_size,
@ -330,9 +333,9 @@ impl<'a> AccelerationStructure<'a> {
)
}
fn generate(
fn generate<'pipeline, 'cbuffer>(
&self,
buffer_recorder: &mut CommandBufferRecorder<'_, '_>,
buffer_recorder: &mut CommandBufferRecorder<'device, 'pipeline, 'cbuffer>,
src: VkAccelerationStructureKHR,
mode: VkBuildAccelerationStructureModeKHR,
) -> Result<()> {
@ -390,10 +393,10 @@ impl<'a> AccelerationStructure<'a> {
#[inline]
fn create_scratch_buffer(
device: &'a Device,
device: &'device Device,
size: VkDeviceSize,
alignment: VkDeviceSize,
) -> Result<Buffer<'a, RawBuffer>> {
) -> Result<Buffer<'device, RawBuffer>> {
Buffer::builder()
.set_usage(
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
@ -418,11 +421,11 @@ impl_vk_handle!(
acceleration_structure
);
enum AccelerationStructureGenerationData<'a> {
enum AccelerationStructureGenerationData<'device> {
TopLevel(
Vec<VkAccelerationStructureInstanceKHR>,
VkAccelerationStructureGeometryKHR,
Buffer<'a, VkAccelerationStructureInstanceKHR>,
Buffer<'device, VkAccelerationStructureInstanceKHR>,
),
BottomLevel(
Vec<VkAccelerationStructureGeometryKHR>,
@ -430,26 +433,26 @@ enum AccelerationStructureGenerationData<'a> {
),
}
impl<'a>
impl<'device>
From<(
Vec<VkAccelerationStructureInstanceKHR>,
VkAccelerationStructureGeometryKHR,
Buffer<'a, VkAccelerationStructureInstanceKHR>,
)> for AccelerationStructureGenerationData<'a>
Buffer<'device, VkAccelerationStructureInstanceKHR>,
)> for AccelerationStructureGenerationData<'device>
{
fn from(
(instances, geometry, buffer): (
Vec<VkAccelerationStructureInstanceKHR>,
VkAccelerationStructureGeometryKHR,
Buffer<'a, VkAccelerationStructureInstanceKHR>,
Buffer<'device, VkAccelerationStructureInstanceKHR>,
),
) -> Self {
Self::TopLevel(instances, geometry, buffer)
}
}
impl<'a> From<(Vec<VkAccelerationStructureGeometryKHR>, Vec<u32>)>
for AccelerationStructureGenerationData<'a>
impl<'device> From<(Vec<VkAccelerationStructureGeometryKHR>, Vec<u32>)>
for AccelerationStructureGenerationData<'device>
{
fn from(
(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)]
pub struct Buffer<'a, T: ReprC> {
device: &'a Device,
pub struct Buffer<'device, T: ReprC> {
device: &'device Device,
buffer: VkBuffer,
memory: Memory<'a, T>,
memory: Memory<'device, T>,
_usage: VkBufferUsageFlagBits,
@ -133,7 +133,7 @@ pub struct Buffer<'a, T: ReprC> {
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<()> {
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)
}
pub fn into_device_local<'b>(
pub fn into_device_local<'pipeline, 'cbuffer>(
&self,
buffer_recorder: &mut CommandBufferRecorder<'a, 'b>,
buffer_recorder: &mut CommandBufferRecorder<'device, 'pipeline, 'cbuffer>,
access_mask: impl Into<VkAccessFlagBits>,
stage: impl Into<VkPipelineStageFlagBits>,
usage: impl Into<VkBufferUsageFlagBits>,
) -> Result<Buffer<'a, T>> {
) -> Result<Buffer<'device, T>> {
let new_usage = usage.into() | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
let device_local_buffer = Buffer::builder()

View file

@ -6,7 +6,6 @@ use crate::prelude::*;
use anyhow::Result;
use std::any::Any;
use std::sync::Mutex;
pub struct QueryEnable {
@ -53,36 +52,33 @@ impl CommandBufferBuilder {
buffer: command_buffer,
calls: 0,
stored_handles: Vec::new(),
})
}
}
#[derive(Debug)]
pub struct CommandBuffer<'a> {
device: &'a Device,
pool: CommandPool<'a>,
pub struct CommandBuffer<'device> {
device: &'device Device,
pool: CommandPool<'device>,
buffer: VkCommandBuffer,
calls: usize,
stored_handles: Vec<&'a (dyn Any + Send + Sync)>,
}
#[derive(Debug)]
pub struct CommandBufferRecorder<'a, 'b> {
device: &'a Device,
pub struct CommandBufferRecorder<'device, 'pipeline, 'cbuffer> {
device: &'device Device,
sub_pass: u32,
pipeline: Option<&'a Pipeline<'a>>,
pipeline: Option<&'pipeline Pipeline<'device>>,
calls: &'b mut usize,
calls: &'cbuffer mut usize,
buffer: VkCommandBuffer,
handles_lock: &'b mut Vec<&'a (dyn Any + Send + Sync)>,
}
impl_vk_handle!(CommandBuffer<'a>, VkCommandBuffer, buffer);
impl<'a> CommandBuffer<'a> {
impl<'device> CommandBuffer<'device> {
pub fn new_primary() -> CommandBufferBuilder {
CommandBufferBuilder {
buffer_level: VK_COMMAND_BUFFER_LEVEL_PRIMARY,
@ -105,17 +101,12 @@ impl<'a> CommandBuffer<'a> {
self.calls
}
pub fn begin<'b>(
&'a mut self,
pub fn begin<'pipeline, 'cbuffer>(
&'cbuffer mut self,
begin_info: VkCommandBufferBeginInfo,
) -> Result<CommandBufferRecorder<'a, 'b>>
where
'b: 'a,
'a: 'b,
{
) -> Result<CommandBufferRecorder<'device, 'pipeline, 'cbuffer>> {
self.device.begin_command_buffer(self.buffer, &begin_info)?;
self.stored_handles.clear();
self.calls = 0;
Ok(CommandBufferRecorder {
@ -125,7 +116,6 @@ impl<'a> CommandBuffer<'a> {
calls: &mut self.calls,
buffer: self.buffer,
handles_lock: &mut self.stored_handles,
})
}
@ -162,10 +152,10 @@ impl<'a> CommandBuffer<'a> {
}
}
pub fn inheritance_info(
render_pass: Option<&RenderPass<'a>>,
pub fn inheritance_info<'image>(
render_pass: Option<&RenderPass<'device>>,
sub_pass: Option<u32>,
framebuffer: Option<&Framebuffer<'a>>,
framebuffer: Option<&Framebuffer<'device, 'image>>,
query_enable: Option<QueryEnable>,
) -> VkCommandBufferInheritanceInfo {
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(
&mut self,
&'me mut self,
src_stage_mask: impl Into<VkPipelineStageFlagBits>,
dst_stage_mask: impl Into<VkPipelineStageFlagBits>,
dependency_flags: impl Into<VkDependencyFlagBits>,
@ -212,7 +205,7 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn memory_barrier(
&mut self,
&'me mut self,
src_access_mask: impl Into<VkAccessFlagBits>,
src_stage: VkPipelineStageFlags,
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>(
&'a mut self,
buffer: &'b Buffer<'a, T>,
&'me mut self,
buffer: &'handle Buffer<'device, T>,
src_access_mask: impl Into<VkAccessFlagBits>,
src_stage: impl Into<VkPipelineStageFlagBits>,
dst_access_mask: impl Into<VkAccessFlagBits>,
dst_stage: impl Into<VkPipelineStageFlagBits>,
) where
'b: 'a,
{
self.handles_lock.push(buffer);
) {
self.pipeline_barrier(
src_stage,
dst_stage,
@ -259,18 +248,18 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn image_barrier(
&mut self,
image: &Image<'a>,
&'me mut self,
image: &'handle Image<'device>,
old_image_layout: VkImageLayout,
src_stage: impl Into<VkPipelineStageFlagBits>,
new_image_layout: VkImageLayout,
dst_stage: impl Into<VkPipelineStageFlagBits>,
) {
) where
'handle: 'me,
{
let src_access_mask = Image::src_layout_to_access(old_image_layout);
let dst_access_mask = Image::dst_layout_to_access(new_image_layout);
self.handles_lock.push(image);
self.pipeline_barrier(
src_stage,
dst_stage,
@ -293,16 +282,14 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn image_barrier_auto_stage(
&mut self,
image: &Image<'a>,
&'me mut self,
image: &'handle Image<'device>,
old_image_layout: VkImageLayout,
new_image_layout: VkImageLayout,
) {
let src_access_mask = Image::src_layout_to_access(old_image_layout);
let dst_access_mask = Image::dst_layout_to_access(new_image_layout);
self.handles_lock.push(image);
self.pipeline_barrier(
CommandBuffer::access_to_stage(src_access_mask),
CommandBuffer::access_to_stage(dst_access_mask),
@ -325,7 +312,7 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn begin_render_pass(
&mut self,
&'me mut self,
renderpass_begin_info: VkRenderPassBeginInfo,
subpass_contents: VkSubpassContents,
) {
@ -335,16 +322,13 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
.cmd_begin_render_pass(self.buffer, &renderpass_begin_info, subpass_contents);
}
pub fn begin_render_pass_full(
&mut self,
render_pass: &RenderPass<'a>,
framebuffer: &Framebuffer<'a>,
pub fn begin_render_pass_full<'image>(
&'me mut self,
render_pass: &'handle RenderPass<'device>,
framebuffer: &'handle Framebuffer<'device, 'image>,
clear_values: &[VkClearValue],
subpass_contents: VkSubpassContents,
) {
self.handles_lock.push(render_pass.clone());
self.handles_lock.push(framebuffer.clone());
self.sub_pass = 0;
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);
}
pub fn next_subpass(&mut self, subpass_contents: VkSubpassContents) {
pub fn next_subpass(&'me mut self, subpass_contents: VkSubpassContents) {
self.sub_pass += 1;
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);
}
pub fn bind_pipeline(&mut self, pipeline: &Pipeline<'a>) -> Result<()> {
self.handles_lock.push(pipeline);
pub fn bind_pipeline(&'me mut self, pipeline: &'pipeline Pipeline<'device>) -> Result<()> {
match pipeline.pipeline_type() {
PipelineType::Graphics => {
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(())
}
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;
let buffers: Vec<VkCommandBuffer> =
@ -413,7 +398,10 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
.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;
let (pipeline_bind_point, vk_layout) = {
@ -433,11 +421,7 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
let vk_descriptor_sets: Vec<VkDescriptorSet> = descriptor_sets
.iter()
.map(|ds: &&DescriptorSet<'a>| {
self.handles_lock.push((*ds).clone());
ds.vk_handle()
})
.map(|ds: &&DescriptorSet<'device, 'a>| ds.vk_handle())
.collect();
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.handles_lock.push(buffer);
self.device
.cmd_bind_vertex_buffers(self.buffer, 0, &[buffer.vk_handle()], &[0]);
}
pub fn bind_vertex_buffers_minimal<T: ReprC + Send + Sync + 'static>(
&mut self,
buffers: &[&Buffer<'a, T>],
&'me mut self,
buffers: &[&'handle Buffer<'device, T>],
) {
*self.calls += 1;
let vk_buffers: Vec<VkBuffer> = buffers
.iter()
.map(|b: &&Buffer<'a, T>| {
self.handles_lock.push((*b).clone());
b.vk_handle()
})
.map(|b: &&Buffer<'device, T>| b.vk_handle())
.collect();
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>(
&mut self,
buffer: &Buffer<'a, T>,
&'me mut self,
buffer: &'handle Buffer<'device, T>,
offset: VkDeviceSize,
index_type: VkIndexType,
) {
*self.calls += 1;
self.handles_lock.push(buffer);
self.device
.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);
}
pub fn set_scissor(&self, scissors: &[VkRect2D]) {
pub fn set_scissor(&'me self, scissors: &[VkRect2D]) {
self.device.cmd_set_scissor(self.buffer, 0, scissors);
}
pub fn draw(
&self,
&'me mut self,
vertex_count: u32,
instance_count: 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.device.cmd_draw(self.buffer, vertex_count, 1, 0, 0);
}
pub fn draw_indexed(
&self,
&'me mut self,
index_count: u32,
instance_count: 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.device
.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;
let pipeline = match &self.pipeline {
@ -572,16 +555,14 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn set_image_layout(
&mut self,
image: &Image<'a>,
&'me mut self,
image: &'handle Image<'device>,
new_image_layout: VkImageLayout,
subresource_range: VkImageSubresourceRange,
) {
let src_access = Image::src_layout_to_access(image.image_layout());
let dst_access = Image::dst_layout_to_access(new_image_layout);
self.handles_lock.push(image);
self.pipeline_barrier(
CommandBuffer::access_to_stage(src_access),
CommandBuffer::access_to_stage(dst_access),
@ -603,12 +584,14 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
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 dst_access = Image::dst_layout_to_access(new_image_layout);
self.handles_lock.push(image);
self.pipeline_barrier(
CommandBuffer::access_to_stage(src_access),
CommandBuffer::access_to_stage(dst_access),
@ -631,63 +614,60 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
// TODO:
pub fn set_line_width(&self) {
pub fn set_line_width(&'me self) {
unimplemented!();
}
pub fn set_depth_bias(&self) {
pub fn set_depth_bias(&'me self) {
unimplemented!();
}
pub fn set_blend_constants(&self) {
pub fn set_blend_constants(&'me self) {
unimplemented!();
}
pub fn set_depth_bounds(&self) {
pub fn set_depth_bounds(&'me self) {
unimplemented!();
}
pub fn set_stencil_compare_mask(&self) {
pub fn set_stencil_compare_mask(&'me self) {
unimplemented!();
}
pub fn set_stencil_write_mask(&self) {
pub fn set_stencil_write_mask(&'me self) {
unimplemented!();
}
pub fn set_stencil_reference(&self) {
pub fn set_stencil_reference(&'me self) {
unimplemented!();
}
pub fn draw_indirect(&self) {
pub fn draw_indirect(&'me self) {
unimplemented!();
}
pub fn draw_indexed_indirect(&self) {
pub fn draw_indexed_indirect(&'me self) {
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.device.cmd_dispatch(self.buffer, x, y, z);
}
pub fn dispatch_indirect(&self) {
pub fn dispatch_indirect(&'me self) {
unimplemented!();
}
pub fn copy_buffer<T: ReprC + Send + Sync + 'static, U: ReprC + Send + Sync + 'static>(
&mut self,
src_buffer: &Buffer<'a, T>,
dst_buffer: &Buffer<'a, U>,
&'me mut self,
src_buffer: &'handle Buffer<'device, T>,
dst_buffer: &'handle Buffer<'device, U>,
regions: &[VkBufferCopy],
) {
*self.calls += 1;
self.handles_lock.push(src_buffer);
self.handles_lock.push(dst_buffer);
self.device.cmd_copy_buffer(
self.buffer,
src_buffer.vk_handle(),
@ -697,18 +677,15 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn copy_image(
&mut self,
src_image: &Image<'a>,
dst_image: &Image<'a>,
&'me mut self,
src_image: &'handle Image<'device>,
dst_image: &'handle Image<'device>,
src_layout: VkImageLayout,
dst_layout: VkImageLayout,
regions: &[VkImageCopy],
) {
*self.calls += 1;
self.handles_lock.push(src_image);
self.handles_lock.push(dst_image);
self.device.cmd_copy_image(
self.buffer,
src_image.vk_handle(),
@ -720,14 +697,11 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn blit_complete(
&mut self,
src_image: &Image<'a>,
dst_image: &Image<'a>,
&'me mut self,
src_image: &'handle Image<'device>,
dst_image: &'handle Image<'device>,
filter: VkFilter,
) {
self.handles_lock.push(src_image);
self.handles_lock.push(dst_image);
let image_blit = VkImageBlit {
srcSubresource: src_image.full_resource_layers(),
srcOffsets: [
@ -760,9 +734,9 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn blit_image(
&mut self,
src_image: &Image<'a>,
dst_image: &Image<'a>,
&'me mut self,
src_image: &'handle Image<'device>,
dst_image: &'handle Image<'device>,
src_layout: VkImageLayout,
dst_layout: VkImageLayout,
regions: &[VkImageBlit],
@ -770,9 +744,6 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
) {
*self.calls += 1;
self.handles_lock.push(src_image);
self.handles_lock.push(dst_image);
self.device.cmd_blit_image(
self.buffer,
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>(
&mut self,
src_buffer: &Buffer<'a, T>,
dst_image: &Image<'a>,
&'me mut self,
src_buffer: &'handle Buffer<'device, T>,
dst_image: &'handle Image<'device>,
image_layout: VkImageLayout,
regions: &[VkBufferImageCopy],
) {
*self.calls += 1;
self.handles_lock.push(src_buffer);
self.handles_lock.push(dst_image);
self.device.cmd_copy_buffer_to_image(
self.buffer,
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>(
&mut self,
src_image: &Image<'a>,
&'me mut self,
src_image: &'handle Image<'device>,
image_layout: VkImageLayout,
dst_buffer: &Buffer<'a, T>,
dst_buffer: &'handle Buffer<'device, T>,
regions: &[VkBufferImageCopy],
) {
*self.calls += 1;
self.handles_lock.push(src_image);
self.handles_lock.push(dst_buffer);
self.device.cmd_copy_image_to_buffer(
self.buffer,
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!();
}
pub fn fill_buffer(&self) {
pub fn fill_buffer(&'me self) {
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.handles_lock.push(image);
self.device.cmd_clear_color_image(
self.buffer,
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!();
}
pub fn clear_attachments(&self) {
pub fn clear_attachments(&'me self) {
unimplemented!();
}
pub fn resolve_image(
&mut self,
src_image: &Image<'a>,
dst_image: &Image<'a>,
&'me mut self,
src_image: &'handle Image<'device>,
dst_image: &'handle Image<'device>,
regions: &[VkImageResolve],
) {
*self.calls += 1;
self.handles_lock.push(src_image);
self.handles_lock.push(dst_image);
self.device.cmd_resolve_image(
self.buffer,
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!();
}
pub fn reset_event(&self) {
pub fn reset_event(&'me self) {
unimplemented!();
}
pub fn wait_events(&self) {
pub fn wait_events(&'me self) {
unimplemented!();
}
pub fn begin_query(&self) {
pub fn begin_query(&'me self) {
unimplemented!();
}
pub fn end_query(&self) {
pub fn end_query(&'me self) {
unimplemented!();
}
pub fn reset_query_pool(&self) {
pub fn reset_query_pool(&'me self) {
unimplemented!();
}
pub fn write_timestamp(
&mut self,
query_pool: &QueryPool,
&'me mut self,
query_pool: &'handle QueryPool,
query: u32,
pipeline_stage: impl Into<VkPipelineStageFlagBits>,
) {
*self.calls += 1;
self.handles_lock.push(query_pool);
self.device
.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!();
}
}
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(
&mut self,
&'me mut self,
infos: &[VkAccelerationStructureBuildGeometryInfoKHR],
indirect_buffers: &[Buffer<'a, impl ReprC + Send + Sync + 'static>],
indirect_buffers: &[Buffer<'device, impl ReprC + Send + Sync + 'static>],
indirect_strides: &[u32],
max_primitive_counts: &[&u32],
) {
let mut device_addresses: Vec<VkDeviceAddress> = Vec::with_capacity(indirect_buffers.len());
for indirect_buffer in indirect_buffers.iter() {
self.handles_lock.push(indirect_buffer);
device_addresses.push(indirect_buffer.device_address().into());
}
@ -945,7 +909,7 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn build_acceleration_structures(
&self,
&'me self,
infos: &[VkAccelerationStructureBuildGeometryInfoKHR],
range_infos: &[&[VkAccelerationStructureBuildRangeInfoKHR]],
) {
@ -954,14 +918,11 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn copy_acceleration_structure(
&mut self,
src: &AccelerationStructure<'a>,
dst: &AccelerationStructure<'a>,
&'me mut self,
src: &'handle AccelerationStructure<'device>,
dst: &'handle AccelerationStructure<'device>,
mode: VkCopyAccelerationStructureModeKHR,
) {
self.handles_lock.push(src);
self.handles_lock.push(dst);
let info = VkCopyAccelerationStructureInfoKHR::new(src.vk_handle(), dst.vk_handle(), mode);
self.device
@ -969,13 +930,11 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn copy_acceleration_structure_to_memory(
&mut self,
src: &AccelerationStructure<'a>,
&'me mut self,
src: &'handle AccelerationStructure<'device>,
dst: VkDeviceOrHostAddressKHR,
mode: VkCopyAccelerationStructureModeKHR,
) {
self.handles_lock.push(src);
let info = VkCopyAccelerationStructureToMemoryInfoKHR::new(src.vk_handle(), dst, mode);
self.device
@ -983,13 +942,11 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn copy_memory_to_acceleration_structure(
&mut self,
&'me mut self,
src: VkDeviceOrHostAddressConstKHR,
dst: &AccelerationStructure<'a>,
dst: &'handle AccelerationStructure<'device>,
mode: VkCopyAccelerationStructureModeKHR,
) {
self.handles_lock.push(dst);
let info = VkCopyMemoryToAccelerationStructureInfoKHR::new(src, dst.vk_handle(), mode);
self.device
@ -997,12 +954,10 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn trace_rays_indirect(
&mut self,
sbt: ShaderBindingTable<'a>,
buffer: Buffer<'a, impl ReprC + Send + Sync + 'static>,
&'me mut self,
sbt: &'handle ShaderBindingTable<'device>,
buffer: &'handle Buffer<'device, impl ReprC + Send + Sync + 'static>,
) {
self.handles_lock.push(&buffer);
self.device.cmd_trace_rays_indirect(
self.buffer,
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.buffer,
sbt.raygen_shader_binding_table(),
@ -1027,20 +988,15 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
pub fn write_acceleration_structure_properties(
&mut self,
acceleration_structures: &[&AccelerationStructure<'a>],
&'me mut self,
acceleration_structures: &[&'handle AccelerationStructure<'device>],
query_type: VkQueryType,
query_pool: &QueryPool,
query_pool: &'handle QueryPool,
first_query: u32,
) {
self.handles_lock.push(query_pool);
let as_handles: Vec<VkAccelerationStructureKHR> = acceleration_structures
.iter()
.map(|a| {
self.handles_lock.push((*a).clone());
a.vk_handle()
})
.map(|a| a.vk_handle())
.collect();
self.device.cmd_write_acceleration_structure_properties(
@ -1053,20 +1009,20 @@ impl<'a, 'b> CommandBufferRecorder<'a, 'b> {
}
}
impl<'a> VulkanDevice for CommandBuffer<'a> {
fn device(&self) -> &Device {
impl<'device> VulkanDevice for CommandBuffer<'device> {
fn device(&self) -> &'device Device {
&self.device
}
}
impl<'a> Drop for CommandBuffer<'a> {
impl<'device> Drop for CommandBuffer<'device> {
fn drop(&mut self) {
self.device
.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) {
self.device.end_command_buffer(self.buffer).unwrap()
}

View file

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

View file

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

View file

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

View file

@ -385,7 +385,7 @@ impl<'a> ImageBuilder<'a> {
fn create_from_source(
device: &'a Device,
queue: &Mutex<Queue<'a>>,
queue: &'a Mutex<Queue<'a>>,
info: &ImageCreateInfo<'a>,
sampler: Option<Arc<Sampler>>,
mut view_ci: VkImageViewCreateInfo,
@ -400,8 +400,8 @@ impl<'a> ImageBuilder<'a> {
let image_view = device.create_image_view(&view_ci)?;
Ok(Image {
device: device.clone(),
queue: queue.clone(),
device,
queue,
image,
image_view,
@ -448,7 +448,7 @@ impl<'a> ImageBuilder<'a> {
fn optimize_fill(
device: &'a Device,
queue: &Mutex<Queue<'a>>,
queue: &'a Mutex<Queue<'a>>,
data: &[RawBuffer],
image: &Image<'a>,
) -> 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>(
image: &Image<'a>,
device: &'a Device,
queue: &Mutex<Queue<'a>>,
queue: &'a Mutex<Queue<'a>>,
buffer: &Buffer<'a, T>,
) -> Result<()>
where
T: Copy,
{
// 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
@ -1046,7 +1046,7 @@ where
fn copy_images_to_imagearray<'a>(
device: &'a Device,
queue: &Mutex<Queue<'a>>,
queue: &'a Mutex<Queue<'a>>,
image_array: &Image<'a>,
images: &[Image<'a>],
) -> Result<()> {
@ -1118,10 +1118,10 @@ fn copy_images_to_imagearray<'a>(
Ok(())
}
fn copy_image_to_image<'a>(
buffer_recorder: &mut CommandBufferRecorder<'_, '_>,
src_image: &Image<'a>,
dst_image: &Image<'a>,
fn copy_image_to_image<'device, 'pipeline, 'cbuffer>(
buffer_recorder: &mut CommandBufferRecorder<'device, 'pipeline, 'cbuffer>,
src_image: &Image<'device>,
dst_image: &Image<'device>,
mip_level: u32,
dst_layer: u32,
) {
@ -1180,9 +1180,9 @@ fn copy_image_to_image<'a>(
);
}
fn blit_mip_maps<'a>(
buffer_recorder: &mut CommandBufferRecorder<'_, '_>,
image: &Image<'a>,
fn blit_mip_maps<'device, 'pipeline, 'cbuffer>(
buffer_recorder: &mut CommandBufferRecorder<'device, 'pipeline, 'cbuffer>,
image: &Image<'device>,
target_image_layout: VkImageLayout,
) {
let mut mip_width = image.width();

View file

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

View file

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

View file

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

View file

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