[Mesa-dev] [PATCH 34/43] st/nine: Fix depth stencil formats bindings flags.

Axel Davy axel.davy at ens.fr
Fri Jan 30 12:34:33 PST 2015


Signed-off-by: Axel Davy <axel.davy at ens.fr>
---
 src/gallium/state_trackers/nine/adapter9.c   | 26 ++------------
 src/gallium/state_trackers/nine/device9.c    |  4 ++-
 src/gallium/state_trackers/nine/nine_pipe.h  | 51 ++++++++++++++++++++++++++++
 src/gallium/state_trackers/nine/swapchain9.c | 20 +++++++++--
 4 files changed, 74 insertions(+), 27 deletions(-)

diff --git a/src/gallium/state_trackers/nine/adapter9.c b/src/gallium/state_trackers/nine/adapter9.c
index 459aac3..e9bb9c0 100644
--- a/src/gallium/state_trackers/nine/adapter9.c
+++ b/src/gallium/state_trackers/nine/adapter9.c
@@ -385,29 +385,6 @@ NineAdapter9_CheckDeviceMultiSampleType( struct NineAdapter9 *This,
     return D3D_OK;
 }
 
-static INLINE boolean
-depth_stencil_format( D3DFORMAT fmt )
-{
-    static D3DFORMAT allowed[] = {
-        D3DFMT_D16_LOCKABLE,
-        D3DFMT_D32,
-        D3DFMT_D15S1,
-        D3DFMT_D24S8,
-        D3DFMT_D24X8,
-        D3DFMT_D24X4S4,
-        D3DFMT_D16,
-        D3DFMT_D32F_LOCKABLE,
-        D3DFMT_D24FS8,
-        D3DFMT_D32_LOCKABLE
-    };
-    unsigned i;
-
-    for (i = 0; i < sizeof(allowed)/sizeof(D3DFORMAT); i++) {
-        if (fmt == allowed[i]) { return TRUE; }
-    }
-    return FALSE;
-}
-
 HRESULT WINAPI
 NineAdapter9_CheckDepthStencilMatch( struct NineAdapter9 *This,
                                      D3DDEVTYPE DeviceType,
@@ -441,7 +418,8 @@ NineAdapter9_CheckDepthStencilMatch( struct NineAdapter9 *This,
         bfmt = dfmt;
     zsfmt = d3d9_to_pipe_format_checked(screen, DepthStencilFormat,
                                         PIPE_TEXTURE_2D, 0,
-                                        PIPE_BIND_DEPTH_STENCIL, FALSE);
+                                        d3d9_get_pipe_depth_format_bindings(DepthStencilFormat),
+                                        FALSE);
     if (dfmt == PIPE_FORMAT_NONE ||
         bfmt == PIPE_FORMAT_NONE ||
         zsfmt == PIPE_FORMAT_NONE) {
diff --git a/src/gallium/state_trackers/nine/device9.c b/src/gallium/state_trackers/nine/device9.c
index dfec5f9..fe251fe 100644
--- a/src/gallium/state_trackers/nine/device9.c
+++ b/src/gallium/state_trackers/nine/device9.c
@@ -971,7 +971,7 @@ create_zs_or_rt_surface(struct NineDevice9 *This,
     templ.bind = PIPE_BIND_SAMPLER_VIEW; /* StretchRect */
     switch (type) {
     case 0: templ.bind |= PIPE_BIND_RENDER_TARGET; break;
-    case 1: templ.bind |= PIPE_BIND_DEPTH_STENCIL; break;
+    case 1: templ.bind = d3d9_get_pipe_depth_format_bindings(Format); break;
     default:
         assert(type == 2);
         break;
@@ -1042,6 +1042,8 @@ NineDevice9_CreateDepthStencilSurface( struct NineDevice9 *This,
                                        HANDLE *pSharedHandle )
 {
     *ppSurface = NULL;
+    if (!depth_stencil_format(Format))
+        return D3DERR_NOTAVAILABLE;
     return create_zs_or_rt_surface(This, 1, D3DPOOL_DEFAULT,
                                    Width, Height, Format,
                                    MultiSample, MultisampleQuality,
diff --git a/src/gallium/state_trackers/nine/nine_pipe.h b/src/gallium/state_trackers/nine/nine_pipe.h
index 9521d1a..7295bdf 100644
--- a/src/gallium/state_trackers/nine/nine_pipe.h
+++ b/src/gallium/state_trackers/nine/nine_pipe.h
@@ -175,6 +175,57 @@ pipe_to_d3d9_format(enum pipe_format format)
     return nine_pipe_to_d3d9_format_map[format];
 }
 
+static INLINE boolean
+depth_stencil_format( D3DFORMAT fmt )
+{
+    static D3DFORMAT allowed[] = {
+        D3DFMT_D16_LOCKABLE,
+        D3DFMT_D32,
+        D3DFMT_D15S1,
+        D3DFMT_D24S8,
+        D3DFMT_D24X8,
+        D3DFMT_D24X4S4,
+        D3DFMT_D16,
+        D3DFMT_D32F_LOCKABLE,
+        D3DFMT_D24FS8,
+        D3DFMT_D32_LOCKABLE,
+        D3DFMT_DF16,
+        D3DFMT_DF24,
+        D3DFMT_INTZ
+    };
+    unsigned i;
+
+    for (i = 0; i < sizeof(allowed)/sizeof(D3DFORMAT); i++) {
+        if (fmt == allowed[i]) { return TRUE; }
+    }
+    return FALSE;
+}
+
+static INLINE unsigned
+d3d9_get_pipe_depth_format_bindings(D3DFORMAT format)
+{
+    switch (format) {
+    case D3DFMT_D32:
+    case D3DFMT_D15S1:
+    case D3DFMT_D24S8:
+    case D3DFMT_D24X8:
+    case D3DFMT_D24X4S4:
+    case D3DFMT_D16:
+    case D3DFMT_D24FS8:
+        return PIPE_BIND_DEPTH_STENCIL;
+    case D3DFMT_D32F_LOCKABLE:
+    case D3DFMT_D16_LOCKABLE:
+    case D3DFMT_D32_LOCKABLE:
+        return PIPE_BIND_DEPTH_STENCIL | PIPE_BIND_TRANSFER_READ |
+               PIPE_BIND_TRANSFER_WRITE;
+    case D3DFMT_DF16:
+    case D3DFMT_DF24:
+    case D3DFMT_INTZ:
+        return PIPE_BIND_DEPTH_STENCIL | PIPE_BIND_SAMPLER_VIEW;
+    default: assert(0);
+    }
+}
+
 static INLINE enum pipe_format
 d3d9_to_pipe_format_internal(D3DFORMAT format)
 {
diff --git a/src/gallium/state_trackers/nine/swapchain9.c b/src/gallium/state_trackers/nine/swapchain9.c
index 9db6ff4..0e13507 100644
--- a/src/gallium/state_trackers/nine/swapchain9.c
+++ b/src/gallium/state_trackers/nine/swapchain9.c
@@ -341,8 +341,14 @@ NineSwapChain9_Resize( struct NineSwapChain9 *This,
         pipe_resource_reference(&resource, NULL);
     }
     if (pParams->EnableAutoDepthStencil) {
-        tmplt.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_TRANSFER_READ |
-                     PIPE_BIND_TRANSFER_WRITE | PIPE_BIND_DEPTH_STENCIL;
+        tmplt.bind = d3d9_get_pipe_depth_format_bindings(pParams->AutoDepthStencilFormat);
+        /* Checking the d3d9 depth format for texture support indicates the app if it can use
+         * the format for shadow mapping or texturing. If the check returns true, then the app
+         * is allowed to use this functionnality, so try first to create the buffer
+         * with PIPE_BIND_SAMPLER_VIEW. If the format can't be created with it, try without.
+         * If it fails with PIPE_BIND_SAMPLER_VIEW, then the app check for texture support
+         * would fail too, so we are fine. */
+        tmplt.bind |= PIPE_BIND_SAMPLER_VIEW;
         tmplt.nr_samples = pParams->MultiSampleType;
         tmplt.format = d3d9_to_pipe_format_checked(This->screen,
                                                    pParams->AutoDepthStencilFormat,
@@ -350,6 +356,16 @@ NineSwapChain9_Resize( struct NineSwapChain9 *This,
                                                    tmplt.nr_samples,
                                                    tmplt.bind,
                                                    FALSE);
+        if (tmplt.format == PIPE_FORMAT_NONE) {
+            tmplt.bind &= ~PIPE_BIND_SAMPLER_VIEW;
+            tmplt.format = d3d9_to_pipe_format_checked(This->screen,
+                                                       pParams->AutoDepthStencilFormat,
+                                                       PIPE_TEXTURE_2D,
+                                                       tmplt.nr_samples,
+                                                       tmplt.bind,
+                                                       FALSE);
+        }
+
         if (tmplt.format == PIPE_FORMAT_NONE)
             return D3DERR_INVALIDCALL;
 
-- 
2.1.0



More information about the mesa-dev mailing list