From b8c84d03cdd507590e048343ff2e5068246eedcc Mon Sep 17 00:00:00 2001 From: Jason Fielder Date: Mon, 20 Nov 2023 08:45:56 +0100 Subject: [PATCH] Fix #107025: Resolve incorrect UV stretch color on macOS Modify `UVStretchAngle` vertex struct alignment to match 4-byte struct alignment for Metal. This includes reordering array elements to the front and adding additional padding to the struct in Metal such that the raw-data write size matches the padded vertex format. Authored by Apple: Michael Parkin-White Pull Request: https://projects.blender.org/blender/blender/pulls/114923 --- .../extract_mesh_vbo_edituv_stretch_angle.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc index 6b4145573d5..c0a898784d2 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc @@ -23,9 +23,19 @@ namespace blender::draw { * \{ */ struct UVStretchAngle { - int16_t angle; + /* NOTE: To more easily satisfy cross-platform alignment requirements, placing the 4-byte aligned + * 2 element array first ensures each attribute block is 4-byte aligned. */ int16_t uv_angles[2]; + int16_t angle; +#if defined(WITH_METAL_BACKEND) + /* For apple platforms, vertex data struct must align to minimum per-vertex-stride of 4 bytes. + * Hence, this struct needs to align to 8 bytes. */ + int16_t __pad; +#endif }; +#if defined(WITH_METAL_BACKEND) +BLI_STATIC_ASSERT_ALIGN(UVStretchAngle, 4) +#endif struct MeshExtract_StretchAngle_Data { UVStretchAngle *vbo_data; @@ -85,8 +95,8 @@ static void extract_edituv_stretch_angle_init(const MeshRenderData &mr, static GPUVertFormat format = {0}; if (format.attr_len == 0) { /* Waning: adjust #UVStretchAngle struct accordingly. */ - GPU_vertformat_attr_add(&format, "angle", GPU_COMP_I16, 1, GPU_FETCH_INT_TO_FLOAT_UNIT); GPU_vertformat_attr_add(&format, "uv_angles", GPU_COMP_I16, 2, GPU_FETCH_INT_TO_FLOAT_UNIT); + GPU_vertformat_attr_add(&format, "angle", GPU_COMP_I16, 1, GPU_FETCH_INT_TO_FLOAT_UNIT); } GPU_vertbuf_init_with_format(vbo, &format);