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
This commit is contained in:
parent
596ce11556
commit
17cab47ed1
Notes:
blender-bot
2023-02-14 08:33:26 +01:00
Referenced by issue #94736, Crash when modifying strength of world environment texture Referenced by issue #94740, Crash on deleting last light
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue