Blender V5.3
sepcomb_vector.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
8#include "kernel/svm/util.h"
9
11
12/* Vector combine / separate, used for the RGB and XYZ nodes */
13
14template<typename Float3Type>
17{
18 using FloatType = dual_scalar_t<Float3Type>;
19 const FloatType value = stack_load<FloatType>(stack, node.in);
20
21 if (stack_valid(node.out_offset)) {
22 if constexpr (is_dual_v<Float3Type>) {
23 stack_store_float(stack, node.out_offset + node.vector_index, value.val);
24 stack_store_float(stack, node.out_offset + node.vector_index + 3, value.dx);
25 stack_store_float(stack, node.out_offset + node.vector_index + 6, value.dy);
26 }
27 else {
28 stack_store_float(stack, node.out_offset + node.vector_index, value);
29 }
30 }
31}
32
33template<typename Float3Type>
36{
37 const Float3Type vector = stack_load<Float3Type>(stack, node.vector);
38
39 if (stack_valid(node.out_offset)) {
40 if constexpr (is_dual_v<Float3Type>) {
41 if (node.vector_index == 0) {
42 stack_store(stack, node.out_offset, vector.x());
43 }
44 else if (node.vector_index == 1) {
45 stack_store(stack, node.out_offset, vector.y());
46 }
47 else {
48 stack_store(stack, node.out_offset, vector.z());
49 }
50 }
51 else {
52 if (node.vector_index == 0) {
53 stack_store(stack, node.out_offset, vector.x);
54 }
55 else if (node.vector_index == 1) {
56 stack_store(stack, node.out_offset, vector.y);
57 }
58 else {
59 stack_store(stack, node.out_offset, vector.z);
60 }
61 }
62 }
63}
64
65template<typename Float3Type>
67 ccl_private float *ccl_restrict stack,
69{
70 const Float3Type vector = stack_load<Float3Type>(stack, node.vector);
71 const int index = stack_load(stack, node.index);
72
73 if (stack_valid(node.out_offset)) {
76 }
77 else if constexpr (is_dual_v<Float3Type>) {
78 if (index == 0) {
79 stack_store(stack, node.out_offset, vector.x());
80 }
81 else if (index == 1) {
82 stack_store(stack, node.out_offset, vector.y());
83 }
84 else {
85 stack_store(stack, node.out_offset, vector.z());
86 }
87 }
88 else {
89 if (index == 0) {
90 stack_store(stack, node.out_offset, vector.x);
91 }
92 else if (index == 1) {
93 stack_store(stack, node.out_offset, vector.y);
94 }
95 else {
96 stack_store(stack, node.out_offset, vector.z);
97 }
98 }
99 }
100}
101
ccl_device_inline void stack_store_float(ccl_private float *stack, const uint a, const float f)
ccl_device_inline void stack_store(ccl_private float *stack, const uint a, const float f)
ccl_device_inline bool stack_valid(const uint a)
ccl_device_inline T stack_load(const ccl_private float *stack, const uint a)
#define ccl_restrict
#define ccl_private
#define ccl_global
#define CCL_NAMESPACE_END
#define index(i)
ccl_device_inline T make_zero()
Definition math_dual.h:20
#define ccl_device
CCL_NAMESPACE_BEGIN ccl_device void svm_node_combine_vector(ccl_private float *ccl_restrict stack, const ccl_global SVMNodeCombineVector &ccl_restrict node)
ccl_device void svm_node_get_vector_component(ccl_private float *ccl_restrict stack, const ccl_global SVMNodeGetVectorComponent &ccl_restrict node)
ccl_device void svm_node_separate_vector(ccl_private float *ccl_restrict stack, const ccl_global SVMNodeSeparateVector &ccl_restrict node)
ccl_static_constexpr bool is_dual_v
Definition types_dual.h:118
typename dual_scalar_type< T >::type dual_scalar_t
Definition types_dual.h:141