2019-06-26 00:15:40 +00:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2019-06-24 23:46:49 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <optional>
|
2019-06-27 04:39:40 +00:00
|
|
|
#include <set>
|
2019-09-24 02:55:25 +00:00
|
|
|
#include <variant>
|
2019-06-24 23:46:49 +00:00
|
|
|
|
|
|
|
#include "video_core/engines/shader_bytecode.h"
|
2019-06-29 02:59:43 +00:00
|
|
|
#include "video_core/shader/ast.h"
|
2019-08-16 20:25:02 +00:00
|
|
|
#include "video_core/shader/compiler_settings.h"
|
2020-02-28 23:53:10 +00:00
|
|
|
#include "video_core/shader/registry.h"
|
2019-08-16 20:25:02 +00:00
|
|
|
#include "video_core/shader/shader_ir.h"
|
2019-06-24 23:46:49 +00:00
|
|
|
|
|
|
|
namespace VideoCommon::Shader {
|
|
|
|
|
|
|
|
using Tegra::Shader::ConditionCode;
|
|
|
|
using Tegra::Shader::Pred;
|
|
|
|
|
|
|
|
constexpr s32 exit_branch = -1;
|
|
|
|
|
|
|
|
struct Condition {
|
|
|
|
Pred predicate{Pred::UnusedIndex};
|
|
|
|
ConditionCode cc{ConditionCode::T};
|
|
|
|
|
|
|
|
bool IsUnconditional() const {
|
2019-06-26 00:15:40 +00:00
|
|
|
return predicate == Pred::UnusedIndex && cc == ConditionCode::T;
|
|
|
|
}
|
2019-07-16 15:59:57 +00:00
|
|
|
|
2019-06-26 00:15:40 +00:00
|
|
|
bool operator==(const Condition& other) const {
|
|
|
|
return std::tie(predicate, cc) == std::tie(other.predicate, other.cc);
|
2019-06-24 23:46:49 +00:00
|
|
|
}
|
2019-07-16 15:59:57 +00:00
|
|
|
|
|
|
|
bool operator!=(const Condition& other) const {
|
|
|
|
return !operator==(other);
|
|
|
|
}
|
2019-06-24 23:46:49 +00:00
|
|
|
};
|
|
|
|
|
2019-09-24 02:55:25 +00:00
|
|
|
class SingleBranch {
|
|
|
|
public:
|
|
|
|
SingleBranch() = default;
|
2020-12-05 16:40:14 +00:00
|
|
|
explicit SingleBranch(Condition condition_, s32 address_, bool kill_, bool is_sync_,
|
|
|
|
bool is_brk_, bool ignore_)
|
|
|
|
: condition{condition_}, address{address_}, kill{kill_}, is_sync{is_sync_}, is_brk{is_brk_},
|
|
|
|
ignore{ignore_} {}
|
2019-09-24 02:55:25 +00:00
|
|
|
|
|
|
|
bool operator==(const SingleBranch& b) const {
|
|
|
|
return std::tie(condition, address, kill, is_sync, is_brk, ignore) ==
|
|
|
|
std::tie(b.condition, b.address, b.kill, b.is_sync, b.is_brk, b.ignore);
|
|
|
|
}
|
|
|
|
|
2019-10-17 14:35:16 +00:00
|
|
|
bool operator!=(const SingleBranch& b) const {
|
|
|
|
return !operator==(b);
|
|
|
|
}
|
|
|
|
|
2019-09-24 02:55:25 +00:00
|
|
|
Condition condition{};
|
|
|
|
s32 address{exit_branch};
|
|
|
|
bool kill{};
|
|
|
|
bool is_sync{};
|
|
|
|
bool is_brk{};
|
|
|
|
bool ignore{};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CaseBranch {
|
2020-12-05 16:40:14 +00:00
|
|
|
explicit CaseBranch(u32 cmp_value_, u32 address_) : cmp_value{cmp_value_}, address{address_} {}
|
2019-09-24 02:55:25 +00:00
|
|
|
u32 cmp_value;
|
|
|
|
u32 address;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MultiBranch {
|
|
|
|
public:
|
2020-12-05 16:40:14 +00:00
|
|
|
explicit MultiBranch(u32 gpr_, std::vector<CaseBranch>&& branches_)
|
|
|
|
: gpr{gpr_}, branches{std::move(branches_)} {}
|
2019-07-16 15:59:57 +00:00
|
|
|
|
2019-09-24 02:55:25 +00:00
|
|
|
u32 gpr{};
|
|
|
|
std::vector<CaseBranch> branches{};
|
|
|
|
};
|
2019-07-16 15:59:57 +00:00
|
|
|
|
2019-09-24 02:55:25 +00:00
|
|
|
using BranchData = std::variant<SingleBranch, MultiBranch>;
|
|
|
|
using BlockBranchInfo = std::shared_ptr<BranchData>;
|
2019-07-16 15:59:57 +00:00
|
|
|
|
2019-09-24 02:55:25 +00:00
|
|
|
bool BlockBranchInfoAreEqual(BlockBranchInfo first, BlockBranchInfo second);
|
|
|
|
|
|
|
|
struct ShaderBlock {
|
2019-07-16 15:59:57 +00:00
|
|
|
u32 start{};
|
|
|
|
u32 end{};
|
|
|
|
bool ignore_branch{};
|
2019-09-24 02:55:25 +00:00
|
|
|
BlockBranchInfo branch{};
|
2019-07-16 15:59:57 +00:00
|
|
|
|
2019-06-24 23:46:49 +00:00
|
|
|
bool operator==(const ShaderBlock& sb) const {
|
2019-09-24 02:55:25 +00:00
|
|
|
return std::tie(start, end, ignore_branch) ==
|
|
|
|
std::tie(sb.start, sb.end, sb.ignore_branch) &&
|
|
|
|
BlockBranchInfoAreEqual(branch, sb.branch);
|
2019-06-24 23:46:49 +00:00
|
|
|
}
|
2019-07-16 15:59:57 +00:00
|
|
|
|
|
|
|
bool operator!=(const ShaderBlock& sb) const {
|
|
|
|
return !operator==(sb);
|
|
|
|
}
|
2019-06-24 23:46:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ShaderCharacteristics {
|
2019-06-26 00:40:38 +00:00
|
|
|
std::list<ShaderBlock> blocks{};
|
2019-08-16 20:25:02 +00:00
|
|
|
std::set<u32> labels{};
|
2019-06-26 00:40:38 +00:00
|
|
|
u32 start{};
|
|
|
|
u32 end{};
|
2019-09-21 01:12:06 +00:00
|
|
|
ASTManager manager{true, true};
|
2019-08-16 20:25:02 +00:00
|
|
|
CompilerSettings settings{};
|
2019-06-24 23:46:49 +00:00
|
|
|
};
|
|
|
|
|
2019-09-25 02:34:18 +00:00
|
|
|
std::unique_ptr<ShaderCharacteristics> ScanFlow(const ProgramCode& program_code, u32 start_address,
|
2019-09-23 19:40:58 +00:00
|
|
|
const CompilerSettings& settings,
|
2020-02-28 23:53:10 +00:00
|
|
|
Registry& registry);
|
2019-06-24 23:46:49 +00:00
|
|
|
|
|
|
|
} // namespace VideoCommon::Shader
|