nv-sgl 0.6.0__cp313-cp313-win_amd64.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 +142 -0
- nv_sgl-0.6.0.dist-info/WHEEL +5 -0
- nv_sgl-0.6.0.dist-info/top_level.txt +1 -0
- sgl/__init__.py +15 -0
- sgl/__init__.pyi +6738 -0
- sgl/d3d12/D3D12Core.dll +0 -0
- sgl/d3d12/d3d12SDKLayers.dll +0 -0
- sgl/dxcompiler.dll +0 -0
- sgl/dxil.dll +0 -0
- sgl/gfx.dll +0 -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/math/__init__.pyi +5083 -0
- sgl/platform/__init__.pyi +102 -0
- sgl/renderdoc/__init__.pyi +51 -0
- sgl/sgl.dll +0 -0
- sgl/sgl_ext.cp313-win_amd64.pyd +0 -0
- sgl/shaders/nvapi/nvHLSLExtns.h +2315 -0
- sgl/shaders/nvapi/nvHLSLExtnsInternal.h +758 -0
- sgl/shaders/nvapi/nvShaderExtnEnums.h +142 -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/slang-glslang.dll +0 -0
- sgl/slang-llvm.dll +0 -0
- sgl/slang-rt.dll +0 -0
- sgl/slang.dll +0 -0
- sgl/slangpy/__init__.pyi +268 -0
- sgl/tev/__init__.pyi +108 -0
- sgl/tevclient.lib +0 -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 +108 -0
@@ -0,0 +1,360 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
/**
|
4
|
+
* This is a modified version of the struct.h file from Mitsuba 3.0 found at
|
5
|
+
* https://github.com/mitsuba-renderer/mitsuba3/blob/master/include/mitsuba/core/struct.h
|
6
|
+
*
|
7
|
+
* Original license below:
|
8
|
+
*
|
9
|
+
* Copyright (c) 2017 Wenzel Jakob <wenzel.jakob\epfl.ch>, All rights reserved.
|
10
|
+
*
|
11
|
+
* Redistribution and use in source and binary forms, with or without
|
12
|
+
* modification, are permitted provided that the following conditions are met:
|
13
|
+
*
|
14
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
15
|
+
* list of conditions and the following disclaimer.
|
16
|
+
*
|
17
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
18
|
+
* this list of conditions and the following disclaimer in the documentation
|
19
|
+
* and/or other materials provided with the distribution.
|
20
|
+
*
|
21
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
22
|
+
* may be used to endorse or promote products derived from this software
|
23
|
+
* without specific prior written permission.
|
24
|
+
*
|
25
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
26
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
27
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
28
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
29
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
30
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
31
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
32
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
33
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
34
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35
|
+
*
|
36
|
+
* You are under no obligation whatsoever to provide any bug fixes, patches, or
|
37
|
+
* upgrades to the features, functionality or performance of the source code
|
38
|
+
* ("Enhancements") to anyone; however, if you choose to make your Enhancements
|
39
|
+
* available either publicly, or directly to the author of this software, without
|
40
|
+
* imposing a separate written license agreement for such Enhancements, then you
|
41
|
+
* hereby grant the following license: a non-exclusive, royalty-free perpetual
|
42
|
+
* license to install, use, modify, prepare derivative works, incorporate into
|
43
|
+
* other computer software, distribute, and sublicense such enhancements or
|
44
|
+
* derivative works thereof, in binary and source code form.
|
45
|
+
*/
|
46
|
+
|
47
|
+
#pragma once
|
48
|
+
|
49
|
+
#include "sgl/core/macros.h"
|
50
|
+
#include "sgl/core/object.h"
|
51
|
+
#include "sgl/core/enum.h"
|
52
|
+
|
53
|
+
#include <utility>
|
54
|
+
|
55
|
+
namespace sgl {
|
56
|
+
|
57
|
+
/**
|
58
|
+
* \brief Structured data definition.
|
59
|
+
*
|
60
|
+
* This class is used to describe a structured data type layout.
|
61
|
+
* It is used by the \ref StructConverter class to convert between different layouts.
|
62
|
+
*/
|
63
|
+
class SGL_API Struct : Object {
|
64
|
+
SGL_OBJECT(Struct)
|
65
|
+
public:
|
66
|
+
/// Struct field type.
|
67
|
+
enum class Type {
|
68
|
+
int8,
|
69
|
+
int16,
|
70
|
+
int32,
|
71
|
+
int64,
|
72
|
+
uint8,
|
73
|
+
uint16,
|
74
|
+
uint32,
|
75
|
+
uint64,
|
76
|
+
float16,
|
77
|
+
float32,
|
78
|
+
float64,
|
79
|
+
};
|
80
|
+
|
81
|
+
static constexpr uint32_t TYPE_COUNT = uint32_t(Type::float64) + 1;
|
82
|
+
|
83
|
+
SGL_ENUM_INFO(
|
84
|
+
Type,
|
85
|
+
{
|
86
|
+
{Type::int8, "int8"},
|
87
|
+
{Type::int16, "int16"},
|
88
|
+
{Type::int32, "int32"},
|
89
|
+
{Type::int64, "int64"},
|
90
|
+
{Type::uint8, "uint8"},
|
91
|
+
{Type::uint16, "uint16"},
|
92
|
+
{Type::uint32, "uint32"},
|
93
|
+
{Type::uint64, "uint64"},
|
94
|
+
{Type::float16, "float16"},
|
95
|
+
{Type::float32, "float32"},
|
96
|
+
{Type::float64, "float64"},
|
97
|
+
}
|
98
|
+
);
|
99
|
+
|
100
|
+
/// Struct field flags.
|
101
|
+
enum class Flags {
|
102
|
+
none = 0,
|
103
|
+
/// Integer fields represent normalized values in the range [0, 1].
|
104
|
+
normalized = 1,
|
105
|
+
/// Field encodes an sRGB gamma-corrected value.
|
106
|
+
srgb_gamma = 2,
|
107
|
+
/// Use default when field is not present in the source struct during conversion.
|
108
|
+
default_ = 4,
|
109
|
+
};
|
110
|
+
|
111
|
+
SGL_ENUM_INFO(
|
112
|
+
Flags,
|
113
|
+
{
|
114
|
+
{Flags::none, "none"},
|
115
|
+
{Flags::normalized, "normalized"},
|
116
|
+
{Flags::srgb_gamma, "srgb_gamma"},
|
117
|
+
{Flags::default_, "default"},
|
118
|
+
}
|
119
|
+
);
|
120
|
+
|
121
|
+
/// Byte order.
|
122
|
+
enum class ByteOrder {
|
123
|
+
little_endian,
|
124
|
+
big_endian,
|
125
|
+
host,
|
126
|
+
};
|
127
|
+
|
128
|
+
SGL_ENUM_INFO(
|
129
|
+
ByteOrder,
|
130
|
+
{
|
131
|
+
{ByteOrder::little_endian, "little_endian"},
|
132
|
+
{ByteOrder::big_endian, "big_endian"},
|
133
|
+
{ByteOrder::host, "host"},
|
134
|
+
}
|
135
|
+
);
|
136
|
+
|
137
|
+
/// Struct field.
|
138
|
+
struct SGL_API Field {
|
139
|
+
/// Name of the field.
|
140
|
+
std::string name;
|
141
|
+
|
142
|
+
/// Type of the field.
|
143
|
+
Type type{0};
|
144
|
+
|
145
|
+
/// Field flags.
|
146
|
+
Flags flags{Flags::none};
|
147
|
+
|
148
|
+
/// Size of the field in bytes.
|
149
|
+
size_t size{0};
|
150
|
+
|
151
|
+
/// Offset of the field in bytes.
|
152
|
+
size_t offset{0};
|
153
|
+
|
154
|
+
/// Default value.
|
155
|
+
double default_value{0.0};
|
156
|
+
|
157
|
+
using BlendList = std::vector<std::pair<double, std::string>>;
|
158
|
+
|
159
|
+
/// List of blend weights and names.
|
160
|
+
/// If set, the \c StructConverter will blend fields from the source struct
|
161
|
+
/// with the specified weights to generate the destination field.
|
162
|
+
/// Blending is done in linear space.
|
163
|
+
BlendList blend;
|
164
|
+
|
165
|
+
/// Check if the field is an integer type.
|
166
|
+
bool is_integer() const { return Struct::is_integer(type); }
|
167
|
+
|
168
|
+
/// Check if the field is a floating point type.
|
169
|
+
bool is_float() const { return Struct::is_float(type); }
|
170
|
+
|
171
|
+
/// Check if the field is an unsigned type.
|
172
|
+
bool is_unsigned() const { return Struct::is_unsigned(type); }
|
173
|
+
|
174
|
+
/// Check if the field is a signed type.
|
175
|
+
bool is_signed() const { return Struct::is_signed(type); }
|
176
|
+
|
177
|
+
/// Equality operator.
|
178
|
+
bool operator==(const Field& other) const
|
179
|
+
{
|
180
|
+
return name == other.name && type == other.type && flags == other.flags && size == other.size
|
181
|
+
&& offset == other.offset && default_value == other.default_value && blend == other.blend;
|
182
|
+
}
|
183
|
+
|
184
|
+
/// Inequality operator.
|
185
|
+
bool operator!=(const Field& other) const { return !operator==(other); }
|
186
|
+
|
187
|
+
/// Compute hash from the field.
|
188
|
+
SGL_API friend size_t hash(const Field& field);
|
189
|
+
|
190
|
+
std::string to_string() const;
|
191
|
+
};
|
192
|
+
|
193
|
+
using FieldIterator = std::vector<Field>::iterator;
|
194
|
+
using FieldConstIterator = std::vector<Field>::const_iterator;
|
195
|
+
|
196
|
+
/// Constructor.
|
197
|
+
/// \param pack If true, the struct will be packed.
|
198
|
+
/// \param byte_order Byte order of the struct.
|
199
|
+
Struct(bool pack = true, ByteOrder byte_order = ByteOrder::host);
|
200
|
+
|
201
|
+
/// The byte order of the struct.
|
202
|
+
ByteOrder byte_order() const { return m_byte_order; }
|
203
|
+
|
204
|
+
/// Append a field to the struct.
|
205
|
+
Struct& append(Field field);
|
206
|
+
|
207
|
+
/// Append a field to the struct.
|
208
|
+
/// \param name Name of the field.
|
209
|
+
/// \param type Type of the field.
|
210
|
+
/// \param flags Field flags.
|
211
|
+
/// \param default_value Default value.
|
212
|
+
/// \param blend List of blend weights/names.
|
213
|
+
/// \return Reference to the struct.
|
214
|
+
Struct& append(
|
215
|
+
std::string_view name,
|
216
|
+
Type type,
|
217
|
+
Flags flags = Flags::none,
|
218
|
+
double default_value = 0.0,
|
219
|
+
const Field::BlendList& blend = {}
|
220
|
+
);
|
221
|
+
|
222
|
+
/// Field iterator (begin).
|
223
|
+
FieldIterator begin() { return m_fields.begin(); }
|
224
|
+
|
225
|
+
/// Const field iterator (begin).
|
226
|
+
FieldConstIterator begin() const { return m_fields.cbegin(); }
|
227
|
+
|
228
|
+
/// Field iterator (end).
|
229
|
+
FieldConstIterator end() const { return m_fields.cend(); }
|
230
|
+
|
231
|
+
/// Const field iterator (end).
|
232
|
+
FieldIterator end() { return m_fields.end(); }
|
233
|
+
|
234
|
+
/// The number of fields in the struct.
|
235
|
+
size_t field_count() const { return m_fields.size(); }
|
236
|
+
|
237
|
+
/// Access field by index.
|
238
|
+
Field& operator[](size_t i) { return m_fields[i]; }
|
239
|
+
|
240
|
+
/// Access field by index.
|
241
|
+
const Field& operator[](size_t i) const { return m_fields[i]; }
|
242
|
+
|
243
|
+
/// Access field by name. Throws if field is not found.
|
244
|
+
Field& field(std::string_view name);
|
245
|
+
|
246
|
+
/// Access field by name. Throws if field is not found.
|
247
|
+
const Field& field(std::string_view name) const;
|
248
|
+
|
249
|
+
/// Check if a field with the specified name exists.
|
250
|
+
bool has_field(std::string_view name) const;
|
251
|
+
|
252
|
+
/// The size of the struct in bytes (with padding).
|
253
|
+
size_t size() const;
|
254
|
+
|
255
|
+
/// The alignment of the struct in bytes.
|
256
|
+
size_t alignment() const;
|
257
|
+
|
258
|
+
/// Equality operator.
|
259
|
+
bool operator==(const Struct& other) const
|
260
|
+
{
|
261
|
+
return m_pack == other.m_pack && m_byte_order == other.m_byte_order && m_fields == other.m_fields;
|
262
|
+
}
|
263
|
+
|
264
|
+
/// Inequality operator.
|
265
|
+
bool operator!=(const Struct& other) const { return !operator==(other); }
|
266
|
+
|
267
|
+
/// Compute hash from the struct.
|
268
|
+
SGL_API friend size_t hash(const Struct& struct_);
|
269
|
+
|
270
|
+
std::string to_string() const override;
|
271
|
+
|
272
|
+
/// The host byte order.
|
273
|
+
static ByteOrder host_byte_order();
|
274
|
+
|
275
|
+
/// Get the size of a type in bytes.
|
276
|
+
static size_t type_size(Type type)
|
277
|
+
{
|
278
|
+
switch (type) {
|
279
|
+
case Type::int8:
|
280
|
+
case Type::uint8:
|
281
|
+
return 1;
|
282
|
+
case Type::int16:
|
283
|
+
case Type::uint16:
|
284
|
+
case Type::float16:
|
285
|
+
return 2;
|
286
|
+
case Type::int32:
|
287
|
+
case Type::uint32:
|
288
|
+
case Type::float32:
|
289
|
+
return 4;
|
290
|
+
case Type::int64:
|
291
|
+
case Type::uint64:
|
292
|
+
case Type::float64:
|
293
|
+
return 8;
|
294
|
+
}
|
295
|
+
SGL_THROW("Invalid type.");
|
296
|
+
}
|
297
|
+
|
298
|
+
/// Get the numeric range of a type.
|
299
|
+
static std::pair<double, double> type_range(Type type);
|
300
|
+
|
301
|
+
/// Check if \c type is an integer type.
|
302
|
+
static bool is_integer(Type type) { return !is_float(type); }
|
303
|
+
|
304
|
+
/// Check if \c type is a floating point type.
|
305
|
+
static bool is_float(Type type) { return type == Type::float16 || type == Type::float32 || type == Type::float64; }
|
306
|
+
|
307
|
+
/// Check if \c type is an unsigned type.
|
308
|
+
static bool is_unsigned(Type type)
|
309
|
+
{
|
310
|
+
return type == Type::uint8 || type == Type::uint16 || type == Type::uint32 || type == Type::uint64;
|
311
|
+
}
|
312
|
+
|
313
|
+
/// Check if \c type is a signed type.
|
314
|
+
static bool is_signed(Type type) { return !is_unsigned(type); }
|
315
|
+
|
316
|
+
|
317
|
+
private:
|
318
|
+
bool m_pack;
|
319
|
+
ByteOrder m_byte_order;
|
320
|
+
std::vector<Field> m_fields;
|
321
|
+
};
|
322
|
+
|
323
|
+
SGL_ENUM_REGISTER(Struct::Type);
|
324
|
+
SGL_ENUM_REGISTER(Struct::Flags);
|
325
|
+
SGL_ENUM_CLASS_OPERATORS(Struct::Flags);
|
326
|
+
SGL_ENUM_REGISTER(Struct::ByteOrder);
|
327
|
+
|
328
|
+
/**
|
329
|
+
* \brief Struct converter.
|
330
|
+
*
|
331
|
+
* This helper class can be used to convert between structs with different layouts.
|
332
|
+
*/
|
333
|
+
class SGL_API StructConverter : Object {
|
334
|
+
SGL_OBJECT(StructConverter)
|
335
|
+
public:
|
336
|
+
/// Constructor.
|
337
|
+
/// \param src Source struct definition.
|
338
|
+
/// \param dst Destination struct definition.
|
339
|
+
StructConverter(const Struct* src, const Struct* dst);
|
340
|
+
|
341
|
+
/// The source struct definition.
|
342
|
+
const Struct* src() const { return m_src; }
|
343
|
+
|
344
|
+
/// The destination struct definition.
|
345
|
+
const Struct* dst() const { return m_dst; }
|
346
|
+
|
347
|
+
/// Convert data from source struct to destination struct.
|
348
|
+
/// \param src Source data.
|
349
|
+
/// \param dst Destination data.
|
350
|
+
/// \param count Number of structs to convert.
|
351
|
+
void convert(const void* src, void* dst, size_t count) const;
|
352
|
+
|
353
|
+
std::string to_string() const override;
|
354
|
+
|
355
|
+
private:
|
356
|
+
ref<const Struct> m_src;
|
357
|
+
ref<const Struct> m_dst;
|
358
|
+
};
|
359
|
+
|
360
|
+
} // namespace sgl
|
@@ -0,0 +1,28 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/macros.h"
|
6
|
+
|
7
|
+
#include <BS_thread_pool.hpp>
|
8
|
+
|
9
|
+
#include <type_traits>
|
10
|
+
#include <future>
|
11
|
+
|
12
|
+
namespace sgl::thread {
|
13
|
+
|
14
|
+
SGL_API void static_init();
|
15
|
+
SGL_API void static_shutdown();
|
16
|
+
|
17
|
+
/// Block until all scheduled tasks are completed.
|
18
|
+
SGL_API void wait_for_tasks();
|
19
|
+
|
20
|
+
SGL_API BS::thread_pool& global_thread_pool();
|
21
|
+
|
22
|
+
template<typename F, typename... A, typename R = std::invoke_result_t<std::decay_t<F>, std::decay_t<A>...>>
|
23
|
+
std::future<R> do_async(F&& task, A&&... args)
|
24
|
+
{
|
25
|
+
return global_thread_pool().submit(std::forward<F>(task), std::forward<A>(args)...);
|
26
|
+
}
|
27
|
+
|
28
|
+
} // namespace sgl::thread
|
@@ -0,0 +1,52 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "macros.h"
|
6
|
+
|
7
|
+
#include <cstdint>
|
8
|
+
|
9
|
+
namespace sgl {
|
10
|
+
|
11
|
+
/// High resolution CPU timer.
|
12
|
+
class SGL_API Timer {
|
13
|
+
public:
|
14
|
+
// Time point in nanoseconds.
|
15
|
+
using TimePoint = uint64_t;
|
16
|
+
|
17
|
+
Timer() { reset(); }
|
18
|
+
|
19
|
+
/// Reset the timer.
|
20
|
+
void reset() { m_start = now(); }
|
21
|
+
|
22
|
+
/// Elapsed seconds since last reset.
|
23
|
+
double elapsed_s() const { return delta_s(m_start, now()); }
|
24
|
+
|
25
|
+
/// Elapsed milliseconds since last reset.
|
26
|
+
double elapsed_ms() const { return delta_ms(m_start, now()); }
|
27
|
+
|
28
|
+
/// Elapsed microseconds since last reset.
|
29
|
+
double elapsed_us() const { return delta_us(m_start, now()); }
|
30
|
+
|
31
|
+
/// Elapsed nanoseconds since last reset.
|
32
|
+
double elapsed_ns() const { return delta_ns(m_start, now()); }
|
33
|
+
|
34
|
+
/// Compute elapsed seconds between two time points.
|
35
|
+
static double delta_s(TimePoint start, TimePoint end) { return (end - start) * 1e-9; }
|
36
|
+
|
37
|
+
/// Compute elapsed milliseconds between two time points.
|
38
|
+
static double delta_ms(TimePoint start, TimePoint end) { return (end - start) * 1e-6; }
|
39
|
+
|
40
|
+
/// Compute elapsed microseconds between two time points.
|
41
|
+
static double delta_us(TimePoint start, TimePoint end) { return (end - start) * 1e-3; }
|
42
|
+
|
43
|
+
/// Compute elapsed nanoseconds between two time points.
|
44
|
+
static double delta_ns(TimePoint start, TimePoint end) { return double(end - start); }
|
45
|
+
|
46
|
+
/// Current time point in nanoseconds since epoch.
|
47
|
+
static TimePoint now();
|
48
|
+
|
49
|
+
private:
|
50
|
+
TimePoint m_start;
|
51
|
+
};
|
52
|
+
} // namespace sgl
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include <type_traits>
|
6
|
+
|
7
|
+
namespace sgl {
|
8
|
+
|
9
|
+
template<typename T>
|
10
|
+
struct is_boolean : std::is_same<T, bool> { };
|
11
|
+
|
12
|
+
template<typename T>
|
13
|
+
inline constexpr bool is_boolean_v = is_boolean<T>::value;
|
14
|
+
|
15
|
+
} // namespace sgl
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/error.h"
|
6
|
+
|
7
|
+
#include <utility>
|
8
|
+
|
9
|
+
namespace sgl {
|
10
|
+
|
11
|
+
template<typename R, typename T>
|
12
|
+
R narrow_cast(T value)
|
13
|
+
{
|
14
|
+
if (!std::in_range<R>(value))
|
15
|
+
SGL_THROW("narrow_cast failed");
|
16
|
+
return static_cast<R>(value);
|
17
|
+
}
|
18
|
+
|
19
|
+
} // namespace sgl
|
@@ -0,0 +1,177 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/platform.h"
|
6
|
+
#include "sgl/core/object.h"
|
7
|
+
#include "sgl/core/input.h"
|
8
|
+
|
9
|
+
#include <cstdint>
|
10
|
+
#include <filesystem>
|
11
|
+
#include <functional>
|
12
|
+
#include <optional>
|
13
|
+
#include <span>
|
14
|
+
#include <string>
|
15
|
+
|
16
|
+
// GLFW forward declarations.
|
17
|
+
struct GLFWwindow;
|
18
|
+
|
19
|
+
namespace sgl {
|
20
|
+
|
21
|
+
/// Window modes.
|
22
|
+
enum class WindowMode {
|
23
|
+
normal,
|
24
|
+
minimized,
|
25
|
+
fullscreen,
|
26
|
+
};
|
27
|
+
|
28
|
+
/// Window description.
|
29
|
+
struct WindowDesc {
|
30
|
+
/// Width of the window in pixels.
|
31
|
+
uint32_t width;
|
32
|
+
/// Height of the window in pixels.
|
33
|
+
uint32_t height;
|
34
|
+
/// Title of the window.
|
35
|
+
std::string title;
|
36
|
+
/// Window mode.
|
37
|
+
WindowMode mode{WindowMode::normal};
|
38
|
+
/// Whether the window is resizable.
|
39
|
+
bool resizable{true};
|
40
|
+
};
|
41
|
+
|
42
|
+
/**
|
43
|
+
* \brief Window class.
|
44
|
+
*
|
45
|
+
* Platform independent class for managing a window and handle input events.
|
46
|
+
*/
|
47
|
+
class SGL_API Window : public Object {
|
48
|
+
SGL_OBJECT(Window)
|
49
|
+
public:
|
50
|
+
/// Constructor.
|
51
|
+
/// \param width Width of the window in pixels.
|
52
|
+
/// \param height Height of the window in pixels.
|
53
|
+
/// \param title Title of the window.
|
54
|
+
/// \param mode Window mode.
|
55
|
+
/// \param resizable Whether the window is resizable.
|
56
|
+
Window(WindowDesc desc);
|
57
|
+
~Window();
|
58
|
+
|
59
|
+
static ref<Window> create(WindowDesc desc) { return make_ref<Window>(desc); }
|
60
|
+
|
61
|
+
/// The native window handle.
|
62
|
+
WindowHandle window_handle() const;
|
63
|
+
|
64
|
+
/// The width of the window in pixels.
|
65
|
+
uint32_t width() const { return m_width; }
|
66
|
+
/// The height of the window in pixels.
|
67
|
+
uint32_t height() const { return m_height; }
|
68
|
+
|
69
|
+
/// Resize the window.
|
70
|
+
/// \param width The new width of the window in pixels.
|
71
|
+
/// \param height The new height of the window in pixels.
|
72
|
+
void resize(uint32_t width, uint32_t height);
|
73
|
+
|
74
|
+
/// The title of the window.
|
75
|
+
const std::string& title() const { return m_title; }
|
76
|
+
void set_title(std::string title);
|
77
|
+
|
78
|
+
void set_icon(const std::filesystem::path& path);
|
79
|
+
|
80
|
+
/// Close the window.
|
81
|
+
void close();
|
82
|
+
|
83
|
+
/// True if the window should be closed.
|
84
|
+
bool should_close() const;
|
85
|
+
|
86
|
+
/// Process any pending events.
|
87
|
+
void process_events();
|
88
|
+
|
89
|
+
/// Set the clipboard content.
|
90
|
+
void set_clipboard(const std::string& text);
|
91
|
+
|
92
|
+
/// Get the clipboard content.
|
93
|
+
std::optional<std::string> get_clipboard() const;
|
94
|
+
|
95
|
+
/// The mouse cursor mode.
|
96
|
+
CursorMode cursor_mode() const { return m_cursor_mode; }
|
97
|
+
void set_cursor_mode(CursorMode mode);
|
98
|
+
|
99
|
+
// events
|
100
|
+
|
101
|
+
using ResizeCallback = std::function<void(uint32_t /* width */, uint32_t /* height */)>;
|
102
|
+
using KeyboardEventCallback = std::function<void(const KeyboardEvent& /* event */)>;
|
103
|
+
using MouseEventCallback = std::function<void(const MouseEvent& /* event */)>;
|
104
|
+
using GamepadEventCallback = std::function<void(const GamepadEvent& /* event */)>;
|
105
|
+
using GamepadStateCallback = std::function<void(const GamepadState& /* state */)>;
|
106
|
+
using DropFilesCallback = std::function<void(std::span<const char*> /* files */)>;
|
107
|
+
|
108
|
+
/// Event handler to be called when the window is resized.
|
109
|
+
const ResizeCallback& on_resize() const { return m_on_resize; }
|
110
|
+
void set_on_resize(ResizeCallback on_resize) { m_on_resize = std::move(on_resize); }
|
111
|
+
|
112
|
+
/// Event handler to be called when a keyboard event occurs.
|
113
|
+
const KeyboardEventCallback& on_keyboard_event() const { return m_on_keyboard_event; }
|
114
|
+
void set_on_keyboard_event(KeyboardEventCallback on_keyboard_event)
|
115
|
+
{
|
116
|
+
m_on_keyboard_event = std::move(on_keyboard_event);
|
117
|
+
}
|
118
|
+
|
119
|
+
/// Event handler to be called when a mouse event occurs.
|
120
|
+
const MouseEventCallback& on_mouse_event() const { return m_on_mouse_event; }
|
121
|
+
void set_on_mouse_event(MouseEventCallback on_mouse_event) { m_on_mouse_event = std::move(on_mouse_event); }
|
122
|
+
|
123
|
+
/// Event handler to be called when a gamepad event occurs.
|
124
|
+
const GamepadEventCallback& on_gamepad_event() const { return m_on_gamepad_event; }
|
125
|
+
void set_on_gamepad_event(GamepadEventCallback on_gamepad_event)
|
126
|
+
{
|
127
|
+
m_on_gamepad_event = std::move(on_gamepad_event);
|
128
|
+
}
|
129
|
+
|
130
|
+
/// Event handler to be called when the gamepad state changes.
|
131
|
+
const GamepadStateCallback& on_gamepad_state() const { return m_on_gamepad_state; }
|
132
|
+
void set_on_gamepad_state(GamepadStateCallback on_gamepad_state)
|
133
|
+
{
|
134
|
+
m_on_gamepad_state = std::move(on_gamepad_state);
|
135
|
+
}
|
136
|
+
|
137
|
+
/// Event handler to be called when files are dropped onto the window.
|
138
|
+
const DropFilesCallback& on_drop_files() const { return m_on_drop_files; }
|
139
|
+
void set_on_drop_files(DropFilesCallback on_drop_files) { m_on_drop_files = std::move(on_drop_files); }
|
140
|
+
|
141
|
+
std::string to_string() const override;
|
142
|
+
|
143
|
+
private:
|
144
|
+
void poll_gamepad_input();
|
145
|
+
|
146
|
+
void handle_window_size(uint32_t width, uint32_t height);
|
147
|
+
void handle_keyboard_event(const KeyboardEvent& event);
|
148
|
+
void handle_mouse_event(const MouseEvent& event);
|
149
|
+
void handle_gamepad_event(const GamepadEvent& event);
|
150
|
+
void handle_drop_files(std::span<const char*> files);
|
151
|
+
|
152
|
+
uint32_t m_width;
|
153
|
+
uint32_t m_height;
|
154
|
+
std::string m_title;
|
155
|
+
GLFWwindow* m_window;
|
156
|
+
|
157
|
+
bool m_should_close{false};
|
158
|
+
|
159
|
+
CursorMode m_cursor_mode{CursorMode::normal};
|
160
|
+
float2 m_mouse_pos{0.f, 0.f};
|
161
|
+
KeyModifierFlags m_mods{KeyModifierFlags::none};
|
162
|
+
|
163
|
+
static constexpr int INVALID_GAMEPAD_ID = -1;
|
164
|
+
int m_gamepad_id{INVALID_GAMEPAD_ID};
|
165
|
+
GamepadState m_gamepad_prev_state;
|
166
|
+
|
167
|
+
ResizeCallback m_on_resize;
|
168
|
+
KeyboardEventCallback m_on_keyboard_event;
|
169
|
+
MouseEventCallback m_on_mouse_event;
|
170
|
+
GamepadEventCallback m_on_gamepad_event;
|
171
|
+
GamepadStateCallback m_on_gamepad_state;
|
172
|
+
DropFilesCallback m_on_drop_files;
|
173
|
+
|
174
|
+
friend struct EventHandlers;
|
175
|
+
};
|
176
|
+
|
177
|
+
} // namespace sgl
|
@@ -0,0 +1,24 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/config.h"
|
6
|
+
|
7
|
+
// -------------------------------------------------------------------------------------------------
|
8
|
+
// D3D12 Agility SDK
|
9
|
+
// -------------------------------------------------------------------------------------------------
|
10
|
+
|
11
|
+
#if SGL_HAS_AGILITY_SDK
|
12
|
+
#define SGL_AGILITY_SDK_VERSION 611
|
13
|
+
#define SGL_AGILITY_SDK_PATH ".\\d3d12\\"
|
14
|
+
// To enable the D3D12 Agility SDK, this macro needs to be added to the main source file of the executable.
|
15
|
+
#define SGL_EXPORT_AGILITY_SDK \
|
16
|
+
extern "C" { \
|
17
|
+
SGL_API_EXPORT extern const unsigned int D3D12SDKVersion = SGL_AGILITY_SDK_VERSION; \
|
18
|
+
} \
|
19
|
+
extern "C" { \
|
20
|
+
SGL_API_EXPORT extern const char* D3D12SDKPath = SGL_AGILITY_SDK_PATH; \
|
21
|
+
}
|
22
|
+
#else
|
23
|
+
#define SGL_EXPORT_AGILITY_SDK
|
24
|
+
#endif
|