st/nine: Rework vs int and bool constants buffer
authorAxel Davy <axel.davy@ens.fr>
Tue, 4 Oct 2016 17:45:40 +0000 (19:45 +0200)
committerAxel Davy <axel.davy@ens.fr>
Mon, 10 Oct 2016 21:43:49 +0000 (23:43 +0200)
This will help to support swvp constants.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
src/gallium/state_trackers/nine/device9.c
src/gallium/state_trackers/nine/nine_state.c
src/gallium/state_trackers/nine/nine_state.h
src/gallium/state_trackers/nine/stateblock9.c

index 591a021002ad26c4712fbd3d7f78817660842e31..dca75c53e6e83518a47a91151d61a71cf7c5eeca 100644 (file)
@@ -326,8 +326,11 @@ NineDevice9_ctor( struct NineDevice9 *This,
         This->state.ps_const_f = CALLOC(This->ps_const_size, 1);
         This->state.vs_lconstf_temp = CALLOC(This->vs_const_size,1);
         This->state.ps_lconstf_temp = CALLOC(This->ps_const_size,1);
+        This->state.vs_const_i = CALLOC(NINE_MAX_CONST_I * sizeof(int[4]), 1);
+        This->state.vs_const_b = CALLOC(NINE_MAX_CONST_B * sizeof(BOOL), 1);
         if (!This->state.vs_const_f || !This->state.ps_const_f ||
-            !This->state.vs_lconstf_temp || !This->state.ps_lconstf_temp)
+            !This->state.vs_lconstf_temp || !This->state.ps_lconstf_temp ||
+            !This->state.vs_const_i || !This->state.vs_const_b)
             return E_OUTOFMEMORY;
 
         if (strstr(pScreen->get_name(pScreen), "AMD") ||
@@ -459,6 +462,8 @@ NineDevice9_dtor( struct NineDevice9 *This )
     FREE(This->state.ps_const_f);
     FREE(This->state.vs_lconstf_temp);
     FREE(This->state.ps_lconstf_temp);
+    FREE(This->state.vs_const_i);
+    FREE(This->state.vs_const_b);
 
     if (This->swapchains) {
         for (i = 0; i < This->nswapchains; ++i)
@@ -3438,19 +3443,19 @@ NineDevice9_SetVertexShaderConstantI( struct NineDevice9 *This,
 
     if (This->driver_caps.vs_integer) {
         if (!This->is_recording) {
-            if (!memcmp(&state->vs_const_i[StartRegister][0], pConstantData,
-                        Vector4iCount * sizeof(state->vs_const_i[0])))
+            if (!memcmp(&state->vs_const_i[4 * StartRegister], pConstantData,
+                        Vector4iCount * sizeof(int[4])))
                 return D3D_OK;
         }
-        memcpy(&state->vs_const_i[StartRegister][0],
+        memcpy(&state->vs_const_i[4 * StartRegister],
                pConstantData,
-               Vector4iCount * sizeof(state->vs_const_i[0]));
+               Vector4iCount * sizeof(int[4]));
     } else {
         for (i = 0; i < Vector4iCount; i++) {
-            state->vs_const_i[StartRegister+i][0] = fui((float)(pConstantData[4*i]));
-            state->vs_const_i[StartRegister+i][1] = fui((float)(pConstantData[4*i+1]));
-            state->vs_const_i[StartRegister+i][2] = fui((float)(pConstantData[4*i+2]));
-            state->vs_const_i[StartRegister+i][3] = fui((float)(pConstantData[4*i+3]));
+            state->vs_const_i[4 * (StartRegister + i)] = fui((float)(pConstantData[4 * i]));
+            state->vs_const_i[4 * (StartRegister + i) + 1] = fui((float)(pConstantData[4 * i + 1]));
+            state->vs_const_i[4 * (StartRegister + i) + 2] = fui((float)(pConstantData[4 * i + 2]));
+            state->vs_const_i[4 * (StartRegister + i) + 3] = fui((float)(pConstantData[4 * i + 3]));
         }
     }
 
@@ -3477,14 +3482,14 @@ NineDevice9_GetVertexShaderConstantI( struct NineDevice9 *This,
 
     if (This->driver_caps.vs_integer) {
         memcpy(pConstantData,
-               &state->vs_const_i[StartRegister][0],
-               Vector4iCount * sizeof(state->vs_const_i[0]));
+               &state->vs_const_i[4 * StartRegister],
+               Vector4iCount * sizeof(int[4]));
     } else {
         for (i = 0; i < Vector4iCount; i++) {
-            pConstantData[4*i] = (int32_t) uif(state->vs_const_i[StartRegister+i][0]);
-            pConstantData[4*i+1] = (int32_t) uif(state->vs_const_i[StartRegister+i][1]);
-            pConstantData[4*i+2] = (int32_t) uif(state->vs_const_i[StartRegister+i][2]);
-            pConstantData[4*i+3] = (int32_t) uif(state->vs_const_i[StartRegister+i][3]);
+            pConstantData[4 * i] = (int32_t) uif(state->vs_const_i[4 * (StartRegister + i)]);
+            pConstantData[4 * i + 1] = (int32_t) uif(state->vs_const_i[4 * (StartRegister + i) + 1]);
+            pConstantData[4 * i + 2] = (int32_t) uif(state->vs_const_i[4 * (StartRegister + i) + 2]);
+            pConstantData[4 * i + 3] = (int32_t) uif(state->vs_const_i[4 * (StartRegister + i) + 3]);
         }
     }
 
index b7a211d21f7b1a2bb5c14785b5b0e6ea4705c51a..2faca121fe6f950b9c6f1974890787bf50174142 100644 (file)
@@ -93,13 +93,13 @@ prepare_vs_constants_userbuf(struct NineDevice9 *device)
 
     if (state->changed.vs_const_i) {
         int *idst = (int *)&state->vs_const_f[4 * device->max_vs_const_f];
-        memcpy(idst, state->vs_const_i, sizeof(state->vs_const_i));
+        memcpy(idst, state->vs_const_i, NINE_MAX_CONST_I * sizeof(int[4]));
         state->changed.vs_const_i = 0;
     }
     if (state->changed.vs_const_b) {
         int *idst = (int *)&state->vs_const_f[4 * device->max_vs_const_f];
         uint32_t *bdst = (uint32_t *)&idst[4 * NINE_MAX_CONST_I];
-        memcpy(bdst, state->vs_const_b, sizeof(state->vs_const_b));
+        memcpy(bdst, state->vs_const_b, NINE_MAX_CONST_B * sizeof(BOOL));
         state->changed.vs_const_b = 0;
     }
 
index 7c395b84a28e6228d4b32063a4b2858b479da206..8c9483231e05a0447e5b5512ee75168d74c41483 100644 (file)
@@ -157,8 +157,8 @@ struct nine_state
      */
     struct NineVertexShader9 *vs;
     float *vs_const_f;
-    int    vs_const_i[NINE_MAX_CONST_I][4];
-    BOOL   vs_const_b[NINE_MAX_CONST_B];
+    int   *vs_const_i;
+    BOOL  *vs_const_b;
     float *vs_lconstf_temp;
     BOOL programmable_vs;
 
index 7ba19e76c1943c79d87d5ff966b32597b41d5a25..19c3766b3c680221838e4cacebd5280c4c97dde1 100644 (file)
@@ -30,6 +30,9 @@
 
 /* XXX TODO: handling of lights is broken */
 
+#define VS_CONST_I_SIZE (NINE_MAX_CONST_I * sizeof(int[4]))
+#define VS_CONST_B_SIZE (NINE_MAX_CONST_B * sizeof(BOOL))
+
 HRESULT
 NineStateBlock9_ctor( struct NineStateBlock9 *This,
                       struct NineUnknownParams *pParams,
@@ -46,7 +49,10 @@ NineStateBlock9_ctor( struct NineStateBlock9 *This,
 
     This->state.vs_const_f = MALLOC(This->base.device->vs_const_size);
     This->state.ps_const_f = MALLOC(This->base.device->ps_const_size);
-    if (!This->state.vs_const_f || !This->state.ps_const_f)
+    This->state.vs_const_i = MALLOC(VS_CONST_I_SIZE);
+    This->state.vs_const_b = MALLOC(VS_CONST_B_SIZE);
+    if (!This->state.vs_const_f || !This->state.ps_const_f ||
+        !This->state.vs_const_i || !This->state.vs_const_b)
         return E_OUTOFMEMORY;
 
     return D3D_OK;
@@ -63,6 +69,8 @@ NineStateBlock9_dtor( struct NineStateBlock9 *This )
 
     FREE(state->vs_const_f);
     FREE(state->ps_const_f);
+    FREE(state->vs_const_i);
+    FREE(state->vs_const_b);
 
     FREE(state->ff.light);
 
@@ -131,8 +139,8 @@ nine_state_copy_common(struct nine_state *dst,
                                    pool);
         }
         for (r = mask->changed.vs_const_i; r; r = r->next) {
-            memcpy(&dst->vs_const_i[r->bgn],
-                   &src->vs_const_i[r->bgn],
+            memcpy(&dst->vs_const_i[r->bgn * 4],
+                   &src->vs_const_i[r->bgn * 4],
                    (r->end - r->bgn) * 4 * sizeof(int));
             if (apply)
                 nine_ranges_insert(&dst->changed.vs_const_i, r->bgn, r->end,
@@ -365,8 +373,8 @@ nine_state_copy_common_all(struct nine_state *dst,
         if (apply)
             nine_ranges_insert(&dst->changed.vs_const_f, r->bgn, r->end, pool);
 
-        memcpy(dst->vs_const_i, src->vs_const_i, sizeof(dst->vs_const_i));
-        memcpy(dst->vs_const_b, src->vs_const_b, sizeof(dst->vs_const_b));
+        memcpy(dst->vs_const_i, src->vs_const_i, VS_CONST_I_SIZE);
+        memcpy(dst->vs_const_b, src->vs_const_b, VS_CONST_B_SIZE);
         if (apply) {
             r = help->changed.vs_const_i;
             nine_ranges_insert(&dst->changed.vs_const_i, r->bgn, r->end, pool);