Implement allocator traits for Arcs (#2068)

This commit is contained in:
marc0246 2022-10-31 08:08:59 +01:00 committed by GitHub
parent a5942a8d27
commit 45f3eb9ac8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 127 additions and 35 deletions

View File

@ -138,7 +138,7 @@ impl AmbientLightingSystem {
let layout = self.pipeline.layout().set_layouts().get(0).unwrap();
let descriptor_set = PersistentDescriptorSet::new(
&*self.descriptor_set_allocator,
&self.descriptor_set_allocator,
layout.clone(),
[WriteDescriptorSet::image_view(0, color_input)],
)
@ -151,7 +151,7 @@ impl AmbientLightingSystem {
};
let mut builder = AutoCommandBufferBuilder::secondary(
&*self.command_buffer_allocator,
&self.command_buffer_allocator,
self.gfx_queue.queue_family_index(),
CommandBufferUsage::MultipleSubmit,
CommandBufferInheritanceInfo {

View File

@ -149,7 +149,7 @@ impl DirectionalLightingSystem {
let layout = self.pipeline.layout().set_layouts().get(0).unwrap();
let descriptor_set = PersistentDescriptorSet::new(
&*self.descriptor_set_allocator,
&self.descriptor_set_allocator,
layout.clone(),
[
WriteDescriptorSet::image_view(0, color_input),
@ -165,7 +165,7 @@ impl DirectionalLightingSystem {
};
let mut builder = AutoCommandBufferBuilder::secondary(
&*self.command_buffer_allocator,
&self.command_buffer_allocator,
self.gfx_queue.queue_family_index(),
CommandBufferUsage::MultipleSubmit,
CommandBufferInheritanceInfo {

View File

@ -161,7 +161,7 @@ impl PointLightingSystem {
let layout = self.pipeline.layout().set_layouts().get(0).unwrap();
let descriptor_set = PersistentDescriptorSet::new(
&*self.descriptor_set_allocator,
&self.descriptor_set_allocator,
layout.clone(),
[
WriteDescriptorSet::image_view(0, color_input),
@ -178,7 +178,7 @@ impl PointLightingSystem {
};
let mut builder = AutoCommandBufferBuilder::secondary(
&*self.command_buffer_allocator,
&self.command_buffer_allocator,
self.gfx_queue.queue_family_index(),
CommandBufferUsage::MultipleSubmit,
CommandBufferInheritanceInfo {

View File

@ -155,7 +155,7 @@ impl FrameSystem {
// These images will be replaced the first time we call `frame()`.
let diffuse_buffer = ImageView::new_default(
AttachmentImage::with_usage(
&*memory_allocator,
&memory_allocator,
[1, 1],
Format::A2B10G10R10_UNORM_PACK32,
ImageUsage {
@ -169,7 +169,7 @@ impl FrameSystem {
.unwrap();
let normals_buffer = ImageView::new_default(
AttachmentImage::with_usage(
&*memory_allocator,
&memory_allocator,
[1, 1],
Format::R16G16B16A16_SFLOAT,
ImageUsage {
@ -183,7 +183,7 @@ impl FrameSystem {
.unwrap();
let depth_buffer = ImageView::new_default(
AttachmentImage::with_usage(
&*memory_allocator,
&memory_allocator,
[1, 1],
Format::D16_UNORM,
ImageUsage {
@ -206,21 +206,21 @@ impl FrameSystem {
let ambient_lighting_system = AmbientLightingSystem::new(
gfx_queue.clone(),
lighting_subpass.clone(),
&*memory_allocator,
&memory_allocator,
command_buffer_allocator.clone(),
descriptor_set_allocator.clone(),
);
let directional_lighting_system = DirectionalLightingSystem::new(
gfx_queue.clone(),
lighting_subpass.clone(),
&*memory_allocator,
&memory_allocator,
command_buffer_allocator.clone(),
descriptor_set_allocator.clone(),
);
let point_lighting_system = PointLightingSystem::new(
gfx_queue.clone(),
lighting_subpass,
&*memory_allocator,
&memory_allocator,
command_buffer_allocator.clone(),
descriptor_set_allocator,
);
@ -277,7 +277,7 @@ impl FrameSystem {
// render pass their content becomes undefined.
self.diffuse_buffer = ImageView::new_default(
AttachmentImage::with_usage(
&*self.memory_allocator,
&self.memory_allocator,
img_dims,
Format::A2B10G10R10_UNORM_PACK32,
ImageUsage {
@ -291,7 +291,7 @@ impl FrameSystem {
.unwrap();
self.normals_buffer = ImageView::new_default(
AttachmentImage::with_usage(
&*self.memory_allocator,
&self.memory_allocator,
img_dims,
Format::R16G16B16A16_SFLOAT,
ImageUsage {
@ -305,7 +305,7 @@ impl FrameSystem {
.unwrap();
self.depth_buffer = ImageView::new_default(
AttachmentImage::with_usage(
&*self.memory_allocator,
&self.memory_allocator,
img_dims,
Format::D16_UNORM,
ImageUsage {
@ -337,7 +337,7 @@ impl FrameSystem {
// Start the command buffer builder that will be filled throughout the frame handling.
let mut command_buffer_builder = AutoCommandBufferBuilder::primary(
&*self.command_buffer_allocator,
&self.command_buffer_allocator,
self.gfx_queue.queue_family_index(),
CommandBufferUsage::OneTimeSubmit,
)
@ -389,7 +389,9 @@ pub struct Frame<'a> {
// Framebuffer that was used when starting the render pass.
framebuffer: Arc<Framebuffer>,
// The command buffer builder that will be built during the lifetime of this object.
command_buffer_builder: Option<AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>>,
command_buffer_builder: Option<
AutoCommandBufferBuilder<PrimaryAutoCommandBuffer, Arc<StandardCommandBufferAllocator>>,
>,
// Matrix that was passed to `frame()`.
world_to_framebuffer: Matrix4<f32>,
}

View File

@ -98,7 +98,7 @@ impl TriangleDrawSystem {
/// Builds a secondary command buffer that draws the triangle on the current subpass.
pub fn draw(&self, viewport_dimensions: [u32; 2]) -> SecondaryAutoCommandBuffer {
let mut builder = AutoCommandBufferBuilder::secondary(
&*self.command_buffer_allocator,
&self.command_buffer_allocator,
self.gfx_queue.queue_family_index(),
CommandBufferUsage::MultipleSubmit,
CommandBufferInheritanceInfo {

View File

@ -81,7 +81,7 @@ impl FractalApp {
),
place_over_frame: RenderPassPlaceOverFrame::new(
gfx_queue,
&*memory_allocator,
&memory_allocator,
command_buffer_allocator,
descriptor_set_allocator,
image_format,

View File

@ -56,7 +56,7 @@ impl FractalComputePipeline {
];
let palette_size = colors.len() as i32;
let palette = CpuAccessibleBuffer::from_iter(
&*memory_allocator,
&memory_allocator,
BufferUsage {
storage_buffer: true,
..BufferUsage::empty()
@ -102,7 +102,7 @@ impl FractalComputePipeline {
colors.push([r, g, b, a]);
}
self.palette = CpuAccessibleBuffer::from_iter(
&*self.memory_allocator,
&self.memory_allocator,
BufferUsage {
storage_buffer: true,
..BufferUsage::empty()
@ -127,7 +127,7 @@ impl FractalComputePipeline {
let pipeline_layout = self.pipeline.layout();
let desc_layout = pipeline_layout.set_layouts().get(0).unwrap();
let set = PersistentDescriptorSet::new(
&*self.descriptor_set_allocator,
&self.descriptor_set_allocator,
desc_layout.clone(),
[
WriteDescriptorSet::image_view(0, image),
@ -136,7 +136,7 @@ impl FractalComputePipeline {
)
.unwrap();
let mut builder = AutoCommandBufferBuilder::primary(
&*self.command_buffer_allocator,
&self.command_buffer_allocator,
self.queue.queue_family_index(),
CommandBufferUsage::OneTimeSubmit,
)

View File

@ -151,7 +151,7 @@ impl PixelsDrawPipeline {
.unwrap();
PersistentDescriptorSet::new(
&*self.descriptor_set_allocator,
&self.descriptor_set_allocator,
layout.clone(),
[WriteDescriptorSet::image_view_sampler(
0,
@ -169,7 +169,7 @@ impl PixelsDrawPipeline {
image: Arc<dyn ImageViewAbstract>,
) -> SecondaryAutoCommandBuffer {
let mut builder = AutoCommandBufferBuilder::secondary(
&*self.command_buffer_allocator,
&self.command_buffer_allocator,
self.gfx_queue.queue_family_index(),
CommandBufferUsage::MultipleSubmit,
CommandBufferInheritanceInfo {

View File

@ -96,7 +96,7 @@ impl RenderPassPlaceOverFrame {
.unwrap();
// Create primary command buffer builder
let mut command_buffer_builder = AutoCommandBufferBuilder::primary(
&*self.command_buffer_allocator,
&self.command_buffer_allocator,
self.gfx_queue.queue_family_index(),
CommandBufferUsage::OneTimeSubmit,
)

View File

@ -129,7 +129,7 @@ impl GameOfLifeComputePipeline {
dead_color: [f32; 4],
) -> Box<dyn GpuFuture> {
let mut builder = AutoCommandBufferBuilder::primary(
&*self.command_buffer_allocator,
&self.command_buffer_allocator,
self.compute_queue.queue_family_index(),
CommandBufferUsage::OneTimeSubmit,
)
@ -159,7 +159,10 @@ impl GameOfLifeComputePipeline {
/// Build the command for a dispatch.
fn dispatch(
&self,
builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
builder: &mut AutoCommandBufferBuilder<
PrimaryAutoCommandBuffer,
Arc<StandardCommandBufferAllocator>,
>,
life_color: [f32; 4],
dead_color: [f32; 4],
// Step determines whether we color or compute life (see branch in the shader)s
@ -170,7 +173,7 @@ impl GameOfLifeComputePipeline {
let pipeline_layout = self.compute_life_pipeline.layout();
let desc_layout = pipeline_layout.set_layouts().get(0).unwrap();
let set = PersistentDescriptorSet::new(
&*self.descriptor_set_allocator,
&self.descriptor_set_allocator,
desc_layout.clone(),
[
WriteDescriptorSet::image_view(0, self.image.clone()),

View File

@ -151,7 +151,7 @@ impl PixelsDrawPipeline {
.unwrap();
PersistentDescriptorSet::new(
&*self.descriptor_set_allocator,
&self.descriptor_set_allocator,
layout.clone(),
[WriteDescriptorSet::image_view_sampler(
0,
@ -169,7 +169,7 @@ impl PixelsDrawPipeline {
image: Arc<dyn ImageViewAbstract>,
) -> SecondaryAutoCommandBuffer {
let mut builder = AutoCommandBufferBuilder::secondary(
&*self.command_buffer_allocator,
&self.command_buffer_allocator,
self.gfx_queue.queue_family_index(),
CommandBufferUsage::MultipleSubmit,
CommandBufferInheritanceInfo {

View File

@ -96,7 +96,7 @@ impl RenderPassPlaceOverFrame {
.unwrap();
// Create primary command buffer builder
let mut command_buffer_builder = AutoCommandBufferBuilder::primary(
&*self.command_buffer_allocator,
&self.command_buffer_allocator,
self.gfx_queue.queue_family_index(),
CommandBufferUsage::OneTimeSubmit,
)

View File

@ -161,7 +161,7 @@ fn main() {
let memory_allocator = Arc::new(StandardMemoryAllocator::new_default(device.clone()));
let vertex_buffer = CpuAccessibleBuffer::from_iter(
&*memory_allocator,
&memory_allocator,
BufferUsage {
vertex_buffer: true,
..BufferUsage::empty()
@ -171,7 +171,7 @@ fn main() {
)
.unwrap();
let normals_buffer = CpuAccessibleBuffer::from_iter(
&*memory_allocator,
&memory_allocator,
BufferUsage {
vertex_buffer: true,
..BufferUsage::empty()
@ -181,7 +181,7 @@ fn main() {
)
.unwrap();
let index_buffer = CpuAccessibleBuffer::from_iter(
&*memory_allocator,
&memory_allocator,
BufferUsage {
index_buffer: true,
..BufferUsage::empty()

View File

@ -275,6 +275,24 @@ unsafe impl CommandBufferAllocator for StandardCommandBufferAllocator {
}
}
unsafe impl CommandBufferAllocator for Arc<StandardCommandBufferAllocator> {
type Iter = IntoIter<StandardCommandBufferBuilderAlloc>;
type Builder = StandardCommandBufferBuilderAlloc;
type Alloc = StandardCommandBufferAlloc;
#[inline]
fn allocate(
&self,
queue_family_index: u32,
level: CommandBufferLevel,
command_buffer_count: u32,
) -> Result<Self::Iter, OomError> {
(**self).allocate(queue_family_index, level, command_buffer_count)
}
}
unsafe impl DeviceOwned for StandardCommandBufferAllocator {
#[inline]
fn device(&self) -> &Arc<Device> {

View File

@ -188,6 +188,19 @@ unsafe impl DescriptorSetAllocator for StandardDescriptorSetAllocator {
}
}
unsafe impl DescriptorSetAllocator for Arc<StandardDescriptorSetAllocator> {
type Alloc = StandardDescriptorSetAlloc;
#[inline]
fn allocate(
&self,
layout: &Arc<DescriptorSetLayout>,
variable_descriptor_count: u32,
) -> Result<Self::Alloc, OomError> {
(**self).allocate(layout, variable_descriptor_count)
}
}
unsafe impl DeviceOwned for StandardDescriptorSetAllocator {
#[inline]
fn device(&self) -> &Arc<Device> {

View File

@ -1416,6 +1416,62 @@ unsafe impl<S: Suballocator> MemoryAllocator for GenericMemoryAllocator<S> {
}
}
unsafe impl<S: Suballocator> MemoryAllocator for Arc<GenericMemoryAllocator<S>> {
fn find_memory_type_index(
&self,
memory_type_bits: u32,
filter: MemoryTypeFilter,
) -> Option<u32> {
(**self).find_memory_type_index(memory_type_bits, filter)
}
fn allocate_from_type(
&self,
memory_type_index: u32,
create_info: SuballocationCreateInfo,
) -> Result<MemoryAlloc, AllocationCreationError> {
(**self).allocate_from_type(memory_type_index, create_info)
}
unsafe fn allocate_from_type_unchecked(
&self,
memory_type_index: u32,
create_info: SuballocationCreateInfo,
never_allocate: bool,
) -> Result<MemoryAlloc, AllocationCreationError> {
(**self).allocate_from_type_unchecked(memory_type_index, create_info, never_allocate)
}
fn allocate(
&self,
create_info: AllocationCreateInfo<'_>,
) -> Result<MemoryAlloc, AllocationCreationError> {
(**self).allocate(create_info)
}
unsafe fn allocate_unchecked(
&self,
create_info: AllocationCreateInfo<'_>,
) -> Result<MemoryAlloc, AllocationCreationError> {
(**self).allocate_unchecked(create_info)
}
unsafe fn allocate_dedicated_unchecked(
&self,
memory_type_index: u32,
allocation_size: DeviceSize,
dedicated_allocation: Option<DedicatedAllocation<'_>>,
export_handle_types: ExternalMemoryHandleTypes,
) -> Result<MemoryAlloc, AllocationCreationError> {
(**self).allocate_dedicated_unchecked(
memory_type_index,
allocation_size,
dedicated_allocation,
export_handle_types,
)
}
}
unsafe impl<S: Suballocator> DeviceOwned for GenericMemoryAllocator<S> {
fn device(&self) -> &Arc<Device> {
&self.device