diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/gfx/cuda/cuda-device.cpp | 25 | ||||
| -rw-r--r-- | tools/gfx/cuda/cuda-helper-functions.cpp | 40 | ||||
| -rw-r--r-- | tools/gfx/cuda/cuda-helper-functions.h | 2 | ||||
| -rw-r--r-- | tools/gfx/d3d/d3d-util.cpp | 31 | ||||
| -rw-r--r-- | tools/gfx/d3d/d3d-util.h | 8 | ||||
| -rw-r--r-- | tools/gfx/d3d11/d3d11-device.cpp | 10 | ||||
| -rw-r--r-- | tools/gfx/d3d11/d3d11-helper-functions.cpp | 4 | ||||
| -rw-r--r-- | tools/gfx/d3d12/d3d12-device.cpp | 8 | ||||
| -rw-r--r-- | tools/gfx/d3d12/d3d12-device.h | 2 | ||||
| -rw-r--r-- | tools/gfx/d3d12/d3d12-helper-functions.cpp | 4 | ||||
| -rw-r--r-- | tools/gfx/open-gl/render-gl.cpp | 13 | ||||
| -rw-r--r-- | tools/gfx/vulkan/vk-device.cpp | 31 | ||||
| -rw-r--r-- | tools/gfx/vulkan/vk-helper-functions.cpp | 98 | ||||
| -rw-r--r-- | tools/gfx/vulkan/vk-helper-functions.h | 2 | ||||
| -rw-r--r-- | tools/render-test/options.cpp | 4 | ||||
| -rw-r--r-- | tools/render-test/options.h | 2 | ||||
| -rw-r--r-- | tools/render-test/render-test-main.cpp | 5 |
17 files changed, 168 insertions, 121 deletions
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) |
