summaryrefslogtreecommitdiffstats
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
parent9a3a4b08c8817905c2f608549c0e57216f8068c5 (diff)
Add AdapterLUID to identify GPU adapters (#2492)
* Add AdapterLUID to identify GPU adapters * Remove adapter option in render-test
-rw-r--r--slang-gfx.h29
-rw-r--r--tools/gfx/cuda/cuda-device.cpp25
-rw-r--r--tools/gfx/cuda/cuda-helper-functions.cpp40
-rw-r--r--tools/gfx/cuda/cuda-helper-functions.h2
-rw-r--r--tools/gfx/d3d/d3d-util.cpp31
-rw-r--r--tools/gfx/d3d/d3d-util.h8
-rw-r--r--tools/gfx/d3d11/d3d11-device.cpp10
-rw-r--r--tools/gfx/d3d11/d3d11-helper-functions.cpp4
-rw-r--r--tools/gfx/d3d12/d3d12-device.cpp8
-rw-r--r--tools/gfx/d3d12/d3d12-device.h2
-rw-r--r--tools/gfx/d3d12/d3d12-helper-functions.cpp4
-rw-r--r--tools/gfx/open-gl/render-gl.cpp13
-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
-rw-r--r--tools/render-test/options.cpp4
-rw-r--r--tools/render-test/options.h2
-rw-r--r--tools/render-test/render-test-main.cpp5
18 files changed, 195 insertions, 123 deletions
diff --git a/slang-gfx.h b/slang-gfx.h
index 5decc9010..8db2a6ee4 100644
--- a/slang-gfx.h
+++ b/slang-gfx.h
@@ -2071,11 +2071,36 @@ public:
0x8eccc8ec, 0x5c04, 0x4a51, { 0x99, 0x75, 0x13, 0xf8, 0xfe, 0xa1, 0x59, 0xf3 } \
}
+struct AdapterLUID
+{
+ uint8_t luid[16];
+
+ bool operator==(const AdapterLUID& other) const
+ {
+ for (int i = 0; i < sizeof(AdapterLUID::luid); ++i)
+ if (luid[i] != other.luid[i])
+ return false;
+ return true;
+ }
+ bool operator!=(const AdapterLUID& other) const
+ {
+ return !this->operator==(other);
+ }
+};
+
struct AdapterInfo
{
+ // Descriptive name of the adapter.
char name[128];
+
+ // Unique identifier for the vendor (only available for D3D and Vulkan).
uint32_t vendorID;
+
+ // Unique identifier for the physical device among devices from the vendor (only available for D3D and Vulkan)
uint32_t deviceID;
+
+ // Logically unique identifier of the adapter.
+ AdapterLUID luid;
};
class AdapterList
@@ -2182,8 +2207,8 @@ public:
// for the ID3D12Device. For Vulkan, the first InteropHandle is the VkInstance, the second is the VkPhysicalDevice,
// and the third is the VkDevice. For CUDA, this only contains a single value for the CUDADevice.
InteropHandles existingDeviceHandles;
- // Name to identify the adapter to use
- const char* adapter = nullptr;
+ // LUID of the adapter to use. Use getGfxAdapters() to get a list of available adapters.
+ AdapterLUID* adapterLUID = nullptr;
// Number of required features.
GfxCount requiredFeatureCount = 0;
// Array of required feature names, whose size is `requiredFeatureCount`.
diff --git a/tools/gfx/cuda/cuda-device.cpp b/tools/gfx/cuda/cuda-device.cpp
index 32454109b..76538cfad 100644
--- a/tools/gfx/cuda/cuda-device.cpp
+++ b/tools/gfx/cuda/cuda-device.cpp
@@ -150,13 +150,30 @@ SLANG_NO_THROW SlangResult SLANG_MCALL DeviceImpl::initialize(const Desc& desc)
SLANG_RETURN_ON_FAIL(_initCuda(reportType));
- SLANG_RETURN_ON_FAIL(_findMaxFlopsDeviceIndex(&m_deviceIndex));
+ if (desc.adapterLUID)
+ {
+ int deviceCount = -1;
+ cuDeviceGetCount(&deviceCount);
+ for (int deviceIndex = 0; deviceIndex < deviceCount; ++deviceIndex)
+ {
+ if (cuda::getAdapterLUID(deviceIndex) == *desc.adapterLUID)
+ {
+ m_deviceIndex = deviceIndex;
+ break;
+ }
+ }
+ if (m_deviceIndex >= deviceCount)
+ return SLANG_E_INVALID_ARG;
+ }
+ else
+ {
+ SLANG_RETURN_ON_FAIL(_findMaxFlopsDeviceIndex(&m_deviceIndex));
+ }
+
SLANG_CUDA_RETURN_WITH_REPORT_ON_FAIL(cudaSetDevice(m_deviceIndex), reportType);
m_context = new CUDAContext();
- int count = -1;
- cuDeviceGetCount(&count);
SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGet(&m_device, m_deviceIndex));
SLANG_CUDA_RETURN_WITH_REPORT_ON_FAIL(
@@ -1103,7 +1120,7 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::readBufferResource(
ISlangBlob** outBlob)
{
auto bufferImpl = static_cast<BufferResourceImpl*>(buffer);
-
+
List<uint8_t> blobData;
blobData.setCount((Index)size);
diff --git a/tools/gfx/cuda/cuda-helper-functions.cpp b/tools/gfx/cuda/cuda-helper-functions.cpp
index 702caf253..0a8d734d8 100644
--- a/tools/gfx/cuda/cuda-helper-functions.cpp
+++ b/tools/gfx/cuda/cuda-helper-functions.cpp
@@ -70,18 +70,36 @@ void _optixLogCallback(unsigned int level, const char* tag, const char* message,
}
# endif
# endif
+
+AdapterLUID getAdapterLUID(int device)
+{
+ AdapterLUID luid = {};
+#if SLANG_WIN32 || SLANG_WIN64
+ // LUID reported by CUDA is undefined i not on windows platform.
+ cudaDeviceProp prop;
+ cudaGetDeviceProperties(&prop, device);
+ SLANG_ASSERT(sizeof(AdapterLUID) >= sizeof(cudaDeviceProp::luid));
+ memcpy(&luid, prop.luid, sizeof(cudaDeviceProp::luid));
+#else
+ SLANG_ASSERT(sizeof(AdapterLUID) >= sizeof(int));
+ memcpy(&luid, &device, sizeof(int));
+#endif
+ return luid;
+}
+
} // namespace cuda
Result SLANG_MCALL getCUDAAdapters(List<AdapterInfo>& outAdapters)
{
- int count;
- cudaGetDeviceCount(&count);
- for (int i = 0; i < count; i++)
+ int deviceCount;
+ cudaGetDeviceCount(&deviceCount);
+ for (int device = 0; device < deviceCount; device++)
{
cudaDeviceProp prop;
- cudaGetDeviceProperties(&prop, i);
+ cudaGetDeviceProperties(&prop, device);
AdapterInfo info = {};
memcpy(info.name, prop.name, Math::Min(strlen(prop.name), sizeof(AdapterInfo::name) - 1));
+ info.luid = cuda::getAdapterLUID(device);
outAdapters.add(info);
}
@@ -90,10 +108,10 @@ Result SLANG_MCALL getCUDAAdapters(List<AdapterInfo>& outAdapters)
Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice)
{
-RefPtr<cuda::DeviceImpl> result = new cuda::DeviceImpl();
-SLANG_RETURN_ON_FAIL(result->initialize(*desc));
-returnComPtr(outDevice, result);
-return SLANG_OK;
+ RefPtr<cuda::DeviceImpl> result = new cuda::DeviceImpl();
+ SLANG_RETURN_ON_FAIL(result->initialize(*desc));
+ returnComPtr(outDevice, result);
+ return SLANG_OK;
}
#else
@@ -105,9 +123,9 @@ Result SLANG_MCALL getCUDAAdapters(List<AdapterInfo>& outAdapters)
Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice)
{
-SLANG_UNUSED(desc);
-*outDevice = nullptr;
-return SLANG_FAIL;
+ SLANG_UNUSED(desc);
+ *outDevice = nullptr;
+ return SLANG_FAIL;
}
#endif
diff --git a/tools/gfx/cuda/cuda-helper-functions.h b/tools/gfx/cuda/cuda-helper-functions.h
index 92ac4f4ed..7417249d5 100644
--- a/tools/gfx/cuda/cuda-helper-functions.h
+++ b/tools/gfx/cuda/cuda-helper-functions.h
@@ -99,6 +99,8 @@ void _optixLogCallback(unsigned int level, const char* tag, const char* message,
# endif
+AdapterLUID getAdapterLUID(int device);
+
} // namespace cuda
#endif
diff --git a/tools/gfx/d3d/d3d-util.cpp b/tools/gfx/d3d/d3d-util.cpp
index e50ddaa80..dff93810c 100644
--- a/tools/gfx/d3d/d3d-util.cpp
+++ b/tools/gfx/d3d/d3d-util.cpp
@@ -163,7 +163,7 @@ D3D12_DEPTH_STENCILOP_DESC D3DUtil::translateStencilOpDesc(DepthStencilOpDesc de
case Format::R16G16B16A16_UINT: return DXGI_FORMAT_R16G16B16A16_UINT;
case Format::R16G16_UINT: return DXGI_FORMAT_R16G16_UINT;
case Format::R16_UINT: return DXGI_FORMAT_R16_UINT;
-
+
case Format::R8G8B8A8_UINT: return DXGI_FORMAT_R8G8B8A8_UINT;
case Format::R8G8_UINT: return DXGI_FORMAT_R8G8_UINT;
case Format::R8_UINT: return DXGI_FORMAT_R8_UINT;
@@ -550,26 +550,21 @@ bool D3DUtil::isTypeless(DXGI_FORMAT format)
}
}
-/* static */SlangResult D3DUtil::findAdapters(DeviceCheckFlags flags, const Slang::UnownedStringSlice& adapaterName, List<ComPtr<IDXGIAdapter>>& outDxgiAdapters)
+/* static */SlangResult D3DUtil::findAdapters(DeviceCheckFlags flags, const AdapterLUID* adapterLUID, List<ComPtr<IDXGIAdapter>>& outDxgiAdapters)
{
ComPtr<IDXGIFactory> factory;
SLANG_RETURN_ON_FAIL(createFactory(flags, factory));
- return findAdapters(flags, adapaterName, factory, outDxgiAdapters);
+ return findAdapters(flags, adapterLUID, factory, outDxgiAdapters);
}
-static bool _isMatch(IDXGIAdapter* adapter, const Slang::UnownedStringSlice& lowerAdapaterName)
+/* static */ AdapterLUID D3DUtil::getAdapterLUID(IDXGIAdapter* dxgiAdapter)
{
- if (lowerAdapaterName.getLength() == 0)
- {
- return true;
- }
-
DXGI_ADAPTER_DESC desc;
- adapter->GetDesc(&desc);
-
- String descName = String::fromWString(desc.Description).toLower();
-
- return descName.indexOf(lowerAdapaterName) != Index(-1);
+ dxgiAdapter->GetDesc(&desc);
+ AdapterLUID luid = {};
+ SLANG_ASSERT(sizeof(AdapterLUID) >= sizeof(LUID));
+ memcpy(&luid, &desc.AdapterLuid, sizeof(LUID));
+ return luid;
}
/* static */bool D3DUtil::isWarp(IDXGIFactory* dxgiFactory, IDXGIAdapter* adapterIn)
@@ -841,10 +836,8 @@ D3D12_RESOURCE_STATES D3DUtil::getResourceState(ResourceState state)
}
}
-/* static */SlangResult D3DUtil::findAdapters(DeviceCheckFlags flags, const UnownedStringSlice& adapterName, IDXGIFactory* dxgiFactory, List<ComPtr<IDXGIAdapter>>& outDxgiAdapters)
+/* static */SlangResult D3DUtil::findAdapters(DeviceCheckFlags flags, const AdapterLUID* adapterLUID, IDXGIFactory* dxgiFactory, List<ComPtr<IDXGIAdapter>>& outDxgiAdapters)
{
- Slang::String lowerAdapterName = Slang::String(adapterName).toLower();
-
outDxgiAdapters.clear();
ComPtr<IDXGIAdapter> warpAdapter;
@@ -854,7 +847,7 @@ D3D12_RESOURCE_STATES D3DUtil::getResourceState(ResourceState state)
if (SLANG_SUCCEEDED(dxgiFactory->QueryInterface(IID_PPV_ARGS(dxgiFactory4.writeRef()))))
{
dxgiFactory4->EnumWarpAdapter(IID_PPV_ARGS(warpAdapter.writeRef()));
- if (_isMatch(warpAdapter, lowerAdapterName.getUnownedSlice()))
+ if (!adapterLUID || D3DUtil::getAdapterLUID(warpAdapter) == *adapterLUID)
{
outDxgiAdapters.add(warpAdapter);
}
@@ -872,7 +865,7 @@ D3D12_RESOURCE_STATES D3DUtil::getResourceState(ResourceState state)
{
continue;
}
- if (!_isMatch(dxgiAdapter, lowerAdapterName.getUnownedSlice()))
+ if (adapterLUID && D3DUtil::getAdapterLUID(dxgiAdapter) != *adapterLUID)
{
continue;
}
diff --git a/tools/gfx/d3d/d3d-util.h b/tools/gfx/d3d/d3d-util.h
index 34feabc7f..4e5880c0a 100644
--- a/tools/gfx/d3d/d3d-util.h
+++ b/tools/gfx/d3d/d3d-util.h
@@ -78,16 +78,18 @@ class D3DUtil
/// Append text in in, into wide char array
static void appendWideChars(const char* in, Slang::List<wchar_t>& out);
-
+
static SlangResult createFactory(DeviceCheckFlags flags, Slang::ComPtr<IDXGIFactory>& outFactory);
/// Get the dxgiModule
static HMODULE getDxgiModule();
/// Find adapters
- static SlangResult findAdapters(DeviceCheckFlags flags, const Slang::UnownedStringSlice& adapaterName, IDXGIFactory* dxgiFactory, Slang::List<Slang::ComPtr<IDXGIAdapter>>& dxgiAdapters);
+ static SlangResult findAdapters(DeviceCheckFlags flags, const AdapterLUID* adapterLUID, IDXGIFactory* dxgiFactory, Slang::List<Slang::ComPtr<IDXGIAdapter>>& dxgiAdapters);
/// Find adapters
- static SlangResult findAdapters(DeviceCheckFlags flags, const Slang::UnownedStringSlice& adapaterName, Slang::List<Slang::ComPtr<IDXGIAdapter>>& dxgiAdapters);
+ static SlangResult findAdapters(DeviceCheckFlags flags, const AdapterLUID* adapterLUID, Slang::List<Slang::ComPtr<IDXGIAdapter>>& dxgiAdapters);
+
+ static AdapterLUID getAdapterLUID(IDXGIAdapter* dxgiAdapter);
/// True if the adapter is warp
static bool isWarp(IDXGIFactory* dxgiFactory, IDXGIAdapter* adapter);
diff --git a/tools/gfx/d3d11/d3d11-device.cpp b/tools/gfx/d3d11/d3d11-device.cpp
index fbc24c9ce..4872d2a54 100644
--- a/tools/gfx/d3d11/d3d11-device.cpp
+++ b/tools/gfx/d3d11/d3d11-device.cpp
@@ -112,12 +112,12 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
const auto deviceCheckFlags = combiner.getCombination(i);
D3DUtil::createFactory(deviceCheckFlags, m_dxgiFactory);
- // If we have an adapter set on the desc, look it up. We only need to do so for hardware
+ // If we have an adapter set on the desc, look it up.
ComPtr<IDXGIAdapter> adapter;
- if (desc.adapter && (deviceCheckFlags & DeviceCheckFlag::UseHardwareDevice))
+ if (desc.adapterLUID)
{
List<ComPtr<IDXGIAdapter>> dxgiAdapters;
- D3DUtil::findAdapters(deviceCheckFlags, Slang::UnownedStringSlice(desc.adapter), dxgiAdapters);
+ D3DUtil::findAdapters(deviceCheckFlags, desc.adapterLUID, m_dxgiFactory, dxgiAdapters);
if (dxgiAdapters.getCount() == 0)
{
continue;
@@ -147,7 +147,7 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
m_device.writeRef(),
&featureLevel,
m_immediateContext.writeRef());
- // Check if successfully constructed - if so we are done.
+ // Check if successfully constructed - if so we are done.
if (SLANG_SUCCEEDED(res))
{
break;
@@ -882,7 +882,7 @@ Result DeviceImpl::createInputLayout(IInputLayout::Desc const& desc, IInputLayou
default:
return SLANG_FAIL;
}
-
+
hlslCursor += sprintf(hlslCursor, "%s a%d : %s%d",
typeName,
(int)ii,
diff --git a/tools/gfx/d3d11/d3d11-helper-functions.cpp b/tools/gfx/d3d11/d3d11-helper-functions.cpp
index 93065077a..4e1df9879 100644
--- a/tools/gfx/d3d11/d3d11-helper-functions.cpp
+++ b/tools/gfx/d3d11/d3d11-helper-functions.cpp
@@ -348,8 +348,7 @@ namespace d3d11
Result SLANG_MCALL getD3D11Adapters(List<AdapterInfo>& outAdapters)
{
List<ComPtr<IDXGIAdapter>> dxgiAdapters;
- DeviceCheckFlags flags = DeviceCheckFlag::UseHardwareDevice;
- SLANG_RETURN_ON_FAIL(D3DUtil::findAdapters(flags, UnownedStringSlice(), dxgiAdapters));
+ SLANG_RETURN_ON_FAIL(D3DUtil::findAdapters(DeviceCheckFlag::UseHardwareDevice, nullptr, dxgiAdapters));
outAdapters.clear();
for (const auto& dxgiAdapter : dxgiAdapters)
@@ -361,6 +360,7 @@ Result SLANG_MCALL getD3D11Adapters(List<AdapterInfo>& outAdapters)
memcpy(info.name, name.getBuffer(), Math::Min(name.getLength(), (Index)sizeof(AdapterInfo::name) - 1));
info.vendorID = desc.VendorId;
info.deviceID = desc.DeviceId;
+ info.luid = D3DUtil::getAdapterLUID(dxgiAdapter);
outAdapters.add(info);
}
return SLANG_OK;
diff --git a/tools/gfx/d3d12/d3d12-device.cpp b/tools/gfx/d3d12/d3d12-device.cpp
index c87e6b4ca..ebb416c39 100644
--- a/tools/gfx/d3d12/d3d12-device.cpp
+++ b/tools/gfx/d3d12/d3d12-device.cpp
@@ -277,7 +277,7 @@ Result DeviceImpl::getNativeDeviceHandles(InteropHandles* outHandles)
Result DeviceImpl::_createDevice(
DeviceCheckFlags deviceCheckFlags,
- const UnownedStringSlice& nameMatch,
+ const AdapterLUID* adapterLUID,
D3D_FEATURE_LEVEL featureLevel,
D3D12DeviceInfo& outDeviceInfo)
{
@@ -293,7 +293,7 @@ Result DeviceImpl::_createDevice(
List<ComPtr<IDXGIAdapter>> dxgiAdapters;
SLANG_RETURN_ON_FAIL(
- D3DUtil::findAdapters(deviceCheckFlags, nameMatch, dxgiFactory, dxgiAdapters));
+ D3DUtil::findAdapters(deviceCheckFlags, adapterLUID, dxgiFactory, dxgiAdapters));
ComPtr<ID3D12Device> device;
ComPtr<IDXGIAdapter> adapter;
@@ -471,7 +471,7 @@ Result DeviceImpl::initialize(const Desc& desc)
if (SLANG_SUCCEEDED(m_D3D12GetDebugInterface(IID_PPV_ARGS(m_dxDebug.writeRef()))))
{
# if 0
- // Can enable for extra validation. NOTE! That d3d12 warns if you do....
+ // Can enable for extra validation. NOTE! That d3d12 warns if you do....
// D3D12 MESSAGE : Device Debug Layer Startup Options : GPU - Based Validation is enabled(disabled by default).
// This results in new validation not possible during API calls on the CPU, by creating patched shaders that have validation
// added directly to the shader. However, it can slow things down a lot, especially for applications with numerous
@@ -534,7 +534,7 @@ Result DeviceImpl::initialize(const Desc& desc)
{
if (SLANG_SUCCEEDED(_createDevice(
combiner.getCombination(i),
- UnownedStringSlice(desc.adapter),
+ desc.adapterLUID,
featureLevel,
m_deviceInfo)))
{
diff --git a/tools/gfx/d3d12/d3d12-device.h b/tools/gfx/d3d12/d3d12-device.h
index 38b3251fd..fb54e5543 100644
--- a/tools/gfx/d3d12/d3d12-device.h
+++ b/tools/gfx/d3d12/d3d12-device.h
@@ -236,7 +236,7 @@ public:
Result _createDevice(
DeviceCheckFlags deviceCheckFlags,
- const UnownedStringSlice& nameMatch,
+ const AdapterLUID* adapterLUID,
D3D_FEATURE_LEVEL featureLevel,
D3D12DeviceInfo& outDeviceInfo);
diff --git a/tools/gfx/d3d12/d3d12-helper-functions.cpp b/tools/gfx/d3d12/d3d12-helper-functions.cpp
index 34efa8401..efa379786 100644
--- a/tools/gfx/d3d12/d3d12-helper-functions.cpp
+++ b/tools/gfx/d3d12/d3d12-helper-functions.cpp
@@ -616,8 +616,7 @@ void translatePostBuildInfoDescs(
Result SLANG_MCALL getD3D12Adapters(List<AdapterInfo>& outAdapters)
{
List<ComPtr<IDXGIAdapter>> dxgiAdapters;
- DeviceCheckFlags flags = DeviceCheckFlag::UseHardwareDevice;
- SLANG_RETURN_ON_FAIL(D3DUtil::findAdapters(flags, UnownedStringSlice(), dxgiAdapters));
+ SLANG_RETURN_ON_FAIL(D3DUtil::findAdapters(DeviceCheckFlag::UseHardwareDevice, nullptr, dxgiAdapters));
outAdapters.clear();
for (const auto& dxgiAdapter : dxgiAdapters)
@@ -629,6 +628,7 @@ Result SLANG_MCALL getD3D12Adapters(List<AdapterInfo>& outAdapters)
memcpy(info.name, name.getBuffer(), Math::Min(name.getLength(), (Index)sizeof(AdapterInfo::name) - 1));
info.vendorID = desc.VendorId;
info.deviceID = desc.DeviceId;
+ info.luid = D3DUtil::getAdapterLUID(dxgiAdapter);
outAdapters.add(info);
}
return SLANG_OK;
diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp
index f6fe5c9af..9167266e9 100644
--- a/tools/gfx/open-gl/render-gl.cpp
+++ b/tools/gfx/open-gl/render-gl.cpp
@@ -1367,7 +1367,7 @@ public:
auto subObjectLayout = subObjectRange.layout;
auto const& bindingRange =
layout->getBindingRange(subObjectRange.bindingRangeIndex);
-
+
switch (bindingRange.bindingType)
{
case slang::BindingType::ConstantBuffer:
@@ -2039,16 +2039,9 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::initialize(const Desc& desc)
auto renderer = glGetString(GL_RENDERER);
m_info.adapterName = (char*)renderer;
- if (renderer && desc.adapter)
+ if (desc.adapterLUID)
{
- String lowerAdapter = String(desc.adapter).toLower();
- String lowerRenderer = String((const char*)renderer).toLower();
-
- // The adapter is not available
- if (lowerRenderer.indexOf(lowerAdapter) == Index(-1))
- {
- return SLANG_E_NOT_AVAILABLE;
- }
+ return SLANG_E_INVALID_ARG;
}
if (m_desc.nvapiExtnSlot >= 0)
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);
diff --git a/tools/render-test/options.cpp b/tools/render-test/options.cpp
index a4a643e22..ef15346c6 100644
--- a/tools/render-test/options.cpp
+++ b/tools/render-test/options.cpp
@@ -153,10 +153,6 @@ static gfx::DeviceType _toRenderType(Slang::RenderApiType apiType)
{
outOptions.performanceProfile = true;
}
- else if (argValue == "-adapter")
- {
- SLANG_RETURN_ON_FAIL(reader.expectArg(outOptions.adapter));
- }
else if (argValue == "-output-using-type")
{
outOptions.outputUsingType = true;
diff --git a/tools/render-test/options.h b/tools/render-test/options.h
index f41614360..22b14c862 100644
--- a/tools/render-test/options.h
+++ b/tools/render-test/options.h
@@ -65,8 +65,6 @@ struct Options
Slang::List<Slang::String> renderFeatures; /// Required render features for this test to run
- Slang::String adapter; ///< The adapter to use either name or index
-
uint32_t computeDispatchSize[3] = { 1, 1, 1 };
Slang::String nvapiExtnSlot; ///< The nvapiRegister to use.
diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp
index 16b47a001..805f08d10 100644
--- a/tools/render-test/render-test-main.cpp
+++ b/tools/render-test/render-test-main.cpp
@@ -1266,10 +1266,6 @@ static SlangResult _innerMain(Slang::StdWriters* stdWriters, SlangSession* sessi
StringBuilder rendererName;
auto info =
rendererName << "[" << gfxGetDeviceTypeName(options.deviceType) << "] ";
- if (options.adapter.getLength())
- {
- rendererName << "'" << options.adapter << "'";
- }
if (options.onlyStartup)
{
@@ -1318,7 +1314,6 @@ static SlangResult _innerMain(Slang::StdWriters* stdWriters, SlangSession* sessi
{
IDevice::Desc desc = {};
desc.deviceType = options.deviceType;
- desc.adapter = options.adapter.getBuffer();
desc.slang.lineDirectiveMode = SLANG_LINE_DIRECTIVE_MODE_NONE;
if (options.generateSPIRVDirectly)