2 * Copyright 2020 Google LLC
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #ifndef GrD3DRenderTarget_DEFINED
10 #define GrD3DRenderTarget_DEFINED
12 #include "src/gpu/ganesh/GrRenderTarget.h"
13 #include "src/gpu/ganesh/d3d/GrD3DTextureResource.h"
15 #include "include/gpu/d3d/GrD3DTypes.h"
16 #include "src/gpu/ganesh/GrGpu.h"
17 #include "src/gpu/ganesh/d3d/GrD3DDescriptorHeap.h"
18 #include "src/gpu/ganesh/d3d/GrD3DResourceProvider.h"
21 class GrD3DRenderTarget;
23 struct GrD3DTextureResourceInfo;
25 class GrD3DRenderTarget: public GrRenderTarget, public virtual GrD3DTextureResource {
27 static sk_sp<GrD3DRenderTarget> MakeWrappedRenderTarget(GrD3DGpu*, SkISize, int sampleCnt,
28 const GrD3DTextureResourceInfo&,
29 sk_sp<GrD3DResourceState>);
30 ~GrD3DRenderTarget() override;
32 GrBackendFormat backendFormat() const override { return this->getBackendFormat(); }
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.
39 const GrD3DTextureResource* msaaTextureResource() const;
40 GrD3DTextureResource* msaaTextureResource();
42 bool canAttemptStencilAttachment(bool useMSAASurface) const override {
43 SkASSERT(useMSAASurface == (this->numSamples() > 1));
47 GrBackendRenderTarget getBackendRenderTarget() const override;
49 D3D12_CPU_DESCRIPTOR_HANDLE colorRenderTargetView() const {
50 return fColorRenderTargetView.fHandle;
53 DXGI_FORMAT stencilDxgiFormat() const;
55 // Key used for the program desc
56 void genKey(skgpu::KeyBuilder* b) const;
59 GrD3DRenderTarget(GrD3DGpu* gpu,
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 std::string_view label);
69 GrD3DRenderTarget(GrD3DGpu* gpu,
71 const GrD3DTextureResourceInfo& info,
72 sk_sp<GrD3DResourceState> state,
73 const GrD3DDescriptorHeap::CPUHandle& renderTargetView,
74 std::string_view label);
76 void onAbandon() override;
77 void onRelease() override;
79 // This accounts for the texture's memory and any MSAA renderbuffer's memory.
80 size_t onGpuMemorySize() const override {
81 int numColorSamples = this->numSamples();
82 if (numColorSamples > 1) {
83 // Add one to account for the resolved VkImage.
86 return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(),
87 numColorSamples, GrMipmapped::kNo);
91 // Extra param to disambiguate from constructor used by subclasses.
92 enum Wrapped { kWrapped };
93 GrD3DRenderTarget(GrD3DGpu* gpu,
95 const GrD3DTextureResourceInfo& info,
96 sk_sp<GrD3DResourceState> state,
97 const GrD3DTextureResourceInfo& msaaInfo,
98 sk_sp<GrD3DResourceState> msaaState,
99 const GrD3DDescriptorHeap::CPUHandle& colorRenderTargetView,
100 const GrD3DDescriptorHeap::CPUHandle& resolveRenderTargetView,
102 std::string_view label);
104 GrD3DRenderTarget(GrD3DGpu* gpu,
106 const GrD3DTextureResourceInfo& info,
107 sk_sp<GrD3DResourceState> state,
108 const GrD3DDescriptorHeap::CPUHandle& renderTargetView,
110 std::string_view label);
112 GrD3DGpu* getD3DGpu() const;
114 bool completeStencilAttachment(GrAttachment* stencil, bool useMSAASurface) override {
115 SkASSERT(useMSAASurface == (this->numSamples() > 1));
119 // In Direct3D we call the release proc after we are finished with the underlying
120 // GrD3DTextureResource::Resource object (which occurs after the GPU finishes all work on it).
121 void onSetRelease(sk_sp<skgpu::RefCntedCallback> releaseHelper) override {
122 // Forward the release proc on to GrD3DTextureResource
123 this->setResourceRelease(std::move(releaseHelper));
126 void releaseInternalObjects();
128 std::unique_ptr<GrD3DTextureResource> fMSAATextureResource;
130 GrD3DDescriptorHeap::CPUHandle fColorRenderTargetView;
131 GrD3DDescriptorHeap::CPUHandle fResolveRenderTargetView;