Vulkan extension detection fix (#2418)
* Fix variable naming * Check if VK_KHR_get_physical_device_properties2 is actually supported * Fix extension detection logic Device extension data wasn't cleared after enumerating each physical device, essentially checking if ANY device supports that extensions, not just the selected device
This commit is contained in:
parent
998947d58c
commit
28be8bba61
@ -346,14 +346,14 @@ VK_IMPORT_DEVICE
|
||||
};
|
||||
BX_STATIC_ASSERT(Extension::Count == BX_COUNTOF(s_extension) );
|
||||
|
||||
bool updateExtension(const char* _name, uint32_t _version, bool _instanceExt)
|
||||
bool updateExtension(const char* _name, uint32_t _version, bool _instanceExt, Extension _extensions[Extension::Count])
|
||||
{
|
||||
const bx::StringView ext(_name);
|
||||
|
||||
bool supported = false;
|
||||
for (uint32_t ii = 0; ii < Extension::Count; ++ii)
|
||||
{
|
||||
Extension& extension = s_extension[ii];
|
||||
Extension& extension = _extensions[ii];
|
||||
LayerInfo& layerInfo = _instanceExt
|
||||
? s_layer[extension.m_layer].m_instance
|
||||
: s_layer[extension.m_layer].m_device
|
||||
@ -660,7 +660,7 @@ VK_IMPORT_DEVICE
|
||||
;
|
||||
}
|
||||
|
||||
void dumpExtensions(VkPhysicalDevice _physicalDevice)
|
||||
void dumpExtensions(VkPhysicalDevice _physicalDevice, Extension _extensions[Extension::Count])
|
||||
{
|
||||
{ // Global extensions.
|
||||
uint32_t numExtensionProperties;
|
||||
@ -690,6 +690,7 @@ VK_IMPORT_DEVICE
|
||||
extensionProperties[extension].extensionName
|
||||
, extensionProperties[extension].specVersion
|
||||
, VK_NULL_HANDLE == _physicalDevice
|
||||
, _extensions
|
||||
);
|
||||
|
||||
BX_TRACE("\tv%-3d %s%s"
|
||||
@ -760,6 +761,7 @@ VK_IMPORT_DEVICE
|
||||
extensionProperties[extension].extensionName
|
||||
, extensionProperties[extension].specVersion
|
||||
, VK_NULL_HANDLE == _physicalDevice
|
||||
, _extensions
|
||||
);
|
||||
|
||||
BX_TRACE("%c\t\t%s (s: 0x%08x)"
|
||||
@ -1499,7 +1501,11 @@ VK_IMPORT_DEVICE
|
||||
};
|
||||
|
||||
ErrorState::Enum errorState = ErrorState::Default;
|
||||
void** ppNextFeatures = NULL;
|
||||
|
||||
VkPhysicalDeviceLineRasterizationFeaturesEXT lineRasterizationFeatures;
|
||||
const void* nextFeatures = NULL;
|
||||
|
||||
bx::memSet(&lineRasterizationFeatures, 0, sizeof(lineRasterizationFeatures) );
|
||||
|
||||
m_fbh.idx = kInvalidHandle;
|
||||
bx::memSet(m_uniforms, 0, sizeof(m_uniforms) );
|
||||
@ -1554,12 +1560,14 @@ VK_IMPORT
|
||||
}
|
||||
|
||||
{
|
||||
dumpExtensions(VK_NULL_HANDLE);
|
||||
dumpExtensions(VK_NULL_HANDLE, s_extension);
|
||||
|
||||
uint32_t numEnabledLayers = 0;
|
||||
|
||||
const char* enabledLayer[Layer::Count];
|
||||
|
||||
BX_TRACE("Enabled instance layers:");
|
||||
|
||||
for (uint32_t ii = 0; ii < Layer::Count; ++ii)
|
||||
{
|
||||
const Layer& layer = s_layer[ii];
|
||||
@ -1568,7 +1576,7 @@ VK_IMPORT
|
||||
&& layer.m_instance.m_initialize)
|
||||
{
|
||||
enabledLayer[numEnabledLayers++] = layer.m_name;
|
||||
BX_TRACE("%d: %s", numEnabledLayers, layer.m_name);
|
||||
BX_TRACE("\t%s", layer.m_name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1596,10 +1604,16 @@ VK_IMPORT
|
||||
&& layerEnabled)
|
||||
{
|
||||
enabledExtension[numEnabledExtensions++] = extension.m_name;
|
||||
BX_TRACE("%d: %s", numEnabledExtensions, extension.m_name);
|
||||
}
|
||||
}
|
||||
|
||||
BX_TRACE("Enabled instance extensions:");
|
||||
|
||||
for (uint32_t ii = 0; ii < numEnabledExtensions; ++ii)
|
||||
{
|
||||
BX_TRACE("\t%s", enabledExtension[ii]);
|
||||
}
|
||||
|
||||
uint32_t vulkanApiVersionSelector;
|
||||
|
||||
if (NULL != vkEnumerateInstanceVersion)
|
||||
@ -1705,12 +1719,6 @@ VK_IMPORT_INSTANCE
|
||||
BX_WARN(VK_SUCCESS == result, "vkCreateDebugReportCallbackEXT failed %d: %s.", result, getName(result) );
|
||||
}
|
||||
|
||||
VkPhysicalDeviceFeatures2KHR deviceFeatures2;
|
||||
deviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
|
||||
deviceFeatures2.pNext = NULL;
|
||||
|
||||
ppNextFeatures = &deviceFeatures2.pNext;
|
||||
|
||||
{
|
||||
BX_TRACE("---");
|
||||
|
||||
@ -1739,8 +1747,10 @@ VK_IMPORT_INSTANCE
|
||||
goto error;
|
||||
}
|
||||
|
||||
VkPhysicalDevice fallbackPhysicalDevice = VK_NULL_HANDLE;
|
||||
m_physicalDevice = VK_NULL_HANDLE;
|
||||
Extension physicalDeviceExtensions[4][Extension::Count];
|
||||
|
||||
uint32_t physicalDeviceIdx = UINT32_MAX;
|
||||
uint32_t fallbackPhysicalDeviceIdx = UINT32_MAX;
|
||||
|
||||
for (uint32_t ii = 0; ii < numPhysicalDevices; ++ii)
|
||||
{
|
||||
@ -1767,11 +1777,11 @@ VK_IMPORT_INSTANCE
|
||||
{
|
||||
if (BX_ENABLED(BGFX_CONFIG_PREFER_DISCRETE_GPU) && (pdp.deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) )
|
||||
{
|
||||
fallbackPhysicalDevice = physicalDevices[ii];
|
||||
fallbackPhysicalDeviceIdx = ii;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_physicalDevice = physicalDevices[ii];
|
||||
physicalDeviceIdx = ii;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1800,35 +1810,59 @@ VK_IMPORT_INSTANCE
|
||||
);
|
||||
}
|
||||
|
||||
dumpExtensions(physicalDevices[ii]);
|
||||
bx::memCopy(&physicalDeviceExtensions[ii][0], &s_extension[0], sizeof(s_extension) );
|
||||
dumpExtensions(physicalDevices[ii], physicalDeviceExtensions[ii]);
|
||||
}
|
||||
|
||||
if (VK_NULL_HANDLE == m_physicalDevice)
|
||||
if (UINT32_MAX == physicalDeviceIdx)
|
||||
{
|
||||
m_physicalDevice = VK_NULL_HANDLE == fallbackPhysicalDevice
|
||||
? physicalDevices[0]
|
||||
: fallbackPhysicalDevice
|
||||
physicalDeviceIdx = UINT32_MAX == fallbackPhysicalDeviceIdx
|
||||
? 0
|
||||
: fallbackPhysicalDeviceIdx
|
||||
;
|
||||
}
|
||||
|
||||
m_physicalDevice = physicalDevices[physicalDeviceIdx];
|
||||
|
||||
bx::memCopy(&s_extension[0], &physicalDeviceExtensions[physicalDeviceIdx][0], sizeof(s_extension) );
|
||||
|
||||
vkGetPhysicalDeviceProperties(m_physicalDevice, &m_deviceProperties);
|
||||
g_caps.vendorId = uint16_t(m_deviceProperties.vendorID);
|
||||
g_caps.deviceId = uint16_t(m_deviceProperties.deviceID);
|
||||
|
||||
*ppNextFeatures = &m_lineRasterizationFeatures;
|
||||
ppNextFeatures = &m_lineRasterizationFeatures.pNext;
|
||||
m_lineRasterizationFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT;
|
||||
m_lineRasterizationFeatures.pNext = NULL;
|
||||
BX_TRACE("Using physical device %d: %s", physicalDeviceIdx, m_deviceProperties.deviceName);
|
||||
|
||||
vkGetPhysicalDeviceFeatures2KHR(m_physicalDevice, &deviceFeatures2);
|
||||
if (s_extension[Extension::KHR_get_physical_device_properties2].m_supported)
|
||||
{
|
||||
VkPhysicalDeviceFeatures2KHR deviceFeatures2;
|
||||
deviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
|
||||
deviceFeatures2.pNext = NULL;
|
||||
|
||||
deviceFeatures2.features.robustBufferAccess = VK_FALSE;
|
||||
VkBaseOutStructure* next = (VkBaseOutStructure*)&deviceFeatures2;
|
||||
|
||||
m_deviceFeatures = deviceFeatures2.features;
|
||||
if (s_extension[Extension::EXT_line_rasterization].m_supported)
|
||||
{
|
||||
next->pNext = (VkBaseOutStructure*)&lineRasterizationFeatures;
|
||||
next = (VkBaseOutStructure*)&lineRasterizationFeatures;
|
||||
lineRasterizationFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT;
|
||||
lineRasterizationFeatures.pNext = NULL;
|
||||
}
|
||||
|
||||
nextFeatures = deviceFeatures2.pNext;
|
||||
|
||||
vkGetPhysicalDeviceFeatures2KHR(m_physicalDevice, &deviceFeatures2);
|
||||
m_deviceFeatures = deviceFeatures2.features;
|
||||
}
|
||||
else
|
||||
{
|
||||
vkGetPhysicalDeviceFeatures(m_physicalDevice, &m_deviceFeatures);
|
||||
}
|
||||
|
||||
m_deviceFeatures.robustBufferAccess = VK_FALSE;
|
||||
|
||||
m_lineAASupport = true
|
||||
&& s_extension[Extension::EXT_line_rasterization].m_supported
|
||||
&& m_lineRasterizationFeatures.smoothLines
|
||||
&& lineRasterizationFeatures.smoothLines
|
||||
;
|
||||
|
||||
const bool indirectDrawSupport = true
|
||||
@ -2028,6 +2062,8 @@ VK_IMPORT_INSTANCE
|
||||
|
||||
const char* enabledLayer[Layer::Count];
|
||||
|
||||
BX_TRACE("Enabled device layers:");
|
||||
|
||||
for (uint32_t ii = 0; ii < Layer::Count; ++ii)
|
||||
{
|
||||
const Layer& layer = s_layer[ii];
|
||||
@ -2036,7 +2072,7 @@ VK_IMPORT_INSTANCE
|
||||
&& layer.m_device.m_initialize)
|
||||
{
|
||||
enabledLayer[numEnabledLayers++] = layer.m_name;
|
||||
BX_TRACE("%d: %s", numEnabledLayers, layer.m_name);
|
||||
BX_TRACE("\t%s", layer.m_name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2063,10 +2099,16 @@ VK_IMPORT_INSTANCE
|
||||
&& layerEnabled)
|
||||
{
|
||||
enabledExtension[numEnabledExtensions++] = extension.m_name;
|
||||
BX_TRACE("%d: %s", numEnabledExtensions, extension.m_name);
|
||||
}
|
||||
}
|
||||
|
||||
BX_TRACE("Enabled device extensions:");
|
||||
|
||||
for (uint32_t ii = 0; ii < numEnabledExtensions; ++ii)
|
||||
{
|
||||
BX_TRACE("\t%s", enabledExtension[ii]);
|
||||
}
|
||||
|
||||
float queuePriorities[1] = { 0.0f };
|
||||
VkDeviceQueueCreateInfo dcqi;
|
||||
dcqi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
|
||||
@ -2078,7 +2120,7 @@ VK_IMPORT_INSTANCE
|
||||
|
||||
VkDeviceCreateInfo dci;
|
||||
dci.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
||||
dci.pNext = &deviceFeatures2;
|
||||
dci.pNext = nextFeatures;
|
||||
dci.flags = 0;
|
||||
dci.queueCreateInfoCount = 1;
|
||||
dci.pQueueCreateInfos = &dcqi;
|
||||
@ -2086,7 +2128,7 @@ VK_IMPORT_INSTANCE
|
||||
dci.ppEnabledLayerNames = enabledLayer;
|
||||
dci.enabledExtensionCount = numEnabledExtensions;
|
||||
dci.ppEnabledExtensionNames = enabledExtension;
|
||||
dci.pEnabledFeatures = NULL;
|
||||
dci.pEnabledFeatures = &m_deviceFeatures;
|
||||
|
||||
result = vkCreateDevice(
|
||||
m_physicalDevice
|
||||
@ -4112,21 +4154,21 @@ VK_IMPORT_DEVICE
|
||||
VkPipelineRasterizationStateCreateInfo rasterizationState;
|
||||
setRasterizerState(rasterizationState, _state, m_wireframe);
|
||||
|
||||
const void** ppNext = &rasterizationState.pNext;
|
||||
VkBaseInStructure* nextRasterizationState = (VkBaseInStructure*)&rasterizationState;
|
||||
|
||||
VkPipelineRasterizationConservativeStateCreateInfoEXT conservativeRasterizationState;
|
||||
if (s_extension[Extension::EXT_conservative_rasterization].m_supported)
|
||||
{
|
||||
*ppNext = &conservativeRasterizationState;
|
||||
ppNext = &conservativeRasterizationState.pNext;
|
||||
nextRasterizationState->pNext = (VkBaseInStructure*)&conservativeRasterizationState;
|
||||
nextRasterizationState = (VkBaseInStructure*)&conservativeRasterizationState;
|
||||
setConservativeRasterizerState(conservativeRasterizationState, _state);
|
||||
}
|
||||
|
||||
VkPipelineRasterizationLineStateCreateInfoEXT lineRasterizationState;
|
||||
if (m_lineAASupport)
|
||||
{
|
||||
*ppNext = &lineRasterizationState;
|
||||
ppNext = &lineRasterizationState.pNext;
|
||||
nextRasterizationState->pNext = (VkBaseInStructure*)&lineRasterizationState;
|
||||
nextRasterizationState = (VkBaseInStructure*)&lineRasterizationState;
|
||||
setLineRasterizerState(lineRasterizationState, _state);
|
||||
}
|
||||
|
||||
@ -4848,8 +4890,6 @@ VK_IMPORT_DEVICE
|
||||
VkPhysicalDeviceMemoryProperties m_memoryProperties;
|
||||
VkPhysicalDeviceFeatures m_deviceFeatures;
|
||||
|
||||
VkPhysicalDeviceLineRasterizationFeaturesEXT m_lineRasterizationFeatures;
|
||||
|
||||
bool m_lineAASupport;
|
||||
|
||||
VkSwapchainCreateInfoKHR m_sci;
|
||||
@ -7764,15 +7804,15 @@ BX_UNUSED(presentMin, presentMax);
|
||||
dmbp.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT;
|
||||
dmbp.pNext = NULL;
|
||||
|
||||
VkPhysicalDeviceMemoryProperties2 pdmp2;
|
||||
pdmp2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2;
|
||||
pdmp2.pNext = &dmbp;
|
||||
|
||||
int64_t gpuMemoryAvailable = -INT64_MAX;
|
||||
int64_t gpuMemoryUsed = -INT64_MAX;
|
||||
|
||||
if (s_extension[Extension::EXT_memory_budget].m_supported)
|
||||
{
|
||||
VkPhysicalDeviceMemoryProperties2 pdmp2;
|
||||
pdmp2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2;
|
||||
pdmp2.pNext = &dmbp;
|
||||
|
||||
vkGetPhysicalDeviceMemoryProperties2KHR(m_physicalDevice, &pdmp2);
|
||||
|
||||
gpuMemoryAvailable = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user