ShaderIR: interpret kill as a return abort in non fragment shaders.

This commit is contained in:
FernandoS27
2021-01-04 16:17:13 +01:00
committed by Morph
parent 5181234508
commit abc158cdfe
3 changed files with 32 additions and 8 deletions

View File

@@ -1193,7 +1193,11 @@ void ARBDecompiler::VisitAST(const ASTNode& node) {
ResetTemporaries(); ResetTemporaries();
} }
if (ast_return->kills) { if (ast_return->kills) {
AddLine("KIL TR;"); if (stage == ShaderType::Fragment) {
AddLine("KIL TR;");
} else {
AddLine("RET;");
}
} else { } else {
Exit(); Exit();
} }
@@ -2082,6 +2086,10 @@ std::string ARBDecompiler::Exit(Operation) {
} }
std::string ARBDecompiler::Discard(Operation) { std::string ARBDecompiler::Discard(Operation) {
if (stage != ShaderType::Fragment) {
AddLine("RET;");
return {};
}
AddLine("KIL TR;"); AddLine("KIL TR;");
return {}; return {};
} }

View File

@@ -2305,7 +2305,11 @@ private:
// about unexecuted instructions that may follow this. // about unexecuted instructions that may follow this.
code.AddLine("if (true) {{"); code.AddLine("if (true) {{");
++code.scope; ++code.scope;
code.AddLine("discard;"); if (stage != ShaderType::Fragment) {
code.AddLine("return;");
} else {
code.AddLine("discard;");
}
--code.scope; --code.scope;
code.AddLine("}}"); code.AddLine("}}");
return {}; return {};
@@ -2932,7 +2936,11 @@ public:
decomp.code.scope++; decomp.code.scope++;
} }
if (ast.kills) { if (ast.kills) {
decomp.code.AddLine("discard;"); if (decomp.stage != ShaderType::Fragment) {
decomp.code.AddLine("return;");
} else {
decomp.code.AddLine("discard;");
}
} else { } else {
if (decomp.context_func->IsMain()) { if (decomp.context_func->IsMain()) {
decomp.PreExit(); decomp.PreExit();

View File

@@ -591,6 +591,14 @@ private:
DeclareOutputVertex(); DeclareOutputVertex();
} }
void SafeKill() {
if (stage != ShaderType::Fragment) {
OpReturn();
return;
}
OpKill();
}
void DeclareFragment() { void DeclareFragment() {
if (stage != ShaderType::Fragment) { if (stage != ShaderType::Fragment) {
return; return;
@@ -2126,7 +2134,7 @@ private:
OpBranchConditional(condition, true_label, discard_label); OpBranchConditional(condition, true_label, discard_label);
AddLabel(discard_label); AddLabel(discard_label);
OpKill(); SafeKill();
AddLabel(true_label); AddLabel(true_label);
} }
@@ -2196,12 +2204,12 @@ private:
Expression Discard(Operation operation) { Expression Discard(Operation operation) {
inside_branch = true; inside_branch = true;
if (conditional_branch_set) { if (conditional_branch_set) {
OpKill(); SafeKill();
} else { } else {
const Id dummy = OpLabel(); const Id dummy = OpLabel();
OpBranch(dummy); OpBranch(dummy);
AddLabel(dummy); AddLabel(dummy);
OpKill(); SafeKill();
AddLabel(); AddLabel();
} }
return {}; return {};
@@ -3053,7 +3061,7 @@ public:
decomp.OpBranchConditional(condition, then_label, endif_label); decomp.OpBranchConditional(condition, then_label, endif_label);
decomp.AddLabel(then_label); decomp.AddLabel(then_label);
if (ast.kills) { if (ast.kills) {
decomp.OpKill(); decomp.SafeKill();
} else { } else {
if (decomp.context_func->IsMain()) { if (decomp.context_func->IsMain()) {
decomp.PreExit(); decomp.PreExit();
@@ -3066,7 +3074,7 @@ public:
decomp.OpBranch(next_block); decomp.OpBranch(next_block);
decomp.AddLabel(next_block); decomp.AddLabel(next_block);
if (ast.kills) { if (ast.kills) {
decomp.OpKill(); decomp.SafeKill();
} else { } else {
if (decomp.context_func->IsMain()) { if (decomp.context_func->IsMain()) {
decomp.PreExit(); decomp.PreExit();