From 5cb32d45a8aa6e6538975b396a5a28d4cb45729f Mon Sep 17 00:00:00 2001 From: Gurchetan Singh Date: Tue, 9 Jul 2024 08:59:01 -0700 Subject: [PATCH] gfxstream: vulkan: fix issue with GCC With newer versions of libstdc++, debug builds of gfxstream hit this assert: 0x00007ffff6ed2d60 in std::__glibcxx_assert_fail (file=, line=, function=, condition=) at /usr/src/debug/gcc/gcc/libstdc++-v3/src/c++11/assert_fail.cc:41 std::allocator >::operator[] (this=0x555555609380, __n=0) at /usr/include/c++/14.1.1/bits/stl_vector.h:1130 (pDescriptorSets=0x7fffffffcc30, descriptorSetCount=2, bufferInfos=std::vector of length 1, capacity 1 = {...}) at ../guest/vulkan/gfxstream_vk_device.cpp:718 (device=0x55555562f400, descriptorWriteCount=2, pDescriptorWrites=0x7fffffffcc30, descriptorCopyCount=0, pDescriptorCopies=0x0) at ../guest/vulkan/gfxstream_vk_device.cpp:746 Use resize instead of reserve + memset. "That way the vector size would be initialized, bounds checks would be happy, and default-init would automatically zero out POD structs for us." -- dextero@ Reviewed-by: Aaron Ruby Acked-by: Yonggang Luo Acked-by: Adam Jackson Part-of: --- src/gfxstream/codegen/scripts/cereal/functable.py | 3 +-- src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/gfxstream/codegen/scripts/cereal/functable.py b/src/gfxstream/codegen/scripts/cereal/functable.py index 20906fe279d..a718babede8 100644 --- a/src/gfxstream/codegen/scripts/cereal/functable.py +++ b/src/gfxstream/codegen/scripts/cereal/functable.py @@ -392,8 +392,7 @@ class VulkanFuncTable(VulkanWrapperGenerator): cgen.stmt("%s = %s.size()" % (countParamName, nestedOutName)) else: # Standard translation - cgen.stmt("%s.reserve(%s)" % (nestedOutName, countParamName)) - cgen.stmt("memset(&%s[0], 0, sizeof(%s) * %s)" % (nestedOutName, member.typeName, countParamName)) + cgen.stmt("%s.resize(%s)" % (nestedOutName, countParamName)) if not nextLoopVar: nextLoopVar = getNextLoopVar() internalArray = genInternalArray(member, countParamName, nestedOutName, inArrayName, nextLoopVar) diff --git a/src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp b/src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp index 2ccf87e031d..1aa2b8ab46d 100644 --- a/src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp +++ b/src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp @@ -714,7 +714,7 @@ static std::vector transformDescriptorSetList( outDescriptorSet = srcDescriptorSet; bufferInfos.push_back(std::vector()); - bufferInfos[i].reserve(descriptorCount); + bufferInfos[i].resize(descriptorCount); memset(&bufferInfos[i][0], 0, sizeof(VkDescriptorBufferInfo) * descriptorCount); for (uint32_t j = 0; j < descriptorCount; ++j) { const auto* srcBufferInfo = srcDescriptorSet.pBufferInfo;