summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2019-09-21 03:12:06 +0200
committerFernandoS27 <fsahmkow27@gmail.com>2019-10-05 00:52:52 +0200
commit2e9a810423ef36178ac3947f8feeb7b9a5b29bce (patch)
treecad196eab22eafd8766a51e7086b8812e510b1c6
parentvk_shader_compiler: Implement the decompiler in SPIR-V (diff)
downloadyuzu-2e9a810423ef36178ac3947f8feeb7b9a5b29bce.tar
yuzu-2e9a810423ef36178ac3947f8feeb7b9a5b29bce.tar.gz
yuzu-2e9a810423ef36178ac3947f8feeb7b9a5b29bce.tar.bz2
yuzu-2e9a810423ef36178ac3947f8feeb7b9a5b29bce.tar.lz
yuzu-2e9a810423ef36178ac3947f8feeb7b9a5b29bce.tar.xz
yuzu-2e9a810423ef36178ac3947f8feeb7b9a5b29bce.tar.zst
yuzu-2e9a810423ef36178ac3947f8feeb7b9a5b29bce.zip
-rw-r--r--src/video_core/renderer_vulkan/vk_shader_decompiler.cpp6
-rw-r--r--src/video_core/shader/ast.cpp9
-rw-r--r--src/video_core/shader/ast.h3
-rw-r--r--src/video_core/shader/compiler_settings.h3
-rw-r--r--src/video_core/shader/control_flow.cpp3
-rw-r--r--src/video_core/shader/control_flow.h2
-rw-r--r--src/video_core/shader/shader_ir.cpp2
7 files changed, 18 insertions, 10 deletions
diff --git a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
index 505e49570..72fbc69c4 100644
--- a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
+++ b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
@@ -1667,7 +1667,8 @@ public:
}
void operator()(VideoCommon::Shader::ExprVar& expr) {
- current_id = decomp.Emit(decomp.OpLoad(decomp.t_bool, decomp.flow_variables.at(expr.var_index)));
+ current_id =
+ decomp.Emit(decomp.OpLoad(decomp.t_bool, decomp.flow_variables.at(expr.var_index)));
}
void operator()(VideoCommon::Shader::ExprBoolean& expr) {
@@ -1749,7 +1750,8 @@ public:
const Id loop_end_block = decomp.OpLabel();
current_loop_exit = endloop_label;
decomp.Emit(loop_label);
- decomp.Emit(decomp.OpLoopMerge(endloop_label, loop_end_block, spv::LoopControlMask::MaskNone));
+ decomp.Emit(
+ decomp.OpLoopMerge(endloop_label, loop_end_block, spv::LoopControlMask::MaskNone));
decomp.Emit(decomp.OpBranch(loop_start_block));
decomp.Emit(loop_start_block);
ASTNode current = ast.nodes.GetFirst();
diff --git a/src/video_core/shader/ast.cpp b/src/video_core/shader/ast.cpp
index 74b9a8f9a..7e5e916ab 100644
--- a/src/video_core/shader/ast.cpp
+++ b/src/video_core/shader/ast.cpp
@@ -363,7 +363,8 @@ std::string ASTManager::Print() {
return printer.GetResult();
}
-ASTManager::ASTManager(bool full_decompile) : full_decompile{full_decompile} {};
+ASTManager::ASTManager(bool full_decompile, bool disable_else_derivation)
+ : full_decompile{full_decompile}, disable_else_derivation{disable_else_derivation} {};
ASTManager::~ASTManager() {
Clear();
@@ -378,7 +379,8 @@ void ASTManager::Init() {
ASTManager::ASTManager(ASTManager&& other)
: labels_map(std::move(other.labels_map)), labels_count{other.labels_count},
gotos(std::move(other.gotos)), labels(std::move(other.labels)), variables{other.variables},
- program{other.program}, main_node{other.main_node}, false_condition{other.false_condition} {
+ program{other.program}, main_node{other.main_node}, false_condition{other.false_condition},
+ disable_else_derivation{other.disable_else_derivation} {
other.main_node.reset();
}
@@ -392,6 +394,7 @@ ASTManager& ASTManager::operator=(ASTManager&& other) {
program = other.program;
main_node = other.main_node;
false_condition = other.false_condition;
+ disable_else_derivation = other.disable_else_derivation;
other.main_node.reset();
return *this;
@@ -641,7 +644,7 @@ void ASTManager::EncloseIfThen(ASTNode goto_node, ASTNode label) {
ASTNode prev = goto_node->GetPrevious();
Expr condition = goto_node->GetGotoCondition();
bool do_else = false;
- if (prev->IsIfThen()) {
+ if (!disable_else_derivation && prev->IsIfThen()) {
Expr if_condition = prev->GetIfCondition();
do_else = ExprAreEqual(if_condition, condition);
}
diff --git a/src/video_core/shader/ast.h b/src/video_core/shader/ast.h
index 12db336df..1b73f301f 100644
--- a/src/video_core/shader/ast.h
+++ b/src/video_core/shader/ast.h
@@ -298,7 +298,7 @@ private:
class ASTManager final {
public:
- ASTManager(bool full_decompile);
+ ASTManager(bool full_decompile, bool disable_else_derivation);
~ASTManager();
ASTManager(const ASTManager& o) = delete;
@@ -378,6 +378,7 @@ private:
}
bool full_decompile{};
+ bool disable_else_derivation{};
std::unordered_map<u32, u32> labels_map{};
u32 labels_count{};
std::vector<ASTNode> labels{};
diff --git a/src/video_core/shader/compiler_settings.h b/src/video_core/shader/compiler_settings.h
index e1fb5bc3a..916018c01 100644
--- a/src/video_core/shader/compiler_settings.h
+++ b/src/video_core/shader/compiler_settings.h
@@ -19,7 +19,8 @@ enum class CompileDepth : u32 {
std::string CompileDepthAsString(CompileDepth cd);
struct CompilerSettings {
- CompileDepth depth;
+ CompileDepth depth{CompileDepth::NoFlowStack};
+ bool disable_else_derivation{true};
};
} // namespace VideoCommon::Shader
diff --git a/src/video_core/shader/control_flow.cpp b/src/video_core/shader/control_flow.cpp
index c4351969b..c2fa734e7 100644
--- a/src/video_core/shader/control_flow.cpp
+++ b/src/video_core/shader/control_flow.cpp
@@ -516,7 +516,8 @@ std::unique_ptr<ShaderCharacteristics> ScanFlow(const ProgramCode& program_code,
std::sort(state.block_info.begin(), state.block_info.end(),
[](const BlockInfo& a, const BlockInfo& b) -> bool { return a.start < b.start; });
if (decompiled && settings.depth != CompileDepth::NoFlowStack) {
- ASTManager manager{settings.depth != CompileDepth::DecompileBackwards};
+ ASTManager manager{settings.depth != CompileDepth::DecompileBackwards,
+ settings.disable_else_derivation};
state.manager = &manager;
DecompileShader(state);
decompiled = state.manager->IsFullyDecompiled();
diff --git a/src/video_core/shader/control_flow.h b/src/video_core/shader/control_flow.h
index 8d0d08422..74e54a5c7 100644
--- a/src/video_core/shader/control_flow.h
+++ b/src/video_core/shader/control_flow.h
@@ -72,7 +72,7 @@ struct ShaderCharacteristics {
std::set<u32> labels{};
u32 start{};
u32 end{};
- ASTManager manager{true};
+ ASTManager manager{true, true};
CompilerSettings settings{};
};
diff --git a/src/video_core/shader/shader_ir.cpp b/src/video_core/shader/shader_ir.cpp
index 04e364634..c1f2b88c8 100644
--- a/src/video_core/shader/shader_ir.cpp
+++ b/src/video_core/shader/shader_ir.cpp
@@ -25,7 +25,7 @@ using Tegra::Shader::Register;
ShaderIR::ShaderIR(const ProgramCode& program_code, u32 main_offset, const std::size_t size,
CompilerSettings settings)
: program_code{program_code}, main_offset{main_offset}, program_size{size}, basic_blocks{},
- program_manager{true}, settings{settings} {
+ program_manager{true, true}, settings{settings} {
Decode();
}