Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
GrD3DRenderTarget Class Reference

#include <GrD3DRenderTarget.h>

Inheritance diagram for GrD3DRenderTarget:
GrRenderTarget GrD3DTextureResource GrSurface SkNoncopyable GrGpuResource GrIORef< GrGpuResource > SkNoncopyable GrD3DTextureRenderTarget

Public Member Functions

 ~GrD3DRenderTarget () override
 
GrBackendFormat backendFormat () const override
 
const GrD3DTextureResourcemsaaTextureResource () const
 
GrD3DTextureResourcemsaaTextureResource ()
 
bool canAttemptStencilAttachment (bool useMSAASurface) const override
 
GrBackendRenderTarget getBackendRenderTarget () const override
 
D3D12_CPU_DESCRIPTOR_HANDLE colorRenderTargetView () const
 
DXGI_FORMAT stencilDxgiFormat () const
 
void genKey (skgpu::KeyBuilder *b) const
 
- Public Member Functions inherited from GrRenderTarget
virtual bool alwaysClearStencil () const
 
GrRenderTargetasRenderTarget () override
 
const GrRenderTargetasRenderTarget () const override
 
int numSamples () const
 
virtual GrBackendRenderTarget getBackendRenderTarget () const =0
 
GrAttachmentgetStencilAttachment (bool useMSAASurface) const
 
GrAttachmentgetStencilAttachment () const
 
virtual bool canAttemptStencilAttachment (bool useMSAASurface) const =0
 
void attachStencilAttachment (sk_sp< GrAttachment > stencil, bool useMSAASurface)
 
int numStencilBits (bool useMSAASurface) const
 
int getSamplePatternKey ()
 
const skia_private::TArray< SkPoint > & getSampleLocations ()
 
void setRequiresManualMSAAResolve ()
 
bool requiresManualMSAAResolve () const
 
- Public Member Functions inherited from GrSurface
SkISize dimensions () const
 
int width () const
 
int height () const
 
SkRect getBoundsRect () const
 
virtual GrBackendFormat backendFormat () const =0
 
void setRelease (sk_sp< skgpu::RefCntedCallback > releaseHelper)
 
void setRelease (ReleaseProc proc, ReleaseCtx ctx)
 
virtual GrTextureasTexture ()
 
virtual const GrTextureasTexture () const
 
virtual GrRenderTargetasRenderTarget ()
 
virtual const GrRenderTargetasRenderTarget () const
 
GrInternalSurfaceFlags flags () const
 
bool readOnly () const
 
bool framebufferOnly () const
 
bool isProtected () const
 
void setFramebufferOnly ()
 
- Public Member Functions inherited from GrGpuResource
bool wasDestroyed () const
 
const GrDirectContextgetContext () const
 
GrDirectContextgetContext ()
 
size_t gpuMemorySize () const
 
UniqueID uniqueID () const
 
const skgpu::UniqueKeygetUniqueKey () const
 
std::string getLabel () const
 
void setLabel (std::string_view label)
 
CacheAccess cacheAccess ()
 
const CacheAccess cacheAccess () const
 
ProxyAccess proxyAccess ()
 
ResourcePriv resourcePriv ()
 
const ResourcePriv resourcePriv () const
 
virtual void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 
virtual const char * getResourceType () const =0
 
- Public Member Functions inherited from GrIORef< GrGpuResource >
bool unique () const
 
void ref () const
 
void unref () const
 
void refCommandBuffer () const
 
void unrefCommandBuffer () const
 
- Public Member Functions inherited from SkNoncopyable
 SkNoncopyable ()=default
 
 SkNoncopyable (SkNoncopyable &&)=default
 
SkNoncopyableoperator= (SkNoncopyable &&)=default
 
- Public Member Functions inherited from GrD3DTextureResource
 GrD3DTextureResource (const GrD3DTextureResourceInfo &info, sk_sp< GrD3DResourceState > state)
 
virtual ~GrD3DTextureResource ()
 
ID3D12Resource * d3dResource () const
 
DXGI_FORMAT dxgiFormat () const
 
GrBackendFormat getBackendFormat () const
 
sk_sp< Resource > resource () const
 
uint32_t mipLevels () const
 
sk_sp< GrD3DResourceStategrD3DResourceState () const
 
D3D12_RESOURCE_STATES currentState () const
 
void setResourceState (const GrD3DGpu *gpu, D3D12_RESOURCE_STATES newResourceState, unsigned int subresource=D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES)
 
void prepareForPresent (GrD3DGpu *gpu)
 
