mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 08:40:11 +01:00
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>
|
||
|---|---|---|
| .. | ||
| ci | ||
| cle | ||
| clif | ||
| common | ||
| compiler | ||
| drm-shim | ||
| qpu | ||
| simulator | ||
| vulkan | ||
| .editorconfig | ||
| meson.build | ||