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,705 @@
|
|
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/device_resource.h"
|
8
|
+
#include "sgl/device/formats.h"
|
9
|
+
#include "sgl/device/shared_handle.h"
|
10
|
+
#include "sgl/device/native_handle.h"
|
11
|
+
|
12
|
+
#include "sgl/core/fwd.h"
|
13
|
+
#include "sgl/core/macros.h"
|
14
|
+
#include "sgl/core/enum.h"
|
15
|
+
#include "sgl/core/object.h"
|
16
|
+
|
17
|
+
#include <slang-gfx.h>
|
18
|
+
|
19
|
+
#include <map>
|
20
|
+
#include <set>
|
21
|
+
#include <limits>
|
22
|
+
|
23
|
+
namespace sgl {
|
24
|
+
|
25
|
+
enum class ResourceType : uint32_t {
|
26
|
+
unknown = static_cast<uint32_t>(gfx::IResource::Type::Unknown),
|
27
|
+
buffer = static_cast<uint32_t>(gfx::IResource::Type::Buffer),
|
28
|
+
texture_1d = static_cast<uint32_t>(gfx::IResource::Type::Texture1D),
|
29
|
+
texture_2d = static_cast<uint32_t>(gfx::IResource::Type::Texture2D),
|
30
|
+
texture_3d = static_cast<uint32_t>(gfx::IResource::Type::Texture3D),
|
31
|
+
texture_cube = static_cast<uint32_t>(gfx::IResource::Type::TextureCube),
|
32
|
+
};
|
33
|
+
|
34
|
+
SGL_ENUM_INFO(
|
35
|
+
ResourceType,
|
36
|
+
{
|
37
|
+
{ResourceType::unknown, "unknown"},
|
38
|
+
{ResourceType::buffer, "buffer"},
|
39
|
+
{ResourceType::texture_1d, "texture_1d"},
|
40
|
+
{ResourceType::texture_2d, "texture_2d"},
|
41
|
+
{ResourceType::texture_3d, "texture_3d"},
|
42
|
+
{ResourceType::texture_cube, "texture_cube"},
|
43
|
+
}
|
44
|
+
);
|
45
|
+
SGL_ENUM_REGISTER(ResourceType);
|
46
|
+
|
47
|
+
enum class ResourceState : uint32_t {
|
48
|
+
undefined = static_cast<uint32_t>(gfx::ResourceState::Undefined),
|
49
|
+
general = static_cast<uint32_t>(gfx::ResourceState::General),
|
50
|
+
pre_initialized = static_cast<uint32_t>(gfx::ResourceState::PreInitialized),
|
51
|
+
vertex_buffer = static_cast<uint32_t>(gfx::ResourceState::VertexBuffer),
|
52
|
+
index_buffer = static_cast<uint32_t>(gfx::ResourceState::IndexBuffer),
|
53
|
+
constant_buffer = static_cast<uint32_t>(gfx::ResourceState::ConstantBuffer),
|
54
|
+
stream_output = static_cast<uint32_t>(gfx::ResourceState::StreamOutput),
|
55
|
+
shader_resource = static_cast<uint32_t>(gfx::ResourceState::ShaderResource),
|
56
|
+
unordered_access = static_cast<uint32_t>(gfx::ResourceState::UnorderedAccess),
|
57
|
+
render_target = static_cast<uint32_t>(gfx::ResourceState::RenderTarget),
|
58
|
+
depth_read = static_cast<uint32_t>(gfx::ResourceState::DepthRead),
|
59
|
+
depth_write = static_cast<uint32_t>(gfx::ResourceState::DepthWrite),
|
60
|
+
present = static_cast<uint32_t>(gfx::ResourceState::Present),
|
61
|
+
indirect_argument = static_cast<uint32_t>(gfx::ResourceState::IndirectArgument),
|
62
|
+
copy_source = static_cast<uint32_t>(gfx::ResourceState::CopySource),
|
63
|
+
copy_destination = static_cast<uint32_t>(gfx::ResourceState::CopyDestination),
|
64
|
+
resolve_source = static_cast<uint32_t>(gfx::ResourceState::ResolveSource),
|
65
|
+
resolve_destination = static_cast<uint32_t>(gfx::ResourceState::ResolveDestination),
|
66
|
+
acceleration_structure = static_cast<uint32_t>(gfx::ResourceState::AccelerationStructure),
|
67
|
+
acceleration_structure_build_output = static_cast<uint32_t>(gfx::ResourceState::AccelerationStructureBuildInput),
|
68
|
+
pixel_shader_resource = static_cast<uint32_t>(gfx::ResourceState::PixelShaderResource),
|
69
|
+
non_pixel_shader_resource = static_cast<uint32_t>(gfx::ResourceState::NonPixelShaderResource),
|
70
|
+
};
|
71
|
+
|
72
|
+
SGL_ENUM_INFO(
|
73
|
+
ResourceState,
|
74
|
+
{
|
75
|
+
{ResourceState::undefined, "undefined"},
|
76
|
+
{ResourceState::general, "general"},
|
77
|
+
{ResourceState::pre_initialized, "pre_initialized"},
|
78
|
+
{ResourceState::vertex_buffer, "vertex_buffer"},
|
79
|
+
{ResourceState::index_buffer, "index_buffer"},
|
80
|
+
{ResourceState::constant_buffer, "constant_buffer"},
|
81
|
+
{ResourceState::stream_output, "stream_output"},
|
82
|
+
{ResourceState::shader_resource, "shader_resource"},
|
83
|
+
{ResourceState::unordered_access, "unordered_access"},
|
84
|
+
{ResourceState::render_target, "render_target"},
|
85
|
+
{ResourceState::depth_read, "depth_read"},
|
86
|
+
{ResourceState::depth_write, "depth_write"},
|
87
|
+
{ResourceState::present, "present"},
|
88
|
+
{ResourceState::indirect_argument, "indirect_argument"},
|
89
|
+
{ResourceState::copy_source, "copy_source"},
|
90
|
+
{ResourceState::copy_destination, "copy_destination"},
|
91
|
+
{ResourceState::resolve_source, "resolve_source"},
|
92
|
+
{ResourceState::resolve_destination, "resolve_destination"},
|
93
|
+
{ResourceState::acceleration_structure, "acceleration_structure"},
|
94
|
+
{ResourceState::acceleration_structure_build_output, "acceleration_structure_build_output"},
|
95
|
+
{ResourceState::pixel_shader_resource, "pixel_shader_resource"},
|
96
|
+
{ResourceState::non_pixel_shader_resource, "non_pixel_shader_resource"},
|
97
|
+
}
|
98
|
+
);
|
99
|
+
SGL_ENUM_REGISTER(ResourceState);
|
100
|
+
|
101
|
+
using ResourceStateSet = std::set<ResourceState>;
|
102
|
+
|
103
|
+
enum class ResourceUsage : uint32_t {
|
104
|
+
/// The resource will not be bound the pipeline. Use this to create a staging resource.
|
105
|
+
none = 0x0,
|
106
|
+
/// The resource will be bound as a vertex-buffer.
|
107
|
+
vertex = 0x1,
|
108
|
+
/// The resource will be bound as a index-buffer.
|
109
|
+
index = 0x2,
|
110
|
+
/// The resource will be bound as a constant-buffer.
|
111
|
+
constant = 0x4,
|
112
|
+
/// The resource will be bound to the stream-output stage as an output buffer.
|
113
|
+
stream_output = 0x8,
|
114
|
+
/// The resource will be bound as a shader-resource.
|
115
|
+
shader_resource = 0x10,
|
116
|
+
/// The resource will be bound as an UAV.
|
117
|
+
unordered_access = 0x20,
|
118
|
+
/// The resource will be bound as a render-target.
|
119
|
+
render_target = 0x40,
|
120
|
+
/// The resource will be bound as a depth-stencil buffer.
|
121
|
+
depth_stencil = 0x80,
|
122
|
+
/// The resource will be bound as an indirect argument buffer.
|
123
|
+
indirect_arg = 0x100,
|
124
|
+
/// The resource will be shared with a different adapter. Mostly useful for sharing resoures with CUDA.
|
125
|
+
shared = 0x200,
|
126
|
+
/// The resource will be bound as an acceleration structure
|
127
|
+
acceleration_structure = 0x80000000,
|
128
|
+
};
|
129
|
+
|
130
|
+
SGL_ENUM_INFO(
|
131
|
+
ResourceUsage,
|
132
|
+
{
|
133
|
+
{ResourceUsage::none, "none"},
|
134
|
+
{ResourceUsage::vertex, "vertex"},
|
135
|
+
{ResourceUsage::index, "index"},
|
136
|
+
{ResourceUsage::constant, "constant"},
|
137
|
+
{ResourceUsage::stream_output, "stream_output"},
|
138
|
+
{ResourceUsage::shader_resource, "shader_resource"},
|
139
|
+
{ResourceUsage::unordered_access, "unordered_access"},
|
140
|
+
{ResourceUsage::render_target, "render_target"},
|
141
|
+
{ResourceUsage::depth_stencil, "depth_stencil"},
|
142
|
+
{ResourceUsage::indirect_arg, "indirect_arg"},
|
143
|
+
{ResourceUsage::shared, "shared"},
|
144
|
+
{ResourceUsage::acceleration_structure, "acceleration_structure"},
|
145
|
+
}
|
146
|
+
);
|
147
|
+
SGL_ENUM_REGISTER(ResourceUsage);
|
148
|
+
|
149
|
+
SGL_ENUM_CLASS_OPERATORS(ResourceUsage)
|
150
|
+
|
151
|
+
enum class MemoryType : uint32_t {
|
152
|
+
device_local = static_cast<uint32_t>(gfx::MemoryType::DeviceLocal),
|
153
|
+
upload = static_cast<uint32_t>(gfx::MemoryType::Upload),
|
154
|
+
read_back = static_cast<uint32_t>(gfx::MemoryType::ReadBack),
|
155
|
+
};
|
156
|
+
|
157
|
+
SGL_ENUM_INFO(
|
158
|
+
MemoryType,
|
159
|
+
{
|
160
|
+
{MemoryType::device_local, "device_local"},
|
161
|
+
{MemoryType::upload, "upload"},
|
162
|
+
{MemoryType::read_back, "read_back"},
|
163
|
+
}
|
164
|
+
);
|
165
|
+
SGL_ENUM_REGISTER(MemoryType);
|
166
|
+
|
167
|
+
enum class ResourceViewType : uint32_t {
|
168
|
+
unknown = static_cast<uint32_t>(gfx::IResourceView::Type::Unknown),
|
169
|
+
render_target = static_cast<uint32_t>(gfx::IResourceView::Type::RenderTarget),
|
170
|
+
depth_stencil = static_cast<uint32_t>(gfx::IResourceView::Type::DepthStencil),
|
171
|
+
shader_resource = static_cast<uint32_t>(gfx::IResourceView::Type::ShaderResource),
|
172
|
+
unordered_access = static_cast<uint32_t>(gfx::IResourceView::Type::UnorderedAccess),
|
173
|
+
// acceleration_structure = static_cast<uint32_t>(gfx::IResourceView::Type::AccelerationStructure),
|
174
|
+
};
|
175
|
+
|
176
|
+
SGL_ENUM_INFO(
|
177
|
+
ResourceViewType,
|
178
|
+
{
|
179
|
+
{ResourceViewType::unknown, "unknown"},
|
180
|
+
{ResourceViewType::render_target, "render_target"},
|
181
|
+
{ResourceViewType::depth_stencil, "depth_stencil"},
|
182
|
+
{ResourceViewType::shader_resource, "shader_resource"},
|
183
|
+
{ResourceViewType::unordered_access, "unordered_access"},
|
184
|
+
// {ResourceViewType::acceleration_structure, "acceleration_structure"},
|
185
|
+
}
|
186
|
+
);
|
187
|
+
SGL_ENUM_REGISTER(ResourceViewType);
|
188
|
+
|
189
|
+
struct BufferRange {
|
190
|
+
static constexpr uint64_t ALL = std::numeric_limits<uint64_t>::max();
|
191
|
+
uint64_t offset{0};
|
192
|
+
uint64_t size{ALL};
|
193
|
+
|
194
|
+
auto operator<=>(const BufferRange&) const = default;
|
195
|
+
|
196
|
+
std::string to_string() const { return fmt::format("BufferRange(offset={}, size={}", offset, size); }
|
197
|
+
};
|
198
|
+
|
199
|
+
enum class TextureAspect : uint32_t {
|
200
|
+
default_ = static_cast<uint32_t>(gfx::TextureAspect::Default),
|
201
|
+
color = static_cast<uint32_t>(gfx::TextureAspect::Color),
|
202
|
+
depth = static_cast<uint32_t>(gfx::TextureAspect::Depth),
|
203
|
+
stencil = static_cast<uint32_t>(gfx::TextureAspect::Stencil),
|
204
|
+
meta_data = static_cast<uint32_t>(gfx::TextureAspect::MetaData),
|
205
|
+
plane0 = static_cast<uint32_t>(gfx::TextureAspect::Plane0),
|
206
|
+
plane1 = static_cast<uint32_t>(gfx::TextureAspect::Plane1),
|
207
|
+
plane2 = static_cast<uint32_t>(gfx::TextureAspect::Plane2),
|
208
|
+
depth_stencil = depth | stencil,
|
209
|
+
};
|
210
|
+
SGL_ENUM_INFO(
|
211
|
+
TextureAspect,
|
212
|
+
{
|
213
|
+
{TextureAspect::default_, "default_"},
|
214
|
+
{TextureAspect::color, "color"},
|
215
|
+
{TextureAspect::depth, "depth"},
|
216
|
+
{TextureAspect::stencil, "stencil"},
|
217
|
+
{TextureAspect::meta_data, "meta_data"},
|
218
|
+
{TextureAspect::plane0, "plane0"},
|
219
|
+
{TextureAspect::plane1, "plane1"},
|
220
|
+
{TextureAspect::plane2, "plane2"},
|
221
|
+
{TextureAspect::depth_stencil, "depth_stencil"},
|
222
|
+
|
223
|
+
}
|
224
|
+
);
|
225
|
+
SGL_ENUM_REGISTER(TextureAspect);
|
226
|
+
|
227
|
+
struct SubresourceRange {
|
228
|
+
static constexpr uint32_t ALL = std::numeric_limits<uint32_t>::max();
|
229
|
+
/// Texture aspect.
|
230
|
+
TextureAspect texture_aspect{TextureAspect::default_};
|
231
|
+
/// Most detailed mip level.
|
232
|
+
uint32_t mip_level{0};
|
233
|
+
/// Number of mip levels.
|
234
|
+
uint32_t mip_count{ALL};
|
235
|
+
/// First array layer.
|
236
|
+
uint32_t base_array_layer{0}; // For Texture3D, this is WSlice.
|
237
|
+
/// Number of array layers.
|
238
|
+
uint32_t layer_count{ALL}; // For cube maps, this is a multiple of 6.
|
239
|
+
|
240
|
+
auto operator<=>(const SubresourceRange&) const = default;
|
241
|
+
|
242
|
+
std::string to_string() const
|
243
|
+
{
|
244
|
+
return fmt::format(
|
245
|
+
"SubresourceRange(texture_aspect={}, mip_level={}, mip_count={}, base_array_layer={}, layer_count={}",
|
246
|
+
texture_aspect,
|
247
|
+
mip_level,
|
248
|
+
mip_count,
|
249
|
+
base_array_layer,
|
250
|
+
layer_count
|
251
|
+
);
|
252
|
+
}
|
253
|
+
};
|
254
|
+
|
255
|
+
struct ResourceViewDesc {
|
256
|
+
static constexpr uint32_t MAX_POSSIBLE = std::numeric_limits<uint32_t>::max();
|
257
|
+
|
258
|
+
ResourceViewType type{ResourceViewType::unknown};
|
259
|
+
Format format{Format::unknown};
|
260
|
+
|
261
|
+
// For buffer views.
|
262
|
+
BufferRange buffer_range;
|
263
|
+
uint64_t buffer_element_size;
|
264
|
+
|
265
|
+
// For texture views.
|
266
|
+
SubresourceRange subresource_range;
|
267
|
+
|
268
|
+
auto operator<=>(const ResourceViewDesc&) const = default;
|
269
|
+
};
|
270
|
+
|
271
|
+
class SGL_API ResourceView : public Object {
|
272
|
+
SGL_OBJECT(ResourceView)
|
273
|
+
public:
|
274
|
+
ResourceView(const ResourceViewDesc& desc, Buffer* buffer);
|
275
|
+
ResourceView(const ResourceViewDesc& desc, Texture* texture);
|
276
|
+
|
277
|
+
~ResourceView();
|
278
|
+
|
279
|
+
void invalidate(bool deferred_release);
|
280
|
+
|
281
|
+
const ResourceViewDesc& desc() const { return m_desc; }
|
282
|
+
|
283
|
+
ResourceViewType type() const { return m_desc.type; }
|
284
|
+
|
285
|
+
Resource* resource() const { return m_resource; }
|
286
|
+
|
287
|
+
const BufferRange& buffer_range() const { return m_desc.buffer_range; }
|
288
|
+
const SubresourceRange& subresource_range() const { return m_desc.subresource_range; }
|
289
|
+
|
290
|
+
/// True if the view covers all subresources.
|
291
|
+
bool all_subresources() const { return m_all_subresources; }
|
292
|
+
|
293
|
+
gfx::IResourceView* gfx_resource_view() const { return m_gfx_resource_view; }
|
294
|
+
|
295
|
+
/// Returns the native API handle:
|
296
|
+
/// - D3D12: D3D12_CPU_DESCRIPTOR_HANDLE
|
297
|
+
/// - Vulkan: VkImageView for texture views, VkBufferView for typed buffer views, VkBuffer for untyped buffer views
|
298
|
+
NativeHandle get_native_handle() const;
|
299
|
+
|
300
|
+
std::string to_string() const override;
|
301
|
+
|
302
|
+
private:
|
303
|
+
ResourceViewDesc m_desc;
|
304
|
+
Resource* m_resource{nullptr};
|
305
|
+
bool m_all_subresources{false};
|
306
|
+
Slang::ComPtr<gfx::IResourceView> m_gfx_resource_view;
|
307
|
+
};
|
308
|
+
|
309
|
+
class ResourceStateTracker {
|
310
|
+
public:
|
311
|
+
ResourceStateTracker() = default;
|
312
|
+
|
313
|
+
bool has_global_state() const { return m_has_global_state; }
|
314
|
+
|
315
|
+
ResourceState global_state() const { return m_global_state; }
|
316
|
+
|
317
|
+
void set_global_state(ResourceState state)
|
318
|
+
{
|
319
|
+
m_has_global_state = true;
|
320
|
+
m_global_state = state;
|
321
|
+
}
|
322
|
+
|
323
|
+
ResourceState subresource_state(uint32_t subresource) const
|
324
|
+
{
|
325
|
+
if (m_has_global_state)
|
326
|
+
return m_global_state;
|
327
|
+
SGL_ASSERT(m_subresource_states);
|
328
|
+
if (subresource >= m_subresource_states->size())
|
329
|
+
return m_global_state;
|
330
|
+
return m_subresource_states->operator[](subresource);
|
331
|
+
}
|
332
|
+
|
333
|
+
void set_subresource_state(uint32_t subresource, ResourceState state)
|
334
|
+
{
|
335
|
+
if (m_has_global_state && (state == m_global_state))
|
336
|
+
return;
|
337
|
+
m_has_global_state = false;
|
338
|
+
if (!m_subresource_states)
|
339
|
+
m_subresource_states = std::make_unique<std::vector<ResourceState>>(subresource + 1, m_global_state);
|
340
|
+
if (subresource >= m_subresource_states->size())
|
341
|
+
m_subresource_states->resize(subresource + 1, m_global_state);
|
342
|
+
m_subresource_states->operator[](subresource) = state;
|
343
|
+
}
|
344
|
+
|
345
|
+
private:
|
346
|
+
bool m_has_global_state{true};
|
347
|
+
ResourceState m_global_state{ResourceState::undefined};
|
348
|
+
std::unique_ptr<std::vector<ResourceState>> m_subresource_states;
|
349
|
+
};
|
350
|
+
|
351
|
+
class SGL_API Resource : public DeviceResource {
|
352
|
+
SGL_OBJECT(Resource)
|
353
|
+
public:
|
354
|
+
virtual ~Resource();
|
355
|
+
|
356
|
+
ResourceType type() const { return m_type; };
|
357
|
+
|
358
|
+
virtual Format format() const = 0;
|
359
|
+
|
360
|
+
ResourceStateTracker& state_tracker() const { return m_state_tracker; }
|
361
|
+
|
362
|
+
void invalidate_views();
|
363
|
+
|
364
|
+
const Buffer* as_buffer() const;
|
365
|
+
Buffer* as_buffer();
|
366
|
+
|
367
|
+
const Texture* as_texture() const;
|
368
|
+
Texture* as_texture();
|
369
|
+
|
370
|
+
virtual gfx::IResource* gfx_resource() const = 0;
|
371
|
+
|
372
|
+
/// Get the shared resource handle.
|
373
|
+
SharedResourceHandle get_shared_handle() const;
|
374
|
+
|
375
|
+
/// Returns the native API handle:
|
376
|
+
/// - D3D12: ID3D12Resource*
|
377
|
+
/// - Vulkan: VkBuffer or VkImage
|
378
|
+
NativeHandle get_native_handle() const;
|
379
|
+
|
380
|
+
protected:
|
381
|
+
Resource() = delete;
|
382
|
+
Resource(ref<Device> device, ResourceType type);
|
383
|
+
|
384
|
+
ResourceType m_type;
|
385
|
+
mutable ResourceStateTracker m_state_tracker;
|
386
|
+
|
387
|
+
std::map<ResourceViewDesc, ref<ResourceView>> m_views;
|
388
|
+
|
389
|
+
bool m_deferred_release{true};
|
390
|
+
|
391
|
+
friend class ResourceView;
|
392
|
+
};
|
393
|
+
|
394
|
+
|
395
|
+
struct BufferDesc {
|
396
|
+
/// Buffer size in bytes.
|
397
|
+
size_t size{0};
|
398
|
+
|
399
|
+
/// Buffer size in number of struct elements. Can be used instead of \c size.
|
400
|
+
size_t element_count{0};
|
401
|
+
/// Struct size in bytes.
|
402
|
+
size_t struct_size{0};
|
403
|
+
/// Struct type. Can be used instead of \c struct_size to specify the size of the struct.
|
404
|
+
ref<const TypeLayoutReflection> struct_type;
|
405
|
+
|
406
|
+
/// Buffer format. Used when creating typed buffer views.
|
407
|
+
Format format{Format::unknown};
|
408
|
+
|
409
|
+
/// Initial resource state.
|
410
|
+
ResourceState initial_state{ResourceState::undefined};
|
411
|
+
/// Resource usage flags.
|
412
|
+
ResourceUsage usage{ResourceUsage::none};
|
413
|
+
/// Memory type.
|
414
|
+
MemoryType memory_type{MemoryType::device_local};
|
415
|
+
|
416
|
+
/// Resource debug name.
|
417
|
+
std::string debug_name;
|
418
|
+
|
419
|
+
/// Initial data to upload to the buffer.
|
420
|
+
const void* data{nullptr};
|
421
|
+
/// Size of the initial data in bytes.
|
422
|
+
size_t data_size{0};
|
423
|
+
};
|
424
|
+
|
425
|
+
class SGL_API Buffer : public Resource {
|
426
|
+
SGL_OBJECT(Buffer)
|
427
|
+
public:
|
428
|
+
Buffer(ref<Device> device, BufferDesc desc);
|
429
|
+
|
430
|
+
~Buffer();
|
431
|
+
|
432
|
+
const BufferDesc& desc() const { return m_desc; }
|
433
|
+
|
434
|
+
size_t size() const { return m_desc.size; }
|
435
|
+
size_t struct_size() const { return m_desc.struct_size; }
|
436
|
+
Format format() const override { return m_desc.format; }
|
437
|
+
MemoryType memory_type() const { return m_desc.memory_type; }
|
438
|
+
|
439
|
+
/// Map the whole buffer.
|
440
|
+
/// Only available for buffers created with \c MemoryType::upload or \c MemoryType::read_back.
|
441
|
+
void* map() const;
|
442
|
+
|
443
|
+
template<typename T>
|
444
|
+
T* map() const
|
445
|
+
{
|
446
|
+
return reinterpret_cast<T*>(map());
|
447
|
+
}
|
448
|
+
|
449
|
+
/// Map a range of the buffer.
|
450
|
+
/// Only available for buffers created with \c MemoryType::upload or \c MemoryType::read_back.
|
451
|
+
void* map(DeviceOffset offset, DeviceSize size) const;
|
452
|
+
|
453
|
+
template<typename T>
|
454
|
+
T* map(size_t offset, size_t count) const
|
455
|
+
{
|
456
|
+
return reinterpret_cast<T*>(map(offset * sizeof(T), count * sizeof(T)));
|
457
|
+
}
|
458
|
+
|
459
|
+
/// Unmap the buffer.
|
460
|
+
void unmap() const;
|
461
|
+
|
462
|
+
/// Returns true if buffer is currently mapped.
|
463
|
+
bool is_mapped() const { return m_mapped_ptr != nullptr; }
|
464
|
+
|
465
|
+
/// Returns a pointer to the CUDA memory.
|
466
|
+
/// This is only supported if the buffer was created with ResourceUsage::shared
|
467
|
+
/// and the device has CUDA interop enabled.
|
468
|
+
void* cuda_memory() const;
|
469
|
+
|
470
|
+
/**
|
471
|
+
* Set buffer data from host memory.
|
472
|
+
*
|
473
|
+
* \param data Data to write.
|
474
|
+
* \param size Size of the data in bytes.
|
475
|
+
* \param offset Offset in the buffer to write to.
|
476
|
+
*/
|
477
|
+
void set_data(const void* data, size_t size, DeviceOffset offset = 0);
|
478
|
+
|
479
|
+
template<typename T>
|
480
|
+
void set_element(size_t index, const T& value)
|
481
|
+
{
|
482
|
+
set_data(&value, sizeof(T), index * sizeof(T));
|
483
|
+
}
|
484
|
+
|
485
|
+
template<typename T>
|
486
|
+
void set_elements(size_t index, std::span<const T> values)
|
487
|
+
{
|
488
|
+
set_data(values.data(), values.size() * sizeof(T), index * sizeof(T));
|
489
|
+
}
|
490
|
+
|
491
|
+
/**
|
492
|
+
* Get buffer data to host memory.
|
493
|
+
* \note If the buffer is in device local memory, this will wait until the data is copied back to host memory.
|
494
|
+
*
|
495
|
+
* \param data Data buffer to read to.
|
496
|
+
* \param size Size of the data in bytes.
|
497
|
+
* \param offset Offset in the buffer to read from.
|
498
|
+
*/
|
499
|
+
void get_data(void* data, size_t size, DeviceOffset offset = 0);
|
500
|
+
|
501
|
+
template<typename T>
|
502
|
+
void get_element(size_t index)
|
503
|
+
{
|
504
|
+
T value;
|
505
|
+
get_data(&value, sizeof(T), index * sizeof(T));
|
506
|
+
return value;
|
507
|
+
}
|
508
|
+
|
509
|
+
template<typename T>
|
510
|
+
std::vector<T> get_elements(size_t index = 0, size_t count = 0)
|
511
|
+
{
|
512
|
+
if (count == 0)
|
513
|
+
count = (m_desc.size / sizeof(T)) - index;
|
514
|
+
std::vector<T> values(count);
|
515
|
+
get_data(values.data(), values.size() * sizeof(T), index * sizeof(T));
|
516
|
+
return values;
|
517
|
+
}
|
518
|
+
|
519
|
+
DeviceAddress device_address() const { return m_gfx_buffer->getDeviceAddress(); }
|
520
|
+
|
521
|
+
/// Get a resource view. Views are cached and reused.
|
522
|
+
ref<ResourceView> get_view(ResourceViewDesc desc);
|
523
|
+
|
524
|
+
/// Get a shader resource view for a range of the buffer.
|
525
|
+
ref<ResourceView> get_srv(BufferRange range = BufferRange());
|
526
|
+
|
527
|
+
/// Get a unordered access view for a range of the buffer.
|
528
|
+
ref<ResourceView> get_uav(BufferRange range = BufferRange());
|
529
|
+
|
530
|
+
virtual gfx::IResource* gfx_resource() const override { return m_gfx_buffer; }
|
531
|
+
gfx::IBufferResource* gfx_buffer_resource() const { return m_gfx_buffer; }
|
532
|
+
|
533
|
+
MemoryUsage memory_usage() const override;
|
534
|
+
|
535
|
+
std::string to_string() const override;
|
536
|
+
|
537
|
+
private:
|
538
|
+
BufferDesc m_desc;
|
539
|
+
Slang::ComPtr<gfx::IBufferResource> m_gfx_buffer;
|
540
|
+
mutable ref<cuda::ExternalMemory> m_cuda_memory;
|
541
|
+
mutable void* m_mapped_ptr{nullptr};
|
542
|
+
};
|
543
|
+
|
544
|
+
struct SubresourceData {
|
545
|
+
const void* data{nullptr};
|
546
|
+
size_t size{0};
|
547
|
+
size_t row_pitch{0};
|
548
|
+
size_t slice_pitch{0};
|
549
|
+
};
|
550
|
+
|
551
|
+
struct OwnedSubresourceData : SubresourceData {
|
552
|
+
std::unique_ptr<uint8_t[]> owned_data;
|
553
|
+
};
|
554
|
+
|
555
|
+
struct TextureDesc {
|
556
|
+
/// Resource type (optional). Type is inferred from width, height, depth if not specified.
|
557
|
+
ResourceType type{ResourceType::unknown};
|
558
|
+
/// Texture format.
|
559
|
+
Format format{Format::unknown};
|
560
|
+
/// Width in pixels.
|
561
|
+
uint32_t width{0};
|
562
|
+
/// Height in pixels.
|
563
|
+
uint32_t height{0};
|
564
|
+
/// Depth in pixels.
|
565
|
+
uint32_t depth{0};
|
566
|
+
/// Number of array slices (1 for non-array textures).
|
567
|
+
uint32_t array_size{1};
|
568
|
+
/// Number of mip levels (0 for auto-generated mips).
|
569
|
+
uint32_t mip_count{0};
|
570
|
+
/// Number of samples per pixel (1 for non-multisampled textures).
|
571
|
+
uint32_t sample_count{1};
|
572
|
+
/// Quality level for multisampled textures.
|
573
|
+
uint32_t quality{0};
|
574
|
+
|
575
|
+
// TODO(@skallweit): support clear value
|
576
|
+
|
577
|
+
ResourceState initial_state{ResourceState::undefined};
|
578
|
+
ResourceUsage usage{ResourceUsage::none};
|
579
|
+
MemoryType memory_type{MemoryType::device_local};
|
580
|
+
|
581
|
+
std::string debug_name;
|
582
|
+
|
583
|
+
const void* data{nullptr};
|
584
|
+
size_t data_size{0};
|
585
|
+
};
|
586
|
+
|
587
|
+
struct SubresourceLayout {
|
588
|
+
/// Size of a single row in bytes (unaligned).
|
589
|
+
size_t row_pitch;
|
590
|
+
/// Size of a single row in bytes (aligned to device texture alignment).
|
591
|
+
size_t row_pitch_aligned;
|
592
|
+
/// Number of rows.
|
593
|
+
size_t row_count;
|
594
|
+
/// Number of depth slices.
|
595
|
+
size_t depth;
|
596
|
+
|
597
|
+
/// Get the total size of the subresource in bytes (unaligned).
|
598
|
+
size_t total_size() const { return row_pitch * row_count * depth; }
|
599
|
+
|
600
|
+
/// Get the total size of the subresource in bytes (aligned to device texture alignment).
|
601
|
+
size_t total_size_aligned() const { return row_pitch_aligned * row_count * depth; }
|
602
|
+
};
|
603
|
+
|
604
|
+
class SGL_API Texture : public Resource {
|
605
|
+
SGL_OBJECT(Texture)
|
606
|
+
public:
|
607
|
+
Texture(ref<Device> device, TextureDesc desc);
|
608
|
+
Texture(ref<Device> device, TextureDesc desc, gfx::ITextureResource* resource, bool deferred_release);
|
609
|
+
|
610
|
+
~Texture();
|
611
|
+
|
612
|
+
const TextureDesc& desc() const { return m_desc; }
|
613
|
+
|
614
|
+
Format format() const override { return m_desc.format; }
|
615
|
+
uint32_t width() const { return m_desc.width; }
|
616
|
+
uint32_t height() const { return m_desc.height; }
|
617
|
+
uint32_t depth() const { return m_desc.depth; }
|
618
|
+
|
619
|
+
uint32_t array_size() const { return m_desc.array_size; }
|
620
|
+
uint32_t mip_count() const { return m_desc.mip_count; }
|
621
|
+
uint32_t layer_count() const { return array_size() * (type() == ResourceType::texture_cube ? 6 : 1); }
|
622
|
+
|
623
|
+
uint32_t subresource_count() const { return layer_count() * mip_count(); }
|
624
|
+
|
625
|
+
uint32_t get_subresource_index(uint32_t mip_level, uint32_t array_slice) const
|
626
|
+
{
|
627
|
+
return mip_level + array_slice * mip_count();
|
628
|
+
}
|
629
|
+
|
630
|
+
uint32_t get_subresource_array_slice(uint32_t subresource) const { return subresource / mip_count(); }
|
631
|
+
|
632
|
+
uint32_t get_subresource_mip_level(uint32_t subresource) const { return subresource % mip_count(); }
|
633
|
+
|
634
|
+
uint32_t get_mip_width(uint32_t mip_level = 0) const
|
635
|
+
{
|
636
|
+
return (mip_level == 0) || (mip_level < mip_count()) ? std::max(1U, width() >> mip_level) : 0;
|
637
|
+
}
|
638
|
+
|
639
|
+
uint32_t get_mip_height(uint32_t mip_level = 0) const
|
640
|
+
{
|
641
|
+
return (mip_level == 0) || (mip_level < mip_count()) ? std::max(1U, height() >> mip_level) : 0;
|
642
|
+
}
|
643
|
+
|
644
|
+
uint32_t get_mip_depth(uint32_t mip_level = 0) const
|
645
|
+
{
|
646
|
+
return (mip_level == 0) || (mip_level < mip_count()) ? std::max(1U, depth() >> mip_level) : 0;
|
647
|
+
}
|
648
|
+
|
649
|
+
uint3 get_mip_dimensions(uint32_t mip_level = 0) const
|
650
|
+
{
|
651
|
+
return uint3(get_mip_width(mip_level), get_mip_height(mip_level), get_mip_depth(mip_level));
|
652
|
+
}
|
653
|
+
|
654
|
+
SubresourceLayout get_subresource_layout(uint32_t subresource) const;
|
655
|
+
|
656
|
+
/**
|
657
|
+
* Set subresource data from host memory.
|
658
|
+
*
|
659
|
+
* \param subresource Subresource index.
|
660
|
+
* \param subresource_data Subresource data.
|
661
|
+
*/
|
662
|
+
void set_subresource_data(uint32_t subresource, SubresourceData subresource_data);
|
663
|
+
|
664
|
+
/**
|
665
|
+
* Get subresource data to host memory.
|
666
|
+
* \note This will wait until the data is copied back to host memory.
|
667
|
+
*
|
668
|
+
* \param subresource Subresource index.
|
669
|
+
* \return Subresource data.
|
670
|
+
*/
|
671
|
+
OwnedSubresourceData get_subresource_data(uint32_t subresource) const;
|
672
|
+
|
673
|
+
/// Get a resource view. Views are cached and reused.
|
674
|
+
ref<ResourceView> get_view(ResourceViewDesc desc);
|
675
|
+
|
676
|
+
/// Get a shader resource view for a subresource range of the texture.
|
677
|
+
ref<ResourceView> get_srv(SubresourceRange range = SubresourceRange());
|
678
|
+
|
679
|
+
/// Get a unordered access view for a subresource range of the texture.
|
680
|
+
/// \note Only a single mip level can be bound.
|
681
|
+
ref<ResourceView> get_uav(SubresourceRange range = SubresourceRange());
|
682
|
+
|
683
|
+
/// Get a depth stencil view for a subresource range of the texture.
|
684
|
+
/// \note Only a single mip level can be bound.
|
685
|
+
ref<ResourceView> get_dsv(SubresourceRange range = SubresourceRange());
|
686
|
+
|
687
|
+
/// Get a render target view for a subresource range of the texture.
|
688
|
+
/// \note Only a single mip level can be bound.
|
689
|
+
ref<ResourceView> get_rtv(SubresourceRange range = SubresourceRange());
|
690
|
+
|
691
|
+
virtual gfx::IResource* gfx_resource() const override { return m_gfx_texture; }
|
692
|
+
gfx::ITextureResource* gfx_texture_resource() const { return m_gfx_texture; }
|
693
|
+
|
694
|
+
MemoryUsage memory_usage() const override;
|
695
|
+
|
696
|
+
ref<Bitmap> to_bitmap(uint32_t mip_level = 0, uint32_t array_slice = 0) const;
|
697
|
+
|
698
|
+
std::string to_string() const override;
|
699
|
+
|
700
|
+
private:
|
701
|
+
TextureDesc m_desc;
|
702
|
+
Slang::ComPtr<gfx::ITextureResource> m_gfx_texture;
|
703
|
+
};
|
704
|
+
|
705
|
+
} // namespace sgl
|