summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/spirv/emit_spirv.h
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-02-14 22:46:40 -0300
committerGravatar ameerj2021-07-22 21:51:22 -0400
commit1b0cf2309c760c1cb97a230a1572f8e87f84444a (patch)
tree6316825f65565b4c764b7851d061be0776a89974 /src/shader_recompiler/backend/spirv/emit_spirv.h
parentshader: Support SSA loops on IR (diff)
downloadyuzu-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.h40
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
17using Sirit::Id; 15using Sirit::Id;
18 16
19class DefMap {
20public:
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
41private:
42 struct InstInfo {
43 int use_count;
44 Id def_id;
45 };
46
47 boost::container::flat_map<IR::Inst*, InstInfo> map;
48};
49
50class VectorTypes { 17class VectorTypes {
51public: 18public:
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
119private: 82private:
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