Skip to content

Commit 9952102

Browse files
IEngineFactoryVk: added GetVulkanVersion method (API256009)
1 parent 6276a6e commit 9952102

File tree

7 files changed

+76
-7
lines changed

7 files changed

+76
-7
lines changed

Graphics/GraphicsEngine/interface/APIInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/// \file
3131
/// Diligent API information
3232

33-
#define DILIGENT_API_VERSION 256008
33+
#define DILIGENT_API_VERSION 256009
3434

3535
#include "../../../Primitives/interface/BasicTypes.h"
3636

Graphics/GraphicsEngineVulkan/include/VulkanUtilities/Instance.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class Instance : public std::enable_shared_from_this<Instance>
4848
Instance& operator = ( Instance&&) = delete;
4949
// clang-format on
5050

51+
static uint32_t GetApiVersion();
52+
5153
struct CreateInfo
5254
{
5355
uint32_t ApiVersion = 0;

Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -99,13 +99,19 @@ DILIGENT_BEGIN_INTERFACE(IEngineFactoryVk, IEngineFactory)
9999
const NativeWindow REF Window,
100100
ISwapChain** ppSwapChain) PURE;
101101

102-
/// Enable device simulation layer (if available).
102+
/// Enables device simulation layer (if available).
103103

104104
/// Vulkan instance will be created with the device simulation layer.
105105
/// Use VK_DEVSIM_FILENAME environment variable to define the path to the .json file.
106106
///
107107
/// \remarks Use this function before calling EnumerateAdapters() and CreateDeviceAndContextsVk().
108108
VIRTUAL void METHOD(EnableDeviceSimulation)(THIS) PURE;
109+
110+
111+
/// Returns the supported Vulkan version. If Vulkan is not supported, returns 0.
112+
113+
/// This function can be used to check whether Vulkan is supported on the platform.
114+
VIRTUAL Version METHOD(GetVulkanVersion)(THIS) CONST PURE;
109115
};
110116
DILIGENT_END_INTERFACE
111117

@@ -118,6 +124,7 @@ DILIGENT_END_INTERFACE
118124
# define IEngineFactoryVk_CreateDeviceAndContextsVk(This, ...) CALL_IFACE_METHOD(EngineFactoryVk, CreateDeviceAndContextsVk, This, __VA_ARGS__)
119125
# define IEngineFactoryVk_CreateSwapChainVk(This, ...) CALL_IFACE_METHOD(EngineFactoryVk, CreateSwapChainVk, This, __VA_ARGS__)
120126
# define IEngineFactoryVk_EnableDeviceSimulation(This) CALL_IFACE_METHOD(EngineFactoryVk, EnableDeviceSimulation, This)
127+
# define IEngineFactoryVk_GetVulkanVersion(This) CALL_IFACE_METHOD(EngineFactoryVk, GetVulkanVersion, This)
121128

122129
// clang-format on
123130

Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ class EngineFactoryVkImpl final : public EngineFactoryBase<IEngineFactoryVk>
116116
m_EnableDeviceSimulation = true;
117117
}
118118

119+
virtual Version DILIGENT_CALL_TYPE GetVulkanVersion() const override final
120+
{
121+
uint32_t ApiVersion = VulkanUtilities::Instance::GetApiVersion();
122+
return {VK_VERSION_MAJOR(ApiVersion), VK_VERSION_MINOR(ApiVersion)};
123+
}
124+
119125
virtual void DILIGENT_CALL_TYPE CreateDearchiver(const DearchiverCreateInfo& CreateInfo,
120126
IDearchiver** ppDearchiver) const override final
121127
{

Graphics/GraphicsEngineVulkan/src/VulkanUtilities/Instance.cpp

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,65 @@ static bool LoadVulkan()
257257
if (VulkanLoaded)
258258
return true;
259259

260-
if (volkInitialize() == VK_SUCCESS)
260+
VulkanLoaded = (volkInitialize() == VK_SUCCESS);
261+
return VulkanLoaded;
262+
}
263+
#endif
264+
265+
uint32_t Instance::GetApiVersion()
266+
{
267+
#if DILIGENT_USE_VOLK
268+
if (!LoadVulkan())
261269
{
262-
VulkanLoaded = true;
270+
return 0;
263271
}
272+
#endif
264273

265-
return VulkanLoaded;
266-
}
274+
uint32_t ApiVersion = VK_API_VERSION_1_0;
275+
#if DILIGENT_USE_VOLK
276+
if (vkEnumerateInstanceVersion != nullptr)
277+
{
278+
vkEnumerateInstanceVersion(&ApiVersion);
279+
}
267280
#endif
268281

282+
VkApplicationInfo AppInfo{};
283+
AppInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
284+
AppInfo.apiVersion = ApiVersion;
285+
286+
VkInstanceCreateInfo InstCI{};
287+
InstCI.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
288+
InstCI.pApplicationInfo = &AppInfo;
289+
290+
VkInstance vkInstance = VK_NULL_HANDLE;
291+
VkResult Result = vkCreateInstance(&InstCI, nullptr, &vkInstance);
292+
if (Result != VK_SUCCESS)
293+
{
294+
return 0;
295+
}
296+
297+
uint32_t DeviceCount = 0;
298+
if (PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices = reinterpret_cast<PFN_vkEnumeratePhysicalDevices>(vkGetInstanceProcAddr(vkInstance, "vkEnumeratePhysicalDevices")))
299+
{
300+
Result = EnumeratePhysicalDevices(vkInstance, &DeviceCount, nullptr);
301+
}
302+
else
303+
{
304+
UNEXPECTED("Unable to load vkEnumeratePhysicalDevices function.");
305+
}
306+
307+
if (PFN_vkDestroyInstance DestroyInstance = reinterpret_cast<PFN_vkDestroyInstance>(vkGetInstanceProcAddr(vkInstance, "vkDestroyInstance")))
308+
{
309+
DestroyInstance(vkInstance, nullptr);
310+
}
311+
else
312+
{
313+
UNEXPECTED("Unable to load vkDestroyInstance function.");
314+
}
315+
316+
return DeviceCount > 0 ? ApiVersion : 0;
317+
}
318+
269319
Instance::Instance(const CreateInfo& CI) :
270320
m_pvkAllocator{CI.pVkAllocator}
271321
{

ReleaseHistory.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Current progress
44

5+
* Added `IEngineFactoryVk::GetVulkanVersion` method (API256009)
56
* Added `SHADER_COMPILE_FLAG_HLSL_TO_SPIRV_VIA_GLSL` flag (API256008)
67
* Added `IRenderDevice::CreateDeferredContext()` method (API256007)
78
* Added `HostImageCopy` member to `DeviceFeaturesVk` struct (API256006)

Tests/GPUTestFramework/src/GPUTestingEnvironment.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ GPUTestingEnvironment::GPUTestingEnvironment(const CreateInfo& EnvCI, const Swap
393393
pFactoryVk->SetMessageCallback(EnvCI.MessageCallback);
394394
pFactoryVk->SetBreakOnError(false);
395395

396+
Version VulkanVersion = pFactoryVk->GetVulkanVersion();
397+
VERIFY(VulkanVersion >= Version(1, 0), "Vulkan is not supported on this platform.");
398+
396399
if (EnvCI.EnableDeviceSimulation)
397400
pFactoryVk->EnableDeviceSimulation();
398401

0 commit comments

Comments
 (0)