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.
Files changed (142) 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 +142 -0
  5. nv_sgl-0.6.0.dist-info/WHEEL +5 -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/d3d12/D3D12Core.dll +0 -0
  10. sgl/d3d12/d3d12SDKLayers.dll +0 -0
  11. sgl/dxcompiler.dll +0 -0
  12. sgl/dxil.dll +0 -0
  13. sgl/gfx.dll +0 -0
  14. sgl/include/sgl/app/app.h +113 -0
  15. sgl/include/sgl/core/bitmap.h +302 -0
  16. sgl/include/sgl/core/crypto.h +89 -0
  17. sgl/include/sgl/core/data_type.h +46 -0
  18. sgl/include/sgl/core/dds_file.h +103 -0
  19. sgl/include/sgl/core/enum.h +201 -0
  20. sgl/include/sgl/core/error.h +161 -0
  21. sgl/include/sgl/core/file_stream.h +77 -0
  22. sgl/include/sgl/core/file_system_watcher.h +141 -0
  23. sgl/include/sgl/core/format.h +36 -0
  24. sgl/include/sgl/core/fwd.h +90 -0
  25. sgl/include/sgl/core/hash.h +45 -0
  26. sgl/include/sgl/core/input.h +522 -0
  27. sgl/include/sgl/core/logger.h +214 -0
  28. sgl/include/sgl/core/macros.h +184 -0
  29. sgl/include/sgl/core/maths.h +45 -0
  30. sgl/include/sgl/core/memory_mapped_file.h +112 -0
  31. sgl/include/sgl/core/memory_mapped_file_stream.h +32 -0
  32. sgl/include/sgl/core/memory_stream.h +74 -0
  33. sgl/include/sgl/core/object.h +683 -0
  34. sgl/include/sgl/core/platform.h +239 -0
  35. sgl/include/sgl/core/plugin.h +331 -0
  36. sgl/include/sgl/core/resolver.h +39 -0
  37. sgl/include/sgl/core/short_vector.h +141 -0
  38. sgl/include/sgl/core/static_vector.h +111 -0
  39. sgl/include/sgl/core/stream.h +54 -0
  40. sgl/include/sgl/core/string.h +276 -0
  41. sgl/include/sgl/core/struct.h +360 -0
  42. sgl/include/sgl/core/thread.h +28 -0
  43. sgl/include/sgl/core/timer.h +52 -0
  44. sgl/include/sgl/core/traits.h +15 -0
  45. sgl/include/sgl/core/type_utils.h +19 -0
  46. sgl/include/sgl/core/window.h +177 -0
  47. sgl/include/sgl/device/agility_sdk.h +24 -0
  48. sgl/include/sgl/device/blit.h +88 -0
  49. sgl/include/sgl/device/buffer_cursor.h +162 -0
  50. sgl/include/sgl/device/command.h +539 -0
  51. sgl/include/sgl/device/cuda_api.h +766 -0
  52. sgl/include/sgl/device/cuda_interop.h +39 -0
  53. sgl/include/sgl/device/cuda_utils.h +107 -0
  54. sgl/include/sgl/device/cursor_utils.h +129 -0
  55. sgl/include/sgl/device/device.h +668 -0
  56. sgl/include/sgl/device/device_resource.h +37 -0
  57. sgl/include/sgl/device/fence.h +91 -0
  58. sgl/include/sgl/device/formats.h +330 -0
  59. sgl/include/sgl/device/framebuffer.h +85 -0
  60. sgl/include/sgl/device/fwd.h +164 -0
  61. sgl/include/sgl/device/helpers.h +20 -0
  62. sgl/include/sgl/device/hot_reload.h +75 -0
  63. sgl/include/sgl/device/input_layout.h +74 -0
  64. sgl/include/sgl/device/kernel.h +69 -0
  65. sgl/include/sgl/device/memory_heap.h +155 -0
  66. sgl/include/sgl/device/native_formats.h +342 -0
  67. sgl/include/sgl/device/native_handle.h +73 -0
  68. sgl/include/sgl/device/native_handle_traits.h +65 -0
  69. sgl/include/sgl/device/pipeline.h +138 -0
  70. sgl/include/sgl/device/print.h +45 -0
  71. sgl/include/sgl/device/python/cursor_utils.h +853 -0
  72. sgl/include/sgl/device/query.h +52 -0
  73. sgl/include/sgl/device/raytracing.h +84 -0
  74. sgl/include/sgl/device/reflection.h +1254 -0
  75. sgl/include/sgl/device/resource.h +705 -0
  76. sgl/include/sgl/device/sampler.h +57 -0
  77. sgl/include/sgl/device/shader.h +516 -0
  78. sgl/include/sgl/device/shader_cursor.h +85 -0
  79. sgl/include/sgl/device/shader_object.h +94 -0
  80. sgl/include/sgl/device/shader_offset.h +67 -0
  81. sgl/include/sgl/device/shared_handle.h +12 -0
  82. sgl/include/sgl/device/slang_utils.h +54 -0
  83. sgl/include/sgl/device/swapchain.h +74 -0
  84. sgl/include/sgl/device/types.h +782 -0
  85. sgl/include/sgl/math/colorspace.h +56 -0
  86. sgl/include/sgl/math/constants.h +7 -0
  87. sgl/include/sgl/math/float16.h +146 -0
  88. sgl/include/sgl/math/matrix.h +6 -0
  89. sgl/include/sgl/math/matrix_math.h +746 -0
  90. sgl/include/sgl/math/matrix_types.h +207 -0
  91. sgl/include/sgl/math/python/primitivetype.h +33 -0
  92. sgl/include/sgl/math/quaternion.h +6 -0
  93. sgl/include/sgl/math/quaternion_math.h +484 -0
  94. sgl/include/sgl/math/quaternion_types.h +83 -0
  95. sgl/include/sgl/math/ray.h +47 -0
  96. sgl/include/sgl/math/scalar_math.h +249 -0
  97. sgl/include/sgl/math/scalar_types.h +107 -0
  98. sgl/include/sgl/math/vector.h +6 -0
  99. sgl/include/sgl/math/vector_math.h +1796 -0
  100. sgl/include/sgl/math/vector_types.h +336 -0
  101. sgl/include/sgl/python/nanobind.h +489 -0
  102. sgl/include/sgl/python/py_doc.h +11600 -0
  103. sgl/include/sgl/python/sgl_ext_pch.h +8 -0
  104. sgl/include/sgl/sgl.h +21 -0
  105. sgl/include/sgl/sgl_pch.h +6 -0
  106. sgl/include/sgl/stl/bit.h +377 -0
  107. sgl/include/sgl/tests/testing.h +54 -0
  108. sgl/include/sgl/ui/fwd.h +34 -0
  109. sgl/include/sgl/ui/imgui_config.h +43 -0
  110. sgl/include/sgl/ui/ui.h +71 -0
  111. sgl/include/sgl/ui/widgets.h +918 -0
  112. sgl/include/sgl/utils/python/slangpy.h +366 -0
  113. sgl/include/sgl/utils/renderdoc.h +50 -0
  114. sgl/include/sgl/utils/slangpy.h +153 -0
  115. sgl/include/sgl/utils/tev.h +93 -0
  116. sgl/include/sgl/utils/texture_loader.h +106 -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.dll +0 -0
  121. sgl/sgl_ext.cp313-win_amd64.pyd +0 -0
  122. sgl/shaders/nvapi/nvHLSLExtns.h +2315 -0
  123. sgl/shaders/nvapi/nvHLSLExtnsInternal.h +758 -0
  124. sgl/shaders/nvapi/nvShaderExtnEnums.h +142 -0
  125. sgl/shaders/sgl/device/blit.slang +93 -0
  126. sgl/shaders/sgl/device/nvapi.slang +5 -0
  127. sgl/shaders/sgl/device/nvapi.slangh +7 -0
  128. sgl/shaders/sgl/device/print.slang +445 -0
  129. sgl/shaders/sgl/math/constants.slang +4 -0
  130. sgl/shaders/sgl/math/ray.slang +29 -0
  131. sgl/shaders/sgl/ui/imgui.slang +49 -0
  132. sgl/slang-glslang.dll +0 -0
  133. sgl/slang-llvm.dll +0 -0
  134. sgl/slang-rt.dll +0 -0
  135. sgl/slang.dll +0 -0
  136. sgl/slangpy/__init__.pyi +268 -0
  137. sgl/tev/__init__.pyi +108 -0
  138. sgl/tevclient.lib +0 -0
  139. sgl/thread/__init__.pyi +4 -0
  140. sgl/ui/__init__.pyi +1118 -0
  141. share/cmake/tevclient/tevclient-config-release.cmake +19 -0
  142. share/cmake/tevclient/tevclient-config.cmake +108 -0
