From 5a3411567a35e49bc2ae0c88ca5596804e6948c2 Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Wed, 21 Sep 2022 21:00:05 +0200 Subject: [PATCH] radv: Properly initialize all memory in RRA dumps. Helps debugging when making RADV BVH format changes. changes: 1. Change bool to uint32_t because padding was uninitialized 2. Named bitfields, because unnamed bitfields were never initialized. 3. Use calloc where possible. Reviewed-by: Friedrich Vock Part-of: --- src/amd/vulkan/radv_rra.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/amd/vulkan/radv_rra.c b/src/amd/vulkan/radv_rra.c index 574f1e5c1c0..3560d8e13aa 100644 --- a/src/amd/vulkan/radv_rra.c +++ b/src/amd/vulkan/radv_rra.c @@ -55,7 +55,7 @@ enum rra_file_api { struct rra_file_chunk_description { char name[16]; - bool is_zstd_compressed; + uint32_t is_zstd_compressed; enum rra_chunk_type type; uint64_t header_offset; uint64_t header_size; @@ -197,10 +197,10 @@ static_assert(sizeof(struct rra_accel_struct_chunk_header) == 28, struct rra_accel_struct_post_build_info { uint32_t bvh_type : 1; - uint32_t : 5; + uint32_t reserved1 : 5; uint32_t tri_compression_mode : 2; uint32_t fp16_interior_mode : 2; - uint32_t : 6; + uint32_t reserved2 : 6; uint32_t build_flags : 16; }; @@ -629,20 +629,20 @@ rra_dump_acceleration_structure(struct rra_copied_accel_struct *copied_struct, return VK_ERROR_VALIDATION_FAILED_EXT; } - uint32_t *node_parent_table = malloc(node_parent_table_size); + uint32_t *node_parent_table = calloc(node_parent_table_size, 1); if (!node_parent_table) { return VK_ERROR_OUT_OF_HOST_MEMORY; } node_parent_table[rra_parent_table_index_from_offset(RRA_ROOT_NODE_OFFSET, node_parent_table_size)] = 0xffffffff; - uint32_t *leaf_node_ids = malloc(primitive_count * sizeof(uint32_t)); + uint32_t *leaf_node_ids = calloc(primitive_count, sizeof(uint32_t)); if (!leaf_node_ids) { free(node_parent_table); return VK_ERROR_OUT_OF_HOST_MEMORY; } uint8_t *dst_structure_data = - malloc(RRA_ROOT_NODE_OFFSET + dst_internal_nodes_size + dst_leaf_nodes_size); + calloc(RRA_ROOT_NODE_OFFSET + dst_internal_nodes_size + dst_leaf_nodes_size, 1); if (!dst_structure_data) { free(node_parent_table); free(leaf_node_ids);