Expose the 11On12 device and Command Queue via backend
This change makes Dawn's D3D12 command queue and D3D11On12 device
available to Chromium via the D3D12Backend interface. The command queue
and device will be used to support D3D12 resource based Direct
Composition textures.
Change-Id: I9030b34aa0572130922de8c45fad8b8d936b9380
Bug: 425864542
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/268034
Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Sahir Vellani <sahir.vellani@microsoft.com>
diff --git a/include/dawn/native/D3D12Backend.h b/include/dawn/native/D3D12Backend.h
index 74b6556..b5ef2d6 100644
--- a/include/dawn/native/D3D12Backend.h
+++ b/include/dawn/native/D3D12Backend.h
@@ -28,6 +28,7 @@
#ifndef INCLUDE_DAWN_NATIVE_D3D12BACKEND_H_
#define INCLUDE_DAWN_NATIVE_D3D12BACKEND_H_
+#include <d3d11on12.h>
#include <d3d12.h>
#include <dxgi1_4.h>
#include <wrl/client.h>
@@ -48,6 +49,12 @@
DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D12Device> GetD3D12Device(WGPUDevice device);
+DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D11On12Device> GetOrCreateD3D11On12Device(
+ WGPUDevice device);
+
+DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D12CommandQueue> GetD3D12CommandQueue(
+ WGPUDevice device);
+
DAWN_NATIVE_EXPORT uint64_t SetExternalMemoryReservation(WGPUDevice device,
uint64_t requestedReservationSize,
MemorySegment memorySegment);
diff --git a/src/dawn/native/d3d12/D3D12Backend.cpp b/src/dawn/native/d3d12/D3D12Backend.cpp
index 66e25d1..7615ca9 100644
--- a/src/dawn/native/d3d12/D3D12Backend.cpp
+++ b/src/dawn/native/d3d12/D3D12Backend.cpp
@@ -41,6 +41,14 @@
namespace dawn::native::d3d12 {
+Microsoft::WRL::ComPtr<ID3D11On12Device> GetOrCreateD3D11On12Device(WGPUDevice device) {
+ return ToBackend(FromAPI(device))->GetOrCreateD3D11On12Device();
+}
+
+Microsoft::WRL::ComPtr<ID3D12CommandQueue> GetD3D12CommandQueue(WGPUDevice device) {
+ return ToBackend(FromAPI(device))->GetD3D12CommandQueue();
+}
+
Microsoft::WRL::ComPtr<ID3D12Device> GetD3D12Device(WGPUDevice device) {
return ToBackend(FromAPI(device))->GetD3D12Device();
}
diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp
index 1f0618e..7909de0 100644
--- a/src/dawn/native/d3d12/DeviceD3D12.cpp
+++ b/src/dawn/native/d3d12/DeviceD3D12.cpp
@@ -29,6 +29,7 @@
#include <algorithm>
#include <limits>
+#include <memory>
#include <sstream>
#include <utility>
@@ -217,7 +218,20 @@
return mD3d12Device.Get();
}
-ResultOrError<ComPtr<ID3D11On12Device>> Device::GetOrCreateD3D11on12Device() {
+ComPtr<ID3D11On12Device> Device::GetOrCreateD3D11On12Device() {
+ ComPtr<ID3D11On12Device> d3d11On12Device;
+ // Use std::addressof to avoid ComPtr's overloaded operator& returning ComPtrRef type.
+ if (ConsumedError(GetOrCreateD3D11On12DeviceInternal(), std::addressof(d3d11On12Device))) {
+ return nullptr;
+ }
+ return d3d11On12Device;
+}
+
+ComPtr<ID3D12CommandQueue> Device::GetD3D12CommandQueue() const {
+ return ToBackend(GetQueue())->GetCommandQueue();
+}
+
+ResultOrError<ComPtr<ID3D11On12Device>> Device::GetOrCreateD3D11On12DeviceInternal() {
if (mD3d11On12Device == nullptr) {
ComPtr<ID3D11Device> d3d11Device;
D3D_FEATURE_LEVEL d3dFeatureLevel;
@@ -604,7 +618,7 @@
if (useKeyedMutex) {
ComPtr<ID3D11On12Device> d3d11on12Device;
- DAWN_TRY_ASSIGN(d3d11on12Device, GetOrCreateD3D11on12Device());
+ DAWN_TRY_ASSIGN(d3d11on12Device, GetOrCreateD3D11On12DeviceInternal());
// Since D3D12 does not directly support keyed mutexes, we need to wrap the D3D12 resource
// using 11on12 and QueryInterface the D3D11 representation for the keyed mutex.
diff --git a/src/dawn/native/d3d12/DeviceD3D12.h b/src/dawn/native/d3d12/DeviceD3D12.h
index 01f86c7..ec7812e 100644
--- a/src/dawn/native/d3d12/DeviceD3D12.h
+++ b/src/dawn/native/d3d12/DeviceD3D12.h
@@ -72,6 +72,8 @@
MaybeError TickImpl() override;
ID3D12Device* GetD3D12Device() const;
+ ComPtr<ID3D11On12Device> GetOrCreateD3D11On12Device();
+ ComPtr<ID3D12CommandQueue> GetD3D12CommandQueue() const;
ComPtr<ID3D12CommandSignature> GetDispatchIndirectSignature() const;
ComPtr<ID3D12CommandSignature> GetDrawIndirectSignature() const;
@@ -221,7 +223,7 @@
void AppendDebugLayerMessages(ErrorData* error) override;
void AppendDeviceLostMessage(ErrorData* error) override;
- ResultOrError<ComPtr<ID3D11On12Device>> GetOrCreateD3D11on12Device();
+ ResultOrError<ComPtr<ID3D11On12Device>> GetOrCreateD3D11On12DeviceInternal();
void Flush11On12DeviceToAvoidLeaks();
MaybeError EnsureCompilerLibraries();