[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:
parent
9d66c5353f
commit
5a1d39ad0b
|
@ -70,6 +70,18 @@ namespace dawn_native { namespace d3d12 {
|
|||
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
|
||||
|
||||
Backend::Backend(InstanceBase* instance)
|
||||
|
@ -127,23 +139,34 @@ namespace dawn_native { namespace d3d12 {
|
|||
}
|
||||
|
||||
ASSERT(dxgiAdapter != nullptr);
|
||||
|
||||
ComPtr<IDXGIAdapter3> dxgiAdapter3;
|
||||
HRESULT result = dxgiAdapter.As(&dxgiAdapter3);
|
||||
ASSERT(SUCCEEDED(result));
|
||||
|
||||
std::unique_ptr<Adapter> adapter =
|
||||
std::make_unique<Adapter>(this, std::move(dxgiAdapter3));
|
||||
if (GetInstance()->ConsumedError(adapter->Initialize())) {
|
||||
ResultOrError<std::unique_ptr<AdapterBase>> adapter =
|
||||
CreateAdapterFromIDXGIAdapter(this, dxgiAdapter);
|
||||
if (adapter.IsError()) {
|
||||
adapter.AcquireError();
|
||||
continue;
|
||||
}
|
||||
|
||||
adapters.push_back(std::move(adapter));
|
||||
adapters.push_back(std::move(adapter.AcquireSuccess()));
|
||||
}
|
||||
|
||||
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) {
|
||||
Backend* backend = new Backend(instance);
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ namespace dawn_native { namespace d3d12 {
|
|||
const PlatformFunctions* GetFunctions() const;
|
||||
|
||||
std::vector<std::unique_ptr<AdapterBase>> DiscoverDefaultAdapters() override;
|
||||
ResultOrError<std::vector<std::unique_ptr<AdapterBase>>> DiscoverAdapters(
|
||||
const AdapterDiscoveryOptionsBase* optionsBase) override;
|
||||
|
||||
private:
|
||||
// Keep mFunctions as the first member so that in the destructor it is freed last. Otherwise
|
||||
|
|
|
@ -69,4 +69,7 @@ namespace dawn_native { namespace d3d12 {
|
|||
return reinterpret_cast<WGPUTexture>(texture.Detach());
|
||||
}
|
||||
|
||||
AdapterDiscoveryOptions::AdapterDiscoveryOptions(ComPtr<IDXGIAdapter> adapter)
|
||||
: AdapterDiscoveryOptionsBase(WGPUBackendType_D3D12), dxgiAdapter(std::move(adapter)) {
|
||||
}
|
||||
}} // namespace dawn_native::d3d12
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <dawn/dawn_wsi.h>
|
||||
#include <dawn_native/DawnNative.h>
|
||||
|
||||
#include <DXGI1_4.h>
|
||||
#include <windows.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
|
@ -52,6 +53,12 @@ namespace dawn_native { namespace d3d12 {
|
|||
DAWN_NATIVE_EXPORT WGPUTexture
|
||||
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
|
||||
|
||||
#endif // DAWNNATIVE_D3D12BACKEND_H_
|
||||
|
|
Loading…
Reference in New Issue