diff options
author | Michael Jones <michael_p_jones@apple.com> | 2022-01-19 20:57:24 +0300 |
---|---|---|
committer | Michael Jones <michael_p_jones@apple.com> | 2022-01-19 21:17:37 +0300 |
commit | 17cab47ed10a99818f9cdd15657c1231e312da25 (patch) | |
tree | b923bf476b6ce067ebf0445b8e35371b6e13ddd4 /intern/cycles | |
parent | 596ce115567e3ddfd7ab5b7a8a488d064983e83c (diff) |
Cycles: Fix T94736: Crash when modifying strength of world environment texture
This patch fixes crash T94736 on Metal in which the launch_params were not being updated to reflect destruction of MetalMem objects.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D13875
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/device/metal/device_impl.h | 2 | ||||
-rw-r--r-- | intern/cycles/device/metal/device_impl.mm | 30 |
2 files changed, 23 insertions, 9 deletions
diff --git a/intern/cycles/device/metal/device_impl.h b/intern/cycles/device/metal/device_impl.h index a420a3ba704..8d289beda13 100644 --- a/intern/cycles/device/metal/device_impl.h +++ b/intern/cycles/device/metal/device_impl.h @@ -115,6 +115,8 @@ class MetalDevice : public Device { void load_texture_info(); + void erase_allocation(device_memory &mem); + virtual bool should_use_graphics_interop() override; virtual unique_ptr<DeviceQueue> gpu_queue_create() override; diff --git a/intern/cycles/device/metal/device_impl.mm b/intern/cycles/device/metal/device_impl.mm index 4ad5a3caebc..1105fb20360 100644 --- a/intern/cycles/device/metal/device_impl.mm +++ b/intern/cycles/device/metal/device_impl.mm @@ -432,6 +432,25 @@ void MetalDevice::load_texture_info() } } +void MetalDevice::erase_allocation(device_memory &mem) +{ + stats.mem_free(mem.device_size); + mem.device_pointer = 0; + mem.device_size = 0; + + auto it = metal_mem_map.find(&mem); + if (it != metal_mem_map.end()) { + MetalMem *mmem = it->second.get(); + + /* blank out reference to MetalMem* in the launch params (fixes crash T94736) */ + if (mmem->pointer_index >= 0) { + device_ptr *pointers = (device_ptr*)&launch_params; + pointers[mmem->pointer_index] = 0; + } + metal_mem_map.erase(it); + } +} + MetalDevice::MetalMem *MetalDevice::generic_alloc(device_memory &mem) { size_t size = mem.memory_size(); @@ -561,11 +580,7 @@ void MetalDevice::generic_free(device_memory &mem) mmem.mtlBuffer = nil; } - stats.mem_free(mem.device_size); - mem.device_pointer = 0; - mem.device_size = 0; - - metal_mem_map.erase(&mem); + erase_allocation(mem); } } @@ -954,10 +969,7 @@ void MetalDevice::tex_free(device_texture &mem) delayed_free_list.push_back(mmem.mtlTexture); mmem.mtlTexture = nil; } - stats.mem_free(mem.device_size); - mem.device_pointer = 0; - mem.device_size = 0; - metal_mem_map.erase(&mem); + erase_allocation(mem); } } |