Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Backends/DRMBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3426,7 +3426,7 @@ namespace gamescope
}
virtual bool ValidPhysicalDevice( VkPhysicalDevice pVkPhysicalDevice ) const override
{
return true;
return vulkan_has_drm_props();
}

virtual int Present( const FrameInfo_t *pFrameInfo, bool bAsync )
Expand Down
62 changes: 32 additions & 30 deletions src/rendervulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,46 +431,41 @@ bool CVulkanDevice::selectPhysDev(VkSurfaceKHR surface)

bool CVulkanDevice::createDevice()
{
vk.GetPhysicalDeviceMemoryProperties( physDev(), &m_memoryProperties );

uint32_t supportedExtensionCount;
vk.EnumerateDeviceExtensionProperties( physDev(), NULL, &supportedExtensionCount, NULL );

std::vector<VkExtensionProperties> supportedExts(supportedExtensionCount);
vk.EnumerateDeviceExtensionProperties( physDev(), NULL, &supportedExtensionCount, supportedExts.data() );
m_supportedExts.resize(supportedExtensionCount);
vk.EnumerateDeviceExtensionProperties( physDev(), NULL, &supportedExtensionCount, m_supportedExts.data() );

if ( !GetBackend()->ValidPhysicalDevice( physDev() ) ) {
vk_log.errorf( "not a valid physical device" );
return false;
}

vk.GetPhysicalDeviceMemoryProperties( physDev(), &m_memoryProperties );

bool hasDrmProps = false;
bool hasDrmProps = vulkan_has_drm_props();
bool supportsForeignQueue = false;
bool supportsHDRMetadata = false;
for ( uint32_t i = 0; i < supportedExtensionCount; ++i )
{
if ( strcmp(supportedExts[i].extensionName,
VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) == 0 )
for (const auto& ext : m_supportedExts) {
if ( strcmp(ext.extensionName, VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) == 0 )
m_bSupportsModifiers = true;

if ( strcmp(supportedExts[i].extensionName,
VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME) == 0 )
hasDrmProps = true;

if ( strcmp(supportedExts[i].extensionName,
VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME) == 0 )
if ( strcmp(ext.extensionName, VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME) == 0 )
supportsForeignQueue = true;

if ( strcmp(supportedExts[i].extensionName,
VK_EXT_HDR_METADATA_EXTENSION_NAME) == 0 )
supportsHDRMetadata = true;
if ( strcmp(ext.extensionName, VK_EXT_HDR_METADATA_EXTENSION_NAME) == 0 )
supportsHDRMetadata = true;
}

vk_log.infof( "physical device %s DRM format modifiers", m_bSupportsModifiers ? "supports" : "does not support" );

if ( !GetBackend()->ValidPhysicalDevice( physDev() ) )
return false;

if ( !hasDrmProps ) {
// This could happen when e.g. running the lavapipe driver
// (without an actual physical device)
vk_log.warnf( "physical device doesn't support VK_EXT_physical_device_drm" );
} else {
#if HAVE_DRM
// XXX(JoshA): Move this to ValidPhysicalDevice.
// We need to refactor some Vulkan stuff to do that though.
if ( hasDrmProps )
{
VkPhysicalDeviceDrmPropertiesEXT drmProps = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT,
};
Expand Down Expand Up @@ -509,12 +504,9 @@ bool CVulkanDevice::createDevice()
m_bHasDrmPrimaryDevId = true;
m_drmPrimaryDevId = makedev( drmProps.primaryMajor, drmProps.primaryMinor );
}
}
else
#else
vk_log.warnf( "built without DRM support" );
#endif
{
vk_log.errorf( "physical device doesn't support VK_EXT_physical_device_drm" );
return false;
}

if ( m_bSupportsModifiers && !supportsForeignQueue ) {
Expand Down Expand Up @@ -4186,6 +4178,16 @@ void vulkan_wait( uint64_t ulSeqNo, bool bReset )
return g_device.wait( ulSeqNo, bReset );
}

bool vulkan_has_drm_props()
{
for (const auto& ext : g_device.supportedExtensions()) {
if ( strcmp(ext.extensionName, VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME) == 0 )
return true;
}

return false;
}

gamescope::Rc<CVulkanTexture> vulkan_get_last_output_image( bool partial, bool defer )
{
// Get previous image ( +2 )
Expand Down
7 changes: 7 additions & 0 deletions src/rendervulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ class CVulkanDevice
inline bool hasDrmPrimaryDevId() {return m_bHasDrmPrimaryDevId;}
inline dev_t primaryDevId() {return m_drmPrimaryDevId;}
inline bool supportsFp16() {return m_bSupportsFp16;}
inline std::vector<VkExtensionProperties>& supportedExtensions() {return m_supportedExts;}

inline std::pair<void *, uint32_t> uploadBufferData(uint32_t size)
{
Expand Down Expand Up @@ -894,6 +895,9 @@ class CVulkanDevice
std::atomic<uint64_t> m_submissionSeqNo = { 0 };
std::vector<std::unique_ptr<CVulkanCmdBuffer>> m_unusedCmdBufs;
std::map<uint64_t, std::unique_ptr<CVulkanCmdBuffer>> m_pendingCmdBufs;

private:
std::vector<VkExtensionProperties> m_supportedExts;
};

struct TextureState
Expand Down Expand Up @@ -996,4 +1000,7 @@ bool vulkan_supports_hdr10();

void vulkan_wait_idle();

// Whether the driver implements VK_EXT_physical_device_drm
bool vulkan_has_drm_props();

extern CVulkanDevice g_device;