vk_shader_decompiler: Correct Branches inside conditionals.

This commit is contained in:
Fernando Sahmkow 2019-09-25 14:34:08 -04:00 committed by FernandoS27
parent 000ad558dd
commit 507a9c6a40

View file

@ -650,7 +650,11 @@ private:
VisitBasicBlock(conditional->GetCode()); VisitBasicBlock(conditional->GetCode());
--conditional_nest_count; --conditional_nest_count;
if (inside_branch == 0) {
Emit(OpBranch(skip_label)); Emit(OpBranch(skip_label));
} else {
inside_branch--;
}
Emit(skip_label); Emit(skip_label);
return {}; return {};
@ -1014,6 +1018,7 @@ private:
Emit(OpStore(jmp_to, Constant(t_uint, target->GetValue()))); Emit(OpStore(jmp_to, Constant(t_uint, target->GetValue())));
Emit(OpBranch(continue_label)); Emit(OpBranch(continue_label));
inside_branch = conditional_nest_count;
if (conditional_nest_count == 0) { if (conditional_nest_count == 0) {
Emit(OpLabel()); Emit(OpLabel());
} }
@ -1025,6 +1030,7 @@ private:
Emit(OpStore(jmp_to, op_a)); Emit(OpStore(jmp_to, op_a));
Emit(OpBranch(continue_label)); Emit(OpBranch(continue_label));
inside_branch = conditional_nest_count;
if (conditional_nest_count == 0) { if (conditional_nest_count == 0) {
Emit(OpLabel()); Emit(OpLabel());
} }
@ -1055,6 +1061,7 @@ private:
Emit(OpStore(flow_stack_top, previous)); Emit(OpStore(flow_stack_top, previous));
Emit(OpStore(jmp_to, target)); Emit(OpStore(jmp_to, target));
Emit(OpBranch(continue_label)); Emit(OpBranch(continue_label));
inside_branch = conditional_nest_count;
if (conditional_nest_count == 0) { if (conditional_nest_count == 0) {
Emit(OpLabel()); Emit(OpLabel());
} }
@ -1114,6 +1121,7 @@ private:
Id Exit(Operation operation) { Id Exit(Operation operation) {
PreExit(); PreExit();
inside_branch = conditional_nest_count;
if (conditional_nest_count > 0) { if (conditional_nest_count > 0) {
Emit(OpReturn()); Emit(OpReturn());
} else { } else {
@ -1127,6 +1135,7 @@ private:
} }
Id Discard(Operation operation) { Id Discard(Operation operation) {
inside_branch = conditional_nest_count;
if (conditional_nest_count > 0) { if (conditional_nest_count > 0) {
Emit(OpKill()); Emit(OpKill());
} else { } else {
@ -1536,6 +1545,7 @@ private:
const ShaderStage stage; const ShaderStage stage;
const Tegra::Shader::Header header; const Tegra::Shader::Header header;
u64 conditional_nest_count{}; u64 conditional_nest_count{};
u64 inside_branch{};
const Id t_void = Name(TypeVoid(), "void"); const Id t_void = Name(TypeVoid(), "void");