vc4: Add support for texture rectangles
authorEric Anholt <eric@anholt.net>
Thu, 17 Jul 2014 04:39:05 +0000 (21:39 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 11 Aug 2014 21:40:45 +0000 (14:40 -0700)
v2: Rebase on helpers change.

src/gallium/drivers/vc4/vc4_program.c
src/gallium/drivers/vc4/vc4_qir.h

index b45507d154d7b689ebab1604fd59296913fc8127..a85a0b4d293cabffd18ad01a15623e71343fa3c8 100644 (file)
@@ -303,6 +303,22 @@ tgsi_to_qir_tex(struct tgsi_to_qir *trans,
                 t = qir_FMUL(c, t, proj);
         }
 
+        /* There is no native support for GL texture rectangle coordinates, so
+         * we have to rescale from ([0, width], [0, height]) to ([0, 1], [0,
+         * 1]).
+         */
+        if (tgsi_inst->Texture.Texture == TGSI_TEXTURE_RECT) {
+                uint32_t sampler = 0; /* XXX */
+                s = qir_FMUL(c, s,
+                             get_temp_for_uniform(trans,
+                                                  QUNIFORM_TEXRECT_SCALE_X,
+                                                  sampler));
+                t = qir_FMUL(c, t,
+                             get_temp_for_uniform(trans,
+                                                  QUNIFORM_TEXRECT_SCALE_Y,
+                                                  sampler));
+        }
+
         uint32_t tex_and_sampler = 0; /* XXX */
         qir_TEX_T(c, t, add_uniform(trans, QUNIFORM_TEXTURE_CONFIG_P0,
                                     tex_and_sampler));
@@ -1170,6 +1186,22 @@ get_texture_p1(struct vc4_texture_stateobj *texstate,
                 (translate_wrap(sampler->wrap_s) << 0));
 }
 
+static uint32_t
+get_texrect_scale(struct vc4_texture_stateobj *texstate,
+                  enum quniform_contents contents,
+                  uint32_t data)
+{
+        struct pipe_sampler_view *texture = texstate->textures[data];
+        uint32_t dim;
+
+        if (contents == QUNIFORM_TEXRECT_SCALE_X)
+                dim = texture->texture->width0;
+        else
+                dim = texture->texture->height0;
+
+        return fui(1.0f / dim);
+}
+
 void
 vc4_get_uniform_bo(struct vc4_context *vc4, struct vc4_compiled_shader *shader,
                    struct vc4_constbuf_stateobj *cb,
@@ -1205,6 +1237,13 @@ vc4_get_uniform_bo(struct vc4_context *vc4, struct vc4_compiled_shader *shader,
                 case QUNIFORM_TEXTURE_CONFIG_P1:
                         map[i] = get_texture_p1(texstate, uinfo->data[i]);
                         break;
+
+                case QUNIFORM_TEXRECT_SCALE_X:
+                case QUNIFORM_TEXRECT_SCALE_Y:
+                        map[i] = get_texrect_scale(texstate,
+                                                   uinfo->contents[i],
+                                                   uinfo->data[i]);
+                        break;
                 }
 #if 0
                 fprintf(stderr, "%p/%d: %d: 0x%08x (%f)\n",
index a76d091b327c2b30bd4785b097bb86cef202cc33..1b450cac8c5171f31128038a5e5b84c4584a1c93 100644 (file)
@@ -157,6 +157,9 @@ enum quniform_contents {
          * sequence.
          */
         QUNIFORM_TEXTURE_CONFIG_P1,
+
+        QUNIFORM_TEXRECT_SCALE_X,
+        QUNIFORM_TEXRECT_SCALE_Y,
 };
 
 struct qcompile {