@@ -0,0 +1,142 @@
1
+ /*********************************************************************************************************\
2
+ |* *|
3
+ |* SPDX-FileCopyrightText: Copyright (c) 2019-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. *|
4
+ |* SPDX-License-Identifier: MIT *|
5
+ |* *|
6
+ |* Permission is hereby granted, free of charge, to any person obtaining a *|
7
+ |* copy of this software and associated documentation files (the "Software"), *|
8
+ |* to deal in the Software without restriction, including without limitation *|
9
+ |* the rights to use, copy, modify, merge, publish, distribute, sublicense, *|
10
+ |* and/or sell copies of the Software, and to permit persons to whom the *|
11
+ |* Software is furnished to do so, subject to the following conditions: *|
12
+ |* *|
13
+ |* The above copyright notice and this permission notice shall be included in *|
14
+ |* all copies or substantial portions of the Software. *|
15
+ |* *|
16
+ |* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *|
17
+ |* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *|
18
+ |* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *|
19
+ |* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *|
20
+ |* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *|
21
+ |* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *|
22
+ |* DEALINGS IN THE SOFTWARE. *|
23
+ |* *|
24
+ |* *|
25
+ \*********************************************************************************************************/
26
+
27
+ ////////////////////////////////////////////////////////////////////////////////
28
+ ////////////////////////// NVIDIA SHADER EXTENSIONS ////////////////////////////
29
+ ////////////////////////////////////////////////////////////////////////////////
30
+
31
+ // This file can be included both from HLSL shader code as well as C++ code.
32
+ // The app should call NvAPI_D3D11_IsNvShaderExtnOpCodeSupported() / NvAPI_D3D12_IsNvShaderExtnOpCodeSupported()
33
+ // to check for support for every nv shader extension opcode it plans to use
34
+
35
+
36
+
37
+ //----------------------------------------------------------------------------//
38
+ //---------------------------- NV Shader Extn Version -----------------------//
39
+ //----------------------------------------------------------------------------//
40
+ #define NV_SHADER_EXTN_VERSION 1
41
+
42
+ //----------------------------------------------------------------------------//
43
+ //---------------------------- Misc constants --------------------------------//
44
+ //----------------------------------------------------------------------------//
45
+ #define NV_WARP_SIZE 32
46
+ #define NV_WARP_SIZE_LOG2 5
47
+
48
+ //----------------------------------------------------------------------------//
49
+ //---------------------------- opCode constants ------------------------------//
50
+ //----------------------------------------------------------------------------//
51
+
52
+
53
+ #define NV_EXTN_OP_SHFL 1
54
+ #define NV_EXTN_OP_SHFL_UP 2
55
+ #define NV_EXTN_OP_SHFL_DOWN 3
56
+ #define NV_EXTN_OP_SHFL_XOR 4
57
+
58
+ #define NV_EXTN_OP_VOTE_ALL 5
59
+ #define NV_EXTN_OP_VOTE_ANY 6
60
+ #define NV_EXTN_OP_VOTE_BALLOT 7
61
+
62
+ #define NV_EXTN_OP_GET_LANE_ID 8
63
+ #define NV_EXTN_OP_FP16_ATOMIC 12
64
+ #define NV_EXTN_OP_FP32_ATOMIC 13
65
+
66
+ #define NV_EXTN_OP_GET_SPECIAL 19
67
+
68
+ #define NV_EXTN_OP_UINT64_ATOMIC 20
69
+
70
+ #define NV_EXTN_OP_MATCH_ANY 21
71
+
72
+ // FOOTPRINT - For Sample and SampleBias
73
+ #define NV_EXTN_OP_FOOTPRINT 28
74
+ #define NV_EXTN_OP_FOOTPRINT_BIAS 29
75
+
76
+ #define NV_EXTN_OP_GET_SHADING_RATE 30
77
+
78
+ // FOOTPRINT - For SampleLevel and SampleGrad
79
+ #define NV_EXTN_OP_FOOTPRINT_LEVEL 31
80
+ #define NV_EXTN_OP_FOOTPRINT_GRAD 32
81
+
82
+ // SHFL Generic
83
+ #define NV_EXTN_OP_SHFL_GENERIC 33
84
+
85
+ #define NV_EXTN_OP_VPRS_EVAL_ATTRIB_AT_SAMPLE 51
86
+ #define NV_EXTN_OP_VPRS_EVAL_ATTRIB_SNAPPED 52
87
+
88
+ // HitObject API
89
+ #define NV_EXTN_OP_HIT_OBJECT_TRACE_RAY 67
90
+ #define NV_EXTN_OP_HIT_OBJECT_MAKE_HIT 68
91
+ #define NV_EXTN_OP_HIT_OBJECT_MAKE_HIT_WITH_RECORD_INDEX 69
92
+ #define NV_EXTN_OP_HIT_OBJECT_MAKE_MISS 70
93
+ #define NV_EXTN_OP_HIT_OBJECT_REORDER_THREAD 71
94
+ #define NV_EXTN_OP_HIT_OBJECT_INVOKE 72
95
+ #define NV_EXTN_OP_HIT_OBJECT_IS_MISS 73
96
+ #define NV_EXTN_OP_HIT_OBJECT_GET_INSTANCE_ID 74
97
+ #define NV_EXTN_OP_HIT_OBJECT_GET_INSTANCE_INDEX 75
98
+ #define NV_EXTN_OP_HIT_OBJECT_GET_PRIMITIVE_INDEX 76
99
+ #define NV_EXTN_OP_HIT_OBJECT_GET_GEOMETRY_INDEX 77
100
+ #define NV_EXTN_OP_HIT_OBJECT_GET_HIT_KIND 78
101
+ #define NV_EXTN_OP_HIT_OBJECT_GET_RAY_DESC 79
102
+ #define NV_EXTN_OP_HIT_OBJECT_GET_ATTRIBUTES 80
103
+ #define NV_EXTN_OP_HIT_OBJECT_GET_SHADER_TABLE_INDEX 81
104
+ #define NV_EXTN_OP_HIT_OBJECT_LOAD_LOCAL_ROOT_TABLE_CONSTANT 82
105
+ #define NV_EXTN_OP_HIT_OBJECT_IS_HIT 83
106
+ #define NV_EXTN_OP_HIT_OBJECT_IS_NOP 84
107
+ #define NV_EXTN_OP_HIT_OBJECT_MAKE_NOP 85
108
+
109
+ // Micro-map API
110
+ #define NV_EXTN_OP_RT_TRIANGLE_OBJECT_POSITIONS 86
111
+ #define NV_EXTN_OP_RT_MICRO_TRIANGLE_OBJECT_POSITIONS 87
112
+ #define NV_EXTN_OP_RT_MICRO_TRIANGLE_BARYCENTRICS 88
113
+ #define NV_EXTN_OP_RT_IS_MICRO_TRIANGLE_HIT 89
114
+ #define NV_EXTN_OP_RT_IS_BACK_FACING 90
115
+ #define NV_EXTN_OP_RT_MICRO_VERTEX_OBJECT_POSITION 91
116
+ #define NV_EXTN_OP_RT_MICRO_VERTEX_BARYCENTRICS 92
117
+
118
+ //----------------------------------------------------------------------------//
119
+ //-------------------- GET_SPECIAL subOpCode constants -----------------------//
120
+ //----------------------------------------------------------------------------//
121
+ #define NV_SPECIALOP_THREADLTMASK 4
122
+ #define NV_SPECIALOP_FOOTPRINT_SINGLELOD_PRED 5
123
+ #define NV_SPECIALOP_GLOBAL_TIMER_LO 9
124
+ #define NV_SPECIALOP_GLOBAL_TIMER_HI 10
125
+
126
+ //----------------------------------------------------------------------------//
127
+ //----------------------------- Texture Types -------------------------------//
128
+ //----------------------------------------------------------------------------//
129
+ #define NV_EXTN_TEXTURE_1D 2
130
+ #define NV_EXTN_TEXTURE_1D_ARRAY 3
131
+ #define NV_EXTN_TEXTURE_2D 4
132
+ #define NV_EXTN_TEXTURE_2D_ARRAY 5
133
+ #define NV_EXTN_TEXTURE_3D 6
134
+ #define NV_EXTN_TEXTURE_CUBE 7
135
+ #define NV_EXTN_TEXTURE_CUBE_ARRAY 8
136
+
137
+
138
+ //---------------------------------------------------------------------------//
139
+ //----------------FOOTPRINT Enums for NvFootprint* extns---------------------//
140
+ //---------------------------------------------------------------------------//
141
+ #define NV_EXTN_FOOTPRINT_MODE_FINE 0
142
+ #define NV_EXTN_FOOTPRINT_MODE_COARSE 1
@@ -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,5 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ #if SGL_ENABLE_NVAPI
4
+ #include "nvapi/nvHLSLExtns.h"
5
+ #endif
@@ -0,0 +1,7 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ #pragma once
4
+ #if SGL_ENABLE_NVAPI
5
+ #include "nvapi/nvShaderExtnEnums.h"
6
+ #endif
7
+ import sgl.device.nvapi;
@@ -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