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 18 #include <dawn/dawn_wsi.h> 19 #include <dawn_native/DawnNative.h> 20 21 #include <DXGI1_4.h> 22 #include <d3d12.h> 23 #include <windows.h> 24 #include <wrl/client.h> 25 26 #include <memory> 27 28 struct ID3D12Device; 29 struct ID3D12Resource; 30 31 namespace dawn_native { namespace d3d12 { 32 33 class D3D11on12ResourceCache; 34 35 DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D12Device> GetD3D12Device(WGPUDevice device); 36 DAWN_NATIVE_EXPORT DawnSwapChainImplementation CreateNativeSwapChainImpl(WGPUDevice device, 37 HWND window); 38 DAWN_NATIVE_EXPORT WGPUTextureFormat 39 GetNativeSwapChainPreferredFormat(const DawnSwapChainImplementation* swapChain); 40 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 50 struct DAWN_NATIVE_EXPORT ExternalImageDescriptorDXGISharedHandle : ExternalImageDescriptor { 51 public: 52 ExternalImageDescriptorDXGISharedHandle(); 53 54 // Note: SharedHandle must be a handle to a texture object. 55 HANDLE sharedHandle; 56 }; 57 58 struct DAWN_NATIVE_EXPORT ExternalImageAccessDescriptorDXGIKeyedMutex 59 : ExternalImageAccessDescriptor { 60 public: 61 uint64_t acquireMutexKey; 62 uint64_t releaseMutexKey; 63 bool isSwapChainTexture = false; 64 }; 65 66 class DAWN_NATIVE_EXPORT ExternalImageDXGI { 67 public: 68 ~ExternalImageDXGI(); 69 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; 87 WGPUTextureUsageFlags mUsageInternal = WGPUTextureUsage_None; 88 WGPUTextureDimension mDimension; 89 WGPUExtent3D mSize; 90 WGPUTextureFormat mFormat; 91 uint32_t mMipLevelCount; 92 uint32_t mSampleCount; 93 94 std::unique_ptr<D3D11on12ResourceCache> mD3D11on12ResourceCache; 95 }; 96 97 struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase { 98 AdapterDiscoveryOptions(); 99 AdapterDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter); 100 101 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter; 102 }; 103 104 }} // namespace dawn_native::d3d12 105 106 #endif // DAWNNATIVE_D3D12BACKEND_H_ 107