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/ganesh/GrRenderTarget.h" 13 #include "src/gpu/ganesh/d3d/GrD3DTextureResource.h" 14 15 #include "include/gpu/ganesh/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" 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(skgpu::KeyBuilder* 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 std::string_view label); 68 69 GrD3DRenderTarget(GrD3DGpu* gpu, 70 SkISize dimensions, 71 const GrD3DTextureResourceInfo& info, 72 sk_sp<GrD3DResourceState> state, 73 const GrD3DDescriptorHeap::CPUHandle& renderTargetView, 74 std::string_view label); 75 76 void onAbandon() override; 77 void onRelease() override; 78 79 // This accounts for the texture's memory and any MSAA renderbuffer's memory. onGpuMemorySize()80 size_t onGpuMemorySize() const override { 81 int numColorSamples = this->numSamples(); 82 if (numColorSamples > 1) { 83 // Add one to account for the resolved VkImage. 84 numColorSamples += 1; 85 } 86 return GrSurface::ComputeSize( 87 this->backendFormat(), this->dimensions(), numColorSamples, skgpu::Mipmapped::kNo); 88 } 89 90 void onSetLabel() override; 91 92 private: 93 // Extra param to disambiguate from constructor used by subclasses. 94 enum Wrapped { kWrapped }; 95 GrD3DRenderTarget(GrD3DGpu* gpu, 96 SkISize dimensions, 97 const GrD3DTextureResourceInfo& info, 98 sk_sp<GrD3DResourceState> state, 99 const GrD3DTextureResourceInfo& msaaInfo, 100 sk_sp<GrD3DResourceState> msaaState, 101 const GrD3DDescriptorHeap::CPUHandle& colorRenderTargetView, 102 const GrD3DDescriptorHeap::CPUHandle& resolveRenderTargetView, 103 Wrapped, 104 std::string_view label); 105 106 GrD3DRenderTarget(GrD3DGpu* gpu, 107 SkISize dimensions, 108 const GrD3DTextureResourceInfo& info, 109 sk_sp<GrD3DResourceState> state, 110 const GrD3DDescriptorHeap::CPUHandle& renderTargetView, 111 Wrapped, 112 std::string_view label); 113 114 GrD3DGpu* getD3DGpu() const; 115 completeStencilAttachment(GrAttachment * stencil,bool useMSAASurface)116 bool completeStencilAttachment(GrAttachment* stencil, bool useMSAASurface) override { 117 SkASSERT(useMSAASurface == (this->numSamples() > 1)); 118 return true; 119 } 120 121 // In Direct3D we call the release proc after we are finished with the underlying 122 // GrD3DTextureResource::Resource object (which occurs after the GPU finishes all work on it). onSetRelease(sk_sp<RefCntedReleaseProc> releaseHelper)123 void onSetRelease(sk_sp<RefCntedReleaseProc> releaseHelper) override { 124 // Forward the release proc on to GrD3DTextureResource 125 this->setResourceRelease(std::move(releaseHelper)); 126 } 127 128 void releaseInternalObjects(); 129 130 std::unique_ptr<GrD3DTextureResource> fMSAATextureResource; 131 132 GrD3DDescriptorHeap::CPUHandle fColorRenderTargetView; 133 GrD3DDescriptorHeap::CPUHandle fResolveRenderTargetView; 134 }; 135 136 #endif 137