unsigned int sampleQualityPattern () const
 
void updateResourceState (D3D12_RESOURCE_STATES newState)
 
void setResourceRelease (sk_sp< GrSurface::RefCntedReleaseProc > releaseHelper)
 

Static Public Member Functions

static sk_sp< GrD3DRenderTargetMakeWrappedRenderTarget (GrD3DGpu *, SkISize, int sampleCnt, const GrD3DTextureResourceInfo &, sk_sp< GrD3DResourceState >)
 
- Static Public Member Functions inherited from GrSurface
static size_t ComputeSize (const GrBackendFormat &, SkISize dimensions, int colorSamplesPerPixel, skgpu::Mipmapped, bool binSize=false)
 
- Static Public Member Functions inherited from GrGpuResource
static uint32_t CreateUniqueID ()
 
- Static Public Member Functions inherited from GrD3DTextureResource
static bool InitTextureResourceInfo (GrD3DGpu *gpu, const D3D12_RESOURCE_DESC &desc, D3D12_RESOURCE_STATES initialState, GrProtected, D3D12_CLEAR_VALUE *, GrD3DTextureResourceInfo *)
 
static std::pair< GrD3DTextureResourceInfo, sk_sp< GrD3DResourceState > > CreateMSAA (GrD3DGpu *gpu, SkISize dimensions, int sampleCnt, const GrD3DTextureResourceInfo &info, SkColor4f clearColor)
 

Protected Member Functions

 GrD3DRenderTarget (GrD3DGpu *gpu, SkISize dimensions, const GrD3DTextureResourceInfo &info, sk_sp< GrD3DResourceState > state, const GrD3DTextureResourceInfo &msaaInfo, sk_sp< GrD3DResourceState > msaaState, const GrD3DDescriptorHeap::CPUHandle &colorRenderTargetView, const GrD3DDescriptorHeap::CPUHandle &resolveRenderTargetView, std::string_view label)
 
 GrD3DRenderTarget (GrD3DGpu *gpu, SkISize dimensions, const GrD3DTextureResourceInfo &info, sk_sp< GrD3DResourceState > state, const GrD3DDescriptorHeap::CPUHandle &renderTargetView, std::string_view label)
 
void onAbandon () override
 
void onRelease () override
 
size_t onGpuMemorySize () const override
 
void onSetLabel () override
 
- Protected Member Functions inherited from GrRenderTarget
 GrRenderTarget (GrGpu *, const SkISize &, int sampleCount, GrProtected, std::string_view label, sk_sp< GrAttachment > stenicl=nullptr)
 
 ~GrRenderTarget () override
 
void onAbandon () override
 
void onRelease () override
 
- Protected Member Functions inherited from GrSurface
void setGLRTFBOIDIs0 ()
 
bool glRTFBOIDis0 () const
 
void setRequiresManualMSAAResolve ()
 
bool requiresManualMSAAResolve () const
 
void setReadOnly ()
 
void setVkRTSupportsInputAttachment ()
 
 GrSurface (GrGpu *gpu, const SkISize &dimensions, skgpu::Protected isProtected, std::string_view label)
 
 ~GrSurface () override
 
void onRelease () override
 
void onAbandon () override
 
- Protected Member Functions inherited from GrGpuResource
void registerWithCache (skgpu::Budgeted)
 
void registerWithCacheWrapped (GrWrapCacheable)
 
 GrGpuResource (GrGpu *, std::string_view label)
 
virtual ~GrGpuResource ()
 
GrGpugetGpu () const
 
virtual void onRelease ()
 
virtual void onAbandon ()
 
virtual void setMemoryBacking (SkTraceMemoryDump *, const SkString &) const
 
SkString getResourceName () const
 
void dumpMemoryStatisticsPriv (SkTraceMemoryDump *traceMemoryDump, const SkString &resourceName, const char *type, size_t size) const
 
- Protected Member Functions inherited from GrIORef< GrGpuResource >
 GrIORef ()
 
bool internalHasRef () const
 
bool internalHasNoCommandBufferUsages () const
 
void addInitialRef () const
 
- Protected Member Functions inherited from GrD3DTextureResource
void releaseResource (GrD3DGpu *gpu)
 

Additional Inherited Members

- Public Types inherited from GrSurface
typedef void * ReleaseCtx
 
typedef void(* ReleaseProc) (ReleaseCtx)
 
- Public Types inherited from GrIORef< GrGpuResource >
enum  LastRemovedRef
 
