[PATCH v2 1/4] wined3d: Align vertex attribute offsets to their size, if smaller than 4.

Jan Sikorski jsikorski at codeweavers.com
Mon Feb 8 04:41:50 CST 2021


This should not change behavior for d3d9 and earlier, where all formats
have sizes that are multiples of 4.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=43422
Signed-off-by: Jan Sikorski <jsikorski at codeweavers.com>
---
 dlls/wined3d/vertexdeclaration.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/dlls/wined3d/vertexdeclaration.c b/dlls/wined3d/vertexdeclaration.c
index c5df45541e4..ec8e2bc1d24 100644
--- a/dlls/wined3d/vertexdeclaration.c
+++ b/dlls/wined3d/vertexdeclaration.c
@@ -200,6 +200,7 @@ static HRESULT vertexdeclaration_init(struct wined3d_vertex_declaration *declara
     for (i = 0; i < element_count; ++i)
     {
         struct wined3d_vertex_declaration_element *e = &declaration->elements[i];
+        unsigned int alignment;
 
         e->format = wined3d_get_format(adapter, elements[i].format, 0);
         e->ffp_valid = declaration_element_valid_ffp(&elements[i]);
@@ -212,6 +213,9 @@ static HRESULT vertexdeclaration_init(struct wined3d_vertex_declaration *declara
         e->usage = elements[i].usage;
         e->usage_idx = elements[i].usage_idx;
 
+        alignment = e->format->byte_count;
+        if (alignment > 4) alignment = 4;
+
         if (e->usage == WINED3D_DECL_USAGE_POSITIONT)
             declaration->position_transformed = TRUE;
 
@@ -239,15 +243,15 @@ static HRESULT vertexdeclaration_init(struct wined3d_vertex_declaration *declara
                 prev = &declaration->elements[i - j];
                 if (prev->input_slot == e->input_slot)
                 {
-                    e->offset = (prev->offset + prev->format->byte_count + 3) & ~3;
+                    e->offset = (prev->offset + prev->format->byte_count + alignment - 1) & ~(alignment - 1);
                     break;
                 }
             }
         }
 
-        if (e->offset & 0x3)
-        {
-            WARN("Declaration element %u is not 4 byte aligned(%u), returning E_FAIL.\n", i, e->offset);
+        if (e->offset & (alignment - 1)) {
+            WARN("Declaration element %u with format %s is not %d byte aligned(%u). returning E_FAIL.\n",
+                    i, debug_d3dformat(elements[i].format), alignment, e->offset);
             heap_free(declaration->elements);
             return E_FAIL;
         }
-- 
2.30.0




More information about the wine-devel mailing list