From 56cbde568baec28a31f2ac450534cf2f18c3e447 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 11 Apr 2024 10:51:45 +0200 Subject: [PATCH] Fix #120046: Broken render on AMD Metal GPUs This is a regression since fdc2962bebb The size of state can not be different between CPU and GPU. This change replaces compile-time condition with a kernel feature check, which solves the render regression on AMD Metal. It also minimizes the state size on other GPUs when Light Tree is disabled. Pull Request: https://projects.blender.org/blender/blender/pulls/120476 --- intern/cycles/kernel/integrator/shade_volume.h | 4 +++- intern/cycles/kernel/integrator/state_template.h | 4 +--- intern/cycles/kernel/types.h | 3 +++ intern/cycles/scene/integrator.cpp | 4 ++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/intern/cycles/kernel/integrator/shade_volume.h b/intern/cycles/kernel/integrator/shade_volume.h index 7d0c28acc25..55dedda5963 100644 --- a/intern/cycles/kernel/integrator/shade_volume.h +++ b/intern/cycles/kernel/integrator/shade_volume.h @@ -945,7 +945,9 @@ ccl_device_forceinline bool integrate_volume_phase_scatter( INTEGRATOR_STATE_WRITE(state, ray, D) = normalize(phase_wo); INTEGRATOR_STATE_WRITE(state, ray, tmin) = 0.0f; # ifdef __LIGHT_TREE__ - INTEGRATOR_STATE_WRITE(state, ray, previous_dt) = ray->tmax - ray->tmin; + if (kernel_data.integrator.use_light_tree) { + INTEGRATOR_STATE_WRITE(state, ray, previous_dt) = ray->tmax - ray->tmin; + } # endif INTEGRATOR_STATE_WRITE(state, ray, tmax) = FLT_MAX; # ifdef __RAY_DIFFERENTIALS__ diff --git a/intern/cycles/kernel/integrator/state_template.h b/intern/cycles/kernel/integrator/state_template.h index 34154d1c7fa..0c84416e4e5 100644 --- a/intern/cycles/kernel/integrator/state_template.h +++ b/intern/cycles/kernel/integrator/state_template.h @@ -75,9 +75,7 @@ KERNEL_STRUCT_MEMBER(ray, float, tmax, KERNEL_FEATURE_PATH_TRACING) KERNEL_STRUCT_MEMBER(ray, float, time, KERNEL_FEATURE_PATH_TRACING) KERNEL_STRUCT_MEMBER(ray, float, dP, KERNEL_FEATURE_PATH_TRACING) KERNEL_STRUCT_MEMBER(ray, float, dD, KERNEL_FEATURE_PATH_TRACING) -#ifdef __LIGHT_TREE__ -KERNEL_STRUCT_MEMBER(ray, float, previous_dt, KERNEL_FEATURE_PATH_TRACING) -#endif +KERNEL_STRUCT_MEMBER(ray, float, previous_dt, KERNEL_FEATURE_LIGHT_TREE) KERNEL_STRUCT_END(ray) /*************************** Intersection result ******************************/ diff --git a/intern/cycles/kernel/types.h b/intern/cycles/kernel/types.h index 260e35f8ae6..c896d56db7c 100644 --- a/intern/cycles/kernel/types.h +++ b/intern/cycles/kernel/types.h @@ -1748,6 +1748,9 @@ enum KernelFeatureFlag : uint32_t { /* Use denoising kernels and output denoising passes. */ KERNEL_FEATURE_DENOISING = (1U << 29U), + + /* Light tree. */ + KERNEL_FEATURE_LIGHT_TREE = (1U << 30U), }; /* Shader node feature mask, to specialize shader evaluation for kernels. */ diff --git a/intern/cycles/scene/integrator.cpp b/intern/cycles/scene/integrator.cpp index 61bf09ecc9e..8cf24ab3fad 100644 --- a/intern/cycles/scene/integrator.cpp +++ b/intern/cycles/scene/integrator.cpp @@ -345,6 +345,10 @@ uint Integrator::get_kernel_features() const kernel_features |= KERNEL_FEATURE_AO_ADDITIVE; } + if (get_use_light_tree()) { + kernel_features |= KERNEL_FEATURE_LIGHT_TREE; + } + return kernel_features; }