Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrD3DTexture.cpp
Go to the documentation of this file.
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
9
13
15
16// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
18 skgpu::Budgeted budgeted,
19 SkISize dimensions,
22 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView,
23 GrMipmapStatus mipmapStatus,
24 std::string_view label)
25 : GrSurface(gpu, dimensions, info.fProtected, label)
27 , INHERITED(gpu, dimensions, info.fProtected, GrTextureType::k2D, mipmapStatus, label)
28 , fShaderResourceView(shaderResourceView) {
29 SkASSERT((GrMipmapStatus::kNotAllocated == mipmapStatus) == (1 == info.fLevelCount));
30 this->registerWithCache(budgeted);
31 if (GrDxgiFormatIsCompressed(info.fFormat)) {
32 this->setReadOnly();
33 }
34}
35
38 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView,
39 GrMipmapStatus mipmapStatus, GrWrapCacheable cacheable,
40 GrIOType ioType,
41 std::string_view label)
42 : GrSurface(gpu, dimensions, info.fProtected, label)
44 , INHERITED(gpu, dimensions, info.fProtected, GrTextureType::k2D, mipmapStatus, label)
45 , fShaderResourceView(shaderResourceView) {
46 SkASSERT((GrMipmapStatus::kNotAllocated == mipmapStatus) == (1 == info.fLevelCount));
47 if (ioType == kRead_GrIOType) {
48 this->setReadOnly();
49 }
50 this->registerWithCacheWrapped(cacheable);
51}
52
53// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
55 SkISize dimensions,
58 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView,
59 GrMipmapStatus mipmapStatus,
60 std::string_view label)
61 : GrSurface(gpu, dimensions, info.fProtected, label)
63 , INHERITED(gpu, dimensions, info.fProtected, GrTextureType::k2D, mipmapStatus, label)
64 , fShaderResourceView(shaderResourceView) {
65 SkASSERT((GrMipmapStatus::kNotAllocated == mipmapStatus) == (1 == info.fLevelCount));
66}
67
69 skgpu::Budgeted budgeted,
70 SkISize dimensions,
71 const D3D12_RESOURCE_DESC& desc,
72 GrProtected isProtected,
73 GrMipmapStatus mipmapStatus,
74 std::string_view label) {
77 D3D12_RESOURCE_STATE_COPY_DEST,
78 isProtected, nullptr, &info)) {
79 return nullptr;
80 }
81
83 new GrD3DResourceState(static_cast<D3D12_RESOURCE_STATES>(info.fResourceState)));
84
86 gpu->resourceProvider().createShaderResourceView(info.fResource.get());
87
88 GrD3DTexture* tex = new GrD3DTexture(gpu, budgeted, dimensions, info, std::move(state),
91 label);
92
93 return sk_sp<GrD3DTexture>(tex);
94}
95
97 SkISize dimensions,
98 GrWrapCacheable cacheable,
99 GrIOType ioType,
102 // TODO: If a client uses their own heap to allocate, how do we manage that?
103 // Adopted textures require both image and allocation because we're responsible for freeing
104 //SkASSERT(info.fTexture &&
105 // (kBorrow_GrWrapOwnership == wrapOwnership || VK_NULL_HANDLE != info.fAlloc.fMemory));
106
109
111 gpu->resourceProvider().createShaderResourceView(info.fResource.get());
112
113 return sk_sp<GrD3DTexture>(new GrD3DTexture(gpu, dimensions, info, std::move(state),
115 ioType,
116 /*label=*/"D3DWrappedTexture"));
117}
118
120 sk_sp<GrD3DTexture> originalTexture,
121 const D3D12_RESOURCE_DESC& newDesc,
122 D3D12_RESOURCE_STATES resourceState) {
123 GrD3DTextureResourceInfo info = originalTexture->fInfo;
124 info.fResource = gpu->memoryAllocator()->createAliasingResource(info.fAlloc, 0, &newDesc,
125 resourceState, nullptr);
126 if (!info.fResource) {
127 return nullptr;
128 }
129 info.fResourceState = resourceState;
130
132 new GrD3DResourceState(static_cast<D3D12_RESOURCE_STATES>(resourceState)));
133
135 gpu->resourceProvider().createShaderResourceView(info.fResource.get());
136
137 GrD3DTexture* tex = new GrD3DTexture(gpu,
139 originalTexture->dimensions(),
140 info,
141 std::move(state),
143 originalTexture->mipmapStatus(),
144 /*label=*/"AliasingTexture");
145 return sk_sp<GrD3DTexture>(tex);
146}
147
149 GrD3DGpu* gpu = this->getD3DGpu();
150 gpu->resourceProvider().recycleShaderView(fShaderResourceView);
151 this->releaseResource(gpu);
152
154}
155
157 GrD3DGpu* gpu = this->getD3DGpu();
158 gpu->resourceProvider().recycleShaderView(fShaderResourceView);
159 this->releaseResource(gpu);
161}
162
166
168 SkASSERT(!this->wasDestroyed());
169 return static_cast<GrD3DGpu*>(this->getGpu());
170}
171
173 SkASSERT(this->d3dResource());
174 if (!this->getLabel().empty()) {
175 const std::wstring label = L"_Skia_" + GrD3DMultiByteToWide(this->getLabel());
176 this->d3dResource()->SetName(label.c_str());
177 }
178}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
std::wstring GrD3DMultiByteToWide(const std::string &str)
Definition GrD3DUtil.cpp:25
bool GrDxgiFormatIsCompressed(DXGI_FORMAT format)
Definition GrD3DUtil.cpp:15
GrWrapCacheable
Definition GrTypesPriv.h:84
GrIOType
@ kRead_GrIOType
GrMipmapStatus
GrTextureType
#define SkASSERT(cond)
Definition SkAssert.h:116
#define INHERITED(method,...)
GrD3DMemoryAllocator * memoryAllocator() const
Definition GrD3DGpu.h:46
GrD3DResourceProvider & resourceProvider()
Definition GrD3DGpu.h:38
virtual gr_cp< ID3D12Resource > createAliasingResource(sk_sp< GrD3DAlloc > &allocation, uint64_t localOffset, const D3D12_RESOURCE_DESC *, D3D12_RESOURCE_STATES initialResourceState, const D3D12_CLEAR_VALUE *)=0
void recycleShaderView(const GrD3DDescriptorHeap::CPUHandle &)
GrD3DDescriptorHeap::CPUHandle createShaderResourceView(ID3D12Resource *resource, unsigned int mostDetailedMip=0, unsigned int mipLevels=-1)
GrD3DTextureResourceInfo fInfo
ID3D12Resource * d3dResource() const
void releaseResource(GrD3DGpu *gpu)
sk_sp< GrD3DResourceState > grD3DResourceState() const
static bool InitTextureResourceInfo(GrD3DGpu *gpu, const D3D12_RESOURCE_DESC &desc, D3D12_RESOURCE_STATES initialState, GrProtected, D3D12_CLEAR_VALUE *, GrD3DTextureResourceInfo *)
GrD3DTexture(GrD3DGpu *, SkISize dimensions, const GrD3DTextureResourceInfo &, sk_sp< GrD3DResourceState >, const GrD3DDescriptorHeap::CPUHandle &shaderResourceView, GrMipmapStatus, std::string_view label)
GrD3DGpu * getD3DGpu() const
void onRelease() override
static sk_sp< GrD3DTexture > MakeNewTexture(GrD3DGpu *, skgpu::Budgeted, SkISize dimensions, const D3D12_RESOURCE_DESC &, GrProtected, GrMipmapStatus, std::string_view label)
static sk_sp< GrD3DTexture > MakeAliasingTexture(GrD3DGpu *, sk_sp< GrD3DTexture >, const D3D12_RESOURCE_DESC &newDesc, D3D12_RESOURCE_STATES)
GrBackendTexture getBackendTexture() const override
static sk_sp< GrD3DTexture > MakeWrappedTexture(GrD3DGpu *, SkISize dimensions, GrWrapCacheable, GrIOType, const GrD3DTextureResourceInfo &, sk_sp< GrD3DResourceState >)
D3D12_CPU_DESCRIPTOR_HANDLE shaderResourceView()
void onSetLabel() override
void onAbandon() override
virtual void onAbandon()
std::string getLabel() const
GrGpu * getGpu() const
bool wasDestroyed() const
virtual void onRelease()
SkISize dimensions() const
Definition GrSurface.h:27
bool isProtected() const
Definition GrSurface.h:87
int height() const
Definition GrSurface.h:37
int width() const
Definition GrSurface.h:32
GrMipmapStatus mipmapStatus() const
Definition GrTexture.h:66
EMSCRIPTEN_KEEPALIVE void empty()
AtkStateType state
Budgeted
Definition GpuTypes.h:35
Protected
Definition GpuTypes.h:61
Definition ref_ptr.h:256