Skip to content

Commit 92a0615

Browse files
committed
IPhysicalDevice::APIVersion struct and version reporting for Vulkan and GL backends
1 parent 5e62b0c commit 92a0615

File tree

5 files changed

+70
-28
lines changed

5 files changed

+70
-28
lines changed

include/nbl/video/IPhysicalDevice.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class IPhysicalDevice : public core::Interface, public core::Unmovable
103103
// a workgroup of the next cut of the DAG spins for an extended time to wait on a workgroup from a previous one.
104104
inline uint32_t computeOptimalPersistentWorkgroupDispatchSize(const uint64_t elementCount, const uint32_t workgroupSize, const uint32_t workgroupSpinningProtection=1u) const
105105
{
106-
assert(elementCount!=0ull && "Input element count can't be 0!");
106+
assert(elementCount!=0ull && "Input element count can't be 0!");
107107
const uint64_t infinitelyWideDeviceWGCount = (elementCount-1ull)/(static_cast<uint64_t>(workgroupSize)*static_cast<uint64_t>(workgroupSpinningProtection))+1ull;
108108
const uint32_t maxResidentWorkgroups = maxResidentInvocations/workgroupSize;
109109
return static_cast<uint32_t>(core::min<uint64_t>(infinitelyWideDeviceWGCount,maxResidentWorkgroups));
@@ -320,9 +320,17 @@ class IPhysicalDevice : public core::Interface, public core::Unmovable
320320
asset::VkExtent3D minImageTransferGranularity;
321321
};
322322

323+
struct APIVersion
324+
{
325+
uint32_t major : 5;
326+
uint32_t minor : 5;
327+
uint32_t patch : 22;
328+
};
329+
323330
const SLimits& getLimits() const { return m_limits; }
324331
const SFeatures& getFeatures() const { return m_features; }
325332
const SMemoryProperties& getMemoryProperties() const { return m_memoryProperties; }
333+
const APIVersion& getAPIVersion() const { return m_apiVersion; }
326334

327335
// these are the defines which shall be added to any IGPUShader which has its source as GLSL
328336
inline core::SRange<const char* const> getExtraGLSLDefines() const
@@ -402,6 +410,7 @@ class IPhysicalDevice : public core::Interface, public core::Unmovable
402410
SLimits m_limits;
403411
SFeatures m_features;
404412
SMemoryProperties m_memoryProperties;
413+
APIVersion m_apiVersion;
405414
using qfam_props_array_t = core::smart_refctd_dynamic_array<SQueueFamilyProperties>;
406415
qfam_props_array_t m_qfamProperties;
407416

src/nbl/video/CVulkanCommon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace nbl::video
66
{
77

8+
static constexpr uint32_t MinimumVulkanApiVersion = VK_MAKE_API_VERSION(0, 1, 1, 0);
9+
810
static inline asset::E_FORMAT getFormatFromVkFormat(VkFormat in)
911
{
1012
switch (in)

src/nbl/video/CVulkanConnection.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,17 @@ namespace nbl::video
175175
debugMessengerCreateInfo.pfnUserCallback = CVulkanDebugCallback::defaultCallback;
176176
debugMessengerCreateInfo.pUserData = debugCallback.get();
177177
}
178+
179+
uint32_t instanceApiVersion = MinimumVulkanApiVersion;
180+
vkEnumerateInstanceVersion(&instanceApiVersion); // Get Highest
181+
if(instanceApiVersion < MinimumVulkanApiVersion)
182+
{
183+
assert(false);
184+
return nullptr;
185+
}
178186

179187
VkInstance vk_instance;
180188
{
181-
uint32_t instanceApiVersion = VK_MAKE_API_VERSION(0, 1, 1, 0);
182-
vkEnumerateInstanceVersion(&instanceApiVersion);
183-
184189
VkApplicationInfo applicationInfo = { VK_STRUCTURE_TYPE_APPLICATION_INFO };
185190
applicationInfo.pNext = nullptr; // pNext must be NULL
186191
applicationInfo.pApplicationName = appName;
@@ -242,7 +247,7 @@ namespace nbl::video
242247
physicalDevices.emplace_back(std::make_unique<CVulkanPhysicalDevice>(
243248
core::smart_refctd_ptr(sys),
244249
core::make_smart_refctd_ptr<asset::IGLSLCompiler>(sys.get()),
245-
api.get(), api->m_rdoc_api, vk_physicalDevices[i], vk_instance));
250+
api.get(), api->m_rdoc_api, vk_physicalDevices[i], vk_instance, instanceApiVersion));
246251

247252
}
248253

