1 // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "VkInstance.hpp"
16 #include "VkDebugUtilsMessenger.hpp"
17 #include "VkDestroy.hpp"
18
19 namespace vk {
20
Instance(const VkInstanceCreateInfo * pCreateInfo,void * mem,VkPhysicalDevice physicalDevice,DebugUtilsMessenger * messenger)21 Instance::Instance(const VkInstanceCreateInfo *pCreateInfo, void *mem, VkPhysicalDevice physicalDevice, DebugUtilsMessenger *messenger)
22 : physicalDevice(physicalDevice)
23 , messenger(messenger)
24 {
25 }
26
destroy(const VkAllocationCallbacks * pAllocator)27 void Instance::destroy(const VkAllocationCallbacks *pAllocator)
28 {
29 if(messenger)
30 {
31 vk::destroy(static_cast<VkDebugUtilsMessengerEXT>(*messenger), pAllocator);
32 }
33 vk::destroy(physicalDevice, pAllocator);
34 }
35
getPhysicalDevices(uint32_t * pPhysicalDeviceCount,VkPhysicalDevice * pPhysicalDevices) const36 VkResult Instance::getPhysicalDevices(uint32_t *pPhysicalDeviceCount, VkPhysicalDevice *pPhysicalDevices) const
37 {
38 if(!pPhysicalDevices)
39 {
40 *pPhysicalDeviceCount = 1;
41 return VK_SUCCESS;
42 }
43
44 if(*pPhysicalDeviceCount < 1)
45 {
46 return VK_INCOMPLETE;
47 }
48
49 pPhysicalDevices[0] = physicalDevice;
50 *pPhysicalDeviceCount = 1;
51
52 return VK_SUCCESS;
53 }
54
getPhysicalDeviceGroups(uint32_t * pPhysicalDeviceGroupCount,VkPhysicalDeviceGroupProperties * pPhysicalDeviceGroupProperties) const55 VkResult Instance::getPhysicalDeviceGroups(uint32_t *pPhysicalDeviceGroupCount,
56 VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties) const
57 {
58 if(!pPhysicalDeviceGroupProperties)
59 {
60 *pPhysicalDeviceGroupCount = 1;
61 return VK_SUCCESS;
62 }
63
64 if(*pPhysicalDeviceGroupCount < 1)
65 {
66 return VK_INCOMPLETE;
67 }
68
69 pPhysicalDeviceGroupProperties[0].physicalDeviceCount = 1;
70 pPhysicalDeviceGroupProperties[0].physicalDevices[0] = physicalDevice;
71 pPhysicalDeviceGroupProperties[0].subsetAllocation = VK_FALSE;
72 *pPhysicalDeviceGroupCount = 1;
73
74 return VK_SUCCESS;
75 }
76
submitDebugUtilsMessage(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,VkDebugUtilsMessageTypeFlagsEXT messageTypes,const VkDebugUtilsMessengerCallbackDataEXT * pCallbackData)77 void Instance::submitDebugUtilsMessage(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData)
78 {
79 if(messenger)
80 {
81 messenger->submitMessage(messageSeverity, messageTypes, pCallbackData);
82 }
83 }
84
85 } // namespace vk
86