[PATCH 01/11] wined3d: Move WINED3DFMT_FLAG_FLOAT to a separate group.

Chip Davis wine at gitlab.winehq.org
Mon May 16 20:26:45 CDT 2022


From: Chip Davis <cdavis5x at gmail.com>

There are only three unused format flags left. I will soon submit changes
which add four more format flags.

I've noticed that format flags generally fall into two groups:

* The first group consists of flags describing the content of a pixel
  format, e.g. whether or not this is a depth format, or whether this is
  a blocked format. These flags are the same for all resource types.
* The second group consists of flags describing capabilities of the
  implementation with this format. These can and do vary by resource
  type.

Only the second group needs to be stored per-resource-type.
---
 dlls/wined3d/adapter_gl.c      |  4 +-
 dlls/wined3d/device.c          |  3 +-
 dlls/wined3d/resource.c        |  1 +
 dlls/wined3d/utils.c           | 94 ++++++++++++++++++----------------
 dlls/wined3d/view.c            |  1 +
 dlls/wined3d/wined3d_private.h |  6 ++-
 6 files changed, 61 insertions(+), 48 deletions(-)

diff --git a/dlls/wined3d/adapter_gl.c b/dlls/wined3d/adapter_gl.c
index d72c43e48b8..547c2f67709 100644
--- a/dlls/wined3d/adapter_gl.c
+++ b/dlls/wined3d/adapter_gl.c
@@ -4474,7 +4474,7 @@ static BOOL wined3d_check_pixel_format_color(const struct wined3d_pixel_format *
         const struct wined3d_format *format)
 {
     /* Float formats need FBOs. If FBOs are used this function isn't called */
-    if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT)
+    if (format->base_flags & WINED3DFMT_FLAG_FLOAT)
         return FALSE;
 
     /* Probably a RGBA_float or color index mode. */
