Corentin Wallez | 196ade6 | 2018-07-25 13:37:28 +0200 | [diff] [blame] | 1 | // 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 Wallez | 196ade6 | 2018-07-25 13:37:28 +0200 | [diff] [blame] | 18 | #include <dawn/dawn_wsi.h> |
Corentin Wallez | d77fd5f | 2019-01-30 16:07:48 +0000 | [diff] [blame] | 19 | #include <dawn_native/DawnNative.h> |
Corentin Wallez | 196ade6 | 2018-07-25 13:37:28 +0200 | [diff] [blame] | 20 | |
Natasha Lee | 5a1d39a | 2020-07-15 18:26:17 +0000 | [diff] [blame] | 21 | #include <DXGI1_4.h> |
Bryan Bernhart | 9c3aefa | 2021-02-26 22:44:48 +0000 | [diff] [blame] | 22 | #include <d3d12.h> |
Corentin Wallez | 196ade6 | 2018-07-25 13:37:28 +0200 | [diff] [blame] | 23 | #include <windows.h> |
Rafael Cintron | 179d7b2 | 2019-09-02 19:19:34 +0000 | [diff] [blame] | 24 | #include <wrl/client.h> |
| 25 | |
Bryan Bernhart | 9c3aefa | 2021-02-26 22:44:48 +0000 | [diff] [blame] | 26 | #include <memory> |
| 27 | |
Rafael Cintron | 179d7b2 | 2019-09-02 19:19:34 +0000 | [diff] [blame] | 28 | struct ID3D12Device; |
Bryan Bernhart | 9c3aefa | 2021-02-26 22:44:48 +0000 | [diff] [blame] | 29 | struct ID3D12Resource; |
Corentin Wallez | 196ade6 | 2018-07-25 13:37:28 +0200 | [diff] [blame] | 30 | |
| 31 | namespace dawn_native { namespace d3d12 { |
Bryan Bernhart | 31f0393 | 2021-08-12 23:32:49 +0000 | [diff] [blame] | 32 | |
| 33 | class D3D11on12ResourceCache; |
| 34 | |
Corentin Wallez | 9f90c8d | 2019-10-24 23:55:37 +0000 | [diff] [blame] | 35 | DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D12Device> GetD3D12Device(WGPUDevice device); |
| 36 | DAWN_NATIVE_EXPORT DawnSwapChainImplementation CreateNativeSwapChainImpl(WGPUDevice device, |
Corentin Wallez | 196ade6 | 2018-07-25 13:37:28 +0200 | [diff] [blame] | 37 | HWND window); |
Corentin Wallez | 9f90c8d | 2019-10-24 23:55:37 +0000 | [diff] [blame] | 38 | DAWN_NATIVE_EXPORT WGPUTextureFormat |
Austin Eng | 45f9730 | 2019-03-11 16:52:42 +0000 | [diff] [blame] | 39 | GetNativeSwapChainPreferredFormat(const DawnSwapChainImplementation* swapChain); |
Rafael Cintron | 179d7b2 | 2019-09-02 19:19:34 +0000 | [diff] [blame] | 40 | |
Brandon Jones | f56f190 | 2020-04-22 21:57:00 +0000 | [diff] [blame] | 41 | 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 Lee | 6f92b916 | 2020-03-02 22:27:46 +0000 | [diff] [blame] | 50 | struct DAWN_NATIVE_EXPORT ExternalImageDescriptorDXGISharedHandle : ExternalImageDescriptor { |
| 51 | public: |
| 52 | ExternalImageDescriptorDXGISharedHandle(); |
| 53 | |
Bryan Bernhart | 1a23244 | 2021-03-25 21:31:34 +0000 | [diff] [blame] | 54 | // Note: SharedHandle must be a handle to a texture object. |
Natasha Lee | 6f92b916 | 2020-03-02 22:27:46 +0000 | [diff] [blame] | 55 | HANDLE sharedHandle; |
Natasha Lee | 6f92b916 | 2020-03-02 22:27:46 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
Bryan Bernhart | 9c3aefa | 2021-02-26 22:44:48 +0000 | [diff] [blame] | 58 | struct DAWN_NATIVE_EXPORT ExternalImageAccessDescriptorDXGIKeyedMutex |
| 59 | : ExternalImageAccessDescriptor { |
| 60 | public: |
| 61 | uint64_t acquireMutexKey; |
Corentin Wallez | 0f3c35c | 2021-07-19 14:44:06 +0000 | [diff] [blame] | 62 | uint64_t releaseMutexKey; |
Bryan Bernhart | 9c3aefa | 2021-02-26 22:44:48 +0000 | [diff] [blame] | 63 | bool isSwapChainTexture = false; |
| 64 | }; |
| 65 | |
| 66 | class DAWN_NATIVE_EXPORT ExternalImageDXGI { |
| 67 | public: |
Bryan Bernhart | 31f0393 | 2021-08-12 23:32:49 +0000 | [diff] [blame] | 68 | ~ExternalImageDXGI(); |
| 69 | |
Bryan Bernhart | 9c3aefa | 2021-02-26 22:44:48 +0000 | [diff] [blame] | 70 | // 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; |
Juanmi | 633bb68 | 2021-08-12 20:17:39 +0000 | [diff] [blame] | 87 | WGPUTextureUsageFlags mUsageInternal = WGPUTextureUsage_None; |
Bryan Bernhart | 9c3aefa | 2021-02-26 22:44:48 +0000 | [diff] [blame] | 88 | WGPUTextureDimension mDimension; |
| 89 | WGPUExtent3D mSize; |
| 90 | WGPUTextureFormat mFormat; |
| 91 | uint32_t mMipLevelCount; |
| 92 | uint32_t mSampleCount; |
Bryan Bernhart | 31f0393 | 2021-08-12 23:32:49 +0000 | [diff] [blame] | 93 | |
| 94 | std::unique_ptr<D3D11on12ResourceCache> mD3D11on12ResourceCache; |
Bryan Bernhart | 9c3aefa | 2021-02-26 22:44:48 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
Natasha Lee | 5a1d39a | 2020-07-15 18:26:17 +0000 | [diff] [blame] | 97 | struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase { |
| 98 | AdapterDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter); |
| 99 | |
| 100 | Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter; |
| 101 | }; |
| 102 | |
Corentin Wallez | 196ade6 | 2018-07-25 13:37:28 +0200 | [diff] [blame] | 103 | }} // namespace dawn_native::d3d12 |
| 104 | |
| 105 | #endif // DAWNNATIVE_D3D12BACKEND_H_ |