- Protected Attributes inherited from GrD3DTextureResource
GrD3DTextureResourceInfo fInfo
 
sk_sp< GrD3DResourceStatefState
 

Detailed Description

Definition at line 25 of file GrD3DRenderTarget.h.

Constructor & Destructor Documentation

◆ ~GrD3DRenderTarget()

GrD3DRenderTarget::~GrD3DRenderTarget ( )
override

Definition at line 137 of file GrD3DRenderTarget.cpp.

137 {
138 // either release or abandon should have been called by the owner of this object.
139 SkASSERT(!fMSAATextureResource);
140}
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ GrD3DRenderTarget() [1/2]

GrD3DRenderTarget::GrD3DRenderTarget ( GrD3DGpu gpu,
SkISize  dimensions,
const GrD3DTextureResourceInfo info,
sk_sp< GrD3DResourceState state,
const GrD3DTextureResourceInfo msaaInfo,
sk_sp< GrD3DResourceState msaaState,
const GrD3DDescriptorHeap::CPUHandle colorRenderTargetView,
const GrD3DDescriptorHeap::CPUHandle resolveRenderTargetView,
std::string_view  label 
)
protected

Definition at line 45 of file GrD3DRenderTarget.cpp.

54 : GrSurface(gpu, dimensions, info.fProtected, label)
55 , GrD3DTextureResource(info, std::move(state))
56 // for the moment we only support 1:1 color to stencil
57 , GrRenderTarget(gpu, dimensions, msaaInfo.fSampleCount, info.fProtected, label)
58 , fMSAATextureResource(new GrD3DTextureResource(msaaInfo, std::move(msaaState)))
59 , fColorRenderTargetView(colorRenderTargetView)
60 , fResolveRenderTargetView(resolveRenderTargetView) {
61 SkASSERT(info.fProtected == msaaInfo.fProtected);
62 SkASSERT(msaaInfo.fSampleCount > 1);
63}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
D3D12_CPU_DESCRIPTOR_HANDLE colorRenderTargetView() const
GrD3DTextureResource(const GrD3DTextureResourceInfo &info, sk_sp< GrD3DResourceState > state)
GrRenderTarget(GrGpu *, const SkISize &, int sampleCount, GrProtected, std::string_view label, sk_sp< GrAttachment > stenicl=nullptr)
SkISize dimensions() const
Definition: GrSurface.h:27
GrSurface(GrGpu *gpu, const SkISize &dimensions, skgpu::Protected isProtected, std::string_view label)
Definition: GrSurface.h:140
AtkStateType state
skgpu::Protected fProtected
Definition: GrD3DTypes.h:187

◆ GrD3DRenderTarget() [2/2]

GrD3DRenderTarget::GrD3DRenderTarget ( GrD3DGpu gpu,
SkISize  dimensions,
const GrD3DTextureResourceInfo info,
sk_sp< GrD3DResourceState state,
const GrD3DDescriptorHeap::CPUHandle renderTargetView,
std::string_view  label 
)
protected

Definition at line 84 of file GrD3DRenderTarget.cpp.

90 : GrSurface(gpu, dimensions, info.fProtected, label)
91 , GrD3DTextureResource(info, std::move(state))
92 , GrRenderTarget(gpu, dimensions, info.fSampleCount, info.fProtected, label)
93 , fMSAATextureResource(nullptr)
94 , fColorRenderTargetView(renderTargetView) {}

Member Function Documentation

◆ backendFormat()

GrBackendFormat GrD3DRenderTarget::backendFormat ( ) const
inlineoverridevirtual

Implements GrSurface.

Reimplemented in GrD3DTextureRenderTarget.

Definition at line 32 of file GrD3DRenderTarget.h.

32{ return this->getBackendFormat(); }
GrBackendFormat getBackendFormat() const

◆ canAttemptStencilAttachment()

bool GrD3DRenderTarget::canAttemptStencilAttachment ( bool  useMSAASurface) const
inlineoverridevirtual

Implements GrRenderTarget.

Definition at line 42 of file GrD3DRenderTarget.h.

42 {
43 SkASSERT(useMSAASurface == (this->numSamples() > 1));
44 return true;
45 }
int numSamples() const

◆ colorRenderTargetView()

D3D12_CPU_DESCRIPTOR_HANDLE GrD3DRenderTarget::colorRenderTargetView ( ) const
inline

Definition at line 49 of file GrD3DRenderTarget.h.

49 {
50 return fColorRenderTargetView.fHandle;
51 }
D3D12_CPU_DESCRIPTOR_HANDLE fHandle

