blender/intern/cycles/device/hip/kernel.cpp
Brecht Van Lommel 5fc85d1cb7 Refactor: Cycles: Move MNEE walk into separate kernel
The new intersect_mnee kernel runs before shade_surface, and
shade_surface_mnee is eliminated. That large kernel was causing problems
for some GPU compilers.

MNEE state is packed into a shadow path state to avoid significantly
increasing the path state size. This shadow state is then either turned
into an actual shadow ray state or discarded in shade_surface.

MNEE was re-enabled on HIP RDNA2 as it works again now. Texture cache
misses now also work correctly with MNEE.

This adds some extra code to the regular shade_surface kernel even when
MNEE is not used, to use the MNEE sampled point instead of sampling a
light. But there seems to be no significant performance impact.

Co-authored-by: Sergey Sharybin <sergey@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/158698
2026-05-27 20:34:06 +02:00

81 lines
2.4 KiB
C++

/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: Apache-2.0 */
#ifdef WITH_HIP
# include "kernel/types.h"
# include "device/hip/device_impl.h"
# include "device/hip/kernel.h"
CCL_NAMESPACE_BEGIN
bool HIPDeviceKernels::load_kernel(HIPDevice *device,
hipModule_t hip_module,
const DeviceKernel kernel)
{
if (available(kernel)) {
return true;
}
if (!device_kernel_has_gpu_function(kernel)) {
return false;
}
HIPDeviceKernel &hip_kernel = kernels_[int(kernel)];
const std::string function_name = std::string("kernel_gpu_") + device_kernel_as_string(kernel);
hip_device_assert(device,
hipModuleGetFunction(&hip_kernel.function, hip_module, function_name.c_str()));
if (!hip_kernel.function) {
LOG_ERROR << "Unable to load kernel " << function_name;
return false;
}
hip_device_assert(device, hipFuncSetCacheConfig(hip_kernel.function, hipFuncCachePreferL1));
hip_device_assert(
device,
hipModuleOccupancyMaxPotentialBlockSize(
&hip_kernel.min_blocks, &hip_kernel.num_threads_per_block, hip_kernel.function, 0, 0));
LOG_DEBUG << "Loaded kernel: " << function_name;
return true;
}
void HIPDeviceKernels::load_all(HIPDevice *device, hipModule_t hip_module)
{
LOG_DEBUG << "Loading all HIP kernels";
for (int i = 0; i < (int)DEVICE_KERNEL_NUM; i++) {
load_kernel(device, hip_module, DeviceKernel(i));
}
}
void HIPDeviceKernels::load_raytrace(HIPDevice *device, hipModule_t hip_module)
{
LOG_DEBUG << "Loading ray-tracing HIP-RT kernels";
load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_INTERSECT_CLOSEST);
load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_INTERSECT_SHADOW);
load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_INTERSECT_SUBSURFACE);
load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_INTERSECT_VOLUME_STACK);
load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_INTERSECT_DEDICATED_LIGHT);
load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_INTERSECT_MNEE);
load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE_RAYTRACE);
}
const HIPDeviceKernel &HIPDeviceKernels::get(DeviceKernel kernel) const
{
return kernels_[(int)kernel];
}
bool HIPDeviceKernels::available(DeviceKernel kernel) const
{
return kernels_[(int)kernel].function != nullptr;
}
CCL_NAMESPACE_END
#endif /* WITH_HIP */