• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "VkDevice.hpp"
16 
17 #include "VkConfig.h"
18 #include "VkDebug.hpp"
19 #include "VkQueue.hpp"
20 
21 #include <new> // Must #include this to use "placement new"
22 
23 namespace vk
24 {
25 
Device(const Device::CreateInfo * info,void * mem)26 Device::Device(const Device::CreateInfo* info, void* mem)
27 	: physicalDevice(info->pPhysicalDevice), queues(reinterpret_cast<Queue*>(mem))
28 {
29 	const auto* pCreateInfo = info->pCreateInfo;
30 	for(uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++)
31 	{
32 		const VkDeviceQueueCreateInfo& queueCreateInfo = pCreateInfo->pQueueCreateInfos[i];
33 		queueCount += queueCreateInfo.queueCount;
34 	}
35 
36 	uint32_t queueID = 0;
37 	for(uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++)
38 	{
39 		const VkDeviceQueueCreateInfo& queueCreateInfo = pCreateInfo->pQueueCreateInfos[i];
40 
41 		for(uint32_t j = 0; j < queueCreateInfo.queueCount; j++, queueID++)
42 		{
43 			new (&queues[queueID]) Queue(queueCreateInfo.queueFamilyIndex, queueCreateInfo.pQueuePriorities[j]);
44 		}
45 	}
46 
47 	if(pCreateInfo->enabledLayerCount)
48 	{
49 		// "The ppEnabledLayerNames and enabledLayerCount members of VkDeviceCreateInfo are deprecated and their values must be ignored by implementations."
50 		UNIMPLEMENTED();   // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
51 	}
52 
53 	if(pCreateInfo->enabledExtensionCount)
54 	{
55 		UNIMPLEMENTED();
56 	}
57 }
58 
destroy(const VkAllocationCallbacks * pAllocator)59 void Device::destroy(const VkAllocationCallbacks* pAllocator)
60 {
61 	for(uint32_t i = 0; i < queueCount; i++)
62 	{
63 		queues[i].destroy();
64 	}
65 
66 	vk::deallocate(queues, pAllocator);
67 }
68 
ComputeRequiredAllocationSize(const Device::CreateInfo * info)69 size_t Device::ComputeRequiredAllocationSize(const Device::CreateInfo* info)
70 {
71 	uint32_t queueCount = 0;
72 	for(uint32_t i = 0; i < info->pCreateInfo->queueCreateInfoCount; i++)
73 	{
74 		queueCount += info->pCreateInfo->pQueueCreateInfos[i].queueCount;
75 	}
76 
77 	return sizeof(Queue) * queueCount;
78 }
79 
getQueue(uint32_t queueFamilyIndex,uint32_t queueIndex) const80 VkQueue Device::getQueue(uint32_t queueFamilyIndex, uint32_t queueIndex) const
81 {
82 	ASSERT(queueFamilyIndex == 0);
83 
84 	return queues[queueIndex];
85 }
86 
waitForFences(uint32_t fenceCount,const VkFence * pFences,VkBool32 waitAll,uint64_t timeout)87 void Device::waitForFences(uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
88 {
89 	// FIXME(b/117835459) : noop
90 }
91 
waitIdle()92 void Device::waitIdle()
93 {
94 	for(uint32_t i = 0; i < queueCount; i++)
95 	{
96 		queues[i].waitIdle();
97 	}
98 }
99 
getDescriptorSetLayoutSupport(const VkDescriptorSetLayoutCreateInfo * pCreateInfo,VkDescriptorSetLayoutSupport * pSupport) const100 void Device::getDescriptorSetLayoutSupport(const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
101                                            VkDescriptorSetLayoutSupport* pSupport) const
102 {
103 	// Mark everything as unsupported
104 	pSupport->supported = VK_FALSE;
105 }
106 
107 } // namespace vk
108