freedreno: extract helper for stage->sb for a4xx+
authorRob Clark <robdclark@gmail.com>
Wed, 5 Apr 2017 23:43:31 +0000 (19:43 -0400)
committerRob Clark <robdclark@gmail.com>
Mon, 17 Apr 2017 18:00:05 +0000 (14:00 -0400)
Signed-off-by: Rob Clark <robdclark@gmail.com>
src/gallium/drivers/freedreno/a4xx/fd4_emit.c
src/gallium/drivers/freedreno/a4xx/fd4_program.c
src/gallium/drivers/freedreno/a5xx/fd5_emit.c
src/gallium/drivers/freedreno/a5xx/fd5_program.c
src/gallium/drivers/freedreno/freedreno_util.h

index e07694a6ed1cd6268f19f13e6835428be12fee03..733e4a8c1714cde6c42d73d072cae6c7c19f089b 100644 (file)
 #include "fd4_format.h"
 #include "fd4_zsa.h"
 
-static const enum a4xx_state_block sb[] = {
-       [SHADER_VERTEX]   = SB4_VS_SHADER,
-       [SHADER_FRAGMENT] = SB4_FS_SHADER,
-};
-
 /* regid:          base const register
  * prsc or dwords: buffer containing constant values
  * sizedwords:     size of const value buffer
@@ -76,7 +71,7 @@ fd4_emit_const(struct fd_ringbuffer *ring, enum shader_t type,
        OUT_PKT3(ring, CP_LOAD_STATE4, 2 + sz);
        OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(regid/4) |
                        CP_LOAD_STATE4_0_STATE_SRC(src) |
-                       CP_LOAD_STATE4_0_STATE_BLOCK(sb[type]) |
+                       CP_LOAD_STATE4_0_STATE_BLOCK(fd4_stage2shadersb(type)) |
                        CP_LOAD_STATE4_0_NUM_UNIT(sizedwords/4));
        if (prsc) {
                struct fd_bo *bo = fd_resource(prsc)->bo;
@@ -104,7 +99,7 @@ fd4_emit_const_bo(struct fd_ringbuffer *ring, enum shader_t type, boolean write,
        OUT_PKT3(ring, CP_LOAD_STATE4, 2 + anum);
        OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(regid/4) |
                        CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
-                       CP_LOAD_STATE4_0_STATE_BLOCK(sb[type]) |
+                       CP_LOAD_STATE4_0_STATE_BLOCK(fd4_stage2shadersb(type)) |
                        CP_LOAD_STATE4_0_NUM_UNIT(anum/4));
        OUT_RING(ring, CP_LOAD_STATE4_1_EXT_SRC_ADDR(0) |
                        CP_LOAD_STATE4_1_STATE_TYPE(ST4_CONSTANTS));
index d9f13af1d9b0c12be7aab58cc091a17ef5da4080..05b0c4f9ae0e38ae9a4779ee9a48f63e20a9d02e 100644 (file)
@@ -89,16 +89,10 @@ static void
 emit_shader(struct fd_ringbuffer *ring, const struct ir3_shader_variant *so)
 {
        const struct ir3_info *si = &so->info;
-       enum adreno_state_block sb;
+       enum a4xx_state_block sb = fd4_stage2shadersb(so->type);
        enum adreno_state_src src;
        uint32_t i, sz, *bin;
 
-       if (so->type == SHADER_VERTEX) {
-               sb = SB4_VS_SHADER;
-       } else {
-               sb = SB4_FS_SHADER;
-       }
-
        if (fd_mesa_debug & FD_DBG_DIRECT) {
                sz = si->sizedwords;
                src = SS4_DIRECT;
index cbb86d890c0b89ea8ffe77e9bcae90ddd5927374..e9dbab93b1a38865bcf5f136f4333f1a0f5dd79f 100644 (file)
 #include "fd5_format.h"
 #include "fd5_zsa.h"
 
-static const enum a4xx_state_block sb[] = {
-       [SHADER_VERTEX]   = SB4_VS_SHADER,
-       [SHADER_FRAGMENT] = SB4_FS_SHADER,
-};
-
 /* regid:          base const register
  * prsc or dwords: buffer containing constant values
  * sizedwords:     size of const value buffer
@@ -74,7 +69,7 @@ fd5_emit_const(struct fd_ringbuffer *ring, enum shader_t type,
        OUT_PKT7(ring, CP_LOAD_STATE4, 3 + sz);
        OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(regid/4) |
                        CP_LOAD_STATE4_0_STATE_SRC(src) |
-                       CP_LOAD_STATE4_0_STATE_BLOCK(sb[type]) |
+                       CP_LOAD_STATE4_0_STATE_BLOCK(fd4_stage2shadersb(type)) |
                        CP_LOAD_STATE4_0_NUM_UNIT(sizedwords/4));
        if (prsc) {
                struct fd_bo *bo = fd_resource(prsc)->bo;
@@ -103,7 +98,7 @@ fd5_emit_const_bo(struct fd_ringbuffer *ring, enum shader_t type, boolean write,
        OUT_PKT7(ring, CP_LOAD_STATE4, 3 + (2 * anum));
        OUT_RING(ring, CP_LOAD_STATE4_0_DST_OFF(regid/4) |
                        CP_LOAD_STATE4_0_STATE_SRC(SS4_DIRECT) |
-                       CP_LOAD_STATE4_0_STATE_BLOCK(sb[type]) |
+                       CP_LOAD_STATE4_0_STATE_BLOCK(fd4_stage2shadersb(type)) |
                        CP_LOAD_STATE4_0_NUM_UNIT(anum/2));
        OUT_RING(ring, CP_LOAD_STATE4_1_EXT_SRC_ADDR(0) |
                        CP_LOAD_STATE4_1_STATE_TYPE(ST4_CONSTANTS));
index b8722a5d0387fba6e00d0040c5c4f0e50456d909..232b3fb877574d2771a464c8b7e465964f68fe46 100644 (file)
@@ -88,16 +88,10 @@ static void
 emit_shader(struct fd_ringbuffer *ring, const struct ir3_shader_variant *so)
 {
        const struct ir3_info *si = &so->info;
-       enum a4xx_state_block sb;
+       enum a4xx_state_block sb = fd4_stage2shadersb(so->type);
        enum a4xx_state_src src;
        uint32_t i, sz, *bin;
 
-       if (so->type == SHADER_VERTEX) {
-               sb = SB4_VS_SHADER;
-       } else {
-               sb = SB4_FS_SHADER;
-       }
-
        if (fd_mesa_debug & FD_DBG_DIRECT) {
                sz = si->sizedwords;
                src = SS4_DIRECT;
index a9b38c93759b91cdd2954d3f1ce54830c21ecee8..e6444337900b52da8fb075ad617963e0a33c8e4f 100644 (file)
@@ -449,4 +449,27 @@ pack_rgba(enum pipe_format format, const float *rgba)
 #define foreach_bit(b, mask) \
        for (uint32_t _m = (mask); _m && ({(b) = u_bit_scan(&_m); 1;});)
 
+
+#define BIT(bit) (1u << bit)
+
+/*
+ * a4xx+ helpers:
+ */
+
+static inline enum a4xx_state_block
+fd4_stage2shadersb(enum shader_t type)
+{
+       switch (type) {
+       case SHADER_VERTEX:
+               return SB4_VS_SHADER;
+       case SHADER_FRAGMENT:
+               return SB4_FS_SHADER;
+       case SHADER_COMPUTE:
+               return SB4_CS_SHADER;
+       default:
+               unreachable("bad shader type");
+               return ~0;
+       }
+}
+
 #endif /* FREEDRENO_UTIL_H_ */