Module: Mesa
Branch: master
Commit: cd42ed34b0259c0597597715ef0ad07fc9df2698
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=cd42ed34b0259c0597597715ef0ad07fc9df2698

Author: Marek Olšák <marek.ol...@amd.com>
Date:   Sat Jan  9 08:58:11 2021 -0500

radeonsi: optimize translating index_size to index_type

gcc generated a lookup table for the switch. This replaces it with
arithmetics.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-pra...@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8653>

---

 src/gallium/drivers/radeonsi/si_state_draw.cpp | 31 +++++++++++---------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_state_draw.cpp 
b/src/gallium/drivers/radeonsi/si_state_draw.cpp
index d17ab2e7a37..6c79e703a0d 100644
--- a/src/gallium/drivers/radeonsi/si_state_draw.cpp
+++ b/src/gallium/drivers/radeonsi/si_state_draw.cpp
@@ -1022,24 +1022,19 @@ static void si_emit_draw_packets(struct si_context 
*sctx, const struct pipe_draw
       if (index_size != sctx->last_index_size || sctx->shadowed_regs) {
          unsigned index_type;
 
-         /* index type */
-         switch (index_size) {
-         case 1:
-            index_type = V_028A7C_VGT_INDEX_8;
-            break;
-         case 2:
-            index_type =
-               V_028A7C_VGT_INDEX_16 |
-               (SI_BIG_ENDIAN && GFX_VERSION <= GFX7 ? 
V_028A7C_VGT_DMA_SWAP_16_BIT : 0);
-            break;
-         case 4:
-            index_type =
-               V_028A7C_VGT_INDEX_32 |
-               (SI_BIG_ENDIAN && GFX_VERSION <= GFX7 ? 
V_028A7C_VGT_DMA_SWAP_32_BIT : 0);
-            break;
-         default:
-            assert(!"unreachable");
-            return;
+         /* Index type computation. When we look at how we need to translate 
index_size,
+          * we can see that we just need 2 shifts to get the hw value.
+          *
+          * 1 = 001b --> 10b = 2
+          * 2 = 010b --> 00b = 0
+          * 4 = 100b --> 01b = 1
+          */
+         index_type = ((index_size >> 2) | (index_size << 1)) & 0x3;
+
+         if (GFX_VERSION <= GFX7 && SI_BIG_ENDIAN) {
+            /* GFX7 doesn't support ubyte indices. */
+            index_type |= index_size == 2 ? V_028A7C_VGT_DMA_SWAP_16_BIT
+                                          : V_028A7C_VGT_DMA_SWAP_32_BIT;
          }
 
          if (GFX_VERSION >= GFX9) {

_______________________________________________
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to