[virglrenderer-devel] [PATCH 6/7] shader: add texture image samples query support.

Dave Airlie airlied at gmail.com
Fri Jul 20 00:05:13 UTC 2018


From: Dave Airlie <airlied at redhat.com>

This adds support for the TXQS opcode, and RESQ	w channel
---
 src/vrend_shader.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index e991669..11cb614 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -58,6 +58,7 @@ extern int vrend_dump_shaders;
 #define SHADER_REQ_FP64               (1 << 14)
 #define SHADER_REQ_ES31_COMPAT        (1 << 15)
 #define SHADER_REQ_IMAGE_SIZE         (1 << 16)
+#define SHADER_REQ_TXQS               (1 << 17)
 
 struct vrend_shader_io {
    unsigned                name;
@@ -223,6 +224,7 @@ static const struct vrend_shader_table shader_req_table[] = {
     { SHADER_REQ_FP64, "GL_ARB_gpu_shader_fp64" },
     { SHADER_REQ_ES31_COMPAT, "GL_ARB_ES3_1_compatibility" },
     { SHADER_REQ_IMAGE_SIZE, "GL_ARB_shader_image_size" },
+    { SHADER_REQ_TXQS, "GL_ARB_shader_texture_image_samples" },
 };
 
 enum vrend_type_qualifier {
@@ -1761,6 +1763,31 @@ static int emit_txq(struct dump_ctx *ctx,
    return 0;
 }
 
+/* sample queries are pretty much separate */
+static int emit_txqs(struct dump_ctx *ctx,
+                     struct tgsi_full_instruction *inst,
+                     uint32_t sreg_index,
+                     char srcs[4][255],
+                     char dsts[3][255])
+{
+   char buf[512];
+   const int sampler_index = 0;
+   bool is_shad;
+   enum vrend_type_qualifier dtypeprefix = INT_BITS_TO_FLOAT;
+
+   ctx->shader_req_bits |= SHADER_REQ_TXQS;
+   if (set_texture_reqs(ctx, inst, sreg_index, &is_shad) == false)
+      return FALSE;
+
+   if (inst->Texture.Texture != TGSI_TEXTURE_2D_MSAA &&
+       inst->Texture.Texture != TGSI_TEXTURE_2D_ARRAY_MSAA)
+      return FALSE;
+
+   snprintf(buf, 255, "%s = %s(textureSamples(%s));\n", dsts[0], get_string(dtypeprefix), srcs[sampler_index]);
+   EMIT_BUF_WITH_RET(ctx, buf);
+   return 0;
+}
+
 static const char *get_tex_inst_ext(struct tgsi_full_instruction *inst)
 {
    const char *tex_ext = "";
@@ -2396,9 +2423,16 @@ translate_resq(struct dump_ctx *ctx, struct tgsi_full_instruction *inst,
    const struct tgsi_full_src_register *src = &inst->Src[0];
 
    if (src->Register.File == TGSI_FILE_IMAGE) {
-      ctx->shader_req_bits |= SHADER_REQ_IMAGE_SIZE;
-      snprintf(buf, 255, "%s = %s(imageSize(%s));\n", dsts[0], get_string(INT_BITS_TO_FLOAT), srcs[0]);
-      EMIT_BUF_WITH_RET(ctx, buf);
+      if (inst->Dst[0].Register.WriteMask & 0x8) {
+         ctx->shader_req_bits |= SHADER_REQ_TXQS | SHADER_REQ_INTS;
+         snprintf(buf, 255, "%s = %s(imageSamples(%s));\n", dsts[0], get_string(INT_BITS_TO_FLOAT), srcs[0]);
+         EMIT_BUF_WITH_RET(ctx, buf);
+      }
+      if (inst->Dst[0].Register.WriteMask & 0x7) {
+         ctx->shader_req_bits |= SHADER_REQ_IMAGE_SIZE | SHADER_REQ_INTS;
+         snprintf(buf, 255, "%s = %s(imageSize(%s));\n", dsts[0], get_string(INT_BITS_TO_FLOAT), srcs[0]);
+         EMIT_BUF_WITH_RET(ctx, buf);
+      }
    } else if (src->Register.File == TGSI_FILE_BUFFER) {
       snprintf(buf, 255, "%s = %s(int(%s.length()) << 2);\n", dsts[0], get_string(INT_BITS_TO_FLOAT), srcs[0]);
       EMIT_BUF_WITH_RET(ctx, buf);
@@ -3376,6 +3410,11 @@ iter_instruction(struct tgsi_iterate_context *iter,
       if (ret)
          return FALSE;
       break;
+   case TGSI_OPCODE_TXQS:
+      ret = emit_txqs(ctx, inst, sinfo.sreg_index, srcs, dsts);
+      if (ret)
+         return FALSE;
+      break;
    case TGSI_OPCODE_I2F:
       snprintf(buf, 255, "%s = %s(ivec4(%s)%s);\n", dsts[0], get_string(dinfo.dstconv), srcs[0], writemask);
       EMIT_BUF_WITH_RET(ctx, buf);
-- 
2.14.3



More information about the virglrenderer-devel mailing list