Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitce717dc

Browse files
liam-middlebrookjp7677
authored andcommitted
nvofapi: Use std::vector rather than callocing arrays
1 parent761f011 commitce717dc

File tree

2 files changed

+17
-31
lines changed

2 files changed

+17
-31
lines changed

‎src/nvofapi/nvofapi_common.cpp‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,14 @@ namespace nvofapi {
5050
uint32_tNvOFInstance::GetVkOFAQueue() {
5151
uint32_t count =0;
5252
m_vkGetPhysicalDeviceQueueFamilyProperties(m_vkPhysicalDevice, &count,nullptr);
53-
VkQueueFamilyProperties* queueFamProps =(VkQueueFamilyProperties*)calloc(sizeof(VkQueueFamilyProperties),count);
54-
m_vkGetPhysicalDeviceQueueFamilyProperties(m_vkPhysicalDevice, &count, queueFamProps);
53+
auto queueFamProps =std::vector<VkQueueFamilyProperties>(count);
54+
m_vkGetPhysicalDeviceQueueFamilyProperties(m_vkPhysicalDevice, &count, queueFamProps.data());
5555

5656
for (uint32_t i =0; i < count; i++) {
5757
if (queueFamProps[i].queueFlags & VK_QUEUE_OPTICAL_FLOW_BIT_NV) {
58-
free(queueFamProps);
5958
return i;
6059
}
6160
}
62-
free(queueFamProps);
6361
return -1;
6462
}
6563

@@ -193,29 +191,23 @@ namespace nvofapi {
193191
}
194192
}
195193
}
196-
VkRect2D* regions =nullptr;
197-
198-
if (inParams->numRois) {
199-
regions = (VkRect2D*)calloc(sizeof(VkRect2D), inParams->numRois);
200-
for (uint32_t i =0; i < inParams->numRois; i++) {
201-
regions[i].offset.x = inParams->roiData[i].start_x;
202-
regions[i].offset.y = inParams->roiData[i].start_y;
203-
regions[i].extent.width = inParams->roiData[i].width;
204-
regions[i].extent.height = inParams->roiData[i].height;
205-
}
194+
auto regions = std::vector<VkRect2D>(inParams->numRois);
195+
for (uint32_t i =0; i < inParams->numRois; i++) {
196+
regions[i].offset.x = inParams->roiData[i].start_x;
197+
regions[i].offset.y = inParams->roiData[i].start_y;
198+
regions[i].extent.width = inParams->roiData[i].width;
199+
regions[i].extent.height = inParams->roiData[i].height;
206200
}
207201

208202
VkOpticalFlowExecuteInfoNV ofaExecuteInfo{};
209203
ofaExecuteInfo.sType = VK_STRUCTURE_TYPE_OPTICAL_FLOW_EXECUTE_INFO_NV;
210204
ofaExecuteInfo.regionCount = inParams->numRois;
211-
ofaExecuteInfo.pRegions = regions;
205+
ofaExecuteInfo.pRegions = regions.data();
212206

213207
if (inParams->disableTemporalHints) {
214208
ofaExecuteInfo.flags |= VK_OPTICAL_FLOW_EXECUTE_DISABLE_TEMPORAL_HINTS_BIT_NV;
215209
}
216210

217211
m_vkCmdOpticalFlowExecuteNV(cmdBuf, m_vkOfaSession, &ofaExecuteInfo);
218-
219-
free(regions);
220212
}
221213
}

‎src/vulkan/nvofapi_vulkan_instance.cpp‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,12 @@ namespace nvofapi {
102102
" numWaitSync:", inParams->numWaitSyncs,
103103
" pWaitSyncs:", inParams->pWaitSyncs));
104104

105-
VkSemaphoreSubmitInfo* waitSyncs =nullptr;
106-
107-
if (inParams->numWaitSyncs) {
108-
waitSyncs = (VkSemaphoreSubmitInfo*)calloc(sizeof(VkSemaphoreSubmitInfo), inParams->numWaitSyncs);
109-
for (uint32_t i =0; i < inParams->numWaitSyncs; i++) {
110-
waitSyncs[i].sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO;
111-
waitSyncs[i].semaphore = inParams->pWaitSyncs[i].semaphore;
112-
waitSyncs[i].value = inParams->pWaitSyncs[i].value;
113-
waitSyncs[i].stageMask = VK_PIPELINE_STAGE_2_OPTICAL_FLOW_BIT_NV;
114-
}
105+
auto waitSyncs = std::vector<VkSemaphoreSubmitInfo>(inParams->numWaitSyncs);
106+
for (uint32_t i =0; i < inParams->numWaitSyncs; i++) {
107+
waitSyncs[i].sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO;
108+
waitSyncs[i].semaphore = inParams->pWaitSyncs[i].semaphore;
109+
waitSyncs[i].value = inParams->pWaitSyncs[i].value;
110+
waitSyncs[i].stageMask = VK_PIPELINE_STAGE_2_OPTICAL_FLOW_BIT_NV;
115111
}
116112

117113
VkSemaphoreSubmitInfo signalSync{};
@@ -138,17 +134,15 @@ namespace nvofapi {
138134

139135
VkSubmitInfo2 submit{};
140136
submit.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2;
141-
submit.waitSemaphoreInfoCount =inParams->numWaitSyncs;
142-
submit.pWaitSemaphoreInfos = waitSyncs;
137+
submit.waitSemaphoreInfoCount =waitSyncs.size();
138+
submit.pWaitSemaphoreInfos = waitSyncs.data();
143139
submit.commandBufferInfoCount =1;
144140
submit.pCommandBufferInfos = &cmdbufInfo;
145141
submit.signalSemaphoreInfoCount = (outParams->pSignalSync) ?1 :0;
146142
submit.pSignalSemaphoreInfos = &signalSync;
147143

148144
m_vkQueueSubmit2(m_queue,1, &submit, VK_NULL_HANDLE);
149145

150-
free(waitSyncs);
151-
152146
m_cmdBufIndex++;
153147
if (m_cmdBufIndex >= CMDS_IN_FLIGHT)
154148
m_cmdBufIndex =0;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp