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,214 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/macros.h"
|
6
|
+
#include "sgl/core/object.h"
|
7
|
+
#include "sgl/core/format.h"
|
8
|
+
|
9
|
+
#include <mutex>
|
10
|
+
#include <string_view>
|
11
|
+
#include <set>
|
12
|
+
#include <filesystem>
|
13
|
+
|
14
|
+
namespace sgl {
|
15
|
+
|
16
|
+
|
17
|
+
/// Log level.
|
18
|
+
enum class LogLevel {
|
19
|
+
none,
|
20
|
+
debug,
|
21
|
+
info,
|
22
|
+
warn,
|
23
|
+
error,
|
24
|
+
fatal,
|
25
|
+
};
|
26
|
+
|
27
|
+
/// Log frequency.
|
28
|
+
enum class LogFrequency {
|
29
|
+
/// Log the message every time.
|
30
|
+
always,
|
31
|
+
/// Log the message only once.
|
32
|
+
once,
|
33
|
+
};
|
34
|
+
|
35
|
+
/// Abstract base class for logger outputs.
|
36
|
+
class SGL_API LoggerOutput : public Object {
|
37
|
+
SGL_OBJECT(LoggerOutput)
|
38
|
+
public:
|
39
|
+
virtual ~LoggerOutput() = default;
|
40
|
+
|
41
|
+
/// Write a log message.
|
42
|
+
/// \param level The log level.
|
43
|
+
/// \param module The module name.
|
44
|
+
/// \param msg The message.
|
45
|
+
virtual void write(LogLevel level, const std::string_view module, const std::string_view msg) = 0;
|
46
|
+
};
|
47
|
+
|
48
|
+
/// Logger output that writes to the console.
|
49
|
+
/// Error messages are printed to stderr, all other messages to stdout.
|
50
|
+
/// Messages are optionally colored.
|
51
|
+
class SGL_API ConsoleLoggerOutput : public LoggerOutput {
|
52
|
+
public:
|
53
|
+
ConsoleLoggerOutput(bool colored = true);
|
54
|
+
|
55
|
+
void write(LogLevel level, const std::string_view module, const std::string_view msg) override;
|
56
|
+
|
57
|
+
std::string to_string() const override;
|
58
|
+
|
59
|
+
private:
|
60
|
+
static bool enable_ansi_control_sequences();
|
61
|
+
|
62
|
+
bool m_colored;
|
63
|
+
};
|
64
|
+
|
65
|
+
/// Logger output that writes to a file.
|
66
|
+
class SGL_API FileLoggerOutput : public LoggerOutput {
|
67
|
+
public:
|
68
|
+
FileLoggerOutput(const std::filesystem::path& path);
|
69
|
+
~FileLoggerOutput();
|
70
|
+
|
71
|
+
const std::filesystem::path& path() const { return m_path; }
|
72
|
+
|
73
|
+
void write(LogLevel level, const std::string_view module, const std::string_view msg) override;
|
74
|
+
|
75
|
+
std::string to_string() const override;
|
76
|
+
|
77
|
+
private:
|
78
|
+
std::filesystem::path m_path;
|
79
|
+
void* m_file;
|
80
|
+
};
|
81
|
+
|
82
|
+
/// Logger output that writes to the debug console (Windows only).
|
83
|
+
class SGL_API DebugConsoleLoggerOutput : public LoggerOutput {
|
84
|
+
public:
|
85
|
+
void write(LogLevel level, const std::string_view module, const std::string_view msg) override;
|
86
|
+
|
87
|
+
std::string to_string() const override;
|
88
|
+
};
|
89
|
+
|
90
|
+
/// Defines a family of logging functions for a given log level.
|
91
|
+
/// The functions are:
|
92
|
+
/// - name(msg)
|
93
|
+
/// - name(fmt, ...)
|
94
|
+
/// - name_once(msg)
|
95
|
+
/// - name_once(fmt, ...)
|
96
|
+
/// The once variants only log the message once per program run.
|
97
|
+
#define SGL_LOG_FUNC_FAMILY(name, level, log_func) \
|
98
|
+
inline void name(const std::string_view msg) \
|
99
|
+
{ \
|
100
|
+
log_func(level, msg, LogFrequency::always); \
|
101
|
+
} \
|
102
|
+
template<typename... Args> \
|
103
|
+
inline void name(fmt::format_string<Args...> fmt, Args&&... args) \
|
104
|
+
{ \
|
105
|
+
log_func(level, fmt::format(fmt, std::forward<Args>(args)...), LogFrequency::always); \
|
106
|
+
} \
|
107
|
+
inline void name##_once(const std::string_view msg) \
|
108
|
+
{ \
|
109
|
+
log_func(level, msg, LogFrequency::once); \
|
110
|
+
} \
|
111
|
+
template<typename... Args> \
|
112
|
+
inline void name##_once(fmt::format_string<Args...> fmt, Args&&... args) \
|
113
|
+
{ \
|
114
|
+
log_func(level, fmt::format(fmt, std::forward<Args>(args)...), LogFrequency::once); \
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
class SGL_API Logger : public Object {
|
119
|
+
SGL_OBJECT(Logger)
|
120
|
+
public:
|
121
|
+
/// Constructor.
|
122
|
+
/// \param level The log level to use (messages with level >= this will be logged).
|
123
|
+
/// \param name The name of the logger.
|
124
|
+
/// \param use_default_outputs Whether to use the default outputs (console + debug console on windows).
|
125
|
+
Logger(LogLevel level = LogLevel::info, const std::string_view name = {}, bool use_default_outputs = true);
|
126
|
+
|
127
|
+
static ref<Logger>
|
128
|
+
create(LogLevel level = LogLevel::info, const std::string_view name = {}, bool use_default_outputs = true)
|
129
|
+
{
|
130
|
+
return make_ref<Logger>(level, name, use_default_outputs);
|
131
|
+
}
|
132
|
+
|
133
|
+
/// Add a console logger output.
|
134
|
+
/// \param colored Whether to use colored output.
|
135
|
+
/// \return The created logger output.
|
136
|
+
ref<LoggerOutput> add_console_output(bool colored = true);
|
137
|
+
|
138
|
+
/// Add a file logger output.
|
139
|
+
/// \param path The path to the log file.
|
140
|
+
/// \return The created logger output.
|
141
|
+
ref<LoggerOutput> add_file_output(const std::filesystem::path& path);
|
142
|
+
|
143
|
+
/// Add a debug console logger output (Windows only).
|
144
|
+
/// \return The created logger output.
|
145
|
+
ref<LoggerOutput> add_debug_console_output();
|
146
|
+
|
147
|
+
/// Use the same outputs as the given logger.
|
148
|
+
/// \param other Logger to copy outputs from.
|
149
|
+
void use_same_outputs(const Logger& other);
|
150
|
+
|
151
|
+
/// Add a logger output.
|
152
|
+
/// \param output The logger output to add.
|
153
|
+
void add_output(ref<LoggerOutput> output);
|
154
|
+
|
155
|
+
/// Remove a logger output.
|
156
|
+
/// \param output The logger output to remove.
|
157
|
+
void remove_output(ref<LoggerOutput> output);
|
158
|
+
|
159
|
+
/// Remove all logger outputs.
|
160
|
+
void remove_all_outputs();
|
161
|
+
|
162
|
+
/// The name of the logger.
|
163
|
+
std::string name() const;
|
164
|
+
void set_name(std::string_view name);
|
165
|
+
|
166
|
+
/// The log level.
|
167
|
+
LogLevel level() const;
|
168
|
+
void set_level(LogLevel level);
|
169
|
+
|
170
|
+
/// Log a message.
|
171
|
+
/// \param level The log level.
|
172
|
+
/// \param msg The message.
|
173
|
+
/// \param frequency The log frequency.
|
174
|
+
void log(LogLevel level, const std::string_view msg, LogFrequency frequency = LogFrequency::always);
|
175
|
+
|
176
|
+
// Define logging functions.
|
177
|
+
SGL_LOG_FUNC_FAMILY(debug, LogLevel::debug, log)
|
178
|
+
SGL_LOG_FUNC_FAMILY(info, LogLevel::info, log)
|
179
|
+
SGL_LOG_FUNC_FAMILY(warn, LogLevel::warn, log)
|
180
|
+
SGL_LOG_FUNC_FAMILY(error, LogLevel::error, log)
|
181
|
+
SGL_LOG_FUNC_FAMILY(fatal, LogLevel::fatal, log)
|
182
|
+
|
183
|
+
/// Returns the global logger instance.
|
184
|
+
static Logger& get();
|
185
|
+
|
186
|
+
static void static_init();
|
187
|
+
static void static_shutdown();
|
188
|
+
|
189
|
+
private:
|
190
|
+
/// Checks if the given message has already been logged.
|
191
|
+
bool is_duplicate(const std::string_view msg);
|
192
|
+
|
193
|
+
LogLevel m_level{LogLevel::info};
|
194
|
+
std::string m_name;
|
195
|
+
|
196
|
+
std::set<ref<LoggerOutput>> m_outputs;
|
197
|
+
std::set<std::string, std::less<>> m_messages;
|
198
|
+
|
199
|
+
mutable std::mutex m_mutex;
|
200
|
+
};
|
201
|
+
|
202
|
+
// Define global logging functions.
|
203
|
+
SGL_LOG_FUNC_FAMILY(log_debug, LogLevel::debug, Logger::get().log)
|
204
|
+
SGL_LOG_FUNC_FAMILY(log_info, LogLevel::info, Logger::get().log)
|
205
|
+
SGL_LOG_FUNC_FAMILY(log_warn, LogLevel::warn, Logger::get().log)
|
206
|
+
SGL_LOG_FUNC_FAMILY(log_error, LogLevel::error, Logger::get().log)
|
207
|
+
SGL_LOG_FUNC_FAMILY(log_fatal, LogLevel::fatal, Logger::get().log)
|
208
|
+
|
209
|
+
#undef SGL_LOG_FUNC_FAMILY
|
210
|
+
|
211
|
+
} // namespace sgl
|
212
|
+
|
213
|
+
/// Prints the given variable name and value.
|
214
|
+
#define SGL_PRINT(var) ::sgl::Logger::get().log(::sgl::LogLevel::none, ::fmt::format("{} = {}", #var, var))
|
@@ -0,0 +1,184 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
// -------------------------------------------------------------------------------------------------
|
6
|
+
// Compiler macros
|
7
|
+
// -------------------------------------------------------------------------------------------------
|
8
|
+
|
9
|
+
#define SGL_COMPILER_MSVC 1
|
10
|
+
#define SGL_COMPILER_CLANG 2
|
11
|
+
#define SGL_COMPILER_GCC 3
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Determine the compiler in use.
|
15
|
+
* http://sourceforge.net/p/predef/wiki/Compilers/
|
16
|
+
*/
|
17
|
+
#ifndef SGL_COMPILER
|
18
|
+
#if defined(_MSC_VER)
|
19
|
+
#define SGL_COMPILER SGL_COMPILER_MSVC
|
20
|
+
#elif defined(__clang__)
|
21
|
+
#define SGL_COMPILER SGL_COMPILER_CLANG
|
22
|
+
#elif defined(__GNUC__)
|
23
|
+
#define SGL_COMPILER SGL_COMPILER_GCC
|
24
|
+
#else
|
25
|
+
#error "Unsupported compiler"
|
26
|
+
#endif
|
27
|
+
#endif // SGL_COMPILER
|
28
|
+
|
29
|
+
#define SGL_MSVC (SGL_COMPILER == SGL_COMPILER_MSVC)
|
30
|
+
#define SGL_CLANG (SGL_COMPILER == SGL_COMPILER_CLANG)
|
31
|
+
#define SGL_GCC (SGL_COMPILER == SGL_COMPILER_GCC)
|
32
|
+
|
33
|
+
// -------------------------------------------------------------------------------------------------
|
34
|
+
// Architecture macros
|
35
|
+
// -------------------------------------------------------------------------------------------------
|
36
|
+
|
37
|
+
#define SGL_ARCH_X86_64 1
|
38
|
+
#define SGL_ARCH_ARM64 2
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Determine the target architecture in use.
|
42
|
+
* http://sourceforge.net/p/predef/wiki/Architectures/
|
43
|
+
*/
|
44
|
+
#ifndef SGL_ARCH
|
45
|
+
#if defined(_M_X64) || defined(__x86_64__)
|
46
|
+
#define SGL_ARCH SGL_ARCH_X86_64
|
47
|
+
#elif defined(_M_ARM64) || defined(__aarch64__)
|
48
|
+
#define SGL_ARCH SGL_ARCH_ARM64
|
49
|
+
#else
|
50
|
+
#error "Unsupported target architecture"
|
51
|
+
#endif
|
52
|
+
#endif // SGL_ARCH
|
53
|
+
|
54
|
+
#define SGL_X86_64 (SGL_ARCH == SGL_ARCH_X86_64)
|
55
|
+
#define SGL_ARM64 (SGL_ARCH == SGL_ARCH_ARM64)
|
56
|
+
|
57
|
+
// -------------------------------------------------------------------------------------------------
|
58
|
+
// Platform macros
|
59
|
+
// -------------------------------------------------------------------------------------------------
|
60
|
+
|
61
|
+
#define SGL_PLATFORM_WINDOWS 1
|
62
|
+
#define SGL_PLATFORM_LINUX 2
|
63
|
+
#define SGL_PLATFORM_MACOS 3
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Determine the target platform in use.
|
67
|
+
* http://sourceforge.net/p/predef/wiki/OperatingSystems/
|
68
|
+
*/
|
69
|
+
#ifndef SGL_PLATFORM
|
70
|
+
#if defined(_WIN64)
|
71
|
+
#define SGL_PLATFORM SGL_PLATFORM_WINDOWS
|
72
|
+
#elif defined(__linux__)
|
73
|
+
#define SGL_PLATFORM SGL_PLATFORM_LINUX
|
74
|
+
#elif defined(__APPLE__) && defined(__MACH__)
|
75
|
+
#define SGL_PLATFORM SGL_PLATFORM_MACOS
|
76
|
+
#else
|
77
|
+
#error "Unsupported target platform"
|
78
|
+
#endif
|
79
|
+
#endif // SGL_PLATFORM
|
80
|
+
|
81
|
+
#define SGL_WINDOWS (SGL_PLATFORM == SGL_PLATFORM_WINDOWS)
|
82
|
+
#define SGL_LINUX (SGL_PLATFORM == SGL_PLATFORM_LINUX)
|
83
|
+
#define SGL_MACOS (SGL_PLATFORM == SGL_PLATFORM_MACOS)
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Shared library (DLL) export and import.
|
87
|
+
*/
|
88
|
+
#if SGL_WINDOWS
|
89
|
+
#define SGL_API_EXPORT __declspec(dllexport)
|
90
|
+
#define SGL_API_IMPORT __declspec(dllimport)
|
91
|
+
#else
|
92
|
+
#define SGL_API_EXPORT __attribute__((visibility("default")))
|
93
|
+
#define SGL_API_IMPORT
|
94
|
+
#endif
|
95
|
+
|
96
|
+
#ifdef SGL_DLL
|
97
|
+
#define SGL_API SGL_API_EXPORT
|
98
|
+
#else // SGL_DLL
|
99
|
+
#define SGL_API SGL_API_IMPORT
|
100
|
+
#endif // SGL_DLL
|
101
|
+
|
102
|
+
// -------------------------------------------------------------------------------------------------
|
103
|
+
// Convenience macros
|
104
|
+
// -------------------------------------------------------------------------------------------------
|
105
|
+
|
106
|
+
#if SGL_MSVC
|
107
|
+
#define SGL_INLINE __forceinline
|
108
|
+
#elif SGL_CLANG | SGL_GCC
|
109
|
+
#define SGL_INLINE __attribute__((always_inline))
|
110
|
+
#endif
|
111
|
+
|
112
|
+
#define SGL_NON_COPYABLE(cls) \
|
113
|
+
cls(const cls&) = delete; \
|
114
|
+
cls& operator=(const cls&) = delete
|
115
|
+
|
116
|
+
#define SGL_NON_MOVABLE(cls) \
|
117
|
+
cls(cls&&) = delete; \
|
118
|
+
cls& operator=(cls&&) = delete
|
119
|
+
|
120
|
+
#define SGL_NON_COPYABLE_AND_MOVABLE(cls) \
|
121
|
+
SGL_NON_COPYABLE(cls); \
|
122
|
+
SGL_NON_MOVABLE(cls)
|
123
|
+
|
124
|
+
// clang-format off
|
125
|
+
namespace sgl::detail { template<typename... Args> inline void unused(Args&&...) {} }
|
126
|
+
// clang-format on
|
127
|
+
|
128
|
+
#define SGL_UNUSED(...) ::sgl::detail::unused(__VA_ARGS__)
|
129
|
+
|
130
|
+
#define SGL_STRINGIZE(a) #a
|
131
|
+
#define SGL_TO_STRING(a) SGL_STRINGIZE(a)
|
132
|
+
#define SGL_CONCAT_STRINGS_(a, b) a##b
|
133
|
+
#define SGL_CONCAT_STRINGS(a, b) SGL_CONCAT_STRINGS_(a, b)
|
134
|
+
|
135
|
+
// -------------------------------------------------------------------------------------------------
|
136
|
+
// Compiler warnings
|
137
|
+
// -------------------------------------------------------------------------------------------------
|
138
|
+
|
139
|
+
// Example usage:
|
140
|
+
// SGL_DIAGNOSTIC_PUSH
|
141
|
+
// SGL_DISABLE_MSVC_WARNING(4455)
|
142
|
+
// SGL_DISABLE_CLANG_WARNING("-Wuser-defined-literals")
|
143
|
+
// SGL_DISABLE_GCC_WARNING("-Wliteral-suffix")
|
144
|
+
// inline float16_t operator""h(long double value) { return float16_t(static_cast<float>(value)); }
|
145
|
+
// SGL_DIAGNOSTIC_POP
|
146
|
+
|
147
|
+
#if SGL_MSVC
|
148
|
+
#define SGL_DIAGNOSTIC_PUSH __pragma(warning(push))
|
149
|
+
#define SGL_DIAGNOSTIC_POP __pragma(warning(pop))
|
150
|
+
#define SGL_DISABLE_WARNING(warning_) __pragma(warning(disable : warning_))
|
151
|
+
#define SGL_DISABLE_MSVC_WARNING(warning) SGL_DISABLE_WARNING(warning)
|
152
|
+
#define SGL_DISABLE_CLANG_WARNING(warning)
|
153
|
+
#define SGL_DISABLE_GCC_WARNING(warning)
|
154
|
+
#elif SGL_CLANG
|
155
|
+
#define SGL_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
|
156
|
+
#define SGL_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
|
157
|
+
#define SGL_DISABLE_WARNING(warning) _Pragma(SGL_STRINGIZE(clang diagnostic ignored warning))
|
158
|
+
#define SGL_DISABLE_MSVC_WARNING(warning)
|
159
|
+
#define SGL_DISABLE_CLANG_WARNING(warning) SGL_DISABLE_WARNING(warning)
|
160
|
+
#define SGL_DISABLE_GCC_WARNING(warning)
|
161
|
+
#elif SGL_GCC
|
162
|
+
#define SGL_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
|
163
|
+
#define SGL_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
|
164
|
+
#define SGL_DISABLE_WARNING(warning) _Pragma(SGL_STRINGIZE(GCC diagnostic ignored warning))
|
165
|
+
#define SGL_DISABLE_MSVC_WARNING(warning)
|
166
|
+
#define SGL_DISABLE_CLANG_WARNING(warning)
|
167
|
+
#define SGL_DISABLE_GCC_WARNING(warning) SGL_DISABLE_WARNING(warning)
|
168
|
+
#endif
|
169
|
+
|
170
|
+
// -------------------------------------------------------------------------------------------------
|
171
|
+
// Enum flags
|
172
|
+
// -------------------------------------------------------------------------------------------------
|
173
|
+
|
174
|
+
// clang-format off
|
175
|
+
/// Implement logical operators on a class enum for making it usable as a flags enum.
|
176
|
+
#define SGL_ENUM_CLASS_OPERATORS(e_) \
|
177
|
+
inline e_ operator& (e_ a, e_ b) { return static_cast<e_>(static_cast<int>(a)& static_cast<int>(b)); } \
|
178
|
+
inline e_ operator| (e_ a, e_ b) { return static_cast<e_>(static_cast<int>(a)| static_cast<int>(b)); } \
|
179
|
+
inline e_& operator|= (e_& a, e_ b) { a = a | b; return a; }; \
|
180
|
+
inline e_& operator&= (e_& a, e_ b) { a = a & b; return a; }; \
|
181
|
+
inline e_ operator~ (e_ a) { return static_cast<e_>(~static_cast<int>(a)); } \
|
182
|
+
inline bool is_set(e_ val, e_ flag) { return (val & flag) != static_cast<e_>(0); } \
|
183
|
+
inline void flip_bit(e_& val, e_ flag) { val = is_set(val, flag) ? (val & (~flag)) : (val | flag); }
|
184
|
+
// clang-format on
|
@@ -0,0 +1,45 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include <algorithm>
|
6
|
+
#include <concepts>
|
7
|
+
|
8
|
+
namespace sgl {
|
9
|
+
|
10
|
+
/// Clamp x to [lo..hi] range.
|
11
|
+
template<typename T>
|
12
|
+
constexpr T clamp(const T& x, const T& lo, const T& hi)
|
13
|
+
{
|
14
|
+
return std::min(std::max(x, lo), hi);
|
15
|
+
}
|
16
|
+
|
17
|
+
/// Linearly interpolate between a and b.
|
18
|
+
template<typename T, std::floating_point U>
|
19
|
+
constexpr T lerp(const T& a, const T& b, const U& t)
|
20
|
+
{
|
21
|
+
return (U(1) - t) * a + t * b;
|
22
|
+
}
|
23
|
+
|
24
|
+
/// Returns true if integer value is a power of two.
|
25
|
+
template<std::integral T>
|
26
|
+
constexpr bool is_power_of_two(T a)
|
27
|
+
{
|
28
|
+
return (a & (a - (T)1)) == 0;
|
29
|
+
}
|
30
|
+
|
31
|
+
/// Divide a by b and round up to the next integer.
|
32
|
+
template<std::integral T>
|
33
|
+
constexpr T div_round_up(T a, T b)
|
34
|
+
{
|
35
|
+
return (a + b - T(1)) / b;
|
36
|
+
}
|
37
|
+
|
38
|
+
/// Align an integer value to the given alignment.
|
39
|
+
template<std::integral T>
|
40
|
+
constexpr T align_to(T alignment, T value)
|
41
|
+
{
|
42
|
+
return ((value + alignment - T(1)) / alignment) * alignment;
|
43
|
+
}
|
44
|
+
|
45
|
+
} // namespace sgl
|
@@ -0,0 +1,112 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/macros.h"
|
6
|
+
|
7
|
+
#include <cstdint>
|
8
|
+
#include <filesystem>
|
9
|
+
#include <limits>
|
10
|
+
|
11
|
+
namespace sgl {
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Utility class for reading memory-mapped files.
|
15
|
+
*/
|
16
|
+
class SGL_API MemoryMappedFile {
|
17
|
+
public:
|
18
|
+
enum class AccessHint {
|
19
|
+
/// Good overall performance.
|
20
|
+
normal,
|
21
|
+
/// Read file once with few seeks.
|
22
|
+
sequential,
|
23
|
+
/// Good for random access.
|
24
|
+
random
|
25
|
+
};
|
26
|
+
|
27
|
+
static constexpr size_t WHOLE_FILE = std::numeric_limits<size_t>::max();
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Default constructor. Use open() for opening a file.
|
31
|
+
*/
|
32
|
+
MemoryMappedFile() = default;
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Constructor opening a file. Use is_open() to check if successful.
|
36
|
+
* \param path Path to open.
|
37
|
+
* \param mapped_size Number of bytes to map into memory (automatically clamped to the file size).
|
38
|
+
* \param access_hint Hint on how memory is accessed.
|
39
|
+
*/
|
40
|
+
MemoryMappedFile(
|
41
|
+
const std::filesystem::path& path,
|
42
|
+
size_t mapped_size = WHOLE_FILE,
|
43
|
+
AccessHint access_hint = AccessHint::normal
|
44
|
+
);
|
45
|
+
|
46
|
+
/// Destructor. Closes the file.
|
47
|
+
~MemoryMappedFile();
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Open a file.
|
51
|
+
* \param path Path to open.
|
52
|
+
* \param mapped_size Number of bytes to map into memory (automatically clamped to the file size).
|
53
|
+
* \param access_hint Hint on how memory is accessed.
|
54
|
+
* \return True if file was successfully opened.
|
55
|
+
*/
|
56
|
+
bool open(
|
57
|
+
const std::filesystem::path& path,
|
58
|
+
size_t mapped_size = WHOLE_FILE,
|
59
|
+
AccessHint access_hint = AccessHint::normal
|
60
|
+
);
|
61
|
+
|
62
|
+
/// Close the file.
|
63
|
+
void close();
|
64
|
+
|
65
|
+
/// True, if file successfully opened.
|
66
|
+
bool is_open() const { return m_mapped_data != nullptr; }
|
67
|
+
|
68
|
+
/// Get the file size in bytes.
|
69
|
+
size_t size() const { return m_size; }
|
70
|
+
|
71
|
+
/// Get the mapped data.
|
72
|
+
const void* data() const { return m_mapped_data; };
|
73
|
+
|
74
|
+
/// Get the mapped memory size in bytes.
|
75
|
+
size_t mapped_size() const { return m_mapped_size; };
|
76
|
+
|
77
|
+
/// Get the OS page size (for remap).
|
78
|
+
static size_t page_size();
|
79
|
+
|
80
|
+
private:
|
81
|
+
MemoryMappedFile(const MemoryMappedFile&) = delete;
|
82
|
+
MemoryMappedFile(MemoryMappedFile&) = delete;
|
83
|
+
MemoryMappedFile& operator=(const MemoryMappedFile&) = delete;
|
84
|
+
MemoryMappedFile& operator=(const MemoryMappedFile&&) = delete;
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Replace mapping by a new one of the same file.
|
88
|
+
* \param offset Offset from start of the file in bytes (must be multiple of page size).
|
89
|
+
* \param mapped_size Size of mapping in bytes.
|
90
|
+
* \return True if successful.
|
91
|
+
*/
|
92
|
+
bool remap(uint64_t offset, size_t mapped_size);
|
93
|
+
|
94
|
+
std::filesystem::path m_path;
|
95
|
+
AccessHint m_access_hint = AccessHint::normal;
|
96
|
+
size_t m_size = 0;
|
97
|
+
|
98
|
+
#if SGL_WINDOWS
|
99
|
+
using FileHandle = void*;
|
100
|
+
void* m_mapped_file{nullptr};
|
101
|
+
#elif SGL_LINUX || SGL_MACOS
|
102
|
+
using FileHandle = int;
|
103
|
+
#else
|
104
|
+
#error "Unknown OS"
|
105
|
+
#endif
|
106
|
+
|
107
|
+
FileHandle m_file = 0;
|
108
|
+
void* m_mapped_data = 0;
|
109
|
+
size_t m_mapped_size = 0;
|
110
|
+
};
|
111
|
+
|
112
|
+
} // namespace sgl
|
@@ -0,0 +1,32 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/memory_stream.h"
|
6
|
+
#include "sgl/core/memory_mapped_file.h"
|
7
|
+
|
8
|
+
#include <filesystem>
|
9
|
+
#include <memory>
|
10
|
+
|
11
|
+
namespace sgl {
|
12
|
+
|
13
|
+
class SGL_API MemoryMappedFileStream : public MemoryStream {
|
14
|
+
SGL_OBJECT(MemoryMappedFileStream)
|
15
|
+
public:
|
16
|
+
MemoryMappedFileStream(
|
17
|
+
const std::filesystem::path& path,
|
18
|
+
size_t mapped_size = MemoryMappedFile::WHOLE_FILE,
|
19
|
+
MemoryMappedFile::AccessHint access_hint = MemoryMappedFile::AccessHint::normal
|
20
|
+
);
|
21
|
+
~MemoryMappedFileStream();
|
22
|
+
|
23
|
+
const std::filesystem::path& path() const { return m_path; }
|
24
|
+
|
25
|
+
std::string to_string() const override;
|
26
|
+
|
27
|
+
public:
|
28
|
+
std::filesystem::path m_path;
|
29
|
+
std::unique_ptr<MemoryMappedFile> m_file;
|
30
|
+
};
|
31
|
+
|
32
|
+
} // namespace sgl
|
@@ -0,0 +1,74 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/stream.h"
|
6
|
+
|
7
|
+
namespace sgl {
|
8
|
+
|
9
|
+
class SGL_API MemoryStream : public Stream {
|
10
|
+
SGL_OBJECT(MemoryStream)
|
11
|
+
public:
|
12
|
+
/// Create a read/write memory stream with the given initial capacity.
|
13
|
+
MemoryStream(size_t capacity = 1024);
|
14
|
+
|
15
|
+
/// Create a read-only memory stream from an existing buffer.
|
16
|
+
MemoryStream(const void* data, size_t size);
|
17
|
+
|
18
|
+
/// Create a read/write memory stream from an existing buffer.
|
19
|
+
MemoryStream(void* data, size_t size);
|
20
|
+
|
21
|
+
/// Destructor.
|
22
|
+
virtual ~MemoryStream();
|
23
|
+
|
24
|
+
virtual bool is_open() const override { return m_is_open; }
|
25
|
+
|
26
|
+
virtual bool is_readable() const override { return true; }
|
27
|
+
|
28
|
+
virtual bool is_writable() const override { return m_is_writable; }
|
29
|
+
|
30
|
+
virtual void close() override;
|
31
|
+
|
32
|
+
virtual void read(void* p, size_t size) override;
|
33
|
+
|
34
|
+
virtual void write(const void* p, size_t size) override;
|
35
|
+
|
36
|
+
virtual void seek(size_t pos) override { m_pos = pos; }
|
37
|
+
|
38
|
+
virtual void truncate(size_t size) override;
|
39
|
+
|
40
|
+
virtual size_t tell() const override { return m_pos; }
|
41
|
+
|
42
|
+
virtual size_t size() const override { return m_size; }
|
43
|
+
|
44
|
+
virtual void flush() override { }
|
45
|
+
|
46
|
+
/// Return the current capacity of the underlying buffer.
|
47
|
+
size_t capacity() const { return m_capacity; }
|
48
|
+
|
49
|
+
/// Return true if stream owns the underlying buffer.
|
50
|
+
bool owns_data() const { return m_owns_data; }
|
51
|
+
|
52
|
+
/// Return the underlying raw buffer.
|
53
|
+
const uint8_t* data() const { return m_data; }
|
54
|
+
|
55
|
+
protected:
|
56
|
+
void resize(size_t new_size);
|
57
|
+
|
58
|
+
/// Current capacity of the underlying buffer.
|
59
|
+
size_t m_capacity;
|
60
|
+
/// Current size of the stream.
|
61
|
+
size_t m_size;
|
62
|
+
/// Current position in the stream.
|
63
|
+
size_t m_pos;
|
64
|
+
/// Pointer to the underlying buffer.
|
65
|
+
uint8_t* m_data;
|
66
|
+
/// True if the stream owns the underlying buffer.
|
67
|
+
bool m_owns_data;
|
68
|
+
/// True if the stream is open.
|
69
|
+
bool m_is_open;
|
70
|
+
/// True if the stream is writable.
|
71
|
+
bool m_is_writable;
|
72
|
+
};
|
73
|
+
|
74
|
+
} // namespace sgl
|