[D3D12] Add DXGIAdapter to AdapterDiscoveryOptions

This gives Chromium the option to give Dawn the correct dxgi adapter to use

Bug: chromium:1036711
Change-Id: Ica544d2e76d1c300038fa07b5b639a35c43f60b9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24761
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com>
Commit-Queue: Natasha Lee <natlee@microsoft.com>
This commit is contained in:
Natasha Lee 2020-07-15 18:26:17 +00:00 committed by Commit Bot service account
parent 9d66c5353f
commit 5a1d39ad0b
4 changed files with 44 additions and 9 deletions

View File

@ -70,6 +70,18 @@ namespace dawn_native { namespace d3d12 {
return std::move(factory); return std::move(factory);
} }
ResultOrError<std::unique_ptr<AdapterBase>> CreateAdapterFromIDXGIAdapter(
Backend* backend,
ComPtr<IDXGIAdapter> dxgiAdapter) {
ComPtr<IDXGIAdapter3> dxgiAdapter3;
DAWN_TRY(CheckHRESULT(dxgiAdapter.As(&dxgiAdapter3), "DXGIAdapter retrieval"));
std::unique_ptr<Adapter> adapter =
std::make_unique<Adapter>(backend, std::move(dxgiAdapter3));
DAWN_TRY(adapter->Initialize());
return {std::move(adapter)};
}
} // anonymous namespace } // anonymous namespace
Backend::Backend(InstanceBase* instance) Backend::Backend(InstanceBase* instance)
@ -127,23 +139,34 @@ namespace dawn_native { namespace d3d12 {
} }
ASSERT(dxgiAdapter != nullptr); ASSERT(dxgiAdapter != nullptr);
ResultOrError<std::unique_ptr<AdapterBase>> adapter =
ComPtr<IDXGIAdapter3> dxgiAdapter3; CreateAdapterFromIDXGIAdapter(this, dxgiAdapter);
HRESULT result = dxgiAdapter.As(&dxgiAdapter3); if (adapter.IsError()) {
ASSERT(SUCCEEDED(result)); adapter.AcquireError();
std::unique_ptr<Adapter> adapter =
std::make_unique<Adapter>(this, std::move(dxgiAdapter3));
if (GetInstance()->ConsumedError(adapter->Initialize())) {
continue; continue;
} }
adapters.push_back(std::move(adapter)); adapters.push_back(std::move(adapter.AcquireSuccess()));
} }
return adapters; return adapters;
} }
ResultOrError<std::vector<std::unique_ptr<AdapterBase>>> Backend::DiscoverAdapters(
const AdapterDiscoveryOptionsBase* optionsBase) {
ASSERT(optionsBase->backendType == WGPUBackendType_D3D12);
const AdapterDiscoveryOptions* options =
static_cast<const AdapterDiscoveryOptions*>(optionsBase);
ASSERT(options->dxgiAdapter != nullptr);
std::unique_ptr<AdapterBase> adapter;
DAWN_TRY_ASSIGN(adapter, CreateAdapterFromIDXGIAdapter(this, options->dxgiAdapter));
std::vector<std::unique_ptr<AdapterBase>> adapters;
adapters.push_back(std::move(adapter));
return std::move(adapters);
}
BackendConnection* Connect(InstanceBase* instance) { BackendConnection* Connect(InstanceBase* instance) {
Backend* backend = new Backend(instance); Backend* backend = new Backend(instance);

View File

@ -35,6 +35,8 @@ namespace dawn_native { namespace d3d12 {
const PlatformFunctions* GetFunctions() const; const PlatformFunctions* GetFunctions() const;
std::vector<std::unique_ptr<AdapterBase>> DiscoverDefaultAdapters() override; std::vector<std::unique_ptr<AdapterBase>> DiscoverDefaultAdapters() override;
ResultOrError<std::vector<std::unique_ptr<AdapterBase>>> DiscoverAdapters(
const AdapterDiscoveryOptionsBase* optionsBase) override;
private: private:
// Keep mFunctions as the first member so that in the destructor it is freed last. Otherwise // Keep mFunctions as the first member so that in the destructor it is freed last. Otherwise

View File

@ -69,4 +69,7 @@ namespace dawn_native { namespace d3d12 {
return reinterpret_cast<WGPUTexture>(texture.Detach()); return reinterpret_cast<WGPUTexture>(texture.Detach());
} }
AdapterDiscoveryOptions::AdapterDiscoveryOptions(ComPtr<IDXGIAdapter> adapter)
: AdapterDiscoveryOptionsBase(WGPUBackendType_D3D12), dxgiAdapter(std::move(adapter)) {
}
}} // namespace dawn_native::d3d12 }} // namespace dawn_native::d3d12

View File

@ -18,6 +18,7 @@
#include <dawn/dawn_wsi.h> #include <dawn/dawn_wsi.h>
#include <dawn_native/DawnNative.h> #include <dawn_native/DawnNative.h>
#include <DXGI1_4.h>
#include <windows.h> #include <windows.h>
#include <wrl/client.h> #include <wrl/client.h>
@ -52,6 +53,12 @@ namespace dawn_native { namespace d3d12 {
DAWN_NATIVE_EXPORT WGPUTexture DAWN_NATIVE_EXPORT WGPUTexture
WrapSharedHandle(WGPUDevice device, const ExternalImageDescriptorDXGISharedHandle* descriptor); WrapSharedHandle(WGPUDevice device, const ExternalImageDescriptorDXGISharedHandle* descriptor);
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
AdapterDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter;
};
}} // namespace dawn_native::d3d12 }} // namespace dawn_native::d3d12
#endif // DAWNNATIVE_D3D12BACKEND_H_ #endif // DAWNNATIVE_D3D12BACKEND_H_