mesa/src/broadcom
Juan A. Suarez Romero fc286867fb v3dv: fix misalignment in descriptor layout structure
Current memory layout for v3dv_descriptior_set_layout structure is the
following:

```
                                                                  /* offset           size */
type = struct v3dv_descriptor_set_layout {
    struct vk_object_base base;                                   /*   0                64 */
    VkDescriptorSetLayoutCreateFlags flags;                       /*  64                 4 */
    uint32_t binding_count;                                       /*  68                 4 */
    uint32_t bo_size;                                             /*  72                 4 */
    uint16_t shader_stages;                                       /*  76                 2 */
                                                                  /*         PAD 2         */
    uint32_t descriptor_count;                                    /*  80                 4 */
    uint16_t dynamic_offset_count;                                /*  84                 2 */
                                                                  /*         PAD 2         */
    uint32_t ref_cnt;                                             /*  88                 4 */
    struct v3dv_descriptor_set_binding_layout binding[0];         /*  92                32 */
}                               [...]         binding[1];         /* 124                32 */
```

Besides wasting 4 bytes in padding, the main problem is that `binding`
fields are not aligned to 8 bytes (64-bits), which is undefined behaviour
in C.

Just moving `descriptor_count` field below we get the new layout:

```
                                                                  /* offset           size */
type = struct v3dv_descriptor_set_layout {
    struct vk_object_base base;                                   /*   0                64 */
    VkDescriptorSetLayoutCreateFlags flags;                       /*  64                 4 */
    uint32_t binding_count;                                       /*  68                 4 */
    uint32_t bo_size;                                             /*  72                 4 */
    uint16_t shader_stages;                                       /*  76                 2 */
    uint16_t dynamic_offset_count;                                /*  78                 2 */
    uint32_t descriptor_count;                                    /*  80                 4 */
    uint32_t ref_cnt;                                             /*  84                 4 */
    struct v3dv_descriptor_set_binding_layout binding[0];         /*  88                32 */
}                               [...]         binding[1];         /* 120                32 */
```

Which removes the padding requirement, and more important, make the
`binding` pointers to be correctly aligned.

This has been detected by the Undefined Behaviour Sanitizer (UBSan).

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29911>
2024-07-01 08:02:07 +00:00
..
ci v3d/ci: add nightly job for rusticl testing 2024-06-27 17:49:02 +00:00
cle build: pass licensing information in SPDX form 2024-06-29 12:42:49 -07:00
clif broadcom: only support v42 and v71 2023-11-02 11:59:08 +01:00
common broadcom: move HW-dependant constants to v3d_device_info 2024-06-05 17:14:59 +00:00
compiler broadcom/compiler: use unsigned types when performing bitshifting 2024-07-01 08:02:07 +00:00
drm-shim build: pass licensing information in SPDX form 2024-06-29 12:42:49 -07:00
qpu build: pass licensing information in SPDX form 2024-06-29 12:42:49 -07:00
simulator build: pass licensing information in SPDX form 2024-06-29 12:42:49 -07:00
vulkan v3dv: fix misalignment in descriptor layout structure 2024-07-01 08:02:07 +00:00
.editorconfig
meson.build build: pass licensing information in SPDX form 2024-06-29 12:42:49 -07:00