st/mesa: add ARB_texture_stencil8 support (v4)
authorDave Airlie <airlied@gmail.com>
Sun, 5 Apr 2015 04:45:25 +0000 (14:45 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 23 Apr 2015 00:11:27 +0000 (10:11 +1000)
if we support stencil texturing, enable texture_stencil8
there is no requirement to support native S8 for this,
the texture can be converted to x24s8 fine.

v2: fold fixes from Marek in:
   a) put S8 last in the list
   b) fix renderable to always test for d/s renderable
    fixup the texture case to use a stencil only format
    for picking the format for the texture view.
v3: hit fallback for getteximage
v4: put s8 back in front, it shouldn't get picked now (Ilia)

Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/mesa/state_tracker/st_atom_texture.c
src/mesa/state_tracker/st_cb_texture.c
src/mesa/state_tracker/st_extensions.c
src/mesa/state_tracker/st_format.c

index eff28fc6f3711fbdbc8b832205c08d71584423f3..04ba86448fc576ebc9d54a30104bca2275a1be1c 100644 (file)
@@ -287,16 +287,22 @@ st_get_texture_sampler_view_from_stobj(struct st_context *st,
                                       enum pipe_format format)
 {
    struct pipe_sampler_view **sv;
-
+   const struct st_texture_image *firstImage;
    if (!stObj || !stObj->pt) {
       return NULL;
    }
 
    sv = st_texture_get_sampler_view(st, stObj);
 
-   if (stObj->base.StencilSampling &&
-       util_format_is_depth_and_stencil(format))
-      format = util_format_stencil_only(format);
+   if (util_format_is_depth_and_stencil(format)) {
+      if (stObj->base.StencilSampling)
+         format = util_format_stencil_only(format);
+      else {
+         firstImage = st_texture_image_const(_mesa_base_tex_image(&stObj->base));
+         if (firstImage->base._BaseFormat == GL_STENCIL_INDEX)
+            format = util_format_stencil_only(format);
+      }
+   }
 
    /* if sampler view has changed dereference it */
    if (*sv) {
index bdf236e82331083542c54fe9b4c74efd29777645..7ea3846fff15af70c48ba8255d20cea1cf891b88 100644 (file)
@@ -950,7 +950,7 @@ st_GetTexImage(struct gl_context * ctx,
 
    /* XXX Fallback to _mesa_GetTexImage_sw for depth-stencil formats
     * due to an incomplete stencil blit implementation in some drivers. */
-   if (format == GL_DEPTH_STENCIL) {
+   if (format == GL_DEPTH_STENCIL || format == GL_STENCIL_INDEX) {
       goto fallback;
    }
 
index bc20f73230da98b092dca6b3b5493e93b953665c..25932dd4cb86d3629f7241f0ea667aa59ac6416b 100644 (file)
@@ -650,6 +650,9 @@ void st_init_extensions(struct pipe_screen *screen,
                           ARRAY_SIZE(vertex_mapping), PIPE_BUFFER,
                           PIPE_BIND_VERTEX_BUFFER);
 
+   if (extensions->ARB_stencil_texturing)
+      extensions->ARB_texture_stencil8 = GL_TRUE;
+
    /* Figure out GLSL support. */
    glsl_feature_level = screen->get_param(screen, PIPE_CAP_GLSL_FEATURE_LEVEL);
 
index 72dbf3bd4c0a47011db7e00eded90b5b79b5fc7c..181465dd81b72fd8f20e86fc422c435f277ca62f 100644 (file)
@@ -1942,11 +1942,6 @@ st_ChooseTextureFormat(struct gl_context *ctx, GLenum target,
                        GLint internalFormat,
                        GLenum format, GLenum type)
 {
-   const boolean want_renderable =
-      internalFormat == 3 || internalFormat == 4 ||
-      internalFormat == GL_RGB || internalFormat == GL_RGBA ||
-      internalFormat == GL_RGB8 || internalFormat == GL_RGBA8 ||
-      internalFormat == GL_BGRA;
    struct st_context *st = st_context(ctx);
    enum pipe_format pFormat;
    unsigned bindings;
@@ -1962,15 +1957,17 @@ st_ChooseTextureFormat(struct gl_context *ctx, GLenum target,
    }
 
    /* GL textures may wind up being render targets, but we don't know
-    * that in advance.  Specify potential render target flags now.
+    * that in advance.  Specify potential render target flags now for formats
+    * that we know should always be renderable.
     */
    bindings = PIPE_BIND_SAMPLER_VIEW;
-   if (want_renderable) {
-      if (_mesa_is_depth_or_stencil_format(internalFormat))
-        bindings |= PIPE_BIND_DEPTH_STENCIL;
-      else
+   if (_mesa_is_depth_or_stencil_format(internalFormat))
+      bindings |= PIPE_BIND_DEPTH_STENCIL;
+   else if (internalFormat == 3 || internalFormat == 4 ||
+            internalFormat == GL_RGB || internalFormat == GL_RGBA ||
+            internalFormat == GL_RGB8 || internalFormat == GL_RGBA8 ||
+            internalFormat == GL_BGRA)
         bindings |= PIPE_BIND_RENDER_TARGET;
-   }
 
    /* GLES allows the driver to choose any format which matches
     * the format+type combo, because GLES only supports unsized internal