nv-sgl 0.6.0__cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Sign up to get free protection for your applications and to get access to all the features.
- include/tevclient.h +393 -0
- nv_sgl-0.6.0.dist-info/LICENSE +29 -0
- nv_sgl-0.6.0.dist-info/METADATA +21 -0
- nv_sgl-0.6.0.dist-info/RECORD +133 -0
- nv_sgl-0.6.0.dist-info/WHEEL +6 -0
- nv_sgl-0.6.0.dist-info/top_level.txt +1 -0
- sgl/__init__.py +15 -0
- sgl/__init__.pyi +6738 -0
- sgl/include/sgl/app/app.h +113 -0
- sgl/include/sgl/core/bitmap.h +302 -0
- sgl/include/sgl/core/crypto.h +89 -0
- sgl/include/sgl/core/data_type.h +46 -0
- sgl/include/sgl/core/dds_file.h +103 -0
- sgl/include/sgl/core/enum.h +201 -0
- sgl/include/sgl/core/error.h +161 -0
- sgl/include/sgl/core/file_stream.h +77 -0
- sgl/include/sgl/core/file_system_watcher.h +141 -0
- sgl/include/sgl/core/format.h +36 -0
- sgl/include/sgl/core/fwd.h +90 -0
- sgl/include/sgl/core/hash.h +45 -0
- sgl/include/sgl/core/input.h +522 -0
- sgl/include/sgl/core/logger.h +214 -0
- sgl/include/sgl/core/macros.h +184 -0
- sgl/include/sgl/core/maths.h +45 -0
- sgl/include/sgl/core/memory_mapped_file.h +112 -0
- sgl/include/sgl/core/memory_mapped_file_stream.h +32 -0
- sgl/include/sgl/core/memory_stream.h +74 -0
- sgl/include/sgl/core/object.h +683 -0
- sgl/include/sgl/core/platform.h +239 -0
- sgl/include/sgl/core/plugin.h +331 -0
- sgl/include/sgl/core/resolver.h +39 -0
- sgl/include/sgl/core/short_vector.h +141 -0
- sgl/include/sgl/core/static_vector.h +111 -0
- sgl/include/sgl/core/stream.h +54 -0
- sgl/include/sgl/core/string.h +276 -0
- sgl/include/sgl/core/struct.h +360 -0
- sgl/include/sgl/core/thread.h +28 -0
- sgl/include/sgl/core/timer.h +52 -0
- sgl/include/sgl/core/traits.h +15 -0
- sgl/include/sgl/core/type_utils.h +19 -0
- sgl/include/sgl/core/window.h +177 -0
- sgl/include/sgl/device/agility_sdk.h +24 -0
- sgl/include/sgl/device/blit.h +88 -0
- sgl/include/sgl/device/buffer_cursor.h +162 -0
- sgl/include/sgl/device/command.h +539 -0
- sgl/include/sgl/device/cuda_api.h +766 -0
- sgl/include/sgl/device/cuda_interop.h +39 -0
- sgl/include/sgl/device/cuda_utils.h +107 -0
- sgl/include/sgl/device/cursor_utils.h +129 -0
- sgl/include/sgl/device/device.h +668 -0
- sgl/include/sgl/device/device_resource.h +37 -0
- sgl/include/sgl/device/fence.h +91 -0
- sgl/include/sgl/device/formats.h +330 -0
- sgl/include/sgl/device/framebuffer.h +85 -0
- sgl/include/sgl/device/fwd.h +164 -0
- sgl/include/sgl/device/helpers.h +20 -0
- sgl/include/sgl/device/hot_reload.h +75 -0
- sgl/include/sgl/device/input_layout.h +74 -0
- sgl/include/sgl/device/kernel.h +69 -0
- sgl/include/sgl/device/memory_heap.h +155 -0
- sgl/include/sgl/device/native_formats.h +342 -0
- sgl/include/sgl/device/native_handle.h +73 -0
- sgl/include/sgl/device/native_handle_traits.h +65 -0
- sgl/include/sgl/device/pipeline.h +138 -0
- sgl/include/sgl/device/print.h +45 -0
- sgl/include/sgl/device/python/cursor_utils.h +853 -0
- sgl/include/sgl/device/query.h +52 -0
- sgl/include/sgl/device/raytracing.h +84 -0
- sgl/include/sgl/device/reflection.h +1254 -0
- sgl/include/sgl/device/resource.h +705 -0
- sgl/include/sgl/device/sampler.h +57 -0
- sgl/include/sgl/device/shader.h +516 -0
- sgl/include/sgl/device/shader_cursor.h +85 -0
- sgl/include/sgl/device/shader_object.h +94 -0
- sgl/include/sgl/device/shader_offset.h +67 -0
- sgl/include/sgl/device/shared_handle.h +12 -0
- sgl/include/sgl/device/slang_utils.h +54 -0
- sgl/include/sgl/device/swapchain.h +74 -0
- sgl/include/sgl/device/types.h +782 -0
- sgl/include/sgl/math/colorspace.h +56 -0
- sgl/include/sgl/math/constants.h +7 -0
- sgl/include/sgl/math/float16.h +146 -0
- sgl/include/sgl/math/matrix.h +6 -0
- sgl/include/sgl/math/matrix_math.h +746 -0
- sgl/include/sgl/math/matrix_types.h +207 -0
- sgl/include/sgl/math/python/primitivetype.h +33 -0
- sgl/include/sgl/math/quaternion.h +6 -0
- sgl/include/sgl/math/quaternion_math.h +484 -0
- sgl/include/sgl/math/quaternion_types.h +83 -0
- sgl/include/sgl/math/ray.h +47 -0
- sgl/include/sgl/math/scalar_math.h +249 -0
- sgl/include/sgl/math/scalar_types.h +107 -0
- sgl/include/sgl/math/vector.h +6 -0
- sgl/include/sgl/math/vector_math.h +1796 -0
- sgl/include/sgl/math/vector_types.h +336 -0
- sgl/include/sgl/python/nanobind.h +489 -0
- sgl/include/sgl/python/py_doc.h +11600 -0
- sgl/include/sgl/python/sgl_ext_pch.h +8 -0
- sgl/include/sgl/sgl.h +21 -0
- sgl/include/sgl/sgl_pch.h +6 -0
- sgl/include/sgl/stl/bit.h +377 -0
- sgl/include/sgl/tests/testing.h +54 -0
- sgl/include/sgl/ui/fwd.h +34 -0
- sgl/include/sgl/ui/imgui_config.h +43 -0
- sgl/include/sgl/ui/ui.h +71 -0
- sgl/include/sgl/ui/widgets.h +918 -0
- sgl/include/sgl/utils/python/slangpy.h +366 -0
- sgl/include/sgl/utils/renderdoc.h +50 -0
- sgl/include/sgl/utils/slangpy.h +153 -0
- sgl/include/sgl/utils/tev.h +93 -0
- sgl/include/sgl/utils/texture_loader.h +106 -0
- sgl/libgfx.so +0 -0
- sgl/libsgl.so +0 -0
- sgl/libslang-glslang.so +0 -0
- sgl/libslang.so +0 -0
- sgl/libtevclient.a +0 -0
- sgl/math/__init__.pyi +5083 -0
- sgl/platform/__init__.pyi +102 -0
- sgl/renderdoc/__init__.pyi +51 -0
- sgl/sgl_ext.cpython-313-x86_64-linux-gnu.so +0 -0
- sgl/shaders/sgl/device/blit.slang +93 -0
- sgl/shaders/sgl/device/nvapi.slang +5 -0
- sgl/shaders/sgl/device/nvapi.slangh +7 -0
- sgl/shaders/sgl/device/print.slang +445 -0
- sgl/shaders/sgl/math/constants.slang +4 -0
- sgl/shaders/sgl/math/ray.slang +29 -0
- sgl/shaders/sgl/ui/imgui.slang +49 -0
- sgl/slangpy/__init__.pyi +268 -0
- sgl/tev/__init__.pyi +108 -0
- sgl/thread/__init__.pyi +4 -0
- sgl/ui/__init__.pyi +1118 -0
- share/cmake/tevclient/tevclient-config-release.cmake +19 -0
- share/cmake/tevclient/tevclient-config.cmake +103 -0
@@ -0,0 +1,249 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/math/scalar_types.h"
|
6
|
+
|
7
|
+
#include "sgl/stl/bit.h" // Replace with <bit> when available on all platforms.
|
8
|
+
|
9
|
+
#include <cmath>
|
10
|
+
|
11
|
+
namespace sgl::math {
|
12
|
+
|
13
|
+
// ----------------------------------------------------------------------------
|
14
|
+
// Boolean reductions
|
15
|
+
// ----------------------------------------------------------------------------
|
16
|
+
|
17
|
+
template<typename T>
|
18
|
+
[[nodiscard]] constexpr bool any(T x)
|
19
|
+
{
|
20
|
+
return x != T(0);
|
21
|
+
}
|
22
|
+
|
23
|
+
template<typename T>
|
24
|
+
[[nodiscard]] constexpr bool all(T x)
|
25
|
+
{
|
26
|
+
return x != T(0);
|
27
|
+
}
|
28
|
+
|
29
|
+
// ----------------------------------------------------------------------------
|
30
|
+
// Basic functions
|
31
|
+
// ----------------------------------------------------------------------------
|
32
|
+
|
33
|
+
template<arithmetic T>
|
34
|
+
[[nodiscard]] constexpr T min(T x, T y) noexcept
|
35
|
+
{
|
36
|
+
return x < y ? x : y;
|
37
|
+
}
|
38
|
+
|
39
|
+
template<arithmetic T>
|
40
|
+
[[nodiscard]] constexpr T max(T x, T y) noexcept
|
41
|
+
{
|
42
|
+
return x > y ? x : y;
|
43
|
+
}
|
44
|
+
|
45
|
+
template<arithmetic T>
|
46
|
+
[[nodiscard]] constexpr T clamp(T x, T min_, T max_) noexcept
|
47
|
+
{
|
48
|
+
return max(min_, min(max_, x));
|
49
|
+
}
|
50
|
+
|
51
|
+
template<signed_number T>
|
52
|
+
[[nodiscard]] constexpr T abs(T x) noexcept
|
53
|
+
{
|
54
|
+
return std::abs(x);
|
55
|
+
}
|
56
|
+
|
57
|
+
template<signed_number T>
|
58
|
+
[[nodiscard]] constexpr T sign(T x) noexcept
|
59
|
+
{
|
60
|
+
return x < T(0) ? T(-1) : (x > T(0) ? T(1) : T(0));
|
61
|
+
}
|
62
|
+
|
63
|
+
// clang-format off
|
64
|
+
|
65
|
+
// ----------------------------------------------------------------------------
|
66
|
+
// Floating point checks
|
67
|
+
// ----------------------------------------------------------------------------
|
68
|
+
|
69
|
+
template<typename T> [[nodiscard]] bool isfinite(T x) noexcept;
|
70
|
+
template<> [[nodiscard]] inline bool isfinite(float x) noexcept { return std::isfinite(x); }
|
71
|
+
template<> [[nodiscard]] inline bool isfinite(double x) noexcept { return std::isfinite(x); }
|
72
|
+
template<> [[nodiscard]] inline bool isfinite(float16_t x) noexcept { return x.isfinite(); }
|
73
|
+
|
74
|
+
template<typename T> [[nodiscard]] bool isinf(T x) noexcept;
|
75
|
+
template<> [[nodiscard]] inline bool isinf(float x) noexcept { return std::isinf(x); }
|
76
|
+
template<> [[nodiscard]] inline bool isinf(double x) noexcept { return std::isinf(x); }
|
77
|
+
template<> [[nodiscard]] inline bool isinf(float16_t x) noexcept { return x.isinf(); }
|
78
|
+
|
79
|
+
template<typename T> [[nodiscard]] bool isnan(T x) noexcept;
|
80
|
+
template<> [[nodiscard]] inline bool isnan(float x) noexcept { return std::isnan(x); }
|
81
|
+
template<> [[nodiscard]] inline bool isnan(double x) noexcept { return std::isnan(x); }
|
82
|
+
template<> [[nodiscard]] inline bool isnan(float16_t x) noexcept { return x.isnan(); }
|
83
|
+
|
84
|
+
// ----------------------------------------------------------------------------
|
85
|
+
// Rounding
|
86
|
+
// ----------------------------------------------------------------------------
|
87
|
+
|
88
|
+
template<typename T> [[nodiscard]] T floor(T x) noexcept;
|
89
|
+
template<> [[nodiscard]] inline float floor(float x) noexcept { return std::floor(x); }
|
90
|
+
template<> [[nodiscard]] inline double floor(double x) noexcept { return std::floor(x); }
|
91
|
+
|
92
|
+
template<typename T> [[nodiscard]] T ceil(T x) noexcept;
|
93
|
+
template<> [[nodiscard]] inline float ceil(float x) noexcept { return std::ceil(x); }
|
94
|
+
template<> [[nodiscard]] inline double ceil(double x) noexcept { return std::ceil(x); }
|
95
|
+
|
96
|
+
template<typename T> [[nodiscard]] T trunc(T x) noexcept;
|
97
|
+
template<> [[nodiscard]] inline float trunc(float x) noexcept { return std::trunc(x); }
|
98
|
+
template<> [[nodiscard]] inline double trunc(double x) noexcept { return std::trunc(x); }
|
99
|
+
|
100
|
+
template<typename T> [[nodiscard]] T round(T x) noexcept;
|
101
|
+
template<> [[nodiscard]] inline float round(float x) noexcept { return std::round(x); }
|
102
|
+
template<> [[nodiscard]] inline double round(double x) noexcept { return std::round(x); }
|
103
|
+
|
104
|
+
// ----------------------------------------------------------------------------
|
105
|
+
// Exponential
|
106
|
+
// ----------------------------------------------------------------------------
|
107
|
+
|
108
|
+
template<typename T> [[nodiscard]] T pow(T x, T y) noexcept;
|
109
|
+
template<> [[nodiscard]] inline float pow(float x, float y) noexcept { return std::pow(x, y); }
|
110
|
+
template<> [[nodiscard]] inline double pow(double x, double y) noexcept { return std::pow(x, y); }
|
111
|
+
|
112
|
+
template<typename T> [[nodiscard]] T sqrt(T x) noexcept;
|
113
|
+
template<> [[nodiscard]] inline float sqrt(float x) noexcept { return std::sqrt(x); }
|
114
|
+
template<> [[nodiscard]] inline double sqrt(double x) noexcept { return std::sqrt(x); }
|
115
|
+
|
116
|
+
template<typename T> [[nodiscard]] T rsqrt(T x) noexcept;
|
117
|
+
template<> [[nodiscard]] inline float rsqrt(float x) noexcept { return 1.f / std::sqrt(x); }
|
118
|
+
template<> [[nodiscard]] inline double rsqrt(double x) noexcept { return 1.0 / std::sqrt(x); }
|
119
|
+
|
120
|
+
template<typename T> [[nodiscard]] T exp(T x) noexcept;
|
121
|
+
template<> [[nodiscard]] inline float exp(float x) noexcept { return std::exp(x); }
|
122
|
+
template<> [[nodiscard]] inline double exp(double x) noexcept { return std::exp(x); }
|
123
|
+
template<> [[nodiscard]] inline float16_t exp(float16_t x) noexcept { return float16_t(std::exp(float(x))); }
|
124
|
+
|
125
|
+
template<typename T> [[nodiscard]] T exp2(T x) noexcept;
|
126
|
+
template<> [[nodiscard]] inline float exp2(float x) noexcept { return std::exp2(x); }
|
127
|
+
template<> [[nodiscard]] inline double exp2(double x) noexcept { return std::exp2(x); }
|
128
|
+
template<> [[nodiscard]] inline float16_t exp2(float16_t x) noexcept { return float16_t(std::exp2(float(x))); }
|
129
|
+
|
130
|
+
template<typename T> [[nodiscard]] T log(T x) noexcept;
|
131
|
+
template<> [[nodiscard]] inline float log(float x) noexcept { return std::log(x); }
|
132
|
+
template<> [[nodiscard]] inline double log(double x) noexcept { return std::log(x); }
|
133
|
+
template<> [[nodiscard]] inline float16_t log(float16_t x) noexcept { return float16_t(std::log(float(x))); }
|
134
|
+
|
135
|
+
template<typename T> [[nodiscard]] T log2(T x) noexcept;
|
136
|
+
template<> [[nodiscard]] inline float log2(float x) noexcept { return std::log2(x); }
|
137
|
+
template<> [[nodiscard]] inline double log2(double x) noexcept { return std::log2(x); }
|
138
|
+
|
139
|
+
template<typename T> [[nodiscard]] T log10(T x) noexcept;
|
140
|
+
template<> [[nodiscard]] inline float log10(float x) noexcept { return std::log10(x); }
|
141
|
+
template<> [[nodiscard]] inline double log10(double x) noexcept { return std::log10(x); }
|
142
|
+
|
143
|
+
// ----------------------------------------------------------------------------
|
144
|
+
// Trigonometry
|
145
|
+
// ----------------------------------------------------------------------------
|
146
|
+
|
147
|
+
template<typename T> [[nodiscard]] T radians(T x) noexcept;
|
148
|
+
template<> [[nodiscard]] inline float radians(float x) noexcept { return x * 0.01745329251994329576923690768489f; }
|
149
|
+
template<> [[nodiscard]] inline double radians(double x) noexcept { return x * 0.01745329251994329576923690768489; }
|
150
|
+
|
151
|
+
template<typename T> [[nodiscard]] T degrees(T x) noexcept;
|
152
|
+
template<> [[nodiscard]] inline float degrees(float x) noexcept { return x * 57.295779513082320876798154814105f; }
|
153
|
+
template<> [[nodiscard]] inline double degrees(double x) noexcept { return x * 57.295779513082320876798154814105; }
|
154
|
+
|
155
|
+
template<typename T> [[nodiscard]] T sin(T x) noexcept;
|
156
|
+
template<> [[nodiscard]] inline float sin(float x) noexcept { return std::sin(x); }
|
157
|
+
template<> [[nodiscard]] inline double sin(double x) noexcept { return std::sin(x); }
|
158
|
+
|
159
|
+
template<typename T> [[nodiscard]] T cos(T x) noexcept;
|
160
|
+
template<> [[nodiscard]] inline float cos(float x) noexcept { return std::cos(x); }
|
161
|
+
template<> [[nodiscard]] inline double cos(double x) noexcept { return std::cos(x); }
|
162
|
+
|
163
|
+
template<typename T> [[nodiscard]] T tan(T x) noexcept;
|
164
|
+
template<> [[nodiscard]] inline float tan(float x) noexcept { return std::tan(x); }
|
165
|
+
template<> [[nodiscard]] inline double tan(double x) noexcept { return std::tan(x); }
|
166
|
+
|
167
|
+
template<typename T> [[nodiscard]] T asin(T x) noexcept;
|
168
|
+
template<> [[nodiscard]] inline float asin(float x) noexcept { return std::asin(x); }
|
169
|
+
template<> [[nodiscard]] inline double asin(double x) noexcept { return std::asin(x); }
|
170
|
+
|
171
|
+
template<typename T> [[nodiscard]] T acos(T x) noexcept;
|
172
|
+
template<> [[nodiscard]] inline float acos(float x) noexcept { return std::acos(x); }
|
173
|
+
template<> [[nodiscard]] inline double acos(double x) noexcept { return std::acos(x); }
|
174
|
+
|
175
|
+
template<typename T> [[nodiscard]] T atan(T x) noexcept;
|
176
|
+
template<> [[nodiscard]] inline float atan(float x) noexcept { return std::atan(x); }
|
177
|
+
template<> [[nodiscard]] inline double atan(double x) noexcept { return std::atan(x); }
|
178
|
+
|
179
|
+
template<typename T> [[nodiscard]] T atan2(T y, T x) noexcept;
|
180
|
+
template<> [[nodiscard]] inline float atan2(float y, float x) noexcept { return std::atan2(y, x); }
|
181
|
+
template<> [[nodiscard]] inline double atan2(double y, double x) noexcept { return std::atan2(y, x); }
|
182
|
+
|
183
|
+
template<typename T> [[nodiscard]] T sinh(T x) noexcept;
|
184
|
+
template<> [[nodiscard]] inline float sinh(float x) noexcept { return std::sinh(x); }
|
185
|
+
template<> [[nodiscard]] inline double sinh(double x) noexcept { return std::sinh(x); }
|
186
|
+
|
187
|
+
template<typename T> [[nodiscard]] T cosh(T x) noexcept;
|
188
|
+
template<> [[nodiscard]] inline float cosh(float x) noexcept { return std::cosh(x); }
|
189
|
+
template<> [[nodiscard]] inline double cosh(double x) noexcept { return std::cosh(x); }
|
190
|
+
|
191
|
+
template<typename T> [[nodiscard]] T tanh(T x) noexcept;
|
192
|
+
template<> [[nodiscard]] inline float tanh(float x) noexcept { return std::tanh(x); }
|
193
|
+
template<> [[nodiscard]] inline double tanh(double x) noexcept { return std::tanh(x); }
|
194
|
+
|
195
|
+
// ----------------------------------------------------------------------------
|
196
|
+
// Misc
|
197
|
+
// ----------------------------------------------------------------------------
|
198
|
+
|
199
|
+
template<typename T> [[nodiscard]] T fmod(T x, T y) noexcept;
|
200
|
+
template<> [[nodiscard]] inline float fmod(float x, float y) noexcept { return std::fmod(x, y); }
|
201
|
+
template<> [[nodiscard]] inline double fmod(double x, double y) noexcept { return std::fmod(x, y); }
|
202
|
+
|
203
|
+
template<typename T> [[nodiscard]] T frac(T x) noexcept;
|
204
|
+
template<> [[nodiscard]] inline float frac(float x) noexcept { return x - floor(x); }
|
205
|
+
template<> [[nodiscard]] inline double frac(double x) noexcept { return x - floor(x); }
|
206
|
+
|
207
|
+
template<typename T> [[nodiscard]] T lerp(T x, T y, T s) noexcept;
|
208
|
+
template<> [[nodiscard]] inline float lerp(float x, float y, float s) noexcept { return (1.f - s) * x + s * y; }
|
209
|
+
template<> [[nodiscard]] inline double lerp(double x, double y, double s) noexcept { return (1.0 - s) * x + s * y; }
|
210
|
+
|
211
|
+
template<typename T> [[nodiscard]] T rcp(T x) noexcept;
|
212
|
+
template<> [[nodiscard]] inline float rcp(float x) noexcept { return 1.f / x; }
|
213
|
+
template<> [[nodiscard]] inline double rcp(double x) noexcept { return 1.0 / x; }
|
214
|
+
|
215
|
+
template<typename T> [[nodiscard]] T saturate(T x) noexcept;
|
216
|
+
template<> [[nodiscard]] inline float saturate(float x) noexcept { return max(0.f, min(1.f, x)); }
|
217
|
+
template<> [[nodiscard]] inline double saturate(double x) noexcept { return max(0.0, min(1.0, x)); }
|
218
|
+
|
219
|
+
template<typename T> [[nodiscard]] T step(T x, T y) noexcept;
|
220
|
+
template<> [[nodiscard]] inline float step(float x, float y) noexcept { return x >= y ? 1.f : 0.f; }
|
221
|
+
template<> [[nodiscard]] inline double step(double x, double y) noexcept { return x >= y ? 1.0 : 0.0; }
|
222
|
+
|
223
|
+
// clang-format on
|
224
|
+
|
225
|
+
template<floating_point T>
|
226
|
+
[[nodiscard]] T smoothstep(T min_, T max_, T x) noexcept
|
227
|
+
{
|
228
|
+
x = saturate((x - min_) / (max_ - min_));
|
229
|
+
return x * x * (T(3) - T(2) * x);
|
230
|
+
}
|
231
|
+
|
232
|
+
// ----------------------------------------------------------------------------
|
233
|
+
// Conversion
|
234
|
+
// ----------------------------------------------------------------------------
|
235
|
+
|
236
|
+
// clang-format off
|
237
|
+
[[nodiscard]] inline float f16tof32(uint32_t v) noexcept { return float16_to_float32(v & 0xffff); }
|
238
|
+
[[nodiscard]] inline uint32_t f32tof16(float v) noexcept { return float32_to_float16(v); }
|
239
|
+
|
240
|
+
[[nodiscard]] inline float asfloat(uint32_t i) noexcept { return stdx::bit_cast<float>(i); }
|
241
|
+
[[nodiscard]] inline float asfloat(int32_t i) noexcept { return stdx::bit_cast<float>(i); }
|
242
|
+
[[nodiscard]] inline float16_t asfloat16(uint16_t i) noexcept { return stdx::bit_cast<float16_t>(i); }
|
243
|
+
|
244
|
+
[[nodiscard]] inline uint32_t asuint(float f) noexcept { return stdx::bit_cast<uint32_t>(f); }
|
245
|
+
[[nodiscard]] inline int32_t asint(float f) noexcept { return stdx::bit_cast<int32_t>(f); }
|
246
|
+
[[nodiscard]] inline uint16_t asuint16(float16_t f) noexcept { return stdx::bit_cast<uint16_t>(f); }
|
247
|
+
// clang-format on
|
248
|
+
|
249
|
+
} // namespace sgl::math
|
@@ -0,0 +1,107 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/math/float16.h"
|
6
|
+
#include "sgl/core/macros.h"
|
7
|
+
#include "sgl/core/format.h"
|
8
|
+
|
9
|
+
#include <concepts>
|
10
|
+
#include <string>
|
11
|
+
#include <cstdint>
|
12
|
+
|
13
|
+
namespace sgl::math {
|
14
|
+
|
15
|
+
enum class Handedness {
|
16
|
+
right_handed,
|
17
|
+
left_handed,
|
18
|
+
};
|
19
|
+
|
20
|
+
using uint = uint32_t;
|
21
|
+
|
22
|
+
// clang-format off
|
23
|
+
template<typename T> [[nodiscard]] std::string to_string(T v);
|
24
|
+
template<> [[nodiscard]] inline std::string to_string(bool v) { return v ? "1" : "0"; }
|
25
|
+
template<> [[nodiscard]] inline std::string to_string(int v) { return std::to_string(v); }
|
26
|
+
template<> [[nodiscard]] inline std::string to_string(uint v) { return std::to_string(v); }
|
27
|
+
template<> [[nodiscard]] inline std::string to_string(float v) { return std::to_string(v); }
|
28
|
+
template<> [[nodiscard]] inline std::string to_string(double v) { return std::to_string(v); }
|
29
|
+
template<> [[nodiscard]] inline std::string to_string(float16_t v) { return std::to_string(float(v)); }
|
30
|
+
// clang-format on
|
31
|
+
|
32
|
+
template<typename T>
|
33
|
+
concept boolean = std::same_as<T, bool>;
|
34
|
+
|
35
|
+
// Note: integral also includes bool
|
36
|
+
using std::integral;
|
37
|
+
using std::signed_integral;
|
38
|
+
|
39
|
+
template<typename T>
|
40
|
+
concept floating_point = std::same_as<T, float> || std::same_as<T, double> || std::same_as<T, float16_t>;
|
41
|
+
|
42
|
+
template<typename T>
|
43
|
+
concept arithmetic = integral<T> || floating_point<T>;
|
44
|
+
|
45
|
+
template<typename T>
|
46
|
+
concept signed_number = std::signed_integral<T> || floating_point<T>;
|
47
|
+
|
48
|
+
|
49
|
+
template<typename T>
|
50
|
+
struct ScalarTraits { };
|
51
|
+
|
52
|
+
template<>
|
53
|
+
struct ScalarTraits<bool> {
|
54
|
+
static constexpr const char* name{"bool"};
|
55
|
+
};
|
56
|
+
|
57
|
+
template<>
|
58
|
+
struct ScalarTraits<int> {
|
59
|
+
static constexpr const char* name{"int"};
|
60
|
+
};
|
61
|
+
|
62
|
+
template<>
|
63
|
+
struct ScalarTraits<uint> {
|
64
|
+
static constexpr const char* name{"uint"};
|
65
|
+
};
|
66
|
+
|
67
|
+
template<>
|
68
|
+
struct ScalarTraits<float> {
|
69
|
+
static constexpr const char* name{"float"};
|
70
|
+
};
|
71
|
+
|
72
|
+
template<>
|
73
|
+
struct ScalarTraits<double> {
|
74
|
+
static constexpr const char* name{"double"};
|
75
|
+
};
|
76
|
+
|
77
|
+
template<>
|
78
|
+
struct ScalarTraits<float16_t> {
|
79
|
+
static constexpr const char* name{"float16_t"};
|
80
|
+
};
|
81
|
+
|
82
|
+
} // namespace sgl::math
|
83
|
+
|
84
|
+
namespace sgl {
|
85
|
+
|
86
|
+
using uint = math::uint;
|
87
|
+
using float16_t = math::float16_t;
|
88
|
+
|
89
|
+
SGL_DIAGNOSTIC_PUSH
|
90
|
+
// disable warning about literal suffixes not starting with an underscore
|
91
|
+
SGL_DISABLE_MSVC_WARNING(4455)
|
92
|
+
|
93
|
+
using math::operator""h;
|
94
|
+
|
95
|
+
SGL_DIAGNOSTIC_POP
|
96
|
+
|
97
|
+
} // namespace sgl
|
98
|
+
|
99
|
+
// Formatter for the float16_t.
|
100
|
+
template<>
|
101
|
+
struct fmt::formatter<sgl::math::float16_t> : formatter<float> {
|
102
|
+
template<typename FormatContext>
|
103
|
+
auto format(sgl::math::float16_t value, FormatContext& ctx) const
|
104
|
+
{
|
105
|
+
return formatter<float>::format(float(value), ctx);
|
106
|
+
}
|
107
|
+
};
|