microsoft/spirv_to_dxil: Fix discard semantics
Unlike in nir, discard is not a super return in DXIL. Therefore, we will lower discard and terminate to demote + return. Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17179>
This commit is contained in:
parent
6689fa2ab4
commit
f367c55573
|
@ -645,14 +645,7 @@ Compilation failed
|
|||
|
||||
Test:SpvParserCFGTest_EmitBody_IfSelection_TrueBranch_LoopBreak.spvasm:main|Fragment: Pass
|
||||
Test:SpvParserCFGTest_EmitBody_Kill_InsideIf.spvasm:main|Fragment: Pass
|
||||
Test:SpvParserCFGTest_EmitBody_Kill_InsideLoop.spvasm:main|Fragment: Fail
|
||||
DXIL: Function: main: error: Loop must have break. Use /Zi for source location.
|
||||
Validation failed.
|
||||
|
||||
|
||||
Failed to validate DXIL
|
||||
|
||||
|
||||
Test:SpvParserCFGTest_EmitBody_Kill_InsideLoop.spvasm:main|Fragment: Pass
|
||||
Test:SpvParserCFGTest_EmitBody_Kill_TopLevel.spvasm:main|Fragment: Pass
|
||||
Test:SpvParserCFGTest_EmitBody_Loop_BodyAlwaysBreaks.spvasm:main|Fragment: Pass
|
||||
Test:SpvParserCFGTest_EmitBody_Loop_BodyConditionallyBreaks_FromFalse.spvasm:main|Fragment: Pass
|
||||
|
|
|
@ -2032,3 +2032,44 @@ dxil_nir_fix_io_uint_type(nir_shader *s, uint64_t in_mask, uint64_t out_mask)
|
|||
|
||||
return progress;
|
||||
}
|
||||
|
||||
static bool
|
||||
lower_kill(struct nir_builder *builder, nir_instr *instr, void *_cb_data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
|
||||
if (intr->intrinsic != nir_intrinsic_discard &&
|
||||
intr->intrinsic != nir_intrinsic_terminate &&
|
||||
intr->intrinsic != nir_intrinsic_discard_if &&
|
||||
intr->intrinsic != nir_intrinsic_terminate_if)
|
||||
return false;
|
||||
|
||||
builder->cursor = nir_instr_remove(instr);
|
||||
if (intr->intrinsic == nir_intrinsic_discard ||
|
||||
intr->intrinsic == nir_intrinsic_terminate) {
|
||||
nir_demote(builder);
|
||||
} else {
|
||||
assert(intr->src[0].is_ssa);
|
||||
nir_demote_if(builder, intr->src[0].ssa);
|
||||
}
|
||||
|
||||
nir_jump(builder, nir_jump_return);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
dxil_nir_lower_discard_and_terminate(nir_shader *s)
|
||||
{
|
||||
if (s->info.stage != MESA_SHADER_FRAGMENT)
|
||||
return false;
|
||||
|
||||
// This pass only works if all functions have been inlined
|
||||
assert(exec_list_length(&s->functions) == 1);
|
||||
|
||||
return nir_shader_instructions_pass(s, lower_kill, nir_metadata_none,
|
||||
NULL);
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ bool dxil_nir_fixup_tess_level_for_domain(nir_shader *nir);
|
|||
bool dxil_nir_set_tcs_patches_in(nir_shader *nir, unsigned num_control_points);
|
||||
bool dxil_nir_lower_ubo_array_one_to_static(nir_shader *s);
|
||||
bool dxil_nir_fix_io_uint_type(nir_shader *s, uint64_t in_mask, uint64_t out_mask);
|
||||
bool dxil_nir_lower_discard_and_terminate(nir_shader* s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -4182,8 +4182,10 @@ emit_intrinsic(struct ntd_context *ctx, nir_intrinsic_instr *intr)
|
|||
case nir_intrinsic_load_scratch_dxil:
|
||||
return emit_load_scratch(ctx, intr);
|
||||
case nir_intrinsic_discard_if:
|
||||
case nir_intrinsic_demote_if:
|
||||
return emit_discard_if(ctx, intr);
|
||||
case nir_intrinsic_discard:
|
||||
case nir_intrinsic_demote:
|
||||
return emit_discard(ctx);
|
||||
case nir_intrinsic_emit_vertex:
|
||||
return emit_emit_vertex(ctx, intr);
|
||||
|
|
|
@ -681,6 +681,10 @@ dxil_spirv_nir_passes(nir_shader *nir,
|
|||
.use_fragcoord_sysval = false,
|
||||
.use_layer_id_sysval = true,
|
||||
});
|
||||
|
||||
NIR_PASS_V(nir, dxil_nir_lower_discard_and_terminate);
|
||||
NIR_PASS_V(nir, nir_lower_returns);
|
||||
|
||||
}
|
||||
|
||||
NIR_PASS_V(nir, nir_opt_deref);
|
||||
|
|
Loading…
Reference in New Issue