From 2f4029a753f72833c30c4e6bad28c06b20540384 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 25 Mar 2019 11:48:10 -0400 Subject: Adapter selection for Renderer (#923) * * Make adapter used selectable on the command line * Added 'adapter' to Renderer::Desc with dx11, dx12, vk honoring it * GL will check that the renderer matches, but cannot select a specific device * Share functionality on dx adapter selection in D3DUtil Note - that on tests that use OpenGL and the adapter doesn't match it will ignore the test (and display a message that the appropriate device couldn't be started) * Small function name improvement. * Variable rename to match type. * Fix typo in Dx12 device selection. * * Add checking if an adapter is warp * Improve some comments --- tools/gfx/render-vk.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'tools/gfx/render-vk.cpp') diff --git a/tools/gfx/render-vk.cpp b/tools/gfx/render-vk.cpp index defc08355..30eff04c9 100644 --- a/tools/gfx/render-vk.cpp +++ b/tools/gfx/render-vk.cpp @@ -948,8 +948,35 @@ SlangResult VKRenderer::initialize(const Desc& desc, void* inWindowHandle) physicalDevices.SetSize(numPhysicalDevices); SLANG_VK_RETURN_ON_FAIL(m_api.vkEnumeratePhysicalDevices(instance, &numPhysicalDevices, physicalDevices.Buffer())); - // TODO: allow override of selected device - uint32_t selectedDeviceIndex = 0; + int32_t selectedDeviceIndex = 0; + + if (desc.adapter.Length()) + { + selectedDeviceIndex = -1; + + String lowerAdapter = desc.adapter.ToLower(); + + for (int i = 0; i < int(physicalDevices.Count()); ++i) + { + auto physicalDevice = physicalDevices[i]; + + VkPhysicalDeviceProperties basicProps = {}; + m_api.vkGetPhysicalDeviceProperties(physicalDevice, &basicProps); + + String lowerName = String(basicProps.deviceName).ToLower(); + + if (lowerName.IndexOf(lowerAdapter) != UInt(-1)) + { + selectedDeviceIndex = i; + break; + } + } + if (selectedDeviceIndex < 0) + { + // Device not found + return SLANG_FAIL; + } + } SLANG_RETURN_ON_FAIL(m_api.initPhysicalDevice(physicalDevices[selectedDeviceIndex])); @@ -2704,7 +2731,7 @@ Result VKRenderer::createGraphicsPipelineState(const GraphicsPipelineStateDesc& VkPipeline pipeline = VK_NULL_HANDLE; SLANG_VK_CHECK(m_api.vkCreateGraphicsPipelines(m_device, pipelineCache, 1, &pipelineInfo, nullptr, &pipeline)); - RefPtr pipelineStateImpl; + RefPtr pipelineStateImpl = new PipelineStateImpl(m_api); pipelineStateImpl->m_pipeline = pipeline; pipelineStateImpl->m_pipelineLayout = pipelineLayoutImpl; pipelineStateImpl->m_shaderProgram = programImpl; -- cgit v1.2.3