[d3d12] Use DeviceAllocationContext for deallocation

This commit is contained in:
Connor Fitzgerald authored and Teodor Tanasoaia committed 2025-04-07 16:01:19 +02:00
1 parent cccb0864cd
commit 46ef1fc061
2 files changed
+9 -15

No files matched your search

+4 -9
View File
@@ -451,10 +451,9 @@ impl crate::Device for super::Device {
unsafe fn destroy_buffer(&self, buffer: super::Buffer) {
suballocation::free_resource(
self,
suballocation::DeviceAllocationContext::from(self),
buffer.resource,
buffer.allocation,
&self.mem_allocator,
);
self.counters.buffers.sub(1);
@@ -542,11 +541,9 @@ impl crate::Device for super::Device {
unsafe fn destroy_texture(&self, texture: super::Texture) {
suballocation::free_resource(
self,
suballocation::DeviceAllocationContext::from(self),
texture.resource,
texture.allocation,
// SAFETY: for allocations to exist, the allocator must exist
&self.mem_allocator,
);
self.counters.textures.sub(1);
@@ -1673,10 +1670,9 @@ impl crate::Device for super::Device {
if let Some(sampler_buffer) = group.sampler_index_buffer {
suballocation::free_resource(
self,
suballocation::DeviceAllocationContext::from(self),
sampler_buffer.buffer,
sampler_buffer.allocation,
&self.mem_allocator,
);
}
@@ -2320,10 +2316,9 @@ impl crate::Device for super::Device {
acceleration_structure: super::AccelerationStructure,
) {
suballocation::free_resource(
self,
suballocation::DeviceAllocationContext::from(self),
acceleration_structure.resource,
acceleration_structure.allocation,
&self.mem_allocator,
);
}
+5 -6
View File
@@ -258,10 +258,9 @@ pub(crate) fn create_acceleration_structure(
}
pub(crate) fn free_resource(
device: &crate::dx12::Device,
ctx: DeviceAllocationContext,
resource: Direct3D12::ID3D12Resource,
allocation: Allocation,
allocator: &Mutex<Allocator>,
) {
// Make sure the resource is released before we free the allocation.
drop(resource);
@@ -271,13 +270,13 @@ pub(crate) fn free_resource(
};
let counter = match allocation.ty {
AllocationType::Buffer => &device.counters.buffer_memory,
AllocationType::Texture => &device.counters.texture_memory,
AllocationType::AccelerationStructure => &device.counters.acceleration_structure_memory,
AllocationType::Buffer => &ctx.counters.buffer_memory,
AllocationType::Texture => &ctx.counters.texture_memory,
AllocationType::AccelerationStructure => &ctx.counters.acceleration_structure_memory,
};
counter.sub(inner.size() as isize);
match allocator.lock().free(inner) {
match ctx.mem_allocator.lock().free(inner) {
Ok(_) => (),
// TODO: Don't panic here
Err(e) => panic!("Failed to destroy dx12 {:?}, {e}", allocation.ty),