crocus: Tidy the ifdefs for emitting STATE_BASE_ADDRESS
authorKenneth Graunke <kenneth@whitecape.org>
Fri, 22 Oct 2021 09:31:25 +0000 (02:31 -0700)
committerMarge Bot <emma+marge@anholt.net>
Thu, 28 Oct 2021 19:45:55 +0000 (19:45 +0000)
This reorganizes the code so that we set fields in a tidy order:

   1. Set the base addresses

   2. Set either buffer sizes (Gfx8) or upper bound values (Gfx4-7)
      (These are logically the same thing, but expressed differently.)

   3. Set MOCS (Gfx6+)

I find this easier to follow.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13480>

src/gallium/drivers/crocus/crocus_state.c

index eabb39f..3dabe9c 100644 (file)
@@ -5504,46 +5504,31 @@ crocus_update_surface_base_address(struct crocus_batch *batch)
 {
    if (batch->state_base_address_emitted)
       return;
-#if GFX_VER >= 6
-   uint32_t mocs = batch->screen->isl_dev.mocs.internal;
-#endif
+
+   UNUSED uint32_t mocs = batch->screen->isl_dev.mocs.internal;
+
    flush_before_state_base_change(batch);
 
    crocus_emit_cmd(batch, GENX(STATE_BASE_ADDRESS), sba) {
+      /* Set base addresses */
+      sba.GeneralStateBaseAddressModifyEnable = true;
+
+#if GFX_VER >= 6
+      sba.DynamicStateBaseAddressModifyEnable = true;
+      sba.DynamicStateBaseAddress = ro_bo(batch->state.bo, 0);
+#endif
 
       sba.SurfaceStateBaseAddressModifyEnable = true;
       sba.SurfaceStateBaseAddress = ro_bo(batch->state.bo, 0);
 
-#if GFX_VER >= 5
-      sba.InstructionBaseAddress = ro_bo(batch->ice->shaders.cache_bo, 0); // TODO!
-#endif
-
-      sba.GeneralStateBaseAddressModifyEnable   = true;
       sba.IndirectObjectBaseAddressModifyEnable = true;
+
 #if GFX_VER >= 5
-      sba.InstructionBaseAddressModifyEnable    = true;
+      sba.InstructionBaseAddressModifyEnable = true;
+      sba.InstructionBaseAddress = ro_bo(batch->ice->shaders.cache_bo, 0); // TODO!
 #endif
 
-#if GFX_VER < 8
-      sba.GeneralStateAccessUpperBoundModifyEnable = true;
-#endif
-#if GFX_VER >= 5 && GFX_VER < 8
-      sba.IndirectObjectAccessUpperBoundModifyEnable = true;
-      sba.InstructionAccessUpperBoundModifyEnable = true;
-#endif
-#if GFX_VER <= 5
-      sba.GeneralStateAccessUpperBound = ro_bo(NULL, 0xfffff000);
-#endif
-#if GFX_VER >= 6
-      /* The hardware appears to pay attention to the MOCS fields even
-       * if you don't set the "Address Modify Enable" bit for the base.
-       */
-      sba.GeneralStateMOCS            = mocs;
-      sba.StatelessDataPortAccessMOCS = mocs;
-      sba.DynamicStateMOCS            = mocs;
-      sba.IndirectObjectMOCS          = mocs;
-      sba.InstructionMOCS             = mocs;
-      sba.SurfaceStateMOCS            = mocs;
+      /* Set buffer sizes on Gen8+ or upper bounds on Gen4-7 */
 #if GFX_VER == 8
       sba.GeneralStateBufferSize   = 0xfffff;
       sba.IndirectObjectBufferSize = 0xfffff;
@@ -5554,22 +5539,38 @@ crocus_update_surface_base_address(struct crocus_batch *batch)
       sba.DynamicStateBufferSizeModifyEnable    = true;
       sba.IndirectObjectBufferSizeModifyEnable  = true;
       sba.InstructionBuffersizeModifyEnable     = true;
-#endif
-
-      sba.DynamicStateBaseAddressModifyEnable   = true;
+#else
+      sba.GeneralStateAccessUpperBoundModifyEnable = true;
+      sba.IndirectObjectAccessUpperBoundModifyEnable = true;
 
-      sba.DynamicStateBaseAddress = ro_bo(batch->state.bo, 0);
+#if GFX_VER >= 5
+      sba.InstructionAccessUpperBoundModifyEnable = true;
+#endif
 
+#if GFX_VER >= 6
       /* Dynamic state upper bound.  Although the documentation says that
        * programming it to zero will cause it to be ignored, that is a lie.
        * If this isn't programmed to a real bound, the sampler border color
        * pointer is rejected, causing border color to mysteriously fail.
        */
-#if GFX_VER < 8
-      sba.DynamicStateAccessUpperBoundModifyEnable = true;
       sba.DynamicStateAccessUpperBound = ro_bo(NULL, 0xfffff000);
+      sba.DynamicStateAccessUpperBoundModifyEnable = true;
+#else
+      /* Same idea but using General State Base Address on Gen4-5 */
+      sba.GeneralStateAccessUpperBound = ro_bo(NULL, 0xfffff000);
+#endif
 #endif
 
+#if GFX_VER >= 6
+      /* The hardware appears to pay attention to the MOCS fields even
+       * if you don't set the "Address Modify Enable" bit for the base.
+       */
+      sba.GeneralStateMOCS            = mocs;
+      sba.StatelessDataPortAccessMOCS = mocs;
+      sba.DynamicStateMOCS            = mocs;
+      sba.IndirectObjectMOCS          = mocs;
+      sba.InstructionMOCS             = mocs;
+      sba.SurfaceStateMOCS            = mocs;
 #endif
    }