• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 
9 #ifndef GrD3DRenderTarget_DEFINED
10 #define GrD3DRenderTarget_DEFINED
11 
12 #include "src/gpu/GrRenderTarget.h"
13 #include "src/gpu/d3d/GrD3DTextureResource.h"
14 
15 #include "include/gpu/d3d/GrD3DTypes.h"
16 #include "src/gpu/GrGpu.h"
17 #include "src/gpu/d3d/GrD3DDescriptorHeap.h"
18 #include "src/gpu/d3d/GrD3DResourceProvider.h"
19 
20 class GrD3DGpu;
21 class GrD3DRenderTarget;
22 
23 struct GrD3DTextureResourceInfo;
24 
25 class GrD3DRenderTarget: public GrRenderTarget, public virtual GrD3DTextureResource {
26 public:
27     static sk_sp<GrD3DRenderTarget> MakeWrappedRenderTarget(GrD3DGpu*, SkISize, int sampleCnt,
28                                                             const GrD3DTextureResourceInfo&,
29                                                             sk_sp<GrD3DResourceState>);
30     ~GrD3DRenderTarget() override;
31 
backendFormat()32     GrBackendFormat backendFormat() const override { return this->getBackendFormat(); }
33 
34     /**
35      * If this render target is multisampled, this returns the MSAA texture for rendering. This
36      * will be different than *this* when we have separate render/resolve images. If not
37      * multisampled returns nullptr.
38      */
39     const GrD3DTextureResource* msaaTextureResource() const;
40     GrD3DTextureResource* msaaTextureResource();
41 
canAttemptStencilAttachment(bool useMSAASurface)42     bool canAttemptStencilAttachment(bool useMSAASurface) const override {
43         SkASSERT(useMSAASurface == (this->numSamples() > 1));
44         return true;
45     }
46 
47     GrBackendRenderTarget getBackendRenderTarget() const override;
48 
colorRenderTargetView()49     D3D12_CPU_DESCRIPTOR_HANDLE colorRenderTargetView() const {
50         return fColorRenderTargetView.fHandle;
51     }
52 
53     DXGI_FORMAT stencilDxgiFormat() const;
54 
55     // Key used for the program desc
56     void genKey(GrProcessorKeyBuilder* b) const;
57 
58 protected:
59     GrD3DRenderTarget(GrD3DGpu* gpu,
60                       SkISize dimensions,
61                       const GrD3DTextureResourceInfo& info,
62                       sk_sp<GrD3DResourceState> state,
63                       const GrD3DTextureResourceInfo& msaaInfo,
64                       sk_sp<GrD3DResourceState> msaaState,
65                       const GrD3DDescriptorHeap::CPUHandle& colorRenderTargetView,
66                       const GrD3DDescriptorHeap::CPUHandle& resolveRenderTargetView);
67 
68     GrD3DRenderTarget(GrD3DGpu* gpu,
69                       SkISize dimensions,
70                       const GrD3DTextureResourceInfo& info,
71                       sk_sp<GrD3DResourceState> state,
72                       const GrD3DDescriptorHeap::CPUHandle& renderTargetView);
73 
74     void onAbandon() override;
75     void onRelease() override;
76 
77     // This accounts for the texture's memory and any MSAA renderbuffer's memory.
onGpuMemorySize()78     size_t onGpuMemorySize() const override {
79         int numColorSamples = this->numSamples();
80         if (numColorSamples > 1) {
81             // Add one to account for the resolved VkImage.
82             numColorSamples += 1;
83         }
84         return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(),
85                                       numColorSamples, GrMipmapped::kNo);
86     }
87 
88 private:
89     // Extra param to disambiguate from constructor used by subclasses.
90     enum Wrapped { kWrapped };
91     GrD3DRenderTarget(GrD3DGpu* gpu,
92                       SkISize dimensions,
93                       const GrD3DTextureResourceInfo& info,
94                       sk_sp<GrD3DResourceState> state,
95                       const GrD3DTextureResourceInfo& msaaInfo,
96                       sk_sp<GrD3DResourceState> msaaState,
97                       const GrD3DDescriptorHeap::CPUHandle& colorRenderTargetView,
98                       const GrD3DDescriptorHeap::CPUHandle& resolveRenderTargetView,
99                       Wrapped);
100 
101     GrD3DRenderTarget(GrD3DGpu* gpu,
102                       SkISize dimensions,
103                       const GrD3DTextureResourceInfo& info,
104                       sk_sp<GrD3DResourceState> state,
105                       const GrD3DDescriptorHeap::CPUHandle& renderTargetView,
106                       Wrapped);
107 
108     GrD3DGpu* getD3DGpu() const;
109 
completeStencilAttachment(GrAttachment * stencil,bool useMSAASurface)110     bool completeStencilAttachment(GrAttachment* stencil, bool useMSAASurface) override {
111         SkASSERT(useMSAASurface == (this->numSamples() > 1));
112         return true;
113     }
114 
115     // In Direct3D we call the release proc after we are finished with the underlying
116     // GrD3DTextureResource::Resource object (which occurs after the GPU finishes all work on it).
onSetRelease(sk_sp<GrRefCntedCallback> releaseHelper)117     void onSetRelease(sk_sp<GrRefCntedCallback> releaseHelper) override {
118         // Forward the release proc on to GrD3DTextureResource
119         this->setResourceRelease(std::move(releaseHelper));
120     }
121 
122     void releaseInternalObjects();
123 
124     std::unique_ptr<GrD3DTextureResource> fMSAATextureResource;
125 
126     GrD3DDescriptorHeap::CPUHandle fColorRenderTargetView;
127     GrD3DDescriptorHeap::CPUHandle fResolveRenderTargetView;
128 };
129 
130 #endif
131