1 //
2 // Copyright (c) 2022 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17
18 #include <algorithm>
19 #include "vulkan_list_map.hpp"
20 #include "vulkan_utility.hpp"
21 #include "vulkan_wrapper.hpp"
22
23 /////////////////////////////////////////////
24 // VulkanPhysicalDeviceList implementation //
25 /////////////////////////////////////////////
26
VulkanPhysicalDeviceList(const VulkanPhysicalDeviceList & physicalDeviceList)27 VulkanPhysicalDeviceList::VulkanPhysicalDeviceList(
28 const VulkanPhysicalDeviceList &physicalDeviceList)
29 {}
30
VulkanPhysicalDeviceList()31 VulkanPhysicalDeviceList::VulkanPhysicalDeviceList() {}
32
~VulkanPhysicalDeviceList()33 VulkanPhysicalDeviceList::~VulkanPhysicalDeviceList() {}
34
35 /////////////////////////////////////////
36 // VulkanMemoryHeapList implementation //
37 /////////////////////////////////////////
38
VulkanMemoryHeapList(const VulkanMemoryHeapList & memoryHeapList)39 VulkanMemoryHeapList::VulkanMemoryHeapList(
40 const VulkanMemoryHeapList &memoryHeapList)
41 {}
42
VulkanMemoryHeapList()43 VulkanMemoryHeapList::VulkanMemoryHeapList() {}
44
~VulkanMemoryHeapList()45 VulkanMemoryHeapList::~VulkanMemoryHeapList() {}
46
47 /////////////////////////////////////////
48 // VulkanMemoryTypeList implementation //
49 /////////////////////////////////////////
50
VulkanMemoryTypeList(const VulkanMemoryTypeList & memoryTypeList)51 VulkanMemoryTypeList::VulkanMemoryTypeList(
52 const VulkanMemoryTypeList &memoryTypeList)
53 {}
54
VulkanMemoryTypeList()55 VulkanMemoryTypeList::VulkanMemoryTypeList() {}
56
~VulkanMemoryTypeList()57 VulkanMemoryTypeList::~VulkanMemoryTypeList() {}
58
59 //////////////////////////////////////////
60 // VulkanQueueFamilyList implementation //
61 //////////////////////////////////////////
62
VulkanQueueFamilyList(const VulkanQueueFamilyList & queueFamilyList)63 VulkanQueueFamilyList::VulkanQueueFamilyList(
64 const VulkanQueueFamilyList &queueFamilyList)
65 {}
66
VulkanQueueFamilyList()67 VulkanQueueFamilyList::VulkanQueueFamilyList() {}
68
~VulkanQueueFamilyList()69 VulkanQueueFamilyList::~VulkanQueueFamilyList() {}
70
71 /////////////////////////////////////////////////////
72 // VulkanQueueFamilyToQueueCountMap implementation //
73 /////////////////////////////////////////////////////
74
VulkanQueueFamilyToQueueCountMap(const VulkanQueueFamilyToQueueCountMap & queueFamilyToQueueCountMap)75 VulkanQueueFamilyToQueueCountMap::VulkanQueueFamilyToQueueCountMap(
76 const VulkanQueueFamilyToQueueCountMap &queueFamilyToQueueCountMap)
77 {}
78
VulkanQueueFamilyToQueueCountMap(uint32_t numQueuesPerFamily)79 VulkanQueueFamilyToQueueCountMap::VulkanQueueFamilyToQueueCountMap(
80 uint32_t numQueuesPerFamily)
81 {
82 uint32_t maxQueueFamilyCount = 0;
83 const VulkanPhysicalDeviceList &physicalDeviceList =
84 getVulkanInstance().getPhysicalDeviceList();
85 for (size_t pdIdx = 0; pdIdx < physicalDeviceList.size(); pdIdx++)
86 {
87 maxQueueFamilyCount = std::max(
88 maxQueueFamilyCount,
89 (uint32_t)physicalDeviceList[pdIdx].getQueueFamilyList().size());
90 }
91
92 for (uint32_t qfIdx = 0; qfIdx < maxQueueFamilyCount; qfIdx++)
93 {
94 insert(qfIdx, numQueuesPerFamily);
95 }
96 }
97
~VulkanQueueFamilyToQueueCountMap()98 VulkanQueueFamilyToQueueCountMap::~VulkanQueueFamilyToQueueCountMap() {}
99
100 ////////////////////////////////////////////////////
101 // VulkanQueueFamilyToQueueListMap implementation //
102 ////////////////////////////////////////////////////
103
VulkanQueueFamilyToQueueListMap(const VulkanQueueFamilyToQueueListMap & queueFamilyToQueueMap)104 VulkanQueueFamilyToQueueListMap::VulkanQueueFamilyToQueueListMap(
105 const VulkanQueueFamilyToQueueListMap &queueFamilyToQueueMap)
106 {}
107
VulkanQueueFamilyToQueueListMap()108 VulkanQueueFamilyToQueueListMap::VulkanQueueFamilyToQueueListMap() {}
109
~VulkanQueueFamilyToQueueListMap()110 VulkanQueueFamilyToQueueListMap::~VulkanQueueFamilyToQueueListMap() {}
111
insert(uint32_t key,VulkanQueueList & queueList)112 void VulkanQueueFamilyToQueueListMap::insert(uint32_t key,
113 VulkanQueueList &queueList)
114 {
115 m_map.insert(std::pair<uint32_t, std::reference_wrapper<VulkanQueueList>>(
116 key, std::reference_wrapper<VulkanQueueList>(queueList)));
117 }
118
operator [](uint32_t key)119 VulkanQueueList &VulkanQueueFamilyToQueueListMap::operator[](uint32_t key)
120 {
121 return m_map.at(key).get();
122 }
123
124 ////////////////////////////////////
125 // VulkanQueueList implementation //
126 ////////////////////////////////////
127
VulkanQueueList(const VulkanQueueList & queueList)128 VulkanQueueList::VulkanQueueList(const VulkanQueueList &queueList) {}
129
VulkanQueueList()130 VulkanQueueList::VulkanQueueList() {}
131
~VulkanQueueList()132 VulkanQueueList::~VulkanQueueList() {}
133
134 /////////////////////////////////////////////////////////
135 // VulkanDescriptorSetLayoutBindingList implementation //
136 /////////////////////////////////////////////////////////
137
VulkanDescriptorSetLayoutBindingList(const VulkanDescriptorSetLayoutBindingList & descriptorSetLayoutBindingList)138 VulkanDescriptorSetLayoutBindingList::VulkanDescriptorSetLayoutBindingList(
139 const VulkanDescriptorSetLayoutBindingList &descriptorSetLayoutBindingList)
140 {}
141
VulkanDescriptorSetLayoutBindingList()142 VulkanDescriptorSetLayoutBindingList::VulkanDescriptorSetLayoutBindingList() {}
143
addBinding(size_t binding,VulkanDescriptorType descriptorType,uint32_t descriptorCount,VulkanShaderStage shaderStage)144 void VulkanDescriptorSetLayoutBindingList::addBinding(
145 size_t binding, VulkanDescriptorType descriptorType,
146 uint32_t descriptorCount, VulkanShaderStage shaderStage)
147 {
148 VulkanDescriptorSetLayoutBinding *descriptorSetLayoutBinding =
149 new VulkanDescriptorSetLayoutBinding(binding, descriptorType,
150 descriptorCount, shaderStage);
151 add(*descriptorSetLayoutBinding);
152 }
153
VulkanDescriptorSetLayoutBindingList(size_t numDescriptorSetLayoutBindings,VulkanDescriptorType descriptorType,uint32_t descriptorCount,VulkanShaderStage shaderStage)154 VulkanDescriptorSetLayoutBindingList::VulkanDescriptorSetLayoutBindingList(
155 size_t numDescriptorSetLayoutBindings, VulkanDescriptorType descriptorType,
156 uint32_t descriptorCount, VulkanShaderStage shaderStage)
157 {
158 for (size_t idx = 0; idx < numDescriptorSetLayoutBindings; idx++)
159 {
160 VulkanDescriptorSetLayoutBinding *descriptorSetLayoutBinding =
161 new VulkanDescriptorSetLayoutBinding((uint32_t)idx, descriptorType,
162 descriptorCount, shaderStage);
163 add(*descriptorSetLayoutBinding);
164 }
165 }
166
VulkanDescriptorSetLayoutBindingList(VulkanDescriptorType descriptorType0,uint32_t descriptorCount0,VulkanDescriptorType descriptorType1,uint32_t descriptorCount1,VulkanShaderStage shaderStage)167 VulkanDescriptorSetLayoutBindingList::VulkanDescriptorSetLayoutBindingList(
168 VulkanDescriptorType descriptorType0, uint32_t descriptorCount0,
169 VulkanDescriptorType descriptorType1, uint32_t descriptorCount1,
170 VulkanShaderStage shaderStage)
171 {
172 for (uint32_t idx = 0; idx < descriptorCount0; idx++)
173 {
174 VulkanDescriptorSetLayoutBinding *descriptorSetLayoutBinding0 =
175 new VulkanDescriptorSetLayoutBinding(idx, descriptorType0, 1,
176 shaderStage);
177 add(*descriptorSetLayoutBinding0);
178 }
179 for (uint32_t idx = 0; idx < descriptorCount1; idx++)
180 {
181 VulkanDescriptorSetLayoutBinding *descriptorSetLayoutBinding1 =
182 new VulkanDescriptorSetLayoutBinding(
183 descriptorCount0 + idx, descriptorType1, 1, shaderStage);
184 add(*descriptorSetLayoutBinding1);
185 }
186 }
187
~VulkanDescriptorSetLayoutBindingList()188 VulkanDescriptorSetLayoutBindingList::~VulkanDescriptorSetLayoutBindingList()
189 {
190 for (size_t idx = 0; idx < m_wrapperList.size(); idx++)
191 {
192 VulkanDescriptorSetLayoutBinding &descriptorSetLayoutBinding =
193 m_wrapperList[idx];
194 delete &descriptorSetLayoutBinding;
195 }
196 }
197
198 //////////////////////////////////////////////////
199 // VulkanDescriptorSetLayoutList implementation //
200 //////////////////////////////////////////////////
201
VulkanDescriptorSetLayoutList(const VulkanDescriptorSetLayoutList & descriptorSetLayoutList)202 VulkanDescriptorSetLayoutList::VulkanDescriptorSetLayoutList(
203 const VulkanDescriptorSetLayoutList &descriptorSetLayoutList)
204 {}
205
VulkanDescriptorSetLayoutList()206 VulkanDescriptorSetLayoutList::VulkanDescriptorSetLayoutList() {}
207
~VulkanDescriptorSetLayoutList()208 VulkanDescriptorSetLayoutList::~VulkanDescriptorSetLayoutList() {}
209
210 ////////////////////////////////////////////
211 // VulkanCommandBufferList implementation //
212 ////////////////////////////////////////////
213
VulkanCommandBufferList(const VulkanCommandBufferList & commandBufferList)214 VulkanCommandBufferList::VulkanCommandBufferList(
215 const VulkanCommandBufferList &commandBufferList)
216 {}
217
VulkanCommandBufferList()218 VulkanCommandBufferList::VulkanCommandBufferList() {}
219
VulkanCommandBufferList(size_t numCommandBuffers,const VulkanDevice & device,const VulkanCommandPool & commandPool)220 VulkanCommandBufferList::VulkanCommandBufferList(
221 size_t numCommandBuffers, const VulkanDevice &device,
222 const VulkanCommandPool &commandPool)
223 {
224 for (size_t idx = 0; idx < numCommandBuffers; idx++)
225 {
226 VulkanCommandBuffer *commandBuffer =
227 new VulkanCommandBuffer(device, commandPool);
228 add(*commandBuffer);
229 }
230 }
231
~VulkanCommandBufferList()232 VulkanCommandBufferList::~VulkanCommandBufferList()
233 {
234 for (size_t idx = 0; idx < m_wrapperList.size(); idx++)
235 {
236 VulkanCommandBuffer &commandBuffer = m_wrapperList[idx];
237 delete &commandBuffer;
238 }
239 }
240
241 /////////////////////////////////////
242 // VulkanBufferList implementation //
243 /////////////////////////////////////
244
VulkanBufferList(const VulkanBufferList & bufferList)245 VulkanBufferList::VulkanBufferList(const VulkanBufferList &bufferList) {}
246
VulkanBufferList(size_t numBuffers,const VulkanDevice & device,uint64_t size,VulkanExternalMemoryHandleType externalMemoryHandleType,VulkanBufferUsage bufferUsage,VulkanSharingMode sharingMode,const VulkanQueueFamilyList & queueFamilyList)247 VulkanBufferList::VulkanBufferList(
248 size_t numBuffers, const VulkanDevice &device, uint64_t size,
249 VulkanExternalMemoryHandleType externalMemoryHandleType,
250 VulkanBufferUsage bufferUsage, VulkanSharingMode sharingMode,
251 const VulkanQueueFamilyList &queueFamilyList)
252 {
253 for (size_t bIdx = 0; bIdx < numBuffers; bIdx++)
254 {
255 VulkanBuffer *buffer =
256 new VulkanBuffer(device, size, externalMemoryHandleType,
257 bufferUsage, sharingMode, queueFamilyList);
258 add(*buffer);
259 }
260 }
261
~VulkanBufferList()262 VulkanBufferList::~VulkanBufferList()
263 {
264 for (size_t bIdx = 0; bIdx < m_wrapperList.size(); bIdx++)
265 {
266 VulkanBuffer &buffer = m_wrapperList[bIdx];
267 delete &buffer;
268 }
269 }
270
271 //////////////////////////////////////
272 // VulkanImage2DList implementation //
273 //////////////////////////////////////
274
VulkanImage2DList(const VulkanImage2DList & image2DList)275 VulkanImage2DList::VulkanImage2DList(const VulkanImage2DList &image2DList) {}
276
VulkanImage2DList(size_t numImages,std::vector<VulkanDeviceMemory * > & deviceMemory,uint64_t baseOffset,uint64_t interImageOffset,const VulkanDevice & device,VulkanFormat format,uint32_t width,uint32_t height,uint32_t mipLevels,VulkanImageTiling vulkanImageTiling,VulkanExternalMemoryHandleType externalMemoryHandleType,VulkanImageCreateFlag imageCreateFlag,VulkanImageUsage imageUsage,VulkanSharingMode sharingMode)277 VulkanImage2DList::VulkanImage2DList(
278 size_t numImages, std::vector<VulkanDeviceMemory *> &deviceMemory,
279 uint64_t baseOffset, uint64_t interImageOffset, const VulkanDevice &device,
280 VulkanFormat format, uint32_t width, uint32_t height, uint32_t mipLevels,
281 VulkanImageTiling vulkanImageTiling,
282 VulkanExternalMemoryHandleType externalMemoryHandleType,
283 VulkanImageCreateFlag imageCreateFlag, VulkanImageUsage imageUsage,
284 VulkanSharingMode sharingMode)
285 {
286 for (size_t i2DIdx = 0; i2DIdx < numImages; i2DIdx++)
287 {
288 VulkanImage2D *image2D = new VulkanImage2D(
289 device, format, width, height, vulkanImageTiling, mipLevels,
290 externalMemoryHandleType, imageCreateFlag, imageUsage, sharingMode);
291 add(*image2D);
292 deviceMemory[i2DIdx]->bindImage(
293 *image2D, baseOffset + (i2DIdx * interImageOffset));
294 }
295 }
296
VulkanImage2DList(size_t numImages,const VulkanDevice & device,VulkanFormat format,uint32_t width,uint32_t height,VulkanImageTiling vulkanImageTiling,uint32_t mipLevels,VulkanExternalMemoryHandleType externalMemoryHandleType,VulkanImageCreateFlag imageCreateFlag,VulkanImageUsage imageUsage,VulkanSharingMode sharingMode)297 VulkanImage2DList::VulkanImage2DList(
298 size_t numImages, const VulkanDevice &device, VulkanFormat format,
299 uint32_t width, uint32_t height, VulkanImageTiling vulkanImageTiling,
300 uint32_t mipLevels, VulkanExternalMemoryHandleType externalMemoryHandleType,
301 VulkanImageCreateFlag imageCreateFlag, VulkanImageUsage imageUsage,
302 VulkanSharingMode sharingMode)
303 {
304 for (size_t bIdx = 0; bIdx < numImages; bIdx++)
305 {
306 VulkanImage2D *image2D = new VulkanImage2D(
307 device, format, width, height, vulkanImageTiling, mipLevels,
308 externalMemoryHandleType, imageCreateFlag, imageUsage, sharingMode);
309 add(*image2D);
310 }
311 }
312
~VulkanImage2DList()313 VulkanImage2DList::~VulkanImage2DList()
314 {
315 for (size_t i2DIdx = 0; i2DIdx < m_wrapperList.size(); i2DIdx++)
316 {
317 VulkanImage2D &image2D = m_wrapperList[i2DIdx];
318 delete &image2D;
319 }
320 }
321
322 ////////////////////////////////////////
323 // VulkanImageViewList implementation //
324 ////////////////////////////////////////
325
VulkanImageViewList(const VulkanImageViewList & image2DList)326 VulkanImageViewList::VulkanImageViewList(const VulkanImageViewList &image2DList)
327 {}
328
VulkanImageViewList(const VulkanDevice & device,const VulkanImage2DList & image2DList,bool createImageViewPerMipLevel)329 VulkanImageViewList::VulkanImageViewList(const VulkanDevice &device,
330 const VulkanImage2DList &image2DList,
331 bool createImageViewPerMipLevel)
332 {
333 for (size_t i2DIdx = 0; i2DIdx < image2DList.size(); i2DIdx++)
334 {
335 if (createImageViewPerMipLevel)
336 {
337 for (uint32_t mipLevel = 0;
338 mipLevel < image2DList[i2DIdx].getNumMipLevels(); mipLevel++)
339 {
340 VulkanImageView *image2DView =
341 new VulkanImageView(device, image2DList[i2DIdx],
342 VULKAN_IMAGE_VIEW_TYPE_2D, mipLevel, 1);
343 add(*image2DView);
344 }
345 }
346 else
347 {
348 VulkanImageView *image2DView = new VulkanImageView(
349 device, image2DList[i2DIdx], VULKAN_IMAGE_VIEW_TYPE_2D);
350 add(*image2DView);
351 }
352 }
353 }
354
~VulkanImageViewList()355 VulkanImageViewList::~VulkanImageViewList()
356 {
357 for (size_t ivIdx = 0; ivIdx < m_wrapperList.size(); ivIdx++)
358 {
359 VulkanImageView &imageView = m_wrapperList[ivIdx];
360 delete &imageView;
361 }
362 }
363
364 ///////////////////////////////////////////
365 // VulkanDeviceMemoryList implementation //
366 ///////////////////////////////////////////
367
VulkanDeviceMemoryList(const VulkanDeviceMemoryList & deviceMemoryList)368 VulkanDeviceMemoryList::VulkanDeviceMemoryList(
369 const VulkanDeviceMemoryList &deviceMemoryList)
370 {}
371
VulkanDeviceMemoryList(size_t numImages,const VulkanImage2DList & image2DList,const VulkanDevice & device,const VulkanMemoryType & memoryType,VulkanExternalMemoryHandleType externalMemoryHandleType)372 VulkanDeviceMemoryList::VulkanDeviceMemoryList(
373 size_t numImages, const VulkanImage2DList &image2DList,
374 const VulkanDevice &device, const VulkanMemoryType &memoryType,
375 VulkanExternalMemoryHandleType externalMemoryHandleType)
376 {
377 for (size_t i2DIdx = 0; i2DIdx < image2DList.size(); i2DIdx++)
378 {
379 VulkanDeviceMemory *deviceMemory = new VulkanDeviceMemory(
380 device, image2DList[i2DIdx], memoryType, externalMemoryHandleType);
381 add(*deviceMemory);
382 deviceMemory->bindImage(image2DList[i2DIdx]);
383 }
384 }
385
~VulkanDeviceMemoryList()386 VulkanDeviceMemoryList::~VulkanDeviceMemoryList()
387 {
388 for (size_t dmIdx = 0; dmIdx < m_wrapperList.size(); dmIdx++)
389 {
390 VulkanDeviceMemory &deviceMemory = m_wrapperList[dmIdx];
391 delete &deviceMemory;
392 }
393 }
394
395 ////////////////////////////////////////
396 // VulkanSemaphoreList implementation //
397 ////////////////////////////////////////
398
VulkanSemaphoreList(const VulkanSemaphoreList & semaphoreList)399 VulkanSemaphoreList::VulkanSemaphoreList(
400 const VulkanSemaphoreList &semaphoreList)
401 {}
402
VulkanSemaphoreList()403 VulkanSemaphoreList::VulkanSemaphoreList() {}
404
VulkanSemaphoreList(size_t numSemaphores,const VulkanDevice & device,VulkanExternalSemaphoreHandleType externalSemaphoreHandleType,const std::wstring namePrefix)405 VulkanSemaphoreList::VulkanSemaphoreList(
406 size_t numSemaphores, const VulkanDevice &device,
407 VulkanExternalSemaphoreHandleType externalSemaphoreHandleType,
408 const std::wstring namePrefix)
409 {
410 std::wstring name = L"";
411 for (size_t idx = 0; idx < numSemaphores; idx++)
412 {
413 if (namePrefix.size())
414 {
415 const size_t maxNameSize = 256;
416 wchar_t tempName[maxNameSize];
417 swprintf(tempName, maxNameSize, L"%s%d", namePrefix.c_str(),
418 (int)idx);
419 name = tempName;
420 }
421 VulkanSemaphore *semaphore =
422 new VulkanSemaphore(device, externalSemaphoreHandleType, name);
423 add(*semaphore);
424 }
425 }
426
~VulkanSemaphoreList()427 VulkanSemaphoreList::~VulkanSemaphoreList()
428 {
429 for (size_t idx = 0; idx < m_wrapperList.size(); idx++)
430 {
431 VulkanSemaphore &Semaphore = m_wrapperList[idx];
432 delete &Semaphore;
433 }
434 }
435