◆ genKey()

void GrD3DRenderTarget::genKey ( skgpu::KeyBuilder b) const

Definition at line 200 of file GrD3DRenderTarget.cpp.

200 {
201 b->add32(this->dxgiFormat());
202 b->add32(this->numSamples());
203 b->add32(this->stencilDxgiFormat());
204#ifdef SK_DEBUG
205 if (const GrAttachment* stencil = this->getStencilAttachment()) {
206 SkASSERT(stencil->numSamples() == this->numSamples());
207 }
208#endif
209 b->add32(this->sampleQualityPattern());
210}
DXGI_FORMAT stencilDxgiFormat() const
DXGI_FORMAT dxgiFormat() const
unsigned int sampleQualityPattern() const
GrAttachment * getStencilAttachment() const
void add32(uint32_t v, std::string_view label="unknown")
Definition: KeyBuilder.h:58
static bool b

◆ getBackendRenderTarget()

GrBackendRenderTarget GrD3DRenderTarget::getBackendRenderTarget ( ) const
overridevirtual

Implements GrRenderTarget.

Definition at line 183 of file GrD3DRenderTarget.cpp.

183 {
184 return GrBackendRenderTarget(this->width(), this->height(), fInfo, this->grD3DResourceState());
185}
GrD3DTextureResourceInfo fInfo
sk_sp< GrD3DResourceState > grD3DResourceState() const
int height() const
Definition: GrSurface.h:37
int width() const
Definition: GrSurface.h:32

◆ MakeWrappedRenderTarget()

sk_sp< GrD3DRenderTarget > GrD3DRenderTarget::MakeWrappedRenderTarget ( GrD3DGpu gpu,
SkISize  dimensions,
int  sampleCnt,
const GrD3DTextureResourceInfo info,
sk_sp< GrD3DResourceState state 
)
static

Definition at line 96 of file GrD3DRenderTarget.cpp.

98 {
99 SkASSERT(info.fResource.get());
100 SkASSERT(info.fLevelCount == 1);
101 SkASSERT(sampleCnt >= 1 && info.fSampleCount >= 1);
102
103 int wrappedTextureSampleCnt = static_cast<int>(info.fSampleCount);
104 if (sampleCnt != wrappedTextureSampleCnt && wrappedTextureSampleCnt != 1) {
105 return nullptr;
106 }
107
108 GrD3DDescriptorHeap::CPUHandle renderTargetView =
109 gpu->resourceProvider().createRenderTargetView(info.fResource.get());
110
111 // create msaa surface if necessary
112 GrD3DRenderTarget* d3dRT;
113 if (sampleCnt != wrappedTextureSampleCnt) {
116 // for wrapped MSAA surface we assume clear to white
117 SkColor4f clearColor = { 1, 1, 1, 1 };
118 std::tie(msInfo, msState) =
119 GrD3DTextureResource::CreateMSAA(gpu, dimensions, sampleCnt, info, clearColor);
120
121 GrD3DDescriptorHeap::CPUHandle msaaRenderTargetView =
123
124 d3dRT = new GrD3DRenderTarget(gpu, dimensions, info, std::move(state), msInfo,
125 std::move(msState), msaaRenderTargetView, renderTargetView,
126 kWrapped,
127 /*label=*/"MakeWrappedRenderTargetWithMSAASurface");
128 } else {
129 d3dRT = new GrD3DRenderTarget(
130 gpu, dimensions, info, std::move(state), renderTargetView, kWrapped,
131 /*label=*/"MakeWrappedRenderTarget");
132 }
133
134 return sk_sp<GrD3DRenderTarget>(d3dRT);
135}
GrD3DResourceProvider & resourceProvider()
Definition: GrD3DGpu.h:38
GrD3DDescriptorHeap::CPUHandle createRenderTargetView(ID3D12Resource *textureResource)
static std::pair< GrD3DTextureResourceInfo, sk_sp< GrD3DResourceState > > CreateMSAA(GrD3DGpu *gpu, SkISize dimensions, int sampleCnt, const GrD3DTextureResourceInfo &info, SkColor4f clearColor)
T * get() const
Definition: GrD3DTypes.h:108
gr_cp< ID3D12Resource > fResource
Definition: GrD3DTypes.h:180

◆ msaaTextureResource() [1/2]

GrD3DTextureResource * GrD3DRenderTarget::msaaTextureResource ( )

Definition at line 154 of file GrD3DRenderTarget.cpp.

