mesa/st: ignore StencilSampling if stencil not part of the format
authorTapani Pälli <tapani.palli@intel.com>
Mon, 9 Oct 2023 04:54:55 +0000 (07:54 +0300)
committerMarge Bot <emma+marge@anholt.net>
Thu, 12 Oct 2023 03:52:26 +0000 (03:52 +0000)
This avoids hitting assert in debug builds and incorrect rendering
on release in case GL_DEPTH_STENCIL_TEXTURE_MODE has been set to
GL_STENCIL_INDEX with a texture that does not have stencil.

Cc: mesa-stable
Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25610>

src/mesa/state_tracker/st_atom_sampler.c
src/mesa/state_tracker/st_sampler_view.c

index 4cad8b0c8796adb4fab2866ca6c6ad2f7a3d3d22..c7171ef1704e0b8f173e99dc9a2390930276f054 100644 (file)
@@ -112,11 +112,20 @@ st_convert_sampler(const struct st_context *st,
        /* This is true if wrap modes are using the border color: */
        (sampler->wrap_s | sampler->wrap_t | sampler->wrap_r) & 0x1) {
       GLenum texBaseFormat = _mesa_base_tex_image(texobj)->_BaseFormat;
+
+      /* From OpenGL 4.3 spec, "Combined Depth/Stencil Textures":
+       *
+       *    "The DEPTH_STENCIL_TEXTURE_MODE is ignored for non
+       *     depth/stencil textures.
+       */
+      const bool has_combined_ds = texBaseFormat == GL_DEPTH_STENCIL;
+
       const GLboolean is_integer =
-         texobj->_IsIntegerFormat || texobj->StencilSampling ||
+         texobj->_IsIntegerFormat ||
+         (texobj->StencilSampling && has_combined_ds) ||
          texBaseFormat == GL_STENCIL_INDEX;
 
-      if (texobj->StencilSampling)
+      if (texobj->StencilSampling && has_combined_ds)
          texBaseFormat = GL_STENCIL_INDEX;
 
       if (st->apply_texture_swizzle_to_border_color ||
index 0b7b57ac7e5c9747ab7e99b8c65805f3d299d6a4..5978c11c12d2411be7af0f5609312d691baf8c2a 100644 (file)
@@ -361,10 +361,19 @@ st_get_sampler_view_format(const struct st_context *st,
    GLenum baseFormat = _mesa_base_tex_image(texObj)->_BaseFormat;
    format = texObj->surface_based ? texObj->surface_format : texObj->pt->format;
 
+   /* From OpenGL 4.3 spec, "Combined Depth/Stencil Textures":
+    *
+    *    "The DEPTH_STENCIL_TEXTURE_MODE is ignored for non
+    *     depth/stencil textures.
+    */
+   const bool has_combined_ds =
+      baseFormat == GL_DEPTH_STENCIL;
+
    if (baseFormat == GL_DEPTH_COMPONENT ||
        baseFormat == GL_DEPTH_STENCIL ||
        baseFormat == GL_STENCIL_INDEX) {
-      if (texObj->StencilSampling || baseFormat == GL_STENCIL_INDEX)
+      if ((texObj->StencilSampling && has_combined_ds) ||
+          baseFormat == GL_STENCIL_INDEX)
          format = util_format_stencil_only(format);
 
       return format;