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,366 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include <vector>
|
6
|
+
#include <map>
|
7
|
+
|
8
|
+
#include "nanobind.h"
|
9
|
+
|
10
|
+
#include "sgl/core/macros.h"
|
11
|
+
#include "sgl/core/fwd.h"
|
12
|
+
#include "sgl/core/object.h"
|
13
|
+
#include "sgl/device/fwd.h"
|
14
|
+
#include "sgl/utils/slangpy.h"
|
15
|
+
|
16
|
+
namespace sgl::slangpy {
|
17
|
+
|
18
|
+
class NativeBoundVariableRuntime;
|
19
|
+
|
20
|
+
/// General exception that includes a message and the bound variable from which the error
|
21
|
+
/// originated.
|
22
|
+
class NativeBoundVariableException : public std::exception {
|
23
|
+
public:
|
24
|
+
NativeBoundVariableException(std::string_view message, ref<NativeBoundVariableRuntime> source = nullptr)
|
25
|
+
: m_message(message)
|
26
|
+
, m_source(std::move(source))
|
27
|
+
{
|
28
|
+
}
|
29
|
+
|
30
|
+
virtual const char* what() const noexcept override { return m_message.c_str(); }
|
31
|
+
|
32
|
+
std::string_view message() const { return m_message; }
|
33
|
+
ref<NativeBoundVariableRuntime> source() const { return m_source; }
|
34
|
+
|
35
|
+
private:
|
36
|
+
std::string m_message;
|
37
|
+
ref<NativeBoundVariableRuntime> m_source;
|
38
|
+
};
|
39
|
+
|
40
|
+
/// Base class for a marshal to a slangpy supported type.
|
41
|
+
class NativeType : public Object {
|
42
|
+
public:
|
43
|
+
virtual ~NativeType() = default;
|
44
|
+
|
45
|
+
/// Get the name of the type (eg 'int', 'vector<float,3>', 'Foo').
|
46
|
+
std::string_view name() const { return m_name; }
|
47
|
+
|
48
|
+
/// Set the name of the type
|
49
|
+
void set_name(std::string_view name) { m_name = name; }
|
50
|
+
|
51
|
+
/// Get the element type (eg vector<float,3> -> float).
|
52
|
+
ref<NativeType> element_type() const { return m_element_type; }
|
53
|
+
|
54
|
+
/// Set the element type.
|
55
|
+
void set_element_type(ref<NativeType> element_type) { m_element_type = std::move(element_type); }
|
56
|
+
|
57
|
+
/// Get the concrete shape of the type. For none-concrete types such as buffers,
|
58
|
+
/// this will return an invalid shape.
|
59
|
+
Shape concrete_shape() const { return m_concrete_shape; }
|
60
|
+
|
61
|
+
/// Set the concrete shape of the type.
|
62
|
+
void set_concrete_shape(const Shape& concrete_shape) { m_concrete_shape = concrete_shape; }
|
63
|
+
|
64
|
+
/// Calculate size in bytes of a value of this type.
|
65
|
+
virtual int get_byte_size(nb::object value) const
|
66
|
+
{
|
67
|
+
SGL_UNUSED(value);
|
68
|
+
return 0;
|
69
|
+
}
|
70
|
+
|
71
|
+
/// Get the container shape when it is a container type (eg buffer, array, etc).
|
72
|
+
/// This does not include the shape of the element type, so a float3[10] array
|
73
|
+
/// would return a shape of [10]. This is typically only called from get_shape
|
74
|
+
/// and is only required if a concrete shape has not been set.
|
75
|
+
virtual Shape get_container_shape(nb::object value) const
|
76
|
+
{
|
77
|
+
SGL_UNUSED(value);
|
78
|
+
return Shape(std::vector<int>());
|
79
|
+
}
|
80
|
+
|
81
|
+
/// Get the full shape of the type. This includes the container shape and the
|
82
|
+
/// shape of the element type. Returns the concrete shape if set, or calculates
|
83
|
+
/// the shape from the element type and container shape if not.
|
84
|
+
virtual Shape get_shape(nb::object value) const
|
85
|
+
{
|
86
|
+
if (m_concrete_shape.valid())
|
87
|
+
return m_concrete_shape;
|
88
|
+
|
89
|
+
auto et = element_type();
|
90
|
+
if (!et) {
|
91
|
+
return get_container_shape(value);
|
92
|
+
} else {
|
93
|
+
return get_container_shape(value) + element_type()->get_shape(value);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
/// Create call data (uniform values) to be passed to a compute kernel.
|
98
|
+
virtual nb::object create_calldata(CallContext* context, NativeBoundVariableRuntime* binding, nb::object data) const
|
99
|
+
{
|
100
|
+
SGL_UNUSED(context);
|
101
|
+
SGL_UNUSED(binding);
|
102
|
+
SGL_UNUSED(data);
|
103
|
+
return nb::none();
|
104
|
+
}
|
105
|
+
|
106
|
+
/// Optionally reads back changes from call data after a kernel has been executed.
|
107
|
+
virtual void
|
108
|
+
read_calldata(CallContext* context, NativeBoundVariableRuntime* binding, nb::object data, nb::object result) const
|
109
|
+
{
|
110
|
+
SGL_UNUSED(context);
|
111
|
+
SGL_UNUSED(binding);
|
112
|
+
SGL_UNUSED(data);
|
113
|
+
SGL_UNUSED(result);
|
114
|
+
}
|
115
|
+
|
116
|
+
/// For types that can be used to return data from a kernel, allocate
|
117
|
+
/// an instance of the correct size to match the call context.
|
118
|
+
virtual nb::object create_output(CallContext* context, NativeBoundVariableRuntime* binding) const
|
119
|
+
{
|
120
|
+
SGL_UNUSED(context);
|
121
|
+
SGL_UNUSED(binding);
|
122
|
+
return nb::none();
|
123
|
+
};
|
124
|
+
|
125
|
+
/// For types that can create_output, read the data allocated in create_output and
|
126
|
+
/// return the python object to be provided to the user.
|
127
|
+
virtual nb::object read_output(CallContext* context, NativeBoundVariableRuntime* binding, nb::object data) const
|
128
|
+
{
|
129
|
+
SGL_UNUSED(context);
|
130
|
+
SGL_UNUSED(binding);
|
131
|
+
SGL_UNUSED(data);
|
132
|
+
return nb::none();
|
133
|
+
};
|
134
|
+
|
135
|
+
private:
|
136
|
+
std::string m_name;
|
137
|
+
ref<NativeType> m_element_type;
|
138
|
+
Shape m_concrete_shape;
|
139
|
+
};
|
140
|
+
|
141
|
+
/// Nanobind trampoline class for NativeType
|
142
|
+
struct PyNativeType : public NativeType {
|
143
|
+
NB_TRAMPOLINE(NativeType, 9);
|
144
|
+
|
145
|
+
int get_byte_size(nb::object value) const override { NB_OVERRIDE(get_byte_size, value); }
|
146
|
+
|
147
|
+
Shape get_container_shape(nb::object value) const override { NB_OVERRIDE(get_container_shape, value); }
|
148
|
+
|
149
|
+
Shape get_shape(nb::object value) const override { NB_OVERRIDE(get_shape, value); }
|
150
|
+
|
151
|
+
nb::object
|
152
|
+
create_calldata(CallContext* context, NativeBoundVariableRuntime* binding, nb::object data) const override
|
153
|
+
{
|
154
|
+
NB_OVERRIDE(create_calldata, context, binding, data);
|
155
|
+
}
|
156
|
+
|
157
|
+
void read_calldata(CallContext* context, NativeBoundVariableRuntime* binding, nb::object data, nb::object result)
|
158
|
+
const override
|
159
|
+
{
|
160
|
+
NB_OVERRIDE(read_calldata, context, binding, data, result);
|
161
|
+
}
|
162
|
+
|
163
|
+
nb::object create_output(CallContext* context, NativeBoundVariableRuntime* binding) const override
|
164
|
+
{
|
165
|
+
NB_OVERRIDE(create_output, context, binding);
|
166
|
+
}
|
167
|
+
nb::object read_output(CallContext* context, NativeBoundVariableRuntime* binding, nb::object data) const override
|
168
|
+
{
|
169
|
+
NB_OVERRIDE(read_output, context, binding, data);
|
170
|
+
}
|
171
|
+
};
|
172
|
+
|
173
|
+
/// Binding information that links a python argument to a slang parameter. In
|
174
|
+
/// the case of structs, this can be nested, mapping python dictionary fields to
|
175
|
+
/// slang struct fields.
|
176
|
+
class NativeBoundVariableRuntime : public Object {
|
177
|
+
public:
|
178
|
+
NativeBoundVariableRuntime() = default;
|
179
|
+
|
180
|
+
/// Get required access for primal and derivative.
|
181
|
+
std::pair<AccessType, AccessType> get_access() const { return m_access; }
|
182
|
+
|
183
|
+
/// Set required access for primal and derivative.
|
184
|
+
void set_access(const std::pair<AccessType, AccessType>& access) { m_access = access; }
|
185
|
+
|
186
|
+
/// Get the call transform.
|
187
|
+
Shape get_transform() const { return m_transform; }
|
188
|
+
|
189
|
+
/// Set the call transform.
|
190
|
+
void set_transform(const Shape& transform) { m_transform = transform; }
|
191
|
+
|
192
|
+
/// Get the python type marshal.
|
193
|
+
ref<NativeType> get_python_type() const { return m_python_type; }
|
194
|
+
|
195
|
+
/// Set the python type marshal.
|
196
|
+
void set_python_type(const ref<NativeType>& python_type) { m_python_type = python_type; }
|
197
|
+
|
198
|
+
/// Get the shape being used for the current call.
|
199
|
+
Shape get_shape() const { return m_shape; }
|
200
|
+
|
201
|
+
/// Set the shape being used for the current call.
|
202
|
+
void set_shape(const Shape& shape) { m_shape = shape; }
|
203
|
+
|
204
|
+
/// Get the uniform variable name.
|
205
|
+
std::string_view get_variable_name() const { return m_variable_name; }
|
206
|
+
|
207
|
+
/// Set the uniform variable name.
|
208
|
+
void set_variable_name(std::string_view variable_name) { m_variable_name = variable_name; }
|
209
|
+
|
210
|
+
/// Get children (for structs).
|
211
|
+
std::optional<std::map<std::string, ref<NativeBoundVariableRuntime>>> get_children() const { return m_children; }
|
212
|
+
|
213
|
+
/// Set children (for structs).
|
214
|
+
void set_children(const std::optional<std::map<std::string, ref<NativeBoundVariableRuntime>>>& children)
|
215
|
+
{
|
216
|
+
m_children = children;
|
217
|
+
}
|
218
|
+
|
219
|
+
/// Recursively populate the overall kernel call shape.
|
220
|
+
void populate_call_shape(std::vector<int>& call_shape, nb::object value);
|
221
|
+
|
222
|
+
/// Write call data to be passed to a compute kernel by calling create_calldata on the marshal.
|
223
|
+
void write_call_data_pre_dispatch(CallContext* context, nb::dict call_data, nb::object value);
|
224
|
+
|
225
|
+
/// Read back changes from call data after a kernel has been executed by calling read_calldata on the marshal.
|
226
|
+
void read_call_data_post_dispatch(CallContext* context, nb::dict call_data, nb::object value);
|
227
|
+
|
228
|
+
/// Read output data from a compute kernel by calling read_output on the marshal.
|
229
|
+
nb::object read_output(CallContext* context, nb::object data);
|
230
|
+
|
231
|
+
private:
|
232
|
+
std::pair<AccessType, AccessType> m_access{AccessType::none, AccessType::none};
|
233
|
+
Shape m_transform;
|
234
|
+
ref<NativeType> m_python_type;
|
235
|
+
Shape m_shape;
|
236
|
+
std::string m_variable_name;
|
237
|
+
std::optional<std::map<std::string, ref<NativeBoundVariableRuntime>>> m_children;
|
238
|
+
};
|
239
|
+
|
240
|
+
/// Binding information for a call to a compute kernel. Includes a set of positional
|
241
|
+
/// and keyword arguments as bound variables.
|
242
|
+
class NativeBoundCallRuntime : Object {
|
243
|
+
public:
|
244
|
+
NativeBoundCallRuntime() = default;
|
245
|
+
|
246
|
+
/// Get positional arguments.
|
247
|
+
const std::vector<ref<NativeBoundVariableRuntime>>& get_args() const { return m_args; }
|
248
|
+
|
249
|
+
/// Set positional arguments.
|
250
|
+
void set_args(const std::vector<ref<NativeBoundVariableRuntime>>& args) { m_args = args; }
|
251
|
+
|
252
|
+
/// Get keyword arguments.
|
253
|
+
const std::map<std::string, ref<NativeBoundVariableRuntime>>& get_kwargs() const { return m_kwargs; }
|
254
|
+
|
255
|
+
/// Set keyword arguments.
|
256
|
+
void set_kwargs(const std::map<std::string, ref<NativeBoundVariableRuntime>>& kwargs) { m_kwargs = kwargs; }
|
257
|
+
|
258
|
+
/// Find a keyword argument by name.
|
259
|
+
ref<NativeBoundVariableRuntime> find_kwarg(const char* name) const
|
260
|
+
{
|
261
|
+
auto it = m_kwargs.find(name);
|
262
|
+
if (it == m_kwargs.end()) {
|
263
|
+
return nullptr;
|
264
|
+
}
|
265
|
+
return it->second;
|
266
|
+
}
|
267
|
+
|
268
|
+
/// Calculate the overall call shape by combining the shapes of all arguments.
|
269
|
+
Shape calculate_call_shape(int call_dimensionality, nb::list args, nb::dict kwargs);
|
270
|
+
|
271
|
+
/// Write call data to be passed to a compute kernel by calling create_calldata on the argument marshals.
|
272
|
+
void write_calldata_pre_dispatch(CallContext* context, nb::dict call_data, nb::list args, nb::dict kwargs);
|
273
|
+
|
274
|
+
/// Read back changes from call data after a kernel has been executed by calling read_calldata on the argument
|
275
|
+
/// marshals.
|
276
|
+
void read_call_data_post_dispatch(CallContext* context, nb::dict call_data, nb::list args, nb::dict kwargs);
|
277
|
+
|
278
|
+
private:
|
279
|
+
std::vector<ref<NativeBoundVariableRuntime>> m_args;
|
280
|
+
std::map<std::string, ref<NativeBoundVariableRuntime>> m_kwargs;
|
281
|
+
};
|
282
|
+
|
283
|
+
/// Contains the compute kernel for a call, the corresponding bindings and any additional
|
284
|
+
/// options provided by the user.
|
285
|
+
class NativeCallData : Object {
|
286
|
+
public:
|
287
|
+
NativeCallData() = default;
|
288
|
+
|
289
|
+
/// Get the device.
|
290
|
+
ref<Device> get_device() const { return m_device; }
|
291
|
+
|
292
|
+
/// Set the device.
|
293
|
+
void set_device(const ref<Device>& device) { m_device = device; }
|
294
|
+
|
295
|
+
/// Get the compute kernel.
|
296
|
+
ref<ComputeKernel> get_kernel() const { return m_kernel; }
|
297
|
+
|
298
|
+
/// Set the compute kernel.
|
299
|
+
void set_kernel(const ref<ComputeKernel>& kernel) { m_kernel = kernel; }
|
300
|
+
|
301
|
+
/// Get the call dimensionality.
|
302
|
+
int get_call_dimensionality() const { return m_call_dimensionality; }
|
303
|
+
|
304
|
+
/// Set the call dimensionality.
|
305
|
+
void set_call_dimensionality(int call_dimensionality) { m_call_dimensionality = call_dimensionality; }
|
306
|
+
|
307
|
+
/// Get the runtime bindings.
|
308
|
+
ref<NativeBoundCallRuntime> get_runtime() const { return m_runtime; }
|
309
|
+
|
310
|
+
/// Set the runtime bindings.
|
311
|
+
void set_runtime(const ref<NativeBoundCallRuntime>& runtime) { m_runtime = runtime; }
|
312
|
+
|
313
|
+
/// Get user provided uniforms.
|
314
|
+
const nb::dict& get_vars() const { return m_vars; }
|
315
|
+
|
316
|
+
/// Set user provided uniforms.
|
317
|
+
void set_vars(const nb::dict& vars) { m_vars = vars; }
|
318
|
+
|
319
|
+
/// Get the call mode (primitive/forward/backward).
|
320
|
+
CallMode get_call_mode() const { return m_call_mode; }
|
321
|
+
|
322
|
+
/// Set the call mode (primitive/forward/backward).
|
323
|
+
void set_call_mode(CallMode call_mode) { m_call_mode = call_mode; }
|
324
|
+
|
325
|
+
/// Add a hook to be called before dispatching or appending the kernel.
|
326
|
+
void add_before_dispatch_hook(const std::function<void(nb::dict)>& hook)
|
327
|
+
{
|
328
|
+
m_before_dispatch_hooks.push_back(hook);
|
329
|
+
}
|
330
|
+
|
331
|
+
/// Add a hook to be called after dispatching the kernel. Not valid
|
332
|
+
/// for append_to.
|
333
|
+
void add_after_dispatch_hooks(const std::function<void(nb::dict)>& hook) { m_after_dispatch_hooks.push_back(hook); }
|
334
|
+
|
335
|
+
/// Get the shape of the last call (useful for debugging).
|
336
|
+
const Shape& get_last_call_shape() const { return m_last_call_shape; }
|
337
|
+
|
338
|
+
/// Call the compute kernel with the provided arguments and keyword arguments.
|
339
|
+
nb::object call(nb::args args, nb::kwargs kwargs);
|
340
|
+
|
341
|
+
/// Append the compute kernel to a command buffer with the provided arguments and keyword arguments.
|
342
|
+
nb::object append_to(ref<CommandBuffer> command_buffer, nb::args args, nb::kwargs kwargs);
|
343
|
+
|
344
|
+
private:
|
345
|
+
ref<Device> m_device;
|
346
|
+
ref<ComputeKernel> m_kernel;
|
347
|
+
int m_call_dimensionality{0};
|
348
|
+
ref<NativeBoundCallRuntime> m_runtime;
|
349
|
+
nb::dict m_vars;
|
350
|
+
CallMode m_call_mode{CallMode::prim};
|
351
|
+
std::vector<std::function<void(nb::dict)>> m_before_dispatch_hooks;
|
352
|
+
std::vector<std::function<void(nb::dict)>> m_after_dispatch_hooks;
|
353
|
+
Shape m_last_call_shape;
|
354
|
+
|
355
|
+
nb::object exec(CommandBuffer* command_buffer, nb::args args, nb::kwargs kwargs);
|
356
|
+
|
357
|
+
nb::list unpack_args(nb::args args);
|
358
|
+
|
359
|
+
nb::dict unpack_kwargs(nb::kwargs kwargs);
|
360
|
+
|
361
|
+
nb::object unpack_arg(nanobind::object arg);
|
362
|
+
|
363
|
+
void pack_arg(nb::object arg, nb::object unpacked_arg);
|
364
|
+
};
|
365
|
+
|
366
|
+
} // namespace sgl::slangpy
|
@@ -0,0 +1,50 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/macros.h"
|
6
|
+
#include "sgl/core/fwd.h"
|
7
|
+
#include "sgl/device/fwd.h"
|
8
|
+
|
9
|
+
namespace sgl::renderdoc {
|
10
|
+
|
11
|
+
/**
|
12
|
+
* \brief Check if RenderDoc is available.
|
13
|
+
*
|
14
|
+
* This is typically the case when the application is running under the RenderDoc.
|
15
|
+
*
|
16
|
+
* \return True if RenderDoc is available.
|
17
|
+
*/
|
18
|
+
SGL_API bool is_available();
|
19
|
+
|
20
|
+
/**
|
21
|
+
* \brief Start capturing a frame in RenderDoc.
|
22
|
+
*
|
23
|
+
* This function will start capturing a frame (or some partial compute/graphics workload) in RenderDoc.
|
24
|
+
*
|
25
|
+
* To end the frame capture, call \c end_frame_capture().
|
26
|
+
*
|
27
|
+
* \param device The device to capture the frame for.
|
28
|
+
* \param window The window to capture the frame for (optional).
|
29
|
+
*
|
30
|
+
* \return True if the frame capture was started successfully.
|
31
|
+
*/
|
32
|
+
SGL_API bool start_frame_capture(ref<Device> device, ref<Window> window = nullptr);
|
33
|
+
|
34
|
+
/**
|
35
|
+
* \brief End capturing a frame in RenderDoc.
|
36
|
+
*
|
37
|
+
* This function will end capturing a frame (or some partial compute/graphics workload) in RenderDoc.
|
38
|
+
*
|
39
|
+
* \return True if the frame capture was ended successfully.
|
40
|
+
*/
|
41
|
+
SGL_API bool end_frame_capture();
|
42
|
+
|
43
|
+
/**
|
44
|
+
* \brief Check if a frame is currently being captured in RenderDoc.
|
45
|
+
*
|
46
|
+
* \return True if a frame is currently being captured.
|
47
|
+
*/
|
48
|
+
SGL_API bool is_frame_capturing();
|
49
|
+
|
50
|
+
} // namespace sgl::renderdoc
|
@@ -0,0 +1,153 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/macros.h"
|
6
|
+
#include "sgl/core/fwd.h"
|
7
|
+
#include "sgl/core/object.h"
|
8
|
+
#include "sgl/core/enum.h"
|
9
|
+
#include "sgl/device/fwd.h"
|
10
|
+
|
11
|
+
#include <vector>
|
12
|
+
#include <map>
|
13
|
+
|
14
|
+
namespace sgl::slangpy {
|
15
|
+
|
16
|
+
enum class AccessType {
|
17
|
+
none,
|
18
|
+
read,
|
19
|
+
write,
|
20
|
+
readwrite,
|
21
|
+
};
|
22
|
+
|
23
|
+
SGL_ENUM_INFO(
|
24
|
+
AccessType,
|
25
|
+
{
|
26
|
+
{AccessType::none, "none"},
|
27
|
+
{AccessType::read, "read"},
|
28
|
+
{AccessType::write, "write"},
|
29
|
+
{AccessType::readwrite, "readwrite"},
|
30
|
+
}
|
31
|
+
);
|
32
|
+
SGL_ENUM_REGISTER(AccessType);
|
33
|
+
|
34
|
+
enum class CallMode { prim = 0, bwds = 1, fwds = 2 };
|
35
|
+
SGL_ENUM_INFO(
|
36
|
+
CallMode,
|
37
|
+
{
|
38
|
+
{CallMode::prim, "prim"},
|
39
|
+
{CallMode::bwds, "bwds"},
|
40
|
+
{CallMode::fwds, "fwds"},
|
41
|
+
}
|
42
|
+
);
|
43
|
+
SGL_ENUM_REGISTER(CallMode);
|
44
|
+
|
45
|
+
|
46
|
+
class SGL_API Shape {
|
47
|
+
public:
|
48
|
+
Shape() = default;
|
49
|
+
|
50
|
+
/// Constructor from optional 'tuple'.
|
51
|
+
Shape(const std::optional<std::vector<int>>& shape)
|
52
|
+
: m_shape(shape)
|
53
|
+
{
|
54
|
+
}
|
55
|
+
|
56
|
+
/// Copy constructor.
|
57
|
+
Shape(const Shape& other)
|
58
|
+
: m_shape(other.m_shape)
|
59
|
+
{
|
60
|
+
}
|
61
|
+
|
62
|
+
/// Move constructor.
|
63
|
+
Shape(Shape&& other) noexcept
|
64
|
+
: m_shape(std::move(other.m_shape))
|
65
|
+
{
|
66
|
+
}
|
67
|
+
|
68
|
+
/// Add operator combines the 2 shapes.
|
69
|
+
Shape operator+(const Shape& other) const
|
70
|
+
{
|
71
|
+
auto& this_vec = as_vector();
|
72
|
+
auto& other_vec = other.as_vector();
|
73
|
+
std::vector<int> combined = this_vec;
|
74
|
+
combined.insert(combined.end(), other_vec.begin(), other_vec.end());
|
75
|
+
return Shape(combined);
|
76
|
+
}
|
77
|
+
|
78
|
+
/// Assignment operator.
|
79
|
+
Shape& operator=(const Shape& other)
|
80
|
+
{
|
81
|
+
m_shape = other.m_shape;
|
82
|
+
return *this;
|
83
|
+
}
|
84
|
+
|
85
|
+
/// Indexers.
|
86
|
+
int operator[](size_t i) const { return as_vector()[i]; }
|
87
|
+
int& operator[](size_t i) { return as_vector()[i]; }
|
88
|
+
|
89
|
+
/// Access to internal vector.
|
90
|
+
std::vector<int>& as_vector()
|
91
|
+
{
|
92
|
+
if (!m_shape) {
|
93
|
+
SGL_THROW("Shape is invalid");
|
94
|
+
}
|
95
|
+
return *m_shape;
|
96
|
+
}
|
97
|
+
|
98
|
+
/// Const access to internal vector.
|
99
|
+
const std::vector<int>& as_vector() const
|
100
|
+
{
|
101
|
+
if (!m_shape) {
|
102
|
+
SGL_THROW("Shape is invalid");
|
103
|
+
}
|
104
|
+
return *m_shape;
|
105
|
+
}
|
106
|
+
|
107
|
+
/// Check if shape is valid (if the std::optional has a value).
|
108
|
+
bool valid() const { return m_shape.has_value(); }
|
109
|
+
|
110
|
+
/// Get size (i.e. number of dimensions) of shape.
|
111
|
+
size_t size() const { return as_vector().size(); }
|
112
|
+
|
113
|
+
/// Check if concrete shape (no dimensions are -1).
|
114
|
+
bool concrete() const
|
115
|
+
{
|
116
|
+
for (auto dim : as_vector()) {
|
117
|
+
if (dim == -1) {
|
118
|
+
return false;
|
119
|
+
}
|
120
|
+
}
|
121
|
+
return true;
|
122
|
+
}
|
123
|
+
|
124
|
+
/// Convert to string
|
125
|
+
std::string to_string() const
|
126
|
+
{
|
127
|
+
if (!m_shape) {
|
128
|
+
return "[invalid]";
|
129
|
+
}
|
130
|
+
return fmt::format("[{}]", fmt::join(as_vector(), ", "));
|
131
|
+
}
|
132
|
+
|
133
|
+
private:
|
134
|
+
std::optional<std::vector<int>> m_shape;
|
135
|
+
};
|
136
|
+
|
137
|
+
class SGL_API CallContext : Object {
|
138
|
+
public:
|
139
|
+
CallContext(ref<Device> device, const Shape& call_shape)
|
140
|
+
: m_device(std::move(device))
|
141
|
+
, m_call_shape(call_shape)
|
142
|
+
{
|
143
|
+
}
|
144
|
+
|
145
|
+
Device* device() const { return m_device.get(); }
|
146
|
+
const Shape& call_shape() const { return m_call_shape; }
|
147
|
+
|
148
|
+
private:
|
149
|
+
ref<Device> m_device;
|
150
|
+
Shape m_call_shape;
|
151
|
+
};
|
152
|
+
|
153
|
+
} // namespace sgl::slangpy
|
@@ -0,0 +1,93 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/macros.h"
|
6
|
+
#include "sgl/core/fwd.h"
|
7
|
+
|
8
|
+
#include "sgl/device/fwd.h"
|
9
|
+
|
10
|
+
#include <string>
|
11
|
+
#include <cstdint>
|
12
|
+
|
13
|
+
namespace sgl::tev {
|
14
|
+
|
15
|
+
/**
|
16
|
+
* \brief Show a bitmap in the tev viewer (https://github.com/Tom94/tev).
|
17
|
+
*
|
18
|
+
* This will block until the image is sent over.
|
19
|
+
*
|
20
|
+
* \param bitmap Bitmap to show.
|
21
|
+
* \param name Name of the image in tev. If not specified, a unique name will be generated.
|
22
|
+
* \param host Host to connect to.
|
23
|
+
* \param port Port to connect to.
|
24
|
+
* \param max_retries Maximum number of retries.
|
25
|
+
* \return True if successful.
|
26
|
+
*/
|
27
|
+
SGL_API bool show(
|
28
|
+
const Bitmap* bitmap,
|
29
|
+
std::string name = "",
|
30
|
+
std::string host = "127.0.0.1",
|
31
|
+
uint16_t port = 14158,
|
32
|
+
uint32_t max_retries = 3
|
33
|
+
);
|
34
|
+
|
35
|
+
/**
|
36
|
+
* \brief Show texture in the tev viewer (https://github.com/Tom94/tev).
|
37
|
+
*
|
38
|
+
* This will block until the image is sent over.
|
39
|
+
*
|
40
|
+
* \param texture Texture to show.
|
41
|
+
* \param name Name of the image in tev. If not specified, a unique name will be generated.
|
42
|
+
* \param host Host to connect to.
|
43
|
+
* \param port Port to connect to.
|
44
|
+
* \param max_retries Maximum number of retries.
|
45
|
+
* \return True if successful.
|
46
|
+
*/
|
47
|
+
SGL_API bool show(
|
48
|
+
const Texture* texture,
|
49
|
+
std::string name = "",
|
50
|
+
std::string host = "127.0.0.1",
|
51
|
+
uint16_t port = 14158,
|
52
|
+
uint32_t max_retries = 3
|
53
|
+
);
|
54
|
+
|
55
|
+
/**
|
56
|
+
* \brief Show a bitmap in the tev viewer (https://github.com/Tom94/tev).
|
57
|
+
*
|
58
|
+
* This will return immediately and send the image asynchronously in the background.
|
59
|
+
*
|
60
|
+
* \param bitmap Bitmap to show.
|
61
|
+
* \param name Name of the image in tev. If not specified, a unique name will be generated.
|
62
|
+
* \param host Host to connect to.
|
63
|
+
* \param port Port to connect to.
|
64
|
+
* \param max_retries Maximum number of retries.
|
65
|
+
*/
|
66
|
+
SGL_API void show_async(
|
67
|
+
const Bitmap* bitmap,
|
68
|
+
std::string name = "",
|
69
|
+
std::string host = "127.0.0.1",
|
70
|
+
uint16_t port = 14158,
|
71
|
+
uint32_t max_retries = 3
|
72
|
+
);
|
73
|
+
|
74
|
+
/**
|
75
|
+
* \brief Show a texture in the tev viewer (https://github.com/Tom94/tev).
|
76
|
+
*
|
77
|
+
* This will return immediately and send the image asynchronously in the background.
|
78
|
+
*
|
79
|
+
* \param bitmap Texture to show.
|
80
|
+
* \param name Name of the image in tev. If not specified, a unique name will be generated.
|
81
|
+
* \param host Host to connect to.
|
82
|
+
* \param port Port to connect to.
|
83
|
+
* \param max_retries Maximum number of retries.
|
84
|
+
*/
|
85
|
+
SGL_API void show_async(
|
86
|
+
const Texture* texture,
|
87
|
+
std::string name = "",
|
88
|
+
std::string host = "127.0.0.1",
|
89
|
+
uint16_t port = 14158,
|
90
|
+
uint32_t max_retries = 3
|
91
|
+
);
|
92
|
+
|
93
|
+
} // namespace sgl::tev
|