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
|
|
|
|
|
|
|
|
|
|
#include "kernel/svm/mapping_util.h"
|
2024-12-26 17:53:57 +01:00
|
|
|
#include "kernel/svm/util.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
/* Mapping Node */
|
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline void svm_node_mapping(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)
|
2019-09-04 23:17:13 +02:00
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
uint vector_stack_offset;
|
|
|
|
|
uint location_stack_offset;
|
|
|
|
|
uint rotation_stack_offset;
|
|
|
|
|
uint scale_stack_offset;
|
2019-09-04 23:17:13 +02:00
|
|
|
svm_unpack_node_uchar4(inputs_stack_offsets,
|
|
|
|
|
&vector_stack_offset,
|
|
|
|
|
&location_stack_offset,
|
|
|
|
|
&rotation_stack_offset,
|
|
|
|
|
&scale_stack_offset);
|
|
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const float3 vector = stack_load_float3(stack, vector_stack_offset);
|
|
|
|
|
const float3 location = stack_load_float3(stack, location_stack_offset);
|
|
|
|
|
const float3 rotation = stack_load_float3(stack, rotation_stack_offset);
|
|
|
|
|
const float3 scale = stack_load_float3(stack, scale_stack_offset);
|
2019-09-04 23:17:13 +02:00
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const float3 result = svm_mapping((NodeMappingType)type, vector, location, rotation, scale);
|
2024-10-08 00:33:56 +02:00
|
|
|
stack_store_float3(stack, result_stack_offset, result);
|
2019-09-04 23:17:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Texture Mapping */
|
|
|
|
|
|
2024-10-08 00:33:56 +02:00
|
|
|
ccl_device_noinline int svm_node_texture_mapping(KernelGlobals kg,
|
|
|
|
|
ccl_private ShaderData *sd,
|
|
|
|
|
ccl_private float *stack,
|
2025-01-01 18:15:54 +01:00
|
|
|
const uint vec_offset,
|
|
|
|
|
const uint out_offset,
|
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
|
|
|
const float3 v = stack_load_float3(stack, vec_offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
Transform tfm;
|
2024-10-08 00:33:56 +02:00
|
|
|
tfm.x = read_node_float(kg, &offset);
|
|
|
|
|
tfm.y = read_node_float(kg, &offset);
|
|
|
|
|
tfm.z = read_node_float(kg, &offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const float3 r = transform_point(&tfm, v);
|
2024-10-08 00:33:56 +02:00
|
|
|
stack_store_float3(stack, out_offset, r);
|
|
|
|
|
return offset;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-08 00:33:56 +02:00
|
|
|
ccl_device_noinline int svm_node_min_max(KernelGlobals kg,
|
|
|
|
|
ccl_private ShaderData *sd,
|
|
|
|
|
ccl_private float *stack,
|
2025-01-01 18:15:54 +01:00
|
|
|
const uint vec_offset,
|
|
|
|
|
const uint out_offset,
|
2024-10-08 00:33:56 +02:00
|
|
|
int offset)
|
2012-05-07 20:24:38 +00:00
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const float3 v = stack_load_float3(stack, vec_offset);
|
2012-05-07 20:24:38 +00:00
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const float3 mn = make_float3(read_node_float(kg, &offset));
|
|
|
|
|
const float3 mx = make_float3(read_node_float(kg, &offset));
|
2012-05-07 20:24:38 +00:00
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const float3 r = min(max(mn, v), mx);
|
2024-10-08 00:33:56 +02:00
|
|
|
stack_store_float3(stack, out_offset, r);
|
|
|
|
|
return offset;
|
2012-05-07 20:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|