Files
test2/intern/cycles/kernel/svm/vector_transform.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

131 lines
3.8 KiB
C
Raw Normal View History

/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: Apache-2.0 */
#pragma once
#include "kernel/geom/object.h"
#include "kernel/svm/util.h"
CCL_NAMESPACE_BEGIN
/* Vector Transform */
ccl_device_noinline void svm_node_vector_transform(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,
const uint4 node)
{
uint itype;
uint ifrom;
uint ito;
uint vector_in;
uint vector_out;
svm_unpack_node_uchar3(node.y, &itype, &ifrom, &ito);
svm_unpack_node_uchar2(node.z, &vector_in, &vector_out);
float3 in = stack_load_float3(stack, vector_in);
const NodeVectorTransformType type = (NodeVectorTransformType)itype;
const NodeVectorTransformConvertSpace from = (NodeVectorTransformConvertSpace)ifrom;
const NodeVectorTransformConvertSpace to = (NodeVectorTransformConvertSpace)ito;
Transform tfm;
const bool is_object = (sd->object != OBJECT_NONE) || (sd->type == PRIMITIVE_LAMP);
const bool is_normal = (type == NODE_VECTOR_TRANSFORM_TYPE_NORMAL);
const bool is_direction = (type == NODE_VECTOR_TRANSFORM_TYPE_VECTOR);
/* From world */
if (from == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD) {
if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) {
if (is_normal) {
tfm = kernel_data.cam.cameratoworld;
in = normalize(transform_direction_transposed(&tfm, in));
}
else {
tfm = kernel_data.cam.worldtocamera;
in = is_direction ? transform_direction(&tfm, in) : transform_point(&tfm, in);
}
}
else if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
if (is_normal) {
object_inverse_normal_transform(kg, sd, &in);
}
else if (is_direction) {
object_inverse_dir_transform(kg, sd, &in);
}
else {
object_inverse_position_transform(kg, sd, &in);
}
}
}
/* From camera */
else if (from == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) {
if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD ||
to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT)
{
if (is_normal) {
tfm = kernel_data.cam.worldtocamera;
in = normalize(transform_direction_transposed(&tfm, in));
}
else {
tfm = kernel_data.cam.cameratoworld;
in = is_direction ? transform_direction(&tfm, in) : transform_point(&tfm, in);
}
}
if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
if (is_normal) {
object_inverse_normal_transform(kg, sd, &in);
}
else if (is_direction) {
object_inverse_dir_transform(kg, sd, &in);
}
else {
object_inverse_position_transform(kg, sd, &in);
}
}
}
/* From object */
else if (from == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT) {
if ((to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD ||
to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) &&
is_object)
{
if (is_normal) {
object_normal_transform(kg, sd, &in);
}
else if (is_direction) {
object_dir_transform(kg, sd, &in);
}
else {
object_position_transform(kg, sd, &in);
}
}
if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) {
if (is_normal) {
tfm = kernel_data.cam.cameratoworld;
in = normalize(transform_direction_transposed(&tfm, in));
}
else {
tfm = kernel_data.cam.worldtocamera;
if (is_direction) {
in = transform_direction(&tfm, in);
}
else {
in = transform_point(&tfm, in);
}
}
}
}
2014-05-05 02:19:08 +10:00
/* Output */
if (stack_valid(vector_out)) {
stack_store_float3(stack, vector_out, in);
}
}
CCL_NAMESPACE_END