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,57 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/device/fwd.h"
|
6
|
+
#include "sgl/device/device_resource.h"
|
7
|
+
#include "sgl/device/types.h"
|
8
|
+
#include "sgl/device/native_handle.h"
|
9
|
+
|
10
|
+
#include "sgl/core/macros.h"
|
11
|
+
#include "sgl/core/object.h"
|
12
|
+
|
13
|
+
#include "sgl/math/vector.h"
|
14
|
+
|
15
|
+
#include <slang-gfx.h>
|
16
|
+
|
17
|
+
namespace sgl {
|
18
|
+
|
19
|
+
struct SamplerDesc {
|
20
|
+
TextureFilteringMode min_filter{TextureFilteringMode::linear};
|
21
|
+
TextureFilteringMode mag_filter{TextureFilteringMode::linear};
|
22
|
+
TextureFilteringMode mip_filter{TextureFilteringMode::linear};
|
23
|
+
TextureReductionOp reduction_op{TextureReductionOp::average};
|
24
|
+
TextureAddressingMode address_u{TextureAddressingMode::wrap};
|
25
|
+
TextureAddressingMode address_v{TextureAddressingMode::wrap};
|
26
|
+
TextureAddressingMode address_w{TextureAddressingMode::wrap};
|
27
|
+
float mip_lod_bias{0.f};
|
28
|
+
uint32_t max_anisotropy{1};
|
29
|
+
ComparisonFunc comparison_func{ComparisonFunc::never};
|
30
|
+
float4 border_color{1.f, 1.f, 1.f, 1.f};
|
31
|
+
float min_lod{-1000.f};
|
32
|
+
float max_lod{1000.f};
|
33
|
+
};
|
34
|
+
|
35
|
+
class SGL_API Sampler : public DeviceResource {
|
36
|
+
SGL_OBJECT(Sampler)
|
37
|
+
public:
|
38
|
+
Sampler(ref<Device> device, SamplerDesc desc);
|
39
|
+
~Sampler();
|
40
|
+
|
41
|
+
const SamplerDesc& desc() const { return m_desc; }
|
42
|
+
|
43
|
+
gfx::ISamplerState* gfx_sampler_state() const { return m_gfx_sampler_state; }
|
44
|
+
|
45
|
+
/// Returns the native API handle:
|
46
|
+
/// - D3D12: D3D12_CPU_DESCRIPTOR_HANDLE
|
47
|
+
/// - Vulkan: VkSampler
|
48
|
+
NativeHandle get_native_handle() const;
|
49
|
+
|
50
|
+
std::string to_string() const override;
|
51
|
+
|
52
|
+
private:
|
53
|
+
SamplerDesc m_desc;
|
54
|
+
Slang::ComPtr<gfx::ISamplerState> m_gfx_sampler_state;
|
55
|
+
};
|
56
|
+
|
57
|
+
} // namespace sgl
|
@@ -0,0 +1,516 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/device/fwd.h"
|
6
|
+
#include "sgl/device/types.h"
|
7
|
+
#include "sgl/device/reflection.h"
|
8
|
+
#include "sgl/device/device_resource.h"
|
9
|
+
|
10
|
+
#include "sgl/core/object.h"
|
11
|
+
#include "sgl/core/enum.h"
|
12
|
+
|
13
|
+
#include <exception>
|
14
|
+
#include <map>
|
15
|
+
#include <set>
|
16
|
+
#include <string>
|
17
|
+
#include <vector>
|
18
|
+
|
19
|
+
#include <slang.h>
|
20
|
+
|
21
|
+
namespace sgl {
|
22
|
+
|
23
|
+
/// \brief Type conformance entry.
|
24
|
+
/// Type conformances are used to narrow the set of types supported by a slang interface.
|
25
|
+
/// They can be specified on an entry point to omit generating code for types that do not conform.
|
26
|
+
struct SGL_API TypeConformance {
|
27
|
+
/// Name of the interface.
|
28
|
+
std::string interface_name;
|
29
|
+
/// Name of the concrete type.
|
30
|
+
std::string type_name;
|
31
|
+
/// Unique id per type for an interface (optional).
|
32
|
+
int32_t id{-1};
|
33
|
+
|
34
|
+
TypeConformance() = default;
|
35
|
+
TypeConformance(std::string_view interface_name, std::string_view type_name, int32_t id = -1)
|
36
|
+
: interface_name(interface_name)
|
37
|
+
, type_name(type_name)
|
38
|
+
, id(id)
|
39
|
+
{
|
40
|
+
}
|
41
|
+
|
42
|
+
std::string to_string() const;
|
43
|
+
};
|
44
|
+
|
45
|
+
/// Exception thrown on compilation errors.
|
46
|
+
class SlangCompileError : public std::runtime_error {
|
47
|
+
public:
|
48
|
+
SlangCompileError(const std::string& what)
|
49
|
+
: std::runtime_error(what)
|
50
|
+
{
|
51
|
+
}
|
52
|
+
};
|
53
|
+
|
54
|
+
/// Slang matrix layout modes.
|
55
|
+
enum class SlangMatrixLayout {
|
56
|
+
row_major = SLANG_MATRIX_LAYOUT_ROW_MAJOR,
|
57
|
+
column_major = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR,
|
58
|
+
};
|
59
|
+
|
60
|
+
SGL_ENUM_INFO(
|
61
|
+
SlangMatrixLayout,
|
62
|
+
{
|
63
|
+
{SlangMatrixLayout::row_major, "row_major"},
|
64
|
+
{SlangMatrixLayout::column_major, "column_major"},
|
65
|
+
}
|
66
|
+
);
|
67
|
+
SGL_ENUM_REGISTER(SlangMatrixLayout);
|
68
|
+
|
69
|
+
/// Slang floating point modes.
|
70
|
+
enum class SlangFloatingPointMode {
|
71
|
+
default_ = SLANG_FLOATING_POINT_MODE_DEFAULT,
|
72
|
+
fast = SLANG_FLOATING_POINT_MODE_FAST,
|
73
|
+
precise = SLANG_FLOATING_POINT_MODE_PRECISE,
|
74
|
+
};
|
75
|
+
|
76
|
+
SGL_ENUM_INFO(
|
77
|
+
SlangFloatingPointMode,
|
78
|
+
{
|
79
|
+
{SlangFloatingPointMode::default_, "default"},
|
80
|
+
{SlangFloatingPointMode::fast, "fast"},
|
81
|
+
{SlangFloatingPointMode::precise, "precise"},
|
82
|
+
}
|
83
|
+
);
|
84
|
+
SGL_ENUM_REGISTER(SlangFloatingPointMode);
|
85
|
+
|
86
|
+
/// Slang debug info levels.
|
87
|
+
enum class SlangDebugInfoLevel {
|
88
|
+
/// No debug information.
|
89
|
+
none = SLANG_DEBUG_INFO_LEVEL_NONE,
|
90
|
+
/// Emit as little debug information as possible, while still supporting stack trackes.
|
91
|
+
minimal = SLANG_DEBUG_INFO_LEVEL_MINIMAL,
|
92
|
+
/// Emit whatever is the standard level of debug information for each target.
|
93
|
+
standard = SLANG_DEBUG_INFO_LEVEL_STANDARD,
|
94
|
+
/// Emit as much debug infromation as possible for each target.
|
95
|
+
maximal = SLANG_DEBUG_INFO_LEVEL_MAXIMAL,
|
96
|
+
};
|
97
|
+
|
98
|
+
SGL_ENUM_INFO(
|
99
|
+
SlangDebugInfoLevel,
|
100
|
+
{
|
101
|
+
{SlangDebugInfoLevel::none, "none"},
|
102
|
+
{SlangDebugInfoLevel::minimal, "minimal"},
|
103
|
+
{SlangDebugInfoLevel::standard, "standard"},
|
104
|
+
{SlangDebugInfoLevel::maximal, "maximal"},
|
105
|
+
}
|
106
|
+
);
|
107
|
+
SGL_ENUM_REGISTER(SlangDebugInfoLevel);
|
108
|
+
|
109
|
+
/// Slang optimization levels.
|
110
|
+
enum class SlangOptimizationLevel {
|
111
|
+
/// No optimizations.
|
112
|
+
none = SLANG_OPTIMIZATION_LEVEL_NONE,
|
113
|
+
/// Default optimization level: balance code quality and compilation time.
|
114
|
+
default_ = SLANG_OPTIMIZATION_LEVEL_DEFAULT,
|
115
|
+
/// Optimize aggressively.
|
116
|
+
high = SLANG_OPTIMIZATION_LEVEL_HIGH,
|
117
|
+
/// Include optimizations that may take a very long time, or may involve severe space-vs-speed tradeoffs.
|
118
|
+
maximal = SLANG_OPTIMIZATION_LEVEL_MAXIMAL,
|
119
|
+
};
|
120
|
+
|
121
|
+
SGL_ENUM_INFO(
|
122
|
+
SlangOptimizationLevel,
|
123
|
+
{
|
124
|
+
{SlangOptimizationLevel::none, "none"},
|
125
|
+
{SlangOptimizationLevel::default_, "default"},
|
126
|
+
{SlangOptimizationLevel::high, "high"},
|
127
|
+
{SlangOptimizationLevel::maximal, "maximal"},
|
128
|
+
}
|
129
|
+
);
|
130
|
+
SGL_ENUM_REGISTER(SlangOptimizationLevel);
|
131
|
+
|
132
|
+
/// Slang compiler options.
|
133
|
+
/// Can be set when creating a Slang session.
|
134
|
+
struct SlangCompilerOptions {
|
135
|
+
/// Specifies a list of include paths to be used when resolving module/include paths.
|
136
|
+
std::vector<std::filesystem::path> include_paths;
|
137
|
+
|
138
|
+
/// Specifies a list of preprocessor defines.
|
139
|
+
std::map<std::string, std::string> defines;
|
140
|
+
|
141
|
+
/// Specifies the shader model to use.
|
142
|
+
/// Defaults to latest available on the device.
|
143
|
+
ShaderModel shader_model{ShaderModel::unknown};
|
144
|
+
|
145
|
+
/// Specifies the matrix layout.
|
146
|
+
/// Defaults to row-major.
|
147
|
+
SlangMatrixLayout matrix_layout{SlangMatrixLayout::row_major};
|
148
|
+
|
149
|
+
/// Specifies a list of warnings to disable (warning codes or names).
|
150
|
+
std::vector<std::string> disable_warnings;
|
151
|
+
|
152
|
+
/// Specifies a list of warnings to enable (warning codes or names).
|
153
|
+
std::vector<std::string> enable_warnings;
|
154
|
+
|
155
|
+
/// Specifies a list of warnings to be treated as errors
|
156
|
+
/// (warning codes or names, or "all" to indicate all warnings).
|
157
|
+
std::vector<std::string> warnings_as_errors;
|
158
|
+
|
159
|
+
/// Turn on/off downstream compilation time report.
|
160
|
+
bool report_downstream_time{false};
|
161
|
+
|
162
|
+
/// Turn on/off reporting of time spend in different parts of the compiler.
|
163
|
+
bool report_perf_benchmark{false};
|
164
|
+
|
165
|
+
/// Specifies whether or not to skip the validation step after emitting SPIRV.
|
166
|
+
bool skip_spirv_validation{false};
|
167
|
+
|
168
|
+
//
|
169
|
+
// Target options.
|
170
|
+
// These can be extended/overriden at link time.
|
171
|
+
//
|
172
|
+
|
173
|
+
/// Specifies the floating point mode.
|
174
|
+
SlangFloatingPointMode floating_point_mode{SlangFloatingPointMode::default_};
|
175
|
+
|
176
|
+
/// Specifies the level of debug information to include in the generated code.
|
177
|
+
SlangDebugInfoLevel debug_info{SlangDebugInfoLevel::none};
|
178
|
+
|
179
|
+
/// Specifies the optimization level.
|
180
|
+
SlangOptimizationLevel optimization{SlangOptimizationLevel::default_};
|
181
|
+
|
182
|
+
/// Specifies a list of additional arguments to be passed to the downstream compiler.
|
183
|
+
std::vector<std::string> downstream_args;
|
184
|
+
|
185
|
+
/// When set will dump the intermediate source output.
|
186
|
+
bool dump_intermediates{false};
|
187
|
+
|
188
|
+
/// The file name prefix for the intermediate source output.
|
189
|
+
std::string dump_intermediates_prefix;
|
190
|
+
};
|
191
|
+
|
192
|
+
/// Slang link options.
|
193
|
+
/// These can optionally be set when linking a shader program.
|
194
|
+
struct SlangLinkOptions {
|
195
|
+
/// Specifies the floating point mode.
|
196
|
+
std::optional<SlangFloatingPointMode> floating_point_mode;
|
197
|
+
|
198
|
+
/// Specifies the level of debug information to include in the generated code.
|
199
|
+
std::optional<SlangDebugInfoLevel> debug_info;
|
200
|
+
|
201
|
+
/// Specifies the optimization level.
|
202
|
+
std::optional<SlangOptimizationLevel> optimization;
|
203
|
+
|
204
|
+
/// Specifies a list of additional arguments to be passed to the downstream compiler.
|
205
|
+
std::optional<std::vector<std::string>> downstream_args;
|
206
|
+
|
207
|
+
/// When set will dump the intermediate source output.
|
208
|
+
std::optional<bool> dump_intermediates;
|
209
|
+
|
210
|
+
/// The file name prefix for the intermediate source output.
|
211
|
+
std::optional<std::string> dump_intermediates_prefix;
|
212
|
+
};
|
213
|
+
|
214
|
+
struct SlangSessionData;
|
215
|
+
struct SlangModuleData;
|
216
|
+
struct SlangEntryPointData;
|
217
|
+
struct ShaderProgramData;
|
218
|
+
|
219
|
+
/// Intermediate structure used during a build that stores new session, module,
|
220
|
+
/// program and entry point information. This is populated during a build, then
|
221
|
+
/// applied to all built modules/entrypoints/programs at once on success.
|
222
|
+
struct SlangSessionBuild {
|
223
|
+
ref<SlangSessionData> session;
|
224
|
+
std::map<const SlangModule*, ref<SlangModuleData>> modules;
|
225
|
+
std::map<const ShaderProgram*, ref<ShaderProgramData>> programs;
|
226
|
+
std::map<const SlangEntryPoint*, ref<SlangEntryPointData>> entry_points;
|
227
|
+
};
|
228
|
+
|
229
|
+
/// Descriptor for slang session initialization.
|
230
|
+
struct SlangSessionDesc {
|
231
|
+
SlangCompilerOptions compiler_options;
|
232
|
+
bool add_default_include_paths{true};
|
233
|
+
std::optional<std::filesystem::path> cache_path;
|
234
|
+
};
|
235
|
+
|
236
|
+
/// Internal data stored once the slang session has been created.
|
237
|
+
struct SlangSessionData : Object {
|
238
|
+
/// Pointer to internal slang session.
|
239
|
+
Slang::ComPtr<slang::ISession> slang_session;
|
240
|
+
|
241
|
+
/// Set of all currently loaded slang modules.
|
242
|
+
std::set<slang::IModule*> loaded_modules;
|
243
|
+
|
244
|
+
/// Unique session hash.
|
245
|
+
std::string uid;
|
246
|
+
|
247
|
+
/// List of include paths used for resolving module/include paths.
|
248
|
+
std::vector<std::filesystem::path> include_paths;
|
249
|
+
|
250
|
+
/// True if session cache is enabled.
|
251
|
+
bool cache_enabled{false};
|
252
|
+
|
253
|
+
/// Cache root path.
|
254
|
+
std::filesystem::path cache_path;
|
255
|
+
|
256
|
+
/// One cache path for each include path under the root cache path.
|
257
|
+
std::vector<std::filesystem::path> cache_include_paths;
|
258
|
+
|
259
|
+
/// Finds fully qualified module name by scanning the cache and include paths.
|
260
|
+
std::string resolve_module_name(std::string_view module_name) const;
|
261
|
+
};
|
262
|
+
|
263
|
+
/// A slang session, used to load modules and link programs.
|
264
|
+
class SGL_API SlangSession : public Object {
|
265
|
+
SGL_OBJECT(SlangSession)
|
266
|
+
public:
|
267
|
+
SlangSession(ref<Device> device, SlangSessionDesc desc);
|
268
|
+
~SlangSession();
|
269
|
+
|
270
|
+
/// Fully recreates this session and any loaded modules or linked programs.
|
271
|
+
void recreate_session();
|
272
|
+
|
273
|
+
Device* device() const { return m_device; }
|
274
|
+
const SlangSessionDesc& desc() const { return m_desc; }
|
275
|
+
|
276
|
+
/// Load a module by name.
|
277
|
+
ref<SlangModule> load_module(std::string_view module_name);
|
278
|
+
|
279
|
+
/// Load a module from string source code.
|
280
|
+
ref<SlangModule> load_module_from_source(
|
281
|
+
std::string_view module_name,
|
282
|
+
std::string_view source,
|
283
|
+
std::optional<std::filesystem::path> path = {}
|
284
|
+
);
|
285
|
+
|
286
|
+
/// Link a program with a set of modules and entry points.
|
287
|
+
ref<ShaderProgram> link_program(
|
288
|
+
std::vector<ref<SlangModule>> modules,
|
289
|
+
std::vector<ref<SlangEntryPoint>> entry_points,
|
290
|
+
std::optional<SlangLinkOptions> link_options = {}
|
291
|
+
);
|
292
|
+
|
293
|
+
/// Load a program from a given module with a set of entry
|
294
|
+
/// points. Internally this simply wraps link_program without
|
295
|
+
/// requiring the user to explicitly load modules.
|
296
|
+
ref<ShaderProgram> load_program(
|
297
|
+
std::string_view module_name,
|
298
|
+
std::vector<std::string_view> entry_point_names,
|
299
|
+
std::optional<std::string_view> additional_source = {},
|
300
|
+
std::optional<SlangLinkOptions> link_options = {}
|
301
|
+
);
|
302
|
+
|
303
|
+
/// Load the source code for a given module.
|
304
|
+
std::string load_source(std::string_view module_name);
|
305
|
+
|
306
|
+
slang::ISession* get_slang_session() const { return m_data->slang_session; }
|
307
|
+
|
308
|
+
std::string to_string() const override;
|
309
|
+
|
310
|
+
// Internal functions to link programs+modules to their owning session
|
311
|
+
void _register_program(ShaderProgram* program);
|
312
|
+
void _unregister_program(ShaderProgram* program);
|
313
|
+
void _register_module(SlangModule* module);
|
314
|
+
void _unregister_module(SlangModule* module);
|
315
|
+
|
316
|
+
// Internal access to the built session data.
|
317
|
+
ref<SlangSessionData> _data() { return m_data; }
|
318
|
+
|
319
|
+
private:
|
320
|
+
ref<Device> m_device;
|
321
|
+
|
322
|
+
/// Descriptor containing all info required to build the session.
|
323
|
+
SlangSessionDesc m_desc;
|
324
|
+
|
325
|
+
/// Data pointer contains all slang pointers + data resulting from build.
|
326
|
+
ref<SlangSessionData> m_data;
|
327
|
+
|
328
|
+
/// Global NVAPI module linked to all programs.
|
329
|
+
ref<SlangModule> m_nvapi_module;
|
330
|
+
|
331
|
+
/// All loaded sgl modules (wrappers around IModule returned from load_module).
|
332
|
+
/// Note: this is a vector, as order of creation matters.
|
333
|
+
std::vector<SlangModule*> m_registered_modules;
|
334
|
+
|
335
|
+
/// All created sgl programs (via link_program)
|
336
|
+
std::set<ShaderProgram*> m_registered_programs;
|
337
|
+
|
338
|
+
void update_module_cache_and_dependencies();
|
339
|
+
bool write_module_to_cache(slang::IModule* module);
|
340
|
+
void create_session(SlangSessionBuild& build);
|
341
|
+
};
|
342
|
+
|
343
|
+
struct SlangModuleDesc {
|
344
|
+
/// Required module name
|
345
|
+
std::string module_name;
|
346
|
+
|
347
|
+
/// Optional module source. If not specified slang module resolution is used.
|
348
|
+
std::optional<std::string> source;
|
349
|
+
|
350
|
+
/// If source specified, additional path for compilation.
|
351
|
+
std::optional<std::filesystem::path> path;
|
352
|
+
};
|
353
|
+
|
354
|
+
struct SlangModuleData : Object {
|
355
|
+
slang::IModule* slang_module = nullptr;
|
356
|
+
std::string name;
|
357
|
+
std::filesystem::path path;
|
358
|
+
};
|
359
|
+
|
360
|
+
class SGL_API SlangModule : public Object {
|
361
|
+
SGL_OBJECT(SlangModule)
|
362
|
+
public:
|
363
|
+
SlangModule(ref<SlangSession> session, const SlangModuleDesc& desc);
|
364
|
+
~SlangModule();
|
365
|
+
|
366
|
+
/// Loads slang module and outputs the resulting SlangModuleData in current build info.
|
367
|
+
void load(SlangSessionBuild& build) const;
|
368
|
+
|
369
|
+
/// Finds this module in current build and updates internal m_data to point at it.
|
370
|
+
void store_built_data(SlangSessionBuild& build_data);
|
371
|
+
|
372
|
+
/// Repopulates a build structure with reference to internal m_data ptr.
|
373
|
+
void populate_build_data(SlangSessionBuild& build_data);
|
374
|
+
|
375
|
+
/// The session from which this module was built.
|
376
|
+
SlangSession* session() const { return m_session; }
|
377
|
+
|
378
|
+
/// Descriptor that holds all data required to create this module.
|
379
|
+
const SlangModuleDesc& desc() const { return m_desc; }
|
380
|
+
|
381
|
+
/// Module name.
|
382
|
+
const std::string& name() const { return m_data->name; }
|
383
|
+
|
384
|
+
/// Module source path. This can be empty if the module was generated from a string.
|
385
|
+
const std::filesystem::path& path() const { return m_data->path; }
|
386
|
+
ref<const ProgramLayout> layout() const
|
387
|
+
{
|
388
|
+
return ProgramLayout::from_slang(ref(this), m_data->slang_module->getLayout());
|
389
|
+
}
|
390
|
+
|
391
|
+
/// Build and return vector of all current entry points in the module.
|
392
|
+
std::vector<ref<SlangEntryPoint>> entry_points() const;
|
393
|
+
|
394
|
+
/// Get an entry point, optionally applying type conformances to it.
|
395
|
+
ref<SlangEntryPoint> entry_point(
|
396
|
+
std::string_view name,
|
397
|
+
std::span<TypeConformance> type_conformances = std::span<TypeConformance>()
|
398
|
+
) const;
|
399
|
+
bool has_entry_point(std::string_view name) const;
|
400
|
+
|
401
|
+
/// Get root decl ref for this module
|
402
|
+
ref<const DeclReflection> module_decl() const;
|
403
|
+
|
404
|
+
/// Internal slang module.
|
405
|
+
slang::IModule* slang_module() const { return m_data->slang_module; }
|
406
|
+
|
407
|
+
/// Text summary of the module.
|
408
|
+
std::string to_string() const override;
|
409
|
+
|
410
|
+
/// Unlinks the session reference for modules that are referred to by the session to avoid ref loops.
|
411
|
+
void break_strong_reference_to_session() { m_session.break_strong_reference(); }
|
412
|
+
|
413
|
+
|
414
|
+
void _register_entry_point(SlangEntryPoint* entry_point) const;
|
415
|
+
void _unregister_entry_point(SlangEntryPoint* entry_point) const;
|
416
|
+
ref<SlangModuleData> _data() { return m_data; }
|
417
|
+
|
418
|
+
private:
|
419
|
+
breakable_ref<SlangSession> m_session;
|
420
|
+
SlangModuleDesc m_desc;
|
421
|
+
ref<SlangModuleData> m_data;
|
422
|
+
|
423
|
+
mutable std::set<SlangEntryPoint*> m_registered_entry_points;
|
424
|
+
};
|
425
|
+
|
426
|
+
struct SlangEntryPointDesc {
|
427
|
+
std::string name;
|
428
|
+
std::vector<TypeConformance> type_conformances;
|
429
|
+
};
|
430
|
+
struct SlangEntryPointData : Object {
|
431
|
+
Slang::ComPtr<slang::IComponentType> slang_entry_point;
|
432
|
+
std::string name;
|
433
|
+
ShaderStage stage;
|
434
|
+
};
|
435
|
+
class SGL_API SlangEntryPoint : public Object {
|
436
|
+
SGL_OBJECT(SlangEntryPoint)
|
437
|
+
public:
|
438
|
+
SlangEntryPoint(ref<SlangModule> module, const SlangEntryPointDesc& desc);
|
439
|
+
~SlangEntryPoint();
|
440
|
+
|
441
|
+
/// Inits slang entry point and outputs the resulting SlangEntryPointData in current build info.
|
442
|
+
void init(SlangSessionBuild& build) const;
|
443
|
+
|
444
|
+
/// Finds this entry point in current build and updates internal m_data to point at it.
|
445
|
+
void store_built_data(SlangSessionBuild& build);
|
446
|
+
|
447
|
+
/// Repopulates a build structure with reference to internal m_data ptr.
|
448
|
+
void populate_build_data(SlangSessionBuild& build);
|
449
|
+
|
450
|
+
SlangModule* module() const { return m_module; }
|
451
|
+
|
452
|
+
const std::string& name() const { return m_data->name; }
|
453
|
+
const SlangEntryPointDesc& desc() const { return m_desc; }
|
454
|
+
ShaderStage stage() const { return m_data->stage; }
|
455
|
+
ref<const EntryPointLayout> layout() const;
|
456
|
+
|
457
|
+
ref<SlangEntryPoint> rename(const std::string& new_name);
|
458
|
+
|
459
|
+
/// Returns a copy of the entry point with a new name.
|
460
|
+
ref<SlangEntryPoint> with_name(const std::string& name) const;
|
461
|
+
|
462
|
+
slang::IComponentType* slang_entry_point() const { return m_data->slang_entry_point.get(); }
|
463
|
+
|
464
|
+
virtual std::string to_string() const override;
|
465
|
+
|
466
|
+
private:
|
467
|
+
ref<SlangModule> m_module;
|
468
|
+
SlangEntryPointDesc m_desc;
|
469
|
+
ref<SlangEntryPointData> m_data;
|
470
|
+
};
|
471
|
+
|
472
|
+
struct ShaderProgramDesc {
|
473
|
+
std::vector<ref<SlangModule>> modules;
|
474
|
+
std::vector<ref<SlangEntryPoint>> entry_points;
|
475
|
+
std::optional<SlangLinkOptions> link_options;
|
476
|
+
};
|
477
|
+
struct ShaderProgramData : Object {
|
478
|
+
Slang::ComPtr<slang::IComponentType> linked_program;
|
479
|
+
Slang::ComPtr<gfx::IShaderProgram> gfx_shader_program;
|
480
|
+
};
|
481
|
+
class SGL_API ShaderProgram : public DeviceResource {
|
482
|
+
SGL_OBJECT(ShaderProgram)
|
483
|
+
public:
|
484
|
+
ShaderProgram(ref<Device> device, ref<SlangSession> session, const ShaderProgramDesc& desc);
|
485
|
+
~ShaderProgram();
|
486
|
+
|
487
|
+
/// Links program and outputs the resulting ShaderProgramData to current build info.
|
488
|
+
void link(SlangSessionBuild& build) const;
|
489
|
+
|
490
|
+
/// Finds this program in current build and updates internal m_data to point at it.
|
491
|
+
void store_built_data(SlangSessionBuild& build);
|
492
|
+
|
493
|
+
const ShaderProgramDesc& desc() const { return m_desc; }
|
494
|
+
|
495
|
+
ref<const ProgramLayout> layout() const
|
496
|
+
{
|
497
|
+
return ProgramLayout::from_slang(ref(this), m_data->linked_program->getLayout());
|
498
|
+
}
|
499
|
+
|
500
|
+
ReflectionCursor reflection() const { return ReflectionCursor(this); }
|
501
|
+
|
502
|
+
gfx::IShaderProgram* gfx_shader_program() const { return m_data->gfx_shader_program; }
|
503
|
+
|
504
|
+
virtual std::string to_string() const override;
|
505
|
+
|
506
|
+
void _register_pipeline(Pipeline* pipeline);
|
507
|
+
void _unregister_pipeline(Pipeline* pipeline);
|
508
|
+
|
509
|
+
private:
|
510
|
+
ref<SlangSession> m_session;
|
511
|
+
ShaderProgramDesc m_desc;
|
512
|
+
ref<ShaderProgramData> m_data;
|
513
|
+
std::set<Pipeline*> m_registered_pipelines;
|
514
|
+
};
|
515
|
+
|
516
|
+
} // namespace sgl
|
@@ -0,0 +1,85 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/device/fwd.h"
|
6
|
+
#include "sgl/device/shader_offset.h"
|
7
|
+
#include "sgl/device/reflection.h"
|
8
|
+
#include "sgl/device/cursor_utils.h"
|
9
|
+
|
10
|
+
#include "sgl/core/config.h"
|
11
|
+
#include "sgl/core/macros.h"
|
12
|
+
|
13
|
+
#include <string_view>
|
14
|
+
|
15
|
+
namespace sgl {
|
16
|
+
|
17
|
+
class SGL_API ShaderCursor {
|
18
|
+
public:
|
19
|
+
ShaderCursor() = default;
|
20
|
+
|
21
|
+
ShaderCursor(ShaderObject* shader_object);
|
22
|
+
|
23
|
+
ShaderOffset offset() const { return m_offset; }
|
24
|
+
|
25
|
+
bool is_valid() const { return m_offset.is_valid(); }
|
26
|
+
|
27
|
+
std::string to_string() const;
|
28
|
+
|
29
|
+
ShaderCursor dereference() const;
|
30
|
+
|
31
|
+
ref<const TypeLayoutReflection> type_layout() const { return m_type_layout; }
|
32
|
+
ref<const TypeReflection> type() const { return m_type_layout->type(); }
|
33
|
+
|
34
|
+
//
|
35
|
+
// Navigation
|
36
|
+
//
|
37
|
+
|
38
|
+
ShaderCursor operator[](std::string_view name) const;
|
39
|
+
ShaderCursor operator[](uint32_t index) const;
|
40
|
+
|
41
|
+
ShaderCursor find_field(std::string_view name) const;
|
42
|
+
ShaderCursor find_element(uint32_t index) const;
|
43
|
+
|
44
|
+
ShaderCursor find_entry_point(uint32_t index) const;
|
45
|
+
|
46
|
+
bool has_field(std::string_view name) const { return find_field(name).is_valid(); }
|
47
|
+
bool has_element(uint32_t index) const { return find_element(index).is_valid(); }
|
48
|
+
|
49
|
+
//
|
50
|
+
// Resource binding
|
51
|
+
//
|
52
|
+
|
53
|
+
void set_object(const ref<MutableShaderObject>& object) const;
|
54
|
+
|
55
|
+
void set_resource(const ref<ResourceView>& resource_view) const;
|
56
|
+
void set_buffer(const ref<Buffer>& buffer) const;
|
57
|
+
void set_texture(const ref<Texture>& texture) const;
|
58
|
+
void set_sampler(const ref<Sampler>& sampler) const;
|
59
|
+
void set_acceleration_structure(const ref<AccelerationStructure>& acceleration_structure) const;
|
60
|
+
|
61
|
+
void set_data(const void* data, size_t size) const;
|
62
|
+
|
63
|
+
void set_cuda_tensor_view(const cuda::TensorView& tensor_view) const;
|
64
|
+
|
65
|
+
template<typename T>
|
66
|
+
void operator=(const T& value) const
|
67
|
+
{
|
68
|
+
set(value);
|
69
|
+
}
|
70
|
+
|
71
|
+
template<typename T>
|
72
|
+
void set(const T& value) const;
|
73
|
+
|
74
|
+
void _set_array(const void* data, size_t size, TypeReflection::ScalarType scalar_type, size_t element_count) const;
|
75
|
+
void _set_scalar(const void* data, size_t size, TypeReflection::ScalarType scalar_type) const;
|
76
|
+
void _set_vector(const void* data, size_t size, TypeReflection::ScalarType scalar_type, int dimension) const;
|
77
|
+
void _set_matrix(const void* data, size_t size, TypeReflection::ScalarType scalar_type, int rows, int cols) const;
|
78
|
+
|
79
|
+
private:
|
80
|
+
ref<const TypeLayoutReflection> m_type_layout;
|
81
|
+
ShaderObject* m_shader_object{nullptr};
|
82
|
+
ShaderOffset m_offset;
|
83
|
+
};
|
84
|
+
|
85
|
+
} // namespace sgl
|