freedreno/ir3: cleanup driver-param stuff
authorRob Clark <robclark@freedesktop.org>
Sat, 25 Jul 2015 16:48:18 +0000 (12:48 -0400)
committerRob Clark <robclark@freedesktop.org>
Mon, 27 Jul 2015 17:51:06 +0000 (13:51 -0400)
Add 'enum ir3_driver_param' to track driver-param slots, and a
create_driver_param() helper to avoid having the knowledge about
where driver params are placed in const regs spread throughout
the code as we add additional driver-params.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c
src/gallium/drivers/freedreno/ir3/ir3_shader.c
src/gallium/drivers/freedreno/ir3/ir3_shader.h

index bdbaf8970cfd3940bfad814b1311fca0e852fdcf..e013abedce6a8fad18a6d2fc965f39d26a8fd890 100644 (file)
@@ -261,13 +261,26 @@ compile_init(struct ir3_compiler *compiler,
 
        so->first_driver_param = so->first_immediate = ctx->s->num_uniforms;
 
-       /* one (vec4) slot for vertex id base: */
-       if (so->type == SHADER_VERTEX)
-               so->first_immediate++;
+       /* Layout of constant registers:
+        *
+        *    num_uniform * vec4  -  user consts
+        *    4 * vec4            -  UBO addresses
+        *    if (vertex shader) {
+        *        1 * vec4        -  driver params (IR3_DP_*)
+        *    }
+        *
+        * TODO this could be made more dynamic, to at least skip sections
+        * that we don't need..
+        */
 
        /* reserve 4 (vec4) slots for ubo base addresses: */
        so->first_immediate += 4;
 
+       if (so->type == SHADER_VERTEX) {
+               /* one (vec4) slot for driver params (see ir3_driver_param): */
+               so->first_immediate++;
+       }
+
        return ctx;
 }
 
@@ -811,6 +824,14 @@ create_frag_face(struct ir3_compile *ctx, unsigned comp)
        }
 }
 
+static struct ir3_instruction *
+create_driver_param(struct ir3_compile *ctx, enum ir3_driver_param dp)
+{
+       /* first four vec4 sysval's reserved for UBOs: */
+       unsigned r = regid(ctx->so->first_driver_param + 4, dp);
+       return create_uniform(ctx, r);
+}
+
 /* helper for instructions that produce multiple consecutive scalar
  * outputs which need to have a split/fanout meta instruction inserted
  */
@@ -1415,9 +1436,7 @@ emit_intrinisic(struct ir3_compile *ctx, nir_intrinsic_instr *intr)
                break;
        case nir_intrinsic_load_base_vertex:
                if (!ctx->basevertex) {
-                       /* first four vec4 sysval's reserved for UBOs: */
-                       unsigned r = regid(ctx->so->first_driver_param + 4, 0);
-                       ctx->basevertex = create_uniform(ctx, r);
+                       ctx->basevertex = create_driver_param(ctx, IR3_DP_VTXID_BASE);
                        add_sysval_input(ctx, TGSI_SEMANTIC_BASEVERTEX,
                                        ctx->basevertex);
                }
index 75425e91378c6b2755997bdaa3376f0723eecb53..166eb007dbba3b6cf6b2639bd1198cbb29af2111 100644 (file)
@@ -548,10 +548,7 @@ ir3_emit_consts(struct ir3_shader_variant *v, struct fd_ringbuffer *ring,
                uint32_t offset = v->first_driver_param + 4;  /* driver params after UBOs */
                if (v->constlen >= offset) {
                        uint32_t vertex_params[4] = {
-                               info->indexed ? info->index_bias : info->start,
-                               0,
-                               0,
-                               0
+                               [IR3_DP_VTXID_BASE] = info->indexed ? info->index_bias : info->start,
                        };
 
                        fd_wfi(ctx, ring);
index f0af4478109bf8cc4a610006bc53cbb1b6fa3c34..4cb252053243c2114b0aa561973ccbf7d6a97369 100644 (file)
 #include "ir3.h"
 #include "disasm.h"
 
+/* driver param indices: */
+enum ir3_driver_param {
+       IR3_DP_VTXID_BASE = 0,
+};
+
 /* internal semantic used for passing vtxcnt to vertex shader to
  * implement transform feedback:
  */