summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Olšák <marek.olsak@amd.com>2021-01-09 08:58:11 -0500
committerMarge Bot <eric+marge@anholt.net>2021-01-22 16:45:30 +0000
commitcd42ed34b0259c0597597715ef0ad07fc9df2698 (patch)
tree69d4e0f0c2a74aa21171ac8ec1258179f90a31b8
parent28e419f00117b223337eaef56067d657342b19c9 (diff)
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-prayer@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8653>
-rw-r--r--src/gallium/drivers/radeonsi/si_state_draw.cpp31
1 files 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) {