blob: 787c2aa609fc95e70447da74f03f071194c01ced [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
Nicolas Capensd689d1c2018-11-19 16:02:36 -050015#include "VkDevice.hpp"
16
Alexis Hetu767b41b2018-09-26 11:25:46 -040017#include "VkConfig.h"
18#include "VkDebug.hpp"
Alexis Hetu048974f2019-02-15 15:28:37 -050019#include "VkDescriptorSetLayout.hpp"
Alexis Hetu9e4d0402018-10-16 15:44:12 -040020#include "VkQueue.hpp"
Alexis Hetu0da99f52019-02-27 12:54:52 -050021#include "Device/Blitter.hpp"
Nicolas Capensd689d1c2018-11-19 16:02:36 -050022
Alexis Hetu767b41b2018-09-26 11:25:46 -040023#include <new> // Must #include this to use "placement new"
24
25namespace vk
26{
27
28Device::Device(const Device::CreateInfo* info, void* mem)
29 : physicalDevice(info->pPhysicalDevice), queues(reinterpret_cast<Queue*>(mem))
30{
31 const auto* pCreateInfo = info->pCreateInfo;
32 for(uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++)
33 {
34 const VkDeviceQueueCreateInfo& queueCreateInfo = pCreateInfo->pQueueCreateInfos[i];
Alexis Hetue70c3512018-10-17 13:18:04 -040035 queueCount += queueCreateInfo.queueCount;
Alexis Hetu767b41b2018-09-26 11:25:46 -040036 }
37
38 uint32_t queueID = 0;
39 for(uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++)
40 {
41 const VkDeviceQueueCreateInfo& queueCreateInfo = pCreateInfo->pQueueCreateInfos[i];
42
43 for(uint32_t j = 0; j < queueCreateInfo.queueCount; j++, queueID++)
44 {
Nicolas Capensd689d1c2018-11-19 16:02:36 -050045 new (&queues[queueID]) Queue(queueCreateInfo.queueFamilyIndex, queueCreateInfo.pQueuePriorities[j]);
Alexis Hetu767b41b2018-09-26 11:25:46 -040046 }
47 }
Nicolas Capensd689d1c2018-11-19 16:02:36 -050048
49 if(pCreateInfo->enabledLayerCount)
50 {
51 // "The ppEnabledLayerNames and enabledLayerCount members of VkDeviceCreateInfo are deprecated and their values must be ignored by implementations."
Ben Clayton00424c12019-03-17 17:29:30 +000052 UNIMPLEMENTED("enabledLayerCount"); // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
Nicolas Capensd689d1c2018-11-19 16:02:36 -050053 }
Alexis Hetu0da99f52019-02-27 12:54:52 -050054
55 blitter = new sw::Blitter();
Alexis Hetu767b41b2018-09-26 11:25:46 -040056}
57
58void Device::destroy(const VkAllocationCallbacks* pAllocator)
59{
Alexis Hetuaf3c1022018-12-12 13:26:15 -050060 for(uint32_t i = 0; i < queueCount; i++)
61 {
62 queues[i].destroy();
63 }
64
Alexis Hetu767b41b2018-09-26 11:25:46 -040065 vk::deallocate(queues, pAllocator);
Alexis Hetu0da99f52019-02-27 12:54:52 -050066
67 delete blitter;
Alexis Hetu767b41b2018-09-26 11:25:46 -040068}
69
70size_t Device::ComputeRequiredAllocationSize(const Device::CreateInfo* info)
71{
72 uint32_t queueCount = 0;
73 for(uint32_t i = 0; i < info->pCreateInfo->queueCreateInfoCount; i++)
74 {
75 queueCount += info->pCreateInfo->pQueueCreateInfos[i].queueCount;
76 }
77
78 return sizeof(Queue) * queueCount;
79}
80
81VkQueue Device::getQueue(uint32_t queueFamilyIndex, uint32_t queueIndex) const
82{
83 ASSERT(queueFamilyIndex == 0);
84
85 return queues[queueIndex];
86}
87
Alexis Hetuc4bd9df2018-12-07 11:28:40 -050088void Device::waitForFences(uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
89{
90 // FIXME(b/117835459) : noop
91}
92
Ben Clayton00424c12019-03-17 17:29:30 +000093void Device::waitIdle()
94{
95 for(uint32_t i = 0; i < queueCount; i++)
96 {
97 queues[i].waitIdle();
98 }
Alexis Hetucda0cf92019-01-24 15:48:55 -050099}
100
Alexis Hetu9e4d0402018-10-16 15:44:12 -0400101void Device::getDescriptorSetLayoutSupport(const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
102 VkDescriptorSetLayoutSupport* pSupport) const
103{
104 // Mark everything as unsupported
105 pSupport->supported = VK_FALSE;
106}
107
Alexis Hetu048974f2019-02-15 15:28:37 -0500108void Device::updateDescriptorSets(uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites,
109 uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies)
110{
111 for(uint32_t i = 0; i < descriptorWriteCount; i++)
112 {
113 DescriptorSetLayout::WriteDescriptorSet(pDescriptorWrites[i]);
114 }
115
116 for(uint32_t i = 0; i < descriptorCopyCount; i++)
117 {
118 DescriptorSetLayout::CopyDescriptorSet(pDescriptorCopies[i]);
119 }
120}
121
Alexis Hetu767b41b2018-09-26 11:25:46 -0400122} // namespace vk