[PATCH 4/6] wined3d: Extend wined3d_check_device_format() to allow querying general format support.

Józef Kucia jkucia at codeweavers.com
Wed May 31 04:43:18 CDT 2017


For D3D10+.

When WINED3D_RTYPE_NONE is passed the wined3d_check_device_format()
function checks if a format is supported for all reasonable resource
types for a given usage. For now render target and depth stencil support
can be queried using this method.

Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---

Only 2D and 3D textures are checked because these resource types are supported
as render targets in wined3d.

---
 dlls/wined3d/directx.c | 68 ++++++++++++++++++++++++++++++--------------------
 dlls/wined3d/utils.c   |  1 +
 include/wine/wined3d.h |  1 +
 3 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index e6cefbd..9614e16 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -5236,9 +5236,9 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad
     const struct wined3d_format *adapter_format = wined3d_get_format(gl_info, adapter_format_id,
             WINED3DUSAGE_RENDERTARGET);
     const struct wined3d_format *format = wined3d_get_format(gl_info, check_format_id, usage);
+    enum wined3d_gl_resource_type gl_type, gl_type_end;
     DWORD format_flags = 0;
     DWORD allowed_usage;
-    enum wined3d_gl_resource_type gl_type;
 
     TRACE("wined3d %p, adapter_idx %u, device_type %s, adapter_format %s, usage %s, %s, "
             "resource_type %s, check_format %s.\n",
@@ -5251,6 +5251,13 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad
 
     switch (resource_type)
     {
+        case WINED3D_RTYPE_NONE:
+            allowed_usage = WINED3DUSAGE_DEPTHSTENCIL
+                    | WINED3DUSAGE_RENDERTARGET;
+            gl_type = WINED3D_GL_RES_TYPE_TEX_2D;
+            gl_type_end = WINED3D_GL_RES_TYPE_TEX_3D;
+            break;
+
         case WINED3D_RTYPE_TEXTURE_2D:
             allowed_usage = WINED3DUSAGE_DEPTHSTENCIL
                     | WINED3DUSAGE_RENDERTARGET
@@ -5265,7 +5272,7 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad
                     return WINED3DERR_NOTAVAILABLE;
                 }
 
-                gl_type = WINED3D_GL_RES_TYPE_RB;
+                gl_type = gl_type_end = WINED3D_GL_RES_TYPE_RB;
                 break;
             }
             allowed_usage |= WINED3DUSAGE_AUTOGENMIPMAP
@@ -5279,11 +5286,11 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad
                     | WINED3DUSAGE_QUERY_SRGBWRITE
                     | WINED3DUSAGE_QUERY_VERTEXTEXTURE
                     | WINED3DUSAGE_QUERY_WRAPANDMIP;
