mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 08:40:11 +01:00
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>
This commit is contained in:
parent
9696fd378a
commit
fc286867fb
1 changed files with 3 additions and 3 deletions
|
|
@ -2063,12 +2063,12 @@ struct v3dv_descriptor_set_layout {
|
|||
/* Shader stages affected by this descriptor set */
|
||||
uint16_t shader_stages;
|
||||
|
||||
/* Number of descriptors in this descriptor set */
|
||||
uint32_t descriptor_count;
|
||||
|
||||
/* Number of dynamic offsets used by this descriptor set */
|
||||
uint16_t dynamic_offset_count;
|
||||
|
||||
/* Number of descriptors in this descriptor set */
|
||||
uint32_t descriptor_count;
|
||||
|
||||
/* Descriptor set layouts can be destroyed even if they are still being
|
||||
* used.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue