• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_D3D12_SWAPCHAIND3D12_H_
16 #define DAWNNATIVE_D3D12_SWAPCHAIND3D12_H_
17 
18 #include "dawn_native/SwapChain.h"
19 
20 #include "dawn_native/IntegerTypes.h"
21 #include "dawn_native/d3d12/d3d12_platform.h"
22 
23 namespace dawn_native { namespace d3d12 {
24 
25     class Device;
26     class Texture;
27 
28     class OldSwapChain final : public OldSwapChainBase {
29       public:
30         static Ref<OldSwapChain> Create(Device* device, const SwapChainDescriptor* descriptor);
31 
32       protected:
33         OldSwapChain(Device* device, const SwapChainDescriptor* descriptor);
34         ~OldSwapChain() override;
35         TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
36         MaybeError OnBeforePresent(TextureViewBase* view) override;
37 
38         wgpu::TextureUsage mTextureUsage;
39     };
40 
41     class SwapChain final : public NewSwapChainBase {
42       public:
43         static ResultOrError<Ref<SwapChain>> Create(Device* device,
44                                                 Surface* surface,
45                                                 NewSwapChainBase* previousSwapChain,
46                                                 const SwapChainDescriptor* descriptor);
47 
48       private:
49         ~SwapChain() override;
50 
51         void DestroyImpl() override;
52 
53         using NewSwapChainBase::NewSwapChainBase;
54         MaybeError Initialize(NewSwapChainBase* previousSwapChain);
55 
56         struct Config {
57             // Information that's passed to the D3D12 swapchain creation call.
58             UINT bufferCount;
59             UINT swapChainFlags;
60             DXGI_FORMAT format;
61             DXGI_USAGE usage;
62         };
63 
64         // NewSwapChainBase implementation
65         MaybeError PresentImpl() override;
66         ResultOrError<TextureViewBase*> GetCurrentTextureViewImpl() override;
67         void DetachFromSurfaceImpl() override;
68 
69         // Does the swapchain initialization steps assuming there is nothing we can reuse.
70         MaybeError InitializeSwapChainFromScratch();
71         // Does the swapchain initialization step of gathering the buffers.
72         MaybeError CollectSwapChainBuffers();
73         // Calls DetachFromSurface but also synchronously waits until all references to the
74         // swapchain and buffers are removed, as that's a constraint for some DXGI operations.
75         MaybeError DetachAndWaitForDeallocation();
76 
77         Config mConfig;
78 
79         ComPtr<IDXGISwapChain3> mDXGISwapChain;
80         std::vector<ComPtr<ID3D12Resource>> mBuffers;
81         std::vector<ExecutionSerial> mBufferLastUsedSerials;
82         uint32_t mCurrentBuffer = 0;
83 
84         Ref<Texture> mApiTexture;
85     };
86 
87 }}  // namespace dawn_native::d3d12
88 
89 #endif  // DAWNNATIVE_D3D12_SWAPCHAIN_D3D12_H_
90