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.
- 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 +133 -0
- nv_sgl-0.6.0.dist-info/WHEEL +6 -0
- nv_sgl-0.6.0.dist-info/top_level.txt +1 -0
- sgl/__init__.py +15 -0
- sgl/__init__.pyi +6738 -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/libgfx.so +0 -0
- sgl/libsgl.so +0 -0
- sgl/libslang-glslang.so +0 -0
- sgl/libslang.so +0 -0
- sgl/libtevclient.a +0 -0
- sgl/math/__init__.pyi +5083 -0
- sgl/platform/__init__.pyi +102 -0
- sgl/renderdoc/__init__.pyi +51 -0
- sgl/sgl_ext.cpython-313-x86_64-linux-gnu.so +0 -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/slangpy/__init__.pyi +268 -0
- sgl/tev/__init__.pyi +108 -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 +103 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
from collections.abc import Sequence
|
2
|
+
import pathlib
|
3
|
+
from typing import overload
|
4
|
+
|
5
|
+
|
6
|
+
class FileDialogFilter:
|
7
|
+
@overload
|
8
|
+
def __init__(self) -> None: ...
|
9
|
+
|
10
|
+
@overload
|
11
|
+
def __init__(self, name: str, pattern: str) -> None: ...
|
12
|
+
|
13
|
+
@overload
|
14
|
+
def __init__(self, arg: tuple[str, str], /) -> None: ...
|
15
|
+
|
16
|
+
@property
|
17
|
+
def name(self) -> str:
|
18
|
+
"""Readable name (e.g. "JPEG")."""
|
19
|
+
|
20
|
+
@name.setter
|
21
|
+
def name(self, arg: str, /) -> None: ...
|
22
|
+
|
23
|
+
@property
|
24
|
+
def pattern(self) -> str:
|
25
|
+
"""File extension pattern (e.g. "*.jpg" or "*.jpg,*.jpeg")."""
|
26
|
+
|
27
|
+
@pattern.setter
|
28
|
+
def pattern(self, arg: str, /) -> None: ...
|
29
|
+
|
30
|
+
class MemoryStats:
|
31
|
+
@property
|
32
|
+
def rss(self) -> int:
|
33
|
+
"""Current resident/working set size in bytes."""
|
34
|
+
|
35
|
+
@property
|
36
|
+
def peak_rss(self) -> int:
|
37
|
+
"""Peak resident/working set size in bytes."""
|
38
|
+
|
39
|
+
def app_data_directory() -> pathlib.Path:
|
40
|
+
"""The application data directory."""
|
41
|
+
|
42
|
+
def choose_folder_dialog() -> pathlib.Path | None:
|
43
|
+
"""
|
44
|
+
Show a folder selection dialog.
|
45
|
+
|
46
|
+
Returns:
|
47
|
+
The selected folder path or nothing if the dialog was cancelled.
|
48
|
+
"""
|
49
|
+
|
50
|
+
def display_scale_factor() -> float:
|
51
|
+
"""The pixel scale factor of the primary display."""
|
52
|
+
|
53
|
+
def executable_directory() -> pathlib.Path:
|
54
|
+
"""The current executable directory."""
|
55
|
+
|
56
|
+
def executable_name() -> str:
|
57
|
+
"""The current executable name."""
|
58
|
+
|
59
|
+
def executable_path() -> pathlib.Path:
|
60
|
+
"""The full path to the current executable."""
|
61
|
+
|
62
|
+
def home_directory() -> pathlib.Path:
|
63
|
+
"""The home directory."""
|
64
|
+
|
65
|
+
def memory_stats() -> MemoryStats:
|
66
|
+
"""Get the current memory stats."""
|
67
|
+
|
68
|
+
def open_file_dialog(filters: Sequence[FileDialogFilter] = []) -> pathlib.Path | None:
|
69
|
+
"""
|
70
|
+
Show a file open dialog.
|
71
|
+
|
72
|
+
Parameter ``filters``:
|
73
|
+
List of file filters.
|
74
|
+
|
75
|
+
Returns:
|
76
|
+
The selected file path or nothing if the dialog was cancelled.
|
77
|
+
"""
|
78
|
+
|
79
|
+
page_size: int = 4096
|
80
|
+
|
81
|
+
def project_directory() -> pathlib.Path:
|
82
|
+
"""
|
83
|
+
The project source directory. Note that this is only valid during
|
84
|
+
development.
|
85
|
+
"""
|
86
|
+
|
87
|
+
def runtime_directory() -> pathlib.Path:
|
88
|
+
"""
|
89
|
+
The runtime directory. This is the path where the sgl runtime library
|
90
|
+
(sgl.dll, libsgl.so or libsgl.dynlib) resides.
|
91
|
+
"""
|
92
|
+
|
93
|
+
def save_file_dialog(filters: Sequence[FileDialogFilter] = []) -> pathlib.Path | None:
|
94
|
+
"""
|
95
|
+
Show a file save dialog.
|
96
|
+
|
97
|
+
Parameter ``filters``:
|
98
|
+
List of file filters.
|
99
|
+
|
100
|
+
Returns:
|
101
|
+
The selected file path or nothing if the dialog was cancelled.
|
102
|
+
"""
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import sgl
|
2
|
+
|
3
|
+
|
4
|
+
def end_frame_capture() -> bool:
|
5
|
+
"""
|
6
|
+
End capturing a frame in RenderDoc.
|
7
|
+
|
8
|
+
This function will end capturing a frame (or some partial
|
9
|
+
compute/graphics workload) in RenderDoc.
|
10
|
+
|
11
|
+
Returns:
|
12
|
+
True if the frame capture was ended successfully.
|
13
|
+
"""
|
14
|
+
|
15
|
+
def is_available() -> bool:
|
16
|
+
"""
|
17
|
+
Check if RenderDoc is available.
|
18
|
+
|
19
|
+
This is typically the case when the application is running under the
|
20
|
+
RenderDoc.
|
21
|
+
|
22
|
+
Returns:
|
23
|
+
True if RenderDoc is available.
|
24
|
+
"""
|
25
|
+
|
26
|
+
def is_frame_capturing() -> bool:
|
27
|
+
"""
|
28
|
+
Check if a frame is currently being captured in RenderDoc.
|
29
|
+
|
30
|
+
Returns:
|
31
|
+
True if a frame is currently being captured.
|
32
|
+
"""
|
33
|
+
|
34
|
+
def start_frame_capture(device: sgl.Device, window: sgl.Window | None = None) -> bool:
|
35
|
+
"""
|
36
|
+
Start capturing a frame in RenderDoc.
|
37
|
+
|
38
|
+
This function will start capturing a frame (or some partial
|
39
|
+
compute/graphics workload) in RenderDoc.
|
40
|
+
|
41
|
+
To end the frame capture, call ``end_frame_capture``().
|
42
|
+
|
43
|
+
Parameter ``device``:
|
44
|
+
The device to capture the frame for.
|
45
|
+
|
46
|
+
Parameter ``window``:
|
47
|
+
The window to capture the frame for (optional).
|
48
|
+
|
49
|
+
Returns:
|
50
|
+
True if the frame capture was started successfully.
|
51
|
+
"""
|
Binary file
|
@@ -0,0 +1,93 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
// This shader uses preprocessor macros to adapt to different texture types and layouts.
|
4
|
+
// Ideally we would use Slang's link time specialization to achieve the same effect,
|
5
|
+
// but there are some limitations in the current implementation that prevent us from doing so.
|
6
|
+
// Mainly we cannot use link time specialization to change the resource format of the source texture
|
7
|
+
// as well as the render target output type.
|
8
|
+
|
9
|
+
// This shader expects the following defines to be set externally:
|
10
|
+
// - SRC_LAYOUT (LAYOUT_TEXTURE2D, LAYOUT_TEXTURE2D_ARRAY)
|
11
|
+
// - SRC_TYPE (TYPE_FLOAT, TYPE_INT)
|
12
|
+
// - DST_TYPE (TYPE_FLOAT, TYPE_INT)
|
13
|
+
|
14
|
+
#define TYPE_FLOAT 0
|
15
|
+
#define TYPE_INT 1
|
16
|
+
|
17
|
+
#define LAYOUT_TEXTURE2D 0
|
18
|
+
#define LAYOUT_TEXTURE2D_ARRAY 1
|
19
|
+
|
20
|
+
|
21
|
+
#if SRC_TYPE == TYPE_FLOAT
|
22
|
+
typedef float4 SrcType;
|
23
|
+
#elif SRC_TYPE == TYPE_INT
|
24
|
+
typedef uint4 SrcType;
|
25
|
+
#else
|
26
|
+
#error "Invalid SRC_TYPE"
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#if DST_TYPE == TYPE_FLOAT
|
30
|
+
typedef float4 DstType;
|
31
|
+
#elif DST_TYPE == TYPE_INT
|
32
|
+
typedef uint4 DstType;
|
33
|
+
#else
|
34
|
+
#error "Invalid DST_TYPE"
|
35
|
+
#endif
|
36
|
+
|
37
|
+
#if SRC_LAYOUT == LAYOUT_TEXTURE2D
|
38
|
+
typedef Texture2D<SrcType> SrcTexture;
|
39
|
+
#elif SRC_LAYOUT == LAYOUT_TEXTURE2D_ARRAY
|
40
|
+
typedef Texture2DArray<SrcType> SrcTexture;
|
41
|
+
#else
|
42
|
+
#error "Invalid SRC_LAYOUT"
|
43
|
+
#endif
|
44
|
+
|
45
|
+
extension Texture2D
|
46
|
+
{
|
47
|
+
SrcType sample(SamplerState s, float2 uv)
|
48
|
+
{
|
49
|
+
#if SRC_TYPE == TYPE_FLOAT
|
50
|
+
return this.Sample(s, uv);
|
51
|
+
#elif SRC_TYPE == TYPE_INT
|
52
|
+
return asuint(this.Sample(s, uv));
|
53
|
+
#endif
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
extension Texture2DArray
|
58
|
+
{
|
59
|
+
SrcType sample(SamplerState s, float2 uv)
|
60
|
+
{
|
61
|
+
#if SRC_TYPE == TYPE_FLOAT
|
62
|
+
return this.Sample(s, float3(uv, 0));
|
63
|
+
#elif SRC_TYPE == TYPE_INT
|
64
|
+
return asuint(this.Sample(s, float3(uv, 0)));
|
65
|
+
#endif
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
SrcTexture src;
|
70
|
+
SamplerState sampler;
|
71
|
+
|
72
|
+
struct VSOut {
|
73
|
+
float4 pos : SV_Position;
|
74
|
+
float2 uv : UV;
|
75
|
+
};
|
76
|
+
|
77
|
+
[shader("vertex")]
|
78
|
+
VSOut vs_main(uint vid: SV_VertexID)
|
79
|
+
{
|
80
|
+
VSOut vs_out;
|
81
|
+
vs_out.uv = float2((vid << 1) & 2, vid & 2);
|
82
|
+
vs_out.pos = float4(vs_out.uv * float2(2, -2) + float2(-1, 1), 0, 1);
|
83
|
+
return vs_out;
|
84
|
+
}
|
85
|
+
|
86
|
+
[shader("fragment")]
|
87
|
+
DstType fs_main(VSOut vs_out)
|
88
|
+
: SV_Target
|
89
|
+
{
|
90
|
+
float2 uv = vs_out.uv;
|
91
|
+
let value = src.sample(sampler, uv);
|
92
|
+
return reinterpret<DstType>(value);
|
93
|
+
}
|
@@ -0,0 +1,445 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#ifndef SGL_ENABLE_PRINT
|
4
|
+
#define SGL_ENABLE_PRINT 0
|
5
|
+
#endif
|
6
|
+
|
7
|
+
namespace detail {
|
8
|
+
|
9
|
+
enum class Kind {
|
10
|
+
scalar,
|
11
|
+
vector,
|
12
|
+
matrix,
|
13
|
+
};
|
14
|
+
|
15
|
+
/// Printable primitive types.
|
16
|
+
enum class Type {
|
17
|
+
boolean,
|
18
|
+
int8,
|
19
|
+
int16,
|
20
|
+
int32,
|
21
|
+
int64,
|
22
|
+
uint8,
|
23
|
+
uint16,
|
24
|
+
uint32,
|
25
|
+
uint64,
|
26
|
+
float16,
|
27
|
+
float32,
|
28
|
+
float64,
|
29
|
+
};
|
30
|
+
|
31
|
+
struct Layout {
|
32
|
+
Kind kind;
|
33
|
+
Type type;
|
34
|
+
uint rows;
|
35
|
+
uint cols;
|
36
|
+
};
|
37
|
+
|
38
|
+
/// Interface to print output.
|
39
|
+
interface IPrintOutput {
|
40
|
+
/// Write a message and reserve space for writing the arguments.
|
41
|
+
/// \param fmt The format string.
|
42
|
+
/// \param arg_count The number of arguments.
|
43
|
+
/// \param total_data_count The total number of data elements in all arguments.
|
44
|
+
/// \param[out] offset Offset into the output buffer. This needs to be passed to \c write_arg calls.
|
45
|
+
/// \return True if the message was written successfully, false if there was not enough space.
|
46
|
+
bool write_msg(String fmt, uint arg_count, uint total_data_count, out uint offset);
|
47
|
+
|
48
|
+
/// Write a single printable argument.
|
49
|
+
/// \param[in,out] offset Offset into the output buffer.
|
50
|
+
void write_arg(inout uint offset, IPrintable arg);
|
51
|
+
};
|
52
|
+
|
53
|
+
/// Interface for printable types.
|
54
|
+
interface IPrintable {
|
55
|
+
[ForceInline]
|
56
|
+
static Layout printable_layout();
|
57
|
+
|
58
|
+
/// The total number of data elements (each element is a \c uint).
|
59
|
+
[ForceInline]
|
60
|
+
static uint printable_data_count();
|
61
|
+
|
62
|
+
/// Get a printable data element.
|
63
|
+
/// \param index The index of the data element in range [0..printable_data_count()).
|
64
|
+
[ForceInline]
|
65
|
+
uint get_printable_data(uint index);
|
66
|
+
};
|
67
|
+
|
68
|
+
// clang-format off
|
69
|
+
extension bool : IPrintable {
|
70
|
+
[ForceInline]
|
71
|
+
static Layout printable_layout() { return Layout(Kind::scalar, Type::boolean); }
|
72
|
+
[ForceInline]
|
73
|
+
static uint printable_data_count() { return 1; }
|
74
|
+
[ForceInline]
|
75
|
+
uint get_printable_data(uint index) { return asuint(this); }
|
76
|
+
};
|
77
|
+
|
78
|
+
extension int8_t : IPrintable {
|
79
|
+
[ForceInline]
|
80
|
+
static Layout printable_layout() { return Layout(Kind::scalar, Type::int8); }
|
81
|
+
[ForceInline]
|
82
|
+
static uint printable_data_count() { return 1; }
|
83
|
+
[ForceInline]
|
84
|
+
uint get_printable_data(uint index) { return asuint(this); }
|
85
|
+
};
|
86
|
+
|
87
|
+
extension int16_t : IPrintable {
|
88
|
+
[ForceInline]
|
89
|
+
static Layout printable_layout() { return Layout(Kind::scalar, Type::int16); }
|
90
|
+
[ForceInline]
|
91
|
+
static uint printable_data_count() { return 1; }
|
92
|
+
[ForceInline]
|
93
|
+
uint get_printable_data(uint index) { return asuint(this); }
|
94
|
+
};
|
95
|
+
|
96
|
+
extension int32_t : IPrintable {
|
97
|
+
[ForceInline]
|
98
|
+
static Layout printable_layout() { return Layout(Kind::scalar, Type::int32); }
|
99
|
+
[ForceInline]
|
100
|
+
static uint printable_data_count() { return 1; }
|
101
|
+
[ForceInline]
|
102
|
+
uint get_printable_data(uint index) { return asuint(this); }
|
103
|
+
};
|
104
|
+
|
105
|
+
extension int64_t : IPrintable {
|
106
|
+
[ForceInline]
|
107
|
+
static Layout printable_layout() { return Layout(Kind::scalar, Type::int64); }
|
108
|
+
[ForceInline]
|
109
|
+
static uint printable_data_count() { return 2; }
|
110
|
+
[ForceInline]
|
111
|
+
uint get_printable_data(uint index) { return index == 0 ? uint(this & 0xffffffff) : uint(this >> 32); }
|
112
|
+
};
|
113
|
+
|
114
|
+
extension uint8_t : IPrintable {
|
115
|
+
[ForceInline]
|
116
|
+
static Layout printable_layout() { return Layout(Kind::scalar, Type::uint8); }
|
117
|
+
[ForceInline]
|
118
|
+
static uint printable_data_count() { return 1; }
|
119
|
+
[ForceInline]
|
120
|
+
uint get_printable_data(uint index) { return this; }
|
121
|
+
};
|
122
|
+
|
123
|
+
extension uint16_t : IPrintable {
|
124
|
+
[ForceInline]
|
125
|
+
static Layout printable_layout() { return Layout(Kind::scalar, Type::uint16); }
|
126
|
+
[ForceInline]
|
127
|
+
static uint printable_data_count() { return 1; }
|
128
|
+
[ForceInline]
|
129
|
+
uint get_printable_data(uint index) { return this; }
|
130
|
+
};
|
131
|
+
|
132
|
+
extension uint32_t : IPrintable {
|
133
|
+
[ForceInline]
|
134
|
+
static Layout printable_layout() { return Layout(Kind::scalar, Type::uint32); }
|
135
|
+
[ForceInline]
|
136
|
+
static uint printable_data_count() { return 1; }
|
137
|
+
[ForceInline]
|
138
|
+
uint get_printable_data(uint index) { return this; }
|
139
|
+
};
|
140
|
+
|
141
|
+
extension uint64_t : IPrintable {
|
142
|
+
[ForceInline]
|
143
|
+
static Layout printable_layout() { return Layout(Kind::scalar, Type::uint64); }
|
144
|
+
[ForceInline]
|
145
|
+
static uint printable_data_count() { return 2; }
|
146
|
+
[ForceInline]
|
147
|
+
uint get_printable_data(uint index) { return index == 0 ? uint(this & 0xffffffffu) : uint(this >> 32); }
|
148
|
+
};
|
149
|
+
|
150
|
+
extension float16_t : IPrintable {
|
151
|
+
[ForceInline]
|
152
|
+
static Layout printable_layout() { return Layout(Kind::scalar, Type::float16); }
|
153
|
+
[ForceInline]
|
154
|
+
static uint printable_data_count() { return 1; }
|
155
|
+
[ForceInline]
|
156
|
+
uint get_printable_data(uint index) { return f32tof16(this); }
|
157
|
+
}
|
158
|
+
|
159
|
+
extension float : IPrintable {
|
160
|
+
[ForceInline]
|
161
|
+
static Layout printable_layout() { return Layout(Kind::scalar, Type::float32); }
|
162
|
+
[ForceInline]
|
163
|
+
static uint printable_data_count() { return 1; }
|
164
|
+
[ForceInline]
|
165
|
+
uint get_printable_data(uint index) { return asuint(this); }
|
166
|
+
}
|
167
|
+
|
168
|
+
extension double : IPrintable {
|
169
|
+
[ForceInline]
|
170
|
+
static Layout printable_layout() { return Layout(Kind::scalar, Type::float64); }
|
171
|
+
[ForceInline]
|
172
|
+
static uint printable_data_count() { return 2; }
|
173
|
+
[ForceInline]
|
174
|
+
uint get_printable_data(uint index) { uint2 data; asuint(this, data.x, data.y); return data[index]; }
|
175
|
+
}
|
176
|
+
|
177
|
+
__generic<T : IPrintable, let N : int>
|
178
|
+
extension vector<T, N> : IPrintable {
|
179
|
+
[ForceInline]
|
180
|
+
static Layout printable_layout() { return Layout(Kind::vector, T::printable_layout().type, N); }
|
181
|
+
[ForceInline]
|
182
|
+
static uint printable_data_count() { return N * T::printable_data_count(); }
|
183
|
+
[ForceInline]
|
184
|
+
uint get_printable_data(uint index) { return this[index / T::printable_data_count()].get_printable_data(index % T::printable_data_count()); }
|
185
|
+
};
|
186
|
+
|
187
|
+
__generic<T : IPrintable, let R : int, let C : int, let L : int>
|
188
|
+
extension matrix<T, R, C, L> : IPrintable {
|
189
|
+
[ForceInline]
|
190
|
+
static Layout printable_layout() { return Layout(Kind::matrix, T::printable_layout().type, R, C); }
|
191
|
+
static uint printable_data_count() { return R * C * T::printable_data_count(); }
|
192
|
+
[ForceInline]
|
193
|
+
uint get_printable_data(uint index) {
|
194
|
+
uint element_index = index / T::printable_data_count();
|
195
|
+
uint row = element_index / C;
|
196
|
+
uint col = element_index % C;
|
197
|
+
return this[row][col].get_printable_data(index % T::printable_data_count());
|
198
|
+
}
|
199
|
+
};
|
200
|
+
// clang-format on
|
201
|
+
|
202
|
+
[ForceInline]
|
203
|
+
void print(IPrintOutput output, String fmt)
|
204
|
+
{
|
205
|
+
uint offset;
|
206
|
+
output.write_msg(fmt, 0, 0, offset);
|
207
|
+
}
|
208
|
+
|
209
|
+
[ForceInline]
|
210
|
+
void print(IPrintOutput output, String fmt, IPrintable arg0)
|
211
|
+
{
|
212
|
+
uint total_data_count = arg0.printable_data_count();
|
213
|
+
uint offset;
|
214
|
+
if (!output.write_msg(fmt, 1, total_data_count, offset))
|
215
|
+
return;
|
216
|
+
output.write_arg(offset, arg0);
|
217
|
+
}
|
218
|
+
|
219
|
+
[ForceInline]
|
220
|
+
void print(IPrintOutput output, String fmt, IPrintable arg0, IPrintable arg1)
|
221
|
+
{
|
222
|
+
uint total_data_count = arg0.printable_data_count() + arg1.printable_data_count();
|
223
|
+
uint offset;
|
224
|
+
if (!output.write_msg(fmt, 2, total_data_count, offset))
|
225
|
+
return;
|
226
|
+
output.write_arg(offset, arg0);
|
227
|
+
output.write_arg(offset, arg1);
|
228
|
+
}
|
229
|
+
|
230
|
+
[ForceInline]
|
231
|
+
void print(IPrintOutput output, String fmt, IPrintable arg0, IPrintable arg1, IPrintable arg2)
|
232
|
+
{
|
233
|
+
uint total_data_count = arg0.printable_data_count() + arg1.printable_data_count() + arg2.printable_data_count();
|
234
|
+
uint offset;
|
235
|
+
if (!output.write_msg(fmt, 3, total_data_count, offset))
|
236
|
+
return;
|
237
|
+
output.write_arg(offset, arg0);
|
238
|
+
output.write_arg(offset, arg1);
|
239
|
+
output.write_arg(offset, arg2);
|
240
|
+
}
|
241
|
+
|
242
|
+
[ForceInline]
|
243
|
+
void print(IPrintOutput output, String fmt, IPrintable arg0, IPrintable arg1, IPrintable arg2, IPrintable arg3)
|
244
|
+
{
|
245
|
+
uint total_data_count = arg0.printable_data_count() + arg1.printable_data_count() + arg2.printable_data_count()
|
246
|
+
+ arg3.printable_data_count();
|
247
|
+
uint offset;
|
248
|
+
if (!output.write_msg(fmt, 4, total_data_count, offset))
|
249
|
+
return;
|
250
|
+
output.write_arg(offset, arg0);
|
251
|
+
output.write_arg(offset, arg1);
|
252
|
+
output.write_arg(offset, arg2);
|
253
|
+
output.write_arg(offset, arg3);
|
254
|
+
}
|
255
|
+
|
256
|
+
[ForceInline]
|
257
|
+
void print(
|
258
|
+
IPrintOutput output,
|
259
|
+
String fmt,
|
260
|
+
IPrintable arg0,
|
261
|
+
IPrintable arg1,
|
262
|
+
IPrintable arg2,
|
263
|
+
IPrintable arg3,
|
264
|
+
IPrintable arg4
|
265
|
+
)
|
266
|
+
{
|
267
|
+
uint total_data_count = arg0.printable_data_count() + arg1.printable_data_count() + arg2.printable_data_count()
|
268
|
+
+ arg3.printable_data_count() + arg4.printable_data_count();
|
269
|
+
;
|
270
|
+
uint offset;
|
271
|
+
if (!output.write_msg(fmt, 5, total_data_count, offset))
|
272
|
+
return;
|
273
|
+
output.write_arg(offset, arg0);
|
274
|
+
output.write_arg(offset, arg1);
|
275
|
+
output.write_arg(offset, arg2);
|
276
|
+
output.write_arg(offset, arg3);
|
277
|
+
output.write_arg(offset, arg4);
|
278
|
+
}
|
279
|
+
|
280
|
+
[ForceInline]
|
281
|
+
void print(
|
282
|
+
IPrintOutput output,
|
283
|
+
String fmt,
|
284
|
+
IPrintable arg0,
|
285
|
+
IPrintable arg1,
|
286
|
+
IPrintable arg2,
|
287
|
+
IPrintable arg3,
|
288
|
+
IPrintable arg4,
|
289
|
+
IPrintable arg5
|
290
|
+
)
|
291
|
+
{
|
292
|
+
uint total_data_count = arg0.printable_data_count() + arg1.printable_data_count() + arg2.printable_data_count()
|
293
|
+
+ arg3.printable_data_count() + arg4.printable_data_count() + arg5.printable_data_count();
|
294
|
+
;
|
295
|
+
uint offset;
|
296
|
+
if (!output.write_msg(fmt, 6, total_data_count, offset))
|
297
|
+
return;
|
298
|
+
output.write_arg(offset, arg0);
|
299
|
+
output.write_arg(offset, arg1);
|
300
|
+
output.write_arg(offset, arg2);
|
301
|
+
output.write_arg(offset, arg3);
|
302
|
+
output.write_arg(offset, arg4);
|
303
|
+
output.write_arg(offset, arg5);
|
304
|
+
}
|
305
|
+
|
306
|
+
[ForceInline]
|
307
|
+
void print(
|
308
|
+
IPrintOutput output,
|
309
|
+
String fmt,
|
310
|
+
IPrintable arg0,
|
311
|
+
IPrintable arg1,
|
312
|
+
IPrintable arg2,
|
313
|
+
IPrintable arg3,
|
314
|
+
IPrintable arg4,
|
315
|
+
IPrintable arg5,
|
316
|
+
IPrintable arg6
|
317
|
+
)
|
318
|
+
{
|
319
|
+
uint total_data_count = arg0.printable_data_count() + arg1.printable_data_count() + arg2.printable_data_count()
|
320
|
+
+ arg3.printable_data_count() + arg4.printable_data_count() + arg5.printable_data_count()
|
321
|
+
+ arg6.printable_data_count();
|
322
|
+
;
|
323
|
+
uint offset;
|
324
|
+
if (!output.write_msg(fmt, 7, total_data_count, offset))
|
325
|
+
return;
|
326
|
+
output.write_arg(offset, arg0);
|
327
|
+
output.write_arg(offset, arg1);
|
328
|
+
output.write_arg(offset, arg2);
|
329
|
+
output.write_arg(offset, arg3);
|
330
|
+
output.write_arg(offset, arg4);
|
331
|
+
output.write_arg(offset, arg5);
|
332
|
+
output.write_arg(offset, arg6);
|
333
|
+
}
|
334
|
+
|
335
|
+
[ForceInline]
|
336
|
+
void print(
|
337
|
+
IPrintOutput output,
|
338
|
+
String fmt,
|
339
|
+
IPrintable arg0,
|
340
|
+
IPrintable arg1,
|
341
|
+
IPrintable arg2,
|
342
|
+
IPrintable arg3,
|
343
|
+
IPrintable arg4,
|
344
|
+
IPrintable arg5,
|
345
|
+
IPrintable arg6,
|
346
|
+
IPrintable arg7
|
347
|
+
)
|
348
|
+
{
|
349
|
+
uint total_data_count = arg0.printable_data_count() + arg1.printable_data_count() + arg2.printable_data_count()
|
350
|
+
+ arg3.printable_data_count() + arg4.printable_data_count() + arg5.printable_data_count()
|
351
|
+
+ arg6.printable_data_count() + arg7.printable_data_count();
|
352
|
+
;
|
353
|
+
uint offset;
|
354
|
+
if (!output.write_msg(fmt, 8, total_data_count, offset))
|
355
|
+
return;
|
356
|
+
output.write_arg(offset, arg0);
|
357
|
+
output.write_arg(offset, arg1);
|
358
|
+
output.write_arg(offset, arg2);
|
359
|
+
output.write_arg(offset, arg3);
|
360
|
+
output.write_arg(offset, arg4);
|
361
|
+
output.write_arg(offset, arg5);
|
362
|
+
output.write_arg(offset, arg6);
|
363
|
+
output.write_arg(offset, arg7);
|
364
|
+
}
|
365
|
+
|
366
|
+
struct DebugPrinter : IPrintOutput {
|
367
|
+
|
368
|
+
/// Single buffer that contains the print messages.
|
369
|
+
/// The first 4 bytes of the buffer store the size of the data following.
|
370
|
+
RWByteAddressBuffer buffer;
|
371
|
+
|
372
|
+
[ForceInline]
|
373
|
+
bool write_msg(String fmt, uint arg_count, uint total_data_count, out uint offset)
|
374
|
+
{
|
375
|
+
uint buffer_capacity;
|
376
|
+
buffer.GetDimensions(buffer_capacity);
|
377
|
+
|
378
|
+
// Compute the size of the message.
|
379
|
+
uint size = (3 + arg_count + total_data_count) * sizeof(uint);
|
380
|
+
|
381
|
+
// Reserve space for the message.
|
382
|
+
offset = 0;
|
383
|
+
buffer.InterlockedAdd(0, size, offset);
|
384
|
+
offset += 4;
|
385
|
+
if (offset + size > buffer_capacity - 4) {
|
386
|
+
// Write sentinel value indicating that we have a buffer overlow.
|
387
|
+
buffer.Store(offset, 0xffffffff);
|
388
|
+
return false;
|
389
|
+
}
|
390
|
+
|
391
|
+
buffer.Store(offset, size);
|
392
|
+
buffer.Store(offset + 4, getStringHash(fmt));
|
393
|
+
buffer.Store(offset + 8, arg_count);
|
394
|
+
offset += 12;
|
395
|
+
return true;
|
396
|
+
}
|
397
|
+
|
398
|
+
[ForceInline]
|
399
|
+
void write_arg(inout uint offset, IPrintable arg)
|
400
|
+
{
|
401
|
+
Layout layout = arg.printable_layout();
|
402
|
+
uint size = (1 + arg.printable_data_count()) * sizeof(uint);
|
403
|
+
// Header: [kind:4][type:4][rows:4][cols:4][size:16]
|
404
|
+
uint header
|
405
|
+
= (uint(layout.kind) << 28) | (uint(layout.type) << 24) | (layout.rows << 20) | (layout.cols << 16) | size;
|
406
|
+
buffer.Store(offset, header);
|
407
|
+
for (uint i = 0; i < arg.printable_data_count(); ++i)
|
408
|
+
buffer.Store(offset + (i + 1) * 4, arg.get_printable_data(i));
|
409
|
+
offset += size;
|
410
|
+
}
|
411
|
+
};
|
412
|
+
|
413
|
+
} // namespace detail
|
414
|
+
|
415
|
+
#if SGL_ENABLE_PRINT
|
416
|
+
|
417
|
+
ParameterBlock<detail::DebugPrinter> g_debug_printer;
|
418
|
+
|
419
|
+
// clang-format off
|
420
|
+
[ForceInline] void print(String fmt) { detail::print(g_debug_printer, fmt); }
|
421
|
+
[ForceInline] void print(String fmt, detail::IPrintable arg0) { detail::print(g_debug_printer, fmt, arg0); }
|
422
|
+
[ForceInline] void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1) { detail::print(g_debug_printer, fmt, arg0, arg1); }
|
423
|
+
[ForceInline] void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1, detail::IPrintable arg2) { detail::print(g_debug_printer, fmt, arg0, arg1, arg2); }
|
424
|
+
[ForceInline] void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1, detail::IPrintable arg2, detail::IPrintable arg3) { detail::print(g_debug_printer, fmt, arg0, arg1, arg2, arg3); }
|
425
|
+
[ForceInline] void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1, detail::IPrintable arg2, detail::IPrintable arg3, detail::IPrintable arg4) { detail::print(g_debug_printer, fmt, arg0, arg1, arg2, arg3, arg4); }
|
426
|
+
[ForceInline] void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1, detail::IPrintable arg2, detail::IPrintable arg3, detail::IPrintable arg4, detail::IPrintable arg5) { detail::print(g_debug_printer, fmt, arg0, arg1, arg2, arg3, arg4, arg5); }
|
427
|
+
[ForceInline] void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1, detail::IPrintable arg2, detail::IPrintable arg3, detail::IPrintable arg4, detail::IPrintable arg5, detail::IPrintable arg6) { detail::print(g_debug_printer, fmt, arg0, arg1, arg2, arg3, arg4, arg5, arg6); }
|
428
|
+
[ForceInline] void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1, detail::IPrintable arg2, detail::IPrintable arg3, detail::IPrintable arg4, detail::IPrintable arg5, detail::IPrintable arg6, detail::IPrintable arg7) { detail::print(g_debug_printer, fmt, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7); }
|
429
|
+
// clang-format on
|
430
|
+
|
431
|
+
#else // SGL_ENABLE_PRINT
|
432
|
+
|
433
|
+
// clang-format off
|
434
|
+
void print(String fmt) { }
|
435
|
+
void print(String fmt, detail::IPrintable arg0) { }
|
436
|
+
void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1) { }
|
437
|
+
void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1, detail::IPrintable arg2) { }
|
438
|
+
void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1, detail::IPrintable arg2, detail::IPrintable arg3) { }
|
439
|
+
void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1, detail::IPrintable arg2, detail::IPrintable arg3, detail::IPrintable arg4) { }
|
440
|
+
void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1, detail::IPrintable arg2, detail::IPrintable arg3, detail::IPrintable arg4, detail::IPrintable arg5) { }
|
441
|
+
void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1, detail::IPrintable arg2, detail::IPrintable arg3, detail::IPrintable arg4, detail::IPrintable arg5, detail::IPrintable arg6) { }
|
442
|
+
void print(String fmt, detail::IPrintable arg0, detail::IPrintable arg1, detail::IPrintable arg2, detail::IPrintable arg3, detail::IPrintable arg4, detail::IPrintable arg5, detail::IPrintable arg6, detail::IPrintable arg7) { }
|
443
|
+
// clang-format on
|
444
|
+
|
445
|
+
#endif // SGL_ENABLE_PRINT
|