Module: Mesa
Branch: main
Commit: 2e3cf3a6a60fc4a067f7cfc74c76e28216cef88f
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=2e3cf3a6a60fc4a067f7cfc74c76e28216cef88f

Author: Corentin Noël <[email protected]>
Date:   Tue May 10 17:23:24 2022 +0200

mesa: Make sure to fallback to handling the original choose texture format

It is possible for st_ChooseTextureFormat to return MESA_FORMAT_NONE when
samples is forced to 2. Always allow to fallback to the original case.

Fixes: 89c94502b6650fed222abd3588e9c927811580aa
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6441
Signed-off-by: Corentin Noël <[email protected]>
Reviewed-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16432>

---

 src/mesa/main/teximage.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index edea906239e..ce64681c37b 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -2824,7 +2824,7 @@ _mesa_choose_texture_format(struct gl_context *ctx,
                             GLenum internalFormat, GLenum format, GLenum type,
                             unsigned samples)
 {
-   mesa_format f;
+   mesa_format f = MESA_FORMAT_NONE;
 
    /* see if we've already chosen a format for the previous level */
    if (level > 0) {
@@ -2843,6 +2843,7 @@ _mesa_choose_texture_format(struct gl_context *ctx,
    }
 
    if (samples > 0) {
+      unsigned trySamples = samples;
       /* TODO: This somewhat duplicates the logic in st_texture_storage. */
       /* Find msaa sample count which is actually supported.  For example,
        * if the user requests 1x but only 4x or 8x msaa is supported, we'll
@@ -2850,19 +2851,22 @@ _mesa_choose_texture_format(struct gl_context *ctx,
        */
       if (ctx->Const.MaxSamples > 1 && samples == 1) {
          /* don't try num_samples = 1 with drivers that support real msaa */
-         samples = 2;
+         trySamples = 2;
       }
 
-      for (; samples <= ctx->Const.MaxSamples; samples++) {
+      for (; trySamples <= ctx->Const.MaxSamples; trySamples++) {
          f = st_ChooseTextureFormat(ctx, target, internalFormat,
-                                    format, type, samples);
-         if (f != PIPE_FORMAT_NONE)
+                                    format, type, trySamples);
+         if (f != MESA_FORMAT_NONE)
             break;
       }
-   } else {
+   }
+
+   if (f == MESA_FORMAT_NONE) {
       f = st_ChooseTextureFormat(ctx, target, internalFormat,
                                  format, type, samples);
    }
+
    assert(f != MESA_FORMAT_NONE);
    return f;
 }

Reply via email to