| 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 "GrVkTextureRenderTarget.h" | 8 #include "GrVkTextureRenderTarget.h" |
| 9 | 9 |
| 10 #include "GrRenderTargetPriv.h" | 10 #include "GrRenderTargetPriv.h" |
| 11 #include "GrVkGpu.h" | 11 #include "GrVkGpu.h" |
| 12 #include "GrVkImageView.h" | 12 #include "GrVkImageView.h" |
| 13 #include "GrVkUtil.h" | 13 #include "GrVkUtil.h" |
| 14 | 14 |
| 15 #include "SkMipMap.h" | 15 #include "SkMipMap.h" |
| 16 | 16 |
| 17 #include "vk/GrVkTypes.h" | 17 #include "vk/GrVkTypes.h" |
| 18 | 18 |
| 19 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) | 19 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) |
| 20 | 20 |
| 21 GrVkTextureRenderTarget* GrVkTextureRenderTarget::Create(GrVkGpu* gpu, | 21 GrVkTextureRenderTarget* GrVkTextureRenderTarget::Create(GrVkGpu* gpu, |
| 22 const GrSurfaceDesc& de
sc, | 22 const GrSurfaceDesc& de
sc, |
| 23 const GrVkImageInfo& in
fo, | 23 const GrVkImageInfo& in
fo, |
| 24 SkBudgeted budgeted, | 24 SkBudgeted budgeted, |
| 25 GrVkImage::Wrapped wrap
ped) { | 25 GrVkImage::Wrapped wrap
ped) { |
| 26 VkImage image = info.fImage; | 26 VkImage image = info.fImage; |
| 27 // Create the texture ImageView | 27 // Create the texture ImageView |
| 28 uint32_t mipLevels = 1; | |
| 29 //TODO: does a mipmapped textureRenderTarget make sense? | |
| 30 //if (desc.fIsMipMapped) { | |
| 31 // mipLevels = SkMipMap::ComputeLevelCount(this->width(), this->height())
+ 1; | |
| 32 //} | |
| 33 const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, info.fFor
mat, | 28 const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, info.fFor
mat, |
| 34 GrVkImageView::kColor
_Type, mipLevels); | 29 GrVkImageView::kColor
_Type, |
| 30 info.fLevelCount); |
| 35 if (!imageView) { | 31 if (!imageView) { |
| 36 return nullptr; | 32 return nullptr; |
| 37 } | 33 } |
| 38 | 34 |
| 39 VkFormat pixelFormat; | 35 VkFormat pixelFormat; |
| 40 GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat); | 36 GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat); |
| 41 | 37 |
| 42 VkImage colorImage; | 38 VkImage colorImage; |
| 43 | 39 |
| 44 // create msaa surface if necessary | 40 // create msaa surface if necessary |
| (...skipping 11 matching lines...) Expand all Loading... |
| 56 msImageDesc.fUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; | 52 msImageDesc.fUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 57 msImageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; | 53 msImageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 58 | 54 |
| 59 if (!GrVkImage::InitImageInfo(gpu, msImageDesc, &msInfo)) { | 55 if (!GrVkImage::InitImageInfo(gpu, msImageDesc, &msInfo)) { |
| 60 return nullptr; | 56 return nullptr; |
| 61 } | 57 } |
| 62 | 58 |
| 63 // Set color attachment image | 59 // Set color attachment image |
| 64 colorImage = msInfo.fImage; | 60 colorImage = msInfo.fImage; |
| 65 | 61 |
| 66 // Create resolve attachment view if necessary. | 62 // Create resolve attachment view. |
| 67 // If the format matches, this is the same as the texture imageView. | 63 resolveAttachmentView = GrVkImageView::Create(gpu, image, pixelFormat, |
| 68 if (pixelFormat == info.fFormat) { | 64 GrVkImageView::kColor_Type
, |
| 69 resolveAttachmentView = imageView; | 65 info.fLevelCount); |
| 70 resolveAttachmentView->ref(); | 66 if (!resolveAttachmentView) { |
| 71 } else { | 67 GrVkImage::DestroyImageInfo(gpu, &msInfo); |
| 72 resolveAttachmentView = GrVkImageView::Create(gpu, image, pixelForma
t, | 68 imageView->unref(gpu); |
| 73 GrVkImageView::kColor_
Type, 1); | 69 return nullptr; |
| 74 if (!resolveAttachmentView) { | |
| 75 GrVkImage::DestroyImageInfo(gpu, &msInfo); | |
| 76 imageView->unref(gpu); | |
| 77 return nullptr; | |
| 78 } | |
| 79 } | 70 } |
| 80 } else { | 71 } else { |
| 81 // Set color attachment image | 72 // Set color attachment image |
| 82 colorImage = info.fImage; | 73 colorImage = info.fImage; |
| 83 } | 74 } |
| 84 | 75 |
| 85 const GrVkImageView* colorAttachmentView; | 76 const GrVkImageView* colorAttachmentView = GrVkImageView::Create(gpu, colorI
mage, pixelFormat, |
| 86 // Get color attachment view. | 77 GrVkImageVi
ew::kColor_Type, 1); |
| 87 // If the format matches and there's no multisampling, | 78 if (!colorAttachmentView) { |
| 88 // this is the same as the texture imageView | 79 if (desc.fSampleCnt) { |
| 89 if (pixelFormat == info.fFormat && !resolveAttachmentView) { | 80 resolveAttachmentView->unref(gpu); |
| 90 colorAttachmentView = imageView; | 81 GrVkImage::DestroyImageInfo(gpu, &msInfo); |
| 91 colorAttachmentView->ref(); | |
| 92 } else { | |
| 93 colorAttachmentView = GrVkImageView::Create(gpu, colorImage, pixelFormat
, | |
| 94 GrVkImageView::kColor_Type,
1); | |
| 95 if (!colorAttachmentView) { | |
| 96 if (desc.fSampleCnt) { | |
| 97 resolveAttachmentView->unref(gpu); | |
| 98 GrVkImage::DestroyImageInfo(gpu, &msInfo); | |
| 99 } | |
| 100 imageView->unref(gpu); | |
| 101 return nullptr; | |
| 102 } | 82 } |
| 83 imageView->unref(gpu); |
| 84 return nullptr; |
| 103 } | 85 } |
| 86 |
| 104 GrVkTextureRenderTarget* texRT; | 87 GrVkTextureRenderTarget* texRT; |
| 105 if (desc.fSampleCnt) { | 88 if (desc.fSampleCnt) { |
| 106 if (GrVkImage::kNot_Wrapped == wrapped) { | 89 if (GrVkImage::kNot_Wrapped == wrapped) { |
| 107 texRT = new GrVkTextureRenderTarget(gpu, budgeted, desc, | 90 texRT = new GrVkTextureRenderTarget(gpu, budgeted, desc, |
| 108 info, imageView, msInfo, | 91 info, imageView, msInfo, |
| 109 colorAttachmentView, | 92 colorAttachmentView, |
| 110 resolveAttachmentView); | 93 resolveAttachmentView); |
| 111 } else { | 94 } else { |
| 112 texRT = new GrVkTextureRenderTarget(gpu, desc, | 95 texRT = new GrVkTextureRenderTarget(gpu, desc, |
| 113 info, imageView, msInfo, | 96 info, imageView, msInfo, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // Wrapped textures require both image and allocation (because they can be m
apped) | 141 // Wrapped textures require both image and allocation (because they can be m
apped) |
| 159 SkASSERT(VK_NULL_HANDLE != info->fImage && VK_NULL_HANDLE != info->fAlloc.fM
emory); | 142 SkASSERT(VK_NULL_HANDLE != info->fImage && VK_NULL_HANDLE != info->fAlloc.fM
emory); |
| 160 | 143 |
| 161 GrVkImage::Wrapped wrapped = kBorrow_GrWrapOwnership == ownership ? GrVkImag
e::kBorrowed_Wrapped | 144 GrVkImage::Wrapped wrapped = kBorrow_GrWrapOwnership == ownership ? GrVkImag
e::kBorrowed_Wrapped |
| 162 : GrVkImag
e::kAdopted_Wrapped; | 145 : GrVkImag
e::kAdopted_Wrapped; |
| 163 | 146 |
| 164 GrVkTextureRenderTarget* trt = Create(gpu, desc, *info, SkBudgeted::kNo, wra
pped); | 147 GrVkTextureRenderTarget* trt = Create(gpu, desc, *info, SkBudgeted::kNo, wra
pped); |
| 165 | 148 |
| 166 return trt; | 149 return trt; |
| 167 } | 150 } |
| 151 |
| 152 bool GrVkTextureRenderTarget::updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo&
newInfo) { |
| 153 VkFormat pixelFormat; |
| 154 GrPixelConfigToVkFormat(fDesc.fConfig, &pixelFormat); |
| 155 if (fDesc.fSampleCnt) { |
| 156 const GrVkImageView* resolveAttachmentView = |
| 157 GrVkImageView::Create(gpu, |
| 158 newInfo.fImage, |
| 159 pixelFormat, |
| 160 GrVkImageView::kColor_Type, |
| 161 newInfo.fLevelCount); |
| 162 if (!resolveAttachmentView) { |
| 163 return false; |
| 164 } |
| 165 fResolveAttachmentView->unref(gpu); |
| 166 fResolveAttachmentView = resolveAttachmentView; |
| 167 } else { |
| 168 const GrVkImageView* colorAttachmentView = GrVkImageView::Create(gpu, |
| 169 newInfo
.fImage, |
| 170 pixelFo
rmat, |
| 171 GrVkIma
geView::kColor_Type, |
| 172 1); |
| 173 if (!colorAttachmentView) { |
| 174 return false; |
| 175 } |
| 176 fColorAttachmentView->unref(gpu); |
| 177 fColorAttachmentView = colorAttachmentView; |
| 178 } |
| 179 |
| 180 this->createFramebuffer(gpu); |
| 181 return true; |
| 182 } |
| 183 |
| OLD | NEW |