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" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 232 |
233 // Vulkan requires us to create a compatible renderpass before we can create
our framebuffer, | 233 // Vulkan requires us to create a compatible renderpass before we can create
our framebuffer, |
234 // so we use this to get a (cached) basic renderpass, only for creation. | 234 // so we use this to get a (cached) basic renderpass, only for creation. |
235 fCachedSimpleRenderPass = | 235 fCachedSimpleRenderPass = |
236 gpu->resourceProvider().findCompatibleRenderPass(*this, &fCompatibleRPHa
ndle); | 236 gpu->resourceProvider().findCompatibleRenderPass(*this, &fCompatibleRPHa
ndle); |
237 | 237 |
238 // Stencil attachment view is stored in the base RT stencil attachment | 238 // Stencil attachment view is stored in the base RT stencil attachment |
239 const GrVkImageView* stencilView = this->stencilAttachmentView(); | 239 const GrVkImageView* stencilView = this->stencilAttachmentView(); |
240 fFramebuffer = GrVkFramebuffer::Create(gpu, this->width(), this->height(), | 240 fFramebuffer = GrVkFramebuffer::Create(gpu, this->width(), this->height(), |
241 fCachedSimpleRenderPass, fColorAttach
mentView, | 241 fCachedSimpleRenderPass, fColorAttach
mentView, |
242 fResolveAttachmentView, stencilView); | 242 stencilView); |
243 SkASSERT(fFramebuffer); | 243 SkASSERT(fFramebuffer); |
244 } | 244 } |
245 | 245 |
246 void GrVkRenderTarget::getAttachmentsDescriptor( | 246 void GrVkRenderTarget::getAttachmentsDescriptor( |
247 GrVkRenderPass::AttachmentsDescriptor
* desc, | 247 GrVkRenderPass::AttachmentsDescriptor
* desc, |
248 GrVkRenderPass::AttachmentFlags* atta
chmentFlags) const { | 248 GrVkRenderPass::AttachmentFlags* atta
chmentFlags) const { |
249 int colorSamples = this->numColorSamples(); | 249 int colorSamples = this->numColorSamples(); |
250 VkFormat colorFormat; | 250 VkFormat colorFormat; |
251 GrPixelConfigToVkFormat(this->config(), &colorFormat); | 251 GrPixelConfigToVkFormat(this->config(), &colorFormat); |
252 desc->fColor.fFormat = colorFormat; | 252 desc->fColor.fFormat = colorFormat; |
253 desc->fColor.fSamples = colorSamples ? colorSamples : 1; | 253 desc->fColor.fSamples = colorSamples ? colorSamples : 1; |
254 *attachmentFlags = GrVkRenderPass::kColor_AttachmentFlag; | 254 *attachmentFlags = GrVkRenderPass::kColor_AttachmentFlag; |
255 uint32_t attachmentCount = 1; | 255 uint32_t attachmentCount = 1; |
256 if (colorSamples > 0) { | |
257 desc->fResolve.fFormat = colorFormat; | |
258 desc->fResolve.fSamples = 1; | |
259 *attachmentFlags |= GrVkRenderPass::kResolve_AttachmentFlag; | |
260 ++attachmentCount; | |
261 } | |
262 | 256 |
263 const GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAtta
chment(); | 257 const GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAtta
chment(); |
264 if (stencil) { | 258 if (stencil) { |
265 const GrVkStencilAttachment* vkStencil = static_cast<const GrVkStencilAt
tachment*>(stencil); | 259 const GrVkStencilAttachment* vkStencil = static_cast<const GrVkStencilAt
tachment*>(stencil); |
266 desc->fStencil.fFormat = vkStencil->vkFormat(); | 260 desc->fStencil.fFormat = vkStencil->vkFormat(); |
267 desc->fStencil.fSamples = vkStencil->numSamples() ? vkStencil->numSample
s() : 1; | 261 desc->fStencil.fSamples = vkStencil->numSamples() ? vkStencil->numSample
s() : 1; |
268 // Currently in vulkan stencil and color attachments must all have same
number of samples | 262 // Currently in vulkan stencil and color attachments must all have same
number of samples |
269 SkASSERT(desc->fColor.fSamples == desc->fStencil.fSamples); | 263 SkASSERT(desc->fColor.fSamples == desc->fStencil.fSamples); |
270 *attachmentFlags |= GrVkRenderPass::kStencil_AttachmentFlag; | 264 *attachmentFlags |= GrVkRenderPass::kStencil_AttachmentFlag; |
271 ++attachmentCount; | 265 ++attachmentCount; |
272 } | 266 } |
273 desc->fAttachmentCount = attachmentCount; | 267 desc->fAttachmentCount = attachmentCount; |
274 } | 268 } |
275 | 269 |
276 GrVkRenderTarget::~GrVkRenderTarget() { | 270 GrVkRenderTarget::~GrVkRenderTarget() { |
277 // either release or abandon should have been called by the owner of this ob
ject. | 271 // either release or abandon should have been called by the owner of this ob
ject. |
278 SkASSERT(!fMSAAImage); | 272 SkASSERT(!fMSAAImage); |
279 SkASSERT(!fResolveAttachmentView); | 273 SkASSERT(!fResolveAttachmentView); |
280 SkASSERT(!fColorAttachmentView); | 274 SkASSERT(!fColorAttachmentView); |
281 SkASSERT(!fFramebuffer); | 275 SkASSERT(!fFramebuffer); |
282 SkASSERT(!fCachedSimpleRenderPass); | 276 SkASSERT(!fCachedSimpleRenderPass); |
283 } | 277 } |
284 | 278 |
285 void GrVkRenderTarget::addResources(GrVkCommandBuffer& commandBuffer) const { | 279 void GrVkRenderTarget::addResources(GrVkCommandBuffer& commandBuffer) const { |
286 commandBuffer.addResource(this->framebuffer()); | 280 commandBuffer.addResource(this->framebuffer()); |
287 commandBuffer.addResource(this->resource()); | |
288 commandBuffer.addResource(this->colorAttachmentView()); | 281 commandBuffer.addResource(this->colorAttachmentView()); |
289 if (this->msaaImageResource()) { | 282 commandBuffer.addResource(this->msaaImageResource() ? this->msaaImageResourc
e() |
290 commandBuffer.addResource(this->msaaImageResource()); | 283 : this->resource()); |
291 commandBuffer.addResource(this->resolveAttachmentView()); | |
292 } | |
293 if (this->stencilImageResource()) { | 284 if (this->stencilImageResource()) { |
294 commandBuffer.addResource(this->stencilImageResource()); | 285 commandBuffer.addResource(this->stencilImageResource()); |
295 commandBuffer.addResource(this->stencilAttachmentView()); | 286 commandBuffer.addResource(this->stencilAttachmentView()); |
296 } | 287 } |
297 } | 288 } |
298 | 289 |
299 void GrVkRenderTarget::releaseInternalObjects() { | 290 void GrVkRenderTarget::releaseInternalObjects() { |
300 GrVkGpu* gpu = this->getVkGpu(); | 291 GrVkGpu* gpu = this->getVkGpu(); |
301 | 292 |
302 if (fMSAAImage) { | 293 if (fMSAAImage) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 373 } |
383 | 374 |
384 return nullptr; | 375 return nullptr; |
385 } | 376 } |
386 | 377 |
387 | 378 |
388 GrVkGpu* GrVkRenderTarget::getVkGpu() const { | 379 GrVkGpu* GrVkRenderTarget::getVkGpu() const { |
389 SkASSERT(!this->wasDestroyed()); | 380 SkASSERT(!this->wasDestroyed()); |
390 return static_cast<GrVkGpu*>(this->getGpu()); | 381 return static_cast<GrVkGpu*>(this->getGpu()); |
391 } | 382 } |
OLD | NEW |