summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2019-09-17 15:13:30 -0700
committerEric Anholt <[email protected]>2019-11-15 20:32:17 +0000
commite5b06008f15fd916c53b1f7be2353ac6ecfbbc8f (patch)
treebaedaa347eb9a249b42e5f5f542f2bb87b37a270 /src/mesa
parent69f109cc37fff6300ea9e1914779620b7a117bf9 (diff)
mesa/st: Simplify st_choose_matching_format().
We now have a nice helper function for finding those memcpy formats, without needing to go through each entry of the mesa format table to see if it happens to match. While looking at sysprof of a softpipe GLES2 CTS run, we were spending ~8% of the CPU on ChooseTextureFormat. With this, roughly the same region of the testsuite was .4%. v2: Add Ken's fix for canonicalizing array formats. Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/state_tracker/st_format.c38
1 files changed, 11 insertions, 27 deletions
diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index d2199d5af59..396254afbea 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -1277,36 +1277,20 @@ st_choose_matching_format(struct st_context *st, unsigned bind,
GLenum format, GLenum type, GLboolean swapBytes)
{
struct pipe_screen *screen = st->pipe->screen;
- mesa_format mesa_format;
- for (mesa_format = 1; mesa_format < MESA_FORMAT_COUNT; mesa_format++) {
- if (!_mesa_get_format_name(mesa_format))
- continue;
-
- if (_mesa_is_format_srgb(mesa_format)) {
- continue;
- }
- if (_mesa_get_format_bits(mesa_format, GL_TEXTURE_INTENSITY_SIZE) > 0) {
- /* If `format` is GL_RED/GL_RED_INTEGER, then we might match some
- * intensity formats, which we don't want.
- */
- continue;
- }
-
- if (_mesa_format_matches_format_and_type(mesa_format, format, type,
- swapBytes, NULL)) {
- enum pipe_format format =
- st_mesa_format_to_pipe_format(st, mesa_format);
+ if (swapBytes && !_mesa_swap_bytes_in_type_enum(&type))
+ return PIPE_FORMAT_NONE;
- if (format &&
- screen->is_format_supported(screen, format, PIPE_TEXTURE_2D,
- 0, 0, bind)) {
- return format;
- }
- /* It's unlikely to find 2 matching Mesa formats. */
- break;
- }
+ mesa_format mesa_format = _mesa_format_from_format_and_type(format, type);
+ if (_mesa_format_is_mesa_array_format(mesa_format))
+ mesa_format = _mesa_format_from_array_format(mesa_format);
+ if (mesa_format != MESA_FORMAT_NONE) {
+ enum pipe_format format = st_mesa_format_to_pipe_format(st, mesa_format);
+ if (format != PIPE_FORMAT_NONE &&
+ screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, 0, bind))
+ return format;
}
+
return PIPE_FORMAT_NONE;
}