src/nbl/video/CVulkanPhysicalDevice.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace nbl::video
1212
class CVulkanPhysicalDevice final : public IPhysicalDevice
1313
{
1414
public:
15-
CVulkanPhysicalDevice(core::smart_refctd_ptr<system::ISystem>&& sys, core::smart_refctd_ptr<asset::IGLSLCompiler>&& glslc, IAPIConnection* api, renderdoc_api_t* rdoc, VkPhysicalDevice vk_physicalDevice, VkInstance vk_instance)
15+
CVulkanPhysicalDevice(core::smart_refctd_ptr<system::ISystem>&& sys, core::smart_refctd_ptr<asset::IGLSLCompiler>&& glslc, IAPIConnection* api, renderdoc_api_t* rdoc, VkPhysicalDevice vk_physicalDevice, VkInstance vk_instance, uint32_t instanceApiVersion)
1616
: IPhysicalDevice(std::move(sys),std::move(glslc)), m_api(api), m_rdoc_api(rdoc), m_vkPhysicalDevice(vk_physicalDevice), m_vkInstance(vk_instance)
1717
{
1818
// Get Supported Extensions
@@ -80,21 +80,38 @@ class CVulkanPhysicalDevice final : public IPhysicalDevice
8080
constexpr auto beefyGPUWorkgroupMaxOccupancy = 256u; // TODO: find a way to query and report this somehow, persistent threads are very useful!
8181
m_limits.maxResidentInvocations = beefyGPUWorkgroupMaxOccupancy*m_limits.maxOptimallyResidentWorkgroupInvocations;
8282

83+
84+
/*
85+
[NO NABALA SUPPORT] Vulkan 1.0 implementation must support the 1.0 version of SPIR-V and the 1.0 version of the SPIR-V Extended Instructions for GLSL. If the VK_KHR_spirv_1_4 extension is enabled, the implementation must additionally support the 1.4 version of SPIR-V.
86+
A Vulkan 1.1 implementation must support the 1.0, 1.1, 1.2, and 1.3 versions of SPIR-V and the 1.0 version of the SPIR-V Extended Instructions for GLSL.
87+
A Vulkan 1.2 implementation must support the 1.0, 1.1, 1.2, 1.3, 1.4, and 1.5 versions of SPIR-V and the 1.0 version of the SPIR-V Extended Instructions for GLSL.
88+
*/
89+
90+
uint32_t apiVersion = std::min(instanceApiVersion, deviceProperties.properties.apiVersion);
91+
assert(apiVersion >= MinimumVulkanApiVersion);
8392
m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_3;
8493

85-
switch (VK_API_VERSION_MINOR(deviceProperties.properties.apiVersion))
94+
switch (VK_API_VERSION_MINOR(apiVersion))
8695
{
8796
case 0:
88-
m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_0; break;
97+
m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_0;
98+
assert(false);
99+
break;
89100
case 1:
90-
m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_3; break;
101+
m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_3;
102+
break;
91103
case 2:
92-
m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_5; break;
104+
m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_5;
105+
break;
93106
default:
94107
_NBL_DEBUG_BREAK_IF("Invalid Vulkan minor version!");
95108
break;
96109
}
97110

111+
m_apiVersion.major = VK_API_VERSION_MAJOR(apiVersion);
112+
m_apiVersion.minor = VK_API_VERSION_MINOR(apiVersion);
113+
m_apiVersion.patch = VK_API_VERSION_PATCH(apiVersion);
114+
98115
// AccelerationStructure
99116
if (m_availableFeatureSet.find(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME) != m_availableFeatureSet.end())
100117
{

src/nbl/video/IOpenGL_PhysicalDeviceBase.h

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ namespace nbl::video
2222
template <typename LogicalDeviceType>
2323
class IOpenGL_PhysicalDeviceBase : public IPhysicalDevice
2424
{
25-
using function_table_t = typename LogicalDeviceType::FunctionTableType;
26-
static inline constexpr EGLint EGL_API_TYPE = function_table_t::EGL_API_TYPE;
27-
static inline constexpr bool IsGLES = (EGL_API_TYPE == EGL_OPENGL_ES_API);
25+
using function_table_t = typename LogicalDeviceType::FunctionTableType;
26+
static inline constexpr EGLint EGL_API_TYPE = function_table_t::EGL_API_TYPE;
27+
static inline constexpr bool IsGLES = (EGL_API_TYPE == EGL_OPENGL_ES_API);
2828

2929
static inline constexpr uint32_t MaxQueues = 8u;
3030

@@ -162,17 +162,17 @@ class IOpenGL_PhysicalDeviceBase : public IPhysicalDevice
162162
}
163163

164164
public:
165-
IOpenGL_PhysicalDeviceBase(IAPIConnection* api, renderdoc_api_t* rdoc, core::smart_refctd_ptr<system::ISystem>&& s, egl::CEGL&& _egl, COpenGLDebugCallback&& _dbgCb, EGLConfig _config, EGLContext ctx, EGLint _major, EGLint _minor)
165+
IOpenGL_PhysicalDeviceBase(IAPIConnection* api, renderdoc_api_t* rdoc, core::smart_refctd_ptr<system::ISystem>&& s, egl::CEGL&& _egl, COpenGLDebugCallback&& _dbgCb, EGLConfig _config, EGLContext ctx, EGLint _major, EGLint _minor)
166166
: IPhysicalDevice(std::move(s),core::make_smart_refctd_ptr<asset::IGLSLCompiler>(s.get())), m_api(api), m_rdoc_api(rdoc), m_egl(std::move(_egl)), m_dbgCb(std::move(_dbgCb)), m_config(_config), m_gl_major(_major), m_gl_minor(_minor)
167-
{
168-
// OpenGL backend emulates presence of just one queue family with all capabilities (graphics, compute, transfer, ... what about sparse binding?)
169-
SQueueFamilyProperties qprops;
170-
qprops.queueFlags = core::bitflag(EQF_GRAPHICS_BIT)|EQF_COMPUTE_BIT|EQF_TRANSFER_BIT;
171-
qprops.queueCount = MaxQueues;
172-
qprops.timestampValidBits = 30u; // ??? TODO: glGetQueryiv(GL_TIMESTAMP,GL_QUERY_COUNTER_BITS,&qprops.timestampValidBits)
173-
qprops.minImageTransferGranularity = { 1u,1u,1u };
167+
{
168+
// OpenGL backend emulates presence of just one queue family with all capabilities (graphics, compute, transfer, ... what about sparse binding?)
169+
SQueueFamilyProperties qprops;
170+
qprops.queueFlags = core::bitflag(EQF_GRAPHICS_BIT)|EQF_COMPUTE_BIT|EQF_TRANSFER_BIT;
171+
qprops.queueCount = MaxQueues;
172+
qprops.timestampValidBits = 30u; // ??? TODO: glGetQueryiv(GL_TIMESTAMP,GL_QUERY_COUNTER_BITS,&qprops.timestampValidBits)
173+
qprops.minImageTransferGranularity = { 1u,1u,1u };
174174

175-
m_qfamProperties = core::make_refctd_dynamic_array<qfam_props_array_t>(1u, qprops);
175+
m_qfamProperties = core::make_refctd_dynamic_array<qfam_props_array_t>(1u, qprops);
176176

177177
m_egl.call.peglBindAPI(EGL_API_TYPE);
178178

@@ -492,8 +492,17 @@ class IOpenGL_PhysicalDeviceBase : public IPhysicalDevice
492492
}
493493
}
494494

495+
int majorVer = 0;
496+
int minorVer = 0;
497+
GetIntegerv(GL_MAJOR_VERSION, &majorVer);
498+
GetIntegerv(GL_MINOR_VERSION, &minorVer);
499+
m_apiVersion.major = majorVer;
500+
m_apiVersion.minor = minorVer;
501+
m_apiVersion.patch = 0u;
502+
503+
495504
std::ostringstream pool;
496-
addCommonGLSLDefines(pool,runningInRenderDoc);
505+
addCommonGLSLDefines(pool,runningInRenderDoc);
497506
{
498507
std::string define;
499508
for (size_t j=0ull; j<std::extent<decltype(COpenGLFeatureMap::m_GLSLExtensions)>::value; ++j)
@@ -507,13 +516,13 @@ class IOpenGL_PhysicalDeviceBase : public IPhysicalDevice
507516
}
508517
}
509518
}
510-
finalizeGLSLDefinePool(std::move(pool));
519+
finalizeGLSLDefinePool(std::move(pool));
511520

512521
// we dont need this any more
513522
m_egl.call.peglMakeCurrent(m_egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
514523
m_egl.call.peglDestroyContext(m_egl.display, ctx);
515524
m_egl.call.peglDestroySurface(m_egl.display, pbuf);
516-
}
525+
}
517526

518527
IDebugCallback* getDebugCallback()
519528
{
@@ -530,11 +539,11 @@ class IOpenGL_PhysicalDeviceBase : public IPhysicalDevice
530539

531540
IAPIConnection* m_api; // dumb pointer to avoid circ ref
532541
renderdoc_api_t* m_rdoc_api;
533-
egl::CEGL m_egl;
542+
egl::CEGL m_egl;
534543
COpenGLDebugCallback m_dbgCb;
535544

536-
EGLConfig m_config;
537-
EGLint m_gl_major, m_gl_minor;
545+
EGLConfig m_config;
546+
EGLint m_gl_major, m_gl_minor;
538547

539548
COpenGLFeatureMap m_glfeatures;
540549
};

0 commit comments

Comments
 (0)