nv-sgl 0.6.0__cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. include/tevclient.h +393 -0
  2. nv_sgl-0.6.0.dist-info/LICENSE +29 -0
  3. nv_sgl-0.6.0.dist-info/METADATA +21 -0
  4. nv_sgl-0.6.0.dist-info/RECORD +133 -0
  5. nv_sgl-0.6.0.dist-info/WHEEL +6 -0
  6. nv_sgl-0.6.0.dist-info/top_level.txt +1 -0
  7. sgl/__init__.py +15 -0
  8. sgl/__init__.pyi +6738 -0
  9. sgl/include/sgl/app/app.h +113 -0
  10. sgl/include/sgl/core/bitmap.h +302 -0
  11. sgl/include/sgl/core/crypto.h +89 -0
  12. sgl/include/sgl/core/data_type.h +46 -0
  13. sgl/include/sgl/core/dds_file.h +103 -0
  14. sgl/include/sgl/core/enum.h +201 -0
  15. sgl/include/sgl/core/error.h +161 -0
  16. sgl/include/sgl/core/file_stream.h +77 -0
  17. sgl/include/sgl/core/file_system_watcher.h +141 -0
  18. sgl/include/sgl/core/format.h +36 -0
  19. sgl/include/sgl/core/fwd.h +90 -0
  20. sgl/include/sgl/core/hash.h +45 -0
  21. sgl/include/sgl/core/input.h +522 -0
  22. sgl/include/sgl/core/logger.h +214 -0
  23. sgl/include/sgl/core/macros.h +184 -0
  24. sgl/include/sgl/core/maths.h +45 -0
  25. sgl/include/sgl/core/memory_mapped_file.h +112 -0
  26. sgl/include/sgl/core/memory_mapped_file_stream.h +32 -0
  27. sgl/include/sgl/core/memory_stream.h +74 -0
  28. sgl/include/sgl/core/object.h +683 -0
  29. sgl/include/sgl/core/platform.h +239 -0
  30. sgl/include/sgl/core/plugin.h +331 -0
  31. sgl/include/sgl/core/resolver.h +39 -0
  32. sgl/include/sgl/core/short_vector.h +141 -0
  33. sgl/include/sgl/core/static_vector.h +111 -0
  34. sgl/include/sgl/core/stream.h +54 -0
  35. sgl/include/sgl/core/string.h +276 -0
  36. sgl/include/sgl/core/struct.h +360 -0
  37. sgl/include/sgl/core/thread.h +28 -0
  38. sgl/include/sgl/core/timer.h +52 -0
  39. sgl/include/sgl/core/traits.h +15 -0
  40. sgl/include/sgl/core/type_utils.h +19 -0
  41. sgl/include/sgl/core/window.h +177 -0
  42. sgl/include/sgl/device/agility_sdk.h +24 -0
  43. sgl/include/sgl/device/blit.h +88 -0
  44. sgl/include/sgl/device/buffer_cursor.h +162 -0
  45. sgl/include/sgl/device/command.h +539 -0
  46. sgl/include/sgl/device/cuda_api.h +766 -0
  47. sgl/include/sgl/device/cuda_interop.h +39 -0
  48. sgl/include/sgl/device/cuda_utils.h +107 -0
  49. sgl/include/sgl/device/cursor_utils.h +129 -0
  50. sgl/include/sgl/device/device.h +668 -0
  51. sgl/include/sgl/device/device_resource.h +37 -0
  52. sgl/include/sgl/device/fence.h +91 -0
  53. sgl/include/sgl/device/formats.h +330 -0
  54. sgl/include/sgl/device/framebuffer.h +85 -0
  55. sgl/include/sgl/device/fwd.h +164 -0
  56. sgl/include/sgl/device/helpers.h +20 -0
  57. sgl/include/sgl/device/hot_reload.h +75 -0
  58. sgl/include/sgl/device/input_layout.h +74 -0
  59. sgl/include/sgl/device/kernel.h +69 -0
  60. sgl/include/sgl/device/memory_heap.h +155 -0
  61. sgl/include/sgl/device/native_formats.h +342 -0
  62. sgl/include/sgl/device/native_handle.h +73 -0
  63. sgl/include/sgl/device/native_handle_traits.h +65 -0
  64. sgl/include/sgl/device/pipeline.h +138 -0
  65. sgl/include/sgl/device/print.h +45 -0
  66. sgl/include/sgl/device/python/cursor_utils.h +853 -0
  67. sgl/include/sgl/device/query.h +52 -0
  68. sgl/include/sgl/device/raytracing.h +84 -0
  69. sgl/include/sgl/device/reflection.h +1254 -0
  70. sgl/include/sgl/device/resource.h +705 -0
  71. sgl/include/sgl/device/sampler.h +57 -0
  72. sgl/include/sgl/device/shader.h +516 -0
  73. sgl/include/sgl/device/shader_cursor.h +85 -0
  74. sgl/include/sgl/device/shader_object.h +94 -0
  75. sgl/include/sgl/device/shader_offset.h +67 -0
  76. sgl/include/sgl/device/shared_handle.h +12 -0
  77. sgl/include/sgl/device/slang_utils.h +54 -0
  78. sgl/include/sgl/device/swapchain.h +74 -0
  79. sgl/include/sgl/device/types.h +782 -0
  80. sgl/include/sgl/math/colorspace.h +56 -0
  81. sgl/include/sgl/math/constants.h +7 -0
  82. sgl/include/sgl/math/float16.h +146 -0
  83. sgl/include/sgl/math/matrix.h +6 -0
  84. sgl/include/sgl/math/matrix_math.h +746 -0
  85. sgl/include/sgl/math/matrix_types.h +207 -0
  86. sgl/include/sgl/math/python/primitivetype.h +33 -0
  87. sgl/include/sgl/math/quaternion.h +6 -0
  88. sgl/include/sgl/math/quaternion_math.h +484 -0
  89. sgl/include/sgl/math/quaternion_types.h +83 -0
  90. sgl/include/sgl/math/ray.h +47 -0
  91. sgl/include/sgl/math/scalar_math.h +249 -0
  92. sgl/include/sgl/math/scalar_types.h +107 -0
  93. sgl/include/sgl/math/vector.h +6 -0
  94. sgl/include/sgl/math/vector_math.h +1796 -0
  95. sgl/include/sgl/math/vector_types.h +336 -0
  96. sgl/include/sgl/python/nanobind.h +489 -0
  97. sgl/include/sgl/python/py_doc.h +11600 -0
  98. sgl/include/sgl/python/sgl_ext_pch.h +8 -0
  99. sgl/include/sgl/sgl.h +21 -0
  100. sgl/include/sgl/sgl_pch.h +6 -0
  101. sgl/include/sgl/stl/bit.h +377 -0
  102. sgl/include/sgl/tests/testing.h +54 -0
  103. sgl/include/sgl/ui/fwd.h +34 -0
  104. sgl/include/sgl/ui/imgui_config.h +43 -0
  105. sgl/include/sgl/ui/ui.h +71 -0
  106. sgl/include/sgl/ui/widgets.h +918 -0
  107. sgl/include/sgl/utils/python/slangpy.h +366 -0
  108. sgl/include/sgl/utils/renderdoc.h +50 -0
  109. sgl/include/sgl/utils/slangpy.h +153 -0
  110. sgl/include/sgl/utils/tev.h +93 -0
  111. sgl/include/sgl/utils/texture_loader.h +106 -0
  112. sgl/libgfx.so +0 -0
  113. sgl/libsgl.so +0 -0
  114. sgl/libslang-glslang.so +0 -0
  115. sgl/libslang.so +0 -0
  116. sgl/libtevclient.a +0 -0
  117. sgl/math/__init__.pyi +5083 -0
  118. sgl/platform/__init__.pyi +102 -0
  119. sgl/renderdoc/__init__.pyi +51 -0
  120. sgl/sgl_ext.cpython-313-x86_64-linux-gnu.so +0 -0
  121. sgl/shaders/sgl/device/blit.slang +93 -0
  122. sgl/shaders/sgl/device/nvapi.slang +5 -0
  123. sgl/shaders/sgl/device/nvapi.slangh +7 -0
  124. sgl/shaders/sgl/device/print.slang +445 -0
  125. sgl/shaders/sgl/math/constants.slang +4 -0
  126. sgl/shaders/sgl/math/ray.slang +29 -0
  127. sgl/shaders/sgl/ui/imgui.slang +49 -0
  128. sgl/slangpy/__init__.pyi +268 -0
  129. sgl/tev/__init__.pyi +108 -0
  130. sgl/thread/__init__.pyi +4 -0
  131. sgl/ui/__init__.pyi +1118 -0
  132. share/cmake/tevclient/tevclient-config-release.cmake +19 -0
  133. share/cmake/tevclient/tevclient-config.cmake +103 -0
