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 vk::destroy(physicalDevice, pAllocator);
30 }
31
getPhysicalDevices(uint32_t * pPhysicalDeviceCount,VkPhysicalDevice * pPhysicalDevices) const32 VkResult Instance::getPhysicalDevices(uint32_t *pPhysicalDeviceCount, VkPhysicalDevice *pPhysicalDevices) const
33 {
34 if(!pPhysicalDevices)
35 {
36 *pPhysicalDeviceCount = 1;
37 return VK_SUCCESS;
38 }
39
40 if(*pPhysicalDeviceCount < 1)
41 {
42 return VK_INCOMPLETE;
43 }
44
45 pPhysicalDevices[0] = physicalDevice;
46 *pPhysicalDeviceCount = 1;
47
48 return VK_SUCCESS;
49 }
50
getPhysicalDeviceGroups(uint32_t * pPhysicalDeviceGroupCount,VkPhysicalDeviceGroupProperties * pPhysicalDeviceGroupProperties) const51 VkResult Instance::getPhysicalDeviceGroups(uint32_t *pPhysicalDeviceGroupCount,
52 VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties) const
53 {
54 if(!pPhysicalDeviceGroupProperties)
55 {
56 *pPhysicalDeviceGroupCount = 1;
57 return VK_SUCCESS;
58 }
59
60 if(*pPhysicalDeviceGroupCount < 1)
61 {
62 return VK_INCOMPLETE;
63 }
64
65 pPhysicalDeviceGroupProperties[0].physicalDeviceCount = 1;
66 pPhysicalDeviceGroupProperties[0].physicalDevices[0] = physicalDevice;
67 pPhysicalDeviceGroupProperties[0].subsetAllocation = VK_FALSE;
68 *pPhysicalDeviceGroupCount = 1;
69
70 return VK_SUCCESS;
71 }
72
submitDebugUtilsMessage(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,VkDebugUtilsMessageTypeFlagsEXT messageTypes,const VkDebugUtilsMessengerCallbackDataEXT * pCallbackData)73 void Instance::submitDebugUtilsMessage(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData)
74 {
75 if(messenger)
76 {
77 messenger->submitMessage(messageSeverity, messageTypes, pCallbackData);
78 }
79 }
80
81 } // namespace vk
82