shader: Add support for forward declarations

This commit is contained in:
ReinUsesLisp 2021-02-14 22:46:40 -03:00 committed by ameerj
parent cbfb7d182a
commit 1b0cf2309c
11 changed files with 80 additions and 69 deletions

View file

@ -6,8 +6,6 @@
#include <sirit/sirit.h>
#include <boost/container/flat_map.hpp>
#include "common/common_types.h"
#include "shader_recompiler/frontend/ir/microinstruction.h"
#include "shader_recompiler/frontend/ir/program.h"
@ -16,37 +14,6 @@ namespace Shader::Backend::SPIRV {
using Sirit::Id;
class DefMap {
public:
void Define(IR::Inst* inst, Id def_id) {
const InstInfo info{.use_count{inst->UseCount()}, .def_id{def_id}};
const auto it{map.insert(map.end(), std::make_pair(inst, info))};
if (it == map.end()) {
throw LogicError("Defining already defined instruction");
}
}
[[nodiscard]] Id Consume(IR::Inst* inst) {
const auto it{map.find(inst)};
if (it == map.end()) {
throw LogicError("Consuming undefined instruction");
}
const Id def_id{it->second.def_id};
if (--it->second.use_count == 0) {
map.erase(it);
}
return def_id;
}
private:
struct InstInfo {
int use_count;
Id def_id;
};
boost::container::flat_map<IR::Inst*, InstInfo> map;
};
class VectorTypes {
public:
void Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) {
@ -76,7 +43,7 @@ public:
[[nodiscard]] Id Def(const IR::Value& value) {
if (!value.IsImmediate()) {
return def_map.Consume(value.Inst());
return value.Inst()->Definition<Id>();
}
switch (value.Type()) {
case IR::Type::U1:
@ -90,10 +57,6 @@ public:
}
}
void Define(IR::Inst* inst, Id def_id) {
def_map.Define(inst, def_id);
}
[[nodiscard]] Id BlockLabel(IR::Block* block) const {
const auto it{std::ranges::lower_bound(block_label_map, block, {},
&std::pair<IR::Block*, Id>::first)};
@ -117,7 +80,6 @@ public:
Id local_invocation_id{};
private:
DefMap def_map;
std::vector<std::pair<IR::Block*, Id>> block_label_map;
};