Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
| 8 | // This is a GPU-backend specific test. It relies on static intializers to work |
| 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkTypes.h" |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 11 | |
Brian Osman | c7ad40f | 2018-05-31 14:27:17 -0400 | [diff] [blame] | 12 | #if defined(SK_VULKAN) |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 13 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/gpu/vk/GrVkVulkan.h" |
Greg Daniel | 54bfb18 | 2018-11-20 17:12:36 -0500 | [diff] [blame] | 15 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "tests/Test.h" |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 17 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "include/core/SkImage.h" |
| 19 | #include "include/gpu/GrBackendSurface.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "include/gpu/vk/GrVkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrContextPriv.h" |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrRenderTargetContext.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 23 | #include "src/gpu/GrTexture.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 24 | #include "src/gpu/GrTextureProxy.h" |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 25 | #include "src/gpu/SkGpuDevice.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 26 | #include "src/gpu/vk/GrVkGpu.h" |
| 27 | #include "src/gpu/vk/GrVkImageLayout.h" |
| 28 | #include "src/gpu/vk/GrVkTexture.h" |
| 29 | #include "src/image/SkImage_Base.h" |
Greg Daniel | 7c90211 | 2020-03-06 13:07:10 -0500 | [diff] [blame] | 30 | #include "src/image/SkImage_GpuBase.h" |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 31 | #include "src/image/SkSurface_Gpu.h" |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 32 | |
| 33 | DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) { |
| 34 | GrContext* context = ctxInfo.grContext(); |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 35 | |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 36 | GrBackendTexture backendTex = context->createBackendTexture(1, 1, |
| 37 | kRGBA_8888_SkColorType, |
| 38 | SkColors::kTransparent, |
| 39 | GrMipMapped::kNo, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 40 | GrRenderable::kNo, |
| 41 | GrProtected::kNo); |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 42 | REPORTER_ASSERT(reporter, backendTex.isValid()); |
| 43 | |
| 44 | GrVkImageInfo info; |
| 45 | REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info)); |
| 46 | VkImageLayout initLayout = info.fImageLayout; |
| 47 | |
| 48 | // Verify that setting that layout via a copy of a backendTexture is reflected in all the |
| 49 | // backendTextures. |
| 50 | GrBackendTexture backendTexCopy = backendTex; |
| 51 | REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info)); |
| 52 | REPORTER_ASSERT(reporter, initLayout == info.fImageLayout); |
| 53 | |
| 54 | backendTexCopy.setVkImageLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); |
| 55 | |
| 56 | REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info)); |
| 57 | REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout); |
| 58 | |
| 59 | REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info)); |
| 60 | REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout); |
| 61 | |
| 62 | // Setting back the layout since we didn't actually change it |
| 63 | backendTex.setVkImageLayout(initLayout); |
| 64 | |
| 65 | sk_sp<SkImage> wrappedImage = SkImage::MakeFromTexture(context, backendTex, |
| 66 | kTopLeft_GrSurfaceOrigin, |
| 67 | kRGBA_8888_SkColorType, |
| 68 | kPremul_SkAlphaType, nullptr); |
| 69 | REPORTER_ASSERT(reporter, wrappedImage.get()); |
| 70 | |
Greg Daniel | febdedf | 2020-02-05 17:06:27 -0500 | [diff] [blame] | 71 | const GrSurfaceProxyView* view = as_IB(wrappedImage)->view(context); |
| 72 | REPORTER_ASSERT(reporter, view); |
| 73 | REPORTER_ASSERT(reporter, view->proxy()->isInstantiated()); |
| 74 | GrTexture* texture = view->proxy()->peekTexture(); |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 75 | REPORTER_ASSERT(reporter, texture); |
| 76 | |
| 77 | // Verify that modifying the layout via the GrVkTexture is reflected in the GrBackendTexture |
| 78 | GrVkTexture* vkTexture = static_cast<GrVkTexture*>(texture); |
| 79 | REPORTER_ASSERT(reporter, initLayout == vkTexture->currentLayout()); |
| 80 | vkTexture->updateImageLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); |
| 81 | |
| 82 | REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info)); |
| 83 | REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == info.fImageLayout); |
| 84 | |
| 85 | GrBackendTexture backendTexImage = wrappedImage->getBackendTexture(false); |
| 86 | REPORTER_ASSERT(reporter, backendTexImage.getVkImageInfo(&info)); |
| 87 | REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == info.fImageLayout); |
| 88 | |
| 89 | // Verify that modifying the layout via the GrBackendTexutre is reflected in the GrVkTexture |
| 90 | backendTexImage.setVkImageLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); |
| 91 | REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL == vkTexture->currentLayout()); |
| 92 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 93 | vkTexture->updateImageLayout(initLayout); |
| 94 | |
| 95 | REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info)); |
| 96 | REPORTER_ASSERT(reporter, initLayout == info.fImageLayout); |
| 97 | |
| 98 | REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info)); |
| 99 | REPORTER_ASSERT(reporter, initLayout == info.fImageLayout); |
| 100 | |
| 101 | REPORTER_ASSERT(reporter, backendTexImage.getVkImageInfo(&info)); |
| 102 | REPORTER_ASSERT(reporter, initLayout == info.fImageLayout); |
| 103 | |
| 104 | // Check that we can do things like assigning the backend texture to invalid one, assign an |
| 105 | // invalid one, assin a backend texture to inself etc. Success here is that we don't hit any of |
| 106 | // our ref counting asserts. |
| 107 | REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex, backendTexCopy)); |
| 108 | |
| 109 | GrBackendTexture invalidTexture; |
| 110 | REPORTER_ASSERT(reporter, !invalidTexture.isValid()); |
| 111 | REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTexCopy)); |
| 112 | |
| 113 | backendTexCopy = invalidTexture; |
| 114 | REPORTER_ASSERT(reporter, !backendTexCopy.isValid()); |
| 115 | REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTexCopy)); |
| 116 | |
| 117 | invalidTexture = backendTex; |
| 118 | REPORTER_ASSERT(reporter, invalidTexture.isValid()); |
| 119 | REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex)); |
| 120 | |
Ben Wagner | ff134f2 | 2018-04-24 16:29:16 -0400 | [diff] [blame] | 121 | invalidTexture = static_cast<decltype(invalidTexture)&>(invalidTexture); |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 122 | REPORTER_ASSERT(reporter, invalidTexture.isValid()); |
| 123 | REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, invalidTexture)); |
| 124 | |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 125 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 128 | static void testing_release_proc(void* ctx) { |
| 129 | int* count = (int*)ctx; |
| 130 | *count += 1; |
| 131 | } |
| 132 | |
| 133 | // Test to make sure we don't call our release proc on an image until we've transferred it back to |
| 134 | // its original queue family. |
| 135 | DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkReleaseExternalQueueTest, reporter, ctxInfo) { |
| 136 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 137 | GrGpu* gpu = context->priv().getGpu(); |
| 138 | GrVkGpu* vkGpu = static_cast<GrVkGpu*>(gpu); |
| 139 | if (!vkGpu->vkCaps().supportsExternalMemory()) { |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 140 | return; |
| 141 | } |
| 142 | |
| 143 | for (bool useExternal : {false, true}) { |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 144 | GrBackendTexture backendTex = context->createBackendTexture(1, 1, |
| 145 | kRGBA_8888_SkColorType, |
| 146 | SkColors::kTransparent, |
| 147 | GrMipMapped::kNo, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 148 | GrRenderable::kNo, |
| 149 | GrProtected::kNo); |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 150 | sk_sp<SkImage> image; |
| 151 | int count = 0; |
| 152 | if (useExternal) { |
| 153 | // Make a backend texture with an external queue family; |
| 154 | GrVkImageInfo vkInfo; |
| 155 | if (!backendTex.getVkImageInfo(&vkInfo)) { |
| 156 | return; |
| 157 | } |
| 158 | vkInfo.fCurrentQueueFamily = VK_QUEUE_FAMILY_EXTERNAL; |
| 159 | |
| 160 | GrBackendTexture vkExtTex(1, 1, vkInfo); |
| 161 | REPORTER_ASSERT(reporter, vkExtTex.isValid()); |
| 162 | image = SkImage::MakeFromTexture(context, vkExtTex, |
| 163 | kTopLeft_GrSurfaceOrigin, |
| 164 | kRGBA_8888_SkColorType, |
| 165 | kPremul_SkAlphaType, |
| 166 | nullptr, testing_release_proc, |
| 167 | (void*)&count); |
| 168 | |
| 169 | } else { |
| 170 | image = SkImage::MakeFromTexture(context, backendTex, |
| 171 | kTopLeft_GrSurfaceOrigin, |
| 172 | kRGBA_8888_SkColorType, |
| 173 | kPremul_SkAlphaType, |
| 174 | nullptr, testing_release_proc, |
| 175 | (void*)&count); |
| 176 | } |
| 177 | |
| 178 | if (!image) { |
| 179 | continue; |
| 180 | } |
| 181 | |
| 182 | REPORTER_ASSERT(reporter, !count); |
| 183 | |
Greg Daniel | 7c90211 | 2020-03-06 13:07:10 -0500 | [diff] [blame] | 184 | SkImage_GpuBase* gpuImage = static_cast<SkImage_GpuBase*>(as_IB(image)); |
| 185 | GrTexture* texture = gpuImage->getTexture(); |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 186 | REPORTER_ASSERT(reporter, texture); |
| 187 | GrVkTexture* vkTex = static_cast<GrVkTexture*>(texture); |
| 188 | |
| 189 | if (useExternal) { |
| 190 | // Testing helper so we claim that we don't need to transition from our fake external |
| 191 | // queue first. |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 192 | vkTex->setCurrentQueueFamilyToGraphicsQueue(vkGpu); |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | image.reset(); |
| 196 | |
| 197 | // Resetting the image should only trigger the release proc if we are not using an external |
| 198 | // queue. When using an external queue when we free the SkImage and the underlying |
| 199 | // GrTexture, we submit a queue transition on the command buffer. |
| 200 | if (useExternal) { |
| 201 | REPORTER_ASSERT(reporter, !count); |
| 202 | } else { |
| 203 | REPORTER_ASSERT(reporter, count == 1); |
| 204 | } |
| 205 | |
| 206 | gpu->testingOnly_flushGpuAndSync(); |
| 207 | |
| 208 | // Now that we flushed and waited the release proc should have be triggered. |
| 209 | REPORTER_ASSERT(reporter, count == 1); |
| 210 | |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 211 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 215 | // Test to make sure we transition to the original queue when requests for prepareforexternalio are |
| 216 | // in flush calls |
| 217 | DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkPrepareForExternalIOQueueTransitionTest, reporter, ctxInfo) { |
| 218 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9b16f81 | 2019-05-17 10:01:21 -0400 | [diff] [blame] | 219 | |
| 220 | GrVkGpu* vkGpu = static_cast<GrVkGpu*>(context->priv().getGpu()); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 221 | if (!vkGpu->vkCaps().supportsExternalMemory()) { |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 222 | return; |
| 223 | } |
| 224 | |
| 225 | for (bool useSurface : {false, true}) { |
| 226 | for (bool preparePresent : {false, true}) { |
| 227 | if (!useSurface && preparePresent) { |
| 228 | // We don't set textures to present |
| 229 | continue; |
| 230 | } |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 231 | GrBackendTexture backendTex = context->createBackendTexture( |
Robert Phillips | 8062679 | 2019-06-04 07:16:10 -0400 | [diff] [blame] | 232 | 4, 4, kRGBA_8888_SkColorType, |
| 233 | SkColors::kTransparent, GrMipMapped::kNo, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 234 | useSurface ? GrRenderable::kYes : GrRenderable::kNo, |
| 235 | GrProtected::kNo); |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 236 | |
| 237 | // Make a backend texture with an external queue family and general layout. |
| 238 | GrVkImageInfo vkInfo; |
| 239 | if (!backendTex.getVkImageInfo(&vkInfo)) { |
| 240 | return; |
| 241 | } |
| 242 | |
| 243 | // We can't actually make an external texture in our test. However, we lie and say it is |
| 244 | // and then will manually go and swap the queue to the graphics queue once we wrap it. |
| 245 | if (preparePresent) { |
| 246 | // We don't transition to present to things that are going to external for foreign |
| 247 | // queues. |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 248 | vkInfo.fCurrentQueueFamily = vkGpu->queueIndex(); |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 249 | } else { |
| 250 | vkInfo.fCurrentQueueFamily = VK_QUEUE_FAMILY_EXTERNAL; |
| 251 | } |
| 252 | |
| 253 | GrBackendTexture vkExtTex(1, 1, vkInfo); |
| 254 | |
| 255 | sk_sp<SkImage> image; |
| 256 | sk_sp<SkSurface> surface; |
| 257 | GrTexture* texture; |
| 258 | if (useSurface) { |
| 259 | surface = SkSurface::MakeFromBackendTexture(context, vkExtTex, |
| 260 | kTopLeft_GrSurfaceOrigin, 0, kRGBA_8888_SkColorType, nullptr, nullptr); |
| 261 | REPORTER_ASSERT(reporter, surface.get()); |
| 262 | if (!surface) { |
| 263 | continue; |
| 264 | } |
| 265 | SkSurface_Gpu* gpuSurface = static_cast<SkSurface_Gpu*>(surface.get()); |
| 266 | auto* rtc = gpuSurface->getDevice()->accessRenderTargetContext(); |
| 267 | texture = rtc->asTextureProxy()->peekTexture(); |
| 268 | } else { |
| 269 | image = SkImage::MakeFromTexture(context, vkExtTex, kTopLeft_GrSurfaceOrigin, |
| 270 | kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr, nullptr, nullptr); |
| 271 | |
| 272 | REPORTER_ASSERT(reporter, image.get()); |
| 273 | if (!image) { |
| 274 | continue; |
| 275 | } |
| 276 | |
Greg Daniel | 7c90211 | 2020-03-06 13:07:10 -0500 | [diff] [blame] | 277 | SkImage_GpuBase* gpuImage = static_cast<SkImage_GpuBase*>(as_IB(image)); |
| 278 | texture = gpuImage->getTexture(); |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | REPORTER_ASSERT(reporter, texture); |
| 282 | GrVkTexture* vkTex = static_cast<GrVkTexture*>(texture); |
| 283 | |
| 284 | // Testing helper so we claim that we don't need to transition from our fake external |
| 285 | // queue first. |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 286 | vkTex->setCurrentQueueFamilyToGraphicsQueue(vkGpu); |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 287 | |
| 288 | GrBackendTexture newBackendTexture; |
| 289 | if (useSurface) { |
| 290 | newBackendTexture = surface->getBackendTexture( |
| 291 | SkSurface::kFlushRead_TextureHandleAccess); |
| 292 | } else { |
| 293 | newBackendTexture = image->getBackendTexture(false); |
| 294 | } |
| 295 | GrVkImageInfo newVkInfo; |
| 296 | REPORTER_ASSERT(reporter, newBackendTexture.getVkImageInfo(&newVkInfo)); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 297 | REPORTER_ASSERT(reporter, newVkInfo.fCurrentQueueFamily == vkGpu->queueIndex()); |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 298 | VkImageLayout oldLayout = newVkInfo.fImageLayout; |
| 299 | |
| 300 | GrPrepareForExternalIORequests externalRequests; |
| 301 | SkImage* imagePtr; |
| 302 | SkSurface* surfacePtr; |
| 303 | if (useSurface) { |
| 304 | externalRequests.fNumSurfaces = 1; |
| 305 | surfacePtr = surface.get(); |
| 306 | externalRequests.fSurfaces = &surfacePtr; |
| 307 | externalRequests.fPrepareSurfaceForPresent = &preparePresent; |
| 308 | } else { |
| 309 | externalRequests.fNumImages = 1; |
| 310 | imagePtr = image.get(); |
| 311 | externalRequests.fImages = &imagePtr; |
| 312 | |
| 313 | } |
| 314 | context->flush(GrFlushInfo(), externalRequests); |
| 315 | |
| 316 | if (useSurface) { |
| 317 | newBackendTexture = surface->getBackendTexture( |
| 318 | SkSurface::kFlushRead_TextureHandleAccess); |
| 319 | } else { |
| 320 | newBackendTexture = image->getBackendTexture(false); |
| 321 | } |
| 322 | REPORTER_ASSERT(reporter, newBackendTexture.getVkImageInfo(&newVkInfo)); |
| 323 | if (preparePresent) { |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 324 | REPORTER_ASSERT(reporter, newVkInfo.fCurrentQueueFamily == vkGpu->queueIndex()); |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 325 | REPORTER_ASSERT(reporter, |
| 326 | newVkInfo.fImageLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR); |
| 327 | } else { |
| 328 | REPORTER_ASSERT(reporter, newVkInfo.fCurrentQueueFamily == VK_QUEUE_FAMILY_EXTERNAL); |
| 329 | REPORTER_ASSERT(reporter, newVkInfo.fImageLayout == oldLayout); |
| 330 | } |
| 331 | |
| 332 | GrFlushInfo flushInfo; |
| 333 | flushInfo.fFlags = kSyncCpu_GrFlushFlag; |
| 334 | context->flush(flushInfo); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 335 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
Greg Daniel | eed7d63 | 2019-06-26 13:48:12 -0400 | [diff] [blame] | 340 | // This test is disabled because it executes illegal vulkan calls which cause the validations layers |
| 341 | // to fail and makes us assert. Once fixed to use a valid vulkan call sequence it should be |
| 342 | // renenabled, see skbug.com/8936. |
| 343 | #if 0 |
Eric Karl | 3f219cb | 2019-03-22 17:46:55 -0700 | [diff] [blame] | 344 | // Test to make sure we transition from the EXTERNAL queue even when no layout transition is needed. |
| 345 | DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkTransitionExternalQueueTest, reporter, ctxInfo) { |
| 346 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 347 | GrGpu* gpu = context->priv().getGpu(); |
| 348 | GrVkGpu* vkGpu = static_cast<GrVkGpu*>(gpu); |
| 349 | if (!vkGpu->vkCaps().supportsExternalMemory()) { |
Eric Karl | 3f219cb | 2019-03-22 17:46:55 -0700 | [diff] [blame] | 350 | return; |
| 351 | } |
| 352 | |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 353 | GrBackendTexture backendTex = context->createBackendTexture( |
Robert Phillips | 8062679 | 2019-06-04 07:16:10 -0400 | [diff] [blame] | 354 | 1, 1, kRGBA_8888_SkColorType, |
| 355 | SkColors::kTransparent, GrMipMapped::kNo, GrRenderable::kNo); |
Eric Karl | 3f219cb | 2019-03-22 17:46:55 -0700 | [diff] [blame] | 356 | sk_sp<SkImage> image; |
| 357 | // Make a backend texture with an external queue family and general layout. |
| 358 | GrVkImageInfo vkInfo; |
| 359 | if (!backendTex.getVkImageInfo(&vkInfo)) { |
| 360 | return; |
| 361 | } |
| 362 | vkInfo.fCurrentQueueFamily = VK_QUEUE_FAMILY_EXTERNAL; |
| 363 | // Use a read-only layout as these are the ones where we can otherwise skip a transition. |
| 364 | vkInfo.fImageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 365 | |
| 366 | GrBackendTexture vkExtTex(1, 1, vkInfo); |
| 367 | REPORTER_ASSERT(reporter, vkExtTex.isValid()); |
| 368 | image = SkImage::MakeFromTexture(context, vkExtTex, kTopLeft_GrSurfaceOrigin, |
| 369 | kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr, nullptr, |
| 370 | nullptr); |
| 371 | |
| 372 | if (!image) { |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | GrTexture* texture = image->getTexture(); |
| 377 | REPORTER_ASSERT(reporter, texture); |
| 378 | GrVkTexture* vkTex = static_cast<GrVkTexture*>(texture); |
| 379 | |
| 380 | // Change our backend texture to the internal queue, with the same layout. This should force a |
| 381 | // queue transition even though the layouts match. |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 382 | vkTex->setImageLayout(vkGpu, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0, |
Eric Karl | 3f219cb | 2019-03-22 17:46:55 -0700 | [diff] [blame] | 383 | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, false, false); |
| 384 | |
| 385 | // Get our image info again and make sure we transitioned queues. |
| 386 | GrBackendTexture newBackendTexture = image->getBackendTexture(true); |
| 387 | GrVkImageInfo newVkInfo; |
| 388 | REPORTER_ASSERT(reporter, newBackendTexture.getVkImageInfo(&newVkInfo)); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 389 | REPORTER_ASSERT(reporter, newVkInfo.fCurrentQueueFamily == vkGpu->queueIndex()); |
Eric Karl | 3f219cb | 2019-03-22 17:46:55 -0700 | [diff] [blame] | 390 | |
| 391 | image.reset(); |
| 392 | gpu->testingOnly_flushGpuAndSync(); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 393 | context->deleteBackendTexture(backendTex); |
Eric Karl | 3f219cb | 2019-03-22 17:46:55 -0700 | [diff] [blame] | 394 | } |
Greg Daniel | eed7d63 | 2019-06-26 13:48:12 -0400 | [diff] [blame] | 395 | #endif |
Eric Karl | 3f219cb | 2019-03-22 17:46:55 -0700 | [diff] [blame] | 396 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 397 | #endif |