Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Side by Side Diff: src/gpu/vk/GrVkRenderTarget.cpp

Issue 1862043002: Refactor to separate backend object lifecycle and GpuResource budget decision (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix unrelated GrBuffer::onGpuMemorySize() lack of override keyword compile error Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/vk/GrVkRenderTarget.h ('k') | src/gpu/vk/GrVkStencilAttachment.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrVkRenderTarget.h" 8 #include "GrVkRenderTarget.h"
9 9
10 #include "GrRenderTargetPriv.h" 10 #include "GrRenderTargetPriv.h"
11 #include "GrVkCommandBuffer.h" 11 #include "GrVkCommandBuffer.h"
12 #include "GrVkFramebuffer.h" 12 #include "GrVkFramebuffer.h"
13 #include "GrVkGpu.h" 13 #include "GrVkGpu.h"
14 #include "GrVkImageView.h" 14 #include "GrVkImageView.h"
15 #include "GrVkResourceProvider.h" 15 #include "GrVkResourceProvider.h"
16 #include "GrVkUtil.h" 16 #include "GrVkUtil.h"
17 17
18 #include "vk/GrVkTypes.h" 18 #include "vk/GrVkTypes.h"
19 19
20 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) 20 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
21 21
22 // We're virtually derived from GrSurface (via GrRenderTarget) so its 22 // We're virtually derived from GrSurface (via GrRenderTarget) so its
23 // constructor must be explicitly called. 23 // constructor must be explicitly called.
24 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, 24 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
25 SkBudgeted budgeted,
25 const GrSurfaceDesc& desc, 26 const GrSurfaceDesc& desc,
26 GrGpuResource::LifeCycle lifeCycle,
27 const GrVkImage::Resource* imageResource, 27 const GrVkImage::Resource* imageResource,
28 const GrVkImage::Resource* msaaResource, 28 const GrVkImage::Resource* msaaResource,
29 const GrVkImageView* colorAttachmentView, 29 const GrVkImageView* colorAttachmentView,
30 const GrVkImageView* resolveAttachmentView) 30 const GrVkImageView* resolveAttachmentView)
31 : GrSurface(gpu, lifeCycle, desc) 31 : GrSurface(gpu, desc)
32 , GrVkImage(imageResource) 32 , GrVkImage(imageResource)
33 // for the moment we only support 1:1 color to stencil 33 // for the moment we only support 1:1 color to stencil
34 , GrRenderTarget(gpu, lifeCycle, desc, kUnified_SampleConfig) 34 , GrRenderTarget(gpu, desc, kUnified_SampleConfig)
35 , fFramebuffer(nullptr) 35 , fFramebuffer(nullptr)
36 , fColorAttachmentView(colorAttachmentView) 36 , fColorAttachmentView(colorAttachmentView)
37 , fMSAAImageResource(msaaResource) 37 , fMSAAImageResource(msaaResource)
38 , fResolveAttachmentView(resolveAttachmentView) 38 , fResolveAttachmentView(resolveAttachmentView)
39 , fCachedSimpleRenderPass(nullptr) { 39 , fCachedSimpleRenderPass(nullptr) {
40 SkASSERT(desc.fSampleCnt); 40 SkASSERT(desc.fSampleCnt);
41 // The plus 1 is to account for the resolve texture. 41 // The plus 1 is to account for the resolve texture.
42 fColorValuesPerPixel = desc.fSampleCnt + 1; // TODO: this still correct? 42 fColorValuesPerPixel = desc.fSampleCnt + 1; // TODO: this still correct?
43 this->createFramebuffer(gpu); 43 this->createFramebuffer(gpu);
44 this->registerWithCache(); 44 this->registerWithCache(budgeted);
45 msaaResource->ref(); 45 msaaResource->ref();
46 } 46 }
47 47
48 // We're virtually derived from GrSurface (via GrRenderTarget) so its 48 // We're virtually derived from GrSurface (via GrRenderTarget) so its
49 // constructor must be explicitly called. 49 // constructor must be explicitly called.
50 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, 50 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
51 const GrSurfaceDesc& desc, 51 const GrSurfaceDesc& desc,
52 GrGpuResource::LifeCycle lifeCycle,
53 const GrVkImage::Resource* imageResource, 52 const GrVkImage::Resource* imageResource,
54 const GrVkImage::Resource* msaaResource, 53 const GrVkImage::Resource* msaaResource,
55 const GrVkImageView* colorAttachmentView, 54 const GrVkImageView* colorAttachmentView,
56 const GrVkImageView* resolveAttachmentView, 55 const GrVkImageView* resolveAttachmentView)
57 Derived) 56 : GrSurface(gpu, desc)
58 : GrSurface(gpu, lifeCycle, desc)
59 , GrVkImage(imageResource) 57 , GrVkImage(imageResource)
60 // for the moment we only support 1:1 color to stencil 58 // for the moment we only support 1:1 color to stencil
61 , GrRenderTarget(gpu, lifeCycle, desc, kUnified_SampleConfig) 59 , GrRenderTarget(gpu, desc, kUnified_SampleConfig)
62 , fFramebuffer(nullptr) 60 , fFramebuffer(nullptr)
63 , fColorAttachmentView(colorAttachmentView) 61 , fColorAttachmentView(colorAttachmentView)
64 , fMSAAImageResource(msaaResource) 62 , fMSAAImageResource(msaaResource)
65 , fResolveAttachmentView(resolveAttachmentView) 63 , fResolveAttachmentView(resolveAttachmentView)
66 , fCachedSimpleRenderPass(nullptr) { 64 , fCachedSimpleRenderPass(nullptr) {
67 SkASSERT(desc.fSampleCnt); 65 SkASSERT(desc.fSampleCnt);
68 // The plus 1 is to account for the resolve texture. 66 // The plus 1 is to account for the resolve texture.
69 fColorValuesPerPixel = desc.fSampleCnt + 1; // TODO: this still correct? 67 fColorValuesPerPixel = desc.fSampleCnt + 1; // TODO: this still correct?
70 this->createFramebuffer(gpu); 68 this->createFramebuffer(gpu);
71 msaaResource->ref(); 69 msaaResource->ref();
72 } 70 }
73 71
74 // We're virtually derived from GrSurface (via GrRenderTarget) so its 72 // We're virtually derived from GrSurface (via GrRenderTarget) so its
75 // constructor must be explicitly called. 73 // constructor must be explicitly called.
76 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, 74 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
75 SkBudgeted budgeted,
77 const GrSurfaceDesc& desc, 76 const GrSurfaceDesc& desc,
78 GrGpuResource::LifeCycle lifeCycle,
79 const GrVkImage::Resource* imageResource, 77 const GrVkImage::Resource* imageResource,
80 const GrVkImageView* colorAttachmentView) 78 const GrVkImageView* colorAttachmentView)
81 : GrSurface(gpu, lifeCycle, desc) 79 : GrSurface(gpu, desc)
82 , GrVkImage(imageResource) 80 , GrVkImage(imageResource)
83 , GrRenderTarget(gpu, lifeCycle, desc, kUnified_SampleConfig) 81 , GrRenderTarget(gpu, desc, kUnified_SampleConfig)
84 , fFramebuffer(nullptr) 82 , fFramebuffer(nullptr)
85 , fColorAttachmentView(colorAttachmentView) 83 , fColorAttachmentView(colorAttachmentView)
86 , fMSAAImageResource(nullptr) 84 , fMSAAImageResource(nullptr)
87 , fResolveAttachmentView(nullptr) 85 , fResolveAttachmentView(nullptr)
88 , fCachedSimpleRenderPass(nullptr) { 86 , fCachedSimpleRenderPass(nullptr) {
89 SkASSERT(!desc.fSampleCnt); 87 SkASSERT(!desc.fSampleCnt);
90 fColorValuesPerPixel = 1; 88 fColorValuesPerPixel = 1;
91 this->createFramebuffer(gpu); 89 this->createFramebuffer(gpu);
92 this->registerWithCache(); 90 this->registerWithCache(budgeted);
93 } 91 }
94 92
95 // We're virtually derived from GrSurface (via GrRenderTarget) so its 93 // We're virtually derived from GrSurface (via GrRenderTarget) so its
96 // constructor must be explicitly called. 94 // constructor must be explicitly called.
97 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, 95 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
98 const GrSurfaceDesc& desc, 96 const GrSurfaceDesc& desc,
99 GrGpuResource::LifeCycle lifeCycle,
100 const GrVkImage::Resource* imageResource, 97 const GrVkImage::Resource* imageResource,
101 const GrVkImageView* colorAttachmentView, 98 const GrVkImageView* colorAttachmentView)
102 Derived) 99 : GrSurface(gpu, desc)
103 : GrSurface(gpu, lifeCycle, desc)
104 , GrVkImage(imageResource) 100 , GrVkImage(imageResource)
105 , GrRenderTarget(gpu, lifeCycle, desc, kUnified_SampleConfig) 101 , GrRenderTarget(gpu, desc, kUnified_SampleConfig)
106 , fFramebuffer(nullptr) 102 , fFramebuffer(nullptr)
107 , fColorAttachmentView(colorAttachmentView) 103 , fColorAttachmentView(colorAttachmentView)
108 , fMSAAImageResource(nullptr) 104 , fMSAAImageResource(nullptr)
109 , fResolveAttachmentView(nullptr) 105 , fResolveAttachmentView(nullptr)
110 , fCachedSimpleRenderPass(nullptr) { 106 , fCachedSimpleRenderPass(nullptr) {
111 SkASSERT(!desc.fSampleCnt); 107 SkASSERT(!desc.fSampleCnt);
112 fColorValuesPerPixel = 1; 108 fColorValuesPerPixel = 1;
113 this->createFramebuffer(gpu); 109 this->createFramebuffer(gpu);
114 } 110 }
115 111
116 GrVkRenderTarget* 112 GrVkRenderTarget*
117 GrVkRenderTarget::Create(GrVkGpu* gpu, 113 GrVkRenderTarget::Create(GrVkGpu* gpu,
114 SkBudgeted budgeted,
118 const GrSurfaceDesc& desc, 115 const GrSurfaceDesc& desc,
119 GrGpuResource::LifeCycle lifeCycle,
120 const GrVkImage::Resource* imageResource) { 116 const GrVkImage::Resource* imageResource) {
121 VkFormat pixelFormat; 117 VkFormat pixelFormat;
122 GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat); 118 GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat);
123 119
124 VkImage colorImage; 120 VkImage colorImage;
125 121
126 // create msaa surface if necessary 122 // create msaa surface if necessary
127 const GrVkImage::Resource* msaaResource = nullptr; 123 const GrVkImage::Resource* msaaResource = nullptr;
128 const GrVkImageView* resolveAttachmentView = nullptr; 124 const GrVkImageView* resolveAttachmentView = nullptr;
129 if (desc.fSampleCnt) { 125 if (desc.fSampleCnt) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 if (!colorAttachmentView) { 161 if (!colorAttachmentView) {
166 if (msaaResource) { 162 if (msaaResource) {
167 resolveAttachmentView->unref(gpu); 163 resolveAttachmentView->unref(gpu);
168 msaaResource->unref(gpu); 164 msaaResource->unref(gpu);
169 } 165 }
170 return NULL; 166 return NULL;
171 } 167 }
172 168
173 GrVkRenderTarget* texRT; 169 GrVkRenderTarget* texRT;
174 if (msaaResource) { 170 if (msaaResource) {
175 texRT = new GrVkRenderTarget(gpu, desc, lifeCycle, imageResource, msaaRe source, 171 texRT = new GrVkRenderTarget(gpu, budgeted, desc, imageResource, msaaRes ource,
176 colorAttachmentView, resolveAttachmentView) ; 172 colorAttachmentView, resolveAttachmentView) ;
177 msaaResource->unref(gpu); 173 msaaResource->unref(gpu);
178 } else { 174 } else {
179 texRT = new GrVkRenderTarget(gpu, desc, lifeCycle, imageResource, 175 texRT = new GrVkRenderTarget(gpu, budgeted, desc, imageResource,
180 colorAttachmentView); 176 colorAttachmentView);
181 } 177 }
182 178
183 return texRT; 179 return texRT;
184 } 180 }
185 181
186 GrVkRenderTarget* 182 GrVkRenderTarget*
187 GrVkRenderTarget::CreateNewRenderTarget(GrVkGpu* gpu, 183 GrVkRenderTarget::CreateNewRenderTarget(GrVkGpu* gpu,
184 SkBudgeted budgeted,
188 const GrSurfaceDesc& desc, 185 const GrSurfaceDesc& desc,
189 GrGpuResource::LifeCycle lifeCycle,
190 const GrVkImage::ImageDesc& imageDesc) { 186 const GrVkImage::ImageDesc& imageDesc) {
191 SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); 187 SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
192 188
193 const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, im ageDesc); 189 const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, im ageDesc);
194 if (!imageResource) { 190 if (!imageResource) {
195 return nullptr; 191 return nullptr;
196 } 192 }
197 193
198 GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, desc, lifeCycle, imageR esource); 194 GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, budgeted, desc, imageRe source);
199 // Create() will increment the refCount of the image resource if it succeeds 195 // Create() will increment the refCount of the image resource if it succeeds
200 imageResource->unref(gpu); 196 imageResource->unref(gpu);
201 return rt; 197 return rt;
202 } 198 }
203 199
204 GrVkRenderTarget* 200 GrVkRenderTarget*
205 GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu, 201 GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu,
206 const GrSurfaceDesc& desc, 202 const GrSurfaceDesc& desc,
207 GrGpuResource::LifeCycle lifeCycle, 203 GrWrapOwnership ownership,
208 const GrVkTextureInfo* info) { 204 const GrVkTextureInfo* info) {
209 SkASSERT(info); 205 SkASSERT(info);
210 // We can wrap a rendertarget without its allocation, as long as we don't ta ke ownership 206 // We can wrap a rendertarget without its allocation, as long as we don't ta ke ownership
211 SkASSERT(VK_NULL_HANDLE != info->fImage); 207 SkASSERT(VK_NULL_HANDLE != info->fImage);
212 SkASSERT(VK_NULL_HANDLE != info->fAlloc || kAdopted_LifeCycle != lifeCycle); 208 SkASSERT(VK_NULL_HANDLE != info->fAlloc || kAdopt_GrWrapOwnership != ownersh ip);
213 209
214 GrVkImage::Resource::Flags flags = (VK_IMAGE_TILING_LINEAR == info->fImageTi ling) 210 GrVkImage::Resource::Flags flags = (VK_IMAGE_TILING_LINEAR == info->fImageTi ling)
215 ? Resource::kLinearTiling_Flag : Resource:: kNo_Flags; 211 ? Resource::kLinearTiling_Flag : Resource:: kNo_Flags;
216 212
217 const GrVkImage::Resource* imageResource; 213 const GrVkImage::Resource* imageResource;
218 if (kBorrowed_LifeCycle == lifeCycle) { 214 if (kBorrow_GrWrapOwnership == ownership) {
219 imageResource = new GrVkImage::BorrowedResource(info->fImage, 215 imageResource = new GrVkImage::BorrowedResource(info->fImage,
220 info->fAlloc, 216 info->fAlloc,
221 flags, 217 flags,
222 info->fFormat); 218 info->fFormat);
223 } else { 219 } else {
224 imageResource = new GrVkImage::Resource(info->fImage, info->fAlloc, flag s, info->fFormat); 220 imageResource = new GrVkImage::Resource(info->fImage, info->fAlloc, flag s, info->fFormat);
225 } 221 }
226 if (!imageResource) { 222 if (!imageResource) {
227 return nullptr; 223 return nullptr;
228 } 224 }
229 225
230 GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, desc, lifeCycle, imageR esource); 226 GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, SkBudgeted::kNo, desc, imageResource);
231 if (rt) { 227 if (rt) {
232 rt->fCurrentLayout = info->fImageLayout; 228 rt->fCurrentLayout = info->fImageLayout;
233 } 229 }
234 // Create() will increment the refCount of the image resource if it succeeds 230 // Create() will increment the refCount of the image resource if it succeeds
235 imageResource->unref(gpu); 231 imageResource->unref(gpu);
236 232
237 return rt; 233 return rt;
238 } 234 }
239 235
240 bool GrVkRenderTarget::completeStencilAttachment() { 236 bool GrVkRenderTarget::completeStencilAttachment() {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 fFramebuffer = nullptr; 356 fFramebuffer = nullptr;
361 } 357 }
362 if (fCachedSimpleRenderPass) { 358 if (fCachedSimpleRenderPass) {
363 fCachedSimpleRenderPass->unrefAndAbandon(); 359 fCachedSimpleRenderPass->unrefAndAbandon();
364 fCachedSimpleRenderPass = nullptr; 360 fCachedSimpleRenderPass = nullptr;
365 } 361 }
366 } 362 }
367 363
368 void GrVkRenderTarget::onRelease() { 364 void GrVkRenderTarget::onRelease() {
369 this->releaseInternalObjects(); 365 this->releaseInternalObjects();
370 if (this->shouldFreeResources()) { 366 this->releaseImage(this->getVkGpu());
371 this->releaseImage(this->getVkGpu());
372 } else {
373 this->abandonImage();
374 }
375
376 GrRenderTarget::onRelease(); 367 GrRenderTarget::onRelease();
377 } 368 }
378 369
379 void GrVkRenderTarget::onAbandon() { 370 void GrVkRenderTarget::onAbandon() {
380 this->abandonInternalObjects(); 371 this->abandonInternalObjects();
381 this->abandonImage(); 372 this->abandonImage();
382 GrRenderTarget::onAbandon(); 373 GrRenderTarget::onAbandon();
383 } 374 }
384 375
385 376
(...skipping 20 matching lines...) Expand all
406 } 397 }
407 398
408 return nullptr; 399 return nullptr;
409 } 400 }
410 401
411 402
412 GrVkGpu* GrVkRenderTarget::getVkGpu() const { 403 GrVkGpu* GrVkRenderTarget::getVkGpu() const {
413 SkASSERT(!this->wasDestroyed()); 404 SkASSERT(!this->wasDestroyed());
414 return static_cast<GrVkGpu*>(this->getGpu()); 405 return static_cast<GrVkGpu*>(this->getGpu());
415 } 406 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkRenderTarget.h ('k') | src/gpu/vk/GrVkStencilAttachment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698