Skip to content

Commit 6fa6efb

Browse files
committed
GraphicsCore: add some Vulkan device initialisation
1 parent ea0434d commit 6fa6efb

File tree

12 files changed

+804
-5
lines changed

12 files changed

+804
-5
lines changed

src/engine/renderer-vulkan/GraphicsCore/CapabilityPack.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,29 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434
// CapabilityPack.cpp
3535

3636
#include "CapabilityPack.h"
37+
38+
constexpr bool EngineConfigSupportedMinimal( const EngineConfig& config ) {
39+
const bool ret =
40+
config.subgroupQuadOpsAllStages && config.robustBufferAccessDynamic
41+
&& config.quadDivergentImplicitLod
42+
&& config.textureCompressionBC
43+
&& config.descriptorIndexing
44+
&& config.descriptorBindingUpdateUnusedWhilePending
45+
&& config.descriptorBindingPartiallyBound
46+
&& config.descriptorBindingVariableDescriptorCount
47+
&& config.runtimeDescriptorArray
48+
&& config.shaderSampledImageArrayNonUniformIndexing
49+
&& config.shaderStorageImageArrayNonUniformIndexing
50+
&& config.dynamicRendering
51+
&& config.synchronization2;
52+
53+
return ret;
54+
};
55+
56+
CapabilityPackType::Type GetHighestSuppportedCapabilityPack( const EngineConfig& config ) {
57+
if ( EngineConfigSupportedMinimal( config ) ) {
58+
return CapabilityPackType::MINIMAL;
59+
}
60+
61+
return CapabilityPackType::NONE;
62+
}

src/engine/renderer-vulkan/GraphicsCore/CapabilityPack.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4646
#include "../Version.h"
4747
#include "../Memory/Array.h"
4848

