2022-02-11 13:53:21 +01:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#pragma once
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Attribute Node */
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device AttributeDescriptor svm_node_attr_init(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 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
|
|
|
uint4 node,
|
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 NodeAttributeOutputType *type,
|
|
|
|
ccl_private uint *out_offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2015-10-05 14:45:03 +05:00
|
|
|
*out_offset = node.z;
|
2020-10-26 18:32:48 +01:00
|
|
|
*type = (NodeAttributeOutputType)node.w;
|
2016-07-01 17:36:27 -04:00
|
|
|
|
|
|
|
AttributeDescriptor desc;
|
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
if (sd->object != OBJECT_NONE) {
|
2016-07-01 17:36:27 -04:00
|
|
|
desc = find_attribute(kg, sd, node.y);
|
|
|
|
if (desc.offset == ATTR_STD_NOT_FOUND) {
|
2016-08-23 13:57:45 -04:00
|
|
|
desc = attribute_not_found();
|
2016-07-01 17:36:27 -04:00
|
|
|
desc.offset = 0;
|
|
|
|
desc.type = (NodeAttributeType)node.w;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* background */
|
2016-08-23 13:57:45 -04:00
|
|
|
desc = attribute_not_found();
|
2016-07-01 17:36:27 -04:00
|
|
|
desc.offset = 0;
|
|
|
|
desc.type = (NodeAttributeType)node.w;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2016-07-01 17:36:27 -04:00
|
|
|
|
|
|
|
return desc;
|
2011-04-27 11:58:34 +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
|
|
|
template<uint node_feature_mask>
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline void svm_node_attr(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 ShaderData *sd,
|
|
|
|
ccl_private float *stack,
|
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
|
|
|
uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-10-26 18:32:48 +01:00
|
|
|
NodeAttributeOutputType type = NODE_ATTR_OUTPUT_FLOAT;
|
2019-08-21 12:03:32 +02:00
|
|
|
uint out_offset = 0;
|
2016-07-01 17:36:27 -04:00
|
|
|
AttributeDescriptor desc = svm_node_attr_init(kg, sd, node, &type, &out_offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-10-26 18:13:53 +01:00
|
|
|
#ifdef __VOLUME__
|
2021-10-17 16:10:10 +02:00
|
|
|
IF_KERNEL_NODES_FEATURE(VOLUME)
|
|
|
|
{
|
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
|
|
|
/* Volumes
|
|
|
|
* NOTE: moving this into its own node type might help improve performance. */
|
|
|
|
if (primitive_is_volume_attribute(sd, desc)) {
|
|
|
|
const float4 value = volume_attribute_float4(kg, sd, desc);
|
2020-10-26 18:13:53 +01: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
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
|
|
|
const float f = volume_attribute_value_to_float(value);
|
|
|
|
stack_store_float(stack, out_offset, f);
|
|
|
|
}
|
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
|
|
|
const float3 f = volume_attribute_value_to_float3(value);
|
|
|
|
stack_store_float3(stack, out_offset, f);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const float f = volume_attribute_value_to_alpha(value);
|
|
|
|
stack_store_float(stack, out_offset, f);
|
|
|
|
}
|
|
|
|
return;
|
2020-10-26 18:13:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-08-17 23:46:17 +02:00
|
|
|
if (node.y == ATTR_STD_GENERATED && desc.element == ATTR_ELEMENT_NONE) {
|
|
|
|
/* No generated attribute, fall back to object coordinates. */
|
|
|
|
float3 f = sd->P;
|
2022-01-20 21:28:41 +01:00
|
|
|
if (sd->object != OBJECT_NONE) {
|
|
|
|
object_inverse_position_transform(kg, sd, &f);
|
|
|
|
}
|
2021-08-17 23:46:17 +02:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
|
|
|
stack_store_float(stack, out_offset, average(f));
|
|
|
|
}
|
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
|
|
|
stack_store_float3(stack, out_offset, f);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 18:32:48 +01:00
|
|
|
/* Surface. */
|
2019-03-05 14:54:54 +01:00
|
|
|
if (desc.type == NODE_ATTR_FLOAT) {
|
2020-10-26 18:13:53 +01:00
|
|
|
float f = primitive_surface_attribute_float(kg, sd, desc, NULL, NULL);
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2013-01-03 12:08:54 +00:00
|
|
|
stack_store_float(stack, out_offset, f);
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2019-02-19 15:41:22 +01:00
|
|
|
stack_store_float3(stack, out_offset, make_float3(f, f, f));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-03-05 14:54:54 +01:00
|
|
|
else if (desc.type == NODE_ATTR_FLOAT2) {
|
2020-10-26 18:13:53 +01:00
|
|
|
float2 f = primitive_surface_attribute_float2(kg, sd, desc, NULL, NULL);
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2019-03-05 14:54:54 +01:00
|
|
|
stack_store_float(stack, out_offset, f.x);
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2019-03-05 14:54:54 +01:00
|
|
|
stack_store_float3(stack, out_offset, make_float3(f.x, f.y, 0.0f));
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
2019-03-05 14:54:54 +01:00
|
|
|
}
|
2020-10-26 18:23:40 +01:00
|
|
|
else if (desc.type == NODE_ATTR_FLOAT4 || desc.type == NODE_ATTR_RGBA) {
|
2020-10-26 18:13:53 +01:00
|
|
|
float4 f = primitive_surface_attribute_float4(kg, sd, desc, NULL, NULL);
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2019-09-12 17:42:13 +02:00
|
|
|
stack_store_float(stack, out_offset, average(float4_to_float3(f)));
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2019-09-12 17:42:13 +02:00
|
|
|
stack_store_float3(stack, out_offset, float4_to_float3(f));
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, f.w);
|
|
|
|
}
|
2019-09-12 17:42:13 +02:00
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
else {
|
2020-10-26 18:13:53 +01:00
|
|
|
float3 f = primitive_surface_attribute_float3(kg, sd, desc, NULL, NULL);
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2019-02-19 15:41:22 +01:00
|
|
|
stack_store_float(stack, out_offset, average(f));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2019-02-19 15:41:22 +01:00
|
|
|
stack_store_float3(stack, out_offset, f);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline void svm_node_attr_bump_dx(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 ShaderData *sd,
|
|
|
|
ccl_private float *stack,
|
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
|
|
|
uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-10-26 18:32:48 +01:00
|
|
|
NodeAttributeOutputType type = NODE_ATTR_OUTPUT_FLOAT;
|
2019-08-21 12:03:32 +02:00
|
|
|
uint out_offset = 0;
|
2016-07-01 17:36:27 -04:00
|
|
|
AttributeDescriptor desc = svm_node_attr_init(kg, sd, node, &type, &out_offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-10-26 18:13:53 +01:00
|
|
|
#ifdef __VOLUME__
|
|
|
|
/* Volume */
|
|
|
|
if (primitive_is_volume_attribute(sd, desc)) {
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2020-10-26 18:13:53 +01:00
|
|
|
stack_store_float(stack, out_offset, 0.0f);
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2020-10-26 18:13:53 +01:00
|
|
|
stack_store_float3(stack, out_offset, make_float3(0.0f, 0.0f, 0.0f));
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
2020-10-26 18:13:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-08-17 23:46:17 +02:00
|
|
|
if (node.y == ATTR_STD_GENERATED && desc.element == ATTR_ELEMENT_NONE) {
|
|
|
|
/* No generated attribute, fall back to object coordinates. */
|
|
|
|
float3 f = sd->P + sd->dP.dx;
|
2022-01-20 21:28:41 +01:00
|
|
|
if (sd->object != OBJECT_NONE) {
|
|
|
|
object_inverse_position_transform(kg, sd, &f);
|
|
|
|
}
|
2021-08-17 23:46:17 +02:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
|
|
|
stack_store_float(stack, out_offset, average(f));
|
|
|
|
}
|
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
|
|
|
stack_store_float3(stack, out_offset, f);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 18:13:53 +01:00
|
|
|
/* Surface */
|
2019-03-05 14:54:54 +01:00
|
|
|
if (desc.type == NODE_ATTR_FLOAT) {
|
2019-02-19 15:41:22 +01:00
|
|
|
float dx;
|
|
|
|
float f = primitive_surface_attribute_float(kg, sd, desc, &dx, NULL);
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2013-01-03 12:08:54 +00:00
|
|
|
stack_store_float(stack, out_offset, f + dx);
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2019-02-19 15:41:22 +01:00
|
|
|
stack_store_float3(stack, out_offset, make_float3(f + dx, f + dx, f + dx));
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-03-05 14:54:54 +01:00
|
|
|
else if (desc.type == NODE_ATTR_FLOAT2) {
|
|
|
|
float2 dx;
|
2020-10-26 18:13:53 +01:00
|
|
|
float2 f = primitive_surface_attribute_float2(kg, sd, desc, &dx, NULL);
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2019-03-05 14:54:54 +01:00
|
|
|
stack_store_float(stack, out_offset, f.x + dx.x);
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2019-03-05 14:54:54 +01:00
|
|
|
stack_store_float3(stack, out_offset, make_float3(f.x + dx.x, f.y + dx.y, 0.0f));
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
2019-03-05 14:54:54 +01:00
|
|
|
}
|
2020-10-26 18:23:40 +01:00
|
|
|
else if (desc.type == NODE_ATTR_FLOAT4 || desc.type == NODE_ATTR_RGBA) {
|
2019-09-12 17:42:13 +02:00
|
|
|
float4 dx;
|
2020-10-26 18:13:53 +01:00
|
|
|
float4 f = primitive_surface_attribute_float4(kg, sd, desc, &dx, NULL);
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2019-09-12 17:42:13 +02:00
|
|
|
stack_store_float(stack, out_offset, average(float4_to_float3(f + dx)));
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2019-09-12 17:42:13 +02:00
|
|
|
stack_store_float3(stack, out_offset, float4_to_float3(f + dx));
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, f.w + dx.w);
|
|
|
|
}
|
2019-09-12 17:42:13 +02:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
else {
|
2019-02-19 15:41:22 +01:00
|
|
|
float3 dx;
|
|
|
|
float3 f = primitive_surface_attribute_float3(kg, sd, desc, &dx, NULL);
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2019-02-19 15:41:22 +01:00
|
|
|
stack_store_float(stack, out_offset, average(f + dx));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2019-02-19 15:41:22 +01:00
|
|
|
stack_store_float3(stack, out_offset, f + dx);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline void svm_node_attr_bump_dy(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 ShaderData *sd,
|
|
|
|
ccl_private float *stack,
|
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
|
|
|
uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-10-26 18:32:48 +01:00
|
|
|
NodeAttributeOutputType type = NODE_ATTR_OUTPUT_FLOAT;
|
2019-08-21 12:03:32 +02:00
|
|
|
uint out_offset = 0;
|
2016-07-01 17:36:27 -04:00
|
|
|
AttributeDescriptor desc = svm_node_attr_init(kg, sd, node, &type, &out_offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-10-26 18:13:53 +01:00
|
|
|
#ifdef __VOLUME__
|
|
|
|
/* Volume */
|
|
|
|
if (primitive_is_volume_attribute(sd, desc)) {
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2020-10-26 18:13:53 +01:00
|
|
|
stack_store_float(stack, out_offset, 0.0f);
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2020-10-26 18:13:53 +01:00
|
|
|
stack_store_float3(stack, out_offset, make_float3(0.0f, 0.0f, 0.0f));
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
2020-10-26 18:13:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-08-17 23:46:17 +02:00
|
|
|
if (node.y == ATTR_STD_GENERATED && desc.element == ATTR_ELEMENT_NONE) {
|
|
|
|
/* No generated attribute, fall back to object coordinates. */
|
|
|
|
float3 f = sd->P + sd->dP.dy;
|
2022-01-20 21:28:41 +01:00
|
|
|
if (sd->object != OBJECT_NONE) {
|
|
|
|
object_inverse_position_transform(kg, sd, &f);
|
|
|
|
}
|
2021-08-17 23:46:17 +02:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
|
|
|
stack_store_float(stack, out_offset, average(f));
|
|
|
|
}
|
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
|
|
|
stack_store_float3(stack, out_offset, f);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 18:13:53 +01:00
|
|
|
/* Surface */
|
2019-03-05 14:54:54 +01:00
|
|
|
if (desc.type == NODE_ATTR_FLOAT) {
|
2019-02-19 15:41:22 +01:00
|
|
|
float dy;
|
|
|
|
float f = primitive_surface_attribute_float(kg, sd, desc, NULL, &dy);
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2013-01-03 12:08:54 +00:00
|
|
|
stack_store_float(stack, out_offset, f + dy);
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2019-02-19 15:41:22 +01:00
|
|
|
stack_store_float3(stack, out_offset, make_float3(f + dy, f + dy, f + dy));
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-03-05 14:54:54 +01:00
|
|
|
else if (desc.type == NODE_ATTR_FLOAT2) {
|
|
|
|
float2 dy;
|
2020-10-26 18:13:53 +01:00
|
|
|
float2 f = primitive_surface_attribute_float2(kg, sd, desc, NULL, &dy);
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2019-03-05 14:54:54 +01:00
|
|
|
stack_store_float(stack, out_offset, f.x + dy.x);
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2019-03-05 14:54:54 +01:00
|
|
|
stack_store_float3(stack, out_offset, make_float3(f.x + dy.x, f.y + dy.y, 0.0f));
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
2019-03-05 14:54:54 +01:00
|
|
|
}
|
2020-10-26 18:23:40 +01:00
|
|
|
else if (desc.type == NODE_ATTR_FLOAT4 || desc.type == NODE_ATTR_RGBA) {
|
2019-09-12 17:42:13 +02:00
|
|
|
float4 dy;
|
2020-10-26 18:13:53 +01:00
|
|
|
float4 f = primitive_surface_attribute_float4(kg, sd, desc, NULL, &dy);
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2019-09-12 17:42:13 +02:00
|
|
|
stack_store_float(stack, out_offset, average(float4_to_float3(f + dy)));
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2019-09-12 17:42:13 +02:00
|
|
|
stack_store_float3(stack, out_offset, float4_to_float3(f + dy));
|
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, f.w + dy.w);
|
|
|
|
}
|
2019-09-12 17:42:13 +02:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
else {
|
2019-02-19 15:41:22 +01:00
|
|
|
float3 dy;
|
|
|
|
float3 f = primitive_surface_attribute_float3(kg, sd, desc, NULL, &dy);
|
2020-10-26 18:32:48 +01:00
|
|
|
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
2019-02-19 15:41:22 +01:00
|
|
|
stack_store_float(stack, out_offset, average(f + dy));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
2019-02-19 15:41:22 +01:00
|
|
|
stack_store_float3(stack, out_offset, f + dy);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2020-10-26 18:32:48 +01:00
|
|
|
else {
|
|
|
|
stack_store_float(stack, out_offset, 1.0f);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|