Fix #135010: Crash when using Denoise node

Blender crashes when using the Denoise node. That's because the code
assumes normal input would have 4-channels, while this may not be the
case. To fix this, use the channels count from the result or the GPU
texture directly.
This commit is contained in:
Omar Emara
2025-02-24 13:22:40 +02:00
parent 4e069f8f5a
commit c29971c688
2 changed files with 10 additions and 11 deletions

View File

@@ -86,13 +86,13 @@ DenoisedAuxiliaryPass::DenoisedAuxiliaryPass(Context &context,
const int width = pass.domain().size.x;
const int height = pass.domain().size.y;
int pixel_stride = sizeof(float) * 4;
/* Float3 results might be stored in 4-component textures due to hardware limitations, so we need
* to use the pixel stride of the texture. */
if (context.use_gpu()) {
pixel_stride = sizeof(float) * GPU_texture_component_len(GPU_texture_format(pass));
}
/* Float3 results might be stored in 4-component textures due to hardware limitations, so we
* need to use the pixel stride of the texture. */
const int pixel_stride = sizeof(float) *
(context.use_gpu() ?
GPU_texture_component_len(GPU_texture_format(pass)) :
pass.channels_count());
oidn::DeviceRef device = oidn::newDevice(oidn::DeviceType::CPU);
device.commit();

View File

@@ -213,11 +213,10 @@ class DenoiseOperation : public NodeOperation {
/* Float3 results might be stored in 4-component textures due to hardware limitations, so we
* need to use the pixel stride of the texture. */
int normal_pixel_stride = pixel_stride;
if (this->context().use_gpu()) {
normal_pixel_stride = sizeof(float) *
GPU_texture_component_len(GPU_texture_format(input_normal));
}
int normal_pixel_stride = sizeof(float) *
(this->context().use_gpu() ?
GPU_texture_component_len(GPU_texture_format(input_normal)) :
input_normal.channels_count());
filter.setImage(
"normal", normal, oidn::Format::Float3, width, height, 0, normal_pixel_stride);