diff --git a/Common/Include/AdapterOption.h b/Common/Include/AdapterOption.h new file mode 100644 index 0000000..7bab32a --- /dev/null +++ b/Common/Include/AdapterOption.h @@ -0,0 +1,72 @@ +#pragma once + +// Anonymous namespace for usings +namespace +{ + using namespace std; + using namespace Microsoft::IndirectDisp; + using namespace Microsoft::WRL; + + struct AdapterOption + { + bool hasTargetAdapter{}; + LUID adapterLuid{}; + + void load(const char* path) + { + ifstream ifs{ path }; + + if (!ifs.is_open()) + { + return; + } + + std::string line; + getline(ifs, line); + + std::wstring target_name{ line.begin(), line.end() }; + + ComPtr factory{}; + if (!SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) + { + return; + } + + for (UINT i = 0;; i++) + { + ComPtr adapter{}; + if (!SUCCEEDED(factory->EnumAdapters(i, &adapter))) + { + break; + } + + DXGI_ADAPTER_DESC desc; + if (!SUCCEEDED(adapter->GetDesc(&desc))) + { + break; + } + + // We found our target + if (_wcsicmp(target_name.c_str(), desc.Description) == 0) + { + adapterLuid = desc.AdapterLuid; + hasTargetAdapter = true; + } + } + } + + void apply(const IDDCX_ADAPTER& adapter) + { + if (hasTargetAdapter) + { + if (IDD_IS_FUNCTION_AVAILABLE(IddCxAdapterSetRenderAdapter)) + { + IDARG_IN_ADAPTERSETRENDERADAPTER arg{}; + arg.PreferredRenderAdapter = adapterLuid; + + IddCxAdapterSetRenderAdapter(adapter, &arg); + } + } + } + }; +} \ No newline at end of file diff --git a/Virtual Display Driver (HDR)/IddSampleDriver/Driver.cpp b/Virtual Display Driver (HDR)/IddSampleDriver/Driver.cpp index af53529..7b08baa 100644 --- a/Virtual Display Driver (HDR)/IddSampleDriver/Driver.cpp +++ b/Virtual Display Driver (HDR)/IddSampleDriver/Driver.cpp @@ -22,6 +22,7 @@ Environment: #include #include #include +#include using namespace std; using namespace Microsoft::IndirectDisp; @@ -50,6 +51,10 @@ EVT_IDD_CX_ADAPTER_COMMIT_MODES2 IddSampleEvtIddCxAdapterCommitModes2; EVT_IDD_CX_MONITOR_SET_GAMMA_RAMP IddSampleEvtIddCxMonitorSetGammaRamp; +struct +{ + AdapterOption Adapter; +} Options; vector> monitorModes; vector< DISPLAYCONFIG_VIDEO_SIGNAL_INFO> s_KnownMonitorModes2; UINT numVirtualDisplays; @@ -150,6 +155,8 @@ NTSTATUS IddSampleDeviceAdd(WDFDRIVER Driver, PWDFDEVICE_INIT pDeviceInit) // redirects IoDeviceControl requests to an internal queue. This sample does not need this. // IddConfig.EvtIddCxDeviceIoControl = IddSampleIoDeviceControl; loadOptions("C:\\IddSampleDriver\\option.txt"); + Options.Adapter.load("C:\\IddSampleDriver\\adapter.txt"); + IddConfig.EvtIddCxAdapterInitFinished = IddSampleAdapterInitFinished; IddConfig.EvtIddCxMonitorGetDefaultDescriptionModes = IddSampleMonitorGetDefaultModes; @@ -245,6 +252,19 @@ HRESULT Direct3DDevice::Init() return hr; } +#if 0 // Test code + { + FILE* file; + fopen_s(&file, "C:\\IddSampleDriver\\desc_hdr.bin", "wb"); + + DXGI_ADAPTER_DESC desc; + Adapter->GetDesc(&desc); + + fwrite(&desc, 1, sizeof(desc), file); + fclose(file); + } +#endif + // Create a D3D device using the render adapter. BGRA support is required by the WHQL test suite. hr = D3D11CreateDevice(Adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr, D3D11_CREATE_DEVICE_BGRA_SUPPORT, nullptr, 0, D3D11_SDK_VERSION, &Device, nullptr, &DeviceContext); if (FAILED(hr)) @@ -536,6 +556,7 @@ void IndirectDeviceContext::InitAdapter() void IndirectDeviceContext::FinishInit() { + Options.Adapter.apply(m_Adapter); for (unsigned int i = 0; i < numVirtualDisplays; i++) { CreateMonitor(i); } diff --git a/Virtual Display Driver (HDR)/IddSampleDriver/IddSampleDriver.vcxproj b/Virtual Display Driver (HDR)/IddSampleDriver/IddSampleDriver.vcxproj index 212bd88..6a16818 100644 --- a/Virtual Display Driver (HDR)/IddSampleDriver/IddSampleDriver.vcxproj +++ b/Virtual Display Driver (HDR)/IddSampleDriver/IddSampleDriver.vcxproj @@ -214,6 +214,7 @@ trace.h Async true + $(ProjectDir)..\..\Common\Include;%(AdditionalIncludeDirectories) %(AdditionalDependencies);OneCoreUAP.lib;avrt.lib @@ -226,6 +227,7 @@ trace.h Async true + $(ProjectDir)..\..\Common\Include;%(AdditionalIncludeDirectories) %(AdditionalDependencies);OneCoreUAP.lib;avrt.lib @@ -239,6 +241,7 @@ Async true /D_ATL_NO_WIN_SUPPORT /DUMDF_DRIVER /DIDDCX_VERSION_MAJOR=1 /DIDDCX_VERSION_MINOR=4 /DIDDCX_MINIMUM_VERSION_REQUIRED=4 %(AdditionalOptions) + $(ProjectDir)..\..\Common\Include;%(AdditionalIncludeDirectories) %(AdditionalDependencies);OneCoreUAP.lib;avrt.lib @@ -255,6 +258,7 @@ Async true /D_ATL_NO_WIN_SUPPORT /DUMDF_DRIVER /DIDDCX_VERSION_MAJOR=1 /DIDDCX_VERSION_MINOR=10 /DIDDCX_MINIMUM_VERSION_REQUIRED=3 %(AdditionalOptions) + $(ProjectDir)..\..\Common\Include;%(AdditionalIncludeDirectories) %(AdditionalDependencies);OneCoreUAP.lib;avrt.lib diff --git a/Virtual Display Driver (Non-HDR)/IddSampleDriver/Driver.cpp b/Virtual Display Driver (Non-HDR)/IddSampleDriver/Driver.cpp index 234d2a0..e23d5a6 100644 --- a/Virtual Display Driver (Non-HDR)/IddSampleDriver/Driver.cpp +++ b/Virtual Display Driver (Non-HDR)/IddSampleDriver/Driver.cpp @@ -22,6 +22,7 @@ Environment: #include #include #include +#include using namespace std; using namespace Microsoft::IndirectDisp; @@ -42,6 +43,10 @@ EVT_IDD_CX_MONITOR_QUERY_TARGET_MODES IddSampleMonitorQueryModes; EVT_IDD_CX_MONITOR_ASSIGN_SWAPCHAIN IddSampleMonitorAssignSwapChain; EVT_IDD_CX_MONITOR_UNASSIGN_SWAPCHAIN IddSampleMonitorUnassignSwapChain; +struct +{ + AdapterOption Adapter; +} Options; vector> monitorModes; vector< DISPLAYCONFIG_VIDEO_SIGNAL_INFO> s_KnownMonitorModes2; UINT numVirtualDisplays; @@ -122,6 +127,7 @@ void loadOptions(string filepath) { } monitorModes = res; return; } + _Use_decl_annotations_ NTSTATUS IddSampleDeviceAdd(WDFDRIVER Driver, PWDFDEVICE_INIT pDeviceInit) { @@ -141,7 +147,9 @@ NTSTATUS IddSampleDeviceAdd(WDFDRIVER Driver, PWDFDEVICE_INIT pDeviceInit) // If the driver wishes to handle custom IoDeviceControl requests, it's necessary to use this callback since IddCx // redirects IoDeviceControl requests to an internal queue. This sample does not need this. // IddConfig.EvtIddCxDeviceIoControl = IddSampleIoDeviceControl; + loadOptions("C:\\IddSampleDriver\\option.txt"); + Options.Adapter.load("C:\\IddSampleDriver\\adapter.txt"); IddConfig.EvtIddCxAdapterInitFinished = IddSampleAdapterInitFinished; IddConfig.EvtIddCxParseMonitorDescription = IddSampleParseMonitorDescription; @@ -227,6 +235,19 @@ HRESULT Direct3DDevice::Init() return hr; } +#if 0 // Test code + { + FILE* file; + fopen_s(&file, "C:\\IddSampleDriver\\desc.bin", "wb"); + + DXGI_ADAPTER_DESC desc; + Adapter->GetDesc(&desc); + + fwrite(&desc, 1, sizeof(desc), file); + fclose(file); + } +#endif + // Create a D3D device using the render adapter. BGRA support is required by the WHQL test suite. hr = D3D11CreateDevice(Adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr, D3D11_CREATE_DEVICE_BGRA_SUPPORT, nullptr, 0, D3D11_SDK_VERSION, &Device, nullptr, &DeviceContext); if (FAILED(hr)) @@ -488,6 +509,7 @@ void IndirectDeviceContext::InitAdapter() void IndirectDeviceContext::FinishInit() { + Options.Adapter.apply(m_Adapter); for (unsigned int i = 0; i < numVirtualDisplays; i++) { CreateMonitor(i); } diff --git a/Virtual Display Driver (Non-HDR)/IddSampleDriver/IddSampleDriver.vcxproj b/Virtual Display Driver (Non-HDR)/IddSampleDriver/IddSampleDriver.vcxproj index c65bc19..8fcc239 100644 --- a/Virtual Display Driver (Non-HDR)/IddSampleDriver/IddSampleDriver.vcxproj +++ b/Virtual Display Driver (Non-HDR)/IddSampleDriver/IddSampleDriver.vcxproj @@ -52,6 +52,7 @@ Debug Win32 IddSampleDriver + 10.0.26100.0 WindowsUserModeDriver10.0 @@ -101,6 +102,7 @@ true 1 0 + 27 Windows10 @@ -109,6 +111,7 @@ true 1 0 + 27 Windows10 @@ -116,8 +119,10 @@ 2 true 1 - 0 + 4 Spectre + 31 + 27 Windows10 @@ -125,7 +130,9 @@ 2 true 1 - 0 + 4 + 31 + 27 Windows10 @@ -207,6 +214,7 @@ trace.h Async true + $(ProjectDir)..\..\Common\Include;%(AdditionalIncludeDirectories) %(AdditionalDependencies);OneCoreUAP.lib;avrt.lib @@ -219,6 +227,7 @@ trace.h Async true + $(ProjectDir)..\..\Common\Include;%(AdditionalIncludeDirectories) %(AdditionalDependencies);OneCoreUAP.lib;avrt.lib @@ -231,6 +240,8 @@ trace.h Async true + stdcpp17 + $(ProjectDir)..\..\Common\Include;%(AdditionalIncludeDirectories) %(AdditionalDependencies);OneCoreUAP.lib;avrt.lib @@ -243,6 +254,9 @@ trace.h Async true + stdcpp17 + $(ProjectDir)..\..\Common\Include;%(AdditionalIncludeDirectories) + IDDCX_VERSION_MAJOR=1;IDDCX_VERSION_MINOR=4;%(PreprocessorDefinitions) %(AdditionalDependencies);OneCoreUAP.lib;avrt.lib