From 6a264e7024a29eb7b41bbea18c653c3d232d16e8 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Tue, 12 Apr 2022 17:53:12 +0200 Subject: [PATCH] virgl: Apply integer op fix only for ALU ops and clear modifiers For texture fetches and buffer load the fix is not needed, and the override creates faulty TGSI. In addition remove all modifiers from the src in the additional mov instruction. Fixes: d1c7a7b1317c518e160cc6d37245de22b2bfa60d virgl: Add an extra mov for int outputs from constant and immediate inputs v2: Move workaround after the use of virgl_tgsi_rewrite_src_for_input_temp (Emma) Signed-off-by: Gert Wollny Part-of: --- src/gallium/drivers/virgl/virgl_tgsi.c | 45 ++++++++++++++------------ 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/gallium/drivers/virgl/virgl_tgsi.c b/src/gallium/drivers/virgl/virgl_tgsi.c index 5e67278aa9b..9e6158b1690 100644 --- a/src/gallium/drivers/virgl/virgl_tgsi.c +++ b/src/gallium/drivers/virgl/virgl_tgsi.c @@ -329,27 +329,6 @@ virgl_tgsi_transform_instruction(struct tgsi_transform_context *ctx, inst->Src[0].Register.Index = vtctx->src_temp; } - /* virglrenderer doesn't resolve non-float output write properly, - * so we have to first write to a temporary */ - if ((inst->Src[0].Register.File == TGSI_FILE_CONSTANT || - inst->Src[0].Register.File == TGSI_FILE_IMMEDIATE) && - inst->Dst[0].Register.File == TGSI_FILE_OUTPUT && - tgsi_opcode_infer_dst_type(inst->Instruction.Opcode, 0) != TGSI_TYPE_FLOAT) { - struct tgsi_full_instruction op_to_temp = *inst; - op_to_temp.Dst[0].Register.File = TGSI_FILE_TEMPORARY; - op_to_temp.Dst[0].Register.Index = vtctx->src_temp; - ctx->emit_instruction(ctx, &op_to_temp); - - inst->Instruction.Opcode = TGSI_OPCODE_MOV; - inst->Src[0].Register.File = TGSI_FILE_TEMPORARY; - inst->Src[0].Register.Index = vtctx->src_temp; - inst->Src[0].Register.Indirect = 0; - inst->Src[0].Register.SwizzleX = 0; - inst->Src[0].Register.SwizzleY = 1; - inst->Src[0].Register.SwizzleZ = 2; - inst->Src[0].Register.SwizzleW = 3; - } - for (unsigned i = 0; i < inst->Instruction.NumDstRegs; i++) { /* virglrenderer would fail to compile on clipdist, clipvertex, and some * two-sided-related color writes without a full writemask. So, we write @@ -405,6 +384,30 @@ virgl_tgsi_transform_instruction(struct tgsi_transform_context *ctx, } ctx->emit_instruction(ctx, inst); + /* virglrenderer doesn't resolve non-float output write properly, + * so we have to first write to a temporary */ + if ((inst->Src[0].Register.File == TGSI_FILE_CONSTANT || + inst->Src[0].Register.File == TGSI_FILE_IMMEDIATE) && + !tgsi_get_opcode_info(inst->Instruction.Opcode)->is_tex && + !tgsi_get_opcode_info(inst->Instruction.Opcode)->is_store && + inst->Dst[0].Register.File == TGSI_FILE_OUTPUT && + tgsi_opcode_infer_dst_type(inst->Instruction.Opcode, 0) != TGSI_TYPE_FLOAT) { + struct tgsi_full_instruction op_to_temp = *inst; + op_to_temp.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + op_to_temp.Dst[0].Register.Index = vtctx->src_temp; + ctx->emit_instruction(ctx, &op_to_temp); + + inst->Instruction.Opcode = TGSI_OPCODE_MOV; + inst->Instruction.NumSrcRegs = 1; + + memset(&inst->Src[0], 0, sizeof(inst->Src[0])); + inst->Src[0].Register.File = TGSI_FILE_TEMPORARY; + inst->Src[0].Register.Index = vtctx->src_temp; + inst->Src[0].Register.SwizzleY = 1; + inst->Src[0].Register.SwizzleZ = 2; + inst->Src[0].Register.SwizzleW = 3; + } + for (unsigned i = 0; i < inst->Instruction.NumDstRegs; i++) { if (vtctx->num_writemask_fixups && inst->Dst[i].Register.File == TGSI_FILE_TEMPORARY &&