OLD | NEW |
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 SkBudgeted budgeted, |
26 const GrSurfaceDesc& desc, | 26 const GrSurfaceDesc& desc, |
27 const GrVkImage::Resource* imageResource, | 27 const GrVkImageInfo& info, |
28 const GrVkImage::Resource* msaaResource, | 28 const GrVkImageInfo& msaaInfo, |
29 const GrVkImageView* colorAttachmentView, | 29 const GrVkImageView* colorAttachmentView, |
30 const GrVkImageView* resolveAttachmentView) | 30 const GrVkImageView* resolveAttachmentView, |
| 31 GrVkImage::Wrapped wrapped) |
31 : GrSurface(gpu, desc) | 32 : GrSurface(gpu, desc) |
32 , GrVkImage(imageResource) | 33 , GrVkImage(info, wrapped) |
33 // for the moment we only support 1:1 color to stencil | 34 // for the moment we only support 1:1 color to stencil |
34 , GrRenderTarget(gpu, desc, kUnified_SampleConfig) | 35 , GrRenderTarget(gpu, desc, kUnified_SampleConfig) |
35 , fFramebuffer(nullptr) | 36 , fFramebuffer(nullptr) |
36 , fColorAttachmentView(colorAttachmentView) | 37 , fColorAttachmentView(colorAttachmentView) |
37 , fMSAAImageResource(msaaResource) | 38 , fMSAAImage(new GrVkImage(info, GrVkImage::kNot_Wrapped)) |
38 , fResolveAttachmentView(resolveAttachmentView) | 39 , fResolveAttachmentView(resolveAttachmentView) |
39 , fCachedSimpleRenderPass(nullptr) { | 40 , fCachedSimpleRenderPass(nullptr) { |
40 SkASSERT(desc.fSampleCnt); | 41 SkASSERT(desc.fSampleCnt); |
41 // The plus 1 is to account for the resolve texture. | 42 // The plus 1 is to account for the resolve texture. |
42 fColorValuesPerPixel = desc.fSampleCnt + 1; // TODO: this still correct? | 43 fColorValuesPerPixel = desc.fSampleCnt + 1; // TODO: this still correct? |
43 this->createFramebuffer(gpu); | 44 this->createFramebuffer(gpu); |
44 this->registerWithCache(budgeted); | 45 this->registerWithCache(budgeted); |
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 const GrVkImage::Resource* imageResource, | 52 const GrVkImageInfo& info, |
53 const GrVkImage::Resource* msaaResource, | 53 const GrVkImageInfo& msaaInfo, |
54 const GrVkImageView* colorAttachmentView, | 54 const GrVkImageView* colorAttachmentView, |
55 const GrVkImageView* resolveAttachmentView) | 55 const GrVkImageView* resolveAttachmentView, |
| 56 GrVkImage::Wrapped wrapped) |
56 : GrSurface(gpu, desc) | 57 : GrSurface(gpu, desc) |
57 , GrVkImage(imageResource) | 58 , GrVkImage(info, wrapped) |
58 // for the moment we only support 1:1 color to stencil | 59 // for the moment we only support 1:1 color to stencil |
59 , GrRenderTarget(gpu, desc, kUnified_SampleConfig) | 60 , GrRenderTarget(gpu, desc, kUnified_SampleConfig) |
60 , fFramebuffer(nullptr) | 61 , fFramebuffer(nullptr) |
61 , fColorAttachmentView(colorAttachmentView) | 62 , fColorAttachmentView(colorAttachmentView) |
62 , fMSAAImageResource(msaaResource) | 63 , fMSAAImage(new GrVkImage(info, GrVkImage::kNot_Wrapped)) |
63 , fResolveAttachmentView(resolveAttachmentView) | 64 , fResolveAttachmentView(resolveAttachmentView) |
64 , fCachedSimpleRenderPass(nullptr) { | 65 , fCachedSimpleRenderPass(nullptr) { |
65 SkASSERT(desc.fSampleCnt); | 66 SkASSERT(desc.fSampleCnt); |
66 // The plus 1 is to account for the resolve texture. | 67 // The plus 1 is to account for the resolve texture. |
67 fColorValuesPerPixel = desc.fSampleCnt + 1; // TODO: this still correct? | 68 fColorValuesPerPixel = desc.fSampleCnt + 1; // TODO: this still correct? |
68 this->createFramebuffer(gpu); | 69 this->createFramebuffer(gpu); |
69 msaaResource->ref(); | |
70 } | 70 } |
71 | 71 |
72 // We're virtually derived from GrSurface (via GrRenderTarget) so its | 72 // We're virtually derived from GrSurface (via GrRenderTarget) so its |
73 // constructor must be explicitly called. | 73 // constructor must be explicitly called. |
74 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, | 74 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, |
75 SkBudgeted budgeted, | 75 SkBudgeted budgeted, |
76 const GrSurfaceDesc& desc, | 76 const GrSurfaceDesc& desc, |
77 const GrVkImage::Resource* imageResource, | 77 const GrVkImageInfo& info, |
78 const GrVkImageView* colorAttachmentView) | 78 const GrVkImageView* colorAttachmentView, |
| 79 GrVkImage::Wrapped wrapped) |
79 : GrSurface(gpu, desc) | 80 : GrSurface(gpu, desc) |
80 , GrVkImage(imageResource) | 81 , GrVkImage(info, wrapped) |
81 , GrRenderTarget(gpu, desc, kUnified_SampleConfig) | 82 , GrRenderTarget(gpu, desc, kUnified_SampleConfig) |
82 , fFramebuffer(nullptr) | 83 , fFramebuffer(nullptr) |
83 , fColorAttachmentView(colorAttachmentView) | 84 , fColorAttachmentView(colorAttachmentView) |
84 , fMSAAImageResource(nullptr) | 85 , fMSAAImage(nullptr) |
85 , fResolveAttachmentView(nullptr) | 86 , fResolveAttachmentView(nullptr) |
86 , fCachedSimpleRenderPass(nullptr) { | 87 , fCachedSimpleRenderPass(nullptr) { |
87 SkASSERT(!desc.fSampleCnt); | 88 SkASSERT(!desc.fSampleCnt); |
88 fColorValuesPerPixel = 1; | 89 fColorValuesPerPixel = 1; |
89 this->createFramebuffer(gpu); | 90 this->createFramebuffer(gpu); |
90 this->registerWithCache(budgeted); | 91 this->registerWithCache(budgeted); |
91 } | 92 } |
92 | 93 |
93 // We're virtually derived from GrSurface (via GrRenderTarget) so its | 94 // We're virtually derived from GrSurface (via GrRenderTarget) so its |
94 // constructor must be explicitly called. | 95 // constructor must be explicitly called. |
95 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, | 96 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, |
96 const GrSurfaceDesc& desc, | 97 const GrSurfaceDesc& desc, |
97 const GrVkImage::Resource* imageResource, | 98 const GrVkImageInfo& info, |
98 const GrVkImageView* colorAttachmentView) | 99 const GrVkImageView* colorAttachmentView, |
| 100 GrVkImage::Wrapped wrapped) |
99 : GrSurface(gpu, desc) | 101 : GrSurface(gpu, desc) |
100 , GrVkImage(imageResource) | 102 , GrVkImage(info, wrapped) |
101 , GrRenderTarget(gpu, desc, kUnified_SampleConfig) | 103 , GrRenderTarget(gpu, desc, kUnified_SampleConfig) |
102 , fFramebuffer(nullptr) | 104 , fFramebuffer(nullptr) |
103 , fColorAttachmentView(colorAttachmentView) | 105 , fColorAttachmentView(colorAttachmentView) |
104 , fMSAAImageResource(nullptr) | 106 , fMSAAImage(nullptr) |
105 , fResolveAttachmentView(nullptr) | 107 , fResolveAttachmentView(nullptr) |
106 , fCachedSimpleRenderPass(nullptr) { | 108 , fCachedSimpleRenderPass(nullptr) { |
107 SkASSERT(!desc.fSampleCnt); | 109 SkASSERT(!desc.fSampleCnt); |
108 fColorValuesPerPixel = 1; | 110 fColorValuesPerPixel = 1; |
109 this->createFramebuffer(gpu); | 111 this->createFramebuffer(gpu); |
110 } | 112 } |
111 | 113 |
112 GrVkRenderTarget* | 114 GrVkRenderTarget* |
113 GrVkRenderTarget::Create(GrVkGpu* gpu, | 115 GrVkRenderTarget::Create(GrVkGpu* gpu, |
114 SkBudgeted budgeted, | 116 SkBudgeted budgeted, |
115 const GrSurfaceDesc& desc, | 117 const GrSurfaceDesc& desc, |
116 const GrVkImage::Resource* imageResource) { | 118 const GrVkImageInfo& info, |
| 119 GrVkImage::Wrapped wrapped) { |
117 VkFormat pixelFormat; | 120 VkFormat pixelFormat; |
118 GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat); | 121 GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat); |
119 | 122 |
120 VkImage colorImage; | 123 VkImage colorImage; |
121 | 124 |
122 // create msaa surface if necessary | 125 // create msaa surface if necessary |
123 const GrVkImage::Resource* msaaResource = nullptr; | 126 GrVkImageInfo msInfo; |
124 const GrVkImageView* resolveAttachmentView = nullptr; | 127 const GrVkImageView* resolveAttachmentView = nullptr; |
125 if (desc.fSampleCnt) { | 128 if (desc.fSampleCnt) { |
126 GrVkImage::ImageDesc msImageDesc; | 129 GrVkImage::ImageDesc msImageDesc; |
127 msImageDesc.fImageType = VK_IMAGE_TYPE_2D; | 130 msImageDesc.fImageType = VK_IMAGE_TYPE_2D; |
128 msImageDesc.fFormat = pixelFormat; | 131 msImageDesc.fFormat = pixelFormat; |
129 msImageDesc.fWidth = desc.fWidth; | 132 msImageDesc.fWidth = desc.fWidth; |
130 msImageDesc.fHeight = desc.fHeight; | 133 msImageDesc.fHeight = desc.fHeight; |
131 msImageDesc.fLevels = 1; | 134 msImageDesc.fLevels = 1; |
132 msImageDesc.fSamples = desc.fSampleCnt; | 135 msImageDesc.fSamples = desc.fSampleCnt; |
133 msImageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL; | 136 msImageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL; |
134 msImageDesc.fUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; | 137 msImageDesc.fUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
135 msImageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; | 138 msImageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
136 | 139 |
137 msaaResource = GrVkImage::CreateResource(gpu, msImageDesc); | 140 if (!GrVkImage::InitImageInfo(gpu, msImageDesc, &msInfo)) { |
138 | |
139 if (!msaaResource) { | |
140 return nullptr; | 141 return nullptr; |
141 } | 142 } |
142 | 143 |
143 // Set color attachment image | 144 // Set color attachment image |
144 colorImage = msaaResource->fImage; | 145 colorImage = msInfo.fImage; |
145 | 146 |
146 // Create Resolve attachment view | 147 // Create Resolve attachment view |
147 resolveAttachmentView = GrVkImageView::Create(gpu, imageResource->fImage
, pixelFormat, | 148 resolveAttachmentView = GrVkImageView::Create(gpu, info.fImage, pixelFor
mat, |
148 GrVkImageView::kColor_Type
, 1); | 149 GrVkImageView::kColor_Type
, 1); |
149 if (!resolveAttachmentView) { | 150 if (!resolveAttachmentView) { |
150 msaaResource->unref(gpu); | 151 GrVkImage::DestroyImageInfo(gpu, &msInfo); |
151 return nullptr; | 152 return nullptr; |
152 } | 153 } |
153 } else { | 154 } else { |
154 // Set color attachment image | 155 // Set color attachment image |
155 colorImage = imageResource->fImage; | 156 colorImage = info.fImage; |
156 } | 157 } |
157 | 158 |
158 // Get color attachment view | 159 // Get color attachment view |
159 const GrVkImageView* colorAttachmentView = GrVkImageView::Create(gpu, colorI
mage, pixelFormat, | 160 const GrVkImageView* colorAttachmentView = GrVkImageView::Create(gpu, colorI
mage, pixelFormat, |
160 GrVkImageVi
ew::kColor_Type, 1); | 161 GrVkImageVi
ew::kColor_Type, 1); |
161 if (!colorAttachmentView) { | 162 if (!colorAttachmentView) { |
162 if (msaaResource) { | 163 if (desc.fSampleCnt) { |
163 resolveAttachmentView->unref(gpu); | 164 resolveAttachmentView->unref(gpu); |
164 msaaResource->unref(gpu); | 165 GrVkImage::DestroyImageInfo(gpu, &msInfo); |
165 } | 166 } |
166 return NULL; | 167 return nullptr; |
167 } | 168 } |
168 | 169 |
169 GrVkRenderTarget* texRT; | 170 GrVkRenderTarget* texRT; |
170 if (msaaResource) { | 171 if (desc.fSampleCnt) { |
171 texRT = new GrVkRenderTarget(gpu, budgeted, desc, imageResource, msaaRes
ource, | 172 texRT = new GrVkRenderTarget(gpu, budgeted, desc, info, msInfo, |
172 colorAttachmentView, resolveAttachmentView)
; | 173 colorAttachmentView, resolveAttachmentView,
wrapped); |
173 msaaResource->unref(gpu); | |
174 } else { | 174 } else { |
175 texRT = new GrVkRenderTarget(gpu, budgeted, desc, imageResource, | 175 texRT = new GrVkRenderTarget(gpu, budgeted, desc, info, colorAttachmentV
iew, wrapped); |
176 colorAttachmentView); | |
177 } | 176 } |
178 | 177 |
179 return texRT; | 178 return texRT; |
180 } | 179 } |
181 | 180 |
182 GrVkRenderTarget* | 181 GrVkRenderTarget* |
183 GrVkRenderTarget::CreateNewRenderTarget(GrVkGpu* gpu, | 182 GrVkRenderTarget::CreateNewRenderTarget(GrVkGpu* gpu, |
184 SkBudgeted budgeted, | 183 SkBudgeted budgeted, |
185 const GrSurfaceDesc& desc, | 184 const GrSurfaceDesc& desc, |
186 const GrVkImage::ImageDesc& imageDesc) { | 185 const GrVkImage::ImageDesc& imageDesc) { |
187 SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); | 186 SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
188 | 187 |
189 const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, im
ageDesc); | 188 GrVkImageInfo info; |
190 if (!imageResource) { | 189 if (!GrVkImage::InitImageInfo(gpu, imageDesc, &info)) { |
191 return nullptr; | 190 return nullptr; |
192 } | 191 } |
193 | 192 |
194 GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, budgeted, desc, imageRe
source); | 193 GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, budgeted, desc, info, |
195 // Create() will increment the refCount of the image resource if it succeeds | 194 GrVkImage::kNot_Wrapped); |
196 imageResource->unref(gpu); | 195 if (!rt) { |
| 196 GrVkImage::DestroyImageInfo(gpu, &info); |
| 197 } |
197 return rt; | 198 return rt; |
198 } | 199 } |
199 | 200 |
200 GrVkRenderTarget* | 201 GrVkRenderTarget* |
201 GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu, | 202 GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu, |
202 const GrSurfaceDesc& desc, | 203 const GrSurfaceDesc& desc, |
203 GrWrapOwnership ownership, | 204 GrWrapOwnership ownership, |
204 const GrVkTextureInfo* info) { | 205 const GrVkImageInfo* info) { |
205 SkASSERT(info); | 206 SkASSERT(info); |
206 // We can wrap a rendertarget without its allocation, as long as we don't ta
ke ownership | 207 // We can wrap a rendertarget without its allocation, as long as we don't ta
ke ownership |
207 SkASSERT(VK_NULL_HANDLE != info->fImage); | 208 SkASSERT(VK_NULL_HANDLE != info->fImage); |
208 SkASSERT(VK_NULL_HANDLE != info->fAlloc || kAdopt_GrWrapOwnership != ownersh
ip); | 209 SkASSERT(VK_NULL_HANDLE != info->fAlloc || kAdopt_GrWrapOwnership != ownersh
ip); |
209 | 210 |
210 GrVkImage::Resource::Flags flags = (VK_IMAGE_TILING_LINEAR == info->fImageTi
ling) | 211 GrVkImage::Wrapped wrapped = kBorrow_GrWrapOwnership == ownership ? GrVkImag
e::kBorrowed_Wrapped |
211 ? Resource::kLinearTiling_Flag : Resource::
kNo_Flags; | 212 : GrVkImag
e::kAdopted_Wrapped; |
212 | 213 |
213 const GrVkImage::Resource* imageResource; | 214 GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, SkBudgeted::kNo, desc,
*info, wrapped); |
214 if (kBorrow_GrWrapOwnership == ownership) { | |
215 imageResource = new GrVkImage::BorrowedResource(info->fImage, | |
216 info->fAlloc, | |
217 info->fFormat, | |
218 info->fLevelCount, | |
219 flags); | |
220 } else { | |
221 imageResource = new GrVkImage::Resource(info->fImage, info->fAlloc, info
->fFormat, | |
222 info->fLevelCount, flags); | |
223 } | |
224 if (!imageResource) { | |
225 return nullptr; | |
226 } | |
227 | |
228 GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, SkBudgeted::kNo, desc,
imageResource); | |
229 if (rt) { | |
230 rt->fCurrentLayout = info->fImageLayout; | |
231 } | |
232 // Create() will increment the refCount of the image resource if it succeeds | |
233 imageResource->unref(gpu); | |
234 | 215 |
235 return rt; | 216 return rt; |
236 } | 217 } |
237 | 218 |
238 bool GrVkRenderTarget::completeStencilAttachment() { | 219 bool GrVkRenderTarget::completeStencilAttachment() { |
239 this->createFramebuffer(this->getVkGpu()); | 220 this->createFramebuffer(this->getVkGpu()); |
240 return true; | 221 return true; |
241 } | 222 } |
242 | 223 |
243 void GrVkRenderTarget::createFramebuffer(GrVkGpu* gpu) { | 224 void GrVkRenderTarget::createFramebuffer(GrVkGpu* gpu) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // Currently in vulkan stencil and color attachments must all have same
number of samples | 266 // Currently in vulkan stencil and color attachments must all have same
number of samples |
286 SkASSERT(desc->fColor.fSamples == desc->fStencil.fSamples); | 267 SkASSERT(desc->fColor.fSamples == desc->fStencil.fSamples); |
287 *attachmentFlags |= GrVkRenderPass::kStencil_AttachmentFlag; | 268 *attachmentFlags |= GrVkRenderPass::kStencil_AttachmentFlag; |
288 ++attachmentCount; | 269 ++attachmentCount; |
289 } | 270 } |
290 desc->fAttachmentCount = attachmentCount; | 271 desc->fAttachmentCount = attachmentCount; |
291 } | 272 } |
292 | 273 |
293 GrVkRenderTarget::~GrVkRenderTarget() { | 274 GrVkRenderTarget::~GrVkRenderTarget() { |
294 // either release or abandon should have been called by the owner of this ob
ject. | 275 // either release or abandon should have been called by the owner of this ob
ject. |
295 SkASSERT(!fMSAAImageResource); | 276 SkASSERT(!fMSAAImage); |
296 SkASSERT(!fResolveAttachmentView); | 277 SkASSERT(!fResolveAttachmentView); |
297 SkASSERT(!fColorAttachmentView); | 278 SkASSERT(!fColorAttachmentView); |
298 SkASSERT(!fFramebuffer); | 279 SkASSERT(!fFramebuffer); |
299 SkASSERT(!fCachedSimpleRenderPass); | 280 SkASSERT(!fCachedSimpleRenderPass); |
300 } | 281 } |
301 | 282 |
302 void GrVkRenderTarget::addResources(GrVkCommandBuffer& commandBuffer) const { | 283 void GrVkRenderTarget::addResources(GrVkCommandBuffer& commandBuffer) const { |
303 commandBuffer.addResource(this->framebuffer()); | 284 commandBuffer.addResource(this->framebuffer()); |
304 commandBuffer.addResource(this->resource()); | 285 commandBuffer.addResource(this->resource()); |
305 commandBuffer.addResource(this->colorAttachmentView()); | 286 commandBuffer.addResource(this->colorAttachmentView()); |
306 if (this->msaaImageResource()) { | 287 if (this->msaaImageResource()) { |
307 commandBuffer.addResource(this->msaaImageResource()); | 288 commandBuffer.addResource(this->msaaImageResource()); |
308 commandBuffer.addResource(this->resolveAttachmentView()); | 289 commandBuffer.addResource(this->resolveAttachmentView()); |
309 } | 290 } |
310 if (this->stencilImageResource()) { | 291 if (this->stencilImageResource()) { |
311 commandBuffer.addResource(this->stencilImageResource()); | 292 commandBuffer.addResource(this->stencilImageResource()); |
312 commandBuffer.addResource(this->stencilAttachmentView()); | 293 commandBuffer.addResource(this->stencilAttachmentView()); |
313 } | 294 } |
314 } | 295 } |
315 | 296 |
316 void GrVkRenderTarget::releaseInternalObjects() { | 297 void GrVkRenderTarget::releaseInternalObjects() { |
317 GrVkGpu* gpu = this->getVkGpu(); | 298 GrVkGpu* gpu = this->getVkGpu(); |
318 | 299 |
319 if (fMSAAImageResource) { | 300 if (fMSAAImage) { |
320 fMSAAImageResource->unref(gpu); | 301 fMSAAImage->releaseImage(gpu); |
321 fMSAAImageResource = nullptr; | 302 fMSAAImage = nullptr; |
322 } | 303 } |
323 | 304 |
324 if (fResolveAttachmentView) { | 305 if (fResolveAttachmentView) { |
325 fResolveAttachmentView->unref(gpu); | 306 fResolveAttachmentView->unref(gpu); |
326 fResolveAttachmentView = nullptr; | 307 fResolveAttachmentView = nullptr; |
327 } | 308 } |
328 if (fColorAttachmentView) { | 309 if (fColorAttachmentView) { |
329 fColorAttachmentView->unref(gpu); | 310 fColorAttachmentView->unref(gpu); |
330 fColorAttachmentView = nullptr; | 311 fColorAttachmentView = nullptr; |
331 } | 312 } |
332 if (fFramebuffer) { | 313 if (fFramebuffer) { |
333 fFramebuffer->unref(gpu); | 314 fFramebuffer->unref(gpu); |
334 fFramebuffer = nullptr; | 315 fFramebuffer = nullptr; |
335 } | 316 } |
336 if (fCachedSimpleRenderPass) { | 317 if (fCachedSimpleRenderPass) { |
337 fCachedSimpleRenderPass->unref(gpu); | 318 fCachedSimpleRenderPass->unref(gpu); |
338 fCachedSimpleRenderPass = nullptr; | 319 fCachedSimpleRenderPass = nullptr; |
339 } | 320 } |
340 } | 321 } |
341 | 322 |
342 void GrVkRenderTarget::abandonInternalObjects() { | 323 void GrVkRenderTarget::abandonInternalObjects() { |
343 if (fMSAAImageResource) { | 324 if (fMSAAImage) { |
344 fMSAAImageResource->unrefAndAbandon(); | 325 fMSAAImage->abandonImage(); |
345 fMSAAImageResource = nullptr; | 326 fMSAAImage = nullptr; |
346 } | 327 } |
347 | 328 |
348 if (fResolveAttachmentView) { | 329 if (fResolveAttachmentView) { |
349 fResolveAttachmentView->unrefAndAbandon(); | 330 fResolveAttachmentView->unrefAndAbandon(); |
350 fResolveAttachmentView = nullptr; | 331 fResolveAttachmentView = nullptr; |
351 } | 332 } |
352 if (fColorAttachmentView) { | 333 if (fColorAttachmentView) { |
353 fColorAttachmentView->unrefAndAbandon(); | 334 fColorAttachmentView->unrefAndAbandon(); |
354 fColorAttachmentView = nullptr; | 335 fColorAttachmentView = nullptr; |
355 } | 336 } |
(...skipping 18 matching lines...) Expand all Loading... |
374 this->abandonImage(); | 355 this->abandonImage(); |
375 GrRenderTarget::onAbandon(); | 356 GrRenderTarget::onAbandon(); |
376 } | 357 } |
377 | 358 |
378 | 359 |
379 GrBackendObject GrVkRenderTarget::getRenderTargetHandle() const { | 360 GrBackendObject GrVkRenderTarget::getRenderTargetHandle() const { |
380 // Currently just passing back the pointer to the main Image::Resource as th
e handle | 361 // Currently just passing back the pointer to the main Image::Resource as th
e handle |
381 return (GrBackendObject)&fResource; | 362 return (GrBackendObject)&fResource; |
382 } | 363 } |
383 | 364 |
384 const GrVkImage::Resource* GrVkRenderTarget::stencilImageResource() const { | 365 const GrVkResource* GrVkRenderTarget::stencilImageResource() const { |
385 const GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAtta
chment(); | 366 const GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAtta
chment(); |
386 if (stencil) { | 367 if (stencil) { |
387 const GrVkStencilAttachment* vkStencil = static_cast<const GrVkStencilAt
tachment*>(stencil); | 368 const GrVkStencilAttachment* vkStencil = static_cast<const GrVkStencilAt
tachment*>(stencil); |
388 return vkStencil->imageResource(); | 369 return vkStencil->imageResource(); |
389 } | 370 } |
390 | 371 |
391 return nullptr; | 372 return nullptr; |
392 } | 373 } |
393 | 374 |
394 const GrVkImageView* GrVkRenderTarget::stencilAttachmentView() const { | 375 const GrVkImageView* GrVkRenderTarget::stencilAttachmentView() const { |
395 const GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAtta
chment(); | 376 const GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAtta
chment(); |
396 if (stencil) { | 377 if (stencil) { |
397 const GrVkStencilAttachment* vkStencil = static_cast<const GrVkStencilAt
tachment*>(stencil); | 378 const GrVkStencilAttachment* vkStencil = static_cast<const GrVkStencilAt
tachment*>(stencil); |
398 return vkStencil->stencilView(); | 379 return vkStencil->stencilView(); |
399 } | 380 } |
400 | 381 |
401 return nullptr; | 382 return nullptr; |
402 } | 383 } |
403 | 384 |
404 | 385 |
405 GrVkGpu* GrVkRenderTarget::getVkGpu() const { | 386 GrVkGpu* GrVkRenderTarget::getVkGpu() const { |
406 SkASSERT(!this->wasDestroyed()); | 387 SkASSERT(!this->wasDestroyed()); |
407 return static_cast<GrVkGpu*>(this->getGpu()); | 388 return static_cast<GrVkGpu*>(this->getGpu()); |
408 } | 389 } |
OLD | NEW |