Flutter Engine
The Flutter Engine
GrD3DTextureRenderTarget.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
12
13GrD3DTextureRenderTarget::GrD3DTextureRenderTarget(
14 GrD3DGpu* gpu,
15 skgpu::Budgeted budgeted,
16 SkISize dimensions,
19 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView,
20 const GrD3DTextureResourceInfo& msaaInfo,
22 const GrD3DDescriptorHeap::CPUHandle& colorRenderTargetView,
23 const GrD3DDescriptorHeap::CPUHandle& resolveRenderTargetView,
24 GrMipmapStatus mipmapStatus,
25 std::string_view label)
26 : GrSurface(gpu, dimensions, info.fProtected, label)
28 , GrD3DTexture(gpu, dimensions, info, state, shaderResourceView, mipmapStatus, label)
30 dimensions,
31 info,
32 state,
33 msaaInfo,
34 std::move(msaaState),
35 colorRenderTargetView,
36 resolveRenderTargetView,
37 label) {
38 SkASSERT(info.fProtected == msaaInfo.fProtected);
39 this->registerWithCache(budgeted);
40}
41
42GrD3DTextureRenderTarget::GrD3DTextureRenderTarget(
43 GrD3DGpu* gpu,
44 skgpu::Budgeted budgeted,
45 SkISize dimensions,
48 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView,
49 const GrD3DDescriptorHeap::CPUHandle& renderTargetView,
50 GrMipmapStatus mipmapStatus,
51 std::string_view label)
52 : GrSurface(gpu, dimensions, info.fProtected, label)
54 , GrD3DTexture(gpu, dimensions, info, state, shaderResourceView, mipmapStatus, label)
55 , GrD3DRenderTarget(gpu, dimensions, info, state, renderTargetView, label) {
56 this->registerWithCache(budgeted);
57}
58
59GrD3DTextureRenderTarget::GrD3DTextureRenderTarget(
60 GrD3DGpu* gpu,
61 SkISize dimensions,
64 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView,
65 const GrD3DTextureResourceInfo& msaaInfo,
67 const GrD3DDescriptorHeap::CPUHandle& colorRenderTargetView,
68 const GrD3DDescriptorHeap::CPUHandle& resolveRenderTargetView,
69 GrMipmapStatus mipmapStatus,
70 GrWrapCacheable cacheable,
71 std::string_view label)
72 : GrSurface(gpu, dimensions, info.fProtected, label)
74 , GrD3DTexture(gpu, dimensions, info, state, shaderResourceView, mipmapStatus, label)
76 dimensions,
77 info,
78 state,
79 msaaInfo,
80 std::move(msaaState),
81 colorRenderTargetView,
82 resolveRenderTargetView,
83 label) {
84 SkASSERT(info.fProtected == msaaInfo.fProtected);
85 this->registerWithCacheWrapped(cacheable);
86}
87
88GrD3DTextureRenderTarget::GrD3DTextureRenderTarget(
89 GrD3DGpu* gpu,
90 SkISize dimensions,
93 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView,
94 const GrD3DDescriptorHeap::CPUHandle& renderTargetView,
95 GrMipmapStatus mipmapStatus,
96 GrWrapCacheable cacheable,
97 std::string_view label)
98 : GrSurface(gpu, dimensions, info.fProtected, label)
100 , GrD3DTexture(gpu, dimensions, info, state, shaderResourceView, mipmapStatus, label)
101 , GrD3DRenderTarget(gpu, dimensions, info, state, renderTargetView, label) {
102 this->registerWithCacheWrapped(cacheable);
103}
104
106 GrD3DGpu* gpu,
107 skgpu::Budgeted budgeted,
108 SkISize dimensions,
109 int sampleCnt,
110 const D3D12_RESOURCE_DESC& resourceDesc,
111 GrProtected isProtected,
112 GrMipmapStatus mipmapStatus,
113 std::string_view label) {
115 D3D12_RESOURCE_STATES initialState = sampleCnt > 1 ? D3D12_RESOURCE_STATE_RESOLVE_DEST
116 : D3D12_RESOURCE_STATE_RENDER_TARGET;
117
118 D3D12_CLEAR_VALUE clearValue = {};
119 clearValue.Format = resourceDesc.Format;
120 clearValue.Color[0] = 0;
121 clearValue.Color[1] = 0;
122 clearValue.Color[2] = 0;
123 clearValue.Color[3] = 0;
124
125 if (!GrD3DTextureResource::InitTextureResourceInfo(gpu, resourceDesc, initialState,
126 isProtected, &clearValue, &info)) {
127 return nullptr;
128 }
130 static_cast<D3D12_RESOURCE_STATES>(info.fResourceState)));
131
133 gpu->resourceProvider().createShaderResourceView(info.fResource.get());
134
135 const GrD3DDescriptorHeap::CPUHandle renderTargetView =
136 gpu->resourceProvider().createRenderTargetView(info.fResource.get());
137
138 if (sampleCnt > 1) {
141 // created MSAA surface we assume will be used for masks, so clear to transparent black
142 SkColor4f clearColor = { 0, 0, 0, 0 };
143 std::tie(msInfo, msState) =
144 GrD3DTextureResource::CreateMSAA(gpu, dimensions, sampleCnt, info, clearColor);
145 if (!msInfo.fResource || !msState) {
146 return nullptr;
147 }
148
149 const GrD3DDescriptorHeap::CPUHandle msaaRenderTargetView =
151
153 budgeted,
155 info,
156 std::move(state),
158 msInfo,
159 std::move(msState),
160 msaaRenderTargetView,
161 renderTargetView,
163 label);
165 } else {
167 budgeted,
169 info,
170 std::move(state),
172 renderTargetView,
174 label);
176 }
177}
178
180 GrD3DGpu* gpu,
181 SkISize dimensions,
182 int sampleCnt,
183 GrWrapCacheable cacheable,
186 // TODO: If a client uses their own heap to allocate, how do we manage that?
187 // Adopted textures require both image and allocation because we're responsible for freeing
188 //SkASSERT(VK_NULL_HANDLE != info.fImage &&
189 // (kBorrow_GrWrapOwnership == wrapOwnership || VK_NULL_HANDLE != info.fAlloc.fMemory));
190
193
195 gpu->resourceProvider().createShaderResourceView(info.fResource.get());
196
197 const GrD3DDescriptorHeap::CPUHandle renderTargetView =
198 gpu->resourceProvider().createRenderTargetView(info.fResource.get());
199
200 if (sampleCnt > 1) {
203 // for wrapped MSAA surface we assume clear to white
204 SkColor4f clearColor = { 1, 1, 1, 1 };
205 std::tie(msInfo, msState) =
206 GrD3DTextureResource::CreateMSAA(gpu, dimensions, sampleCnt, info, clearColor);
207 if (!msInfo.fResource || !msState) {
208 return nullptr;
209 }
210
211 const GrD3DDescriptorHeap::CPUHandle msaaRenderTargetView =
213
215 gpu,
217 info,
218 std::move(state),
220 msInfo,
221 std::move(msState),
222 msaaRenderTargetView,
223 renderTargetView,
225 cacheable,
226 /*label=*/"MakeWrappedTextureRenderTargetWithMSAASurface");
228 } else {
232 info,
233 std::move(state),
235 renderTargetView,
237 cacheable,
238 /*label=*/"MakeWrappedTextureRenderTarget"));
239 }
240}
241
242size_t GrD3DTextureRenderTarget::onGpuMemorySize() const {
243 int numColorSamples = this->numSamples();
244 if (numColorSamples > 1) {
245 // Add one to account for the resolve VkImage.
246 ++numColorSamples;
247 }
248 return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(),
249 numColorSamples, // TODO: this still correct?
250 this->mipmapped());
251}
252
253void GrD3DTextureRenderTarget::onSetLabel() {
255}
256
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
GrWrapCacheable
Definition: GrTypesPriv.h:85
GrMipmapStatus
Definition: GrTypesPriv.h:523
#define SkASSERT(cond)
Definition: SkAssert.h:116
GrD3DResourceProvider & resourceProvider()
Definition: GrD3DGpu.h:38
void onSetLabel() override
GrD3DDescriptorHeap::CPUHandle createShaderResourceView(ID3D12Resource *resource, unsigned int mostDetailedMip=0, unsigned int mipLevels=-1)
GrD3DDescriptorHeap::CPUHandle createRenderTargetView(ID3D12Resource *textureResource)
static sk_sp< GrD3DTextureRenderTarget > MakeWrappedTextureRenderTarget(GrD3DGpu *, SkISize dimensions, int sampleCnt, GrWrapCacheable, const GrD3DTextureResourceInfo &, sk_sp< GrD3DResourceState >)
GrBackendFormat backendFormat() const override
static sk_sp< GrD3DTextureRenderTarget > MakeNewTextureRenderTarget(GrD3DGpu *, skgpu::Budgeted, SkISize dimensions, int sampleCnt, const D3D12_RESOURCE_DESC &, GrProtected isProtected, GrMipmapStatus, std::string_view label)
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)
D3D12_CPU_DESCRIPTOR_HANDLE shaderResourceView()
Definition: GrD3DTexture.h:45
int numSamples() const
SkISize dimensions() const
Definition: GrSurface.h:27
bool isProtected() const
Definition: GrSurface.h:87
static size_t ComputeSize(const GrBackendFormat &, SkISize dimensions, int colorSamplesPerPixel, skgpu::Mipmapped, bool binSize=false)
Definition: GrSurface.cpp:21
skgpu::Mipmapped mipmapped() const
Definition: GrTexture.h:62
GrMipmapStatus mipmapStatus() const
Definition: GrTexture.h:66
T * get() const
Definition: GrD3DTypes.h:108
AtkStateType state
Budgeted
Definition: GpuTypes.h:35
Protected
Definition: GpuTypes.h:61
Definition: ref_ptr.h:256
gr_cp< ID3D12Resource > fResource
Definition: GrD3DTypes.h:180
skgpu::Protected fProtected
Definition: GrD3DTypes.h:187
Definition: SkSize.h:16