Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/vk/GrVkImage.h" |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 9 | |
| 10 | #include "src/gpu/vk/GrVkGpu.h" |
| 11 | #include "src/gpu/vk/GrVkImageView.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/vk/GrVkMemory.h" |
| 13 | #include "src/gpu/vk/GrVkTexture.h" |
| 14 | #include "src/gpu/vk/GrVkUtil.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 15 | |
| 16 | #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) |
| 17 | |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 18 | sk_sp<GrVkImage> GrVkImage::MakeStencil(GrVkGpu* gpu, |
| 19 | SkISize dimensions, |
| 20 | int sampleCnt, |
| 21 | VkFormat format) { |
| 22 | VkImageUsageFlags vkUsageFlags = |
| 23 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 24 | return GrVkImage::Make(gpu, |
| 25 | dimensions, |
| 26 | UsageFlags::kStencilAttachment, |
| 27 | sampleCnt, |
| 28 | format, |
| 29 | /*mipLevels=*/1, |
| 30 | vkUsageFlags, |
| 31 | GrProtected::kNo, |
| 32 | SkBudgeted::kYes); |
| 33 | } |
| 34 | |
| 35 | sk_sp<GrVkImage> GrVkImage::MakeMSAA(GrVkGpu* gpu, |
| 36 | SkISize dimensions, |
| 37 | int numSamples, |
| 38 | VkFormat format, |
| 39 | GrProtected isProtected) { |
| 40 | SkASSERT(numSamples > 1); |
| 41 | |
| 42 | VkImageUsageFlags vkUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 43 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
| 44 | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 45 | return GrVkImage::Make(gpu, |
| 46 | dimensions, |
| 47 | UsageFlags::kColorAttachment, |
| 48 | numSamples, |
| 49 | format, |
| 50 | /*mipLevels=*/1, |
| 51 | vkUsageFlags, |
| 52 | isProtected, |
| 53 | SkBudgeted::kYes); |
| 54 | } |
| 55 | |
| 56 | sk_sp<GrVkImage> GrVkImage::MakeTexture(GrVkGpu* gpu, |
| 57 | SkISize dimensions, |
| 58 | VkFormat format, |
| 59 | uint32_t mipLevels, |
| 60 | GrRenderable renderable, |
| 61 | int numSamples, |
| 62 | SkBudgeted budgeted, |
| 63 | GrProtected isProtected) { |
| 64 | UsageFlags usageFlags = UsageFlags::kTexture; |
| 65 | VkImageUsageFlags vkUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
| 66 | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 67 | if (renderable == GrRenderable::kYes) { |
| 68 | usageFlags |= UsageFlags::kColorAttachment; |
| 69 | vkUsageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 70 | // We always make our render targets support being used as input attachments |
| 71 | vkUsageFlags |= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; |
| 72 | } |
| 73 | |
| 74 | return GrVkImage::Make(gpu, |
| 75 | dimensions, |
| 76 | usageFlags, |
| 77 | numSamples, |
| 78 | format, |
| 79 | mipLevels, |
| 80 | vkUsageFlags, |
| 81 | isProtected, |
| 82 | budgeted); |
| 83 | } |
| 84 | |
| 85 | static bool make_views(GrVkGpu* gpu, |
| 86 | const GrVkImageInfo& info, |
| 87 | GrAttachment::UsageFlags attachmentUsages, |
| 88 | sk_sp<const GrVkImageView>* framebufferView, |
| 89 | sk_sp<const GrVkImageView>* textureView) { |
| 90 | GrVkImageView::Type viewType; |
| 91 | if (attachmentUsages & GrAttachment::UsageFlags::kStencilAttachment) { |
| 92 | // If we have stencil usage then we shouldn't have any other usages |
| 93 | SkASSERT(attachmentUsages == GrAttachment::UsageFlags::kStencilAttachment); |
| 94 | viewType = GrVkImageView::kStencil_Type; |
| 95 | } else { |
| 96 | viewType = GrVkImageView::kColor_Type; |
| 97 | } |
| 98 | |
| 99 | if (SkToBool(attachmentUsages & GrAttachment::UsageFlags::kStencilAttachment) || |
| 100 | SkToBool(attachmentUsages & GrAttachment::UsageFlags::kColorAttachment)) { |
| 101 | // Attachments can only have a mip level of 1 |
| 102 | *framebufferView = GrVkImageView::Make( |
| 103 | gpu, info.fImage, info.fFormat, viewType, 1, info.fYcbcrConversionInfo); |
| 104 | if (!*framebufferView) { |
| 105 | return false; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if (attachmentUsages & GrAttachment::UsageFlags::kTexture) { |
| 110 | *textureView = GrVkImageView::Make(gpu, |
| 111 | info.fImage, |
| 112 | info.fFormat, |
| 113 | viewType, |
| 114 | info.fLevelCount, |
| 115 | info.fYcbcrConversionInfo); |
| 116 | if (!*textureView) { |
| 117 | return false; |
| 118 | } |
| 119 | } |
| 120 | return true; |
| 121 | } |
| 122 | |
| 123 | sk_sp<GrVkImage> GrVkImage::Make(GrVkGpu* gpu, |
| 124 | SkISize dimensions, |
| 125 | UsageFlags attachmentUsages, |
| 126 | int sampleCnt, |
| 127 | VkFormat format, |
| 128 | uint32_t mipLevels, |
| 129 | VkImageUsageFlags vkUsageFlags, |
| 130 | GrProtected isProtected, |
| 131 | SkBudgeted budgeted) { |
| 132 | GrVkImage::ImageDesc imageDesc; |
| 133 | imageDesc.fImageType = VK_IMAGE_TYPE_2D; |
| 134 | imageDesc.fFormat = format; |
| 135 | imageDesc.fWidth = dimensions.width(); |
| 136 | imageDesc.fHeight = dimensions.height(); |
| 137 | imageDesc.fLevels = mipLevels; |
| 138 | imageDesc.fSamples = sampleCnt; |
| 139 | imageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL; |
| 140 | imageDesc.fUsageFlags = vkUsageFlags; |
| 141 | imageDesc.fIsProtected = isProtected; |
| 142 | |
| 143 | GrVkImageInfo info; |
| 144 | if (!GrVkImage::InitImageInfo(gpu, imageDesc, &info)) { |
| 145 | return nullptr; |
| 146 | } |
| 147 | |
| 148 | sk_sp<const GrVkImageView> framebufferView; |
| 149 | sk_sp<const GrVkImageView> textureView; |
| 150 | if (!make_views(gpu, info, attachmentUsages, &framebufferView, &textureView)) { |
| 151 | GrVkImage::DestroyImageInfo(gpu, &info); |
| 152 | return nullptr; |
| 153 | } |
| 154 | |
| 155 | sk_sp<GrBackendSurfaceMutableStateImpl> mutableState( |
| 156 | new GrBackendSurfaceMutableStateImpl(info.fImageLayout, info.fCurrentQueueFamily)); |
| 157 | return sk_sp<GrVkImage>(new GrVkImage(gpu, |
| 158 | dimensions, |
| 159 | attachmentUsages, |
| 160 | info, |
| 161 | std::move(mutableState), |
| 162 | std::move(framebufferView), |
| 163 | std::move(textureView), |
| 164 | budgeted)); |
| 165 | } |
| 166 | |
| 167 | sk_sp<GrVkImage> GrVkImage::MakeWrapped(GrVkGpu* gpu, |
| 168 | SkISize dimensions, |
| 169 | const GrVkImageInfo& info, |
| 170 | sk_sp<GrBackendSurfaceMutableStateImpl> mutableState, |
| 171 | UsageFlags attachmentUsages, |
| 172 | GrWrapOwnership ownership, |
| 173 | GrWrapCacheable cacheable, |
| 174 | bool forSecondaryCB) { |
| 175 | sk_sp<const GrVkImageView> framebufferView; |
| 176 | sk_sp<const GrVkImageView> textureView; |
| 177 | if (!forSecondaryCB) { |
| 178 | if (!make_views(gpu, info, attachmentUsages, &framebufferView, &textureView)) { |
| 179 | return nullptr; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | GrBackendObjectOwnership backendOwnership = kBorrow_GrWrapOwnership == ownership |
| 184 | ? GrBackendObjectOwnership::kBorrowed |
| 185 | : GrBackendObjectOwnership::kOwned; |
| 186 | |
| 187 | return sk_sp<GrVkImage>(new GrVkImage(gpu, |
| 188 | dimensions, |
| 189 | attachmentUsages, |
| 190 | info, |
| 191 | std::move(mutableState), |
| 192 | std::move(framebufferView), |
| 193 | std::move(textureView), |
| 194 | backendOwnership, |
| 195 | cacheable, |
| 196 | forSecondaryCB)); |
| 197 | } |
| 198 | |
| 199 | GrVkImage::GrVkImage(GrVkGpu* gpu, |
| 200 | SkISize dimensions, |
| 201 | UsageFlags supportedUsages, |
Greg Daniel | aa9d99f | 2020-06-02 11:10:41 -0400 | [diff] [blame] | 202 | const GrVkImageInfo& info, |
| 203 | sk_sp<GrBackendSurfaceMutableStateImpl> mutableState, |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 204 | sk_sp<const GrVkImageView> framebufferView, |
| 205 | sk_sp<const GrVkImageView> textureView, |
| 206 | SkBudgeted budgeted) |
| 207 | : GrAttachment(gpu, |
| 208 | dimensions, |
| 209 | supportedUsages, |
| 210 | info.fSampleCount, |
| 211 | info.fLevelCount > 1 ? GrMipmapped::kYes : GrMipmapped::kNo, |
| 212 | info.fProtected) |
| 213 | , fInfo(info) |
Greg Daniel | aa9d99f | 2020-06-02 11:10:41 -0400 | [diff] [blame] | 214 | , fInitialQueueFamily(info.fCurrentQueueFamily) |
| 215 | , fMutableState(std::move(mutableState)) |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 216 | , fFramebufferView(std::move(framebufferView)) |
| 217 | , fTextureView(std::move(textureView)) |
| 218 | , fIsBorrowed(false) { |
| 219 | this->init(gpu, false); |
| 220 | this->registerWithCache(budgeted); |
| 221 | } |
| 222 | |
| 223 | GrVkImage::GrVkImage(GrVkGpu* gpu, |
| 224 | SkISize dimensions, |
| 225 | UsageFlags supportedUsages, |
| 226 | const GrVkImageInfo& info, |
| 227 | sk_sp<GrBackendSurfaceMutableStateImpl> mutableState, |
| 228 | sk_sp<const GrVkImageView> framebufferView, |
| 229 | sk_sp<const GrVkImageView> textureView, |
| 230 | GrBackendObjectOwnership ownership, |
| 231 | GrWrapCacheable cacheable, |
| 232 | bool forSecondaryCB) |
| 233 | : GrAttachment(gpu, |
| 234 | dimensions, |
| 235 | supportedUsages, |
| 236 | info.fSampleCount, |
| 237 | info.fLevelCount > 1 ? GrMipmapped::kYes : GrMipmapped::kNo, |
| 238 | info.fProtected) |
| 239 | , fInfo(info) |
| 240 | , fInitialQueueFamily(info.fCurrentQueueFamily) |
| 241 | , fMutableState(std::move(mutableState)) |
| 242 | , fFramebufferView(std::move(framebufferView)) |
| 243 | , fTextureView(std::move(textureView)) |
Greg Daniel | aa9d99f | 2020-06-02 11:10:41 -0400 | [diff] [blame] | 244 | , fIsBorrowed(GrBackendObjectOwnership::kBorrowed == ownership) { |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 245 | this->init(gpu, forSecondaryCB); |
| 246 | this->registerWithCacheWrapped(cacheable); |
| 247 | } |
| 248 | |
| 249 | void GrVkImage::init(GrVkGpu* gpu, bool forSecondaryCB) { |
Greg Daniel | aa9d99f | 2020-06-02 11:10:41 -0400 | [diff] [blame] | 250 | SkASSERT(fMutableState->getImageLayout() == fInfo.fImageLayout); |
| 251 | SkASSERT(fMutableState->getQueueFamilyIndex() == fInfo.fCurrentQueueFamily); |
| 252 | #ifdef SK_DEBUG |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 253 | if (fInfo.fImageUsageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { |
| 254 | SkASSERT(SkToBool(fInfo.fImageUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT)); |
Greg Daniel | 7b62dca | 2020-08-21 11:26:12 -0400 | [diff] [blame] | 255 | } else { |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 256 | SkASSERT(SkToBool(fInfo.fImageUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) && |
| 257 | SkToBool(fInfo.fImageUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT)); |
Greg Daniel | 7b62dca | 2020-08-21 11:26:12 -0400 | [diff] [blame] | 258 | } |
Greg Daniel | aa9d99f | 2020-06-02 11:10:41 -0400 | [diff] [blame] | 259 | // We can't transfer from the non graphics queue to the graphics queue since we can't |
| 260 | // release the image from the original queue without having that queue. This limits us in terms |
| 261 | // of the types of queue indices we can handle. |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 262 | if (fInfo.fCurrentQueueFamily != VK_QUEUE_FAMILY_IGNORED && |
| 263 | fInfo.fCurrentQueueFamily != VK_QUEUE_FAMILY_EXTERNAL && |
| 264 | fInfo.fCurrentQueueFamily != VK_QUEUE_FAMILY_FOREIGN_EXT) { |
| 265 | if (fInfo.fSharingMode == VK_SHARING_MODE_EXCLUSIVE) { |
| 266 | if (fInfo.fCurrentQueueFamily != gpu->queueIndex()) { |
Greg Daniel | aa9d99f | 2020-06-02 11:10:41 -0400 | [diff] [blame] | 267 | SkASSERT(false); |
| 268 | } |
| 269 | } else { |
| 270 | SkASSERT(false); |
| 271 | } |
| 272 | } |
| 273 | #endif |
| 274 | if (forSecondaryCB) { |
| 275 | fResource = nullptr; |
| 276 | } else if (fIsBorrowed) { |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 277 | fResource = new BorrowedResource(gpu, fInfo.fImage, fInfo.fAlloc, fInfo.fImageTiling); |
Greg Daniel | aa9d99f | 2020-06-02 11:10:41 -0400 | [diff] [blame] | 278 | } else { |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 279 | SkASSERT(VK_NULL_HANDLE != fInfo.fAlloc.fMemory); |
| 280 | fResource = new Resource(gpu, fInfo.fImage, fInfo.fAlloc, fInfo.fImageTiling); |
Greg Daniel | aa9d99f | 2020-06-02 11:10:41 -0400 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
Greg Daniel | f7828d0 | 2018-10-09 12:01:32 -0400 | [diff] [blame] | 284 | VkPipelineStageFlags GrVkImage::LayoutToPipelineSrcStageFlags(const VkImageLayout layout) { |
Greg Daniel | 6ddbafc | 2018-05-24 12:34:29 -0400 | [diff] [blame] | 285 | if (VK_IMAGE_LAYOUT_GENERAL == layout) { |
| 286 | return VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 287 | } else if (VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == layout || |
| 288 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL == layout) { |
| 289 | return VK_PIPELINE_STAGE_TRANSFER_BIT; |
Greg Daniel | f7828d0 | 2018-10-09 12:01:32 -0400 | [diff] [blame] | 290 | } else if (VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL == layout) { |
| 291 | return VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; |
| 292 | } else if (VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL == layout || |
| 293 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL == layout) { |
| 294 | return VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; |
| 295 | } else if (VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == layout) { |
| 296 | return VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; |
Greg Daniel | 6ddbafc | 2018-05-24 12:34:29 -0400 | [diff] [blame] | 297 | } else if (VK_IMAGE_LAYOUT_PREINITIALIZED == layout) { |
| 298 | return VK_PIPELINE_STAGE_HOST_BIT; |
Ethan Nicholas | 03896ae | 2019-03-07 16:54:24 -0500 | [diff] [blame] | 299 | } else if (VK_IMAGE_LAYOUT_PRESENT_SRC_KHR == layout) { |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 300 | return VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; |
Greg Daniel | 6ddbafc | 2018-05-24 12:34:29 -0400 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | SkASSERT(VK_IMAGE_LAYOUT_UNDEFINED == layout); |
| 304 | return VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; |
| 305 | } |
| 306 | |
| 307 | VkAccessFlags GrVkImage::LayoutToSrcAccessMask(const VkImageLayout layout) { |
| 308 | // Currently we assume we will never being doing any explict shader writes (this doesn't include |
| 309 | // color attachment or depth/stencil writes). So we will ignore the |
| 310 | // VK_MEMORY_OUTPUT_SHADER_WRITE_BIT. |
| 311 | |
| 312 | // We can only directly access the host memory if we are in preinitialized or general layout, |
| 313 | // and the image is linear. |
| 314 | // TODO: Add check for linear here so we are not always adding host to general, and we should |
| 315 | // only be in preinitialized if we are linear |
Brian Salomon | 2335644 | 2018-11-30 15:33:19 -0500 | [diff] [blame] | 316 | VkAccessFlags flags = 0; |
Greg Daniel | 6ddbafc | 2018-05-24 12:34:29 -0400 | [diff] [blame] | 317 | if (VK_IMAGE_LAYOUT_GENERAL == layout) { |
| 318 | flags = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | |
| 319 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 320 | VK_ACCESS_TRANSFER_WRITE_BIT | |
Greg Daniel | b509bbb | 2020-10-02 13:30:41 -0400 | [diff] [blame] | 321 | VK_ACCESS_HOST_WRITE_BIT; |
Greg Daniel | 6ddbafc | 2018-05-24 12:34:29 -0400 | [diff] [blame] | 322 | } else if (VK_IMAGE_LAYOUT_PREINITIALIZED == layout) { |
| 323 | flags = VK_ACCESS_HOST_WRITE_BIT; |
| 324 | } else if (VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL == layout) { |
Greg Daniel | b509bbb | 2020-10-02 13:30:41 -0400 | [diff] [blame] | 325 | flags = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; |
Greg Daniel | 6ddbafc | 2018-05-24 12:34:29 -0400 | [diff] [blame] | 326 | } else if (VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL == layout) { |
| 327 | flags = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 328 | } else if (VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL == layout) { |
| 329 | flags = VK_ACCESS_TRANSFER_WRITE_BIT; |
Greg Daniel | ab79ff9 | 2019-03-29 09:48:05 -0400 | [diff] [blame] | 330 | } else if (VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == layout || |
| 331 | VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == layout || |
| 332 | VK_IMAGE_LAYOUT_PRESENT_SRC_KHR == layout) { |
| 333 | // There are no writes that need to be made available |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 334 | flags = 0; |
Greg Daniel | 6ddbafc | 2018-05-24 12:34:29 -0400 | [diff] [blame] | 335 | } |
| 336 | return flags; |
| 337 | } |
| 338 | |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 339 | VkImageAspectFlags vk_format_to_aspect_flags(VkFormat format) { |
| 340 | switch (format) { |
| 341 | case VK_FORMAT_S8_UINT: |
| 342 | return VK_IMAGE_ASPECT_STENCIL_BIT; |
| 343 | case VK_FORMAT_D24_UNORM_S8_UINT: // fallthrough |
| 344 | case VK_FORMAT_D32_SFLOAT_S8_UINT: |
| 345 | return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 346 | default: |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 347 | return VK_IMAGE_ASPECT_COLOR_BIT; |
| 348 | } |
| 349 | } |
| 350 | |
Greg Daniel | 7f3408b | 2020-06-03 13:31:00 -0400 | [diff] [blame] | 351 | void GrVkImage::setImageLayoutAndQueueIndex(const GrVkGpu* gpu, |
| 352 | VkImageLayout newLayout, |
| 353 | VkAccessFlags dstAccessMask, |
| 354 | VkPipelineStageFlags dstStageMask, |
| 355 | bool byRegion, |
| 356 | uint32_t newQueueFamilyIndex) { |
Greg Daniel | f0e04f0 | 2019-12-04 15:17:54 -0500 | [diff] [blame] | 357 | SkASSERT(!gpu->isDeviceLost()); |
Greg Daniel | 7f3408b | 2020-06-03 13:31:00 -0400 | [diff] [blame] | 358 | SkASSERT(newLayout == this->currentLayout() || |
| 359 | (VK_IMAGE_LAYOUT_UNDEFINED != newLayout && |
| 360 | VK_IMAGE_LAYOUT_PREINITIALIZED != newLayout)); |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 361 | VkImageLayout currentLayout = this->currentLayout(); |
Greg Daniel | 7f3408b | 2020-06-03 13:31:00 -0400 | [diff] [blame] | 362 | uint32_t currentQueueIndex = this->currentQueueFamilyIndex(); |
egdaniel | 19ff103 | 2016-08-31 10:13:08 -0700 | [diff] [blame] | 363 | |
Greg Daniel | 7f3408b | 2020-06-03 13:31:00 -0400 | [diff] [blame] | 364 | #ifdef SK_DEBUG |
| 365 | if (fInfo.fSharingMode == VK_SHARING_MODE_CONCURRENT) { |
| 366 | if (newQueueFamilyIndex == VK_QUEUE_FAMILY_IGNORED) { |
| 367 | SkASSERT(currentQueueIndex == VK_QUEUE_FAMILY_IGNORED || |
| 368 | currentQueueIndex == VK_QUEUE_FAMILY_EXTERNAL || |
| 369 | currentQueueIndex == VK_QUEUE_FAMILY_FOREIGN_EXT); |
| 370 | } else { |
| 371 | SkASSERT(newQueueFamilyIndex == VK_QUEUE_FAMILY_EXTERNAL || |
| 372 | newQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT); |
| 373 | SkASSERT(currentQueueIndex == VK_QUEUE_FAMILY_IGNORED); |
| 374 | } |
| 375 | } else { |
| 376 | SkASSERT(fInfo.fSharingMode == VK_SHARING_MODE_EXCLUSIVE); |
| 377 | if (newQueueFamilyIndex == VK_QUEUE_FAMILY_IGNORED || |
| 378 | currentQueueIndex == gpu->queueIndex()) { |
| 379 | SkASSERT(currentQueueIndex == VK_QUEUE_FAMILY_IGNORED || |
| 380 | currentQueueIndex == VK_QUEUE_FAMILY_EXTERNAL || |
| 381 | currentQueueIndex == VK_QUEUE_FAMILY_FOREIGN_EXT || |
| 382 | currentQueueIndex == gpu->queueIndex()); |
| 383 | } else if (newQueueFamilyIndex == VK_QUEUE_FAMILY_EXTERNAL || |
| 384 | newQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT) { |
| 385 | SkASSERT(currentQueueIndex == VK_QUEUE_FAMILY_IGNORED || |
| 386 | currentQueueIndex == gpu->queueIndex()); |
| 387 | } |
| 388 | } |
| 389 | #endif |
| 390 | |
| 391 | if (fInfo.fSharingMode == VK_SHARING_MODE_EXCLUSIVE) { |
| 392 | if (newQueueFamilyIndex == VK_QUEUE_FAMILY_IGNORED) { |
| 393 | newQueueFamilyIndex = gpu->queueIndex(); |
| 394 | } |
| 395 | if (currentQueueIndex == VK_QUEUE_FAMILY_IGNORED) { |
| 396 | currentQueueIndex = gpu->queueIndex(); |
| 397 | } |
Greg Daniel | ecddbc0 | 2018-08-30 16:39:34 -0400 | [diff] [blame] | 398 | } |
| 399 | |
Greg Daniel | a3b6a55 | 2017-03-21 09:48:44 -0400 | [diff] [blame] | 400 | // If the old and new layout are the same and the layout is a read only layout, there is no need |
Eric Karl | 3f219cb | 2019-03-22 17:46:55 -0700 | [diff] [blame] | 401 | // to put in a barrier unless we also need to switch queues. |
Greg Daniel | 7f3408b | 2020-06-03 13:31:00 -0400 | [diff] [blame] | 402 | if (newLayout == currentLayout && currentQueueIndex == newQueueFamilyIndex && |
Greg Daniel | a3b6a55 | 2017-03-21 09:48:44 -0400 | [diff] [blame] | 403 | (VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL == currentLayout || |
| 404 | VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == currentLayout || |
| 405 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == currentLayout)) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 406 | return; |
| 407 | } |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 408 | |
Greg Daniel | 6ddbafc | 2018-05-24 12:34:29 -0400 | [diff] [blame] | 409 | VkAccessFlags srcAccessMask = GrVkImage::LayoutToSrcAccessMask(currentLayout); |
Greg Daniel | f7828d0 | 2018-10-09 12:01:32 -0400 | [diff] [blame] | 410 | VkPipelineStageFlags srcStageMask = GrVkImage::LayoutToPipelineSrcStageFlags(currentLayout); |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 411 | |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 412 | VkImageAspectFlags aspectFlags = vk_format_to_aspect_flags(fInfo.fFormat); |
Greg Daniel | ecddbc0 | 2018-08-30 16:39:34 -0400 | [diff] [blame] | 413 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 414 | VkImageMemoryBarrier imageMemoryBarrier = { |
jvanverth | 2af0f1b | 2016-05-03 10:36:49 -0700 | [diff] [blame] | 415 | VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 416 | nullptr, // pNext |
Robert Phillips | d1d869d | 2019-06-07 14:21:31 -0400 | [diff] [blame] | 417 | srcAccessMask, // srcAccessMask |
| 418 | dstAccessMask, // dstAccessMask |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 419 | currentLayout, // oldLayout |
jvanverth | 2af0f1b | 2016-05-03 10:36:49 -0700 | [diff] [blame] | 420 | newLayout, // newLayout |
Greg Daniel | 7f3408b | 2020-06-03 13:31:00 -0400 | [diff] [blame] | 421 | currentQueueIndex, // srcQueueFamilyIndex |
| 422 | newQueueFamilyIndex, // dstQueueFamilyIndex |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 423 | fInfo.fImage, // image |
| 424 | { aspectFlags, 0, fInfo.fLevelCount, 0, 1 } // subresourceRange |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 425 | }; |
Greg Daniel | 9a18b08 | 2020-08-14 14:03:50 -0400 | [diff] [blame] | 426 | SkASSERT(srcAccessMask == imageMemoryBarrier.srcAccessMask); |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 427 | gpu->addImageMemoryBarrier(this->resource(), srcStageMask, dstStageMask, byRegion, |
| 428 | &imageMemoryBarrier); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 429 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 430 | this->updateImageLayout(newLayout); |
Greg Daniel | 7f3408b | 2020-06-03 13:31:00 -0400 | [diff] [blame] | 431 | this->setQueueFamilyIndex(newQueueFamilyIndex); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 432 | } |
| 433 | |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 434 | bool GrVkImage::InitImageInfo(GrVkGpu* gpu, const ImageDesc& imageDesc, GrVkImageInfo* info) { |
egdaniel | ab527a5 | 2016-06-28 08:07:26 -0700 | [diff] [blame] | 435 | if (0 == imageDesc.fWidth || 0 == imageDesc.fHeight) { |
| 436 | return false; |
| 437 | } |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 438 | if ((imageDesc.fIsProtected == GrProtected::kYes) && !gpu->vkCaps().supportsProtectedMemory()) { |
| 439 | return false; |
| 440 | } |
Robert Phillips | f62e575 | 2019-05-30 10:36:13 -0400 | [diff] [blame] | 441 | VkImage image = VK_NULL_HANDLE; |
jvanverth | 1e305ba | 2016-06-01 09:39:15 -0700 | [diff] [blame] | 442 | GrVkAlloc alloc; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 443 | |
jvanverth | 6b6ffc4 | 2016-06-13 14:28:07 -0700 | [diff] [blame] | 444 | bool isLinear = VK_IMAGE_TILING_LINEAR == imageDesc.fImageTiling; |
| 445 | VkImageLayout initialLayout = isLinear ? VK_IMAGE_LAYOUT_PREINITIALIZED |
| 446 | : VK_IMAGE_LAYOUT_UNDEFINED; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 447 | |
| 448 | // Create Image |
| 449 | VkSampleCountFlagBits vkSamples; |
| 450 | if (!GrSampleCountToVkSampleCount(imageDesc.fSamples, &vkSamples)) { |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 451 | return false; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 452 | } |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 453 | |
| 454 | SkASSERT(VK_IMAGE_TILING_OPTIMAL == imageDesc.fImageTiling || |
| 455 | VK_SAMPLE_COUNT_1_BIT == vkSamples); |
| 456 | |
Brian Salomon | 4456a0d | 2019-07-18 15:05:11 -0400 | [diff] [blame] | 457 | VkImageCreateFlags createflags = 0; |
| 458 | if (imageDesc.fIsProtected == GrProtected::kYes || gpu->protectedContext()) { |
| 459 | createflags |= VK_IMAGE_CREATE_PROTECTED_BIT; |
| 460 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 461 | const VkImageCreateInfo imageCreateInfo = { |
| 462 | VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // sType |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 463 | nullptr, // pNext |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 464 | createflags, // VkImageCreateFlags |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 465 | imageDesc.fImageType, // VkImageType |
| 466 | imageDesc.fFormat, // VkFormat |
| 467 | { imageDesc.fWidth, imageDesc.fHeight, 1 }, // VkExtent3D |
| 468 | imageDesc.fLevels, // mipLevels |
| 469 | 1, // arrayLayers |
| 470 | vkSamples, // samples |
| 471 | imageDesc.fImageTiling, // VkImageTiling |
| 472 | imageDesc.fUsageFlags, // VkImageUsageFlags |
| 473 | VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode |
| 474 | 0, // queueFamilyCount |
John Stiles | fe0de30 | 2020-08-14 10:52:06 -0400 | [diff] [blame] | 475 | nullptr, // pQueueFamilyIndices |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 476 | initialLayout // initialLayout |
| 477 | }; |
| 478 | |
Greg Daniel | 95f0b16 | 2019-11-11 13:42:30 -0500 | [diff] [blame] | 479 | VkResult result; |
| 480 | GR_VK_CALL_RESULT(gpu, result, CreateImage(gpu->device(), &imageCreateInfo, nullptr, &image)); |
| 481 | if (result != VK_SUCCESS) { |
| 482 | return false; |
| 483 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 484 | |
Greg Daniel | 6763e7c | 2021-09-07 10:46:22 -0400 | [diff] [blame] | 485 | if (!GrVkMemory::AllocAndBindImageMemory(gpu, image, &alloc)) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 486 | VK_CALL(gpu, DestroyImage(gpu->device(), image, nullptr)); |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 487 | return false; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 488 | } |
| 489 | |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 490 | info->fImage = image; |
| 491 | info->fAlloc = alloc; |
| 492 | info->fImageTiling = imageDesc.fImageTiling; |
| 493 | info->fImageLayout = initialLayout; |
| 494 | info->fFormat = imageDesc.fFormat; |
Greg Daniel | 7b62dca | 2020-08-21 11:26:12 -0400 | [diff] [blame] | 495 | info->fImageUsageFlags = imageDesc.fUsageFlags; |
Brian Salomon | 72c7b98 | 2020-10-06 10:07:38 -0400 | [diff] [blame] | 496 | info->fSampleCount = imageDesc.fSamples; |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 497 | info->fLevelCount = imageDesc.fLevels; |
Greg Daniel | ecddbc0 | 2018-08-30 16:39:34 -0400 | [diff] [blame] | 498 | info->fCurrentQueueFamily = VK_QUEUE_FAMILY_IGNORED; |
Brian Salomon | 4456a0d | 2019-07-18 15:05:11 -0400 | [diff] [blame] | 499 | info->fProtected = |
| 500 | (createflags & VK_IMAGE_CREATE_PROTECTED_BIT) ? GrProtected::kYes : GrProtected::kNo; |
Greg Daniel | aa9d99f | 2020-06-02 11:10:41 -0400 | [diff] [blame] | 501 | info->fSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 502 | return true; |
| 503 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 504 | |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 505 | void GrVkImage::DestroyImageInfo(const GrVkGpu* gpu, GrVkImageInfo* info) { |
| 506 | VK_CALL(gpu, DestroyImage(gpu->device(), info->fImage, nullptr)); |
Greg Daniel | 6763e7c | 2021-09-07 10:46:22 -0400 | [diff] [blame] | 507 | GrVkMemory::FreeImageMemory(gpu, info->fAlloc); |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 510 | GrVkImage::~GrVkImage() { |
Greg Daniel | f0e04f0 | 2019-12-04 15:17:54 -0500 | [diff] [blame] | 511 | // should have been released first |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 512 | SkASSERT(!fResource); |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 513 | SkASSERT(!fFramebufferView); |
| 514 | SkASSERT(!fTextureView); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 515 | } |
| 516 | |
Greg Daniel | bae7121 | 2019-03-01 15:24:35 -0500 | [diff] [blame] | 517 | void GrVkImage::prepareForPresent(GrVkGpu* gpu) { |
| 518 | VkImageLayout layout = this->currentLayout(); |
| 519 | if (fInitialQueueFamily != VK_QUEUE_FAMILY_EXTERNAL && |
| 520 | fInitialQueueFamily != VK_QUEUE_FAMILY_FOREIGN_EXT) { |
| 521 | if (gpu->vkCaps().supportsSwapchain()) { |
| 522 | layout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; |
| 523 | } |
| 524 | } |
Greg Daniel | 7f3408b | 2020-06-03 13:31:00 -0400 | [diff] [blame] | 525 | this->setImageLayoutAndQueueIndex(gpu, layout, 0, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, false, |
| 526 | fInitialQueueFamily); |
Greg Daniel | bae7121 | 2019-03-01 15:24:35 -0500 | [diff] [blame] | 527 | } |
| 528 | |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 529 | void GrVkImage::prepareForExternal(GrVkGpu* gpu) { |
Greg Daniel | 7f3408b | 2020-06-03 13:31:00 -0400 | [diff] [blame] | 530 | this->setImageLayoutAndQueueIndex(gpu, this->currentLayout(), 0, |
| 531 | VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, false, |
| 532 | fInitialQueueFamily); |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 533 | } |
| 534 | |
Greg Daniel | 03535f4 | 2020-06-05 14:18:42 -0400 | [diff] [blame] | 535 | void GrVkImage::releaseImage() { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 536 | if (fResource) { |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 537 | fResource->unref(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 538 | fResource = nullptr; |
| 539 | } |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 540 | fFramebufferView.reset(); |
| 541 | fTextureView.reset(); |
| 542 | fCachedBlendingInputDescSet.reset(); |
| 543 | fCachedMSAALoadInputDescSet.reset(); |
| 544 | } |
| 545 | |
| 546 | void GrVkImage::onRelease() { |
| 547 | this->releaseImage(); |
| 548 | GrAttachment::onRelease(); |
| 549 | } |
| 550 | |
| 551 | void GrVkImage::onAbandon() { |
| 552 | this->releaseImage(); |
| 553 | GrAttachment::onAbandon(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 554 | } |
| 555 | |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 556 | void GrVkImage::setResourceRelease(sk_sp<GrRefCntedCallback> releaseHelper) { |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 557 | SkASSERT(fResource); |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 558 | // Forward the release proc on to GrVkImage::Resource |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 559 | fResource->setRelease(std::move(releaseHelper)); |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 560 | } |
| 561 | |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 562 | void GrVkImage::Resource::freeGPUData() const { |
Brian Salomon | 8cabb32 | 2019-02-22 10:44:19 -0500 | [diff] [blame] | 563 | this->invokeReleaseProc(); |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 564 | VK_CALL(fGpu, DestroyImage(fGpu->device(), fImage, nullptr)); |
Greg Daniel | 6763e7c | 2021-09-07 10:46:22 -0400 | [diff] [blame] | 565 | GrVkMemory::FreeImageMemory(fGpu, fAlloc); |
jvanverth | 0fcfb75 | 2016-03-09 09:57:52 -0800 | [diff] [blame] | 566 | } |
jvanverth | fe170d2 | 2016-03-22 13:15:44 -0700 | [diff] [blame] | 567 | |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 568 | void GrVkImage::BorrowedResource::freeGPUData() const { |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 569 | this->invokeReleaseProc(); |
jvanverth | fe170d2 | 2016-03-22 13:15:44 -0700 | [diff] [blame] | 570 | } |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 571 | |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 572 | static void write_input_desc_set(GrVkGpu* gpu, |
| 573 | VkImageView view, |
| 574 | VkImageLayout layout, |
| 575 | VkDescriptorSet descSet) { |
| 576 | VkDescriptorImageInfo imageInfo; |
| 577 | memset(&imageInfo, 0, sizeof(VkDescriptorImageInfo)); |
| 578 | imageInfo.sampler = VK_NULL_HANDLE; |
| 579 | imageInfo.imageView = view; |
| 580 | imageInfo.imageLayout = layout; |
| 581 | |
| 582 | VkWriteDescriptorSet writeInfo; |
| 583 | memset(&writeInfo, 0, sizeof(VkWriteDescriptorSet)); |
| 584 | writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 585 | writeInfo.pNext = nullptr; |
| 586 | writeInfo.dstSet = descSet; |
| 587 | writeInfo.dstBinding = GrVkUniformHandler::kInputBinding; |
| 588 | writeInfo.dstArrayElement = 0; |
| 589 | writeInfo.descriptorCount = 1; |
| 590 | writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 591 | writeInfo.pImageInfo = &imageInfo; |
| 592 | writeInfo.pBufferInfo = nullptr; |
| 593 | writeInfo.pTexelBufferView = nullptr; |
| 594 | |
| 595 | GR_VK_CALL(gpu->vkInterface(), UpdateDescriptorSets(gpu->device(), 1, &writeInfo, 0, nullptr)); |
| 596 | } |
| 597 | |
| 598 | gr_rp<const GrVkDescriptorSet> GrVkImage::inputDescSetForBlending(GrVkGpu* gpu) { |
| 599 | if (!this->supportsInputAttachmentUsage()) { |
| 600 | return nullptr; |
| 601 | } |
| 602 | if (fCachedBlendingInputDescSet) { |
| 603 | return fCachedBlendingInputDescSet; |
| 604 | } |
| 605 | |
| 606 | fCachedBlendingInputDescSet.reset(gpu->resourceProvider().getInputDescriptorSet()); |
| 607 | if (!fCachedBlendingInputDescSet) { |
| 608 | return nullptr; |
| 609 | } |
| 610 | |
| 611 | write_input_desc_set(gpu, |
| 612 | this->framebufferView()->imageView(), |
| 613 | VK_IMAGE_LAYOUT_GENERAL, |
| 614 | *fCachedBlendingInputDescSet->descriptorSet()); |
| 615 | |
| 616 | return fCachedBlendingInputDescSet; |
| 617 | } |
| 618 | |
| 619 | gr_rp<const GrVkDescriptorSet> GrVkImage::inputDescSetForMSAALoad(GrVkGpu* gpu) { |
| 620 | if (!this->supportsInputAttachmentUsage()) { |
| 621 | return nullptr; |
| 622 | } |
| 623 | if (fCachedMSAALoadInputDescSet) { |
| 624 | return fCachedMSAALoadInputDescSet; |
| 625 | } |
| 626 | |
| 627 | fCachedMSAALoadInputDescSet.reset(gpu->resourceProvider().getInputDescriptorSet()); |
| 628 | if (!fCachedMSAALoadInputDescSet) { |
| 629 | return nullptr; |
| 630 | } |
| 631 | |
| 632 | write_input_desc_set(gpu, |
| 633 | this->framebufferView()->imageView(), |
| 634 | VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, |
| 635 | *fCachedMSAALoadInputDescSet->descriptorSet()); |
| 636 | |
| 637 | return fCachedMSAALoadInputDescSet; |
| 638 | } |
| 639 | |
| 640 | GrVkGpu* GrVkImage::getVkGpu() const { |
| 641 | SkASSERT(!this->wasDestroyed()); |
| 642 | return static_cast<GrVkGpu*>(this->getGpu()); |
| 643 | } |
| 644 | |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 645 | #if GR_TEST_UTILS |
| 646 | void GrVkImage::setCurrentQueueFamilyToGraphicsQueue(GrVkGpu* gpu) { |
Greg Daniel | 6c6caf4 | 2020-05-29 12:11:05 -0400 | [diff] [blame] | 647 | fMutableState->setQueueFamilyIndex(gpu->queueIndex()); |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 648 | } |
| 649 | #endif |
| 650 | |