mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-13 16:20:18 +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>
|
||
|---|---|---|
| .. | ||
| .dir-locals.el | ||
| .editorconfig | ||
| meson.build | ||
| v3dv_android.c | ||
| v3dv_bo.c | ||
| v3dv_bo.h | ||
| v3dv_cl.c | ||
| v3dv_cl.h | ||
| v3dv_cmd_buffer.c | ||
| v3dv_debug.c | ||
| v3dv_debug.h | ||
| v3dv_descriptor_set.c | ||
| v3dv_device.c | ||
| v3dv_event.c | ||
| v3dv_formats.c | ||
| v3dv_image.c | ||
| v3dv_limits.h | ||
| v3dv_meta_clear.c | ||
| v3dv_meta_common.h | ||
| v3dv_meta_copy.c | ||
| v3dv_pass.c | ||
| v3dv_pipeline.c | ||
| v3dv_pipeline_cache.c | ||
| v3dv_private.h | ||
| v3dv_query.c | ||
| v3dv_queue.c | ||
| v3dv_uniforms.c | ||
| v3dv_wsi.c | ||
| v3dvx_cmd_buffer.c | ||
| v3dvx_descriptor_set.c | ||
| v3dvx_device.c | ||
| v3dvx_formats.c | ||
| v3dvx_image.c | ||
| v3dvx_meta_common.c | ||
| v3dvx_pipeline.c | ||
| v3dvx_private.h | ||
| v3dvx_query.c | ||
| v3dvx_queue.c | ||