Blender V5.3
types_gpu_compressed.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2026 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "util/half.h"
9
11
12/* Compact storage of data types on GPU, stored in full precision on CPU.
13 * Under the assumption that reducing state size is important on GPU and
14 * math is relatively cheap. */
15
16/* A float stored in half precision. */
20
21#ifdef __KERNEL_GPU__
22 half v;
23#else
24 float v;
25#endif
26
28
30 {
31#ifdef __KERNEL_GPU__
32 v = float_to_half(a);
33#else
34 v = a;
35#endif
36 }
37
39 {
40#ifdef __KERNEL_GPU__
41 return half_to_float(v);
42#else
43 return v;
44#endif
45 }
46
48 {
49#ifdef __KERNEL_GPU__
50 v = float_to_half(a);
51#else
52 v = a;
53#endif
54 return *this;
55 }
56
63
64#ifdef __KERNEL_METAL__
66 {
67# ifdef __KERNEL_GPU__
68 return half_to_float(v);
69# else
70 return v;
71# endif
72 }
73
75 {
76# ifdef __KERNEL_GPU__
77 v = float_to_half(a);
78# else
79 v = a;
80# endif
81 return *this;
82 }
83
86 {
87 v = a.v;
88 return *this;
89 }
90#endif
91};
92
93/* Spectrum stored in half precision. */
97
98#ifdef __KERNEL_GPU__
100#else
102#endif
103
105
107 {
108#ifdef __KERNEL_GPU__
110#else
111 v = a;
112#endif
113 }
114
116 {
117#ifdef __KERNEL_GPU__
119#else
120 return v;
121#endif
122 }
123
126 {
127#ifdef __KERNEL_GPU__
129#else
130 v = a;
131#endif
132 return *this;
133 }
134
141
142#ifdef __KERNEL_METAL__
144 {
145# ifdef __KERNEL_GPU__
147# else
148 return v;
149# endif
150 }
151
154 {
155# ifdef __KERNEL_GPU__
157# else
158 v = a;
159# endif
160 return *this;
161 }
162
165 {
166 v = a.v;
167 return *this;
168 }
169#endif
170};
171
172/* Templates for determining GPU storage type and size from the host. */
173template<typename...> using gpu_void_t = void;
174template<typename T, typename = void> struct gpu_state_storage {
175 using gpu_type = T;
176};
178 using gpu_type = typename T::compressed_type;
179};
180
Definition half.h:29
#define ccl_private
#define ccl_global
#define ccl_device_inline_method
#define CCL_NAMESPACE_END
ccl_device_inline float3 packed_half3_to_float3(const packed_half3 h)
Definition half.h:298
ccl_device_inline float half_to_float(half h)
Definition half.h:198
ccl_device_inline packed_half3 float3_to_packed_half3(const float3 f)
Definition half.h:279
ccl_device_inline half float_to_half(const float f)
Definition half.h:218
#define T
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ccl_device_inline_method FloatCompressedOnGPU(const float a)
ccl_device_inline_method ccl_global FloatCompressedOnGPU & operator=(FloatCompressedOnGPU a) ccl_global
FloatCompressedOnGPU()=default
ccl_device_inline_method ccl_global FloatCompressedOnGPU & operator=(const float a) ccl_global
ccl_device_inline_method ccl_global SpectrumCompressedOnGPU & operator=(SpectrumCompressedOnGPU a) ccl_global
SpectrumCompressedOnGPU()=default
ccl_device_inline_method ccl_global SpectrumCompressedOnGPU & operator=(const Spectrum a) ccl_global
ccl_device_inline_method SpectrumCompressedOnGPU(const Spectrum a)
void gpu_void_t
float3 Spectrum