49+
#include "EngineConfig.h"
50+
4951
template<const uint32 instanceExtensionCount, const uint32 extensionCount, const uint32 featureCount>
5052
struct CapabilityPack {
5153
const Version minVersion;
@@ -57,15 +59,23 @@ struct CapabilityPack {
5759

5860
namespace CapabilityPackType {
5961
enum Type {
62+
NONE,
6063
MINIMAL,
6164
RECOMMENDED,
6265
EXPERIMENTAL
6366
};
67+
68+
constexpr const char* typeStrings[] = {
69+
"NONE",
70+
"MINIMAL",
71+
"RECOMMENDED",
72+
"EXPERIMENTAL"
73+
};
6474
}
6575

6676
constexpr Array instanceExtensions {
6777
"VK_LAYER_KHRONOS_validation",
68-
"VK_KHR_get_physical_device_properties"
78+
"VK_KHR_get_physical_device_properties2"
6979
};
7080

7181
constexpr Array extensionsMinimal {
@@ -76,6 +86,10 @@ constexpr Array featuresMinimal {
7686
"VK_EXT_descriptor_indexing"
7787
};
7888

89+
constexpr bool EngineConfigSupportedMinimal( const EngineConfig& config );
90+
91+
CapabilityPackType::Type GetHighestSuppportedCapabilityPack( const EngineConfig& config );
92+
7993
constexpr CapabilityPack<instanceExtensions.Size(), extensionsMinimal.Size(), featuresMinimal.Size()> capabilityPackMinimal {
8094
.minVersion { 1, 3, 0 },
8195
.requiredInstanceExtensions = instanceExtensions,
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
/*
2+
===========================================================================
3+
4+
Daemon BSD Source Code
5+
Copyright (c) 2025 Daemon Developers
6+
All rights reserved.
7+
8+
This file is part of the Daemon BSD Source Code (Daemon Source Code).
9+
10+
Redistribution and use in source and binary forms, with or without
11+
modification, are permitted provided that the following conditions are met:
12+
* Redistributions of source code must retain the above copyright
13+
notice, this list of conditions and the following disclaimer.
14+
* Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the distribution.
17+
* Neither the name of the Daemon developers nor the
18+
names of its contributors may be used to endorse or promote products
19+
derived from this software without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
25+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
===========================================================================
33+
*/
34+
// EngineConfig.h
35+
36+
#include "engine/qcommon/q_shared.h"
37+
38+
#include "Vulkan.h"
39+
40+
#include "EngineConfig.h"
41+
42+
EngineConfig GetEngineConfigForDevice( const VkPhysicalDevice& device ) {
43+
VkPhysicalDeviceVulkan11Properties properties11 {};
44+
VkPhysicalDeviceVulkan12Properties properties12 { .pNext = &properties11 };
45+
VkPhysicalDeviceVulkan13Properties properties13 { .pNext = &properties12 };
46+
VkPhysicalDeviceProperties2 properties { .pNext = &properties13 };
47+
48+
VkPhysicalDeviceVulkan12Features features12 {};
49+
VkPhysicalDeviceVulkan13Features features13 { .pNext = &features12 };
50+
VkPhysicalDeviceFeatures2 features { .pNext = &features13 };
51+
52+
vkGetPhysicalDeviceProperties2( device, &properties );
53+
vkGetPhysicalDeviceFeatures2( device, &features );
54+
55+
VkPhysicalDeviceProperties& coreProperties = properties.properties;
56+
VkPhysicalDeviceLimits& limits = coreProperties.limits;
57+
VkPhysicalDeviceSparseProperties& sparseProperties = coreProperties.sparseProperties;
58+
VkPhysicalDeviceFeatures& coreFeatures = features.features;
59+
60+
EngineConfig cfg {
61+
.driverID = properties12.driverID,
62+
.conformanceVersion = properties12.conformanceVersion,
63+
64+
.driverVersion = coreProperties.driverVersion,
65+
.vendorID = coreProperties.vendorID,
66+
.deviceID = coreProperties.deviceID,
67+
68+
.maxAllocationSize = properties11.maxMemoryAllocationSize,
69+
.maxBufferSize = properties13.maxBufferSize,
70+
71+
.subgroupSupportedStages = properties11.subgroupSupportedStages,
72+
.subgroupSupportedOps = properties11.subgroupSupportedOperations,
73+
.subgroupQuadOpsAllStages = ( bool ) properties11.subgroupQuadOperationsInAllStages,
74+
75+
.minSubgroupSize = properties13.minSubgroupSize,
76+
.maxSubgroupSize = properties13.maxSubgroupSize,
77+
.maxComputeWorkgroupSubgroups = properties13.maxComputeWorkgroupSubgroups,
78+
.requiredSubgroupSizeStages = properties13.requiredSubgroupSizeStages,
79+
80+
.maxSetDescriptors = properties11.maxPerSetDescriptors,
81+
.maxTotalDynamicDescriptors = properties12.maxUpdateAfterBindDescriptorsInAllPools,
82+
.robustBufferAccessDynamic = ( bool ) properties12.robustBufferAccessUpdateAfterBind,
83+
84+
.maxInlineUniformBlockSize = properties13.maxInlineUniformBlockSize,
85+
.maxInlineUniformTotalSize = properties13.maxInlineUniformTotalSize,
86+
.maxPerStageDescriptorInlineUniformBlocks = properties13.maxPerStageDescriptorInlineUniformBlocks,
87+
.maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks = properties13.maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks,
88+
.maxDescriptorSetInlineUniformBlocks = properties13.maxDescriptorSetInlineUniformBlocks,
89+
.maxDescriptorSetUpdateAfterBindInlineUniformBlocks = properties13.maxDescriptorSetUpdateAfterBindInlineUniformBlocks,
90+
91+
.storageTexelBufferOffsetAlignmentBytes = properties13.storageTexelBufferOffsetAlignmentBytes,
92+
.storageTexelBufferOffsetSingleTexelAlignment = ( bool ) properties13.storageTexelBufferOffsetSingleTexelAlignment,
93+
.uniformTexelBufferOffsetAlignmentBytes = properties13.uniformTexelBufferOffsetAlignmentBytes,
94+
.uniformTexelBufferOffsetSingleTexelAlignment = ( bool ) properties13.uniformTexelBufferOffsetSingleTexelAlignment,
95+
96+
.quadDivergentImplicitLod = ( bool ) properties12.quadDivergentImplicitLod,
97+
98+
.filterMinmaxSingleComponentFormats = ( bool ) properties12.filterMinmaxSingleComponentFormats,
99+
.filterMinmaxImageComponentMapping = ( bool ) properties12.filterMinmaxImageComponentMapping,
100+
101+
.maxImageSize2D = limits.maxImageDimension2D,
102+
.maxImageSize3D = limits.maxImageDimension3D,
103+
.maxImageSizeCube = limits.maxImageDimensionCube,
104+
.maxImageArrayLayers = limits.maxImageArrayLayers,
105+
106+
.maxPushConstSize = limits.maxPushConstantsSize,
107+
.maxAllocations = limits.maxMemoryAllocationCount,
108+
.maxSamplers = limits.maxSamplerAllocationCount,
109+
.bufferImageGranularity = limits.bufferImageGranularity,
110+
.sparseAddressSpaceSize = limits.sparseAddressSpaceSize,
111+
112+
.maxComputeSharedMemSize = limits.maxComputeSharedMemorySize,
113+
.maxComputeWorkGroupCount = {
114+
limits.maxComputeWorkGroupCount[0],
115+
limits.maxComputeWorkGroupCount[1],
116+
limits.maxComputeWorkGroupCount[2],
117+
},
118+
.maxComputeWorkGroupInvocations = limits.maxComputeWorkGroupInvocations,
119+
.maxComputeWorkGroupSize = {
120+
limits.maxComputeWorkGroupSize[0],
121+
limits.maxComputeWorkGroupSize[1],
122+
limits.maxComputeWorkGroupSize[2],
123+
},
124+
125+
.subPixelPrecisionBits = limits.subPixelPrecisionBits,
126+
.subTexelPrecisionBits = limits.subTexelPrecisionBits,
127+
.mipmapPrecisionBits = limits.mipmapPrecisionBits,
128+
129+
.minMemoryMapAlignment = limits.minMemoryMapAlignment,
130+
131+
.discreteQueuePriorities = limits.discreteQueuePriorities,
132+
133+
.optimalBufferCopyOffsetAlignment = limits.optimalBufferCopyOffsetAlignment,
134+
.optimalBufferCopyRowPitchAlignment = limits.optimalBufferCopyRowPitchAlignment,
135+
.nonCoherentAtomSize = limits.nonCoherentAtomSize,
136+
137+
.shaderResourceResidency = ( bool ) coreFeatures.shaderResourceResidency,
138+
.shaderResourceMinLod = ( bool ) coreFeatures.shaderResourceMinLod,
139+
140+
.depthBounds = ( bool ) coreFeatures.depthBounds,
141+
142+
.sparseBinding = ( bool ) coreFeatures.sparseBinding,
143+
.sparseResidencyBuffer = ( bool ) coreFeatures.sparseResidencyBuffer,
144+
.sparseResidencyImage2D = ( bool ) coreFeatures.sparseResidencyImage2D,
145+
.sparseResidencyImage3D = ( bool ) coreFeatures.sparseResidencyImage3D,
146+
.sparseResidency2Samples = ( bool ) coreFeatures.sparseResidency2Samples,
147+
.sparseResidency4Samples = ( bool ) coreFeatures.sparseResidency4Samples,
148+
.sparseResidency8Samples = ( bool ) coreFeatures.sparseResidency8Samples,
149+
.sparseResidency16Samples = ( bool ) coreFeatures.sparseResidency16Samples,
150+
.sparseResidencyAliased = ( bool ) coreFeatures.sparseResidencyAliased,
151+
152+
.residencyStandard2DBlockShape = ( bool ) sparseProperties.residencyStandard2DBlockShape,
153+
.residencyStandard2DMultisampleBlockShape = ( bool ) sparseProperties.residencyStandard2DMultisampleBlockShape,
154+
.residencyStandard3DBlockShape = ( bool ) sparseProperties.residencyStandard3DBlockShape,
155+
.residencyAlignedMipSize = ( bool ) sparseProperties.residencyAlignedMipSize,
156+
.residencyNonResidentStrict = ( bool ) sparseProperties.residencyNonResidentStrict,
157+
158+
.textureCompressionETC2 = ( bool ) coreFeatures.textureCompressionETC2,
159+
.textureCompressionASTC_LDR = ( bool ) coreFeatures.textureCompressionASTC_LDR,
160+
.textureCompressionBC = ( bool ) coreFeatures.textureCompressionBC,
161+
162+
.bufferDeviceAddress = ( bool ) features12.bufferDeviceAddress,
163+
.bufferDeviceAddressCaptureReplay = ( bool ) features12.bufferDeviceAddressCaptureReplay,
164+
165+
.descriptorIndexing = ( bool ) features12.descriptorIndexing,
166+
167+
.descriptorBindingUpdateUnusedWhilePending = ( bool ) features12.descriptorBindingUpdateUnusedWhilePending,
168+
.descriptorBindingPartiallyBound = ( bool ) features12.descriptorBindingPartiallyBound,
169+
.descriptorBindingVariableDescriptorCount = ( bool ) features12.descriptorBindingVariableDescriptorCount,
170+
171+
.runtimeDescriptorArray = ( bool ) features12.runtimeDescriptorArray,
172+
173+
.samplerFilterMinmax = ( bool ) features12.samplerFilterMinmax,
174+
175+
.shaderSampledImageArrayNonUniformIndexing = ( bool ) features12.shaderSampledImageArrayNonUniformIndexing,
176+
.shaderStorageImageArrayNonUniformIndexing = ( bool ) features12.shaderStorageImageArrayNonUniformIndexing,
177+
178+
.dynamicRendering = ( bool ) features13.dynamicRendering,
179+
.synchronization2 = ( bool ) features13.synchronization2,
180+
181+
.maintenance4 = ( bool ) features13.maintenance4,
182+
183+
.textureCompressionASTC_HDR = ( bool ) features13.textureCompressionASTC_HDR
184+
};
185+
186+
memcpy( cfg.driverUUID, properties11.driverUUID, VK_UUID_SIZE );
187+
188+
Q_strncpyz( cfg.driverName, properties12.driverName, VK_MAX_DRIVER_NAME_SIZE );
189+
Q_strncpyz( cfg.driverInfo, properties12.driverInfo, VK_MAX_DRIVER_INFO_SIZE );
190+
191+
Q_strncpyz( cfg.deviceName, coreProperties.deviceName, VK_MAX_PHYSICAL_DEVICE_NAME_SIZE );
192+
193+
memcpy( cfg.pipelineCacheUUID, coreProperties.pipelineCacheUUID, VK_UUID_SIZE );
194+
195+
switch ( coreProperties.deviceType ) {
196+
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
197+
cfg.deviceType = EngineConfig::DISCRETE;
198+
break;
199+
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
200+
cfg.deviceType = EngineConfig::INTEGRATED;
201+
break;
202+
case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
203+
cfg.deviceType = EngineConfig::VIRTUAL;
204+
break;
205+
case VK_PHYSICAL_DEVICE_TYPE_CPU:
206+
case VK_PHYSICAL_DEVICE_TYPE_OTHER:
207+
default:
208+
cfg.deviceType = EngineConfig::CPU;
209+
break;
210+
}
211+
212+
return cfg;
213+
}

0 commit comments

Comments
 (0)