diff options
author | Eric Anholt <[email protected]> | 2019-08-19 15:17:58 -0700 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2019-10-17 21:07:29 +0000 |
commit | 75c601b6cf63c077dbfbb5f2f64f683dcf5524b4 (patch) | |
tree | 1862ee5f747d8f7b4b1e501a75c74984926bafba /src/mesa/main/format_fallback.py | |
parent | d77c77936b3956e8925504ad980acbff74422e7c (diff) |
mesa: Refactor the entirety of _mesa_format_matches_format_and_type().
This function was difficult to implement for new formats due to the
combination of endianness and swapbytes support. Since it's mostly
used for fast paths, bugs in it were often missed during testing.
Just reimplement it on top of the recent
_mesa_format_from_format_and_type() which can give us a canonical
MESA_FORMAT for a format and type enum (while respecting endianness).
Fixes:
- R4G4B4A4_UNORM, B4G4R4_UINT, R4G4B4A4_UINT incorrectly matched with
swapBytes (you can't just reverse the channels if the channels
aren't bytes)
- A4R4G4B4_UNORM and A4R4G4B4_UINT missing BGRA/4444_REV matches
- failing to match RGB/BGR unorm8 array formats on BE
- 2101010 formats incorrectly matching with swapBytes set.
- UINT/SINT byte formats failed to match with swapBytes set.
This deletes the part of tests/mesa_formats.cpp that called
_mesa_format_matches_format_and_type() to make sure it didn't
assertion fail, as it now would assertion fail due to the fact that we
were passing an invalid format (GL_RG) for most types.
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa/main/format_fallback.py')
-rw-r--r-- | src/mesa/main/format_fallback.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/mesa/main/format_fallback.py b/src/mesa/main/format_fallback.py index 4a2b85cecb3..cc388274e75 100644 --- a/src/mesa/main/format_fallback.py +++ b/src/mesa/main/format_fallback.py @@ -85,6 +85,20 @@ def get_rgbx_to_rgba_map(formats): yield rgbx_name, rgba_name +def get_intensity_to_red_map(formats): + names = set(fmt.name for fmt in formats) + + for fmt in formats: + if str(fmt.swizzle) != 'xxxx': + continue + + i_name = fmt.name + r_name = i_name.replace("_I_", "_R_") + + assert r_name in names + + yield i_name, r_name + TEMPLATE = Template(COPYRIGHT + """ #include "formats.h" #include "util/macros.h" @@ -129,6 +143,23 @@ _mesa_get_linear_format_srgb(mesa_format format) } /** + * For an intensity format, return the corresponding red format. For other + * formats, return the format as-is. + */ +mesa_format +_mesa_get_intensity_format_red(mesa_format format) +{ + switch (format) { +%for i, r in intensity_to_red_map: + case ${i}: + return ${r}; +%endfor + default: + return format; + } +} + +/** * If the format has an alpha channel, and there exists a non-alpha * variant of the format with an identical bit layout, then return * the non-alpha format. Otherwise return the original format. @@ -164,6 +195,7 @@ def main(): template_env = { 'unorm_to_srgb_map': list(get_unorm_to_srgb_map(formats)), 'rgbx_to_rgba_map': list(get_rgbx_to_rgba_map(formats)), + 'intensity_to_red_map': list(get_intensity_to_red_map(formats)), } with open(pargs.out, 'w') as f: |