Fix T53134: denoising with CPU + GPU render leaves some tiles noisy.

This commit is contained in:
Brecht Van Lommel 2017-10-24 04:07:24 +02:00
parent 070a668d04
commit a1aad1f8d1
Notes: blender-bot 2023-02-14 08:06:35 +01:00
Referenced by issue #53134, Some tiles remain noisy with denoising in CPU+GPU render from master
3 changed files with 17 additions and 5 deletions

View File

@ -248,26 +248,36 @@ public:
if(!tiles[i].buffers) {
continue;
}
/* If the tile was rendered on another device, copy its memory to
* to the current device now, for the duration of the denoising task.
* Note that this temporarily modifies the RenderBuffers and calls
* the device, so this function is not thread safe. */
device_vector<float> &mem = tiles[i].buffers->buffer;
if(mem.device != sub_device) {
tiles[i].buffers->copy_from_device();
/* Only copy from device to host once. This is faster, but
* also required for the case where a CPU thread is denoising
* a tile rendered on the GPU. In that case we have to avoid
* overwriting the buffer being denoised by the CPU thread. */
if(!tiles[i].buffers->map_neighbor_copied) {
tiles[i].buffers->map_neighbor_copied = true;
mem.copy_from_device(0, mem.data_size, 1);
}
Device *original_device = mem.device;
device_ptr original_ptr = mem.device_pointer;
size_t original_size = mem.device_size;
mem.device = sub_device;
mem.device_pointer = 0;
mem.device_size = 0;
sub_device->mem_alloc(mem);
sub_device->mem_copy_to(mem);
mem.copy_to_device();
tiles[i].buffer = mem.device_pointer;
mem.device = original_device;
mem.device_pointer = original_ptr;
mem.device_size = original_size;
}
}
}
@ -290,7 +300,7 @@ public:
/* Copy denoised tile to the host. */
if(i == 4) {
tiles[i].buffers->copy_from_device();
mem.copy_from_device(0, mem.data_size, 1);
}
sub_device->mem_free(mem);

View File

@ -115,7 +115,8 @@ RenderTile::RenderTile()
/* Render Buffers */
RenderBuffers::RenderBuffers(Device *device)
: buffer(device, "RenderBuffers", MEM_READ_WRITE)
: buffer(device, "RenderBuffers", MEM_READ_WRITE),
map_neighbor_copied(false)
{
}

View File

@ -74,6 +74,7 @@ public:
/* float buffer */
device_vector<float> buffer;
bool map_neighbor_copied;
explicit RenderBuffers(Device *device);
~RenderBuffers();