Skip to content

Commit

Permalink
Fix non-conformant vkEnumeratePhysicalDeviceGroups behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperZielinski-Intel authored and baldurk committed Mar 5, 2024
1 parent b902528 commit 3c02b6f
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,35 +912,38 @@ VkResult WrappedVulkan::vkEnumeratePhysicalDeviceGroups(
VkInstance instance, uint32_t *pPhysicalDeviceGroupCount,
VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties)
{
// we ignore the 'real' physical device groups, and report one group per physical device. We use
// our internal enumerate function to make sure we handle wrapping the objects.
uint32_t numPhys = 0;
vkEnumeratePhysicalDevices(instance, &numPhys, NULL);
// We ignore the 'real' physical device groups, and report one group per physical device.
// We use our internal enumerate function to make sure we handle wrapping the objects.
uint32_t physicalDevicesNumber = 0;
vkEnumeratePhysicalDevices(instance, &physicalDevicesNumber, NULL);

VkPhysicalDevice *phys = new VkPhysicalDevice[numPhys];
vkEnumeratePhysicalDevices(instance, &numPhys, phys);

uint32_t outputSpace = pPhysicalDeviceGroupCount ? *pPhysicalDeviceGroupCount : 0;

if(pPhysicalDeviceGroupCount)
*pPhysicalDeviceGroupCount = numPhys;

if(pPhysicalDeviceGroupProperties)
// Return number of available device groups.
if(pPhysicalDeviceGroupProperties == NULL)
{
// list one group per device
for(uint32_t i = 0; i < outputSpace; i++)
if(pPhysicalDeviceGroupCount)
{
RDCEraseEl(pPhysicalDeviceGroupProperties[i]);
pPhysicalDeviceGroupProperties[i].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES;
pPhysicalDeviceGroupProperties[i].physicalDeviceCount = 1;
pPhysicalDeviceGroupProperties[i].physicalDevices[0] = phys[i];
pPhysicalDeviceGroupProperties[i].subsetAllocation = VK_FALSE;
*pPhysicalDeviceGroupCount = physicalDevicesNumber;
}
return VK_SUCCESS;
}

delete[] phys;
uint32_t physicalDeviceGroupCount = pPhysicalDeviceGroupCount ? *pPhysicalDeviceGroupCount : 0;

rdcarray<VkPhysicalDevice> physicalDevices;
physicalDevices.resize(physicalDeviceGroupCount);
vkEnumeratePhysicalDevices(instance, &physicalDeviceGroupCount, physicalDevices.data());

// List one group per device.
for(uint32_t i = 0; i < physicalDeviceGroupCount; i++)
{
RDCEraseEl(pPhysicalDeviceGroupProperties[i]);
pPhysicalDeviceGroupProperties[i].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES;
pPhysicalDeviceGroupProperties[i].physicalDeviceCount = 1;
pPhysicalDeviceGroupProperties[i].physicalDevices[0] = physicalDevices[i];
pPhysicalDeviceGroupProperties[i].subsetAllocation = VK_FALSE;
}

if(pPhysicalDeviceGroupProperties && outputSpace < numPhys)
if(physicalDeviceGroupCount < physicalDevicesNumber)
return VK_INCOMPLETE;

return VK_SUCCESS;
Expand Down

0 comments on commit 3c02b6f

Please sign in to comment.