Skip to content

Commit 46ef1fc

Browse files
cwfitzgeraldteoxoy
authored andcommitted
[d3d12] Use DeviceAllocationContext for deallocation
1 parent cccb086 commit 46ef1fc

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

wgpu-hal/src/dx12/device.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,9 @@ impl crate::Device for super::Device {
451451

452452
unsafe fn destroy_buffer(&self, buffer: super::Buffer) {
453453
suballocation::free_resource(
454-
self,
454+
suballocation::DeviceAllocationContext::from(self),
455455
buffer.resource,
456456
buffer.allocation,
457-
&self.mem_allocator,
458457
);
459458

460459
self.counters.buffers.sub(1);
@@ -542,11 +541,9 @@ impl crate::Device for super::Device {
542541

543542
unsafe fn destroy_texture(&self, texture: super::Texture) {
544543
suballocation::free_resource(
545-
self,
544+
suballocation::DeviceAllocationContext::from(self),
546545
texture.resource,
547546
texture.allocation,
548-
// SAFETY: for allocations to exist, the allocator must exist
549-
&self.mem_allocator,
550547
);
551548

552549
self.counters.textures.sub(1);
@@ -1673,10 +1670,9 @@ impl crate::Device for super::Device {
16731670

16741671
if let Some(sampler_buffer) = group.sampler_index_buffer {
16751672
suballocation::free_resource(
1676-
self,
1673+
suballocation::DeviceAllocationContext::from(self),
16771674
sampler_buffer.buffer,
16781675
sampler_buffer.allocation,
1679-
&self.mem_allocator,
16801676
);
16811677
}
16821678

@@ -2320,10 +2316,9 @@ impl crate::Device for super::Device {
23202316
acceleration_structure: super::AccelerationStructure,
23212317
) {
23222318
suballocation::free_resource(
2323-
self,
2319+
suballocation::DeviceAllocationContext::from(self),
23242320
acceleration_structure.resource,
23252321
acceleration_structure.allocation,
2326-
&self.mem_allocator,
23272322
);
23282323
}
23292324

wgpu-hal/src/dx12/suballocation.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,9 @@ pub(crate) fn create_acceleration_structure(
258258
}
259259

260260
pub(crate) fn free_resource(
261-
device: &crate::dx12::Device,
261+
ctx: DeviceAllocationContext,
262262
resource: Direct3D12::ID3D12Resource,
263263
allocation: Allocation,
264-
allocator: &Mutex<Allocator>,
265264
) {
266265
// Make sure the resource is released before we free the allocation.
267266
drop(resource);
@@ -271,13 +270,13 @@ pub(crate) fn free_resource(
271270
};
272271

273272
let counter = match allocation.ty {
274-
AllocationType::Buffer => &device.counters.buffer_memory,
275-
AllocationType::Texture => &device.counters.texture_memory,
276-
AllocationType::AccelerationStructure => &device.counters.acceleration_structure_memory,
273+
AllocationType::Buffer => &ctx.counters.buffer_memory,
274+
AllocationType::Texture => &ctx.counters.texture_memory,
275+
AllocationType::AccelerationStructure => &ctx.counters.acceleration_structure_memory,
277276
};
278277
counter.sub(inner.size() as isize);
279278

280-
match allocator.lock().free(inner) {
279+
match ctx.mem_allocator.lock().free(inner) {
281280
Ok(_) => (),
282281
// TODO: Don't panic here
283282
Err(e) => panic!("Failed to destroy dx12 {:?}, {e}", allocation.ty),

0 commit comments

Comments
 (0)