[D3D12] Tiny HLSL control flow cleanup

This commit is contained in:
Triang3l 2018-08-12 01:15:38 +03:00
parent 0900036795
commit b0993fa3f0
1 changed files with 13 additions and 12 deletions

View File

@ -451,13 +451,13 @@ void HlslShaderTranslator::ProcessExecInstructionBegin(
void HlslShaderTranslator::ProcessExecInstructionEnd(
const ParsedExecInstruction& instr) {
Unindent();
EmitSourceDepth("}\n");
if (instr.is_end) {
EmitSourceDepth("xe_pc = 0xFFFFu;\n");
EmitSourceDepth("break;\n");
cf_wrote_pc_ = true;
}
Unindent();
EmitSourceDepth("}\n");
}
void HlslShaderTranslator::ProcessLoopStartInstruction(
@ -551,34 +551,35 @@ void HlslShaderTranslator::ProcessJumpInstruction(
EmitSourceDepth("// ");
instr.Disassemble(&source_inner_);
bool needs_fallthrough = false;
bool conditional = false;
switch (instr.type) {
case ParsedJumpInstruction::Type::kUnconditional:
EmitSourceDepth("{\n");
break;
case ParsedJumpInstruction::Type::kConditional:
EmitSourceDepth("if ((xe_bool_constants[%u].x & (1u << %uu)) %c= 0u) {\n",
instr.bool_constant_index >> 5,
instr.bool_constant_index & 31,
instr.condition ? '!' : '=');
needs_fallthrough = true;
conditional = true;
break;
case ParsedJumpInstruction::Type::kPredicated:
EmitSourceDepth("if (%cxe_p0) {\n", instr.condition ? ' ' : '!');
needs_fallthrough = true;
conditional = true;
break;
}
if (conditional) {
Indent();
}
EmitSourceDepth("xe_pc = %uu; // L%u\n", instr.target_address,
instr.target_address);
if (conditional) {
Unindent();
if (needs_fallthrough) {
uint32_t next_address = instr.dword_index + 1;
EmitSourceDepth("} else {\n");
EmitSourceDepth(" xe_pc = %uu; // Fallthrough to L%u\n", next_address,
next_address);
}
EmitSourceDepth("}\n");
}
EmitSourceDepth("break;\n");
cf_wrote_pc_ = true;
}