2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2017-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2017-10-06 21:47:41 +02:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2025-01-11 04:42:13 +01:00
|
|
|
#include "kernel/globals.h"
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
|
2025-01-11 04:42:13 +01:00
|
|
|
CCL_NAMESPACE_BEGIN
|
2023-12-09 20:46:23 +01:00
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
ccl_device_inline float frac(const float x, ccl_private int *ix)
|
2023-12-09 20:46:23 +01:00
|
|
|
{
|
|
|
|
|
int i = float_to_int(x) - ((x < 0.0f) ? 1 : 0);
|
|
|
|
|
*ix = i;
|
|
|
|
|
return x - (float)i;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-07 02:15:12 +02:00
|
|
|
/* w0, w1, w2, and w3 are the four cubic B-spline basis functions. */
|
2025-01-01 18:15:54 +01:00
|
|
|
ccl_device float cubic_w0(const float a)
|
2017-10-07 02:15:12 +02:00
|
|
|
{
|
|
|
|
|
return (1.0f / 6.0f) * (a * (a * (-a + 3.0f) - 3.0f) + 1.0f);
|
|
|
|
|
}
|
2025-01-01 18:15:54 +01:00
|
|
|
ccl_device float cubic_w1(const float a)
|
2017-10-07 02:15:12 +02:00
|
|
|
{
|
|
|
|
|
return (1.0f / 6.0f) * (a * a * (3.0f * a - 6.0f) + 4.0f);
|
|
|
|
|
}
|
2025-01-01 18:15:54 +01:00
|
|
|
ccl_device float cubic_w2(const float a)
|
2017-10-07 02:15:12 +02:00
|
|
|
{
|
|
|
|
|
return (1.0f / 6.0f) * (a * (a * (-3.0f * a + 3.0f) + 3.0f) + 1.0f);
|
|
|
|
|
}
|
2025-01-01 18:15:54 +01:00
|
|
|
ccl_device float cubic_w3(const float a)
|
2017-10-07 02:15:12 +02:00
|
|
|
{
|
|
|
|
|
return (1.0f / 6.0f) * (a * a * a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* g0 and g1 are the two amplitude functions. */
|
2025-01-01 18:15:54 +01:00
|
|
|
ccl_device float cubic_g0(const float a)
|
2017-10-07 02:15:12 +02:00
|
|
|
{
|
|
|
|
|
return cubic_w0(a) + cubic_w1(a);
|
|
|
|
|
}
|
2025-01-01 18:15:54 +01:00
|
|
|
ccl_device float cubic_g1(const float a)
|
2017-10-07 02:15:12 +02:00
|
|
|
{
|
|
|
|
|
return cubic_w2(a) + cubic_w3(a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* h0 and h1 are the two offset functions */
|
2025-01-01 18:15:54 +01:00
|
|
|
ccl_device float cubic_h0(const float a)
|
2017-10-07 02:15:12 +02:00
|
|
|
{
|
2020-11-06 15:19:58 +01:00
|
|
|
return (cubic_w1(a) / cubic_g0(a)) - 1.0f;
|
2017-10-07 02:15:12 +02:00
|
|
|
}
|
2025-01-01 18:15:54 +01:00
|
|
|
ccl_device float cubic_h1(const float a)
|
2017-10-07 02:15:12 +02:00
|
|
|
{
|
2020-11-06 15:19:58 +01:00
|
|
|
return (cubic_w3(a) / cubic_g1(a)) + 1.0f;
|
2017-10-07 02:15:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Fast bicubic texture lookup using 4 bilinear lookups, adapted from CUDA samples. */
|
|
|
|
|
template<typename T>
|
2024-12-29 17:32:00 +01:00
|
|
|
ccl_device_noinline T kernel_tex_image_interp_bicubic(const ccl_global TextureInfo &info,
|
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
2021-11-09 21:30:46 +00:00
|
|
|
float x,
|
|
|
|
|
float y)
|
2017-10-07 02:15:12 +02:00
|
|
|
{
|
2022-04-01 19:44:31 +02:00
|
|
|
ccl_gpu_tex_object_2D tex = (ccl_gpu_tex_object_2D)info.data;
|
2020-10-02 17:40:28 +02:00
|
|
|
|
2017-10-07 02:15:12 +02:00
|
|
|
x = (x * info.width) - 0.5f;
|
|
|
|
|
y = (y * info.height) - 0.5f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-03-08 13:59:16 +01:00
|
|
|
float px = floorf(x);
|
|
|
|
|
float py = floorf(y);
|
2017-10-07 02:15:12 +02:00
|
|
|
float fx = x - px;
|
|
|
|
|
float fy = y - py;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-10-07 02:15:12 +02:00
|
|
|
float g0x = cubic_g0(fx);
|
|
|
|
|
float g1x = cubic_g1(fx);
|
2020-11-06 15:19:58 +01:00
|
|
|
/* Note +0.5 offset to compensate for CUDA linear filtering convention. */
|
|
|
|
|
float x0 = (px + cubic_h0(fx) + 0.5f) / info.width;
|
|
|
|
|
float x1 = (px + cubic_h1(fx) + 0.5f) / info.width;
|
|
|
|
|
float y0 = (py + cubic_h0(fy) + 0.5f) / info.height;
|
|
|
|
|
float y1 = (py + cubic_h1(fy) + 0.5f) / info.height;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
return cubic_g0(fy) * (g0x * ccl_gpu_tex_object_read_2D<T>(tex, x0, y0) +
|
|
|
|
|
g1x * ccl_gpu_tex_object_read_2D<T>(tex, x1, y0)) +
|
|
|
|
|
cubic_g1(fy) * (g0x * ccl_gpu_tex_object_read_2D<T>(tex, x0, y1) +
|
|
|
|
|
g1x * ccl_gpu_tex_object_read_2D<T>(tex, x1, y1));
|
2017-10-07 02:15:12 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
ccl_device float4 kernel_tex_image_interp(KernelGlobals kg, const int id, const float x, float y)
|
2017-10-06 21:47:41 +02:00
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const ccl_global TextureInfo &info = kernel_data_fetch(texture_info, id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-05 12:37:52 +02:00
|
|
|
/* float4, byte4, ushort4 and half4 */
|
2020-02-26 17:31:33 +01:00
|
|
|
const int texture_type = info.data_type;
|
2017-10-06 21:47:41 +02:00
|
|
|
if (texture_type == IMAGE_DATA_TYPE_FLOAT4 || texture_type == IMAGE_DATA_TYPE_BYTE4 ||
|
2018-07-05 12:37:52 +02:00
|
|
|
texture_type == IMAGE_DATA_TYPE_HALF4 || texture_type == IMAGE_DATA_TYPE_USHORT4)
|
|
|
|
|
{
|
2022-03-11 14:26:01 +01:00
|
|
|
if (info.interpolation == INTERPOLATION_CUBIC || info.interpolation == INTERPOLATION_SMART) {
|
2020-10-02 17:40:28 +02:00
|
|
|
return kernel_tex_image_interp_bicubic<float4>(info, x, y);
|
2017-10-07 02:15:12 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2022-04-01 19:44:31 +02:00
|
|
|
ccl_gpu_tex_object_2D tex = (ccl_gpu_tex_object_2D)info.data;
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
return ccl_gpu_tex_object_read_2D<float4>(tex, x, y);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2017-10-07 02:15:12 +02:00
|
|
|
}
|
2017-10-06 21:47:41 +02:00
|
|
|
/* float, byte and half */
|
|
|
|
|
else {
|
2017-10-07 02:15:12 +02:00
|
|
|
float f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-11 14:26:01 +01:00
|
|
|
if (info.interpolation == INTERPOLATION_CUBIC || info.interpolation == INTERPOLATION_SMART) {
|
2020-10-02 17:40:28 +02:00
|
|
|
f = kernel_tex_image_interp_bicubic<float>(info, x, y);
|
2017-10-07 02:15:12 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2022-04-01 19:44:31 +02:00
|
|
|
ccl_gpu_tex_object_2D tex = (ccl_gpu_tex_object_2D)info.data;
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
f = ccl_gpu_tex_object_read_2D<float>(tex, x, y);
|
2017-10-07 02:15:12 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-10-06 21:47:41 +02:00
|
|
|
return make_float4(f, f, f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
CCL_NAMESPACE_END
|