-            gl_type = WINED3D_GL_RES_TYPE_TEX_2D;
+            gl_type = gl_type_end = WINED3D_GL_RES_TYPE_TEX_2D;
             if (usage & WINED3DUSAGE_LEGACY_CUBEMAP)
             {
                 allowed_usage &= ~(WINED3DUSAGE_DEPTHSTENCIL | WINED3DUSAGE_QUERY_LEGACYBUMPMAP);
-                gl_type = WINED3D_GL_RES_TYPE_TEX_CUBE;
+                gl_type = gl_type_end = WINED3D_GL_RES_TYPE_TEX_CUBE;
             }
             else if ((usage & WINED3DUSAGE_DEPTHSTENCIL)
                     && (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_SHADOW)
@@ -5304,7 +5311,7 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad
                     | WINED3DUSAGE_QUERY_SRGBWRITE
                     | WINED3DUSAGE_QUERY_VERTEXTEXTURE
                     | WINED3DUSAGE_QUERY_WRAPANDMIP;
-            gl_type = WINED3D_GL_RES_TYPE_TEX_3D;
+            gl_type = gl_type_end = WINED3D_GL_RES_TYPE_TEX_3D;
             break;
 
         default:
@@ -5334,39 +5341,46 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad
     if (usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP)
         format_flags |= WINED3DFMT_FLAG_BUMPMAP;
 
-    if ((format->flags[gl_type] & format_flags) != format_flags)
-    {
-        TRACE("Requested format flags %#x, but format %s only has %#x.\n",
-                format_flags, debug_d3dformat(check_format_id), format->flags[gl_type]);
-        return WINED3DERR_NOTAVAILABLE;
-    }
-
     if ((format_flags & WINED3DFMT_FLAG_TEXTURE) && (wined3d->flags & WINED3D_NO3D))
     {
         TRACE("Requested texturing support, but wined3d was created with WINED3D_NO3D.\n");
         return WINED3DERR_NOTAVAILABLE;
     }
 
-    if ((usage & WINED3DUSAGE_DEPTHSTENCIL)
-            && !CheckDepthStencilCapability(adapter, adapter_format, format, gl_type))
+    if ((usage & WINED3DUSAGE_AUTOGENMIPMAP) && !gl_info->supported[SGIS_GENERATE_MIPMAP])
     {
-        TRACE("Requested WINED3DUSAGE_DEPTHSTENCIL, but format %s is not supported for depth / stencil buffers.\n",
-                debug_d3dformat(check_format_id));
-        return WINED3DERR_NOTAVAILABLE;
+        TRACE("No WINED3DUSAGE_AUTOGENMIPMAP support, returning WINED3DOK_NOAUTOGEN.\n");
+        return WINED3DOK_NOAUTOGEN;
     }
 
-    if ((usage & WINED3DUSAGE_RENDERTARGET)
-            && !CheckRenderTargetCapability(adapter, adapter_format, format, gl_type))
+    for (; gl_type <= gl_type_end; ++gl_type)
     {
-        TRACE("Requested WINED3DUSAGE_RENDERTARGET, but format %s is not supported for render targets.\n",
-                debug_d3dformat(check_format_id));
-        return WINED3DERR_NOTAVAILABLE;
-    }
+        if ((format->flags[gl_type] & format_flags) != format_flags)
+        {
+            TRACE("Requested format flags %#x, but format %s only has %#x.\n",
+                    format_flags, debug_d3dformat(check_format_id), format->flags[gl_type]);
+            return WINED3DERR_NOTAVAILABLE;
+        }
 
-    if ((usage & WINED3DUSAGE_AUTOGENMIPMAP) && !gl_info->supported[SGIS_GENERATE_MIPMAP])
-    {
-        TRACE("No WINED3DUSAGE_AUTOGENMIPMAP support, returning WINED3DOK_NOAUTOGEN.\n");
-        return WINED3DOK_NOAUTOGEN;
+        if ((usage & WINED3DUSAGE_RENDERTARGET)
+                && !CheckRenderTargetCapability(adapter, adapter_format, format, gl_type))
+        {
+            TRACE("Requested WINED3DUSAGE_RENDERTARGET, but format %s is not supported for render targets.\n",
+                    debug_d3dformat(check_format_id));
+            return WINED3DERR_NOTAVAILABLE;
+        }
+
+        /* 3D depth / stencil textures are never supported. */
+        if (usage == WINED3DUSAGE_DEPTHSTENCIL && gl_type == WINED3D_GL_RES_TYPE_TEX_3D)
+            continue;
+
+        if ((usage & WINED3DUSAGE_DEPTHSTENCIL)
+                && !CheckDepthStencilCapability(adapter, adapter_format, format, gl_type))
+        {
+            TRACE("Requested WINED3DUSAGE_DEPTHSTENCIL, but format %s is not supported for depth / stencil buffers.\n",
+                    debug_d3dformat(check_format_id));
+            return WINED3DERR_NOTAVAILABLE;
+        }
     }
 
     return WINED3D_OK;
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 2af75bf..79c322f 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -4120,6 +4120,7 @@ const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type)
     switch (resource_type)
     {
 #define WINED3D_TO_STR(x) case x: return #x
+        WINED3D_TO_STR(WINED3D_RTYPE_NONE);
         WINED3D_TO_STR(WINED3D_RTYPE_BUFFER);
         WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_2D);
         WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_3D);
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index 8697fbf..8ead497 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -670,6 +670,7 @@ enum wined3d_texture_filter_type
 
 enum wined3d_resource_type
 {
+    WINED3D_RTYPE_NONE                      = 0,
     WINED3D_RTYPE_BUFFER                    = 1,
     WINED3D_RTYPE_TEXTURE_2D                = 2,
     WINED3D_RTYPE_TEXTURE_3D                = 3,
-- 
2.10.2




More information about the wine-patches mailing list