Jan Sikorski : wined3d: Align vertex attribute offsets to their size, if smaller than 4.

Alexandre Julliard julliard at winehq.org
Mon Feb 8 15:46:42 CST 2021


Module: wine
Branch: master
Commit: 81dfece45ce7c1f0436e28675c53be734e94fb55
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=81dfece45ce7c1f0436e28675c53be734e94fb55

Author: Jan Sikorski <jsikorski at codeweavers.com>
Date:   Mon Feb  8 18:50:37 2021 +0100

wined3d: Align vertex attribute offsets to their size, if smaller than 4.

This should not change behaviour 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>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/wined3d/vertexdeclaration.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/dlls/wined3d/vertexdeclaration.c b/dlls/wined3d/vertexdeclaration.c
index c5df45541e4..e96216db380 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;
 
+        if ((alignment = e->format->byte_count) > 4)
+            alignment = 4;
+
         if (e->usage == WINED3D_DECL_USAGE_POSITIONT)
             declaration->position_transformed = TRUE;
 
@@ -239,15 +243,16 @@ 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)
+        if (e->offset & (alignment - 1))
         {
-            WARN("Declaration element %u is not 4 byte aligned(%u), returning E_FAIL.\n", i, e->offset);
+            WARN("Declaration element %u with format %s and offset %u is not %u byte aligned.\n",
+                    i, debug_d3dformat(elements[i].format), e->offset, alignment);
             heap_free(declaration->elements);
             return E_FAIL;
         }




More information about the wine-cvs mailing list