i965: Use GL_RED for DEPTH_TEXTURE_MODE in ES 3.0 for unsized formats.
authorKenneth Graunke <kenneth@whitecape.org>
Wed, 23 Jan 2013 23:27:39 +0000 (15:27 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 25 Jan 2013 14:04:25 +0000 (09:04 -0500)
Khronos has apparently decided that depth textures with sized formats
(allowed with ARB_internalformat_query or ES 3.0) should be treated as
GL_RED, while unsized formats (an existing feature) should be treated
as GL_INTENSITY for compatibility with ES 2.0.

Ian is proposing changes to ARB_internalformat_query which will make
this actually legal and consistent.

A similar problem exists with GL 4.2, but we're going to ignore that
for the time being.

Tested on Ivybridge: no Piglit regressions; fixes 4 es3conform tests:
- depth_texture_fbo
- depth_texture_fbo_clear
- depth_texture_teximage
- depth_texture_texsubimage

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/drivers/dri/i965/brw_state.h
src/mesa/drivers/dri/i965/brw_wm.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/drivers/dri/i965/gen7_wm_surface_state.c

index c6b8219e6bb77d64ed02ec3d1e0934be89b17037..d9708c14bb7fe9fcc659e0f0531a1a88e7133a2a 100644 (file)
@@ -202,7 +202,8 @@ GLuint translate_tex_format(gl_format mesa_format,
                            GLenum depth_mode,
                            GLenum srgb_decode);
 
-int brw_get_texture_swizzle(const struct gl_texture_object *t);
+int brw_get_texture_swizzle(const struct gl_context *ctx,
+                            const struct gl_texture_object *t);
 
 /* gen7_wm_surface_state.c */
 uint32_t gen7_surface_tiling_mode(uint32_t tiling);
index 289156705a0c794f89e7456903e6e5f7642a9fd5..4b0446574ac637f7e0e7eae711aecce7264aa770 100644 (file)
@@ -316,7 +316,7 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
           * (except for GL_ALPHA); all other platforms need MOVs in the shader.
           */
          if (!intel->is_haswell || alpha_depth)
-            key->swizzles[s] = brw_get_texture_swizzle(t);
+            key->swizzles[s] = brw_get_texture_swizzle(ctx, t);
 
         if (img->InternalFormat == GL_YCBCR_MESA) {
            key->yuvtex_mask |= 1 << s;
index b772ef64e48129bb19858744e3cb35cf1f24cf87..7f7b7ebe2b00c578ae609972cc29b185b3df02cb 100644 (file)
@@ -30,6 +30,7 @@
   */
                    
 
+#include "main/context.h"
 #include "main/mtypes.h"
 #include "main/samplerobj.h"
 #include "program/prog_parameter.h"
@@ -685,7 +686,8 @@ brw_get_surface_num_multisamples(unsigned num_samples)
  * swizzling.
  */
 int
-brw_get_texture_swizzle(const struct gl_texture_object *t)
+brw_get_texture_swizzle(const struct gl_context *ctx,
+                        const struct gl_texture_object *t)
 {
    const struct gl_texture_image *img = t->Image[0][t->BaseLevel];
 
@@ -701,7 +703,19 @@ brw_get_texture_swizzle(const struct gl_texture_object *t)
 
    if (img->_BaseFormat == GL_DEPTH_COMPONENT ||
        img->_BaseFormat == GL_DEPTH_STENCIL) {
-      switch (t->DepthMode) {
+      GLenum depth_mode = t->DepthMode;
+
+      /* In ES 3.0, DEPTH_TEXTURE_MODE is expected to be GL_RED for textures
+       * with depth component data specified with a sized internal format.
+       * Otherwise, it's left at the old default, GL_LUMINANCE.
+       */
+      if (_mesa_is_gles3(ctx) &&
+          img->InternalFormat != GL_DEPTH_COMPONENT &&
+          img->InternalFormat != GL_DEPTH_STENCIL) {
+         depth_mode = GL_RED;
+      }
+
+      switch (depth_mode) {
       case GL_ALPHA:
          swizzles[0] = SWIZZLE_ZERO;
          swizzles[1] = SWIZZLE_ZERO;
index 05e9e75841d06036fd05812f69469cfaa7f735c5..236d50c8bc30c11255c4aef45f1464ca85ed53ef 100644 (file)
@@ -344,9 +344,8 @@ gen7_update_texture_surface(struct gl_context *ctx,
          (firstImage->_BaseFormat == GL_DEPTH_COMPONENT ||
           firstImage->_BaseFormat == GL_DEPTH_STENCIL);
 
-      const int swizzle =
-         unlikely(alpha_depth) ? SWIZZLE_XYZW : brw_get_texture_swizzle(tObj);
-
+      const int swizzle = unlikely(alpha_depth)
+         ? SWIZZLE_XYZW : brw_get_texture_swizzle(ctx, tObj);
 
       surf[7] =
          SET_FIELD(swizzle_to_scs(GET_SWZ(swizzle, 0)), GEN7_SURFACE_SCS_R) |