Mesa (master): svga: add/use new svga_sampler_format() function

Brian Paul brianp at kemper.freedesktop.org
Wed Nov 18 16:38:14 UTC 2015


Module: Mesa
Branch: master
Commit: 1a90e3e1e3ee70504f2ce57462fb592b448269be
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1a90e3e1e3ee70504f2ce57462fb592b448269be

Author: Brian Paul <brianp at vmware.com>
Date:   Mon Nov 16 10:31:46 2015 -0700

svga: add/use new svga_sampler_format() function

This is important for the case of sampling from a depth texture.  In
that case, we need to sample the texture as if it were a single-channel
color texture.  For other/color formats, we can use the format as-is.

Reviewed-by: Charmaine Lee <charmainel at vmware.com>
Reviewed-by: José Fonseca <jfonseca at vmware.com>

---

 src/gallium/drivers/svga/svga_format.c        |   23 +++++++++++++++++++++++
 src/gallium/drivers/svga/svga_format.h        |    4 ++++
 src/gallium/drivers/svga/svga_state_sampler.c |    3 +++
 3 files changed, 30 insertions(+)

diff --git a/src/gallium/drivers/svga/svga_format.c b/src/gallium/drivers/svga/svga_format.c
index 28b8064..41bddd1 100644
--- a/src/gallium/drivers/svga/svga_format.c
+++ b/src/gallium/drivers/svga/svga_format.c
@@ -2098,3 +2098,26 @@ svga_typeless_format(SVGA3dSurfaceFormat format)
       return format;
    }
 }
+
+
+/**
+ * Given a surface format, return the corresponding format to use for
+ * a texture sampler.  In most cases, it's the format unchanged, but there
+ * are some special cases.
+ */
+SVGA3dSurfaceFormat
+svga_sampler_format(SVGA3dSurfaceFormat format)
+{
+   switch (format) {
+   case SVGA3D_D16_UNORM:
+      return SVGA3D_R16_UNORM;
+   case SVGA3D_D24_UNORM_S8_UINT:
+      return SVGA3D_R24_UNORM_X8_TYPELESS;
+   case SVGA3D_D32_FLOAT:
+      return SVGA3D_R32_FLOAT;
+   case SVGA3D_D32_FLOAT_S8X24_UINT:
+      return SVGA3D_R32_FLOAT_X8X24_TYPELESS;
+   default:
+      return format;
+   }
+}
diff --git a/src/gallium/drivers/svga/svga_format.h b/src/gallium/drivers/svga/svga_format.h
index 0af218c..9f9a530 100644
--- a/src/gallium/drivers/svga/svga_format.h
+++ b/src/gallium/drivers/svga/svga_format.h
@@ -93,4 +93,8 @@ SVGA3dSurfaceFormat
 svga_typeless_format(SVGA3dSurfaceFormat format);
 
 
+SVGA3dSurfaceFormat
+svga_sampler_format(SVGA3dSurfaceFormat format);
+
+
 #endif /* SVGA_FORMAT_H_ */
diff --git a/src/gallium/drivers/svga/svga_state_sampler.c b/src/gallium/drivers/svga/svga_state_sampler.c
index 611d2c6..c5d52bb 100644
--- a/src/gallium/drivers/svga/svga_state_sampler.c
+++ b/src/gallium/drivers/svga/svga_state_sampler.c
@@ -108,6 +108,9 @@ svga_validate_pipe_sampler_view(struct svga_context *svga,
                                      PIPE_BIND_SAMPLER_VIEW);
       assert(format != SVGA3D_FORMAT_INVALID);
 
+      /* Convert the format to a sampler-friendly format, if needed */
+      format = svga_sampler_format(format);
+
       if (texture->target == PIPE_BUFFER) {
          viewDesc.buffer.firstElement = sv->base.u.buf.first_element;
          viewDesc.buffer.numElements = (sv->base.u.buf.last_element -




More information about the mesa-commit mailing list