[D3D12] HLSL control flow fixes (still broken)

This commit is contained in:
Triang3l 2018-08-12 01:08:19 +03:00
parent ede9055ca5
commit 0900036795
1 changed files with 16 additions and 8 deletions

View File

@ -393,10 +393,11 @@ void HlslShaderTranslator::ProcessLabel(uint32_t cf_index) {
// 0 is always added in the beginning. // 0 is always added in the beginning.
if (cf_index != 0) { if (cf_index != 0) {
if (!cf_wrote_pc_) { if (!cf_wrote_pc_) {
EmitSourceDepth("xe_pc = %uu;\n", cf_index); EmitSourceDepth(" xe_pc = %uu;\n", cf_index);
EmitSourceDepth("break;\n"); EmitSourceDepth(" break;\n");
} }
EmitSourceDepth("case %uu:\n", cf_index); EmitSourceDepth("case %uu:\n", cf_index);
cf_wrote_pc_ = false;
} }
} }
@ -406,13 +407,21 @@ void HlslShaderTranslator::ProcessControlFlowNopInstruction(uint32_t cf_index) {
void HlslShaderTranslator::ProcessControlFlowInstructionBegin( void HlslShaderTranslator::ProcessControlFlowInstructionBegin(
uint32_t cf_index) { uint32_t cf_index) {
if (cf_wrote_pc_) {
// In case there are instructions after setting the PC and breaking (if
// there's an `if` setting the PC, there's an `else` setting the PC as well
// for falling through).
EmitSourceDepth("case %uu:\n", cf_index);
cf_wrote_pc_ = false; cf_wrote_pc_ = false;
}
Indent();
} }
void HlslShaderTranslator::ProcessControlFlowInstructionEnd(uint32_t cf_index) { void HlslShaderTranslator::ProcessControlFlowInstructionEnd(uint32_t cf_index) {
if (!cf_wrote_pc_) { if (!cf_wrote_pc_) {
EmitSourceDepth("// Falling through to L%u\n", cf_index + 1); EmitSourceDepth("// Falling through to L%u\n", cf_index + 1);
} }
Unindent();
} }
void HlslShaderTranslator::ProcessExecInstructionBegin( void HlslShaderTranslator::ProcessExecInstructionBegin(
@ -560,11 +569,8 @@ void HlslShaderTranslator::ProcessJumpInstruction(
break; break;
} }
Indent(); Indent();
EmitSourceDepth("xe_pc = %uu; // L%u\n", instr.target_address, EmitSourceDepth("xe_pc = %uu; // L%u\n", instr.target_address,
instr.target_address); instr.target_address);
EmitSourceDepth("break;\n");
Unindent(); Unindent();
if (needs_fallthrough) { if (needs_fallthrough) {
uint32_t next_address = instr.dword_index + 1; uint32_t next_address = instr.dword_index + 1;
@ -573,6 +579,8 @@ void HlslShaderTranslator::ProcessJumpInstruction(
next_address); next_address);
} }
EmitSourceDepth("}\n"); EmitSourceDepth("}\n");
EmitSourceDepth("break;\n");
cf_wrote_pc_ = true;
} }
void HlslShaderTranslator::ProcessAllocInstruction( void HlslShaderTranslator::ProcessAllocInstruction(