gstaichi 2.1.1rc3__cp310-cp310-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. gstaichi/CHANGELOG.md +4 -0
  2. gstaichi/__init__.py +40 -0
  3. gstaichi/_funcs.py +706 -0
  4. gstaichi/_kernels.py +420 -0
  5. gstaichi/_lib/__init__.py +3 -0
  6. gstaichi/_lib/core/__init__.py +0 -0
  7. gstaichi/_lib/core/gstaichi_python.cpython-310-darwin.so +0 -0
  8. gstaichi/_lib/core/gstaichi_python.pyi +2909 -0
  9. gstaichi/_lib/core/py.typed +0 -0
  10. gstaichi/_lib/runtime/libMoltenVK.dylib +0 -0
  11. gstaichi/_lib/runtime/runtime_arm64.bc +0 -0
  12. gstaichi/_lib/utils.py +243 -0
  13. gstaichi/_logging.py +131 -0
  14. gstaichi/_snode/__init__.py +5 -0
  15. gstaichi/_snode/fields_builder.py +187 -0
  16. gstaichi/_snode/snode_tree.py +34 -0
  17. gstaichi/_test_tools/__init__.py +18 -0
  18. gstaichi/_test_tools/dataclass_test_tools.py +36 -0
  19. gstaichi/_test_tools/load_kernel_string.py +30 -0
  20. gstaichi/_test_tools/textwrap2.py +6 -0
  21. gstaichi/_version.py +1 -0
  22. gstaichi/_version_check.py +100 -0
  23. gstaichi/ad/__init__.py +3 -0
  24. gstaichi/ad/_ad.py +530 -0
  25. gstaichi/algorithms/__init__.py +3 -0
  26. gstaichi/algorithms/_algorithms.py +117 -0
  27. gstaichi/assets/.git +1 -0
  28. gstaichi/assets/Go-Regular.ttf +0 -0
  29. gstaichi/assets/static/imgs/ti_gallery.png +0 -0
  30. gstaichi/examples/lcg_python.py +26 -0
  31. gstaichi/examples/lcg_taichi.py +34 -0
  32. gstaichi/examples/minimal.py +28 -0
  33. gstaichi/experimental.py +16 -0
  34. gstaichi/lang/__init__.py +50 -0
  35. gstaichi/lang/_dataclass_util.py +31 -0
  36. gstaichi/lang/_fast_caching/__init__.py +3 -0
  37. gstaichi/lang/_fast_caching/args_hasher.py +110 -0
  38. gstaichi/lang/_fast_caching/config_hasher.py +30 -0
  39. gstaichi/lang/_fast_caching/fast_caching_types.py +21 -0
  40. gstaichi/lang/_fast_caching/function_hasher.py +57 -0
  41. gstaichi/lang/_fast_caching/hash_utils.py +11 -0
  42. gstaichi/lang/_fast_caching/python_side_cache.py +52 -0
  43. gstaichi/lang/_fast_caching/src_hasher.py +75 -0
  44. gstaichi/lang/_kernel_impl_dataclass.py +212 -0
  45. gstaichi/lang/_ndarray.py +352 -0
  46. gstaichi/lang/_ndrange.py +152 -0
  47. gstaichi/lang/_template_mapper.py +195 -0
  48. gstaichi/lang/_texture.py +172 -0
  49. gstaichi/lang/_wrap_inspect.py +215 -0
  50. gstaichi/lang/any_array.py +99 -0
  51. gstaichi/lang/ast/__init__.py +5 -0
  52. gstaichi/lang/ast/ast_transformer.py +1323 -0
  53. gstaichi/lang/ast/ast_transformer_utils.py +346 -0
  54. gstaichi/lang/ast/ast_transformers/__init__.py +0 -0
  55. gstaichi/lang/ast/ast_transformers/call_transformer.py +324 -0
  56. gstaichi/lang/ast/ast_transformers/function_def_transformer.py +304 -0
  57. gstaichi/lang/ast/checkers.py +106 -0
  58. gstaichi/lang/ast/symbol_resolver.py +57 -0
  59. gstaichi/lang/ast/transform.py +9 -0
  60. gstaichi/lang/common_ops.py +310 -0
  61. gstaichi/lang/exception.py +80 -0
  62. gstaichi/lang/expr.py +180 -0
  63. gstaichi/lang/field.py +428 -0
  64. gstaichi/lang/impl.py +1243 -0
  65. gstaichi/lang/kernel_arguments.py +155 -0
  66. gstaichi/lang/kernel_impl.py +1341 -0
  67. gstaichi/lang/matrix.py +1835 -0
  68. gstaichi/lang/matrix_ops.py +341 -0
  69. gstaichi/lang/matrix_ops_utils.py +190 -0
  70. gstaichi/lang/mesh.py +687 -0
  71. gstaichi/lang/misc.py +782 -0
  72. gstaichi/lang/ops.py +1494 -0
  73. gstaichi/lang/runtime_ops.py +13 -0
  74. gstaichi/lang/shell.py +35 -0
  75. gstaichi/lang/simt/__init__.py +5 -0
  76. gstaichi/lang/simt/block.py +94 -0
  77. gstaichi/lang/simt/grid.py +7 -0
  78. gstaichi/lang/simt/subgroup.py +191 -0
  79. gstaichi/lang/simt/warp.py +96 -0
  80. gstaichi/lang/snode.py +489 -0
  81. gstaichi/lang/source_builder.py +150 -0
  82. gstaichi/lang/struct.py +810 -0
  83. gstaichi/lang/util.py +312 -0
  84. gstaichi/linalg/__init__.py +8 -0
  85. gstaichi/linalg/matrixfree_cg.py +310 -0
  86. gstaichi/linalg/sparse_cg.py +59 -0
  87. gstaichi/linalg/sparse_matrix.py +303 -0
  88. gstaichi/linalg/sparse_solver.py +123 -0
  89. gstaichi/math/__init__.py +11 -0
  90. gstaichi/math/_complex.py +205 -0
  91. gstaichi/math/mathimpl.py +886 -0
  92. gstaichi/profiler/__init__.py +6 -0
  93. gstaichi/profiler/kernel_metrics.py +260 -0
  94. gstaichi/profiler/kernel_profiler.py +586 -0
  95. gstaichi/profiler/memory_profiler.py +15 -0
  96. gstaichi/profiler/scoped_profiler.py +36 -0
  97. gstaichi/sparse/__init__.py +3 -0
  98. gstaichi/sparse/_sparse_grid.py +77 -0
  99. gstaichi/tools/__init__.py +12 -0
  100. gstaichi/tools/diagnose.py +117 -0
  101. gstaichi/tools/np2ply.py +364 -0
  102. gstaichi/tools/vtk.py +38 -0
  103. gstaichi/types/__init__.py +19 -0
  104. gstaichi/types/annotations.py +52 -0
  105. gstaichi/types/compound_types.py +71 -0
  106. gstaichi/types/enums.py +49 -0
  107. gstaichi/types/ndarray_type.py +169 -0
  108. gstaichi/types/primitive_types.py +206 -0
  109. gstaichi/types/quant.py +88 -0
  110. gstaichi/types/texture_type.py +85 -0
  111. gstaichi/types/utils.py +11 -0
  112. gstaichi-2.1.1rc3.data/data/include/GLFW/glfw3.h +6389 -0
  113. gstaichi-2.1.1rc3.data/data/include/GLFW/glfw3native.h +594 -0
  114. gstaichi-2.1.1rc3.data/data/include/spirv-tools/instrument.hpp +268 -0
  115. gstaichi-2.1.1rc3.data/data/include/spirv-tools/libspirv.h +907 -0
  116. gstaichi-2.1.1rc3.data/data/include/spirv-tools/libspirv.hpp +375 -0
  117. gstaichi-2.1.1rc3.data/data/include/spirv-tools/linker.hpp +97 -0
  118. gstaichi-2.1.1rc3.data/data/include/spirv-tools/optimizer.hpp +970 -0
  119. gstaichi-2.1.1rc3.data/data/include/spirv_cross/GLSL.std.450.h +114 -0
  120. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv.h +2568 -0
  121. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv.hpp +2579 -0
  122. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cfg.hpp +168 -0
  123. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_common.hpp +1920 -0
  124. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cpp.hpp +93 -0
  125. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cross.hpp +1171 -0
  126. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cross_c.h +1074 -0
  127. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cross_containers.hpp +754 -0
  128. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cross_error_handling.hpp +94 -0
  129. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cross_parsed_ir.hpp +256 -0
  130. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cross_util.hpp +37 -0
  131. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_glsl.hpp +1001 -0
  132. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_hlsl.hpp +406 -0
  133. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_msl.hpp +1273 -0
  134. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_parser.hpp +103 -0
  135. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_reflect.hpp +91 -0
  136. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools/SPIRV-ToolsConfig.cmake +5 -0
  137. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools/SPIRV-ToolsTarget-release.cmake +29 -0
  138. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools/SPIRV-ToolsTarget.cmake +114 -0
  139. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-diff/SPIRV-Tools-diffConfig.cmake +5 -0
  140. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-diff/SPIRV-Tools-diffTargets-release.cmake +19 -0
  141. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-diff/SPIRV-Tools-diffTargets.cmake +123 -0
  142. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-link/SPIRV-Tools-linkConfig.cmake +5 -0
  143. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-link/SPIRV-Tools-linkTargets-release.cmake +19 -0
  144. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-link/SPIRV-Tools-linkTargets.cmake +123 -0
  145. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-lint/SPIRV-Tools-lintConfig.cmake +5 -0
  146. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-lint/SPIRV-Tools-lintTargets-release.cmake +19 -0
  147. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-lint/SPIRV-Tools-lintTargets.cmake +123 -0
  148. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-opt/SPIRV-Tools-optConfig.cmake +5 -0
  149. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-opt/SPIRV-Tools-optTargets-release.cmake +19 -0
  150. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-opt/SPIRV-Tools-optTargets.cmake +123 -0
  151. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-reduce/SPIRV-Tools-reduceConfig.cmake +5 -0
  152. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-reduce/SPIRV-Tools-reduceTarget-release.cmake +19 -0
  153. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-reduce/SPIRV-Tools-reduceTarget.cmake +123 -0
  154. gstaichi-2.1.1rc3.data/data/lib/cmake/glfw3/glfw3Config.cmake +3 -0
  155. gstaichi-2.1.1rc3.data/data/lib/cmake/glfw3/glfw3ConfigVersion.cmake +65 -0
  156. gstaichi-2.1.1rc3.data/data/lib/cmake/glfw3/glfw3Targets-release.cmake +19 -0
  157. gstaichi-2.1.1rc3.data/data/lib/cmake/glfw3/glfw3Targets.cmake +107 -0
  158. gstaichi-2.1.1rc3.data/data/lib/libSPIRV-Tools-shared.dylib +0 -0
  159. gstaichi-2.1.1rc3.data/data/share/spirv_cross_c/cmake/spirv_cross_cConfig-release.cmake +19 -0
  160. gstaichi-2.1.1rc3.data/data/share/spirv_cross_c/cmake/spirv_cross_cConfig.cmake +123 -0
  161. gstaichi-2.1.1rc3.data/data/share/spirv_cross_core/cmake/spirv_cross_coreConfig-release.cmake +19 -0
  162. gstaichi-2.1.1rc3.data/data/share/spirv_cross_core/cmake/spirv_cross_coreConfig.cmake +106 -0
  163. gstaichi-2.1.1rc3.data/data/share/spirv_cross_cpp/cmake/spirv_cross_cppConfig-release.cmake +19 -0
  164. gstaichi-2.1.1rc3.data/data/share/spirv_cross_cpp/cmake/spirv_cross_cppConfig.cmake +123 -0
  165. gstaichi-2.1.1rc3.data/data/share/spirv_cross_glsl/cmake/spirv_cross_glslConfig-release.cmake +19 -0
  166. gstaichi-2.1.1rc3.data/data/share/spirv_cross_glsl/cmake/spirv_cross_glslConfig.cmake +123 -0
  167. gstaichi-2.1.1rc3.data/data/share/spirv_cross_hlsl/cmake/spirv_cross_hlslConfig-release.cmake +19 -0
  168. gstaichi-2.1.1rc3.data/data/share/spirv_cross_hlsl/cmake/spirv_cross_hlslConfig.cmake +123 -0
  169. gstaichi-2.1.1rc3.data/data/share/spirv_cross_msl/cmake/spirv_cross_mslConfig-release.cmake +19 -0
  170. gstaichi-2.1.1rc3.data/data/share/spirv_cross_msl/cmake/spirv_cross_mslConfig.cmake +123 -0
  171. gstaichi-2.1.1rc3.data/data/share/spirv_cross_reflect/cmake/spirv_cross_reflectConfig-release.cmake +19 -0
  172. gstaichi-2.1.1rc3.data/data/share/spirv_cross_reflect/cmake/spirv_cross_reflectConfig.cmake +106 -0
  173. gstaichi-2.1.1rc3.data/data/share/spirv_cross_util/cmake/spirv_cross_utilConfig-release.cmake +19 -0
  174. gstaichi-2.1.1rc3.data/data/share/spirv_cross_util/cmake/spirv_cross_utilConfig.cmake +123 -0
  175. gstaichi-2.1.1rc3.dist-info/METADATA +106 -0
  176. gstaichi-2.1.1rc3.dist-info/RECORD +179 -0
  177. gstaichi-2.1.1rc3.dist-info/WHEEL +5 -0
  178. gstaichi-2.1.1rc3.dist-info/licenses/LICENSE +201 -0
  179. gstaichi-2.1.1rc3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,94 @@
