2019-06-25 20:15:40 -04:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2019-06-24 19:46:49 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <list>
|
|
|
|
#include <optional>
|
2019-06-25 13:03:51 -04:00
|
|
|
#include <unordered_set>
|
2019-06-24 19:46:49 -04:00
|
|
|
|
|
|
|
#include "video_core/engines/shader_bytecode.h"
|
|
|
|
#include "video_core/shader/shader_ir.h"
|
|
|
|
|
|
|
|
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-25 20:15:40 -04:00
|
|
|
return predicate == Pred::UnusedIndex && cc == ConditionCode::T;
|
|
|
|
}
|
|
|
|
bool operator==(const Condition& other) const {
|
|
|
|
return std::tie(predicate, cc) == std::tie(other.predicate, other.cc);
|
2019-06-24 19:46:49 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ShaderBlock {
|
2019-06-25 20:15:40 -04:00
|
|
|
ShaderBlock() = default;
|
2019-06-24 19:46:49 -04:00
|
|
|
ShaderBlock(const ShaderBlock& sb) = default;
|
|
|
|
u32 start{};
|
|
|
|
u32 end{};
|
2019-06-25 11:10:45 -04:00
|
|
|
bool ignore_branch{};
|
2019-06-24 19:46:49 -04:00
|
|
|
struct Branch {
|
|
|
|
Condition cond{};
|
|
|
|
bool kills{};
|
|
|
|
s32 address{};
|
|
|
|
bool operator==(const Branch& b) const {
|
2019-06-25 20:15:40 -04:00
|
|
|
return std::tie(cond, kills, address) == std::tie(b.cond, b.kills, b.address);
|
2019-06-24 19:46:49 -04:00
|
|
|
}
|
|
|
|
} branch;
|
|
|
|
bool operator==(const ShaderBlock& sb) const {
|
2019-06-25 20:15:40 -04:00
|
|
|
return std::tie(start, end, ignore_branch, branch) ==
|
|
|
|
std::tie(sb.start, sb.end, sb.ignore_branch, sb.branch);
|
2019-06-24 19:46:49 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ShaderCharacteristics {
|
|
|
|
std::list<ShaderBlock> blocks;
|
|
|
|
bool decompilable{};
|
|
|
|
u32 start;
|
|
|
|
u32 end;
|
2019-06-25 13:03:51 -04:00
|
|
|
std::unordered_set<u32> labels{};
|
2019-06-24 19:46:49 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
bool ScanFlow(const ProgramCode& program_code, u32 program_size, u32 start_address,
|
|
|
|
ShaderCharacteristics& result_out);
|
|
|
|
|
|
|
|
} // namespace VideoCommon::Shader
|