st/nine: Compact nine_ff_get_projected_key
authorAxel Davy <davyaxel0@gmail.com>
Sun, 13 Jan 2019 21:16:35 +0000 (22:16 +0100)
committerAxel Davy <davyaxel0@gmail.com>
Tue, 30 Apr 2019 17:18:51 +0000 (19:18 +0200)
Only the first four sampler slots can be used
by ff ps < 0x14, thus the size of the key
can be reduced.

Signed-off-by: Axel Davy <davyaxel0@gmail.com>
src/gallium/state_trackers/nine/nine_ff.c
src/gallium/state_trackers/nine/nine_ff.h
src/gallium/state_trackers/nine/nine_shader.h
src/gallium/state_trackers/nine/pixelshader9.h

index 85d75d6b2eccc34aa7eb3cdfeef4abe4a0189757..4ef258c876d748cddb4bb186a555b403166e85ae 100644 (file)
@@ -1819,7 +1819,7 @@ nine_ff_get_ps(struct NineDevice9 *device)
     if (s >= 1)
         key.ts[s-1].resultarg = 0;
 
-    key.projected = nine_ff_get_projected_key(context);
+    key.projected = nine_ff_get_projected_key_ff(context);
     key.specular = !!context->rs[D3DRS_SPECULARENABLE];
 
     for (; s < 8; ++s)
index 4d51c3d6ecbad9f98dd7f2c27ee6450d978621e7..5345b99dbb576dff8e3f09006c5affec2016fa2a 100644 (file)
@@ -62,11 +62,11 @@ nine_decltype_get_dim(BYTE type)
 }
 
 static inline uint16_t
-nine_ff_get_projected_key(struct nine_context *context)
+nine_ff_get_projected_key(struct nine_context *context, unsigned num_stages)
 {
     unsigned s, i;
     uint16_t projected = 0;
-    char input_texture_coord[8];
+    char input_texture_coord[num_stages];
     memset(&input_texture_coord, 0, sizeof(input_texture_coord));
 
     if (context->vdecl) {
@@ -74,13 +74,13 @@ nine_ff_get_projected_key(struct nine_context *context)
             uint16_t usage = context->vdecl->usage_map[i];
             if (usage % NINE_DECLUSAGE_COUNT == NINE_DECLUSAGE_TEXCOORD) {
                 s = usage / NINE_DECLUSAGE_COUNT;
-                if (s < 8)
+                if (s < num_stages)
                     input_texture_coord[s] = nine_decltype_get_dim(context->vdecl->decls[i].Type);
             }
         }
     }
 
-    for (s = 0; s < 8; ++s) {
+    for (s = 0; s < num_stages; ++s) {
         unsigned gen = (context->ff.tex_stage[s][D3DTSS_TEXCOORDINDEX] >> 16) + 1;
         unsigned dim = context->ff.tex_stage[s][D3DTSS_TEXTURETRANSFORMFLAGS] & 0x7;
         unsigned proj = !!(context->ff.tex_stage[s][D3DTSS_TEXTURETRANSFORMFLAGS] & D3DTTFF_PROJECTED);
@@ -107,4 +107,20 @@ nine_ff_get_projected_key(struct nine_context *context)
     return projected;
 }
 
+static inline uint16_t
+nine_ff_get_projected_key_ff(struct nine_context *context)
+{
+    /* 8 stages */
+    return nine_ff_get_projected_key(context, 8);
+}
+
+static inline uint8_t
+nine_ff_get_projected_key_programmable(struct nine_context *context)
+{
+    /* We only look at the 4 stages because this function
+     * is used only for ps 1.1-3, where only the first four
+     * slots are available */
+    return (uint8_t)nine_ff_get_projected_key(context, 4);
+}
+
 #endif /* _NINE_FF_H_ */
index 8b5be52de09925fd5b9779610dcf7202f969fae6..7921e455f88df75e573e5df97111f3744e7dedeb 100644 (file)
@@ -69,7 +69,7 @@ struct nine_shader_info
     uint8_t fog_enable;
     uint8_t fog_mode;
     uint8_t force_color_in_centroid;
-    uint16_t projected; /* ps 1.1 to 1.3 */
+    uint8_t projected; /* ps 1.1 to 1.3 */
 
     unsigned const_i_base; /* in vec4 (16 byte) units */
     unsigned const_b_base; /* in vec4 (16 byte) units */
index b616d9d7dee14ebd6fb5b6ea562f8fcbc490746e..b4c990bab8904475ff39664ac5994b774f842567 100644 (file)
@@ -77,7 +77,7 @@ NinePixelShader9_UpdateKey( struct NinePixelShader9 *ps,
 {
     uint16_t samplers_shadow;
     uint16_t samplers_ps1_types;
-    uint16_t projected;
+    uint8_t projected;
     uint64_t key;
     BOOL res;
 
@@ -115,7 +115,7 @@ NinePixelShader9_UpdateKey( struct NinePixelShader9 *ps,
                                                                context->ps_const_b)) << 40;
 
     if (unlikely(ps->byte_code.version < 0x14)) {
-        projected = nine_ff_get_projected_key(context);
+        projected = nine_ff_get_projected_key_programmable(context);
         key |= ((uint64_t) projected) << 48;
     }