blob: f9588e4d4fc2a6fca40812044748422080b628be [file] [log] [blame]
Corentin Wallez196ade62018-07-25 13:37:28 +02001// Copyright 2018 The Dawn Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef DAWNNATIVE_D3D12BACKEND_H_
16#define DAWNNATIVE_D3D12BACKEND_H_
17
Corentin Wallez196ade62018-07-25 13:37:28 +020018#include <dawn/dawn_wsi.h>
Corentin Wallezd77fd5f2019-01-30 16:07:48 +000019#include <dawn_native/DawnNative.h>
Corentin Wallez196ade62018-07-25 13:37:28 +020020
Natasha Lee5a1d39a2020-07-15 18:26:17 +000021#include <DXGI1_4.h>
Bryan Bernhart9c3aefa2021-02-26 22:44:48 +000022#include <d3d12.h>
Corentin Wallez196ade62018-07-25 13:37:28 +020023#include <windows.h>
Rafael Cintron179d7b22019-09-02 19:19:34 +000024#include <wrl/client.h>
25
Bryan Bernhart9c3aefa2021-02-26 22:44:48 +000026#include <memory>
27
Rafael Cintron179d7b22019-09-02 19:19:34 +000028struct ID3D12Device;
Bryan Bernhart9c3aefa2021-02-26 22:44:48 +000029struct ID3D12Resource;
Corentin Wallez196ade62018-07-25 13:37:28 +020030
31namespace dawn_native { namespace d3d12 {
Bryan Bernhart31f03932021-08-12 23:32:49 +000032
33 class D3D11on12ResourceCache;
34
Corentin Wallez9f90c8d2019-10-24 23:55:37 +000035 DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D12Device> GetD3D12Device(WGPUDevice device);
36 DAWN_NATIVE_EXPORT DawnSwapChainImplementation CreateNativeSwapChainImpl(WGPUDevice device,
Corentin Wallez196ade62018-07-25 13:37:28 +020037 HWND window);
Corentin Wallez9f90c8d2019-10-24 23:55:37 +000038 DAWN_NATIVE_EXPORT WGPUTextureFormat
Austin Eng45f97302019-03-11 16:52:42 +000039 GetNativeSwapChainPreferredFormat(const DawnSwapChainImplementation* swapChain);
Rafael Cintron179d7b22019-09-02 19:19:34 +000040
Brandon Jonesf56f1902020-04-22 21:57:00 +000041 enum MemorySegment {
42 Local,
43 NonLocal,
44 };
45
46 DAWN_NATIVE_EXPORT uint64_t SetExternalMemoryReservation(WGPUDevice device,
47 uint64_t requestedReservationSize,
48 MemorySegment memorySegment);
49
Natasha Lee6f92b9162020-03-02 22:27:46 +000050 struct DAWN_NATIVE_EXPORT ExternalImageDescriptorDXGISharedHandle : ExternalImageDescriptor {
51 public:
52 ExternalImageDescriptorDXGISharedHandle();
53
Bryan Bernhart1a232442021-03-25 21:31:34 +000054 // Note: SharedHandle must be a handle to a texture object.
Natasha Lee6f92b9162020-03-02 22:27:46 +000055 HANDLE sharedHandle;
Natasha Lee6f92b9162020-03-02 22:27:46 +000056 };
57
Bryan Bernhart9c3aefa2021-02-26 22:44:48 +000058 struct DAWN_NATIVE_EXPORT ExternalImageAccessDescriptorDXGIKeyedMutex
59 : ExternalImageAccessDescriptor {
60 public:
61 uint64_t acquireMutexKey;
Corentin Wallez0f3c35c2021-07-19 14:44:06 +000062 uint64_t releaseMutexKey;
Bryan Bernhart9c3aefa2021-02-26 22:44:48 +000063 bool isSwapChainTexture = false;
64 };
65
66 class DAWN_NATIVE_EXPORT ExternalImageDXGI {
67 public:
Bryan Bernhart31f03932021-08-12 23:32:49 +000068 ~ExternalImageDXGI();
69
Bryan Bernhart9c3aefa2021-02-26 22:44:48 +000070 // Note: SharedHandle must be a handle to a texture object.
71 static std::unique_ptr<ExternalImageDXGI> Create(
72 WGPUDevice device,
73 const ExternalImageDescriptorDXGISharedHandle* descriptor);
74
75 WGPUTexture ProduceTexture(WGPUDevice device,
76 const ExternalImageAccessDescriptorDXGIKeyedMutex* descriptor);
77
78 private:
79 ExternalImageDXGI(Microsoft::WRL::ComPtr<ID3D12Resource> d3d12Resource,
80 const WGPUTextureDescriptor* descriptor);
81
82 Microsoft::WRL::ComPtr<ID3D12Resource> mD3D12Resource;
83
84 // Contents of WGPUTextureDescriptor are stored individually since the descriptor
85 // could outlive this image.
86 WGPUTextureUsageFlags mUsage;
Juanmi633bb682021-08-12 20:17:39 +000087 WGPUTextureUsageFlags mUsageInternal = WGPUTextureUsage_None;
Bryan Bernhart9c3aefa2021-02-26 22:44:48 +000088 WGPUTextureDimension mDimension;
89 WGPUExtent3D mSize;
90 WGPUTextureFormat mFormat;
91 uint32_t mMipLevelCount;
92 uint32_t mSampleCount;
Bryan Bernhart31f03932021-08-12 23:32:49 +000093
94 std::unique_ptr<D3D11on12ResourceCache> mD3D11on12ResourceCache;
Bryan Bernhart9c3aefa2021-02-26 22:44:48 +000095 };
96
Natasha Lee5a1d39a2020-07-15 18:26:17 +000097 struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
98 AdapterDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
99
100 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter;
101 };
102
Corentin Wallez196ade62018-07-25 13:37:28 +0200103}} // namespace dawn_native::d3d12
104
105#endif // DAWNNATIVE_D3D12BACKEND_H_