Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 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 | |
Nicolas Capens | d689d1c | 2018-11-19 16:02:36 -0500 | [diff] [blame] | 15 | #include "VkDevice.hpp" |
| 16 | |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 17 | #include "VkConfig.h" |
| 18 | #include "VkDebug.hpp" |
Alexis Hetu | 048974f | 2019-02-15 15:28:37 -0500 | [diff] [blame] | 19 | #include "VkDescriptorSetLayout.hpp" |
Alexis Hetu | 9e4d040 | 2018-10-16 15:44:12 -0400 | [diff] [blame] | 20 | #include "VkQueue.hpp" |
Alexis Hetu | 0da99f5 | 2019-02-27 12:54:52 -0500 | [diff] [blame] | 21 | #include "Device/Blitter.hpp" |
Nicolas Capens | d689d1c | 2018-11-19 16:02:36 -0500 | [diff] [blame] | 22 | |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 23 | #include <new> // Must #include this to use "placement new" |
| 24 | |
| 25 | namespace vk |
| 26 | { |
| 27 | |
| 28 | Device::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 Hetu | e70c351 | 2018-10-17 13:18:04 -0400 | [diff] [blame] | 35 | queueCount += queueCreateInfo.queueCount; |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 36 | } |
| 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 Capens | d689d1c | 2018-11-19 16:02:36 -0500 | [diff] [blame] | 45 | new (&queues[queueID]) Queue(queueCreateInfo.queueFamilyIndex, queueCreateInfo.pQueuePriorities[j]); |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 46 | } |
| 47 | } |
Nicolas Capens | d689d1c | 2018-11-19 16:02:36 -0500 | [diff] [blame] | 48 | |
| 49 | if(pCreateInfo->enabledLayerCount) |
| 50 | { |
| 51 | // "The ppEnabledLayerNames and enabledLayerCount members of VkDeviceCreateInfo are deprecated and their values must be ignored by implementations." |
Ben Clayton | 00424c1 | 2019-03-17 17:29:30 +0000 | [diff] [blame^] | 52 | UNIMPLEMENTED("enabledLayerCount"); // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here. |
Nicolas Capens | d689d1c | 2018-11-19 16:02:36 -0500 | [diff] [blame] | 53 | } |
Alexis Hetu | 0da99f5 | 2019-02-27 12:54:52 -0500 | [diff] [blame] | 54 | |
| 55 | blitter = new sw::Blitter(); |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void Device::destroy(const VkAllocationCallbacks* pAllocator) |
| 59 | { |
Alexis Hetu | af3c102 | 2018-12-12 13:26:15 -0500 | [diff] [blame] | 60 | for(uint32_t i = 0; i < queueCount; i++) |
| 61 | { |
| 62 | queues[i].destroy(); |
| 63 | } |
| 64 | |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 65 | vk::deallocate(queues, pAllocator); |
Alexis Hetu | 0da99f5 | 2019-02-27 12:54:52 -0500 | [diff] [blame] | 66 | |
| 67 | delete blitter; |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | size_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 | |
| 81 | VkQueue Device::getQueue(uint32_t queueFamilyIndex, uint32_t queueIndex) const |
| 82 | { |
| 83 | ASSERT(queueFamilyIndex == 0); |
| 84 | |
| 85 | return queues[queueIndex]; |
| 86 | } |
| 87 | |
Alexis Hetu | c4bd9df | 2018-12-07 11:28:40 -0500 | [diff] [blame] | 88 | void Device::waitForFences(uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout) |
| 89 | { |
| 90 | // FIXME(b/117835459) : noop |
| 91 | } |
| 92 | |
Ben Clayton | 00424c1 | 2019-03-17 17:29:30 +0000 | [diff] [blame^] | 93 | void Device::waitIdle() |
| 94 | { |
| 95 | for(uint32_t i = 0; i < queueCount; i++) |
| 96 | { |
| 97 | queues[i].waitIdle(); |
| 98 | } |
Alexis Hetu | cda0cf9 | 2019-01-24 15:48:55 -0500 | [diff] [blame] | 99 | } |
| 100 | |
Alexis Hetu | 9e4d040 | 2018-10-16 15:44:12 -0400 | [diff] [blame] | 101 | void Device::getDescriptorSetLayoutSupport(const VkDescriptorSetLayoutCreateInfo* pCreateInfo, |
| 102 | VkDescriptorSetLayoutSupport* pSupport) const |
| 103 | { |
| 104 | // Mark everything as unsupported |
| 105 | pSupport->supported = VK_FALSE; |
| 106 | } |
| 107 | |
Alexis Hetu | 048974f | 2019-02-15 15:28:37 -0500 | [diff] [blame] | 108 | void 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 Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 122 | } // namespace vk |