Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
GrD3DTextureResource Class Reference

#include <GrD3DTextureResource.h>

Inheritance diagram for GrD3DTextureResource:
SkNoncopyable GrD3DAttachment GrD3DRenderTarget GrD3DTexture GrD3DTextureRenderTarget GrD3DTextureRenderTarget

Public Member Functions

 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 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

void releaseResource (GrD3DGpu *gpu)
 

Protected Attributes

GrD3DTextureResourceInfo fInfo
 
sk_sp< GrD3DResourceStatefState
 

Friends

class GrD3DRenderTarget
 

Detailed Description

Definition at line 20 of file GrD3DTextureResource.h.

Constructor & Destructor Documentation

◆ GrD3DTextureResource()

GrD3DTextureResource::GrD3DTextureResource ( const GrD3DTextureResourceInfo info,
sk_sp< GrD3DResourceState state 
)
inline

Definition at line 25 of file GrD3DTextureResource.h.

26 : fInfo(info)
27 , fState(std::move(state))
28 , fResource(new Resource(fInfo.fResource, info.fAlloc)) {
29 // gr_cp will implicitly ref the ID3D12Resource for us, so we don't need to worry about
30 // whether it's borrowed or not
31 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
GrD3DTextureResourceInfo fInfo
sk_sp< GrD3DResourceState > fState
AtkStateType state
gr_cp< ID3D12Resource > fResource
Definition GrD3DTypes.h:180

◆ ~GrD3DTextureResource()

GrD3DTextureResource::~GrD3DTextureResource ( )
virtual

Definition at line 101 of file GrD3DTextureResource.cpp.

101 {
102 // Should have been reset() before
103 SkASSERT(!fResource);
105}
#define SkASSERT(cond)
Definition SkAssert.h:116

Member Function Documentation

◆ CreateMSAA()

std::pair< GrD3DTextureResourceInfo, sk_sp< GrD3DResourceState > > GrD3DTextureResource::CreateMSAA ( GrD3DGpu gpu,
SkISize  dimensions,
int  sampleCnt,
const GrD3DTextureResourceInfo info,
SkColor4f  clearColor 
)
static

Definition at line 63 of file GrD3DTextureResource.cpp.

65 {
68
69 // create msaa surface
70 D3D12_RESOURCE_DESC msTextureDesc = {};
71 msTextureDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
72 msTextureDesc.Alignment = 0; // Default alignment (64KB)
73 msTextureDesc.Width = dimensions.fWidth;
74 msTextureDesc.Height = dimensions.fHeight;
75 msTextureDesc.DepthOrArraySize = 1;
76 msTextureDesc.MipLevels = 1;
77 msTextureDesc.Format = info.fFormat;
78 msTextureDesc.SampleDesc.Count = sampleCnt;
79 msTextureDesc.SampleDesc.Quality = DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN;
80 msTextureDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; // Use default for dxgi format
81 msTextureDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
82
83 D3D12_CLEAR_VALUE clearValue = {};
84 clearValue.Format = info.fFormat;
85 clearValue.Color[0] = clearColor.fR;
86 clearValue.Color[1] = clearColor.fG;
87 clearValue.Color[2] = clearColor.fB;
88 clearValue.Color[3] = clearColor.fA;
89
90 if (!InitTextureResourceInfo(gpu, msTextureDesc, D3D12_RESOURCE_STATE_RENDER_TARGET,
91 info.fProtected, &clearValue, &msInfo)) {
92 return {};
93 }
94
95 msState.reset(new GrD3DResourceState(
96 static_cast<D3D12_RESOURCE_STATES>(msInfo.fResourceState)));
97
98 return std::make_pair(msInfo, msState);
99}
static bool InitTextureResourceInfo(GrD3DGpu *gpu, const D3D12_RESOURCE_DESC &desc, D3D12_RESOURCE_STATES initialState, GrProtected, D3D12_CLEAR_VALUE *, GrD3DTextureResourceInfo *)
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310
D3D12_RESOURCE_STATES fResourceState
Definition GrD3DTypes.h:182
int32_t fHeight
Definition SkSize.h:18
int32_t fWidth
Definition SkSize.h:17

◆ currentState()

D3D12_RESOURCE_STATES GrD3DTextureResource::currentState ( ) const
inline

Definition at line 50 of file GrD3DTextureResource.h.

50 {
51 return fState->getResourceState();
52 }
D3D12_RESOURCE_STATES getResourceState() const

◆ d3dResource()

ID3D12Resource * GrD3DTextureResource::d3dResource ( ) const
inline

Definition at line 34 of file GrD3DTextureResource.h.

34 {
35 SkASSERT(fResource);
36 return fInfo.fResource.get();
37 }
T * get() const
Definition GrD3DTypes.h:108

◆ dxgiFormat()

DXGI_FORMAT GrD3DTextureResource::dxgiFormat ( ) const
inline

Definition at line 38 of file GrD3DTextureResource.h.

38{ return fInfo.fFormat; }

◆ getBackendFormat()

GrBackendFormat GrD3DTextureResource::getBackendFormat ( ) const
inline

Definition at line 39 of file GrD3DTextureResource.h.

39 {
40 return GrBackendFormat::MakeDxgi(this->dxgiFormat());
41 }
DXGI_FORMAT dxgiFormat() const

◆ grD3DResourceState()

sk_sp< GrD3DResourceState > GrD3DTextureResource::grD3DResourceState ( ) const
inline

Definition at line 48 of file GrD3DTextureResource.h.

48{ return fState; }

◆ InitTextureResourceInfo()

bool GrD3DTextureResource::InitTextureResourceInfo ( GrD3DGpu gpu,
const D3D12_RESOURCE_DESC &  desc,
D3D12_RESOURCE_STATES  initialState,
GrProtected  isProtected,
D3D12_CLEAR_VALUE *  clearValue,
GrD3DTextureResourceInfo info 
)
static

Definition at line 31 of file GrD3DTextureResource.cpp.

35 {
36 if (0 == desc.Width || 0 == desc.Height) {
37 return false;
38 }
39 // TODO: We don't support protected memory at the moment
40 if (isProtected == GrProtected::kYes) {
41 return false;
42 }
43 // If MipLevels is 0, for some formats the API will automatically calculate the maximum
44 // number of levels supported and use that -- we don't support that.
45 SkASSERT(desc.MipLevels > 0);
46
47 info->fResource = gpu->memoryAllocator()->createResource(
48 D3D12_HEAP_TYPE_DEFAULT, &desc, initialState, &info->fAlloc, clearValue);
49 if (!info->fResource) {
50 return false;
51 }
52
53 info->fResourceState = initialState;
54 info->fFormat = desc.Format;
55 info->fLevelCount = desc.MipLevels;
56 info->fSampleCount = desc.SampleDesc.Count;
57 info->fSampleQualityPattern = desc.SampleDesc.Quality;
58 info->fProtected = isProtected;
59
60 return true;
61}
GrD3DMemoryAllocator * memoryAllocator() const
Definition GrD3DGpu.h:46
virtual gr_cp< ID3D12Resource > createResource(D3D12_HEAP_TYPE, const D3D12_RESOURCE_DESC *, D3D12_RESOURCE_STATES initialResourceState, sk_sp< GrD3DAlloc > *allocation, const D3D12_CLEAR_VALUE *)=0

◆ mipLevels()

uint32_t GrD3DTextureResource::mipLevels ( ) const
inline

Definition at line 46 of file GrD3DTextureResource.h.

46{ return fInfo.fLevelCount; }

◆ prepareForPresent()

void GrD3DTextureResource::prepareForPresent ( GrD3DGpu gpu)

Definition at line 107 of file GrD3DTextureResource.cpp.

107 {
108 this->setResourceState(gpu, D3D12_RESOURCE_STATE_PRESENT);
109}
void setResourceState(const GrD3DGpu *gpu, D3D12_RESOURCE_STATES newResourceState, unsigned int subresource=D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES)

◆ releaseResource()

void GrD3DTextureResource::releaseResource ( GrD3DGpu gpu)
protected

Definition at line 111 of file GrD3DTextureResource.cpp.

111 {
112 // TODO: do we need to migrate resource state if we change queues?
113 if (fResource) {
114 fResource.reset();
115 }
118}
void reset(T *object=nullptr)
Definition GrD3DTypes.h:116
sk_sp< GrD3DAlloc > fAlloc
Definition GrD3DTypes.h:181

◆ resource()

sk_sp< Resource > GrD3DTextureResource::resource ( ) const
inline

Definition at line 42 of file GrD3DTextureResource.h.

42 {
43 SkASSERT(fResource);
44 return fResource;
45 }

◆ sampleQualityPattern()

unsigned int GrD3DTextureResource::sampleQualityPattern ( ) const
inline

Definition at line 60 of file GrD3DTextureResource.h.

unsigned int fSampleQualityPattern
Definition GrD3DTypes.h:186

◆ setResourceRelease()

void GrD3DTextureResource::setResourceRelease ( sk_sp< GrSurface::RefCntedReleaseProc releaseHelper)

Definition at line 120 of file GrD3DTextureResource.cpp.

120 {
121 SkASSERT(fResource);
122 // Forward the release proc on to GrD3DTextureResource::Resource
123 fResource->setRelease(std::move(releaseHelper));
124}

◆ setResourceState()

void GrD3DTextureResource::setResourceState ( const GrD3DGpu gpu,
D3D12_RESOURCE_STATES  newResourceState,
unsigned int  subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES 
)

Definition at line 13 of file GrD3DTextureResource.cpp.

15 {
16 D3D12_RESOURCE_STATES currentResourceState = this->currentState();
17 if (newResourceState == currentResourceState) {
18 return;
19 }
20
21 D3D12_RESOURCE_TRANSITION_BARRIER barrier;
22 barrier.pResource = this->d3dResource();
23 barrier.Subresource = subresource;
24 barrier.StateBefore = currentResourceState;
25 barrier.StateAfter = newResourceState;
26 gpu->addResourceBarriers(this->resource(), 1, &barrier);
27
28 this->updateResourceState(newResourceState);
29}
void addResourceBarriers(sk_sp< GrManagedResource > resource, int numBarriers, D3D12_RESOURCE_TRANSITION_BARRIER *barriers) const
void updateResourceState(D3D12_RESOURCE_STATES newState)
ID3D12Resource * d3dResource() const
D3D12_RESOURCE_STATES currentState() const
sk_sp< Resource > resource() const

◆ updateResourceState()

void GrD3DTextureResource::updateResourceState ( D3D12_RESOURCE_STATES  newState)
inline

Definition at line 64 of file GrD3DTextureResource.h.

64 {
65 SkASSERT(fResource);
66 fState->setResourceState(newState);
67 }
void setResourceState(D3D12_RESOURCE_STATES state)

Friends And Related Symbol Documentation

◆ GrD3DRenderTarget

friend class GrD3DRenderTarget
friend

Definition at line 117 of file GrD3DTextureResource.h.

Member Data Documentation

◆ fInfo

GrD3DTextureResourceInfo GrD3DTextureResource::fInfo
protected

Definition at line 81 of file GrD3DTextureResource.h.

◆ fState

sk_sp<GrD3DResourceState> GrD3DTextureResource::fState
protected

Definition at line 82 of file GrD3DTextureResource.h.


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