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