diff --git a/media_common/agnostic/common/codec/shared/codec_def_encode_hevc_trace.h b/media_common/agnostic/common/codec/shared/codec_def_encode_hevc_trace.h index 0f8012b25b4..4f05a10bcf4 100644 --- a/media_common/agnostic/common/codec/shared/codec_def_encode_hevc_trace.h +++ b/media_common/agnostic/common/codec/shared/codec_def_encode_hevc_trace.h @@ -28,6 +28,7 @@ #include "codec_def_encode_hevc.h" #include "mos_utilities.h" +#define RESERVE(num) data.reserve(num) #define NUM_ELEM_ARRAY(member) (sizeof(obj.member) / sizeof(obj.member[0])) #define PUSH(member) data.push_back(obj.member) #define PUSH64(member) \ @@ -37,21 +38,25 @@ data.push_back(p[1]); \ } #define PUSH_ARRAY(member) \ + RESERVE(NUM_ELEM_ARRAY(member)); \ for (size_t i0 = 0; i0 < NUM_ELEM_ARRAY(member); i0++) \ { \ PUSH(member[i0]); \ } #define PUSH_ARRAY2(member) \ + RESERVE(NUM_ELEM_ARRAY(member)); \ for (size_t i1 = 0; i1 < NUM_ELEM_ARRAY(member); i1++) \ { \ PUSH_ARRAY(member[i1]); \ } #define PUSH_ARRAY3(member) \ + RESERVE(NUM_ELEM_ARRAY(member)); \ for (size_t i2 = 0; i2 < NUM_ELEM_ARRAY(member); i2++) \ { \ PUSH_ARRAY2(member[i2]); \ } #define PUSH_SEQ(member, num) \ + RESERVE(num); \ for (size_t i = 0; i < num; i++) \ { \ PUSH(member[i]); \ diff --git a/media_driver/agnostic/Xe_M/Xe_HPM/vp/hal/vphal_render_vebox_xe_hpm.cpp b/media_driver/agnostic/Xe_M/Xe_HPM/vp/hal/vphal_render_vebox_xe_hpm.cpp index b75f8d05ba0..ecdfdc1ab0e 100644 --- a/media_driver/agnostic/Xe_M/Xe_HPM/vp/hal/vphal_render_vebox_xe_hpm.cpp +++ b/media_driver/agnostic/Xe_M/Xe_HPM/vp/hal/vphal_render_vebox_xe_hpm.cpp @@ -71,6 +71,7 @@ VPHAL_VEBOX_STATE_XE_HPM::VPHAL_VEBOX_STATE_XE_HPM( veboxMaxPipeNum = gtSystemInfo->MaxVECS; } + m_veCmdBuffers.reserve(veboxMaxPipeNum); for (i = 0; i < veboxMaxPipeNum; i++) { PMOS_COMMAND_BUFFER pCmdBuffer = (PMOS_COMMAND_BUFFER)MOS_AllocAndZeroMemory(sizeof(MOS_COMMAND_BUFFER)); diff --git a/media_driver/agnostic/Xe_M/Xe_XPM/vp/hal/vphal_render_vebox_xe_xpm.cpp b/media_driver/agnostic/Xe_M/Xe_XPM/vp/hal/vphal_render_vebox_xe_xpm.cpp index a15629cde28..a235e0d1aa7 100644 --- a/media_driver/agnostic/Xe_M/Xe_XPM/vp/hal/vphal_render_vebox_xe_xpm.cpp +++ b/media_driver/agnostic/Xe_M/Xe_XPM/vp/hal/vphal_render_vebox_xe_xpm.cpp @@ -74,6 +74,7 @@ VPHAL_VEBOX_STATE_XE_XPM::VPHAL_VEBOX_STATE_XE_XPM( veboxMaxPipeNum = gtSystemInfo->MaxVECS; } + m_veCmdBuffers.reserve(veboxMaxPipeNum); for (i = 0; i < veboxMaxPipeNum; i++) { PMOS_COMMAND_BUFFER pCmdBuffer = (PMOS_COMMAND_BUFFER)MOS_AllocAndZeroMemory(sizeof(MOS_COMMAND_BUFFER)); diff --git a/media_driver/agnostic/common/cm/cm_hal_generic.h b/media_driver/agnostic/common/cm/cm_hal_generic.h index 4c6006d6535..256e6cb8129 100644 --- a/media_driver/agnostic/common/cm/cm_hal_generic.h +++ b/media_driver/agnostic/common/cm/cm_hal_generic.h @@ -434,6 +434,7 @@ struct CM_HAL_GENERIC //! always return MOS_STATUS_SUCCESS virtual MOS_STATUS AddSupportedCisaIDs(uint32_t *cisaGenIDs, int len = 1) { + m_cisaGenIDs.reserve(len); for (int i = 0; i < len; i++) { m_cisaGenIDs.push_back(cisaGenIDs[i]); diff --git a/media_driver/agnostic/common/cm/cm_kernel_rt.cpp b/media_driver/agnostic/common/cm/cm_kernel_rt.cpp index f5cb877b8e4..f0285aa76f7 100644 --- a/media_driver/agnostic/common/cm/cm_kernel_rt.cpp +++ b/media_driver/agnostic/common/cm/cm_kernel_rt.cpp @@ -1907,6 +1907,7 @@ int32_t CmKernelRT::SetArgsInternal( CM_KERNEL_INTERNAL_ARG_TYPE nArgType, uint3 { size = numSamplers * sizeof(unsigned int); + sampler_index_array.reserve(numSamplers); for (unsigned int i = 0; i < numSamplers; i++) { SamplerIndex* samplerIndex = (SamplerIndex*)value + i; diff --git a/media_driver/agnostic/common/cm/cm_visa.cpp b/media_driver/agnostic/common/cm/cm_visa.cpp index 39a77bbc90e..a12b619d2f2 100644 --- a/media_driver/agnostic/common/cm/cm_visa.cpp +++ b/media_driver/agnostic/common/cm/cm_visa.cpp @@ -48,11 +48,13 @@ ISAfile::ISAfile(const ISAfile& other) { errorIndex = other.errorIndex; header = new Header(other.version); *header = *other.header; + kernel_data.reserve(other.kernel_data.size()); for (KernelBody *kb : other.kernel_data) { KernelBody *kb2 = new KernelBody(other.version); *kb2 = *kb; kernel_data.push_back(kb2); } + function_data.reserve(other.function_data.size()); for (FunctionBody *fb : other.function_data) { FunctionBody *fb2 = new FunctionBody(other.version); *fb2 = *fb; @@ -79,8 +81,10 @@ ISAfile& ISAfile::operator= (const ISAfile& other) { delete kb; for (FunctionBody *fb : function_data) delete fb; + kernel_data.reserve(other.kernel_data.size()); for (KernelBody *kb : other.kernel_data) kernel_data.push_back(&*kb); + function_data.reserve(other.function_data.size()); for (FunctionBody *fb : other.function_data) function_data.push_back(&*fb); } @@ -255,6 +259,7 @@ bool ISAfile::writeToFile(const char *filename, std::vector &originalBu setError("Error writing GEN binary into ISA file, bad offset from original file", 0); return false; } + buffer.reserve(g->getBinarySize()); for (uint32_t b = 0; b < g->getBinarySize(); b++) { buffer.push_back(static_cast(originalBuffer[offset + b])); } @@ -270,14 +275,17 @@ void ISAfile::addToBuffer(Field &field, std::vector &buffer) { switch (field.type) { case Datatype::ONE: buffer.push_back(field.ui8[0]); break; case Datatype::TWO: buffer.push_back(field.ui8[0]); buffer.push_back(field.ui8[1]); break; - case Datatype::FOUR: buffer.push_back(field.ui8[0]); buffer.push_back(field.ui8[1]); + case Datatype::FOUR: buffer.reserve(4); + buffer.push_back(field.ui8[0]); buffer.push_back(field.ui8[1]); buffer.push_back(field.ui8[2]); buffer.push_back(field.ui8[3]); break; - case Datatype::EIGHT: buffer.push_back(field.ui8[0]); buffer.push_back(field.ui8[1]); + case Datatype::EIGHT: buffer.reserve(8); + buffer.push_back(field.ui8[0]); buffer.push_back(field.ui8[1]); buffer.push_back(field.ui8[2]); buffer.push_back(field.ui8[3]); buffer.push_back(field.ui8[4]); buffer.push_back(field.ui8[5]); buffer.push_back(field.ui8[6]); buffer.push_back(field.ui8[7]); break; case Datatype::VARCHAR: { + buffer.reserve(field.size); for (unsigned i = 0; i < field.size; i++) { buffer.push_back(static_cast(field.varchar[i])); } @@ -285,6 +293,7 @@ void ISAfile::addToBuffer(Field &field, std::vector &buffer) { } case Datatype::VARCHAR_POOL: { + buffer.reserve(field.size); for (unsigned i = 0; i < field.size; i++) { buffer.push_back(static_cast(field.varchar[i])); } @@ -292,6 +301,7 @@ void ISAfile::addToBuffer(Field &field, std::vector &buffer) { } case Datatype::GDATA: { + buffer.reserve(field.size); for (unsigned i = 0; i < field.size; i++) { buffer.push_back(static_cast(field.gdata[i])); } diff --git a/media_driver/agnostic/common/cm/cm_visa.h b/media_driver/agnostic/common/cm/cm_visa.h index 600f3078c4e..ec13213a783 100644 --- a/media_driver/agnostic/common/cm/cm_visa.h +++ b/media_driver/agnostic/common/cm/cm_visa.h @@ -2386,11 +2386,13 @@ namespace vISA { //! Function(const Function& other) { fields = other.fields; + variable_reloc_symtab.reserve(other.variable_reloc_symtab.size()); for (RelocationInfo *r : other.variable_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; variable_reloc_symtab.push_back(s); } + function_reloc_symtab.reserve(other.function_reloc_symtab.size()); for (RelocationInfo *r : other.function_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; @@ -2408,6 +2410,7 @@ namespace vISA { fields = other.fields; for (RelocationInfo *r : variable_reloc_symtab) delete r; + variable_reloc_symtab.reserve(other.variable_reloc_symtab.size()); for (RelocationInfo *r : other.variable_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; @@ -2415,6 +2418,7 @@ namespace vISA { } for (RelocationInfo *r : function_reloc_symtab) delete r; + function_reloc_symtab.reserve(other.function_reloc_symtab.size()); for (RelocationInfo *r : other.function_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; @@ -2763,6 +2767,7 @@ namespace vISA { //! GlobalVariable(const GlobalVariable& other) { fields = other.fields; + attribute_info.reserve(other.attribute_info.size()); for (AttributeInfo *r : other.attribute_info) { AttributeInfo *s = new AttributeInfo(); *s = *r; @@ -2780,6 +2785,7 @@ namespace vISA { fields = other.fields; for (AttributeInfo *r : attribute_info) delete r; + attribute_info.reserve(other.attribute_info.size()); for (AttributeInfo *r : other.attribute_info) { AttributeInfo *s = new AttributeInfo(); *s = *r; @@ -4623,16 +4629,19 @@ namespace vISA { //! Kernel(const Kernel& other) { fields = other.fields; + variable_reloc_symtab.reserve(other.variable_reloc_symtab.size()); for (RelocationInfo *r : other.variable_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; variable_reloc_symtab.push_back(s); } + function_reloc_symtab.reserve(other.function_reloc_symtab.size()); for (RelocationInfo *r : other.function_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; function_reloc_symtab.push_back(s); } + gen_binary_info.reserve(other.gen_binary_info.size()); for (GenBinary *r : other.gen_binary_info) { GenBinary *s = new GenBinary(); *s = *r; @@ -4650,6 +4659,7 @@ namespace vISA { fields = other.fields; for (RelocationInfo *r : variable_reloc_symtab) delete r; + variable_reloc_symtab.reserve(other.variable_reloc_symtab.size()); for (RelocationInfo *r : other.variable_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; @@ -4657,6 +4667,7 @@ namespace vISA { } for (RelocationInfo *r : function_reloc_symtab) delete r; + function_reloc_symtab.reserve(other.function_reloc_symtab.size()); for (RelocationInfo *r : other.function_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; @@ -4664,6 +4675,7 @@ namespace vISA { } for (GenBinary *r : gen_binary_info) delete r; + gen_binary_info.reserve(other.gen_binary_info.size()); for (GenBinary *r : other.gen_binary_info) { GenBinary *s = new GenBinary(); *s = *r; @@ -5071,16 +5083,19 @@ namespace vISA { //! Header(const Header& other) { fields = other.fields; + kernel_info.reserve(other.kernel_info.size()); for (Kernel *r : other.kernel_info) { Kernel *s = new Kernel(); *s = *r; kernel_info.push_back(s); } + file_scope_var_info.reserve(other.file_scope_var_info.size()); for (GlobalVariable *r : other.file_scope_var_info) { GlobalVariable *s = new GlobalVariable(); *s = *r; file_scope_var_info.push_back(s); } + function_info.reserve(other.function_info.size()); for (Function *r : other.function_info) { Function *s = new Function(); *s = *r; @@ -5098,6 +5113,7 @@ namespace vISA { fields = other.fields; for (Kernel *r : kernel_info) delete r; + kernel_info.reserve(other.kernel_info.size()); for (Kernel *r : other.kernel_info) { Kernel *s = new Kernel(); *s = *r; @@ -5105,6 +5121,7 @@ namespace vISA { } for (GlobalVariable *r : file_scope_var_info) delete r; + file_scope_var_info.reserve(other.file_scope_var_info.size()); for (GlobalVariable *r : other.file_scope_var_info) { GlobalVariable *s = new GlobalVariable(); *s = *r; @@ -5112,6 +5129,7 @@ namespace vISA { } for (Function *r : function_info) delete r; + function_info.reserve(other.function_info.size()); for (Function *r : other.function_info) { Function *s = new Function(); *s = *r; diff --git a/media_driver/agnostic/gen12/codec/hal/codechal_encode_hevc_g12.cpp b/media_driver/agnostic/gen12/codec/hal/codechal_encode_hevc_g12.cpp index 38ac70eddac..9bbf8d71679 100644 --- a/media_driver/agnostic/gen12/codec/hal/codechal_encode_hevc_g12.cpp +++ b/media_driver/agnostic/gen12/codec/hal/codechal_encode_hevc_g12.cpp @@ -5732,9 +5732,10 @@ class QuadTreeNode void CreateCUs() { - uint32_t size = m_size / 2; - uint32_t level = m_level + 1; + const uint32_t size = m_size / 2; + const uint32_t level = m_level + 1; + m_childBlocks.reserve(4); m_childBlocks.emplace_back(m_ctb, m_x, m_y, level, m_ctbLog2Size); m_childBlocks.emplace_back(m_ctb, m_x + size, m_y, level, m_ctbLog2Size); m_childBlocks.emplace_back(m_ctb, m_x, m_y + size, level, m_ctbLog2Size); diff --git a/media_driver/agnostic/gen9/cm/cm_hal_g9.h b/media_driver/agnostic/gen9/cm/cm_hal_g9.h index fe354e86a03..bb3c09812ec 100644 --- a/media_driver/agnostic/gen9/cm/cm_hal_g9.h +++ b/media_driver/agnostic/gen9/cm/cm_hal_g9.h @@ -157,6 +157,7 @@ struct CM_HAL_G9_X:public CM_HAL_GENERIC void OverwriteSteppingTable(const char **newTable, int len) { m_steppingTable.clear(); + m_steppingTable.reserve(len); for (int i = 0; i < len; i ++) { m_steppingTable.push_back(newTable[i]); diff --git a/media_driver/linux/common/ddi/media_libva_caps.cpp b/media_driver/linux/common/ddi/media_libva_caps.cpp index 41a51861bc0..02b784ebb59 100755 --- a/media_driver/linux/common/ddi/media_libva_caps.cpp +++ b/media_driver/linux/common/ddi/media_libva_caps.cpp @@ -44,6 +44,7 @@ typedef MediaLibvaCapsFactory CapsFactory; #endif #include "set" +#include "unordered_set" #ifndef VA_ENCRYPTION_TYPE_NONE #define VA_ENCRYPTION_TYPE_NONE 0x00000000 @@ -2345,14 +2346,15 @@ VAStatus MediaLibvaCaps::QueryConfigProfiles( { DDI_CHK_NULL(profileList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER); DDI_CHK_NULL(numProfiles, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER); - std::set profiles; + std::unordered_set profiles; int32_t i; + profiles.reserve(m_profileEntryCount); for (i = 0; i < m_profileEntryCount; i++) { profiles.insert((int32_t)m_profileEntryTbl[i].m_profile); } - std::set::iterator it; + std::unordered_set::iterator it; for (it = profiles.begin(), i = 0; it != profiles.end(); ++it, i++) { profileList[i] = (VAProfile)*it; diff --git a/media_driver/linux/ult/ult_app/ddi_test_caps.cpp b/media_driver/linux/ult/ult_app/ddi_test_caps.cpp index 9201390d718..d2f03a5c140 100644 --- a/media_driver/linux/ult/ult_app/ddi_test_caps.cpp +++ b/media_driver/linux/ult/ult_app/ddi_test_caps.cpp @@ -76,6 +76,7 @@ int Test_QueryConfigProfiles(VADriverContextP ctx, vector &queriedFea } else { + queriedFeatureIDTable.reserve(num_entrypoint); for (int j = 0; j < num_entrypoint; j++) { queriedFeatureIDTable.push_back({profile, entrypoints[j]}); diff --git a/media_softlet/agnostic/Xe2_M_plus/Xe2_LPM_base/codec/hal/dec/av1/features/decode_av1_downsampling_feature_xe2_lpm_base.cpp b/media_softlet/agnostic/Xe2_M_plus/Xe2_LPM_base/codec/hal/dec/av1/features/decode_av1_downsampling_feature_xe2_lpm_base.cpp index 63ac72b24cb..0fbf2ac35e2 100644 --- a/media_softlet/agnostic/Xe2_M_plus/Xe2_LPM_base/codec/hal/dec/av1/features/decode_av1_downsampling_feature_xe2_lpm_base.cpp +++ b/media_softlet/agnostic/Xe2_M_plus/Xe2_LPM_base/codec/hal/dec/av1/features/decode_av1_downsampling_feature_xe2_lpm_base.cpp @@ -62,6 +62,7 @@ MOS_STATUS Av1DownSamplingFeatureXe2_Lpm_Base::GetRefFrameList(std::vector } refFrameList.clear(); + refFrameList.reserve(refFrameIndexList.size()); for (uint32_t frameIdx : refFrameIndexList) { refFrameList.push_back(frameIdx); diff --git a/media_softlet/agnostic/common/codec/hal/dec/avc/features/decode_avc_downsampling_feature.cpp b/media_softlet/agnostic/common/codec/hal/dec/avc/features/decode_avc_downsampling_feature.cpp index 49769bc321c..e9cc89e7dbd 100644 --- a/media_softlet/agnostic/common/codec/hal/dec/avc/features/decode_avc_downsampling_feature.cpp +++ b/media_softlet/agnostic/common/codec/hal/dec/avc/features/decode_avc_downsampling_feature.cpp @@ -52,7 +52,7 @@ MOS_STATUS AvcDownSamplingFeature::GetRefFrameList(std::vector &refFra avcBasicFeature->m_refFrames.GetActiveReferenceList(*avcBasicFeature->m_avcPicParams); refFrameList.clear(); - + refFrameList.reserve(activeRefList.size()); for (uint8_t frameIdx : activeRefList) { refFrameList.push_back(frameIdx); diff --git a/media_softlet/agnostic/common/codec/hal/dec/shared/bufferMgr/decode_reference_associated_buffer.h b/media_softlet/agnostic/common/codec/hal/dec/shared/bufferMgr/decode_reference_associated_buffer.h index e025aa6a213..093fba1c622 100644 --- a/media_softlet/agnostic/common/codec/hal/dec/shared/bufferMgr/decode_reference_associated_buffer.h +++ b/media_softlet/agnostic/common/codec/hal/dec/shared/bufferMgr/decode_reference_associated_buffer.h @@ -114,6 +114,7 @@ class RefrenceAssociatedBuffer DECODE_ASSERT(m_availableBuffers.empty()); DECODE_ASSERT(m_activeBuffers.empty()); + m_availableBuffers.reserve(initialAllocNum); for (uint32_t i = 0; i < initialAllocNum; i++) { BufferType *buffer = m_bufferOp.Allocate(); diff --git a/media_softlet/agnostic/common/codec/hal/dec/vp9/features/decode_vp9_reference_frames.cpp b/media_softlet/agnostic/common/codec/hal/dec/vp9/features/decode_vp9_reference_frames.cpp index 9326fd21736..a0001f0fcc0 100644 --- a/media_softlet/agnostic/common/codec/hal/dec/vp9/features/decode_vp9_reference_frames.cpp +++ b/media_softlet/agnostic/common/codec/hal/dec/vp9/features/decode_vp9_reference_frames.cpp @@ -188,6 +188,7 @@ namespace decode DECODE_FUNC_CALL(); m_activeReferenceList.clear(); + m_activeReferenceList.reserve(CODECHAL_MAX_CUR_NUM_REF_FRAME_VP9); for (auto i = 0; i < CODECHAL_MAX_CUR_NUM_REF_FRAME_VP9; i++) { m_activeReferenceList.push_back(picParams.RefFrameList[i].FrameIdx); diff --git a/media_softlet/agnostic/common/codec/hal/enc/av1/pipeline/encode_av1_reference_frames.cpp b/media_softlet/agnostic/common/codec/hal/enc/av1/pipeline/encode_av1_reference_frames.cpp index d693abdfff6..3506e5ebeb5 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/av1/pipeline/encode_av1_reference_frames.cpp +++ b/media_softlet/agnostic/common/codec/hal/enc/av1/pipeline/encode_av1_reference_frames.cpp @@ -539,7 +539,7 @@ std::vector Av1ReferenceFrames::GetEncRefSurface() const auto idxList = GetRefScalingIdx(); std::vector ret; - + ret.reserve(idxList.size()); for (auto idx : idxList) { ret.push_back(m_basicFeature->m_trackedBuf->GetSurface(m_encRefBufType, idx)); @@ -552,7 +552,7 @@ std::vector Av1ReferenceFrames::GetEnc4xRefSurface() const { auto idxList = GetRefScalingIdx(); std::vector ret; - + ret.reserve(idxList.size()); for (auto idx : idxList) { ret.push_back(m_basicFeature->m_trackedBuf->GetSurface(m_enc4xRefBufType, idx)); @@ -565,7 +565,7 @@ std::vector Av1ReferenceFrames::GetEnc8xRefSurface() const { auto idxList = GetRefScalingIdx(); std::vector ret; - + ret.reserve(idxList.size()); for (auto idx : idxList) { ret.push_back(m_basicFeature->m_trackedBuf->GetSurface(m_enc8xRefBufType, idx)); diff --git a/media_softlet/agnostic/common/codec/hal/enc/hevc/features/roi/encode_hevc_vdenc_roi_strategy.cpp b/media_softlet/agnostic/common/codec/hal/enc/hevc/features/roi/encode_hevc_vdenc_roi_strategy.cpp index eb64734f03c..31ad89c982c 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/hevc/features/roi/encode_hevc_vdenc_roi_strategy.cpp +++ b/media_softlet/agnostic/common/codec/hal/enc/hevc/features/roi/encode_hevc_vdenc_roi_strategy.cpp @@ -297,6 +297,7 @@ void RoiStrategy::GetLCUsInRoiRegionForTile( tileEndLcuY, streamInBaseOffset); + lcuVector.reserve((bottom - top) * (right - left)); for (auto y = top; y < bottom; y++) { for (auto x = left; x < right; x++) @@ -347,6 +348,7 @@ void RoiStrategy::GetLCUsInRoiRegion( return; } + lcuVector.reserve((bottom - top) * (right - left)); for (auto y = top; y < bottom; y++) { for (auto x = left; x < right; x++) diff --git a/media_softlet/agnostic/common/codec/hal/enc/shared/bufferMgr/encode_tracked_buffer.cpp b/media_softlet/agnostic/common/codec/hal/enc/shared/bufferMgr/encode_tracked_buffer.cpp index 35275609991..e62802b5d71 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/shared/bufferMgr/encode_tracked_buffer.cpp +++ b/media_softlet/agnostic/common/codec/hal/enc/shared/bufferMgr/encode_tracked_buffer.cpp @@ -40,6 +40,7 @@ TrackedBuffer::TrackedBuffer(EncodeAllocator *allocator, uint8_t maxRefCnt, uint m_allocator(allocator) { m_maxSlotCnt = m_maxRefSlotCnt + m_maxNonRefSlotCnt; + m_bufferSlots.reserve(m_maxSlotCnt); for (uint8_t i = 0; i < m_maxSlotCnt; i++) { m_bufferSlots.push_back(MOS_New(BufferSlot, this)); diff --git a/media_softlet/agnostic/common/shared/media_debug_interface.cpp b/media_softlet/agnostic/common/shared/media_debug_interface.cpp index 9bffef58c68..806740cd700 100644 --- a/media_softlet/agnostic/common/shared/media_debug_interface.cpp +++ b/media_softlet/agnostic/common/shared/media_debug_interface.cpp @@ -137,6 +137,7 @@ MOS_STATUS MediaDebugInterface::SetOutputFilePath() void MediaDebugInterface::PackGoldenReferences(std::initializer_list> goldenReference) { + m_goldenReferences.reserve(goldenReference.size()); for (auto beg = goldenReference.begin(); beg != goldenReference.end(); beg++) { m_goldenReferences.push_back(*beg); @@ -189,6 +190,7 @@ MOS_STATUS MediaDebugInterface::LockResource(uint32_t *semaData, PMOS_RESOURCE r MOS_STATUS MediaDebugInterface::LockSemaResource(std::vector &vSemaData, std::vector &vResource) { + vSemaData.reserve(vResource.size()); for (uint32_t i = 0; i < vResource.size(); i++) { CodechalResLock semaLock(m_osInterface, &vResource[i]); diff --git a/media_softlet/agnostic/common/vp/hal/bufferMgr/vp_resource_manager.cpp b/media_softlet/agnostic/common/vp/hal/bufferMgr/vp_resource_manager.cpp index c80807aae04..dd4a7095a2a 100644 --- a/media_softlet/agnostic/common/vp/hal/bufferMgr/vp_resource_manager.cpp +++ b/media_softlet/agnostic/common/vp/hal/bufferMgr/vp_resource_manager.cpp @@ -1359,7 +1359,11 @@ MOS_STATUS VpResourceManager::AssignExecuteResource(std::vector &fe VP_FUNC_CALL(); std::vector inputSurfaces, pastSurfaces, futureSurfaces; - for (uint32_t i = 0; i < executedFilters.GetSurfaceCount(true); ++i) + auto surfaceCount = executedFilters.GetSurfaceCount(true); + inputSurfaces.reserve(surfaceCount); + pastSurfaces.reserve(surfaceCount); + futureSurfaces.reserve(surfaceCount); + for (uint32_t i = 0; i < surfaceCount; ++i) { VP_SURFACE *inputSurface = GetCopyInstOfExtSurface(executedFilters.GetSurface(true, i)); VP_PUBLIC_CHK_NULL_RETURN(inputSurface); @@ -1404,7 +1408,11 @@ MOS_STATUS VpResourceManager::GetUpdatedExecuteResource(std::vector VP_FUNC_CALL(); std::vector inputSurfaces, pastSurfaces, futureSurfaces; - for (uint32_t i = 0; i < swfilterPipe.GetSurfaceCount(true); ++i) + auto surfaceCount = swfilterPipe.GetSurfaceCount(true); + inputSurfaces.reserve(surfaceCount); + pastSurfaces.reserve(surfaceCount); + futureSurfaces.reserve(surfaceCount); + for (uint32_t i = 0; i < surfaceCount; ++i) { VP_SURFACE *inputSurface = GetCopyInstOfExtSurface(swfilterPipe.GetSurface(true, i)); VP_PUBLIC_CHK_NULL_RETURN(inputSurface); diff --git a/media_softlet/agnostic/common/vp/hal/feature_manager/policy.cpp b/media_softlet/agnostic/common/vp/hal/feature_manager/policy.cpp index 1467a4dab1a..d7b4f5ddc24 100644 --- a/media_softlet/agnostic/common/vp/hal/feature_manager/policy.cpp +++ b/media_softlet/agnostic/common/vp/hal/feature_manager/policy.cpp @@ -200,22 +200,27 @@ MOS_STATUS Policy::RegisterFeatures() m_RenderFeatureHandlers.insert(std::make_pair(FeatureTypeAiOnRender, p)); // Next step to add a table to trace all SW features based on platforms - m_featurePool.push_back(FeatureTypeCsc); - m_featurePool.push_back(FeatureTypeScaling); - m_featurePool.push_back(FeatureTypeRotMir); - m_featurePool.push_back(FeatureTypeDn); - m_featurePool.push_back(FeatureTypeSte); - m_featurePool.push_back(FeatureTypeTcc); - m_featurePool.push_back(FeatureTypeProcamp); - m_featurePool.push_back(FeatureTypeHdr); - m_featurePool.push_back(FeatureTypeDi); - m_featurePool.push_back(FeatureTypeFc); - m_featurePool.push_back(FeatureTypeLumakey); - m_featurePool.push_back(FeatureTypeBlending); - m_featurePool.push_back(FeatureTypeColorFill); - m_featurePool.push_back(FeatureTypeAlpha); - m_featurePool.push_back(FeatureTypeCgc); - m_featurePool.push_back(FeatureTypeAi); + static constexpr std::array features = { + FeatureTypeCsc, + FeatureTypeScaling, + FeatureTypeRotMir, + FeatureTypeDn, + FeatureTypeSte, + FeatureTypeTcc, + FeatureTypeProcamp, + FeatureTypeHdr, + FeatureTypeDi, + FeatureTypeFc, + FeatureTypeLumakey, + FeatureTypeBlending, + FeatureTypeColorFill, + FeatureTypeAlpha, + FeatureTypeCgc, + FeatureTypeAi + }; + m_featurePool.reserve(features.size()); + for (auto feature : features) + m_featurePool.push_back(feature); return MOS_STATUS_SUCCESS; } diff --git a/media_softlet/agnostic/common/vp/hal/feature_manager/policy.h b/media_softlet/agnostic/common/vp/hal/feature_manager/policy.h index 8342a502bdb..3023e537cdb 100644 --- a/media_softlet/agnostic/common/vp/hal/feature_manager/policy.h +++ b/media_softlet/agnostic/common/vp/hal/feature_manager/policy.h @@ -39,6 +39,7 @@ #include "sw_filter_pipe.h" #include "vp_resource_manager.h" #include +#include namespace vp { diff --git a/media_softlet/agnostic/common/vp/hal/feature_manager/sw_filter_pipe.cpp b/media_softlet/agnostic/common/vp/hal/feature_manager/sw_filter_pipe.cpp index 2839ae37f57..857f7aa083a 100644 --- a/media_softlet/agnostic/common/vp/hal/feature_manager/sw_filter_pipe.cpp +++ b/media_softlet/agnostic/common/vp/hal/feature_manager/sw_filter_pipe.cpp @@ -770,6 +770,7 @@ MOS_STATUS SwFilterPipe::AddSwFilterUnordered(SwFilter *swFilter, bool isInputPi VP_PUBLIC_CHK_NULL_RETURN(pipe); if ((size_t)index <= pipes.size()) { + pipes.reserve(index - pipes.size() + 1); // +1 because <= operator for (int32_t i = (int)pipes.size(); i <= index; ++i) { pipes.push_back(nullptr); @@ -958,6 +959,7 @@ MOS_STATUS SwFilterPipe::AddSurface(VP_SURFACE *&surf, bool isInputSurface, uint auto &surfaces = isInputSurface ? m_InputSurfaces : m_OutputSurfaces; auto &pipes = isInputSurface ? m_InputPipes : m_OutputPipes; + surfaces.reserve(index - surfaces.size()); // +1 because <= operator for (uint32_t i = surfaces.size(); i <= index; ++i) { surfaces.push_back(nullptr); @@ -980,6 +982,7 @@ MOS_STATUS SwFilterPipe::AddSurface(VP_SURFACE *&surf, bool isInputSurface, uint return MOS_STATUS_INVALID_PARAMETER; } + pipes.reserve(index - pipes.size() + 1); // +1 because <= operator for (uint32_t i = pipes.size(); i <= index; ++i) { pipes.push_back(nullptr); diff --git a/media_softlet/agnostic/common/vp/hal/packet/vp_render_cmd_packet.cpp b/media_softlet/agnostic/common/vp/hal/packet/vp_render_cmd_packet.cpp index 1e2680bc1a5..02556226166 100644 --- a/media_softlet/agnostic/common/vp/hal/packet/vp_render_cmd_packet.cpp +++ b/media_softlet/agnostic/common/vp/hal/packet/vp_render_cmd_packet.cpp @@ -370,6 +370,7 @@ MOS_STATUS VpRenderCmdPacket::SetupSamplerStates() VP_RENDER_CHK_STATUS_RETURN(m_kernel->SetSamplerStates(m_kernelSamplerStateGroup)); } + samplerStates.reserve(m_kernelSamplerStateGroup.size()); for (int samplerIndex = 0, activeSamplerLeft = m_kernelSamplerStateGroup.size(); activeSamplerLeft > 0; ++samplerIndex) { auto it = m_kernelSamplerStateGroup.find(samplerIndex); diff --git a/media_softlet/agnostic/common/vp/hal/utils/vp_visa.cpp b/media_softlet/agnostic/common/vp/hal/utils/vp_visa.cpp index 4aa2ea8e126..a396e15efda 100644 --- a/media_softlet/agnostic/common/vp/hal/utils/vp_visa.cpp +++ b/media_softlet/agnostic/common/vp/hal/utils/vp_visa.cpp @@ -53,11 +53,13 @@ ISAfile::ISAfile(const ISAfile& other) { errorIndex = other.errorIndex; header = new Header(other.version); *header = *other.header; + kernel_data.reserve(other.kernel_data.size()); for (KernelBody *kb : other.kernel_data) { KernelBody *kb2 = new KernelBody(other.version); *kb2 = *kb; kernel_data.push_back(kb2); } + function_data.reserve(other.function_data.size()); for (FunctionBody *fb : other.function_data) { FunctionBody *fb2 = new FunctionBody(other.version); *fb2 = *fb; @@ -90,8 +92,10 @@ ISAfile& ISAfile::operator= (const ISAfile& other) { delete kb; for (FunctionBody *fb : function_data) delete fb; + kernel_data.reserve(other.kernel_data.size()); for (KernelBody *kb : other.kernel_data) kernel_data.push_back(&*kb); + function_data.reserve(other.function_data.size()); for (FunctionBody *fb : other.function_data) function_data.push_back(&*fb); } @@ -133,6 +137,7 @@ bool ISAfile::loadHeader() { bool ISAfile::loadKernelData() { const uint8_t *p = 0; + kernel_data.reserve(header->getKernelInfo().size()); for (Kernel *k : header->getKernelInfo()) { KernelBody *kb = new KernelBody(version); p = kb->parse(data + k->getOffset(), end, this); @@ -148,6 +153,7 @@ bool ISAfile::loadKernelData() { bool ISAfile::loadFunctionData() { const uint8_t *p = 0; + function_data.reserve(header->getFunctionInfo().size()); for (Function *f : header->getFunctionInfo()) { FunctionBody *fb = new FunctionBody(version); p = fb->parse(data + f->getOffset(), end, this); @@ -270,6 +276,7 @@ bool ISAfile::writeToFile(const char *filename, std::vector &originalBu setError("Error writing GEN binary into ISA file, bad offset from original file", 0); return false; } + buffer.reserve(g->getBinarySize()); for (uint32_t b = 0; b < g->getBinarySize(); b++) { buffer.push_back(static_cast(originalBuffer[offset + b])); } @@ -285,14 +292,17 @@ void ISAfile::addToBuffer(Field &field, std::vector &buffer) { switch (field.type) { case Datatype::ONE: buffer.push_back(field.ui8[0]); break; case Datatype::TWO: buffer.push_back(field.ui8[0]); buffer.push_back(field.ui8[1]); break; - case Datatype::FOUR: buffer.push_back(field.ui8[0]); buffer.push_back(field.ui8[1]); + case Datatype::FOUR: buffer.reserve(4); + buffer.push_back(field.ui8[0]); buffer.push_back(field.ui8[1]); buffer.push_back(field.ui8[2]); buffer.push_back(field.ui8[3]); break; - case Datatype::EIGHT: buffer.push_back(field.ui8[0]); buffer.push_back(field.ui8[1]); + case Datatype::EIGHT: buffer.reserve(8); + buffer.push_back(field.ui8[0]); buffer.push_back(field.ui8[1]); buffer.push_back(field.ui8[2]); buffer.push_back(field.ui8[3]); buffer.push_back(field.ui8[4]); buffer.push_back(field.ui8[5]); buffer.push_back(field.ui8[6]); buffer.push_back(field.ui8[7]); break; case Datatype::VARCHAR: { + buffer.reserve(field.size); for (unsigned i = 0; i < field.size; i++) { buffer.push_back(static_cast(field.varchar[i])); } @@ -300,6 +310,7 @@ void ISAfile::addToBuffer(Field &field, std::vector &buffer) { } case Datatype::VARCHAR_POOL: { + buffer.reserve(field.size); for (unsigned i = 0; i < field.size; i++) { buffer.push_back(static_cast(field.varchar[i])); } @@ -307,6 +318,7 @@ void ISAfile::addToBuffer(Field &field, std::vector &buffer) { } case Datatype::GDATA: { + buffer.reserve(field.size); for (unsigned i = 0; i < field.size; i++) { buffer.push_back(static_cast(field.gdata[i])); } diff --git a/media_softlet/agnostic/common/vp/hal/utils/vp_visa.h b/media_softlet/agnostic/common/vp/hal/utils/vp_visa.h index 945b8f0a0b9..af92b17b15c 100644 --- a/media_softlet/agnostic/common/vp/hal/utils/vp_visa.h +++ b/media_softlet/agnostic/common/vp/hal/utils/vp_visa.h @@ -2424,11 +2424,13 @@ namespace vISA //! Function(const Function& other) { fields = other.fields; + variable_reloc_symtab.reserve(other.variable_reloc_symtab.size()); for (RelocationInfo *r : other.variable_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; variable_reloc_symtab.push_back(s); } + function_reloc_symtab.reserve(other.function_reloc_symtab.size()); for (RelocationInfo *r : other.function_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; @@ -2446,6 +2448,7 @@ namespace vISA fields = other.fields; for (RelocationInfo *r : variable_reloc_symtab) delete r; + variable_reloc_symtab.reserve(other.variable_reloc_symtab.size()); for (RelocationInfo *r : other.variable_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; @@ -2453,6 +2456,7 @@ namespace vISA } for (RelocationInfo *r : function_reloc_symtab) delete r; + function_reloc_symtab.reserve(other.function_reloc_symtab.size()); for (RelocationInfo *r : other.function_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; @@ -2801,6 +2805,7 @@ namespace vISA //! GlobalVariable(const GlobalVariable& other) { fields = other.fields; + attribute_info.reserve(other.attribute_info.size()); for (AttributeInfo *r : other.attribute_info) { AttributeInfo *s = new AttributeInfo(); *s = *r; @@ -2818,6 +2823,7 @@ namespace vISA fields = other.fields; for (AttributeInfo *r : attribute_info) delete r; + attribute_info.reserve(other.attribute_info.size()); for (AttributeInfo *r : other.attribute_info) { AttributeInfo *s = new AttributeInfo(); *s = *r; @@ -4669,16 +4675,19 @@ namespace vISA //! Kernel(const Kernel& other) { fields = other.fields; + variable_reloc_symtab.reserve(other.variable_reloc_symtab.size()); for (RelocationInfo *r : other.variable_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; variable_reloc_symtab.push_back(s); } + function_reloc_symtab.reserve(other.function_reloc_symtab.size()); for (RelocationInfo *r : other.function_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; function_reloc_symtab.push_back(s); } + gen_binary_info.reserve(other.gen_binary_info.size()); for (GenBinary *r : other.gen_binary_info) { GenBinary *s = new GenBinary(); *s = *r; @@ -4696,6 +4705,7 @@ namespace vISA fields = other.fields; for (RelocationInfo *r : variable_reloc_symtab) delete r; + variable_reloc_symtab.reserve(other.variable_reloc_symtab.size()); for (RelocationInfo *r : other.variable_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; @@ -4703,6 +4713,7 @@ namespace vISA } for (RelocationInfo *r : function_reloc_symtab) delete r; + function_reloc_symtab.reserve(other.function_reloc_symtab.size()); for (RelocationInfo *r : other.function_reloc_symtab) { RelocationInfo *s = new RelocationInfo(); *s = *r; @@ -4710,6 +4721,7 @@ namespace vISA } for (GenBinary *r : gen_binary_info) delete r; + gen_binary_info.reserve(other.gen_binary_info.size()); for (GenBinary *r : other.gen_binary_info) { GenBinary *s = new GenBinary(); *s = *r; @@ -5117,16 +5129,19 @@ namespace vISA //! Header(const Header& other) { fields = other.fields; + kernel_info.reserve(other.kernel_info.size()); for (Kernel *r : other.kernel_info) { Kernel *s = new Kernel(); *s = *r; kernel_info.push_back(s); } + file_scope_var_info.reserve(other.file_scope_var_info.size()); for (GlobalVariable *r : other.file_scope_var_info) { GlobalVariable *s = new GlobalVariable(); *s = *r; file_scope_var_info.push_back(s); } + function_info.reserve(other.function_info.size()); for (Function *r : other.function_info) { Function *s = new Function(); *s = *r; @@ -5144,6 +5159,7 @@ namespace vISA fields = other.fields; for (Kernel *r : kernel_info) delete r; + kernel_info.reserve(other.kernel_info.size()); for (Kernel *r : other.kernel_info) { Kernel *s = new Kernel(); *s = *r; @@ -5151,6 +5167,7 @@ namespace vISA } for (GlobalVariable *r : file_scope_var_info) delete r; + file_scope_var_info.reserve(other.file_scope_var_info.size()); for (GlobalVariable *r : other.file_scope_var_info) { GlobalVariable *s = new GlobalVariable(); *s = *r; @@ -5158,6 +5175,7 @@ namespace vISA } for (Function *r : function_info) delete r; + function_info.reserve(other.function_info.size()); for (Function *r : other.function_info) { Function *s = new Function(); *s = *r; diff --git a/media_softlet/linux/common/ddi/media_capstable_specific.cpp b/media_softlet/linux/common/ddi/media_capstable_specific.cpp index 59ea4cafa45..4504f445d4b 100644 --- a/media_softlet/linux/common/ddi/media_capstable_specific.cpp +++ b/media_softlet/linux/common/ddi/media_capstable_specific.cpp @@ -100,6 +100,7 @@ VAStatus MediaCapsTableSpecific::Init(DDI_MEDIA_CONTEXT *mediaCtx) int32_t numAttribList = attriblist->size(); if(componentData && componentData->size() != 0) { + m_configList.reserve(componentData->size()); for(int i = 0; i < componentData->size(); i++) { auto configData = componentData->at(i); diff --git a/media_softlet/linux/common/os/xe/include/mos_bufmgr_xe.h b/media_softlet/linux/common/os/xe/include/mos_bufmgr_xe.h index fdad7b3e1a7..9accccb7ca9 100644 --- a/media_softlet/linux/common/os/xe/include/mos_bufmgr_xe.h +++ b/media_softlet/linux/common/os/xe/include/mos_bufmgr_xe.h @@ -91,6 +91,7 @@ static int64_t __xe_bufmgr_debug__; } #define MOS_XE_GET_VALUES_FROM_MAP(map_datas, v_datas) \ + v_datas.reserve(map_datas.size()); \ for (auto &it : map_datas) \ { \ v_datas.push_back(it.second); \ diff --git a/media_softlet/linux/common/os/xe/mos_bufmgr_xe.c b/media_softlet/linux/common/os/xe/mos_bufmgr_xe.c index f4581d27e0f..6549c108e47 100644 --- a/media_softlet/linux/common/os/xe/mos_bufmgr_xe.c +++ b/media_softlet/linux/common/os/xe/mos_bufmgr_xe.c @@ -1898,6 +1898,8 @@ __mos_gem_bo_wait_timeline_rendering_with_flags_xe(struct mos_linux_bo *bo, rw_flags); bufmgr_gem->m_lock.unlock(); + handles.reserve(timeline_data.size()); + points.reserve(timeline_data.size()); for (auto it : timeline_data) { handles.push_back(it.first);