154 {
155 auto* constThis = const_cast<const GrD3DRenderTarget*>(this);
156 return const_cast<GrD3DTextureResource*>(constThis->msaaTextureResource());
157}

◆ msaaTextureResource() [2/2]

const GrD3DTextureResource * GrD3DRenderTarget::msaaTextureResource ( ) const

If this render target is multisampled, this returns the MSAA texture for rendering. This will be different than this when we have separate render/resolve images. If not multisampled returns nullptr.

Definition at line 142 of file GrD3DRenderTarget.cpp.

142 {
143 if (this->numSamples() == 1) {
144 SkASSERT(!fMSAATextureResource);
145 return nullptr;
146 }
147 if (fMSAATextureResource) {
148 return fMSAATextureResource.get();
149 }
150 SkASSERT(!fMSAATextureResource);
151 return this;
152}

◆ onAbandon()

void GrD3DRenderTarget::onAbandon ( )
overrideprotectedvirtual

Overridden to abandon any internal handles, ptrs, etc to backend API resources. This may be called when the underlying 3D context is no longer valid and so no backend API calls should be made.

Reimplemented from GrGpuResource.

Reimplemented in GrD3DTextureRenderTarget.

Definition at line 177 of file GrD3DRenderTarget.cpp.

177 {
178 this->releaseInternalObjects();
179 this->releaseResource(this->getD3DGpu());
181}
void releaseResource(GrD3DGpu *gpu)
void onAbandon() override

◆ onGpuMemorySize()

size_t GrD3DRenderTarget::onGpuMemorySize ( ) const
inlineoverrideprotectedvirtual

Implements GrGpuResource.

Definition at line 80 of file GrD3DRenderTarget.h.

80 {
81 int numColorSamples = this->numSamples();
82 if (numColorSamples > 1) {
83 // Add one to account for the resolved VkImage.
84 numColorSamples += 1;
85 }
87 this->backendFormat(), this->dimensions(), numColorSamples, skgpu::Mipmapped::kNo);
88 }
GrBackendFormat backendFormat() const override
static size_t ComputeSize(const GrBackendFormat &, SkISize dimensions, int colorSamplesPerPixel, skgpu::Mipmapped, bool binSize=false)
Definition: GrSurface.cpp:21

◆ onRelease()

void GrD3DRenderTarget::onRelease ( )
overrideprotectedvirtual

Overridden to free GPU resources in the backend API.

Reimplemented from GrGpuResource.

Reimplemented in GrD3DTextureRenderTarget.

Definition at line 171 of file GrD3DRenderTarget.cpp.

171 {
172 this->releaseInternalObjects();
173 this->releaseResource(this->getD3DGpu());
175}
void onRelease() override

◆ onSetLabel()

void GrD3DRenderTarget::onSetLabel ( )
overrideprotectedvirtual

Implements GrGpuResource.

Definition at line 212 of file GrD3DRenderTarget.cpp.

212 {
213 SkASSERT(this->d3dResource());
214 if (!this->getLabel().empty()) {
215 if (fMSAATextureResource) {
216 SkASSERT(fMSAATextureResource->d3dResource());
217 const std::wstring suffix = GrD3DMultiByteToWide(this->getLabel());
218 const std::wstring msaaLabel = L"_Skia_MSAA_" + suffix;
219 fMSAATextureResource->d3dResource()->SetName(msaaLabel.c_str());
220 const std::wstring resolveLabel = L"_Skia_Resolve_" + suffix;
221 this->d3dResource()->SetName(resolveLabel.c_str());
222 } else {
223 const std::wstring label = L"_Skia_" + GrD3DMultiByteToWide(this->getLabel());
224 this->d3dResource()->SetName(label.c_str());
225 }
226 }
227}
std::wstring GrD3DMultiByteToWide(const std::string &str)
Definition: GrD3DUtil.cpp:25
ID3D12Resource * d3dResource() const
std::string getLabel() const
EMSCRIPTEN_KEEPALIVE void empty()

◆ stencilDxgiFormat()

DXGI_FORMAT GrD3DRenderTarget::stencilDxgiFormat ( ) const

Definition at line 192 of file GrD3DRenderTarget.cpp.

192 {
193 if (auto stencil = this->getStencilAttachment()) {
194 auto d3dStencil = static_cast<GrD3DAttachment*>(stencil);
195 return d3dStencil->dxgiFormat();
196 }
197 return DXGI_FORMAT_UNKNOWN;
198}

The documentation for this class was generated from the following files: