[Mesa-dev] [PATCH] (UNTESTED) virgl: filter out 2D constant file accesses and declarations

Nicolai Hähnle nhaehnle at gmail.com
Tue Sep 12 20:34:39 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

Sorry for the mess.

I suspect something like this patch is needed. Is this sufficient to
fix the problem?

Cheers,
Nicolai
---
 src/gallium/drivers/virgl/virgl_tgsi.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/gallium/drivers/virgl/virgl_tgsi.c b/src/gallium/drivers/virgl/virgl_tgsi.c
index 7ad1cbdb886..4151e1d8450 100644
--- a/src/gallium/drivers/virgl/virgl_tgsi.c
+++ b/src/gallium/drivers/virgl/virgl_tgsi.c
@@ -42,36 +42,60 @@ virgl_tgsi_transform_property(struct tgsi_transform_context *ctx,
    case TGSI_PROPERTY_NUM_CULLDIST_ENABLED:
    case TGSI_PROPERTY_NEXT_SHADER:
       break;
    default:
       ctx->emit_property(ctx, prop);
       break;
    }
 }
 
 static void
+virgl_tgsi_transform_declaration(struct tgsi_transform_context *ctx,
+                                 struct tgsi_full_declaration *decl)
+{
+   if (decl->Declaration.File == TGSI_FILE_CONSTANT &&
+       decl->Declaration.Dimension &&
+       decl->Dim.Index2D == 0)
+      decl->Declaration.Dimension = 0;
+
+   ctx->emit_declaration(ctx, decl);
+}
+
+static void
 virgl_tgsi_transform_instruction(struct tgsi_transform_context *ctx,
 				 struct tgsi_full_instruction *inst)
 {
    if (inst->Instruction.Precise)
       inst->Instruction.Precise = 0;
+
+   for (unsigned i = 0; i < inst->Instruction.NumSrcRegs; ++i) {
+      struct tgsi_full_src_register *src = &inst->Src[i];
+
+      if (src->Register.File == TGSI_FILE_CONSTANT &&
+          src->Register.Dimension &&
+          !src->Dimension.Indirect &&
+          src->Dimension.Index == 0)
+         src->Register.Dimension = 0;
+   }
+
    ctx->emit_instruction(ctx, inst);
 }
 
 struct tgsi_token *virgl_tgsi_transform(const struct tgsi_token *tokens_in)
 {
 
    struct virgl_transform_context transform;
    const uint newLen = tgsi_num_tokens(tokens_in);
    struct tgsi_token *new_tokens;
 
    new_tokens = tgsi_alloc_tokens(newLen);
    if (!new_tokens)
       return NULL;
 
    memset(&transform, 0, sizeof(transform));
    transform.base.transform_property = virgl_tgsi_transform_property;
    transform.base.transform_instruction = virgl_tgsi_transform_instruction;
+   transform.base.transform_declaration = virgl_tgsi_transform_declaration;
    tgsi_transform_shader(tokens_in, new_tokens, newLen, &transform.base);
 
    return new_tokens;
 }
-- 
2.11.0



More information about the mesa-dev mailing list