@@ -4496,7 +4496,7 @@ static BOOL wined3d_check_pixel_format_depth(const struct wined3d_pixel_format *
     BOOL lockable = FALSE;
 
     /* Float formats need FBOs. If FBOs are used this function isn't called */
-    if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT)
+    if (format->base_flags & WINED3DFMT_FLAG_FLOAT)
         return FALSE;
 
     if ((format->id == WINED3DFMT_D16_LOCKABLE) || (format->id == WINED3DFMT_D32_FLOAT))
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index d39634c49fc..3d4ebabcc60 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -5120,7 +5120,8 @@ void CDECL wined3d_device_context_clear_uav_float(struct wined3d_device_context
 {
     TRACE("context %p, view %p, clear_value %s.\n", context, view, debug_vec4(clear_value));
 
-    if (!(view->format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & (WINED3DFMT_FLAG_FLOAT | WINED3DFMT_FLAG_NORMALISED)))
+    if (!((view->format->base_flags & WINED3DFMT_FLAG_FLOAT) ||
+            (view->format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_NORMALISED)))
     {
         WARN("Not supported for view format %s.\n", debug_d3dformat(view->format->id));
         return;
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index 7fefd516908..20b14bf7a0f 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -188,6 +188,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
     resource->type = type;
     resource->gl_type = gl_type;
     resource->format = format;
+    resource->format_base_flags = format->base_flags;
     if (gl_type < WINED3D_GL_RES_TYPE_COUNT)
         resource->format_flags = format->flags[gl_type];
     resource->multisample_type = multisample_type;
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 088a904ffeb..6f3a8ba3413 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -306,7 +306,8 @@ static const struct wined3d_format_ddi_info ddi_formats[] =
 struct wined3d_format_base_flags
 {
     enum wined3d_format_id id;
-    DWORD flags;
+    unsigned int base_flags;
+    unsigned int flags;
 };
 
 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
@@ -314,48 +315,48 @@ struct wined3d_format_base_flags
  * resource size. */
 static const struct wined3d_format_base_flags format_base_flags[] =
 {
-    {WINED3DFMT_ATI1N,                 WINED3DFMT_FLAG_MAPPABLE | WINED3DFMT_FLAG_BROKEN_PITCH},
-    {WINED3DFMT_ATI2N,                 WINED3DFMT_FLAG_MAPPABLE | WINED3DFMT_FLAG_BROKEN_PITCH},
-    {WINED3DFMT_D16_LOCKABLE,          WINED3DFMT_FLAG_MAPPABLE},
-    {WINED3DFMT_INTZ,                  WINED3DFMT_FLAG_MAPPABLE},
+    {WINED3DFMT_ATI1N,                 0, WINED3DFMT_FLAG_MAPPABLE | WINED3DFMT_FLAG_BROKEN_PITCH},
+    {WINED3DFMT_ATI2N,                 0, WINED3DFMT_FLAG_MAPPABLE | WINED3DFMT_FLAG_BROKEN_PITCH},
+    {WINED3DFMT_D16_LOCKABLE,          0, WINED3DFMT_FLAG_MAPPABLE},
+    {WINED3DFMT_INTZ,                  0, WINED3DFMT_FLAG_MAPPABLE},
     {WINED3DFMT_R11G11B10_FLOAT,       WINED3DFMT_FLAG_FLOAT},
     {WINED3DFMT_D32_FLOAT,             WINED3DFMT_FLAG_FLOAT},
     {WINED3DFMT_S8_UINT_D24_FLOAT,     WINED3DFMT_FLAG_FLOAT},
     {WINED3DFMT_D32_FLOAT_S8X24_UINT,  WINED3DFMT_FLAG_FLOAT},
-    {WINED3DFMT_INST,                  WINED3DFMT_FLAG_EXTENSION},
-    {WINED3DFMT_NULL,                  WINED3DFMT_FLAG_EXTENSION},
-    {WINED3DFMT_NVDB,                  WINED3DFMT_FLAG_EXTENSION},
-    {WINED3DFMT_ATOC,                  WINED3DFMT_FLAG_EXTENSION},
-    {WINED3DFMT_RESZ,                  WINED3DFMT_FLAG_EXTENSION},
-    {WINED3DFMT_R32G32B32A32_TYPELESS, WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R32G32B32A32_FLOAT,    WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R32G32B32A32_UINT,     WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R32G32B32A32_SINT,     WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R16G16B16A16_TYPELESS, WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R16G16B16A16_FLOAT,    WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R16G16B16A16_UNORM,    WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R16G16B16A16_UINT,     WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R16G16B16A16_SNORM,    WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R16G16B16A16_SINT,     WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R32G32_TYPELESS,       WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R32G32_FLOAT,          WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R32G32_UINT,           WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R32G32_SINT,           WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R32_TYPELESS,          WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R32_FLOAT,             WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R32_UINT,              WINED3DFMT_FLAG_CAST_TO_BLOCK | WINED3DFMT_FLAG_INDEX_BUFFER},
-    {WINED3DFMT_R32_SINT,              WINED3DFMT_FLAG_CAST_TO_BLOCK},
-    {WINED3DFMT_R16_UINT,              WINED3DFMT_FLAG_INDEX_BUFFER},
-    {WINED3DFMT_A8_UNORM,              WINED3DFMT_FLAG_NORMALISED},
-    {WINED3DFMT_B10G10R10A2_UNORM,     WINED3DFMT_FLAG_NORMALISED},
-    {WINED3DFMT_B2G3R3_UNORM,          WINED3DFMT_FLAG_NORMALISED},
-    {WINED3DFMT_B4G4R4A4_UNORM,        WINED3DFMT_FLAG_NORMALISED},
-    {WINED3DFMT_B4G4R4X4_UNORM,        WINED3DFMT_FLAG_NORMALISED},
-    {WINED3DFMT_B5G5R5A1_UNORM,        WINED3DFMT_FLAG_NORMALISED},
-    {WINED3DFMT_B5G5R5X1_UNORM,        WINED3DFMT_FLAG_NORMALISED},
-    {WINED3DFMT_B5G6R5_UNORM,          WINED3DFMT_FLAG_NORMALISED},
-    {WINED3DFMT_B8G8R8_UNORM,          WINED3DFMT_FLAG_NORMALISED},
-    {WINED3DFMT_R10G10B10A2_UNORM,     WINED3DFMT_FLAG_NORMALISED},
+    {WINED3DFMT_INST,                  0, WINED3DFMT_FLAG_EXTENSION},
+    {WINED3DFMT_NULL,                  0, WINED3DFMT_FLAG_EXTENSION},
+    {WINED3DFMT_NVDB,                  0, WINED3DFMT_FLAG_EXTENSION},
+    {WINED3DFMT_ATOC,                  0, WINED3DFMT_FLAG_EXTENSION},
+    {WINED3DFMT_RESZ,                  0, WINED3DFMT_FLAG_EXTENSION},
+    {WINED3DFMT_R32G32B32A32_TYPELESS, 0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R32G32B32A32_FLOAT,    0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R32G32B32A32_UINT,     0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R32G32B32A32_SINT,     0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R16G16B16A16_TYPELESS, 0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R16G16B16A16_FLOAT,    0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R16G16B16A16_UNORM,    0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R16G16B16A16_UINT,     0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R16G16B16A16_SNORM,    0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R16G16B16A16_SINT,     0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R32G32_TYPELESS,       0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R32G32_FLOAT,          0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R32G32_UINT,           0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R32G32_SINT,           0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R32_TYPELESS,          0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R32_FLOAT,             0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R32_UINT,              0, WINED3DFMT_FLAG_CAST_TO_BLOCK | WINED3DFMT_FLAG_INDEX_BUFFER},
+    {WINED3DFMT_R32_SINT,              0, WINED3DFMT_FLAG_CAST_TO_BLOCK},
+    {WINED3DFMT_R16_UINT,              0, WINED3DFMT_FLAG_INDEX_BUFFER},
+    {WINED3DFMT_A8_UNORM,              0, WINED3DFMT_FLAG_NORMALISED},
+    {WINED3DFMT_B10G10R10A2_UNORM,     0, WINED3DFMT_FLAG_NORMALISED},
+    {WINED3DFMT_B2G3R3_UNORM,          0, WINED3DFMT_FLAG_NORMALISED},
+    {WINED3DFMT_B4G4R4A4_UNORM,        0, WINED3DFMT_FLAG_NORMALISED},
+    {WINED3DFMT_B4G4R4X4_UNORM,        0, WINED3DFMT_FLAG_NORMALISED},
+    {WINED3DFMT_B5G5R5A1_UNORM,        0, WINED3DFMT_FLAG_NORMALISED},
+    {WINED3DFMT_B5G5R5X1_UNORM,        0, WINED3DFMT_FLAG_NORMALISED},
+    {WINED3DFMT_B5G6R5_UNORM,          0, WINED3DFMT_FLAG_NORMALISED},
+    {WINED3DFMT_B8G8R8_UNORM,          0, WINED3DFMT_FLAG_NORMALISED},
+    {WINED3DFMT_R10G10B10A2_UNORM,     0, WINED3DFMT_FLAG_NORMALISED},
 };
 
 static void rgb888_from_rgb565(WORD rgb565, BYTE *r, BYTE *g, BYTE *b)
@@ -2081,8 +2082,8 @@ static BOOL init_format_base_info(struct wined3d_adapter *adapter)
     for (i = 0; i < ARRAY_SIZE(typed_formats); ++i)
     {
         struct wined3d_format *typeless_format;
+        unsigned int flags = 0, base_flags = 0;
         unsigned int component_count = 0;
-        DWORD flags = 0;
 
         if (!(format = get_format_internal(adapter, typed_formats[i].id)))
             return FALSE;
@@ -2118,7 +2119,7 @@ static BOOL init_format_base_info(struct wined3d_adapter *adapter)
             if (channel_type == WINED3D_CHANNEL_TYPE_UINT || channel_type == WINED3D_CHANNEL_TYPE_SINT)
                 flags |= WINED3DFMT_FLAG_INTEGER;
             if (channel_type == WINED3D_CHANNEL_TYPE_FLOAT)
-                flags |= WINED3DFMT_FLAG_FLOAT;
+                base_flags |= WINED3DFMT_FLAG_FLOAT;
             if (channel_type != WINED3D_CHANNEL_TYPE_UNUSED)
                 ++component_count;
 
@@ -2136,6 +2137,7 @@ static BOOL init_format_base_info(struct wined3d_adapter *adapter)
         }
 
         format->component_count = component_count;
+        format->base_flags |= base_flags;
         format_set_flag(format, flags);
     }
 
@@ -2152,6 +2154,7 @@ static BOOL init_format_base_info(struct wined3d_adapter *adapter)
         if (!(format = get_format_internal(adapter, format_base_flags[i].id)))
             return FALSE;
 
+        format->base_flags |= format_base_flags[i].base_flags;
         format_set_flag(format, format_base_flags[i].flags);
     }
 
@@ -3206,7 +3209,7 @@ static BOOL init_format_texture_info(struct wined3d_adapter *adapter, struct win
         /* ARB_texture_rg defines floating point formats, but only if
          * ARB_texture_float is also supported. */
         if (!gl_info->supported[ARB_TEXTURE_FLOAT]
-                && (format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT))
+                && (format->f.base_flags & WINED3DFMT_FLAG_FLOAT))
             continue;
 
         /* ARB_texture_rg defines integer formats if EXT_texture_integer is also supported. */
@@ -3800,7 +3803,7 @@ static BOOL init_format_vertex_info(const struct wined3d_adapter *adapter,
 static BOOL init_typeless_formats(const struct wined3d_adapter *adapter)
 {
     unsigned int flags[WINED3D_GL_RES_TYPE_COUNT];
-    unsigned int i, j;
+    unsigned int base_flags, i, j;
 
     for (i = 0; i < ARRAY_SIZE(typed_formats); ++i)
     {
@@ -3811,8 +3814,10 @@ static BOOL init_typeless_formats(const struct wined3d_adapter *adapter)
         if (!(typeless_format = get_format_internal(adapter, typed_formats[i].typeless_id)))
             return FALSE;
 
+        base_flags = typeless_format->base_flags;
         memcpy(flags, typeless_format->flags, sizeof(flags));
         copy_format(adapter, typeless_format, format);
+        typeless_format->base_flags = base_flags;
         for (j = 0; j < ARRAY_SIZE(typeless_format->flags); ++j)
             typeless_format->flags[j] |= flags[j];
     }
@@ -3831,6 +3836,7 @@ static BOOL init_typeless_formats(const struct wined3d_adapter *adapter)
         typeless_ds_format = get_format_by_idx(adapter, WINED3D_FORMAT_COUNT + i);
         typeless_ds_format->id = typeless_depth_stencil_formats[i].typeless_id;
         copy_format(adapter, typeless_ds_format, ds_format);
+        typeless_ds_format->base_flags = typeless_format->base_flags;
         for (j = 0; j < ARRAY_SIZE(typeless_ds_format->flags); ++j)
         {
             typeless_ds_format->flags[j] = typeless_format->flags[j];
@@ -4134,7 +4140,7 @@ static void init_format_depth_bias_scale(struct wined3d_adapter *adapter,
                 /* The single-precision binary floating-point format has
                  * a significand precision of 24 bits.
                  */
-                if (format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT)
+                if (format->f.base_flags & WINED3DFMT_FLAG_FLOAT)
                     format->f.depth_bias_scale /= 1u << 24;
                 else
                     format->f.depth_bias_scale /= 1u << format->f.depth_size;
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c
index f2dea8f0f9a..3866f3b4ebe 100644
--- a/dlls/wined3d/view.c
+++ b/dlls/wined3d/view.c
@@ -613,6 +613,7 @@ static HRESULT wined3d_rendertarget_view_init(struct wined3d_rendertarget_view *
     }
     if (!(view->format = validate_resource_view(desc, resource, TRUE, allow_srgb_toggle)))
         return E_INVALIDARG;
+    view->format_base_flags = view->format->base_flags;
     view->format_flags = view->format->flags[resource->gl_type];
     view->desc = *desc;
 
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 1d8bb40cec4..ffad3b82b90 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -4353,6 +4353,7 @@ struct wined3d_resource
     enum wined3d_resource_type type;
     enum wined3d_gl_resource_type gl_type;
     const struct wined3d_format *format;
+    unsigned int format_base_flags;
     unsigned int format_flags;
     enum wined3d_multisample_type multisample_type;
     UINT multisample_quality;
@@ -5337,6 +5338,7 @@ struct wined3d_rendertarget_view
     const struct wined3d_parent_ops *parent_ops;
 
     const struct wined3d_format *format;
+    unsigned int format_base_flags;
     unsigned int format_flags;
     unsigned int sub_resource_idx;
     unsigned int layer_count;
@@ -6104,6 +6106,8 @@ extern enum wined3d_format_id pixelformat_for_depth(DWORD depth) DECLSPEC_HIDDEN
  */
 
 /* WineD3D pixel format flags */
+#define WINED3DFMT_FLAG_FLOAT                       0x00000001
+
 #define WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING    0x00000001
 #define WINED3DFMT_FLAG_FILTERING                   0x00000002
 #define WINED3DFMT_FLAG_UNORDERED_ACCESS            0x00000004
@@ -6113,7 +6117,6 @@ extern enum wined3d_format_id pixelformat_for_depth(DWORD depth) DECLSPEC_HIDDEN
 #define WINED3DFMT_FLAG_FBO_ATTACHABLE              0x00000040
 #define WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB         0x00000080
 #define WINED3DFMT_FLAG_DECOMPRESS                  0x00000100
-#define WINED3DFMT_FLAG_FLOAT                       0x00000200
 #define WINED3DFMT_FLAG_BUMPMAP                     0x00000400
 #define WINED3DFMT_FLAG_SRGB_READ                   0x00000800
 #define WINED3DFMT_FLAG_SRGB_WRITE                  0x00001000
@@ -6186,6 +6189,7 @@ struct wined3d_format
 
     UINT  conv_byte_count;
     DWORD multisample_types;
+    unsigned int base_flags;
     unsigned int flags[WINED3D_GL_RES_TYPE_COUNT];
     float depth_bias_scale;
     struct wined3d_rational height_scale;
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/79



More information about the wine-devel mailing list