summaryrefslogtreecommitdiff
path: root/tools/gfx/vulkan
diff options
context:
space:
mode:
authorskallweitNV <64953474+skallweitNV@users.noreply.github.com>2022-11-04 17:34:53 +0100
committerGitHub <noreply@github.com>2022-11-04 17:34:53 +0100
commit015bde8d5a46f32979c00dbb1feb4b3d80729c44 (patch)
treeb95713bb080d0fbcb11d9b2519b9166e11fe5dde /tools/gfx/vulkan
parent9a3a4b08c8817905c2f608549c0e57216f8068c5 (diff)
Add AdapterLUID to identify GPU adapters (#2492)
* Add AdapterLUID to identify GPU adapters * Remove adapter option in render-test
Diffstat (limited to 'tools/gfx/vulkan')
-rw-r--r--tools/gfx/vulkan/vk-device.cpp31
-rw-r--r--tools/gfx/vulkan/vk-helper-functions.cpp98
-rw-r--r--tools/gfx/vulkan/vk-helper-functions.h2
3 files changed, 82 insertions, 49 deletions
diff --git a/tools/gfx/vulkan/vk-device.cpp b/tools/gfx/vulkan/vk-device.cpp
index b5a681de7..e4e707001 100644
--- a/tools/gfx/vulkan/vk-device.cpp
+++ b/tools/gfx/vulkan/vk-device.cpp
@@ -168,7 +168,7 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
instanceCreateInfo.ppEnabledExtensionNames = &instanceExtensions[0];
const char* layerNames[] = { nullptr };
-
+
if (useValidationLayer)
{
// Depending on driver version, validation layer may or may not exist.
@@ -250,7 +250,6 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
}
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
- Index selectedDeviceIndex = 0;
if (handles[1].handleValue == 0)
{
uint32_t numPhysicalDevices = 0;
@@ -262,34 +261,28 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
SLANG_VK_RETURN_ON_FAIL(m_api.vkEnumeratePhysicalDevices(
instance, &numPhysicalDevices, physicalDevices.getBuffer()));
- if (m_desc.adapter)
+ // Use first physical device by default.
+ Index selectedDeviceIndex = 0;
+
+ // Search for requested adapter.
+ if (m_desc.adapterLUID)
{
selectedDeviceIndex = -1;
-
- String lowerAdapter = String(m_desc.adapter).toLower();
-
for (Index i = 0; i < physicalDevices.getCount(); ++i)
{
- auto physicalDevice = physicalDevices[i];
-
- VkPhysicalDeviceProperties basicProps = {};
- m_api.vkGetPhysicalDeviceProperties(physicalDevice, &basicProps);
-
- String lowerName = String(basicProps.deviceName).toLower();
-
- if (lowerName.indexOf(lowerAdapter) != Index(-1))
+ if (vk::getAdapterLUID(m_api, physicalDevices[i]) == *m_desc.adapterLUID)
{
selectedDeviceIndex = i;
break;
}
}
if (selectedDeviceIndex < 0)
- {
- // Device not found
- return SLANG_FAIL;
- }
+ return SLANG_E_NOT_FOUND;
}
+ if (selectedDeviceIndex >= physicalDevices.getCount())
+ return SLANG_FAIL;
+
physicalDevice = physicalDevices[selectedDeviceIndex];
}
else
@@ -798,7 +791,7 @@ SlangResult DeviceImpl::readTextureResource(
auto textureImpl = static_cast<TextureResourceImpl*>(texture);
List<uint8_t> blobData;
-
+
auto desc = textureImpl->getDesc();
auto width = desc->size.width;
auto height = desc->size.height;
diff --git a/tools/gfx/vulkan/vk-helper-functions.cpp b/tools/gfx/vulkan/vk-helper-functions.cpp
index da2b55fd2..fc44256ed 100644
--- a/tools/gfx/vulkan/vk-helper-functions.cpp
+++ b/tools/gfx/vulkan/vk-helper-functions.cpp
@@ -450,41 +450,79 @@ VkImageAspectFlags getAspectMaskFromFormat(VkFormat format)
}
}
-} // namespace vk
-
-Result SLANG_MCALL getVKAdapters(List<AdapterInfo>& outAdapters)
+AdapterLUID getAdapterLUID(VulkanApi api, VkPhysicalDevice physicalDevice)
{
- VulkanModule module;
- SLANG_RETURN_ON_FAIL(module.init(false));
- VulkanApi api;
- SLANG_RETURN_ON_FAIL(api.initGlobalProcs(module));
-
- VkInstanceCreateInfo instanceCreateInfo = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO };
- VkInstance instance;
- SLANG_VK_RETURN_ON_FAIL(api.vkCreateInstance(&instanceCreateInfo, nullptr, &instance));
-
- // This will fail due to not loading any extensions.
- api.initInstanceProcs(instance);
- // Make sure required functions for enumerating physical devices were loaded.
- if (!api.vkEnumeratePhysicalDevices || !api.vkGetPhysicalDeviceProperties)
- return SLANG_FAIL;
+ AdapterLUID luid = {};
+
+ VkPhysicalDeviceIDPropertiesKHR idProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR };
+ VkPhysicalDeviceProperties2 props = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 };
+ props.pNext = &idProps;
+ SLANG_ASSERT(api.vkGetPhysicalDeviceFeatures2);
+ api.vkGetPhysicalDeviceProperties2(physicalDevice, &props);
+ if (idProps.deviceLUIDValid)
+ {
+ SLANG_ASSERT(sizeof(AdapterLUID) >= VK_LUID_SIZE);
+ memcpy(&luid, idProps.deviceLUID, VK_LUID_SIZE);
+ }
+ else
+ {
+ SLANG_ASSERT(sizeof(AdapterLUID) >= VK_UUID_SIZE);
+ memcpy(&luid, idProps.deviceUUID, VK_UUID_SIZE);
+ }
- uint32_t numPhysicalDevices = 0;
- SLANG_VK_RETURN_ON_FAIL(api.vkEnumeratePhysicalDevices(instance, &numPhysicalDevices, nullptr));
+ return luid;
+}
- List<VkPhysicalDevice> physicalDevices;
- physicalDevices.setCount(numPhysicalDevices);
- SLANG_VK_RETURN_ON_FAIL(api.vkEnumeratePhysicalDevices(instance, &numPhysicalDevices, physicalDevices.getBuffer()));
+} // namespace vk
- for (const auto& physicalDevice : physicalDevices)
+Result SLANG_MCALL getVKAdapters(List<AdapterInfo>& outAdapters)
+{
+ for (int forceSoftware = 0; forceSoftware <= 1; forceSoftware++)
{
- VkPhysicalDeviceProperties props;
- api.vkGetPhysicalDeviceProperties(physicalDevice, &props);
- AdapterInfo info = {};
- memcpy(info.name, props.deviceName, Math::Min(strlen(props.deviceName), sizeof(AdapterInfo::name) - 1));
- info.vendorID = props.vendorID;
- info.deviceID = props.deviceID;
- outAdapters.add(info);
+ VulkanModule module;
+ if (module.init(forceSoftware != 0) != SLANG_OK)
+ continue;
+ VulkanApi api;
+ if (api.initGlobalProcs(module) != SLANG_OK)
+ continue;
+
+ VkInstanceCreateInfo instanceCreateInfo = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO };
+ const char* instanceExtensions[] = {
+ VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
+ };
+ instanceCreateInfo.enabledExtensionCount = SLANG_COUNT_OF(instanceExtensions);
+ instanceCreateInfo.ppEnabledExtensionNames = &instanceExtensions[0];
+ VkInstance instance;
+ SLANG_VK_RETURN_ON_FAIL(api.vkCreateInstance(&instanceCreateInfo, nullptr, &instance));
+
+ // This will fail due to not loading any extensions.
+ api.initInstanceProcs(instance);
+
+ // Make sure required functions for enumerating physical devices were loaded.
+ if (api.vkEnumeratePhysicalDevices || api.vkGetPhysicalDeviceProperties)
+ {
+ uint32_t numPhysicalDevices = 0;
+ SLANG_VK_RETURN_ON_FAIL(api.vkEnumeratePhysicalDevices(instance, &numPhysicalDevices, nullptr));
+
+ List<VkPhysicalDevice> physicalDevices;
+ physicalDevices.setCount(numPhysicalDevices);
+ SLANG_VK_RETURN_ON_FAIL(api.vkEnumeratePhysicalDevices(instance, &numPhysicalDevices, physicalDevices.getBuffer()));
+
+ for (const auto& physicalDevice : physicalDevices)
+ {
+ VkPhysicalDeviceProperties props;
+ api.vkGetPhysicalDeviceProperties(physicalDevice, &props);
+ AdapterInfo info = {};
+ memcpy(info.name, props.deviceName, Math::Min(strlen(props.deviceName), sizeof(AdapterInfo::name) - 1));
+ info.vendorID = props.vendorID;
+ info.deviceID = props.deviceID;
+ info.luid = vk::getAdapterLUID(api, physicalDevice);
+ outAdapters.add(info);
+ }
+ }
+
+ api.vkDestroyInstance(instance, nullptr);
+ module.destroy();
}
return SLANG_OK;
diff --git a/tools/gfx/vulkan/vk-helper-functions.h b/tools/gfx/vulkan/vk-helper-functions.h
index cc80cde40..e2fae801e 100644
--- a/tools/gfx/vulkan/vk-helper-functions.h
+++ b/tools/gfx/vulkan/vk-helper-functions.h
@@ -175,6 +175,8 @@ VkPipelineStageFlags calcPipelineStageFlagsFromImageLayout(VkImageLayout layout)
VkImageAspectFlags getAspectMaskFromFormat(VkFormat format);
+AdapterLUID getAdapterLUID(VulkanApi api, VkPhysicalDevice physicaDevice);
+
} // namespace vk
Result SLANG_MCALL getVKAdapters(List<AdapterInfo>& outAdapters);