@@ -0,0 +1,668 @@
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/native_handle.h"
8
+ #include "sgl/device/resource.h"
9
+ #include "sgl/device/shader.h"
10
+
11
+ #include "sgl/core/fwd.h"
12
+ #include "sgl/core/config.h"
13
+ #include "sgl/core/macros.h"
14
+ #include "sgl/core/enum.h"
15
+ #include "sgl/core/object.h"
16
+ #include "sgl/core/platform.h"
17
+ #include "sgl/math/vector_types.h"
18
+
19
+ #include <slang-gfx.h>
20
+
21
+ #include <array>
22
+ #include <filesystem>
23
+ #include <optional>
24
+ #include <string>
25
+ #include <vector>
26
+ #include <queue>
27
+
28
+ namespace sgl {
29
+
30
+ class DebugPrinter;
31
+
32
+ /// Adapter LUID (locally unique identifier).
33
+ using AdapterLUID = std::array<uint8_t, 16>;
34
+
35
+ struct AdapterInfo {
36
+ /// Descriptive name of the adapter.
37
+ std::string name;
38
+
39
+ /// Unique identifier for the vendor (only available for D3D12 and Vulkan).
40
+ uint32_t vendor_id;
41
+
42
+ /// Unique identifier for the physical device among devices from the vendor (only available for D3D12 and Vulkan).
43
+ uint32_t device_id;
44
+
45
+ /// Logically unique identifier of the adapter.
46
+ AdapterLUID luid;
47
+
48
+ std::string to_string() const
49
+ {
50
+ return fmt::format(
51
+ "AdapterInfo(\n"
52
+ " name = \"{}\",\n"
53
+ " vendor_id = 0x{:x},\n"
54
+ " device_id = 0x{:x},\n"
55
+ " luid = {}\n"
56
+ ")",
57
+ name,
58
+ vendor_id,
59
+ device_id,
60
+ luid
61
+ );
62
+ }
63
+ };
64
+
65
+ enum class DeviceType {
66
+ automatic,
67
+ d3d12,
68
+ vulkan,
69
+ cpu,
70
+ cuda,
71
+ };
72
+
73
+ SGL_ENUM_INFO(
74
+ DeviceType,
75
+ {
76
+ {DeviceType::automatic, "automatic"},
77
+ {DeviceType::d3d12, "d3d12"},
78
+ {DeviceType::vulkan, "vulkan"},
79
+ {DeviceType::cpu, "cpu"},
80
+ {DeviceType::cuda, "cuda"},
81
+ }
82
+ );
83
+ SGL_ENUM_REGISTER(DeviceType);
84
+
85
+ struct DeviceDesc {
86
+ /// The type of the device.
87
+ DeviceType type{DeviceType::automatic};
88
+
89
+ /// Enable debug layers.
90
+ bool enable_debug_layers{false};
91
+
92
+ /// Enable CUDA interoperability.
93
+ bool enable_cuda_interop{false};
94
+
95
+ /// Enable device side printing (adds performance overhead).
96
+ bool enable_print{false};
97
+
98
+ /// Enable automatic shader reload in response to file changes.
99
+ /// Note: Currently windows and linux only.
100
+ bool enable_hot_reload{true};
101
+
102
+ /// Adapter LUID to select adapter on which the device will be created.
103
+ std::optional<AdapterLUID> adapter_luid;
104
+
105
+ /// Compiler options (used for default slang session).
106
+ SlangCompilerOptions compiler_options;
107
+
108
+ /// Path to the shader cache directory (optional).
109
+ /// If a relative path is used, the cache is stored in the application data directory.
110
+ std::optional<std::filesystem::path> shader_cache_path;
111
+ };
112
+
113
+ struct DeviceLimits {
114
+ /// Maximum dimension for 1D textures.
115
+ uint32_t max_texture_dimension_1d;
116
+ /// Maximum dimensions for 2D textures.
117
+ uint32_t max_texture_dimension_2d;
118
+ /// Maximum dimensions for 3D textures.
119
+ uint32_t max_texture_dimension_3d;
120
+ /// Maximum dimensions for cube textures.
121
+ uint32_t max_texture_dimension_cube;
122
+ /// Maximum number of texture layers.
123
+ uint32_t max_texture_array_layers;
124
+
125
+ /// Maximum number of vertex input elements in a graphics pipeline.
126
+ uint32_t max_vertex_input_elements;
127
+ /// Maximum offset of a vertex input element in the vertex stream.
128
+ uint32_t max_vertex_input_element_offset;
129
+ /// Maximum number of vertex streams in a graphics pipeline.
130
+ uint32_t max_vertex_streams;
131
+ /// Maximum stride of a vertex stream.
132
+ uint32_t max_vertex_stream_stride;
133
+
134
+ /// Maximum number of threads per thread group.
135
+ uint32_t max_compute_threads_per_group;
136
+ /// Maximum dimensions of a thread group.
137
+ uint3 max_compute_thread_group_size;
138
+ /// Maximum number of thread groups per dimension in a single dispatch.
139
+ uint3 max_compute_dispatch_thread_groups;
140
+
141
+ /// Maximum number of viewports per pipeline.
142
+ uint32_t max_viewports;
143
+ /// Maximum viewport dimensions.
144
+ uint2 max_viewport_dimensions;
145
+ /// Maximum framebuffer dimensions.
146
+ uint3 max_framebuffer_dimensions;
147
+
148
+ /// Maximum samplers visible in a shader stage.
149
+ uint32_t max_shader_visible_samplers;
150
+ };
151
+
152
+ struct DeviceInfo {
153
+ /// The type of the device.
154
+ DeviceType type;
155
+ /// The name of the graphics API being used by this device.
156
+ std::string api_name;
157
+ /// The name of the graphics adapter.
158
+ std::string adapter_name;
159
+ /// The logically unique identifier of the graphics adapter.
160
+ AdapterLUID adapter_luid;
161
+ /// The frequency of the timestamp counter.
162
+ /// To resolve a timestamp to seconds, divide by this value.
163
+ uint64_t timestamp_frequency;
164
+ /// Limits of the device.
165
+ DeviceLimits limits;
166
+ };
167
+
168
+ struct ShaderCacheStats {
169
+ /// Number of entries in the cache.
170
+ size_t entry_count;
171
+ /// Number of hits in the cache.
172
+ size_t hit_count;
173
+ /// Number of misses in the cache.
174
+ size_t miss_count;
175
+ };
176
+
177
+ /// Event data for hot reload hook.
178
+ struct ShaderHotReloadEvent { };
179
+ using ShaderHotReloadCallback = std::function<void(const ShaderHotReloadEvent&)>;
180
+
181
+
182
+ using DeviceCloseCallback = std::function<void(Device*)>;
183
+
184
+ class SGL_API Device : public Object {
185
+ SGL_OBJECT(Device)
186
+ public:
187
+ Device(const DeviceDesc& desc = DeviceDesc{});
188
+ ~Device();
189
+
190
+ static ref<Device> create(const DeviceDesc& desc = DeviceDesc{}) { return make_ref<Device>(desc); }
191
+
192
+ const DeviceDesc& desc() const { return m_desc; }
193
+
194
+ /// Type of the graphics API used by this device.
195
+ DeviceType type() const { return m_desc.type; }
196
+
197
+ /// Device information.
198
+ const DeviceInfo& info() const { return m_info; }
199
+
200
+ /// Shader cache statistics.
201
+ ShaderCacheStats shader_cache_stats() const;
202
+
203
+ /// The highest shader model supported by the device.
204
+ ShaderModel supported_shader_model() const { return m_supported_shader_model; }
205
+
206
+ /// List of features supported by the device.
207
+ const std::vector<std::string>& features() const { return m_features; }
208
+
209
+ /// True if the device supports CUDA interoperability.
210
+ bool supports_cuda_interop() const { return m_supports_cuda_interop; }
211
+
212
+ /// Returns the supported resource states for a given format.
213
+ ResourceStateSet get_format_supported_resource_states(Format format) const;
214
+
215
+ /// Default slang session.
216
+ SlangSession* slang_session() const { return m_slang_session; }
217
+
218
+ /**
219
+ * \brief Close the device.
220
+ *
221
+ * This function should be called before the device is released.
222
+ * It waits for all pending work to be completed and releases internal
223
+ * resources, removing all cyclic references that might prevent the device
224
+ * from being destroyed. After closing the device, no new resources must be
225
+ * created and no new work must be submitted.
226
+ *
227
+ * \note The Python extension will automatically close all open devices
228
+ * when the interpreter is terminated through an `atexit` handler. If a
229
+ * device is to be destroyed at runtime, it must be closed explicitly.
230
+ */
231
+ void close();
232
+
233
+ /// Close all open devices.
234
+ static void close_all_devices();
235
+
236
+ // Resource creation
237
+
238
+ /**
239
+ * \brief Create a new swapchain.
240
+ *
241
+ * \param format Format of the swapchain images.
242
+ * \param width Width of the swapchain images in pixels.
243
+ * \param height Height of the swapchain images in pixels.
244
+ * \param image_count Number of swapchain images.
245
+ * \param enable_vsync Enable/disable vertical synchronization.
246
+ * \param window Window to create the swapchain for.
247
+ * \return New swapchain object.
248
+ */
249
+ ref<Swapchain> create_swapchain(SwapchainDesc desc, Window* window);
250
+
251
+ /**
252
+ * \brief Create a new swapchain.
253
+ *
254
+ * \param format Format of the swapchain images.
255
+ * \param width Width of the swapchain images in pixels.
256
+ * \param height Height of the swapchain images in pixels.
257
+ * \param image_count Number of swapchain images.
258
+ * \param enable_vsync Enable/disable vertical synchronization.
259
+ * \param window_handle Native window handle to create the swapchain for.
260
+ * \return New swapchain object.
261
+ */
262
+ ref<Swapchain> create_swapchain(SwapchainDesc desc, WindowHandle window_handle);
263
+
264
+ /**
265
+ * \brief Create a new buffer.
266
+ *
267
+ * \param size Buffer size in bytes.
268
+ * \param element_count Buffer size in number of struct elements. Can be used instead of \c size.
269
+ * \param struct_size Struct size in bytes.
270
+ * \param struct_type Struct type. Can be used instead of \c struct_size to specify the size of the struct.
271
+ * \param format Buffer format. Used when creating typed buffer views.
272
+ * \param initial_state Initial resource state.
273
+ * \param usage Resource usage flags.
274
+ * \param memory_type Memory type.
275
+ * \param debug_name Resource debug name.
276
+ * \param data Initial data to upload to the buffer.
277
+ * \param data_size Size of the initial data in bytes.
278
+ * \return New buffer object.
279
+ */
280
+ ref<Buffer> create_buffer(BufferDesc desc);
281
+
282
+ /**
283
+ * \brief Create a new texture.
284
+ *
285
+ * \param type Resource type (optional). Type is inferred from width, height, depth if not specified.
286
+ * \param format Texture format.
287
+ * \param width Width in pixels.
288
+ * \param height Height in pixels.
289
+ * \param depth Depth in pixels.
290
+ * \param array_size Number of array slices (1 for non-array textures).
291
+ * \param mip_count Number of mip levels (0 for auto-generated mips).
292
+ * \param sample_count Number of samples per pixel (1 for non-multisampled textures).
293
+ * \param quality Quality level for multisampled textures.
294
+ * \param usage Resource usage.
295
+ * \param memory_type Memory type.
296
+ * \param debug_name Debug name.
297
+ * \param data Initial data.
298
+ * \return New texture object.
299
+ */
300
+ ref<Texture> create_texture(TextureDesc desc);
301
+
302
+ ref<Texture> create_texture_from_resource(TextureDesc desc, gfx::ITextureResource* resource, bool deferred_release);
303
+
304
+ /**
305
+ * \brief Create a new sampler.
306
+ *
307
+ * \param min_filter Minification filter.
308
+ * \param mag_filter Magnification filter.
309
+ * \param mip_filter Mip-map filter.
310
+ * \param reduction_op Reduction operation.
311
+ * \param address_u Texture addressing mode for the U coordinate.
312
+ * \param address_v Texture addressing mode for the V coordinate.
313
+ * \param address_w Texture addressing mode for the W coordinate.
314
+ * \param mip_lod_bias Mip-map LOD bias.
315
+ * \param max_anisotropy Maximum anisotropy.
316
+ * \param comparison_func Comparison function.
317
+ * \param border_color Border color.
318
+ * \param min_lod Minimum LOD level.
319
+ * \param max_lod Maximum LOD level.
320
+ * \return New sampler object.
321
+ */
322
+ ref<Sampler> create_sampler(SamplerDesc desc);
323
+
324
+ /**
325
+ * \brief Create a new fence.
326
+ *
327
+ * \param initial_value Initial fence value.
328
+ * \param shared Create a shared fence.
329
+ * \return New fence object.
330
+ */
331
+ ref<Fence> create_fence(FenceDesc desc);
332
+
333
+ /**
334
+ * \brief Create a new query pool.
335
+ *
336
+ * \param type Query type.
337
+ * \param count Number of queries in the pool.
338
+ * \return New query pool object.
339
+ */
340
+ ref<QueryPool> create_query_pool(QueryPoolDesc desc);
341
+
342
+ /**
343
+ * \brief Create a new input layout.
344
+ *
345
+ * \param input_elements List of input elements (see \ref InputElementDesc for details).
346
+ * \param vertex_streams List of vertex streams (see \ref VertexStreamDesc for details).
347
+ * \return New input layout object.
348
+ */
349
+ ref<InputLayout> create_input_layout(InputLayoutDesc desc);
350
+
351
+ /**
352
+ * \brief Create a new framebuffer.
353
+ *
354
+ * \param render_target List of render targets (see \ref FramebufferAttachmentDesc for details).
355
+ * \param depth_stencil Optional depth-stencil attachment (see \ref FramebufferAttachmentDesc for details).
356
+ * \return New framebuffer object.
357
+ */
358
+ ref<Framebuffer> create_framebuffer(FramebufferDesc desc);
359
+
360
+ AccelerationStructurePrebuildInfo
361
+ get_acceleration_structure_prebuild_info(const AccelerationStructureBuildInputs& build_inputs);
362
+
363
+ ref<AccelerationStructure> create_acceleration_structure(AccelerationStructureDesc desc);
364
+
365
+ ref<ShaderTable> create_shader_table(ShaderTableDesc desc);
366
+
367
+ /**
368
+ * \brief Create a new slang session.
369
+ *
370
+ * \param compiler_options Compiler options (see \ref SlangCompilerOptions for details).
371
+ * \return New slang session object.
372
+ */
373
+ ref<SlangSession> create_slang_session(SlangSessionDesc desc);
374
+
375
+ ref<SlangModule> load_module(std::string_view module_name);
376
+
377
+ ref<SlangModule> load_module_from_source(
378
+ std::string_view module_name,
379
+ std::string_view source,
380
+ std::optional<std::filesystem::path> path = {}
381
+ );
382
+
383
+ ref<ShaderProgram> link_program(
384
+ std::vector<ref<SlangModule>> modules,
385
+ std::vector<ref<SlangEntryPoint>> entry_points,
386
+ std::optional<SlangLinkOptions> link_options = {}
387
+ );
388
+
389
+ ref<ShaderProgram> load_program(
390
+ std::string_view module_name,
391
+ std::vector<std::string_view> entry_point_names,
392
+ std::optional<std::string_view> additional_source = {},
393
+ std::optional<SlangLinkOptions> link_options = {}
394
+ );
395
+
396
+ void reload_all_programs();
397
+
398
+ ref<MutableShaderObject> create_mutable_shader_object(const ShaderProgram* shader_program);
399
+
400
+ ref<MutableShaderObject> create_mutable_shader_object(const TypeLayoutReflection* type_layout);
401
+
402
+ ref<MutableShaderObject> create_mutable_shader_object(ReflectionCursor cursor);
403
+
404
+ ref<ComputePipeline> create_compute_pipeline(ComputePipelineDesc desc);
405
+
406
+ ref<GraphicsPipeline> create_graphics_pipeline(GraphicsPipelineDesc desc);
407
+
408
+ ref<RayTracingPipeline> create_ray_tracing_pipeline(RayTracingPipelineDesc desc);
409
+
410
+ ref<ComputeKernel> create_compute_kernel(ComputeKernelDesc desc);
411
+
412
+ ref<CommandBuffer> create_command_buffer();
413
+
414
+ void _set_open_command_buffer(CommandBuffer* command_buffer);
415
+ Slang::ComPtr<gfx::ITransientResourceHeap> _get_or_create_transient_resource_heap();
416
+
417
+ CommandBuffer* _begin_shared_command_buffer();
418
+ void _end_shared_command_buffer(bool wait);
419
+
420
+ /**
421
+ * \brief Submit a command buffer to the device.
422
+ *
423
+ * The returned submission ID can be used to wait for the command buffer to complete.
424
+ *
425
+ * \param command_buffer Command buffer to submit.
426
+ * \param queue Command queue to submit to.
427
+ * \return Submission ID.
428
+ */
429
+ uint64_t submit_command_buffer(CommandBuffer* command_buffer, CommandQueueType queue = CommandQueueType::graphics);
430
+
431
+ /**
432
+ * \brief Check if a command buffer is complete.
433
+ *
434
+ * \param id Submission ID.
435
+ * \return True if the command buffer is complete.
436
+ */
437
+ bool is_command_buffer_complete(uint64_t id);
438
+
439
+ /**
440
+ * \brief Wait for a command buffer to complete.
441
+ *
442
+ * \param id Submission ID.
443
+ */
444
+ void wait_command_buffer(uint64_t id);
445
+
446
+ /**
447
+ * \brief Wait for the command queue to be idle.
448
+ *
449
+ * \param queue Command queue to wait for.
450
+ */
451
+ void wait_for_idle(CommandQueueType queue = CommandQueueType::graphics);
452
+
453
+ /**
454
+ * \brief Synchronize CUDA -> device.
455
+ *
456
+ * This signals a shared CUDA semaphore from the CUDA stream and then waits for the signal on the command queue.
457
+ *
458
+ * \param cuda_stream CUDA stream
459
+ */
460
+ void sync_to_cuda(void* cuda_stream = 0);
461
+
462
+ /**
463
+ * \brief Synchronize device -> CUDA.
464
+ *
465
+ * This waits for a shared CUDA semaphore on the CUDA stream, making sure all commands on the device have completed.
466
+ *
467
+ * \param cuda_stream CUDA stream
468
+ */
469
+ void sync_to_device(void* cuda_stream = 0);
470
+
471
+ /**
472
+ * \brief Execute garbage collection.
473
+ *
474
+ * This function should be called regularly to execute deferred releases (at least once a frame).
475
+ */
476
+ void run_garbage_collection();
477
+
478
+ ref<MemoryHeap> create_memory_heap(MemoryHeapDesc desc);
479
+
480
+ MemoryHeap* upload_heap() const { return m_upload_heap; }
481
+ MemoryHeap* read_back_heap() const { return m_read_back_heap; }
482
+
483
+ DebugPrinter* debug_printer() const { return m_debug_printer.get(); }
484
+
485
+ /// Block and flush all shader side debug print output.
486
+ void flush_print();
487
+
488
+ /// Block and flush all shader side debug print output to a string.
489
+ std::string flush_print_to_string();
490
+
491
+ /// Wait for all device work to complete.
492
+ void wait();
493
+
494
+ /**
495
+ * Upload host memory to buffer.
496
+ *
497
+ * \param buffer Buffer to write to.
498
+ * \param data Data to write.
499
+ * \param size Size of the data in bytes.
500
+ * \param offset Offset in the buffer to write to.
501
+ */
502
+ void upload_buffer_data(Buffer* buffer, const void* data, size_t size, size_t offset = 0);
503
+
504
+ /**
505
+ * Read buffer data to host memory.
506
+ * \note This will wait until the data is copied back to host memory.
507
+ *
508
+ * \param buffer Buffer to read from.
509
+ * \param data Data to buffer to read to.
510
+ * \param size Size of the data in bytes.
511
+ * \param offset Offset in the buffer to read from.
512
+ */
513
+ void read_buffer_data(const Buffer* buffer, void* data, size_t size, size_t offset = 0);
514
+
515
+ /**
516
+ * Upload host memory to texture.
517
+ *
518
+ * \param texture Texture to write to.
519
+ * \param subresource Subresource index.
520
+ * \param subresource_data Subresource data.
521
+ */
522
+ void upload_texture_data(Texture* texture, uint32_t subresource, SubresourceData subresource_data);
523
+
524
+ /**
525
+ * Read texture data to host memory.
526
+ * \note This will wait until the data is copied back to host memory.
527
+ *
528
+ * \param texture Texture to read from.
529
+ * \param subresource Subresource index.
530
+ * \return Subresource data in host memory.
531
+ */
532
+ OwnedSubresourceData read_texture_data(const Texture* texture, uint32_t subresource);
533
+
534
+ void deferred_release(ISlangUnknown* object);
535
+
536
+ gfx::IDevice* gfx_device() const { return m_gfx_device; }
537
+ gfx::ICommandQueue* gfx_graphics_queue() const { return m_gfx_graphics_queue; }
538
+
539
+ slang::IGlobalSession* global_session() const { return m_global_session; }
540
+
541
+ /// Returns the native API handle:
542
+ /// - D3D12: ID3D12Device* (0)
543
+ /// - Vulkan: VkInstance (0), VkPhysicalDevice (1), VkDevice (2)
544
+ NativeHandle get_native_handle(uint32_t index = 0) const;
545
+
546
+ /// Returns the native API handle for the command queue:
547
+ /// - D3D12: ID3D12CommandQueue*
548
+ /// - Vulkan: VkQueue (Vulkan)
549
+ NativeHandle get_native_command_queue_handle(CommandQueueType queue = CommandQueueType::graphics) const;
550
+
551
+
552
+ /// Enumerates all available adapters of a given device type.
553
+ static std::vector<AdapterInfo> enumerate_adapters(DeviceType type = DeviceType::automatic);
554
+
555
+ /// Report live objects in the slang/gfx layer.
556
+ /// This is useful for checking clean shutdown with all resources released properly.
557
+ static void report_live_objects();
558
+
559
+ /**
560
+ * Try to enable D3D12 Agility SDK at runtime.
561
+ * Note: This must be called before creating a device to have any effect.
562
+ *
563
+ * Prefer adding SGL_EXPORT_AGILITY_SDK to the main translation unit of executables
564
+ * to tag the application binary to load the D3D12 Agility SDK.
565
+ *
566
+ * When using sgl through as a Python extension tagging the main application
567
+ * (Python interpreter) is not possible. The alternative is to use the
568
+ * D3D12SDKConfiguration API introduced in Windows SDK 20348. This however
569
+ * requires "Developer Mode" to be enabled and the executed Python interpreter to be
570
+ * stored on the same drive as the sgl library.
571
+ *
572
+ * \return Return true if D3D12 Agility SDK was successfully enabled.
573
+ */
574
+ static bool enable_agility_sdk();
575
+
576
+ /// Register a hot reload hook, called immediately after any module is reloaded.
577
+ void register_shader_hot_reload_callback(ShaderHotReloadCallback call_back)
578
+ {
579
+ m_shader_hot_reload_callbacks.push_back(call_back);
580
+ }
581
+
582
+ /// Register a device close callback, called at start of device close.
583
+ void register_device_close_callback(DeviceCloseCallback call_back)
584
+ {
585
+ m_device_close_callbacks.push_back(call_back);
586
+ }
587
+
588
+ cuda::Device* cuda_device() const { return m_cuda_device.get(); }
589
+
590
+ std::string to_string() const override;
591
+
592
+ Blitter* _blitter();
593
+ HotReload* _hot_reload() { return m_hot_reload; }
594
+
595
+ /// Called by hot reload system after reload occurs, to trigger the hooks.
596
+ void _on_hot_reload()
597
+ {
598
+ for (auto& hook : m_shader_hot_reload_callbacks)
599
+ hook({});
600
+ }
601
+
602
+ private:
603
+ DeviceDesc m_desc;
604
+ DeviceInfo m_info;
605
+ ShaderModel m_supported_shader_model{ShaderModel::unknown};
606
+
607
+ bool m_closed{false};
608
+
609
+ bool m_shader_cache_enabled{false};
610
+ std::filesystem::path m_shader_cache_path;
611
+
612
+ Slang::ComPtr<gfx::IDevice> m_gfx_device;
613
+ Slang::ComPtr<gfx::ICommandQueue> m_gfx_graphics_queue;
614
+ Slang::ComPtr<slang::IGlobalSession> m_global_session;
615
+
616
+ ref<SlangSession> m_slang_session;
617
+
618
+ std::vector<std::string> m_features;
619
+
620
+ ref<Fence> m_global_fence;
621
+
622
+ ref<MemoryHeap> m_upload_heap;
623
+ ref<MemoryHeap> m_read_back_heap;
624
+
625
+ std::unique_ptr<DebugPrinter> m_debug_printer;
626
+
627
+ /// Currently open command buffer.
628
+ /// Due to limitations in gfx, only one command buffer can be open at a time.
629
+ CommandBuffer* m_open_command_buffer{nullptr};
630
+ ref<CommandBuffer> m_shared_command_buffer;
631
+
632
+ /// Currently active transient resource heap.
633
+ /// All command buffers are created on this heap.
634
+ Slang::ComPtr<gfx::ITransientResourceHeap> m_current_transient_resource_heap;
635
+
636
+ /// Transient resource heaps available for reuse.
637
+ std::queue<Slang::ComPtr<gfx::ITransientResourceHeap>> m_transient_resource_heap_pool;
638
+
639
+ /// Transient resource heaps that are currently in flight.
640
+ std::queue<std::pair<Slang::ComPtr<gfx::ITransientResourceHeap>, uint64_t>> m_in_flight_transient_resource_heaps;
641
+
642
+ /// List of callbacks for hot reload event
643
+ std::vector<ShaderHotReloadCallback> m_shader_hot_reload_callbacks;
644
+
645
+ /// List of callbacks for shutdown event
646
+ std::vector<DeviceCloseCallback> m_device_close_callbacks;
647
+
648
+ struct DeferredRelease {
649
+ uint64_t fence_value;
650
+ Slang::ComPtr<ISlangUnknown> object;
651
+ };
652
+
653
+ std::queue<DeferredRelease> m_deferred_release_queue;
654
+
655
+ #if SGL_HAS_NVAPI
656
+ class PipelineCreationAPIDispatcher;
657
+ std::unique_ptr<PipelineCreationAPIDispatcher> m_api_dispatcher;
658
+ #endif
659
+
660
+ ref<Blitter> m_blitter;
661
+ ref<HotReload> m_hot_reload;
662
+
663
+ bool m_supports_cuda_interop{false};
664
+ ref<cuda::Device> m_cuda_device;
665
+ ref<cuda::ExternalSemaphore> m_cuda_semaphore;
666
+ };
667
+
668
+ } // namespace sgl
@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ #pragma once
4
+
5
+ #include "sgl/device/fwd.h"
6
+
7
+ #include "sgl/core/object.h"
8
+
9
+ namespace sgl {
10
+
11
+ class SGL_API DeviceResource : public Object {
12
+ SGL_OBJECT(DeviceResource)
13
+ public:
14
+ DeviceResource(ref<Device> device)
15
+ : m_device(std::move(device))
16
+ {
17
+ }
18
+
19
+ virtual ~DeviceResource() = default;
20
+
21
+ Device* device() const { return m_device; }
22
+
23
+ struct MemoryUsage {
24
+ /// The amount of memory in bytes used on the device.
25
+ size_t device{0};
26
+ /// The amount of memory in bytes used on the host.
27
+ size_t host{0};
28
+ };
29
+
30
+ /// The memory usage by this resource.
31
+ virtual MemoryUsage memory_usage() const;
32
+
33
+ protected:
34
+ ref<Device> m_device;
35
+ };
36
+
37
+ } // namespace sgl