2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-12-26 17:53:57 +01:00
|
|
|
#include "kernel/svm/math_util.h"
|
|
|
|
|
#include "kernel/svm/util.h"
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline void svm_node_math(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,
|
2024-10-08 00:33:56 +02:00
|
|
|
ccl_private float *stack,
|
2025-01-01 18:15:54 +01:00
|
|
|
const uint type,
|
|
|
|
|
const uint inputs_stack_offsets,
|
|
|
|
|
const uint result_stack_offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
uint a_stack_offset;
|
|
|
|
|
uint b_stack_offset;
|
|
|
|
|
uint c_stack_offset;
|
Maths Node: Additional functions
When creating shaders and using maths functions it is expected that Blender should match functions in other DCC applications, game engines and shading languages such as GLSL and OSL.
This patch adds missing functions to the Blender maths node.
Ideally, it would be nice to have these functions available to vectors too but that is not part of this patch.
This patch adds the following functions trunc, snap, wrap, compare, pingpong, sign, radians, degrees, cosh, sinh, tanh, exp, smoothmin and inversesqrt.
Sign function is based on GLSL and OSL functions and returns zero when x == 0.
Differential Revision: https://developer.blender.org/D5957
2019-12-05 23:02:05 +00:00
|
|
|
svm_unpack_node_uchar3(inputs_stack_offsets, &a_stack_offset, &b_stack_offset, &c_stack_offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const float a = stack_load_float(stack, a_stack_offset);
|
|
|
|
|
const float b = stack_load_float(stack, b_stack_offset);
|
|
|
|
|
const float c = stack_load_float(stack, c_stack_offset);
|
|
|
|
|
const float result = svm_math((NodeMathType)type, a, b, c);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-10-08 00:33:56 +02:00
|
|
|
stack_store_float(stack, result_stack_offset, result);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-08 00:33:56 +02:00
|
|
|
ccl_device_noinline int svm_node_vector_math(KernelGlobals kg,
|
|
|
|
|
ccl_private ShaderData *sd,
|
|
|
|
|
ccl_private float *stack,
|
2025-01-01 18:15:54 +01:00
|
|
|
const uint type,
|
|
|
|
|
const uint inputs_stack_offsets,
|
|
|
|
|
const uint outputs_stack_offsets,
|
2024-10-08 00:33:56 +02:00
|
|
|
int offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
uint value_stack_offset;
|
|
|
|
|
uint vector_stack_offset;
|
|
|
|
|
uint a_stack_offset;
|
|
|
|
|
uint b_stack_offset;
|
|
|
|
|
uint param1_stack_offset;
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar3(
|
2021-03-23 09:21:56 +00:00
|
|
|
inputs_stack_offsets, &a_stack_offset, &b_stack_offset, ¶m1_stack_offset);
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar2(outputs_stack_offsets, &value_stack_offset, &vector_stack_offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const float3 a = stack_load_float3(stack, a_stack_offset);
|
|
|
|
|
const float3 b = stack_load_float3(stack, b_stack_offset);
|
2020-03-27 14:24:13 +01:00
|
|
|
float3 c = make_float3(0.0f, 0.0f, 0.0f);
|
2024-12-29 17:32:00 +01:00
|
|
|
const float param1 = stack_load_float(stack, param1_stack_offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Shading: Add more operators to Vector Math node.
Add Multiply, Divide, Project, Reflect, Distance, Length, Scale, Snap,
Floor, Ceil, Modulo, Fraction, Absolute, Minimum, and Maximum operators
to the Vector Math node. The Value output has been removed from operators
whose output is a vector, and the other way around. All of those removals
has been handled properly in versioning code.
The patch doesn't include tests for the new operators. Tests will be added
in a later patch.
Reviewers: brecht, JacquesLucke
Differential Revision: https://developer.blender.org/D5523
2019-08-21 19:36:33 +02:00
|
|
|
float value;
|
|
|
|
|
float3 vector;
|
2020-02-14 21:46:10 +00:00
|
|
|
|
|
|
|
|
/* 3 Vector Operators */
|
2021-06-04 16:53:50 +01:00
|
|
|
if (type == NODE_VECTOR_MATH_WRAP || type == NODE_VECTOR_MATH_FACEFORWARD ||
|
|
|
|
|
type == NODE_VECTOR_MATH_MULTIPLY_ADD)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const uint4 extra_node = read_node(kg, &offset);
|
2024-10-08 00:33:56 +02:00
|
|
|
c = stack_load_float3(stack, extra_node.x);
|
2020-02-14 21:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-23 09:21:56 +00:00
|
|
|
svm_vector_math(&value, &vector, (NodeVectorMathType)type, a, b, c, param1);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
if (stack_valid(value_stack_offset)) {
|
2024-10-08 00:33:56 +02:00
|
|
|
stack_store_float(stack, value_stack_offset, value);
|
2024-12-26 17:53:59 +01:00
|
|
|
}
|
|
|
|
|
if (stack_valid(vector_stack_offset)) {
|
2024-10-08 00:33:56 +02:00
|
|
|
stack_store_float3(stack, vector_stack_offset, vector);
|
2024-12-26 17:53:59 +01:00
|
|
|
}
|
2024-10-08 00:33:56 +02:00
|
|
|
return offset;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|