1
+ /*
2
+ * Copyright 2015-2021 Arm Limited
3
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*
19
+ * At your option, you may choose to accept this material under either:
20
+ * 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
21
+ * 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
22
+ */
23
+
24
+ #ifndef SPIRV_CROSS_ERROR_HANDLING
25
+ #define SPIRV_CROSS_ERROR_HANDLING
26
+
27
+ #include <stdio.h>
28
+ #include <stdlib.h>
29
+ #include <string>
30
+ #ifndef SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
31
+ #include <stdexcept>
32
+ #endif
33
+
34
+ #ifdef SPIRV_CROSS_NAMESPACE_OVERRIDE
35
+ #define SPIRV_CROSS_NAMESPACE SPIRV_CROSS_NAMESPACE_OVERRIDE
36
+ #else
37
+ #define SPIRV_CROSS_NAMESPACE spirv_cross
38
+ #endif
39
+
40
+ namespace SPIRV_CROSS_NAMESPACE
41
+ {
42
+ #ifdef SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
43
+ #if !defined(_MSC_VER) || defined(__clang__)
44
+ [[noreturn]]
45
+ #elif defined(_MSC_VER)
46
+ __declspec(noreturn)
47
+ #endif
48
+ inline void
49
+ report_and_abort(const std::string &msg)
50
+ {
51
+ #ifdef NDEBUG
52
+ (void)msg;
53
+ #else
54
+ fprintf(stderr, "There was a compiler error: %s\n", msg.c_str());
55
+ #endif
56
+ fflush(stderr);
57
+ abort();
58
+ }
59
+
60
+ #define SPIRV_CROSS_THROW(x) report_and_abort(x)
61
+ #else
62
+ class CompilerError : public std::runtime_error
63
+ {
64
+ public:
65
+ explicit CompilerError(const std::string &str)
66
+ : std::runtime_error(str)
67
+ {
68
+ }
69
+ };
70
+
71
+ #define SPIRV_CROSS_THROW(x) throw CompilerError(x)
72
+ #endif
73
+
74
+ // MSVC 2013 does not have noexcept. We need this for Variant to get move constructor to work correctly
75
+ // instead of copy constructor.
76
+ // MSVC 2013 ignores that move constructors cannot throw in std::vector, so just don't define it.
77
+ #if defined(_MSC_VER) && _MSC_VER < 1900
78
+ #define SPIRV_CROSS_NOEXCEPT
79
+ #else
80
+ #define SPIRV_CROSS_NOEXCEPT noexcept
81
+ #endif
82
+
83
+ #if __cplusplus >= 201402l
84
+ #define SPIRV_CROSS_DEPRECATED(reason) [[deprecated(reason)]]
85
+ #elif defined(__GNUC__)
86
+ #define SPIRV_CROSS_DEPRECATED(reason) __attribute__((deprecated))
87
+ #elif defined(_MSC_VER)
88
+ #define SPIRV_CROSS_DEPRECATED(reason) __declspec(deprecated(reason))
89
+ #else
90
+ #define SPIRV_CROSS_DEPRECATED(reason)
91
+ #endif
92
+ } // namespace SPIRV_CROSS_NAMESPACE
93
+
94
+ #endif
@@ -0,0 +1,256 @@
1
+ /*
2
+ * Copyright 2018-2021 Arm Limited
3
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*
19
+ * At your option, you may choose to accept this material under either:
20
+ * 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
21
+ * 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
22
+ */
23
+
24
+ #ifndef SPIRV_CROSS_PARSED_IR_HPP
25
+ #define SPIRV_CROSS_PARSED_IR_HPP
26
+
27
+ #include "spirv_common.hpp"
28
+ #include <stdint.h>
29
+ #include <unordered_map>
30
+
31
+ namespace SPIRV_CROSS_NAMESPACE
32
+ {
33
+
34
+ // This data structure holds all information needed to perform cross-compilation and reflection.
35
+ // It is the output of the Parser, but any implementation could create this structure.
36
+ // It is intentionally very "open" and struct-like with some helper functions to deal with decorations.
37
+ // Parser is the reference implementation of how this data structure should be filled in.
38
+
39
+ class ParsedIR
40
+ {
41
+ private:
42
+ // This must be destroyed after the "ids" vector.
43
+ std::unique_ptr<ObjectPoolGroup> pool_group;
44
+
45
+ public:
46
+ ParsedIR();
47
+
48
+ // Due to custom allocations from object pools, we cannot use a default copy constructor.
49
+ ParsedIR(const ParsedIR &other);
50
+ ParsedIR &operator=(const ParsedIR &other);
51
+
52
+ // Moves are unproblematic, but we need to implement it anyways, since MSVC 2013 does not understand
53
+ // how to default-implement these.
54
+ ParsedIR(ParsedIR &&other) SPIRV_CROSS_NOEXCEPT;
55
+ ParsedIR &operator=(ParsedIR &&other) SPIRV_CROSS_NOEXCEPT;
56
+
57
+ // Resizes ids, meta and block_meta.
58
+ void set_id_bounds(uint32_t bounds);
59
+
60
+ // The raw SPIR-V, instructions and opcodes refer to this by offset + count.
61
+ std::vector<uint32_t> spirv;
62
+
63
+ // Holds various data structures which inherit from IVariant.
64
+ SmallVector<Variant> ids;
65
+
66
+ // Various meta data for IDs, decorations, names, etc.
67
+ std::unordered_map<ID, Meta> meta;
68
+
69
+ // Holds all IDs which have a certain type.
70
+ // This is needed so we can iterate through a specific kind of resource quickly,
71
+ // and in-order of module declaration.
72
+ SmallVector<ID> ids_for_type[TypeCount];
73
+
74
+ // Special purpose lists which contain a union of types.
75
+ // This is needed so we can declare specialization constants and structs in an interleaved fashion,
76
+ // among other things.
77
+ // Constants can be undef or of struct type, and struct array sizes can use specialization constants.
78
+ SmallVector<ID> ids_for_constant_undef_or_type;
79
+ SmallVector<ID> ids_for_constant_or_variable;
80
+
81
+ // We need to keep track of the width the Ops that contains a type for the
82
+ // OpSwitch instruction, since this one doesn't contains the type in the
83
+ // instruction itself. And in some case we need to cast the condition to
84
+ // wider types. We only need the width to do the branch fixup since the
85
+ // type check itself can be done at runtime
86
+ std::unordered_map<ID, uint32_t> load_type_width;
87
+
88
+ // Declared capabilities and extensions in the SPIR-V module.
89
+ // Not really used except for reflection at the moment.
90
+ SmallVector<spv::Capability> declared_capabilities;
91
+ SmallVector<std::string> declared_extensions;
92
+
93
+ // Meta data about blocks. The cross-compiler needs to query if a block is either of these types.
94
+ // It is a bitset as there can be more than one tag per block.
95
+ enum BlockMetaFlagBits
96
+ {
97
+ BLOCK_META_LOOP_HEADER_BIT = 1 << 0,
98
+ BLOCK_META_CONTINUE_BIT = 1 << 1,
99
+ BLOCK_META_LOOP_MERGE_BIT = 1 << 2,
100
+ BLOCK_META_SELECTION_MERGE_BIT = 1 << 3,
101
+ BLOCK_META_MULTISELECT_MERGE_BIT = 1 << 4
102
+ };
103
+ using BlockMetaFlags = uint8_t;
104
+ SmallVector<BlockMetaFlags> block_meta;
105
+ std::unordered_map<BlockID, BlockID> continue_block_to_loop_header;
106
+
107
+ // Normally, we'd stick SPIREntryPoint in ids array, but it conflicts with SPIRFunction.
108
+ // Entry points can therefore be seen as some sort of meta structure.
109
+ std::unordered_map<FunctionID, SPIREntryPoint> entry_points;
110
+ FunctionID default_entry_point = 0;
111
+
112
+ struct Source
113
+ {
114
+ uint32_t version = 0;
115
+ bool es = false;
116
+ bool known = false;
117
+ bool hlsl = false;
118
+
119
+ Source() = default;
120
+ };
121
+
122
+ Source source;
123
+
124
+ spv::AddressingModel addressing_model = spv::AddressingModelMax;
125
+ spv::MemoryModel memory_model = spv::MemoryModelMax;
126
+
127
+ // Decoration handling methods.
128
+ // Can be useful for simple "raw" reflection.
129
+ // However, most members are here because the Parser needs most of these,
130
+ // and might as well just have the whole suite of decoration/name handling in one place.
131
+ void set_name(ID id, const std::string &name);
132
+ const std::string &get_name(ID id) const;
133
+ void set_decoration(ID id, spv::Decoration decoration, uint32_t argument = 0);
134
+ void set_decoration_string(ID id, spv::Decoration decoration, const std::string &argument);
135
+ bool has_decoration(ID id, spv::Decoration decoration) const;
136
+ uint32_t get_decoration(ID id, spv::Decoration decoration) const;
137
+ const std::string &get_decoration_string(ID id, spv::Decoration decoration) const;
138
+ const Bitset &get_decoration_bitset(ID id) const;
139
+ void unset_decoration(ID id, spv::Decoration decoration);
140
+
141
+ // Decoration handling methods (for members of a struct).
142
+ void set_member_name(TypeID id, uint32_t index, const std::string &name);
143
+ const std::string &get_member_name(TypeID id, uint32_t index) const;
144
+ void set_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration, uint32_t argument = 0);
145
+ void set_member_decoration_string(TypeID id, uint32_t index, spv::Decoration decoration,
146
+ const std::string &argument);
147
+ uint32_t get_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration) const;
148
+ const std::string &get_member_decoration_string(TypeID id, uint32_t index, spv::Decoration decoration) const;
149
+ bool has_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration) const;
150
+ const Bitset &get_member_decoration_bitset(TypeID id, uint32_t index) const;
151
+ void unset_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration);
152
+
153
+ void mark_used_as_array_length(ID id);
154
+ uint32_t increase_bound_by(uint32_t count);
155
+ Bitset get_buffer_block_flags(const SPIRVariable &var) const;
156
+ Bitset get_buffer_block_type_flags(const SPIRType &type) const;
157
+
158
+ void add_typed_id(Types type, ID id);
159
+ void remove_typed_id(Types type, ID id);
160
+
161
+ class LoopLock
162
+ {
163
+ public:
164
+ explicit LoopLock(uint32_t *counter);
165
+ LoopLock(const LoopLock &) = delete;
166
+ void operator=(const LoopLock &) = delete;
167
+ LoopLock(LoopLock &&other) SPIRV_CROSS_NOEXCEPT;
168
+ LoopLock &operator=(LoopLock &&other) SPIRV_CROSS_NOEXCEPT;
169
+ ~LoopLock();
170
+
171
+ private:
172
+ uint32_t *lock;
173
+ };
174
+
175
+ // This must be held while iterating over a type ID array.
176
+ // It is undefined if someone calls set<>() while we're iterating over a data structure, so we must
177
+ // make sure that this case is avoided.
178
+
179
+ // If we have a hard lock, it is an error to call set<>(), and an exception is thrown.
180
+ // If we have a soft lock, we silently ignore any additions to the typed arrays.
181
+ // This should only be used for physical ID remapping where we need to create an ID, but we will never
182
+ // care about iterating over them.
183
+ LoopLock create_loop_hard_lock() const;
184
+ LoopLock create_loop_soft_lock() const;
185
+
186
+ template <typename T, typename Op>
187
+ void for_each_typed_id(const Op &op)
188
+ {
189
+ auto loop_lock = create_loop_hard_lock();
190
+ for (auto &id : ids_for_type[T::type])
191
+ {
192
+ if (ids[id].get_type() == static_cast<Types>(T::type))
193
+ op(id, get<T>(id));
194
+ }
195
+ }
196
+
197
+ template <typename T, typename Op>
198
+ void for_each_typed_id(const Op &op) const
199
+ {
200
+ auto loop_lock = create_loop_hard_lock();
201
+ for (auto &id : ids_for_type[T::type])
202
+ {
203
+ if (ids[id].get_type() == static_cast<Types>(T::type))
204
+ op(id, get<T>(id));
205
+ }
206
+ }
207
+
208
+ template <typename T>
209
+ void reset_all_of_type()
210
+ {
211
+ reset_all_of_type(static_cast<Types>(T::type));
212
+ }
213
+
214
+ void reset_all_of_type(Types type);
215
+
216
+ Meta *find_meta(ID id);
217
+ const Meta *find_meta(ID id) const;
218
+
219
+ const std::string &get_empty_string() const
220
+ {
221
+ return empty_string;
222
+ }
223
+
224
+ void make_constant_null(uint32_t id, uint32_t type, bool add_to_typed_id_set);
225
+
226
+ void fixup_reserved_names();
227
+
228
+ static void sanitize_underscores(std::string &str);
229
+ static void sanitize_identifier(std::string &str, bool member, bool allow_reserved_prefixes);
230
+ static bool is_globally_reserved_identifier(std::string &str, bool allow_reserved_prefixes);
231
+
232
+ uint32_t get_spirv_version() const;
233
+
234
+ private:
235
+ template <typename T>
236
+ T &get(uint32_t id)
237
+ {
238
+ return variant_get<T>(ids[id]);
239
+ }
240
+
241
+ template <typename T>
242
+ const T &get(uint32_t id) const
243
+ {
244
+ return variant_get<T>(ids[id]);
245
+ }
246
+
247
+ mutable uint32_t loop_iteration_depth_hard = 0;
248
+ mutable uint32_t loop_iteration_depth_soft = 0;
249
+ std::string empty_string;
250
+ Bitset cleared_bitset;
251
+
252
+ std::unordered_set<uint32_t> meta_needing_name_fixup;
253
+ };
254
+ } // namespace SPIRV_CROSS_NAMESPACE
255
+
256
+ #endif
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright 2015-2021 Arm Limited
3
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*
19
+ * At your option, you may choose to accept this material under either:
20
+ * 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
21
+ * 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
22
+ */
23
+
24
+ #ifndef SPIRV_CROSS_UTIL_HPP
25
+ #define SPIRV_CROSS_UTIL_HPP
26
+
27
+ #include "spirv_cross.hpp"
28
+
29
+ namespace spirv_cross_util
30
+ {
31
+ void rename_interface_variable(SPIRV_CROSS_NAMESPACE::Compiler &compiler,
32
+ const SPIRV_CROSS_NAMESPACE::SmallVector<SPIRV_CROSS_NAMESPACE::Resource> &resources,
33
+ uint32_t location, const std::string &name);
34
+ void inherit_combined_sampler_bindings(SPIRV_CROSS_NAMESPACE::Compiler &compiler);
35
+ } // namespace spirv_cross_util
36
+
37
+ #endif