2022-02-11 13:53:21 +01:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
2013-01-03 12:08:54 +00: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
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* Curve Primitive
|
|
|
|
*
|
2017-08-07 19:53:12 +02:00
|
|
|
* Curve primitive for rendering hair and fur. These can be render as flat
|
|
|
|
* ribbons or curves with actual thickness. The curve can also be rendered as
|
|
|
|
* line segments rather than curves for better performance.
|
|
|
|
*/
|
2014-03-29 13:03:48 +01:00
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
#ifdef __HAIR__
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* Reading attributes on various curve elements */
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device float curve_attribute_float(KernelGlobals kg,
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private const ShaderData *sd,
|
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
|
|
|
const AttributeDescriptor desc,
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private float *dx,
|
|
|
|
ccl_private float *dy)
|
2013-01-03 12:08:54 +00:00
|
|
|
{
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_CURVE_KEY | ATTR_ELEMENT_CURVE_KEY_MOTION)) {
|
2021-02-28 23:23:24 +01:00
|
|
|
KernelCurve curve = kernel_tex_fetch(__curves, sd->prim);
|
|
|
|
int k0 = curve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type);
|
2013-01-03 12:09:09 +00:00
|
|
|
int k1 = k0 + 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-01 17:36:27 -04:00
|
|
|
float f0 = kernel_tex_fetch(__attributes_float, desc.offset + k0);
|
|
|
|
float f1 = kernel_tex_fetch(__attributes_float, desc.offset + k1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
# ifdef __RAY_DIFFERENTIALS__
|
2017-02-16 06:24:13 -05:00
|
|
|
if (dx)
|
|
|
|
*dx = sd->du.dx * (f1 - f0);
|
2013-01-03 12:08:54 +00:00
|
|
|
if (dy)
|
|
|
|
*dy = 0.0f;
|
|
|
|
# endif
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
return (1.0f - sd->u) * f0 + sd->u * f1;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
# ifdef __RAY_DIFFERENTIALS__
|
|
|
|
if (dx)
|
|
|
|
*dx = 0.0f;
|
|
|
|
if (dy)
|
|
|
|
*dy = 0.0f;
|
|
|
|
# endif
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
|
|
|
|
const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim :
|
|
|
|
desc.offset;
|
|
|
|
return kernel_tex_fetch(__attributes_float, offset);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device float2 curve_attribute_float2(KernelGlobals kg,
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private const ShaderData *sd,
|
2019-03-05 14:54:54 +01:00
|
|
|
const AttributeDescriptor desc,
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private float2 *dx,
|
|
|
|
ccl_private float2 *dy)
|
2019-03-05 14:54:54 +01:00
|
|
|
{
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_CURVE_KEY | ATTR_ELEMENT_CURVE_KEY_MOTION)) {
|
2021-02-28 23:23:24 +01:00
|
|
|
KernelCurve curve = kernel_tex_fetch(__curves, sd->prim);
|
|
|
|
int k0 = curve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type);
|
2019-03-05 14:54:54 +01:00
|
|
|
int k1 = k0 + 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-05 14:54:54 +01:00
|
|
|
float2 f0 = kernel_tex_fetch(__attributes_float2, desc.offset + k0);
|
|
|
|
float2 f1 = kernel_tex_fetch(__attributes_float2, desc.offset + k1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-05 14:54:54 +01:00
|
|
|
# ifdef __RAY_DIFFERENTIALS__
|
|
|
|
if (dx)
|
|
|
|
*dx = sd->du.dx * (f1 - f0);
|
|
|
|
if (dy)
|
|
|
|
*dy = make_float2(0.0f, 0.0f);
|
|
|
|
# endif
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-05 14:54:54 +01:00
|
|
|
return (1.0f - sd->u) * f0 + sd->u * f1;
|
|
|
|
}
|
|
|
|
else {
|
2020-10-26 19:25:00 +01:00
|
|
|
/* idea: we can't derive any useful differentials here, but for tiled
|
|
|
|
* mipmap image caching it would be useful to avoid reading the highest
|
|
|
|
* detail level always. maybe a derivative based on the hair density
|
|
|
|
* could be computed somehow? */
|
2019-03-05 14:54:54 +01:00
|
|
|
# ifdef __RAY_DIFFERENTIALS__
|
|
|
|
if (dx)
|
|
|
|
*dx = make_float2(0.0f, 0.0f);
|
|
|
|
if (dy)
|
|
|
|
*dy = make_float2(0.0f, 0.0f);
|
|
|
|
# endif
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
|
|
|
|
const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim :
|
|
|
|
desc.offset;
|
|
|
|
return kernel_tex_fetch(__attributes_float2, offset);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return make_float2(0.0f, 0.0f);
|
|
|
|
}
|
2019-03-05 14:54:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device float3 curve_attribute_float3(KernelGlobals kg,
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private const ShaderData *sd,
|
2016-07-01 17:36:27 -04:00
|
|
|
const AttributeDescriptor desc,
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private float3 *dx,
|
|
|
|
ccl_private float3 *dy)
|
2013-01-03 12:08:54 +00:00
|
|
|
{
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_CURVE_KEY | ATTR_ELEMENT_CURVE_KEY_MOTION)) {
|
2021-02-28 23:23:24 +01:00
|
|
|
KernelCurve curve = kernel_tex_fetch(__curves, sd->prim);
|
|
|
|
int k0 = curve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type);
|
2013-01-03 12:09:09 +00:00
|
|
|
int k1 = k0 + 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-11-16 14:03:59 +01:00
|
|
|
float3 f0 = kernel_tex_fetch(__attributes_float3, desc.offset + k0);
|
|
|
|
float3 f1 = kernel_tex_fetch(__attributes_float3, desc.offset + k1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
# ifdef __RAY_DIFFERENTIALS__
|
2017-02-16 06:24:13 -05:00
|
|
|
if (dx)
|
|
|
|
*dx = sd->du.dx * (f1 - f0);
|
2013-01-03 12:08:54 +00:00
|
|
|
if (dy)
|
|
|
|
*dy = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
# endif
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
return (1.0f - sd->u) * f0 + sd->u * f1;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
# ifdef __RAY_DIFFERENTIALS__
|
|
|
|
if (dx)
|
|
|
|
*dx = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
if (dy)
|
|
|
|
*dy = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
# endif
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
|
|
|
|
const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim :
|
|
|
|
desc.offset;
|
2021-11-16 14:03:59 +01:00
|
|
|
return kernel_tex_fetch(__attributes_float3, offset);
|
2020-10-26 19:25:00 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device float4 curve_attribute_float4(KernelGlobals kg,
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private const ShaderData *sd,
|
2020-06-30 14:07:49 +02:00
|
|
|
const AttributeDescriptor desc,
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_private float4 *dx,
|
|
|
|
ccl_private float4 *dy)
|
2020-06-30 14:07:49 +02:00
|
|
|
{
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_CURVE_KEY | ATTR_ELEMENT_CURVE_KEY_MOTION)) {
|
2021-02-28 23:23:24 +01:00
|
|
|
KernelCurve curve = kernel_tex_fetch(__curves, sd->prim);
|
|
|
|
int k0 = curve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type);
|
2020-06-30 14:07:49 +02:00
|
|
|
int k1 = k0 + 1;
|
|
|
|
|
2021-11-16 14:03:59 +01:00
|
|
|
float4 f0 = kernel_tex_fetch(__attributes_float4, desc.offset + k0);
|
|
|
|
float4 f1 = kernel_tex_fetch(__attributes_float4, desc.offset + k1);
|
2020-06-30 14:07:49 +02:00
|
|
|
|
|
|
|
# ifdef __RAY_DIFFERENTIALS__
|
|
|
|
if (dx)
|
|
|
|
*dx = sd->du.dx * (f1 - f0);
|
|
|
|
if (dy)
|
|
|
|
*dy = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
# endif
|
|
|
|
|
|
|
|
return (1.0f - sd->u) * f0 + sd->u * f1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
# ifdef __RAY_DIFFERENTIALS__
|
|
|
|
if (dx)
|
|
|
|
*dx = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
if (dy)
|
|
|
|
*dy = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
# endif
|
|
|
|
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
|
|
|
|
const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim :
|
|
|
|
desc.offset;
|
2021-11-16 14:03:59 +01:00
|
|
|
return kernel_tex_fetch(__attributes_float4, offset);
|
2020-10-26 19:25:00 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
}
|
2020-06-30 14:07:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* Curve thickness */
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device float curve_thickness(KernelGlobals kg, ccl_private const ShaderData *sd)
|
2013-01-03 12:08:54 +00:00
|
|
|
{
|
|
|
|
float r = 0.0f;
|
|
|
|
|
2021-12-20 02:52:56 +01:00
|
|
|
if (sd->type & PRIMITIVE_CURVE) {
|
2021-02-28 23:23:24 +01:00
|
|
|
KernelCurve curve = kernel_tex_fetch(__curves, sd->prim);
|
|
|
|
int k0 = curve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type);
|
2013-01-03 12:09:09 +00:00
|
|
|
int k1 = k0 + 1;
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2014-03-29 13:03:47 +01:00
|
|
|
float4 P_curve[2];
|
|
|
|
|
2021-12-20 02:52:56 +01:00
|
|
|
if (!(sd->type & PRIMITIVE_MOTION)) {
|
2014-03-29 13:03:47 +01:00
|
|
|
P_curve[0] = kernel_tex_fetch(__curve_keys, k0);
|
|
|
|
P_curve[1] = kernel_tex_fetch(__curve_keys, k1);
|
|
|
|
}
|
|
|
|
else {
|
2020-02-18 20:54:41 +01:00
|
|
|
motion_curve_keys_linear(kg, sd->object, sd->prim, sd->time, k0, k1, P_curve);
|
2014-03-29 13:03:47 +01:00
|
|
|
}
|
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
r = (P_curve[1].w - P_curve[0].w) * sd->u + P_curve[0].w;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return r * 2.0f;
|
|
|
|
}
|
|
|
|
|
2022-01-25 13:25:33 +01:00
|
|
|
/* Curve random */
|
|
|
|
|
|
|
|
ccl_device float curve_random(KernelGlobals kg, ccl_private const ShaderData *sd)
|
|
|
|
{
|
|
|
|
if (sd->type & PRIMITIVE_CURVE) {
|
|
|
|
const AttributeDescriptor desc = find_attribute(kg, sd, ATTR_STD_CURVE_RANDOM);
|
|
|
|
return (desc.offset != ATTR_STD_NOT_FOUND) ? curve_attribute_float(kg, sd, desc, NULL, NULL) :
|
|
|
|
0.0f;
|
|
|
|
}
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
2014-05-09 15:32:13 +02:00
|
|
|
/* Curve location for motion pass, linear interpolation between keys and
|
|
|
|
* ignoring radius because we do the same for the motion keys */
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device float3 curve_motion_center_location(KernelGlobals kg, ccl_private const ShaderData *sd)
|
2014-05-09 15:32:13 +02:00
|
|
|
{
|
2021-02-28 23:23:24 +01:00
|
|
|
KernelCurve curve = kernel_tex_fetch(__curves, sd->prim);
|
|
|
|
int k0 = curve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type);
|
2014-05-09 15:32:13 +02:00
|
|
|
int k1 = k0 + 1;
|
|
|
|
|
|
|
|
float4 P_curve[2];
|
|
|
|
|
|
|
|
P_curve[0] = kernel_tex_fetch(__curve_keys, k0);
|
|
|
|
P_curve[1] = kernel_tex_fetch(__curve_keys, k1);
|
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
return float4_to_float3(P_curve[1]) * sd->u + float4_to_float3(P_curve[0]) * (1.0f - sd->u);
|
2014-05-09 15:32:13 +02:00
|
|
|
}
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* Curve tangent normal */
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device float3 curve_tangent_normal(KernelGlobals kg, ccl_private const ShaderData *sd)
|
2017-08-07 19:48:49 +02:00
|
|
|
{
|
2013-01-03 12:08:54 +00:00
|
|
|
float3 tgN = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
|
2021-12-20 02:52:56 +01:00
|
|
|
if (sd->type & PRIMITIVE_CURVE) {
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
tgN = -(-sd->I - sd->dPdu * (dot(sd->dPdu, -sd->I) / len_squared(sd->dPdu)));
|
2013-01-03 12:08:54 +00:00
|
|
|
tgN = normalize(tgN);
|
|
|
|
|
|
|
|
/* need to find suitable scaled gd for corrected normal */
|
|
|
|
# if 0
|
2017-02-16 06:24:13 -05:00
|
|
|
tgN = normalize(tgN - gd * sd->dPdu);
|
2013-01-03 12:08:54 +00:00
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return tgN;
|
|
|
|
}
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* Curve bounds utility function */
|
2013-01-03 12:08:54 +00:00
|
|
|
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_device_inline void curvebounds(ccl_private float *lower,
|
|
|
|
ccl_private float *upper,
|
|
|
|
ccl_private float *extremta,
|
|
|
|
ccl_private float *extrema,
|
|
|
|
ccl_private float *extremtb,
|
|
|
|
ccl_private float *extremb,
|
2014-03-29 13:03:45 +01:00
|
|
|
float p0,
|
|
|
|
float p1,
|
|
|
|
float p2,
|
|
|
|
float p3)
|
|
|
|
{
|
|
|
|
float halfdiscroot = (p2 * p2 - 3 * p3 * p1);
|
|
|
|
float ta = -1.0f;
|
|
|
|
float tb = -1.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:45 +01:00
|
|
|
*extremta = -1.0f;
|
|
|
|
*extremtb = -1.0f;
|
|
|
|
*upper = p0;
|
2014-04-23 01:10:26 +02:00
|
|
|
*lower = (p0 + p1) + (p2 + p3);
|
2014-03-29 13:03:45 +01:00
|
|
|
*extrema = *upper;
|
|
|
|
*extremb = *lower;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:45 +01:00
|
|
|
if (*lower >= *upper) {
|
|
|
|
*upper = *lower;
|
|
|
|
*lower = p0;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:45 +01:00
|
|
|
if (halfdiscroot >= 0) {
|
2014-04-23 01:10:26 +02:00
|
|
|
float inv3p3 = (1.0f / 3.0f) / p3;
|
2014-05-03 07:22:14 +10:00
|
|
|
halfdiscroot = sqrtf(halfdiscroot);
|
2014-04-23 01:10:26 +02:00
|
|
|
ta = (-p2 - halfdiscroot) * inv3p3;
|
|
|
|
tb = (-p2 + halfdiscroot) * inv3p3;
|
2014-03-29 13:03:45 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:45 +01:00
|
|
|
float t2;
|
|
|
|
float t3;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:45 +01:00
|
|
|
if (ta > 0.0f && ta < 1.0f) {
|
|
|
|
t2 = ta * ta;
|
|
|
|
t3 = t2 * ta;
|
|
|
|
*extremta = ta;
|
|
|
|
*extrema = p3 * t3 + p2 * t2 + p1 * ta + p0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-23 01:10:26 +02:00
|
|
|
*upper = fmaxf(*extrema, *upper);
|
|
|
|
*lower = fminf(*extrema, *lower);
|
2014-03-29 13:03:45 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:45 +01:00
|
|
|
if (tb > 0.0f && tb < 1.0f) {
|
|
|
|
t2 = tb * tb;
|
|
|
|
t3 = t2 * tb;
|
|
|
|
*extremtb = tb;
|
|
|
|
*extremb = p3 * t3 + p2 * t2 + p1 * tb + p0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-23 01:10:26 +02:00
|
|
|
*upper = fmaxf(*extremb, *upper);
|
|
|
|
*lower = fminf(*extremb, *lower);
|
2014-03-29 13:03:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-07 19:53:12 +02:00
|
|
|
#endif /* __HAIR__ */
|
2014-03-29 13:03:45 +01:00
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
CCL_NAMESPACE_END
|