diff options
| author | 2021-02-14 22:46:40 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:22 -0400 | |
| commit | 1b0cf2309c760c1cb97a230a1572f8e87f84444a (patch) | |
| tree | 6316825f65565b4c764b7851d061be0776a89974 /src/shader_recompiler/backend/spirv/emit_spirv.h | |
| parent | shader: Support SSA loops on IR (diff) | |
| download | yuzu-1b0cf2309c760c1cb97a230a1572f8e87f84444a.tar.gz yuzu-1b0cf2309c760c1cb97a230a1572f8e87f84444a.tar.xz yuzu-1b0cf2309c760c1cb97a230a1572f8e87f84444a.zip | |
shader: Add support for forward declarations
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_spirv.h')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_spirv.h | 40 |
1 files changed, 1 insertions, 39 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.h b/src/shader_recompiler/backend/spirv/emit_spirv.h index 6b09757d1..7d76377b5 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv.h | |||
| @@ -6,8 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | #include <sirit/sirit.h> | 7 | #include <sirit/sirit.h> |
| 8 | 8 | ||
| 9 | #include <boost/container/flat_map.hpp> | ||
| 10 | |||
| 11 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 12 | #include "shader_recompiler/frontend/ir/microinstruction.h" | 10 | #include "shader_recompiler/frontend/ir/microinstruction.h" |
| 13 | #include "shader_recompiler/frontend/ir/program.h" | 11 | #include "shader_recompiler/frontend/ir/program.h" |
| @@ -16,37 +14,6 @@ namespace Shader::Backend::SPIRV { | |||
| 16 | 14 | ||
| 17 | using Sirit::Id; | 15 | using Sirit::Id; |
| 18 | 16 | ||
| 19 | class DefMap { | ||
| 20 | public: | ||
| 21 | void Define(IR::Inst* inst, Id def_id) { | ||
| 22 | const InstInfo info{.use_count{inst->UseCount()}, .def_id{def_id}}; | ||
| 23 | const auto it{map.insert(map.end(), std::make_pair(inst, info))}; | ||
| 24 | if (it == map.end()) { | ||
| 25 | throw LogicError("Defining already defined instruction"); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | [[nodiscard]] Id Consume(IR::Inst* inst) { | ||
| 30 | const auto it{map.find(inst)}; | ||
| 31 | if (it == map.end()) { | ||
| 32 | throw LogicError("Consuming undefined instruction"); | ||
| 33 | } | ||
| 34 | const Id def_id{it->second.def_id}; | ||
| 35 | if (--it->second.use_count == 0) { | ||
| 36 | map.erase(it); | ||
| 37 | } | ||
| 38 | return def_id; | ||
| 39 | } | ||
| 40 | |||
| 41 | private: | ||
| 42 | struct InstInfo { | ||
| 43 | int use_count; | ||
| 44 | Id def_id; | ||
| 45 | }; | ||
| 46 | |||
| 47 | boost::container::flat_map<IR::Inst*, InstInfo> map; | ||
| 48 | }; | ||
| 49 | |||
| 50 | class VectorTypes { | 17 | class VectorTypes { |
| 51 | public: | 18 | public: |
| 52 | void Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { | 19 | void Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { |
| @@ -76,7 +43,7 @@ public: | |||
| 76 | 43 | ||
| 77 | [[nodiscard]] Id Def(const IR::Value& value) { | 44 | [[nodiscard]] Id Def(const IR::Value& value) { |
| 78 | if (!value.IsImmediate()) { | 45 | if (!value.IsImmediate()) { |
| 79 | return def_map.Consume(value.Inst()); | 46 | return value.Inst()->Definition<Id>(); |
| 80 | } | 47 | } |
| 81 | switch (value.Type()) { | 48 | switch (value.Type()) { |
| 82 | case IR::Type::U1: | 49 | case IR::Type::U1: |
| @@ -90,10 +57,6 @@ public: | |||
| 90 | } | 57 | } |
| 91 | } | 58 | } |
| 92 | 59 | ||
| 93 | void Define(IR::Inst* inst, Id def_id) { | ||
| 94 | def_map.Define(inst, def_id); | ||
| 95 | } | ||
| 96 | |||
| 97 | [[nodiscard]] Id BlockLabel(IR::Block* block) const { | 60 | [[nodiscard]] Id BlockLabel(IR::Block* block) const { |
| 98 | const auto it{std::ranges::lower_bound(block_label_map, block, {}, | 61 | const auto it{std::ranges::lower_bound(block_label_map, block, {}, |
| 99 | &std::pair<IR::Block*, Id>::first)}; | 62 | &std::pair<IR::Block*, Id>::first)}; |
| @@ -117,7 +80,6 @@ public: | |||
| 117 | Id local_invocation_id{}; | 80 | Id local_invocation_id{}; |
| 118 | 81 | ||
| 119 | private: | 82 | private: |
| 120 | DefMap def_map; | ||
| 121 | std::vector<std::pair<IR::Block*, Id>> block_label_map; | 83 | std::vector<std::pair<IR::Block*, Id>> block_label_map; |
| 122 | }; | 84 | }; |
| 123 | 85 | ||