blob: 14f7142f919fa05d1ba15da74544ef81c2f4d93c [file] [log] [blame]
Alexis Hetu767b41b2018-09-26 11:25:46 -04001// 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"
Antonio Maiorano42fd1592020-04-27 11:30:40 -040016#include "VkDestroy.hpp"
Alexis Hetu767b41b2018-09-26 11:25:46 -040017
Nicolas Capens157ba262019-12-10 17:49:14 -050018namespace vk {
Alexis Hetu767b41b2018-09-26 11:25:46 -040019
Ben Clayton2ed93ab2019-12-17 20:38:03 +000020Instance::Instance(const VkInstanceCreateInfo *pCreateInfo, void *mem, VkPhysicalDevice physicalDevice)
21 : physicalDevice(physicalDevice)
Alexis Hetu767b41b2018-09-26 11:25:46 -040022{
Alexis Hetu767b41b2018-09-26 11:25:46 -040023}
24
Ben Clayton2ed93ab2019-12-17 20:38:03 +000025void Instance::destroy(const VkAllocationCallbacks *pAllocator)
Alexis Hetu767b41b2018-09-26 11:25:46 -040026{
27 vk::destroy(physicalDevice, pAllocator);
28}
29
Ben Clayton2ed93ab2019-12-17 20:38:03 +000030VkResult Instance::getPhysicalDevices(uint32_t *pPhysicalDeviceCount, VkPhysicalDevice *pPhysicalDevices) const
Alexis Hetu767b41b2018-09-26 11:25:46 -040031{
Nicolas Capens81bc9d92019-12-16 15:05:57 -050032 if(!pPhysicalDevices)
Chris Forbesdf84b942019-06-12 11:28:09 -070033 {
34 *pPhysicalDeviceCount = 1;
35 return VK_SUCCESS;
36 }
37
Nicolas Capens81bc9d92019-12-16 15:05:57 -050038 if(*pPhysicalDeviceCount < 1)
Chris Forbesdf84b942019-06-12 11:28:09 -070039 {
40 return VK_INCOMPLETE;
41 }
42
43 pPhysicalDevices[0] = physicalDevice;
44 *pPhysicalDeviceCount = 1;
45
46 return VK_SUCCESS;
Alexis Hetu767b41b2018-09-26 11:25:46 -040047}
48
Chris Forbesdf84b942019-06-12 11:28:09 -070049VkResult Instance::getPhysicalDeviceGroups(uint32_t *pPhysicalDeviceGroupCount,
Ben Clayton2ed93ab2019-12-17 20:38:03 +000050 VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties) const
Alexis Hetu767b41b2018-09-26 11:25:46 -040051{
Nicolas Capens81bc9d92019-12-16 15:05:57 -050052 if(!pPhysicalDeviceGroupProperties)
Chris Forbesdf84b942019-06-12 11:28:09 -070053 {
54 *pPhysicalDeviceGroupCount = 1;
55 return VK_SUCCESS;
56 }
Alexis Hetu767b41b2018-09-26 11:25:46 -040057
Nicolas Capens81bc9d92019-12-16 15:05:57 -050058 if(*pPhysicalDeviceGroupCount < 1)
Chris Forbesdf84b942019-06-12 11:28:09 -070059 {
60 return VK_INCOMPLETE;
61 }
Alexis Hetu767b41b2018-09-26 11:25:46 -040062
Chris Forbesdf84b942019-06-12 11:28:09 -070063 pPhysicalDeviceGroupProperties[0].physicalDeviceCount = 1;
64 pPhysicalDeviceGroupProperties[0].physicalDevices[0] = physicalDevice;
65 pPhysicalDeviceGroupProperties[0].subsetAllocation = VK_FALSE;
66 *pPhysicalDeviceGroupCount = 1;
Alexis Hetu767b41b2018-09-26 11:25:46 -040067
Chris Forbesdf84b942019-06-12 11:28:09 -070068 return VK_SUCCESS;
Alexis Hetu767b41b2018-09-26 11:25:46 -040069}
70
Nicolas Capens157ba262019-12-10 17:49:14 -050071} // namespace vk