Skip to content

Commit 9ec9e3b

Browse files
Sahir VellaniDawn LUCI CQ
authored andcommitted
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 <[email protected]> Reviewed-by: Geoff Lang <[email protected]> Commit-Queue: Sahir Vellani <[email protected]>
1 parent 7a8af73 commit 9ec9e3b

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

include/dawn/native/D3D12Backend.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#ifndef INCLUDE_DAWN_NATIVE_D3D12BACKEND_H_
2929
#define INCLUDE_DAWN_NATIVE_D3D12BACKEND_H_
3030

31+
#include <d3d11on12.h>
3132
#include <d3d12.h>
3233
#include <dxgi1_4.h>
3334
#include <wrl/client.h>
@@ -48,6 +49,12 @@ enum MemorySegment {
4849

4950
DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D12Device> GetD3D12Device(WGPUDevice device);
5051

52+
DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D11On12Device> GetOrCreateD3D11On12Device(
53+
WGPUDevice device);
54+
55+
DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D12CommandQueue> GetD3D12CommandQueue(
56+
WGPUDevice device);
57+
5158
DAWN_NATIVE_EXPORT uint64_t SetExternalMemoryReservation(WGPUDevice device,
5259
uint64_t requestedReservationSize,
5360
MemorySegment memorySegment);

src/dawn/native/d3d12/D3D12Backend.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141

4242
namespace dawn::native::d3d12 {
4343

44+
Microsoft::WRL::ComPtr<ID3D11On12Device> GetOrCreateD3D11On12Device(WGPUDevice device) {
45+
return ToBackend(FromAPI(device))->GetOrCreateD3D11On12Device();
46+
}
47+
48+
Microsoft::WRL::ComPtr<ID3D12CommandQueue> GetD3D12CommandQueue(WGPUDevice device) {
49+
return ToBackend(FromAPI(device))->GetD3D12CommandQueue();
50+
}
51+
4452
Microsoft::WRL::ComPtr<ID3D12Device> GetD3D12Device(WGPUDevice device) {
4553
return ToBackend(FromAPI(device))->GetD3D12Device();
4654
}

src/dawn/native/d3d12/DeviceD3D12.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <algorithm>
3131
#include <limits>
32+
#include <memory>
3233
#include <sstream>
3334
#include <utility>
3435

@@ -217,7 +218,20 @@ ID3D12Device* Device::GetD3D12Device() const {
217218
return mD3d12Device.Get();
218219
}
219220

220-
ResultOrError<ComPtr<ID3D11On12Device>> Device::GetOrCreateD3D11on12Device() {
221+
ComPtr<ID3D11On12Device> Device::GetOrCreateD3D11On12Device() {
222+
ComPtr<ID3D11On12Device> d3d11On12Device;
223+
// Use std::addressof to avoid ComPtr's overloaded operator& returning ComPtrRef type.
224+
if (ConsumedError(GetOrCreateD3D11On12DeviceInternal(), std::addressof(d3d11On12Device))) {
225+
return nullptr;
226+
}
227+
return d3d11On12Device;
228+
}
229+
230+
ComPtr<ID3D12CommandQueue> Device::GetD3D12CommandQueue() const {
231+
return ToBackend(GetQueue())->GetCommandQueue();
232+
}
233+
234+
ResultOrError<ComPtr<ID3D11On12Device>> Device::GetOrCreateD3D11On12DeviceInternal() {
221235
if (mD3d11On12Device == nullptr) {
222236
ComPtr<ID3D11Device> d3d11Device;
223237
D3D_FEATURE_LEVEL d3dFeatureLevel;
@@ -604,7 +618,7 @@ MaybeError Device::ImportSharedHandleResource(HANDLE handle,
604618

605619
if (useKeyedMutex) {
606620
ComPtr<ID3D11On12Device> d3d11on12Device;
607-
DAWN_TRY_ASSIGN(d3d11on12Device, GetOrCreateD3D11on12Device());
621+
DAWN_TRY_ASSIGN(d3d11on12Device, GetOrCreateD3D11On12DeviceInternal());
608622

609623
// Since D3D12 does not directly support keyed mutexes, we need to wrap the D3D12 resource
610624
// using 11on12 and QueryInterface the D3D11 representation for the keyed mutex.

src/dawn/native/d3d12/DeviceD3D12.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class Device final : public d3d::Device {
7272
MaybeError TickImpl() override;
7373

7474
ID3D12Device* GetD3D12Device() const;
75+
ComPtr<ID3D11On12Device> GetOrCreateD3D11On12Device();
76+
ComPtr<ID3D12CommandQueue> GetD3D12CommandQueue() const;
7577

7678
ComPtr<ID3D12CommandSignature> GetDispatchIndirectSignature() const;
7779
ComPtr<ID3D12CommandSignature> GetDrawIndirectSignature() const;
@@ -221,7 +223,7 @@ class Device final : public d3d::Device {
221223
void AppendDebugLayerMessages(ErrorData* error) override;
222224
void AppendDeviceLostMessage(ErrorData* error) override;
223225

224-
ResultOrError<ComPtr<ID3D11On12Device>> GetOrCreateD3D11on12Device();
226+
ResultOrError<ComPtr<ID3D11On12Device>> GetOrCreateD3D11On12DeviceInternal();
225227
void Flush11On12DeviceToAvoidLeaks();
226228

227229
MaybeError EnsureCompilerLibraries();

0 commit comments

Comments
 (0)