Blender V5.0
metal/context_begin.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5// clang-format off
6
7#ifdef WITH_NANOVDB
8# include "kernel/util/nanovdb.h"
9#endif
10
11/* Open the Metal kernel context class
12 * Necessary to access resource bindings */
13class MetalKernelContext {
14 public:
15 constant KernelParamsMetal &launch_params_metal;
16 constant MetalAncillaries *metal_ancillaries;
17
18 MetalKernelContext(constant KernelParamsMetal &_launch_params_metal, constant MetalAncillaries * _metal_ancillaries)
19 : launch_params_metal(_launch_params_metal), metal_ancillaries(_metal_ancillaries)
20 {}
21
22 MetalKernelContext(constant KernelParamsMetal &_launch_params_metal)
23 : launch_params_metal(_launch_params_metal)
24 {}
25
26 /* texture fetch adapter functions */
28
29 template<typename T>
30 inline __attribute__((__always_inline__))
31 T ccl_gpu_tex_object_read_2D(ccl_gpu_tex_object_2D tex, const float x, float y) const {
33 return 0;
34 }
35
36 // texture2d
37 template<>
38 inline __attribute__((__always_inline__))
39 float4 ccl_gpu_tex_object_read_2D(ccl_gpu_tex_object_2D tex, const float x, float y) const {
40 const uint tid(tex);
41 const uint sid(tex >> 32);
42 return ((ccl_global Texture2DParamsMetal*)metal_ancillaries->textures)[tid].tex.sample(metal_samplers[sid], float2(x, y));
43 }
44 template<>
45 inline __attribute__((__always_inline__))
46 float ccl_gpu_tex_object_read_2D(ccl_gpu_tex_object_2D tex, const float x, float y) const {
47 const uint tid(tex);
48 const uint sid(tex >> 32);
49 return ((ccl_global Texture2DParamsMetal*)metal_ancillaries->textures)[tid].tex.sample(metal_samplers[sid], float2(x, y)).x;
50 }
51
53
54 // clang-format on
unsigned int uint
unsigned long long int uint64_t
static __attribute__((constructor)) void cpu_check()
Definition cpu_check.cc:94
#define kernel_assert(cond)
#define ccl_global
ccl_device_forceinline T ccl_gpu_tex_object_read_2D(const ccl_gpu_tex_object_2D texobj, const float x, const float y)
CUtexObject ccl_gpu_tex_object_2D
constexpr constant array< sampler, SamplerCount > metal_samplers
VecBase< float, 2 > float2
VecBase< float, 4 > float4
#define T