[Mesa-dev] [PATCH mesa] r600: extend use of HAS_SIZE() macro
Eric Engestrom
eric.engestrom at imgtec.com
Tue Sep 12 11:16:23 UTC 2017
The macro was only used a few times; let's use it everywhere,
simplifying the code.
I also uniformised the use of curly brackets by adding them around
all uses of the macro, removed a few unnecessary `else` after `return`,
and turned a ternary op into an `if`.
Signed-off-by: Eric Engestrom <eric.engestrom at imgtec.com>
---
src/gallium/drivers/r600/r600_state_common.c | 108 +++++++++++++++------------
1 file changed, 59 insertions(+), 49 deletions(-)
diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
index c1bce8304b..b3ccdfc498 100644
--- a/src/gallium/drivers/r600/r600_state_common.c
+++ b/src/gallium/drivers/r600/r600_state_common.c
@@ -2666,78 +2666,88 @@ uint32_t r600_translate_colorformat(enum chip_class chip, enum pipe_format forma
switch (desc->nr_channels) {
case 1:
- switch (desc->channel[0].size) {
- case 8:
+ if (HAS_SIZE(8,0,0,0)) {
return V_0280A0_COLOR_8;
- case 16:
+ }
+ if (HAS_SIZE(16,0,0,0)) {
if (is_float)
return V_0280A0_COLOR_16_FLOAT;
else
return V_0280A0_COLOR_16;
- case 32:
+ }
+ if (HAS_SIZE(32,0,0,0)) {
if (is_float)
return V_0280A0_COLOR_32_FLOAT;
else
return V_0280A0_COLOR_32;
}
break;
+
case 2:
- if (desc->channel[0].size == desc->channel[1].size) {
- switch (desc->channel[0].size) {
- case 4:
- if (chip <= R700)
- return V_0280A0_COLOR_4_4;
- else
- return ~0U; /* removed on Evergreen */
- case 8:
- return V_0280A0_COLOR_8_8;
- case 16:
- if (is_float)
- return V_0280A0_COLOR_16_16_FLOAT;
- else
- return V_0280A0_COLOR_16_16;
- case 32:
- if (is_float)
- return V_0280A0_COLOR_32_32_FLOAT;
- else
- return V_0280A0_COLOR_32_32;
- }
- } else if (HAS_SIZE(8,24,0,0)) {
- return (do_endian_swap ? V_0280A0_COLOR_8_24 : V_0280A0_COLOR_24_8);
- } else if (HAS_SIZE(24,8,0,0)) {
+ if (HAS_SIZE(4,4,0,0)) {
+ if (chip <= R700)
+ return V_0280A0_COLOR_4_4;
+ else
+ return ~0U; /* removed on Evergreen */
+ }
+ if (HAS_SIZE(8,8,0,0)) {
+ return V_0280A0_COLOR_8_8;
+ }
+ if (HAS_SIZE(16,16,0,0)) {
+ if (is_float)
+ return V_0280A0_COLOR_16_16_FLOAT;
+ else
+ return V_0280A0_COLOR_16_16;
+ }
+ if (HAS_SIZE(32,32,0,0)) {
+ if (is_float)
+ return V_0280A0_COLOR_32_32_FLOAT;
+ else
+ return V_0280A0_COLOR_32_32;
+ }
+ if (HAS_SIZE(8,24,0,0)) {
+ if (do_endian_swap)
+ return V_0280A0_COLOR_8_24;
+ else
+ return V_0280A0_COLOR_24_8;
+ }
+ if (HAS_SIZE(24,8,0,0)) {
return V_0280A0_COLOR_8_24;
}
break;
+
case 3:
if (HAS_SIZE(5,6,5,0)) {
return V_0280A0_COLOR_5_6_5;
- } else if (HAS_SIZE(32,8,24,0)) {
+ }
+ if (HAS_SIZE(32,8,24,0)) {
return V_0280A0_COLOR_X24_8_32_FLOAT;
}
break;
+
case 4:
- if (desc->channel[0].size == desc->channel[1].size &&
- desc->channel[0].size == desc->channel[2].size &&
- desc->channel[0].size == desc->channel[3].size) {
- switch (desc->channel[0].size) {
- case 4:
- return V_0280A0_COLOR_4_4_4_4;
- case 8:
- return V_0280A0_COLOR_8_8_8_8;
- case 16:
- if (is_float)
- return V_0280A0_COLOR_16_16_16_16_FLOAT;
- else
- return V_0280A0_COLOR_16_16_16_16;
- case 32:
- if (is_float)
- return V_0280A0_COLOR_32_32_32_32_FLOAT;
- else
- return V_0280A0_COLOR_32_32_32_32;
- }
- } else if (HAS_SIZE(5,5,5,1)) {
+ if (HAS_SIZE(4,4,4,4)) {
+ return V_0280A0_COLOR_4_4_4_4;
+ }
+ if (HAS_SIZE(8,8,8,8)) {
+ return V_0280A0_COLOR_8_8_8_8;
+ }
+ if (HAS_SIZE(16,16,16,16)) {
+ if (is_float)
+ return V_0280A0_COLOR_16_16_16_16_FLOAT;
+ else
+ return V_0280A0_COLOR_16_16_16_16;
+ }
+ if (HAS_SIZE(32,32,32,32)) {
+ if (is_float)
+ return V_0280A0_COLOR_32_32_32_32_FLOAT;
+ else
+ return V_0280A0_COLOR_32_32_32_32;
+ }
+ if (HAS_SIZE(5,5,5,1)) {
return V_0280A0_COLOR_1_5_5_5;
- } else if (HAS_SIZE(10,10,10,2)) {
+ }
+ if (HAS_SIZE(10,10,10,2)) {
return V_0280A0_COLOR_2_10_10_10;
}
break;
--
Cheers,
Eric
More information about the mesa-dev
mailing list