Blender Git Loki

Git Commits -> Revision 3a4c8f4

Revision 3a4c8f4 by Michael Jones (master)
November 9, 2021, 21:43 (GMT)
Cycles: Adapt shared kernel/device/gpu layer for MSL

This patch adapts the shared kernel entrypoints so that they can be compiled as MSL (Metal Shading Language). Where possible, the adaptations avoid changes in common code.

In MSL, kernel function inputs are explicitly bound to resources. In the case of argument buffers, we declare a struct containing the kernel arguments, accessible via device pointer. This differs from CUDA and HIP where kernel function arguments are declared as traditional C-style function parameters. This patch adapts the entrypoints declared in kernel.h so that they can be translated via a new `ccl_gpu_kernel_signature` macro into the required parameter struct + kernel entrypoint pairing for MSL.

MSL buffer attribution must be applied to function parameters or non-static class data members. To allow universal access to the integrator state, kernel data, and texture fetch adapters, we wrap all of the shared kernel code in a `MetalKernelContext` class. This is achieved by bracketing the appropriate kernel headers with "context_begin.h" and "context_end.h" on Metal. When calling deeper into the kernel code, we must reference the context class (e.g. `context.integrator_init_from_camera`). This extra prefixing is performed by a set of defines in "context_end.h". These will require explicit maintenance if entrypoints change. We invite discussion on more maintainable ways to enforce correctness.

Lambda expressions are not supported on MSL, so a new `ccl_gpu_kernel_lambda` macro generates an inline function object and optionally capturing any required state. This yields the same behaviour. This approach is applied to all parallel_... implementations which are templated by operation. The lambda expressions in the film_convert... kernels don't adapt cleanly to use function objects. However, these entrypoints can be macro-generated more concisely to avoid lambda expressions entirely, instead relying on constant folding to handle the pixel/channel conversions.

A separate implementation of `gpu_parallel_active_index_array` is provided for Metal to workaround some subtle differences in SIMD width, and also to encapsulate some required thread parameters which must be declared as explicit entrypoint function parameters.

Ref T92212

Reviewed By: brecht

Maniphest Tasks: T92212

Differential Revision: https://developer.blender.org/D13109

Commit Details:

Full Hash: 3a4c8f406a3a3bf0627477c6183a594fa707a6e2
Parent Commit: 4648c49
Committed By: Michael Jones
Lines Changed: +877, -482

4 Added Paths:

/intern/cycles/kernel/device/metal/context_begin.h (+79, -0) (View)
/intern/cycles/kernel/device/metal/context_end.h (+23, -0) (View)
/intern/cycles/kernel/device/metal/globals.h (+51, -0) (View)
/intern/cycles/kernel/device/metal/kernel.metal (+25, -0) (View)

12 Modified Paths:

/intern/cycles/kernel/CMakeLists.txt (+17, -0) (Diff)
/intern/cycles/kernel/device/cuda/compat.h (+1, -0) (Diff)
/intern/cycles/kernel/device/cuda/config.h (+25, -1) (Diff)
/intern/cycles/kernel/device/gpu/image.h (+7, -5) (Diff)
/intern/cycles/kernel/device/gpu/kernel.h (+403, -434) (Diff)
/intern/cycles/kernel/device/gpu/parallel_active_index.h (+83, -31) (Diff)
/intern/cycles/kernel/device/gpu/parallel_prefix_sum.h (+5, -3) (Diff)
/intern/cycles/kernel/device/gpu/parallel_sorted_index.h (+7, -7) (Diff)
/intern/cycles/kernel/device/hip/compat.h (+1, -0) (Diff)
/intern/cycles/kernel/device/hip/config.h (+25, -1) (Diff)
/intern/cycles/kernel/device/metal/compat.h (+124, -0) (Diff)
/intern/cycles/kernel/device/optix/compat.h (+1, -0) (Diff)
Tehnyt: Miika HämäläinenViimeksi päivitetty: 07.11.2014 14:18MiikaH:n Sivut a.k.a. MiikaHweb | 2003-2021