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 | |
| 8 | #include "GrVkGpu.h" |
| 9 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 10 | #include "GrBackendSurface.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 11 | #include "GrContextOptions.h" |
| 12 | #include "GrGeometryProcessor.h" |
| 13 | #include "GrGpuResourceCacheAccess.h" |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 14 | #include "GrMesh.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 15 | #include "GrPipeline.h" |
| 16 | #include "GrRenderTargetPriv.h" |
| 17 | #include "GrSurfacePriv.h" |
| 18 | #include "GrTexturePriv.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 19 | |
| 20 | #include "GrVkCommandBuffer.h" |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 21 | #include "GrVkGpuCommandBuffer.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 22 | #include "GrVkImage.h" |
| 23 | #include "GrVkIndexBuffer.h" |
| 24 | #include "GrVkMemory.h" |
| 25 | #include "GrVkPipeline.h" |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 26 | #include "GrVkPipelineState.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 27 | #include "GrVkRenderPass.h" |
| 28 | #include "GrVkResourceProvider.h" |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 29 | #include "GrVkSemaphore.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 30 | #include "GrVkTexture.h" |
| 31 | #include "GrVkTextureRenderTarget.h" |
| 32 | #include "GrVkTransferBuffer.h" |
| 33 | #include "GrVkVertexBuffer.h" |
| 34 | |
Matt Sarett | 485c499 | 2017-02-14 14:18:27 -0500 | [diff] [blame] | 35 | #include "SkConvertPixels.h" |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 36 | #include "SkMipMap.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 37 | |
| 38 | #include "vk/GrVkInterface.h" |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 39 | #include "vk/GrVkTypes.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 40 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 41 | #include "SkSLCompiler.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 42 | |
Forrest Reiling | 44f8571 | 2017-03-27 23:22:20 -0700 | [diff] [blame] | 43 | #if !defined(SK_BUILD_FOR_WIN) |
| 44 | #include <unistd.h> |
| 45 | #endif // !defined(SK_BUILD_FOR_WIN) |
| 46 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 47 | #define VK_CALL(X) GR_VK_CALL(this->vkInterface(), X) |
| 48 | #define VK_CALL_RET(RET, X) GR_VK_CALL_RET(this->vkInterface(), RET, X) |
| 49 | #define VK_CALL_ERRCHECK(X) GR_VK_CALL_ERRCHECK(this->vkInterface(), X) |
| 50 | |
egdaniel | 735109c | 2016-07-27 08:03:57 -0700 | [diff] [blame] | 51 | #ifdef SK_ENABLE_VK_LAYERS |
jvanverth | d2497f3 | 2016-03-18 12:39:05 -0700 | [diff] [blame] | 52 | VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback( |
| 53 | VkDebugReportFlagsEXT flags, |
| 54 | VkDebugReportObjectTypeEXT objectType, |
| 55 | uint64_t object, |
| 56 | size_t location, |
| 57 | int32_t messageCode, |
| 58 | const char* pLayerPrefix, |
| 59 | const char* pMessage, |
| 60 | void* pUserData) { |
| 61 | if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) { |
| 62 | SkDebugf("Vulkan error [%s]: code: %d: %s\n", pLayerPrefix, messageCode, pMessage); |
Jim Van Verth | ce3fe23 | 2016-11-11 09:41:04 -0800 | [diff] [blame] | 63 | return VK_TRUE; // skip further layers |
jvanverth | d2497f3 | 2016-03-18 12:39:05 -0700 | [diff] [blame] | 64 | } else if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) { |
| 65 | SkDebugf("Vulkan warning [%s]: code: %d: %s\n", pLayerPrefix, messageCode, pMessage); |
| 66 | } else if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) { |
| 67 | SkDebugf("Vulkan perf warning [%s]: code: %d: %s\n", pLayerPrefix, messageCode, pMessage); |
| 68 | } else { |
| 69 | SkDebugf("Vulkan info/debug [%s]: code: %d: %s\n", pLayerPrefix, messageCode, pMessage); |
| 70 | } |
| 71 | return VK_FALSE; |
| 72 | } |
jvanverth | d2497f3 | 2016-03-18 12:39:05 -0700 | [diff] [blame] | 73 | #endif |
| 74 | |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 75 | GrGpu* GrVkGpu::Create(GrBackendContext backendContext, const GrContextOptions& options, |
| 76 | GrContext* context) { |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 77 | const GrVkBackendContext* vkBackendContext = |
| 78 | reinterpret_cast<const GrVkBackendContext*>(backendContext); |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 79 | if (!vkBackendContext) { |
Brian Salomon | c188982 | 2017-04-24 16:49:05 -0400 | [diff] [blame] | 80 | return nullptr; |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 81 | } else { |
| 82 | vkBackendContext->ref(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 83 | } |
| 84 | |
Greg Daniel | fe2965a | 2016-10-11 16:31:05 -0400 | [diff] [blame] | 85 | if (!vkBackendContext->fInterface->validate(vkBackendContext->fExtensions)) { |
| 86 | return nullptr; |
| 87 | } |
| 88 | |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 89 | return new GrVkGpu(context, options, vkBackendContext); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | //////////////////////////////////////////////////////////////////////////////// |
| 93 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 94 | GrVkGpu::GrVkGpu(GrContext* context, const GrContextOptions& options, |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 95 | const GrVkBackendContext* backendCtx) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 96 | : INHERITED(context) |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 97 | , fDevice(backendCtx->fDevice) |
| 98 | , fQueue(backendCtx->fQueue) |
| 99 | , fResourceProvider(this) { |
| 100 | fBackendContext.reset(backendCtx); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 101 | |
egdaniel | 735109c | 2016-07-27 08:03:57 -0700 | [diff] [blame] | 102 | #ifdef SK_ENABLE_VK_LAYERS |
brianosman | 419ca64 | 2016-05-04 08:19:44 -0700 | [diff] [blame] | 103 | fCallback = VK_NULL_HANDLE; |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 104 | if (backendCtx->fExtensions & kEXT_debug_report_GrVkExtensionFlag) { |
| 105 | // Setup callback creation information |
jvanverth | d2497f3 | 2016-03-18 12:39:05 -0700 | [diff] [blame] | 106 | VkDebugReportCallbackCreateInfoEXT callbackCreateInfo; |
| 107 | callbackCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; |
| 108 | callbackCreateInfo.pNext = nullptr; |
| 109 | callbackCreateInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | |
egdaniel | ef0c10c | 2016-04-07 07:51:22 -0700 | [diff] [blame] | 110 | VK_DEBUG_REPORT_WARNING_BIT_EXT | |
jvanverth | d2497f3 | 2016-03-18 12:39:05 -0700 | [diff] [blame] | 111 | //VK_DEBUG_REPORT_INFORMATION_BIT_EXT | |
| 112 | //VK_DEBUG_REPORT_DEBUG_BIT_EXT | |
egdaniel | b4aa362 | 2016-04-06 13:47:08 -0700 | [diff] [blame] | 113 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; |
jvanverth | d2497f3 | 2016-03-18 12:39:05 -0700 | [diff] [blame] | 114 | callbackCreateInfo.pfnCallback = &DebugReportCallback; |
| 115 | callbackCreateInfo.pUserData = nullptr; |
| 116 | |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 117 | // Register the callback |
jvanverth | a00980e | 2016-05-02 13:24:48 -0700 | [diff] [blame] | 118 | GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateDebugReportCallbackEXT( |
| 119 | backendCtx->fInstance, &callbackCreateInfo, nullptr, &fCallback)); |
jvanverth | d2497f3 | 2016-03-18 12:39:05 -0700 | [diff] [blame] | 120 | } |
| 121 | #endif |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 122 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 123 | fCompiler = new SkSL::Compiler(); |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 124 | |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 125 | fVkCaps.reset(new GrVkCaps(options, this->vkInterface(), backendCtx->fPhysicalDevice, |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 126 | backendCtx->fFeatures, backendCtx->fExtensions)); |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 127 | fCaps.reset(SkRef(fVkCaps.get())); |
| 128 | |
| 129 | VK_CALL(GetPhysicalDeviceMemoryProperties(backendCtx->fPhysicalDevice, &fPhysDevMemProps)); |
| 130 | |
| 131 | const VkCommandPoolCreateInfo cmdPoolInfo = { |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 132 | VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType |
| 133 | nullptr, // pNext |
| 134 | VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | |
| 135 | VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // CmdPoolCreateFlags |
| 136 | backendCtx->fGraphicsQueueIndex, // queueFamilyIndex |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 137 | }; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 138 | GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateCommandPool(fDevice, &cmdPoolInfo, nullptr, |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 139 | &fCmdPool)); |
| 140 | |
| 141 | // must call this after creating the CommandPool |
| 142 | fResourceProvider.init(); |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 143 | fCurrentCmdBuffer = fResourceProvider.findOrCreatePrimaryCommandBuffer(); |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 144 | SkASSERT(fCurrentCmdBuffer); |
| 145 | fCurrentCmdBuffer->begin(this); |
jvanverth | 6b6ffc4 | 2016-06-13 14:28:07 -0700 | [diff] [blame] | 146 | |
| 147 | // set up our heaps |
| 148 | fHeaps[kLinearImage_Heap].reset(new GrVkHeap(this, GrVkHeap::kSubAlloc_Strategy, 16*1024*1024)); |
Greg Daniel | 4f7d97c | 2017-04-26 15:10:00 -0400 | [diff] [blame] | 149 | fHeaps[kOptimalImage_Heap].reset(new GrVkHeap(this, GrVkHeap::kSubAlloc_Strategy, 64*1024*1024)); |
jvanverth | 6b6ffc4 | 2016-06-13 14:28:07 -0700 | [diff] [blame] | 150 | fHeaps[kSmallOptimalImage_Heap].reset(new GrVkHeap(this, GrVkHeap::kSubAlloc_Strategy, 2*1024*1024)); |
| 151 | fHeaps[kVertexBuffer_Heap].reset(new GrVkHeap(this, GrVkHeap::kSingleAlloc_Strategy, 0)); |
| 152 | fHeaps[kIndexBuffer_Heap].reset(new GrVkHeap(this, GrVkHeap::kSingleAlloc_Strategy, 0)); |
jvanverth | 4c6e47a | 2016-07-22 10:34:52 -0700 | [diff] [blame] | 153 | fHeaps[kUniformBuffer_Heap].reset(new GrVkHeap(this, GrVkHeap::kSubAlloc_Strategy, 256*1024)); |
jvanverth | 6b6ffc4 | 2016-06-13 14:28:07 -0700 | [diff] [blame] | 154 | fHeaps[kCopyReadBuffer_Heap].reset(new GrVkHeap(this, GrVkHeap::kSingleAlloc_Strategy, 0)); |
| 155 | fHeaps[kCopyWriteBuffer_Heap].reset(new GrVkHeap(this, GrVkHeap::kSubAlloc_Strategy, 16*1024*1024)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | GrVkGpu::~GrVkGpu() { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 159 | fCurrentCmdBuffer->end(this); |
| 160 | fCurrentCmdBuffer->unref(this); |
| 161 | |
| 162 | // wait for all commands to finish |
jvanverth | ddf9835 | 2016-03-21 11:46:00 -0700 | [diff] [blame] | 163 | fResourceProvider.checkCommandBuffers(); |
Jim Van Verth | 09557d7 | 2016-11-07 11:10:21 -0500 | [diff] [blame] | 164 | VkResult res = VK_CALL(QueueWaitIdle(fQueue)); |
egdaniel | f8c2be3 | 2016-06-24 13:18:27 -0700 | [diff] [blame] | 165 | |
| 166 | // On windows, sometimes calls to QueueWaitIdle return before actually signalling the fences |
| 167 | // on the command buffers even though they have completed. This causes an assert to fire when |
| 168 | // destroying the command buffers. Currently this ony seems to happen on windows, so we add a |
Jim Van Verth | 09557d7 | 2016-11-07 11:10:21 -0500 | [diff] [blame] | 169 | // sleep to make sure the fence signals. |
egdaniel | f8c2be3 | 2016-06-24 13:18:27 -0700 | [diff] [blame] | 170 | #ifdef SK_DEBUG |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 171 | if (this->vkCaps().mustSleepOnTearDown()) { |
egdaniel | f8c2be3 | 2016-06-24 13:18:27 -0700 | [diff] [blame] | 172 | #if defined(SK_BUILD_FOR_WIN) |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 173 | Sleep(10); // In milliseconds |
egdaniel | f8c2be3 | 2016-06-24 13:18:27 -0700 | [diff] [blame] | 174 | #else |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 175 | sleep(1); // In seconds |
egdaniel | f8c2be3 | 2016-06-24 13:18:27 -0700 | [diff] [blame] | 176 | #endif |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 177 | } |
egdaniel | f8c2be3 | 2016-06-24 13:18:27 -0700 | [diff] [blame] | 178 | #endif |
| 179 | |
egdaniel | be9d821 | 2016-09-20 08:54:23 -0700 | [diff] [blame] | 180 | #ifdef SK_DEBUG |
Greg Daniel | 8a8668b | 2016-10-31 16:34:42 -0400 | [diff] [blame] | 181 | SkASSERT(VK_SUCCESS == res || VK_ERROR_DEVICE_LOST == res); |
egdaniel | be9d821 | 2016-09-20 08:54:23 -0700 | [diff] [blame] | 182 | #endif |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 183 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 184 | for (int i = 0; i < fSemaphoresToWaitOn.count(); ++i) { |
| 185 | fSemaphoresToWaitOn[i]->unref(this); |
| 186 | } |
| 187 | fSemaphoresToWaitOn.reset(); |
| 188 | |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 189 | fCopyManager.destroyResources(this); |
| 190 | |
Jim Van Verth | 09557d7 | 2016-11-07 11:10:21 -0500 | [diff] [blame] | 191 | // must call this just before we destroy the command pool and VkDevice |
| 192 | fResourceProvider.destroyResources(VK_ERROR_DEVICE_LOST == res); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 193 | |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 194 | VK_CALL(DestroyCommandPool(fDevice, fCmdPool, nullptr)); |
| 195 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 196 | delete fCompiler; |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 197 | |
egdaniel | 735109c | 2016-07-27 08:03:57 -0700 | [diff] [blame] | 198 | #ifdef SK_ENABLE_VK_LAYERS |
jvanverth | a00980e | 2016-05-02 13:24:48 -0700 | [diff] [blame] | 199 | if (fCallback) { |
| 200 | VK_CALL(DestroyDebugReportCallbackEXT(fBackendContext->fInstance, fCallback, nullptr)); |
brianosman | 419ca64 | 2016-05-04 08:19:44 -0700 | [diff] [blame] | 201 | fCallback = VK_NULL_HANDLE; |
jvanverth | a00980e | 2016-05-02 13:24:48 -0700 | [diff] [blame] | 202 | } |
jvanverth | d2497f3 | 2016-03-18 12:39:05 -0700 | [diff] [blame] | 203 | #endif |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /////////////////////////////////////////////////////////////////////////////// |
| 207 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 208 | GrGpuCommandBuffer* GrVkGpu::createCommandBuffer( |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 209 | const GrGpuCommandBuffer::LoadAndStoreInfo& colorInfo, |
| 210 | const GrGpuCommandBuffer::LoadAndStoreInfo& stencilInfo) { |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 211 | return new GrVkGpuCommandBuffer(this, colorInfo, stencilInfo); |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 214 | void GrVkGpu::submitCommandBuffer(SyncQueue sync, |
| 215 | const GrVkSemaphore::Resource* signalSemaphore) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 216 | SkASSERT(fCurrentCmdBuffer); |
| 217 | fCurrentCmdBuffer->end(this); |
| 218 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 219 | fCurrentCmdBuffer->submitToQueue(this, fQueue, sync, signalSemaphore, fSemaphoresToWaitOn); |
| 220 | |
| 221 | for (int i = 0; i < fSemaphoresToWaitOn.count(); ++i) { |
| 222 | fSemaphoresToWaitOn[i]->unref(this); |
| 223 | } |
| 224 | fSemaphoresToWaitOn.reset(); |
| 225 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 226 | fResourceProvider.checkCommandBuffers(); |
| 227 | |
| 228 | // Release old command buffer and create a new one |
| 229 | fCurrentCmdBuffer->unref(this); |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 230 | fCurrentCmdBuffer = fResourceProvider.findOrCreatePrimaryCommandBuffer(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 231 | SkASSERT(fCurrentCmdBuffer); |
| 232 | |
| 233 | fCurrentCmdBuffer->begin(this); |
| 234 | } |
| 235 | |
| 236 | /////////////////////////////////////////////////////////////////////////////// |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 237 | GrBuffer* GrVkGpu::onCreateBuffer(size_t size, GrBufferType type, GrAccessPattern accessPattern, |
| 238 | const void* data) { |
| 239 | GrBuffer* buff; |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 240 | switch (type) { |
| 241 | case kVertex_GrBufferType: |
| 242 | SkASSERT(kDynamic_GrAccessPattern == accessPattern || |
| 243 | kStatic_GrAccessPattern == accessPattern); |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 244 | buff = GrVkVertexBuffer::Create(this, size, kDynamic_GrAccessPattern == accessPattern); |
egdaniel | e05bbbb | 2016-04-19 12:13:41 -0700 | [diff] [blame] | 245 | break; |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 246 | case kIndex_GrBufferType: |
| 247 | SkASSERT(kDynamic_GrAccessPattern == accessPattern || |
| 248 | kStatic_GrAccessPattern == accessPattern); |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 249 | buff = GrVkIndexBuffer::Create(this, size, kDynamic_GrAccessPattern == accessPattern); |
egdaniel | e05bbbb | 2016-04-19 12:13:41 -0700 | [diff] [blame] | 250 | break; |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 251 | case kXferCpuToGpu_GrBufferType: |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 252 | SkASSERT(kStream_GrAccessPattern == accessPattern); |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 253 | buff = GrVkTransferBuffer::Create(this, size, GrVkBuffer::kCopyRead_Type); |
egdaniel | e05bbbb | 2016-04-19 12:13:41 -0700 | [diff] [blame] | 254 | break; |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 255 | case kXferGpuToCpu_GrBufferType: |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 256 | SkASSERT(kStream_GrAccessPattern == accessPattern); |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 257 | buff = GrVkTransferBuffer::Create(this, size, GrVkBuffer::kCopyWrite_Type); |
egdaniel | e05bbbb | 2016-04-19 12:13:41 -0700 | [diff] [blame] | 258 | break; |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 259 | default: |
| 260 | SkFAIL("Unknown buffer type."); |
| 261 | return nullptr; |
| 262 | } |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 263 | if (data && buff) { |
| 264 | buff->updateData(data, size); |
| 265 | } |
| 266 | return buff; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | //////////////////////////////////////////////////////////////////////////////// |
| 270 | bool GrVkGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
| 271 | GrPixelConfig srcConfig, DrawPreference* drawPreference, |
| 272 | WritePixelTempDrawInfo* tempDrawInfo) { |
Brian Osman | d0be1ef | 2017-01-11 16:57:15 -0500 | [diff] [blame] | 273 | if (GrPixelConfigIsCompressed(dstSurface->config())) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 274 | return false; |
| 275 | } |
| 276 | |
egdaniel | 4583ec5 | 2016-06-27 12:57:00 -0700 | [diff] [blame] | 277 | GrRenderTarget* renderTarget = dstSurface->asRenderTarget(); |
| 278 | |
| 279 | // Start off assuming no swizzling |
| 280 | tempDrawInfo->fSwizzle = GrSwizzle::RGBA(); |
| 281 | tempDrawInfo->fWriteConfig = srcConfig; |
| 282 | |
| 283 | // These settings we will always want if a temp draw is performed. Initially set the config |
| 284 | // to srcConfig, though that may be modified if we decide to do a R/B swap |
| 285 | tempDrawInfo->fTempSurfaceDesc.fFlags = kNone_GrSurfaceFlags; |
| 286 | tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; |
| 287 | tempDrawInfo->fTempSurfaceDesc.fWidth = width; |
| 288 | tempDrawInfo->fTempSurfaceDesc.fHeight = height; |
| 289 | tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; |
| 290 | tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 291 | |
egdaniel | d66110f | 2016-06-28 13:38:26 -0700 | [diff] [blame] | 292 | if (dstSurface->config() == srcConfig) { |
Brian Osman | 3391029 | 2017-04-18 14:38:53 -0400 | [diff] [blame] | 293 | // We only support writing pixels to textures. Forcing a draw lets us write to pure RTs. |
| 294 | if (!dstSurface->asTexture()) { |
| 295 | ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 296 | } |
| 297 | // If the dst is MSAA, we have to draw, or we'll just be writing to the resolve target. |
| 298 | if (renderTarget && renderTarget->numColorSamples() > 1) { |
| 299 | ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
egdaniel | 4583ec5 | 2016-06-27 12:57:00 -0700 | [diff] [blame] | 300 | } |
| 301 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 302 | } |
| 303 | |
Brian Osman | 3391029 | 2017-04-18 14:38:53 -0400 | [diff] [blame] | 304 | // Any config change requires a draw |
| 305 | ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 306 | |
| 307 | bool configsAreRBSwaps = GrPixelConfigSwapRAndB(srcConfig) == dstSurface->config(); |
| 308 | |
| 309 | if (!this->vkCaps().isConfigTexturable(srcConfig) && configsAreRBSwaps) { |
| 310 | tempDrawInfo->fTempSurfaceDesc.fConfig = dstSurface->config(); |
| 311 | tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); |
| 312 | tempDrawInfo->fWriteConfig = dstSurface->config(); |
| 313 | } |
| 314 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | bool GrVkGpu::onWritePixels(GrSurface* surface, |
| 318 | int left, int top, int width, int height, |
bsalomon | a1e6b3b | 2016-03-02 10:58:23 -0800 | [diff] [blame] | 319 | GrPixelConfig config, |
| 320 | const SkTArray<GrMipLevel>& texels) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 321 | GrVkTexture* vkTex = static_cast<GrVkTexture*>(surface->asTexture()); |
| 322 | if (!vkTex) { |
| 323 | return false; |
| 324 | } |
| 325 | |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 326 | // Make sure we have at least the base level |
jvanverth | 03509ea | 2016-03-02 13:19:47 -0800 | [diff] [blame] | 327 | if (texels.empty() || !texels.begin()->fPixels) { |
| 328 | return false; |
| 329 | } |
bsalomon | a1e6b3b | 2016-03-02 10:58:23 -0800 | [diff] [blame] | 330 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 331 | // We assume Vulkan doesn't do sRGB <-> linear conversions when reading and writing pixels. |
| 332 | if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) { |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | bool success = false; |
| 337 | if (GrPixelConfigIsCompressed(vkTex->desc().fConfig)) { |
| 338 | // We check that config == desc.fConfig in GrGpu::getWritePixelsInfo() |
| 339 | SkASSERT(config == vkTex->desc().fConfig); |
| 340 | // TODO: add compressed texture support |
| 341 | // delete the following two lines and uncomment the two after that when ready |
| 342 | vkTex->unref(); |
| 343 | return false; |
| 344 | //success = this->uploadCompressedTexData(vkTex->desc(), buffer, false, left, top, width, |
| 345 | // height); |
| 346 | } else { |
| 347 | bool linearTiling = vkTex->isLinearTiled(); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 348 | if (linearTiling) { |
| 349 | if (texels.count() > 1) { |
| 350 | SkDebugf("Can't upload mipmap data to linear tiled texture"); |
| 351 | return false; |
| 352 | } |
| 353 | if (VK_IMAGE_LAYOUT_PREINITIALIZED != vkTex->currentLayout()) { |
| 354 | // Need to change the layout to general in order to perform a host write |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 355 | vkTex->setImageLayout(this, |
| 356 | VK_IMAGE_LAYOUT_GENERAL, |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 357 | VK_ACCESS_HOST_WRITE_BIT, |
| 358 | VK_PIPELINE_STAGE_HOST_BIT, |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 359 | false); |
egdaniel | bdf8811 | 2016-05-03 07:25:56 -0700 | [diff] [blame] | 360 | this->submitCommandBuffer(kForce_SyncQueue); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 361 | } |
| 362 | success = this->uploadTexDataLinear(vkTex, left, top, width, height, config, |
| 363 | texels.begin()->fPixels, texels.begin()->fRowBytes); |
| 364 | } else { |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 365 | int newMipLevels = texels.count(); |
jvanverth | 82c0558 | 2016-05-03 11:19:01 -0700 | [diff] [blame] | 366 | int currentMipLevels = vkTex->texturePriv().maxMipMapLevel() + 1; |
Greg Daniel | dd20e91 | 2017-04-07 14:42:23 -0400 | [diff] [blame] | 367 | if (newMipLevels > currentMipLevels) { |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 368 | if (!vkTex->reallocForMipmap(this, newMipLevels)) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 369 | return false; |
| 370 | } |
| 371 | } |
| 372 | success = this->uploadTexDataOptimal(vkTex, left, top, width, height, config, texels); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 373 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 374 | } |
egdaniel | 4583ec5 | 2016-06-27 12:57:00 -0700 | [diff] [blame] | 375 | |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 376 | return success; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 377 | } |
| 378 | |
Greg Daniel | bc26c39 | 2017-04-18 13:32:10 -0400 | [diff] [blame] | 379 | void GrVkGpu::resolveImage(GrSurface* dst, GrVkRenderTarget* src, const SkIRect& srcRect, |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 380 | const SkIPoint& dstPoint) { |
| 381 | SkASSERT(dst); |
| 382 | SkASSERT(src && src->numColorSamples() > 1 && src->msaaImage()); |
| 383 | |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 384 | if (this->vkCaps().mustSubmitCommandsBeforeCopyOp()) { |
| 385 | this->submitCommandBuffer(GrVkGpu::kSkip_SyncQueue); |
| 386 | } |
| 387 | |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 388 | // Flip rect if necessary |
| 389 | SkIRect srcVkRect = srcRect; |
| 390 | int32_t dstY = dstPoint.fY; |
| 391 | |
| 392 | if (kBottomLeft_GrSurfaceOrigin == src->origin()) { |
| 393 | SkASSERT(kBottomLeft_GrSurfaceOrigin == dst->origin()); |
| 394 | srcVkRect.fTop = src->height() - srcRect.fBottom; |
| 395 | srcVkRect.fBottom = src->height() - srcRect.fTop; |
| 396 | dstY = dst->height() - dstPoint.fY - srcVkRect.height(); |
| 397 | } |
| 398 | |
| 399 | VkImageResolve resolveInfo; |
| 400 | resolveInfo.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; |
| 401 | resolveInfo.srcOffset = { srcVkRect.fLeft, srcVkRect.fTop, 0 }; |
| 402 | resolveInfo.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; |
| 403 | resolveInfo.dstOffset = { dstPoint.fX, dstY, 0 }; |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 404 | resolveInfo.extent = { (uint32_t)srcVkRect.width(), (uint32_t)srcVkRect.height(), 1 }; |
| 405 | |
Greg Daniel | bc26c39 | 2017-04-18 13:32:10 -0400 | [diff] [blame] | 406 | GrVkImage* dstImage; |
| 407 | GrRenderTarget* dstRT = dst->asRenderTarget(); |
| 408 | if (dstRT) { |
| 409 | GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(dstRT); |
Greg Daniel | bc26c39 | 2017-04-18 13:32:10 -0400 | [diff] [blame] | 410 | dstImage = vkRT; |
| 411 | } else { |
| 412 | SkASSERT(dst->asTexture()); |
| 413 | dstImage = static_cast<GrVkTexture*>(dst->asTexture()); |
| 414 | } |
| 415 | dstImage->setImageLayout(this, |
| 416 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 417 | VK_ACCESS_TRANSFER_WRITE_BIT, |
| 418 | VK_PIPELINE_STAGE_TRANSFER_BIT, |
| 419 | false); |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 420 | |
| 421 | src->msaaImage()->setImageLayout(this, |
| 422 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
| 423 | VK_ACCESS_TRANSFER_READ_BIT, |
| 424 | VK_PIPELINE_STAGE_TRANSFER_BIT, |
| 425 | false); |
| 426 | |
Greg Daniel | bc26c39 | 2017-04-18 13:32:10 -0400 | [diff] [blame] | 427 | fCurrentCmdBuffer->resolveImage(this, *src->msaaImage(), *dstImage, 1, &resolveInfo); |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Greg Daniel | 69d4992 | 2017-02-23 09:44:02 -0500 | [diff] [blame] | 430 | void GrVkGpu::internalResolveRenderTarget(GrRenderTarget* target, bool requiresSubmit) { |
egdaniel | 6693355 | 2016-08-24 07:22:19 -0700 | [diff] [blame] | 431 | if (target->needsResolve()) { |
| 432 | SkASSERT(target->numColorSamples() > 1); |
egdaniel | 52ad251 | 2016-08-04 12:50:01 -0700 | [diff] [blame] | 433 | GrVkRenderTarget* rt = static_cast<GrVkRenderTarget*>(target); |
| 434 | SkASSERT(rt->msaaImage()); |
Greg Daniel | 69d4992 | 2017-02-23 09:44:02 -0500 | [diff] [blame] | 435 | |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 436 | const SkIRect& srcRect = rt->getResolveRect(); |
egdaniel | 52ad251 | 2016-08-04 12:50:01 -0700 | [diff] [blame] | 437 | |
Greg Daniel | bc26c39 | 2017-04-18 13:32:10 -0400 | [diff] [blame] | 438 | this->resolveImage(target, rt, srcRect, SkIPoint::Make(srcRect.fLeft, srcRect.fTop)); |
egdaniel | 52ad251 | 2016-08-04 12:50:01 -0700 | [diff] [blame] | 439 | |
| 440 | rt->flagAsResolved(); |
Greg Daniel | 69d4992 | 2017-02-23 09:44:02 -0500 | [diff] [blame] | 441 | |
| 442 | if (requiresSubmit) { |
| 443 | this->submitCommandBuffer(kSkip_SyncQueue); |
| 444 | } |
egdaniel | 52ad251 | 2016-08-04 12:50:01 -0700 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 448 | bool GrVkGpu::uploadTexDataLinear(GrVkTexture* tex, |
| 449 | int left, int top, int width, int height, |
| 450 | GrPixelConfig dataConfig, |
| 451 | const void* data, |
| 452 | size_t rowBytes) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 453 | SkASSERT(data); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 454 | SkASSERT(tex->isLinearTiled()); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 455 | |
| 456 | // If we're uploading compressed data then we should be using uploadCompressedTexData |
| 457 | SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); |
| 458 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 459 | size_t bpp = GrBytesPerPixel(dataConfig); |
| 460 | |
| 461 | const GrSurfaceDesc& desc = tex->desc(); |
| 462 | |
| 463 | if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, &left, &top, |
| 464 | &width, &height, &data, &rowBytes)) { |
| 465 | return false; |
| 466 | } |
| 467 | size_t trimRowBytes = width * bpp; |
| 468 | |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 469 | SkASSERT(VK_IMAGE_LAYOUT_PREINITIALIZED == tex->currentLayout() || |
| 470 | VK_IMAGE_LAYOUT_GENERAL == tex->currentLayout()); |
| 471 | const VkImageSubresource subres = { |
| 472 | VK_IMAGE_ASPECT_COLOR_BIT, |
| 473 | 0, // mipLevel |
| 474 | 0, // arraySlice |
| 475 | }; |
| 476 | VkSubresourceLayout layout; |
| 477 | VkResult err; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 478 | |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 479 | const GrVkInterface* interface = this->vkInterface(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 480 | |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 481 | GR_VK_CALL(interface, GetImageSubresourceLayout(fDevice, |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 482 | tex->image(), |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 483 | &subres, |
| 484 | &layout)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 485 | |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 486 | int texTop = kBottomLeft_GrSurfaceOrigin == desc.fOrigin ? tex->height() - top - height : top; |
jvanverth | 1e305ba | 2016-06-01 09:39:15 -0700 | [diff] [blame] | 487 | const GrVkAlloc& alloc = tex->alloc(); |
| 488 | VkDeviceSize offset = alloc.fOffset + texTop*layout.rowPitch + left*bpp; |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 489 | VkDeviceSize size = height*layout.rowPitch; |
| 490 | void* mapPtr; |
jvanverth | 1e305ba | 2016-06-01 09:39:15 -0700 | [diff] [blame] | 491 | err = GR_VK_CALL(interface, MapMemory(fDevice, alloc.fMemory, offset, size, 0, &mapPtr)); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 492 | if (err) { |
| 493 | return false; |
| 494 | } |
| 495 | |
| 496 | if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { |
| 497 | // copy into buffer by rows |
| 498 | const char* srcRow = reinterpret_cast<const char*>(data); |
| 499 | char* dstRow = reinterpret_cast<char*>(mapPtr)+(height - 1)*layout.rowPitch; |
| 500 | for (int y = 0; y < height; y++) { |
| 501 | memcpy(dstRow, srcRow, trimRowBytes); |
| 502 | srcRow += rowBytes; |
| 503 | dstRow -= layout.rowPitch; |
| 504 | } |
| 505 | } else { |
Matt Sarett | cf3525a | 2017-01-24 12:43:41 -0500 | [diff] [blame] | 506 | SkRectMemcpy(mapPtr, static_cast<size_t>(layout.rowPitch), data, rowBytes, trimRowBytes, |
| 507 | height); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 508 | } |
| 509 | |
jvanverth | 9d54afc | 2016-09-20 09:20:03 -0700 | [diff] [blame] | 510 | GrVkMemory::FlushMappedAlloc(this, alloc); |
jvanverth | 1e305ba | 2016-06-01 09:39:15 -0700 | [diff] [blame] | 511 | GR_VK_CALL(interface, UnmapMemory(fDevice, alloc.fMemory)); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 512 | |
| 513 | return true; |
| 514 | } |
| 515 | |
| 516 | bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex, |
jvanverth | a584de9 | 2016-06-30 09:10:52 -0700 | [diff] [blame] | 517 | int left, int top, int width, int height, |
| 518 | GrPixelConfig dataConfig, |
| 519 | const SkTArray<GrMipLevel>& texels) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 520 | SkASSERT(!tex->isLinearTiled()); |
| 521 | // The assumption is either that we have no mipmaps, or that our rect is the entire texture |
| 522 | SkASSERT(1 == texels.count() || |
| 523 | (0 == left && 0 == top && width == tex->width() && height == tex->height())); |
| 524 | |
Greg Daniel | dd20e91 | 2017-04-07 14:42:23 -0400 | [diff] [blame] | 525 | // We assume that if the texture has mip levels, we either upload to all the levels or just the |
| 526 | // first. |
| 527 | SkASSERT(1 == texels.count() || texels.count() == (tex->texturePriv().maxMipMapLevel() + 1)); |
| 528 | |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 529 | // If we're uploading compressed data then we should be using uploadCompressedTexData |
| 530 | SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); |
| 531 | |
| 532 | if (width == 0 || height == 0) { |
| 533 | return false; |
| 534 | } |
| 535 | |
| 536 | const GrSurfaceDesc& desc = tex->desc(); |
| 537 | SkASSERT(this->caps()->isConfigTexturable(desc.fConfig)); |
| 538 | size_t bpp = GrBytesPerPixel(dataConfig); |
| 539 | |
| 540 | // texels is const. |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 541 | // But we may need to adjust the fPixels ptr based on the copyRect, or fRowBytes. |
| 542 | // Because of this we need to make a non-const shallow copy of texels. |
| 543 | SkTArray<GrMipLevel> texelsShallowCopy(texels); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 544 | |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 545 | for (int currentMipLevel = texelsShallowCopy.count() - 1; currentMipLevel >= 0; |
| 546 | currentMipLevel--) { |
| 547 | SkASSERT(texelsShallowCopy[currentMipLevel].fPixels); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 548 | } |
| 549 | |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 550 | // Determine whether we need to flip when we copy into the buffer |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 551 | bool flipY = (kBottomLeft_GrSurfaceOrigin == desc.fOrigin && !texelsShallowCopy.empty()); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 552 | |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 553 | // adjust any params (left, top, currentWidth, currentHeight |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 554 | // find the combined size of all the mip levels and the relative offset of |
| 555 | // each into the collective buffer |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 556 | // Do the first level separately because we may need to adjust width and height |
| 557 | // (for the non-mipped case). |
| 558 | if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, &left, &top, |
| 559 | &width, |
| 560 | &height, |
| 561 | &texelsShallowCopy[0].fPixels, |
| 562 | &texelsShallowCopy[0].fRowBytes)) { |
| 563 | return false; |
| 564 | } |
| 565 | SkTArray<size_t> individualMipOffsets(texelsShallowCopy.count()); |
| 566 | individualMipOffsets.push_back(0); |
| 567 | size_t combinedBufferSize = width * bpp * height; |
| 568 | int currentWidth = width; |
| 569 | int currentHeight = height; |
Greg Daniel | 468fd63 | 2017-03-22 17:03:45 -0400 | [diff] [blame] | 570 | // The alignment must be at least 4 bytes and a multiple of the bytes per pixel of the image |
| 571 | // config. This works with the assumption that the bytes in pixel config is always a power of 2. |
| 572 | SkASSERT((bpp & (bpp - 1)) == 0); |
| 573 | const size_t alignmentMask = 0x3 | (bpp - 1); |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 574 | for (int currentMipLevel = 1; currentMipLevel < texelsShallowCopy.count(); currentMipLevel++) { |
| 575 | currentWidth = SkTMax(1, currentWidth/2); |
| 576 | currentHeight = SkTMax(1, currentHeight/2); |
| 577 | if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, &left, &top, |
| 578 | ¤tWidth, |
| 579 | ¤tHeight, |
| 580 | &texelsShallowCopy[currentMipLevel].fPixels, |
| 581 | &texelsShallowCopy[currentMipLevel].fRowBytes)) { |
| 582 | return false; |
| 583 | } |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 584 | const size_t trimmedSize = currentWidth * bpp * currentHeight; |
Greg Daniel | 468fd63 | 2017-03-22 17:03:45 -0400 | [diff] [blame] | 585 | const size_t alignmentDiff = combinedBufferSize & alignmentMask; |
| 586 | if (alignmentDiff != 0) { |
| 587 | combinedBufferSize += alignmentMask - alignmentDiff + 1; |
| 588 | } |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 589 | individualMipOffsets.push_back(combinedBufferSize); |
| 590 | combinedBufferSize += trimmedSize; |
| 591 | } |
| 592 | |
| 593 | // allocate buffer to hold our mip data |
| 594 | GrVkTransferBuffer* transferBuffer = |
| 595 | GrVkTransferBuffer::Create(this, combinedBufferSize, GrVkBuffer::kCopyRead_Type); |
Forrest Reiling | c04f845 | 2017-04-26 19:26:12 -0700 | [diff] [blame] | 596 | if(!transferBuffer) |
| 597 | return false; |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 598 | |
| 599 | char* buffer = (char*) transferBuffer->map(); |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 600 | SkTArray<VkBufferImageCopy> regions(texelsShallowCopy.count()); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 601 | |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 602 | currentWidth = width; |
| 603 | currentHeight = height; |
Greg Daniel | a1b282b | 2017-03-28 14:56:46 -0400 | [diff] [blame] | 604 | int layerHeight = tex->height(); |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 605 | for (int currentMipLevel = 0; currentMipLevel < texelsShallowCopy.count(); currentMipLevel++) { |
Greg Daniel | a1b282b | 2017-03-28 14:56:46 -0400 | [diff] [blame] | 606 | SkASSERT(1 == texelsShallowCopy.count() || currentHeight == layerHeight); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 607 | const size_t trimRowBytes = currentWidth * bpp; |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 608 | const size_t rowBytes = texelsShallowCopy[currentMipLevel].fRowBytes; |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 609 | |
| 610 | // copy data into the buffer, skipping the trailing bytes |
| 611 | char* dst = buffer + individualMipOffsets[currentMipLevel]; |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 612 | const char* src = (const char*)texelsShallowCopy[currentMipLevel].fPixels; |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 613 | if (flipY) { |
| 614 | src += (currentHeight - 1) * rowBytes; |
| 615 | for (int y = 0; y < currentHeight; y++) { |
| 616 | memcpy(dst, src, trimRowBytes); |
| 617 | src -= rowBytes; |
| 618 | dst += trimRowBytes; |
| 619 | } |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 620 | } else { |
| 621 | SkRectMemcpy(dst, trimRowBytes, src, rowBytes, trimRowBytes, currentHeight); |
| 622 | } |
| 623 | |
| 624 | VkBufferImageCopy& region = regions.push_back(); |
| 625 | memset(®ion, 0, sizeof(VkBufferImageCopy)); |
jvanverth | db37909 | 2016-07-07 11:18:46 -0700 | [diff] [blame] | 626 | region.bufferOffset = transferBuffer->offset() + individualMipOffsets[currentMipLevel]; |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 627 | region.bufferRowLength = currentWidth; |
| 628 | region.bufferImageHeight = currentHeight; |
bsalomon | cf942c4 | 2016-04-29 18:30:06 -0700 | [diff] [blame] | 629 | region.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, SkToU32(currentMipLevel), 0, 1 }; |
Greg Daniel | a1b282b | 2017-03-28 14:56:46 -0400 | [diff] [blame] | 630 | region.imageOffset = { left, flipY ? layerHeight - top - currentHeight : top, 0 }; |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 631 | region.imageExtent = { (uint32_t)currentWidth, (uint32_t)currentHeight, 1 }; |
egdaniel | 4583ec5 | 2016-06-27 12:57:00 -0700 | [diff] [blame] | 632 | |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 633 | currentWidth = SkTMax(1, currentWidth/2); |
| 634 | currentHeight = SkTMax(1, currentHeight/2); |
Greg Daniel | a1b282b | 2017-03-28 14:56:46 -0400 | [diff] [blame] | 635 | layerHeight = currentHeight; |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 636 | } |
| 637 | |
jvanverth | 9d54afc | 2016-09-20 09:20:03 -0700 | [diff] [blame] | 638 | // no need to flush non-coherent memory, unmap will do that for us |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 639 | transferBuffer->unmap(); |
| 640 | |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 641 | // Change layout of our target so it can be copied to |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 642 | tex->setImageLayout(this, |
| 643 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 644 | VK_ACCESS_TRANSFER_WRITE_BIT, |
| 645 | VK_PIPELINE_STAGE_TRANSFER_BIT, |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 646 | false); |
| 647 | |
| 648 | // Copy the buffer to the image |
| 649 | fCurrentCmdBuffer->copyBufferToImage(this, |
| 650 | transferBuffer, |
| 651 | tex, |
| 652 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 653 | regions.count(), |
| 654 | regions.begin()); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 655 | transferBuffer->unref(); |
Greg Daniel | dd20e91 | 2017-04-07 14:42:23 -0400 | [diff] [blame] | 656 | if (1 == texelsShallowCopy.count()) { |
| 657 | tex->texturePriv().dirtyMipMaps(true); |
| 658 | } |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 659 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 660 | return true; |
| 661 | } |
| 662 | |
| 663 | //////////////////////////////////////////////////////////////////////////////// |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 664 | GrTexture* GrVkGpu::onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |
bsalomon | a1e6b3b | 2016-03-02 10:58:23 -0800 | [diff] [blame] | 665 | const SkTArray<GrMipLevel>& texels) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 666 | bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 667 | |
| 668 | VkFormat pixelFormat; |
| 669 | if (!GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat)) { |
| 670 | return nullptr; |
| 671 | } |
| 672 | |
| 673 | if (!fVkCaps->isConfigTexturable(desc.fConfig)) { |
| 674 | return nullptr; |
| 675 | } |
| 676 | |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 677 | if (renderTarget && !fVkCaps->isConfigRenderable(desc.fConfig, false)) { |
| 678 | return nullptr; |
| 679 | } |
| 680 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 681 | bool linearTiling = false; |
| 682 | if (SkToBool(desc.fFlags & kZeroCopy_GrSurfaceFlag)) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 683 | // we can't have a linear texture with a mipmap |
| 684 | if (texels.count() > 1) { |
| 685 | SkDebugf("Trying to create linear tiled texture with mipmap"); |
| 686 | return nullptr; |
| 687 | } |
egdaniel | a95d46b | 2016-08-15 08:06:29 -0700 | [diff] [blame] | 688 | if (fVkCaps->isConfigTexturableLinearly(desc.fConfig) && |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 689 | (!renderTarget || fVkCaps->isConfigRenderableLinearly(desc.fConfig, false))) { |
| 690 | linearTiling = true; |
| 691 | } else { |
| 692 | return nullptr; |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 697 | if (renderTarget) { |
| 698 | usageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 699 | } |
| 700 | |
| 701 | // For now we will set the VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT and |
| 702 | // VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT on every texture since we do not know whether or not we |
| 703 | // will be using this texture in some copy or not. Also this assumes, as is the current case, |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 704 | // that all render targets in vulkan are also textures. If we change this practice of setting |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 705 | // both bits, we must make sure to set the destination bit if we are uploading srcData to the |
| 706 | // texture. |
| 707 | usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 708 | |
bsalomon | a1e6b3b | 2016-03-02 10:58:23 -0800 | [diff] [blame] | 709 | VkFlags memProps = (!texels.empty() && linearTiling) ? VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT : |
| 710 | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 711 | |
| 712 | // This ImageDesc refers to the texture that will be read by the client. Thus even if msaa is |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 713 | // requested, this ImageDesc describes the resolved texture. Therefore we always have samples set |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 714 | // to 1. |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 715 | int mipLevels = texels.empty() ? 1 : texels.count(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 716 | GrVkImage::ImageDesc imageDesc; |
| 717 | imageDesc.fImageType = VK_IMAGE_TYPE_2D; |
| 718 | imageDesc.fFormat = pixelFormat; |
| 719 | imageDesc.fWidth = desc.fWidth; |
| 720 | imageDesc.fHeight = desc.fHeight; |
jvanverth | c578b063 | 2016-05-02 10:58:12 -0700 | [diff] [blame] | 721 | imageDesc.fLevels = linearTiling ? 1 : mipLevels; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 722 | imageDesc.fSamples = 1; |
| 723 | imageDesc.fImageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL; |
| 724 | imageDesc.fUsageFlags = usageFlags; |
| 725 | imageDesc.fMemProps = memProps; |
| 726 | |
| 727 | GrVkTexture* tex; |
| 728 | if (renderTarget) { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 729 | tex = GrVkTextureRenderTarget::CreateNewTextureRenderTarget(this, budgeted, desc, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 730 | imageDesc); |
| 731 | } else { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 732 | tex = GrVkTexture::CreateNewTexture(this, budgeted, desc, imageDesc); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | if (!tex) { |
| 736 | return nullptr; |
| 737 | } |
| 738 | |
bsalomon | e699d0c | 2016-03-09 06:25:15 -0800 | [diff] [blame] | 739 | if (!texels.empty()) { |
| 740 | SkASSERT(texels.begin()->fPixels); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 741 | bool success; |
| 742 | if (linearTiling) { |
| 743 | success = this->uploadTexDataLinear(tex, 0, 0, desc.fWidth, desc.fHeight, desc.fConfig, |
| 744 | texels.begin()->fPixels, texels.begin()->fRowBytes); |
| 745 | } else { |
| 746 | success = this->uploadTexDataOptimal(tex, 0, 0, desc.fWidth, desc.fHeight, desc.fConfig, |
| 747 | texels); |
| 748 | } |
| 749 | if (!success) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 750 | tex->unref(); |
| 751 | return nullptr; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | return tex; |
| 756 | } |
| 757 | |
| 758 | //////////////////////////////////////////////////////////////////////////////// |
| 759 | |
jvanverth | db37909 | 2016-07-07 11:18:46 -0700 | [diff] [blame] | 760 | bool GrVkGpu::updateBuffer(GrVkBuffer* buffer, const void* src, |
| 761 | VkDeviceSize offset, VkDeviceSize size) { |
jvanverth | a584de9 | 2016-06-30 09:10:52 -0700 | [diff] [blame] | 762 | |
| 763 | // Update the buffer |
jvanverth | db37909 | 2016-07-07 11:18:46 -0700 | [diff] [blame] | 764 | fCurrentCmdBuffer->updateBuffer(this, buffer, offset, size, src); |
jvanverth | a584de9 | 2016-06-30 09:10:52 -0700 | [diff] [blame] | 765 | |
| 766 | return true; |
| 767 | } |
| 768 | |
| 769 | //////////////////////////////////////////////////////////////////////////////// |
| 770 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 771 | static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin) { |
| 772 | // By default, all textures in Vk use TopLeft |
| 773 | if (kDefault_GrSurfaceOrigin == origin) { |
| 774 | return kTopLeft_GrSurfaceOrigin; |
| 775 | } else { |
| 776 | return origin; |
| 777 | } |
| 778 | } |
| 779 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 780 | sk_sp<GrTexture> GrVkGpu::onWrapBackendTexture(const GrBackendTexture& backendTex, |
| 781 | GrSurfaceOrigin origin, |
| 782 | GrBackendTextureFlags flags, |
| 783 | int sampleCnt, |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 784 | GrWrapOwnership ownership) { |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 785 | const GrVkImageInfo* info = backendTex.getVkImageInfo(); |
| 786 | if (!info) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 787 | return nullptr; |
| 788 | } |
| 789 | |
| 790 | int maxSize = this->caps()->maxTextureSize(); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 791 | if (backendTex.width() > maxSize || backendTex.height() > maxSize) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 792 | return nullptr; |
| 793 | } |
| 794 | |
jvanverth | 1e305ba | 2016-06-01 09:39:15 -0700 | [diff] [blame] | 795 | if (VK_NULL_HANDLE == info->fImage || VK_NULL_HANDLE == info->fAlloc.fMemory) { |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 796 | return nullptr; |
| 797 | } |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 798 | |
| 799 | SkASSERT(backendTex.config() == GrVkFormatToPixelConfig(info->fFormat)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 800 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 801 | GrSurfaceDesc surfDesc; |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 802 | // next line relies on GrBackendTextureFlags matching GrTexture's |
| 803 | surfDesc.fFlags = (GrSurfaceFlags)flags; |
| 804 | surfDesc.fWidth = backendTex.width(); |
| 805 | surfDesc.fHeight = backendTex.height(); |
| 806 | surfDesc.fConfig = backendTex.config(); |
| 807 | surfDesc.fSampleCnt = SkTMin(sampleCnt, this->caps()->maxSampleCount()); |
| 808 | bool renderTarget = SkToBool(flags & kRenderTarget_GrBackendTextureFlag); |
Brian Osman | 766fcbb | 2017-03-13 09:33:09 -0400 | [diff] [blame] | 809 | SkASSERT(!renderTarget || kAdoptAndCache_GrWrapOwnership != ownership); // Not supported |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 810 | // In GL, Chrome assumes all textures are BottomLeft |
| 811 | // In VK, we don't have this restriction |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 812 | surfDesc.fOrigin = resolve_origin(origin); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 813 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 814 | if (!renderTarget) { |
| 815 | return GrVkTexture::MakeWrappedTexture(this, surfDesc, ownership, info); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 816 | } |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 817 | return GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(this, surfDesc, ownership, info); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 818 | } |
| 819 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 820 | sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT, |
| 821 | GrSurfaceOrigin origin){ |
Greg Daniel | e79b473 | 2017-04-20 14:07:46 -0400 | [diff] [blame] | 822 | // Currently the Vulkan backend does not support wrapping of msaa render targets directly. In |
| 823 | // general this is not an issue since swapchain images in vulkan are never multisampled. Thus if |
| 824 | // you want a multisampled RT it is best to wrap the swapchain images and then let Skia handle |
| 825 | // creating and owning the MSAA images. |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 826 | if (backendRT.sampleCnt()) { |
Greg Daniel | e79b473 | 2017-04-20 14:07:46 -0400 | [diff] [blame] | 827 | return nullptr; |
| 828 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 829 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 830 | const GrVkImageInfo* info = backendRT.getVkImageInfo(); |
| 831 | if (!info) { |
| 832 | return nullptr; |
| 833 | } |
Brian Osman | 0b791f5 | 2017-03-10 08:30:22 -0500 | [diff] [blame] | 834 | if (VK_NULL_HANDLE == info->fImage) { |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 835 | return nullptr; |
| 836 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 837 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 838 | GrSurfaceDesc desc; |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 839 | desc.fConfig = backendRT.config(); |
Robert Phillips | 3667b49 | 2016-11-15 14:46:09 -0500 | [diff] [blame] | 840 | desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag; |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 841 | desc.fWidth = backendRT.width(); |
| 842 | desc.fHeight = backendRT.height(); |
Greg Daniel | e79b473 | 2017-04-20 14:07:46 -0400 | [diff] [blame] | 843 | desc.fSampleCnt = 0; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 844 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 845 | SkASSERT(kDefault_GrSurfaceOrigin != origin); |
| 846 | desc.fOrigin = origin; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 847 | |
Brian Osman | 0b791f5 | 2017-03-10 08:30:22 -0500 | [diff] [blame] | 848 | sk_sp<GrVkRenderTarget> tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this, desc, info); |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 849 | if (tgt && backendRT.stencilBits()) { |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 850 | if (!createStencilAttachmentForRenderTarget(tgt.get(), desc.fWidth, desc.fHeight)) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 851 | return nullptr; |
| 852 | } |
| 853 | } |
| 854 | return tgt; |
| 855 | } |
| 856 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 857 | sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex, |
| 858 | GrSurfaceOrigin origin, |
| 859 | int sampleCnt) { |
Brian Osman | 3391029 | 2017-04-18 14:38:53 -0400 | [diff] [blame] | 860 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 861 | const GrVkImageInfo* info = tex.getVkImageInfo(); |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 862 | if (!info) { |
| 863 | return nullptr; |
| 864 | } |
Brian Osman | 3391029 | 2017-04-18 14:38:53 -0400 | [diff] [blame] | 865 | if (VK_NULL_HANDLE == info->fImage) { |
| 866 | return nullptr; |
| 867 | } |
| 868 | |
| 869 | GrSurfaceDesc desc; |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 870 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 871 | desc.fConfig = tex.config(); |
| 872 | desc.fWidth = tex.width(); |
| 873 | desc.fHeight = tex.height(); |
| 874 | desc.fSampleCnt = SkTMin(sampleCnt, this->caps()->maxSampleCount()); |
Brian Osman | 3391029 | 2017-04-18 14:38:53 -0400 | [diff] [blame] | 875 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 876 | desc.fOrigin = resolve_origin(origin); |
Brian Osman | 3391029 | 2017-04-18 14:38:53 -0400 | [diff] [blame] | 877 | |
| 878 | sk_sp<GrVkRenderTarget> tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this, desc, info); |
| 879 | return tgt; |
| 880 | } |
| 881 | |
egdaniel | 50ead53 | 2016-07-13 14:23:26 -0700 | [diff] [blame] | 882 | void GrVkGpu::generateMipmap(GrVkTexture* tex) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 883 | // don't do anything for linearly tiled textures (can't have mipmaps) |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 884 | if (tex->isLinearTiled()) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 885 | SkDebugf("Trying to create mipmap for linear tiled texture"); |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 886 | return; |
| 887 | } |
| 888 | |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 889 | // determine if we can blit to and from this format |
| 890 | const GrVkCaps& caps = this->vkCaps(); |
| 891 | if (!caps.configCanBeDstofBlit(tex->config(), false) || |
egdaniel | 2f5792a | 2016-07-06 08:51:23 -0700 | [diff] [blame] | 892 | !caps.configCanBeSrcofBlit(tex->config(), false) || |
| 893 | !caps.mipMapSupport()) { |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 894 | return; |
| 895 | } |
| 896 | |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 897 | if (this->vkCaps().mustSubmitCommandsBeforeCopyOp()) { |
| 898 | this->submitCommandBuffer(kSkip_SyncQueue); |
| 899 | } |
| 900 | |
egdaniel | 6693355 | 2016-08-24 07:22:19 -0700 | [diff] [blame] | 901 | // We may need to resolve the texture first if it is also a render target |
| 902 | GrVkRenderTarget* texRT = static_cast<GrVkRenderTarget*>(tex->asRenderTarget()); |
| 903 | if (texRT) { |
Greg Daniel | 69d4992 | 2017-02-23 09:44:02 -0500 | [diff] [blame] | 904 | this->internalResolveRenderTarget(texRT, false); |
egdaniel | 6693355 | 2016-08-24 07:22:19 -0700 | [diff] [blame] | 905 | } |
| 906 | |
egdaniel | 7ac5da8 | 2016-07-15 13:41:42 -0700 | [diff] [blame] | 907 | int width = tex->width(); |
| 908 | int height = tex->height(); |
| 909 | VkImageBlit blitRegion; |
| 910 | memset(&blitRegion, 0, sizeof(VkImageBlit)); |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 911 | |
jvanverth | 82c0558 | 2016-05-03 11:19:01 -0700 | [diff] [blame] | 912 | // SkMipMap doesn't include the base level in the level count so we have to add 1 |
| 913 | uint32_t levelCount = SkMipMap::ComputeLevelCount(tex->width(), tex->height()) + 1; |
egdaniel | 7ac5da8 | 2016-07-15 13:41:42 -0700 | [diff] [blame] | 914 | if (levelCount != tex->mipLevels()) { |
| 915 | const GrVkResource* oldResource = tex->resource(); |
| 916 | oldResource->ref(); |
| 917 | // grab handle to the original image resource |
| 918 | VkImage oldImage = tex->image(); |
| 919 | |
| 920 | // change the original image's layout so we can copy from it |
| 921 | tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
| 922 | VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, false); |
| 923 | |
| 924 | if (!tex->reallocForMipmap(this, levelCount)) { |
| 925 | oldResource->unref(this); |
| 926 | return; |
| 927 | } |
| 928 | // change the new image's layout so we can blit to it |
| 929 | tex->setImageLayout(this, VK_IMAGE_LAYOUT_GENERAL, |
| 930 | VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, false); |
| 931 | |
| 932 | // Blit original image to top level of new image |
| 933 | blitRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; |
| 934 | blitRegion.srcOffsets[0] = { 0, 0, 0 }; |
| 935 | blitRegion.srcOffsets[1] = { width, height, 1 }; |
| 936 | blitRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; |
| 937 | blitRegion.dstOffsets[0] = { 0, 0, 0 }; |
| 938 | blitRegion.dstOffsets[1] = { width, height, 1 }; |
| 939 | |
| 940 | fCurrentCmdBuffer->blitImage(this, |
| 941 | oldResource, |
| 942 | oldImage, |
| 943 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
| 944 | tex->resource(), |
| 945 | tex->image(), |
| 946 | VK_IMAGE_LAYOUT_GENERAL, |
| 947 | 1, |
| 948 | &blitRegion, |
| 949 | VK_FILTER_LINEAR); |
| 950 | |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 951 | oldResource->unref(this); |
egdaniel | 7ac5da8 | 2016-07-15 13:41:42 -0700 | [diff] [blame] | 952 | } else { |
| 953 | // change layout of the layers so we can write to them. |
| 954 | tex->setImageLayout(this, VK_IMAGE_LAYOUT_GENERAL, |
| 955 | VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, false); |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 956 | } |
| 957 | |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 958 | // setup memory barrier |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 959 | SkASSERT(kUnknown_GrPixelConfig != GrVkFormatToPixelConfig(tex->imageFormat())); |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 960 | VkImageAspectFlags aspectFlags = VK_IMAGE_ASPECT_COLOR_BIT; |
| 961 | VkImageMemoryBarrier imageMemoryBarrier = { |
| 962 | VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType |
| 963 | NULL, // pNext |
egdaniel | 7ac5da8 | 2016-07-15 13:41:42 -0700 | [diff] [blame] | 964 | VK_ACCESS_TRANSFER_WRITE_BIT, // srcAccessMask |
| 965 | VK_ACCESS_TRANSFER_READ_BIT, // dstAccessMask |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 966 | VK_IMAGE_LAYOUT_GENERAL, // oldLayout |
| 967 | VK_IMAGE_LAYOUT_GENERAL, // newLayout |
| 968 | VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex |
| 969 | VK_QUEUE_FAMILY_IGNORED, // dstQueueFamilyIndex |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 970 | tex->image(), // image |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 971 | { aspectFlags, 0, 1, 0, 1 } // subresourceRange |
| 972 | }; |
| 973 | |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 974 | // Blit the miplevels |
jvanverth | 82c0558 | 2016-05-03 11:19:01 -0700 | [diff] [blame] | 975 | uint32_t mipLevel = 1; |
| 976 | while (mipLevel < levelCount) { |
| 977 | int prevWidth = width; |
| 978 | int prevHeight = height; |
| 979 | width = SkTMax(1, width / 2); |
| 980 | height = SkTMax(1, height / 2); |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 981 | |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 982 | imageMemoryBarrier.subresourceRange.baseMipLevel = mipLevel - 1; |
| 983 | this->addImageMemoryBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, |
| 984 | false, &imageMemoryBarrier); |
| 985 | |
| 986 | blitRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, mipLevel - 1, 0, 1 }; |
jvanverth | 82c0558 | 2016-05-03 11:19:01 -0700 | [diff] [blame] | 987 | blitRegion.srcOffsets[0] = { 0, 0, 0 }; |
brianosman | e9906e7 | 2016-06-08 12:44:27 -0700 | [diff] [blame] | 988 | blitRegion.srcOffsets[1] = { prevWidth, prevHeight, 1 }; |
jvanverth | 82c0558 | 2016-05-03 11:19:01 -0700 | [diff] [blame] | 989 | blitRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, mipLevel, 0, 1 }; |
| 990 | blitRegion.dstOffsets[0] = { 0, 0, 0 }; |
brianosman | e9906e7 | 2016-06-08 12:44:27 -0700 | [diff] [blame] | 991 | blitRegion.dstOffsets[1] = { width, height, 1 }; |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 992 | fCurrentCmdBuffer->blitImage(this, |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 993 | *tex, |
| 994 | *tex, |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 995 | 1, |
| 996 | &blitRegion, |
| 997 | VK_FILTER_LINEAR); |
jvanverth | 82c0558 | 2016-05-03 11:19:01 -0700 | [diff] [blame] | 998 | ++mipLevel; |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 999 | } |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1002 | //////////////////////////////////////////////////////////////////////////////// |
| 1003 | |
| 1004 | GrStencilAttachment* GrVkGpu::createStencilAttachmentForRenderTarget(const GrRenderTarget* rt, |
| 1005 | int width, |
| 1006 | int height) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1007 | SkASSERT(width >= rt->width()); |
| 1008 | SkASSERT(height >= rt->height()); |
| 1009 | |
| 1010 | int samples = rt->numStencilSamples(); |
| 1011 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 1012 | const GrVkCaps::StencilFormat& sFmt = this->vkCaps().preferedStencilFormat(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1013 | |
| 1014 | GrVkStencilAttachment* stencil(GrVkStencilAttachment::Create(this, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1015 | width, |
| 1016 | height, |
| 1017 | samples, |
| 1018 | sFmt)); |
| 1019 | fStats.incStencilAttachmentCreates(); |
| 1020 | return stencil; |
| 1021 | } |
| 1022 | |
| 1023 | //////////////////////////////////////////////////////////////////////////////// |
| 1024 | |
jvanverth | 9d54afc | 2016-09-20 09:20:03 -0700 | [diff] [blame] | 1025 | bool copy_testing_data(GrVkGpu* gpu, void* srcData, const GrVkAlloc& alloc, |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1026 | size_t srcRowBytes, size_t dstRowBytes, int h) { |
| 1027 | void* mapPtr; |
| 1028 | VkResult err = GR_VK_CALL(gpu->vkInterface(), MapMemory(gpu->device(), |
jvanverth | 9d54afc | 2016-09-20 09:20:03 -0700 | [diff] [blame] | 1029 | alloc.fMemory, |
| 1030 | alloc.fOffset, |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1031 | dstRowBytes * h, |
| 1032 | 0, |
| 1033 | &mapPtr)); |
| 1034 | if (err) { |
| 1035 | return false; |
| 1036 | } |
| 1037 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1038 | if (srcData) { |
| 1039 | // If there is no padding on dst we can do a single memcopy. |
| 1040 | // This assumes the srcData comes in with no padding. |
| 1041 | SkRectMemcpy(mapPtr, static_cast<size_t>(dstRowBytes), |
| 1042 | srcData, srcRowBytes, srcRowBytes, h); |
| 1043 | } else { |
| 1044 | // If there is no srcdata we always copy 0's into the textures so that it is initialized |
| 1045 | // with some data. |
| 1046 | if (srcRowBytes == static_cast<size_t>(dstRowBytes)) { |
| 1047 | memset(mapPtr, 0, srcRowBytes * h); |
| 1048 | } else { |
| 1049 | for (int i = 0; i < h; ++i) { |
| 1050 | memset(mapPtr, 0, srcRowBytes); |
| 1051 | mapPtr = SkTAddOffset<void>(mapPtr, static_cast<size_t>(dstRowBytes)); |
| 1052 | } |
| 1053 | } |
| 1054 | } |
jvanverth | 9d54afc | 2016-09-20 09:20:03 -0700 | [diff] [blame] | 1055 | GrVkMemory::FlushMappedAlloc(gpu, alloc); |
| 1056 | GR_VK_CALL(gpu->vkInterface(), UnmapMemory(gpu->device(), alloc.fMemory)); |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1057 | return true; |
| 1058 | } |
| 1059 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1060 | GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, int h, |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 1061 | GrPixelConfig config, |
| 1062 | bool isRenderTarget) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1063 | |
| 1064 | VkFormat pixelFormat; |
| 1065 | if (!GrPixelConfigToVkFormat(config, &pixelFormat)) { |
| 1066 | return 0; |
| 1067 | } |
| 1068 | |
| 1069 | bool linearTiling = false; |
| 1070 | if (!fVkCaps->isConfigTexturable(config)) { |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 1074 | if (isRenderTarget && !fVkCaps->isConfigRenderable(config, false)) { |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
egdaniel | a95d46b | 2016-08-15 08:06:29 -0700 | [diff] [blame] | 1078 | if (fVkCaps->isConfigTexturableLinearly(config) && |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 1079 | (!isRenderTarget || fVkCaps->isConfigRenderableLinearly(config, false))) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1080 | linearTiling = true; |
| 1081 | } |
| 1082 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1083 | VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 1084 | usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1085 | usageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 1086 | if (isRenderTarget) { |
| 1087 | usageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 1088 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1089 | |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 1090 | VkImage image = VK_NULL_HANDLE; |
jvanverth | 9d54afc | 2016-09-20 09:20:03 -0700 | [diff] [blame] | 1091 | GrVkAlloc alloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1092 | |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 1093 | VkImageTiling imageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL; |
| 1094 | VkImageLayout initialLayout = (VK_IMAGE_TILING_LINEAR == imageTiling) |
| 1095 | ? VK_IMAGE_LAYOUT_PREINITIALIZED |
| 1096 | : VK_IMAGE_LAYOUT_UNDEFINED; |
| 1097 | |
| 1098 | // Create Image |
| 1099 | VkSampleCountFlagBits vkSamples; |
| 1100 | if (!GrSampleCountToVkSampleCount(1, &vkSamples)) { |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
| 1104 | const VkImageCreateInfo imageCreateInfo = { |
| 1105 | VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // sType |
| 1106 | NULL, // pNext |
| 1107 | 0, // VkImageCreateFlags |
| 1108 | VK_IMAGE_TYPE_2D, // VkImageType |
| 1109 | pixelFormat, // VkFormat |
ethannicholas | 384b5e9 | 2016-03-25 11:04:06 -0700 | [diff] [blame] | 1110 | { (uint32_t) w, (uint32_t) h, 1 }, // VkExtent3D |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 1111 | 1, // mipLevels |
| 1112 | 1, // arrayLayers |
| 1113 | vkSamples, // samples |
| 1114 | imageTiling, // VkImageTiling |
| 1115 | usageFlags, // VkImageUsageFlags |
| 1116 | VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode |
| 1117 | 0, // queueFamilyCount |
| 1118 | 0, // pQueueFamilyIndices |
| 1119 | initialLayout // initialLayout |
| 1120 | }; |
| 1121 | |
| 1122 | GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateImage(this->device(), &imageCreateInfo, nullptr, &image)); |
| 1123 | |
jvanverth | 6b6ffc4 | 2016-06-13 14:28:07 -0700 | [diff] [blame] | 1124 | if (!GrVkMemory::AllocAndBindImageMemory(this, image, linearTiling, &alloc)) { |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 1125 | VK_CALL(DestroyImage(this->device(), image, nullptr)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1126 | return 0; |
| 1127 | } |
| 1128 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1129 | size_t bpp = GrBytesPerPixel(config); |
| 1130 | size_t rowCopyBytes = bpp * w; |
| 1131 | if (linearTiling) { |
| 1132 | const VkImageSubresource subres = { |
| 1133 | VK_IMAGE_ASPECT_COLOR_BIT, |
| 1134 | 0, // mipLevel |
| 1135 | 0, // arraySlice |
| 1136 | }; |
| 1137 | VkSubresourceLayout layout; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1138 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1139 | VK_CALL(GetImageSubresourceLayout(fDevice, image, &subres, &layout)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1140 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1141 | if (!copy_testing_data(this, srcData, alloc, rowCopyBytes, |
| 1142 | static_cast<size_t>(layout.rowPitch), h)) { |
| 1143 | GrVkMemory::FreeImageMemory(this, linearTiling, alloc); |
| 1144 | VK_CALL(DestroyImage(fDevice, image, nullptr)); |
| 1145 | return 0; |
| 1146 | } |
| 1147 | } else { |
| 1148 | SkASSERT(w && h); |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1149 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1150 | VkBuffer buffer; |
| 1151 | VkBufferCreateInfo bufInfo; |
| 1152 | memset(&bufInfo, 0, sizeof(VkBufferCreateInfo)); |
| 1153 | bufInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1154 | bufInfo.flags = 0; |
| 1155 | bufInfo.size = rowCopyBytes * h; |
| 1156 | bufInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 1157 | bufInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1158 | bufInfo.queueFamilyIndexCount = 0; |
| 1159 | bufInfo.pQueueFamilyIndices = nullptr; |
| 1160 | VkResult err; |
| 1161 | err = VK_CALL(CreateBuffer(fDevice, &bufInfo, nullptr, &buffer)); |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1162 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1163 | if (err) { |
| 1164 | GrVkMemory::FreeImageMemory(this, linearTiling, alloc); |
| 1165 | VK_CALL(DestroyImage(fDevice, image, nullptr)); |
| 1166 | return 0; |
| 1167 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1168 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1169 | GrVkAlloc bufferAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
| 1170 | if (!GrVkMemory::AllocAndBindBufferMemory(this, buffer, GrVkBuffer::kCopyRead_Type, |
| 1171 | true, &bufferAlloc)) { |
| 1172 | GrVkMemory::FreeImageMemory(this, linearTiling, alloc); |
| 1173 | VK_CALL(DestroyImage(fDevice, image, nullptr)); |
| 1174 | VK_CALL(DestroyBuffer(fDevice, buffer, nullptr)); |
| 1175 | return 0; |
| 1176 | } |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1177 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1178 | if (!copy_testing_data(this, srcData, bufferAlloc, rowCopyBytes, rowCopyBytes, h)) { |
| 1179 | GrVkMemory::FreeImageMemory(this, linearTiling, alloc); |
| 1180 | VK_CALL(DestroyImage(fDevice, image, nullptr)); |
| 1181 | GrVkMemory::FreeBufferMemory(this, GrVkBuffer::kCopyRead_Type, bufferAlloc); |
| 1182 | VK_CALL(DestroyBuffer(fDevice, buffer, nullptr)); |
| 1183 | return 0; |
| 1184 | } |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1185 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1186 | const VkCommandBufferAllocateInfo cmdInfo = { |
| 1187 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType |
| 1188 | NULL, // pNext |
| 1189 | fCmdPool, // commandPool |
| 1190 | VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level |
| 1191 | 1 // bufferCount |
| 1192 | }; |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1193 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1194 | VkCommandBuffer cmdBuffer; |
| 1195 | err = VK_CALL(AllocateCommandBuffers(fDevice, &cmdInfo, &cmdBuffer)); |
| 1196 | if (err) { |
| 1197 | GrVkMemory::FreeImageMemory(this, linearTiling, alloc); |
| 1198 | VK_CALL(DestroyImage(fDevice, image, nullptr)); |
| 1199 | GrVkMemory::FreeBufferMemory(this, GrVkBuffer::kCopyRead_Type, bufferAlloc); |
| 1200 | VK_CALL(DestroyBuffer(fDevice, buffer, nullptr)); |
| 1201 | return 0; |
| 1202 | } |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1203 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1204 | VkCommandBufferBeginInfo cmdBufferBeginInfo; |
| 1205 | memset(&cmdBufferBeginInfo, 0, sizeof(VkCommandBufferBeginInfo)); |
| 1206 | cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 1207 | cmdBufferBeginInfo.pNext = nullptr; |
| 1208 | cmdBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 1209 | cmdBufferBeginInfo.pInheritanceInfo = nullptr; |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1210 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1211 | err = VK_CALL(BeginCommandBuffer(cmdBuffer, &cmdBufferBeginInfo)); |
| 1212 | SkASSERT(!err); |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1213 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1214 | // Set image layout and add barrier |
| 1215 | VkImageMemoryBarrier barrier; |
| 1216 | memset(&barrier, 0, sizeof(VkImageMemoryBarrier)); |
| 1217 | barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 1218 | barrier.pNext = nullptr; |
| 1219 | barrier.srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(initialLayout); |
| 1220 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; |
| 1221 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
| 1222 | barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 1223 | barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 1224 | barrier.image = image; |
| 1225 | barrier.subresourceRange = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0 , 1}; |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1226 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1227 | VK_CALL(CmdPipelineBarrier(cmdBuffer, |
| 1228 | GrVkMemory::LayoutToPipelineStageFlags(initialLayout), |
| 1229 | VK_PIPELINE_STAGE_TRANSFER_BIT, |
| 1230 | 0, |
| 1231 | 0, nullptr, |
| 1232 | 0, nullptr, |
| 1233 | 1, &barrier)); |
| 1234 | initialLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1235 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1236 | // Submit copy command |
| 1237 | VkBufferImageCopy region; |
| 1238 | memset(®ion, 0, sizeof(VkBufferImageCopy)); |
| 1239 | region.bufferOffset = 0; |
| 1240 | region.bufferRowLength = w; |
| 1241 | region.bufferImageHeight = h; |
| 1242 | region.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; |
| 1243 | region.imageOffset = { 0, 0, 0 }; |
| 1244 | region.imageExtent = { (uint32_t)w, (uint32_t)h, 1 }; |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1245 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1246 | VK_CALL(CmdCopyBufferToImage(cmdBuffer, buffer, image, initialLayout, 1, ®ion)); |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1247 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1248 | // End CommandBuffer |
| 1249 | err = VK_CALL(EndCommandBuffer(cmdBuffer)); |
| 1250 | SkASSERT(!err); |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1251 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1252 | // Create Fence for queue |
| 1253 | VkFence fence; |
| 1254 | VkFenceCreateInfo fenceInfo; |
| 1255 | memset(&fenceInfo, 0, sizeof(VkFenceCreateInfo)); |
| 1256 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1257 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1258 | err = VK_CALL(CreateFence(fDevice, &fenceInfo, nullptr, &fence)); |
| 1259 | SkASSERT(!err); |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1260 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1261 | VkSubmitInfo submitInfo; |
| 1262 | memset(&submitInfo, 0, sizeof(VkSubmitInfo)); |
| 1263 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1264 | submitInfo.pNext = nullptr; |
| 1265 | submitInfo.waitSemaphoreCount = 0; |
| 1266 | submitInfo.pWaitSemaphores = nullptr; |
| 1267 | submitInfo.pWaitDstStageMask = 0; |
| 1268 | submitInfo.commandBufferCount = 1; |
| 1269 | submitInfo.pCommandBuffers = &cmdBuffer; |
| 1270 | submitInfo.signalSemaphoreCount = 0; |
| 1271 | submitInfo.pSignalSemaphores = nullptr; |
| 1272 | err = VK_CALL(QueueSubmit(this->queue(), 1, &submitInfo, fence)); |
| 1273 | SkASSERT(!err); |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1274 | |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1275 | err = VK_CALL(WaitForFences(fDevice, 1, &fence, true, UINT64_MAX)); |
| 1276 | if (VK_TIMEOUT == err) { |
| 1277 | GrVkMemory::FreeImageMemory(this, linearTiling, alloc); |
| 1278 | VK_CALL(DestroyImage(fDevice, image, nullptr)); |
egdaniel | 3602d4f | 2016-08-12 11:58:53 -0700 | [diff] [blame] | 1279 | GrVkMemory::FreeBufferMemory(this, GrVkBuffer::kCopyRead_Type, bufferAlloc); |
| 1280 | VK_CALL(DestroyBuffer(fDevice, buffer, nullptr)); |
| 1281 | VK_CALL(FreeCommandBuffers(fDevice, fCmdPool, 1, &cmdBuffer)); |
| 1282 | VK_CALL(DestroyFence(fDevice, fence, nullptr)); |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1283 | SkDebugf("Fence failed to signal: %d\n", err); |
| 1284 | SkFAIL("failing"); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1285 | } |
Greg Daniel | 20ece3a | 2017-03-28 10:24:43 -0400 | [diff] [blame] | 1286 | SkASSERT(!err); |
| 1287 | |
| 1288 | // Clean up transfer resources |
| 1289 | GrVkMemory::FreeBufferMemory(this, GrVkBuffer::kCopyRead_Type, bufferAlloc); |
| 1290 | VK_CALL(DestroyBuffer(fDevice, buffer, nullptr)); |
| 1291 | VK_CALL(FreeCommandBuffers(fDevice, fCmdPool, 1, &cmdBuffer)); |
| 1292 | VK_CALL(DestroyFence(fDevice, fence, nullptr)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1293 | } |
| 1294 | |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 1295 | GrVkImageInfo* info = new GrVkImageInfo; |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 1296 | info->fImage = image; |
| 1297 | info->fAlloc = alloc; |
| 1298 | info->fImageTiling = imageTiling; |
| 1299 | info->fImageLayout = initialLayout; |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 1300 | info->fFormat = pixelFormat; |
jvanverth | 2af0f1b | 2016-05-03 10:36:49 -0700 | [diff] [blame] | 1301 | info->fLevelCount = 1; |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 1302 | |
| 1303 | return (GrBackendObject)info; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | bool GrVkGpu::isTestingOnlyBackendTexture(GrBackendObject id) const { |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 1307 | const GrVkImageInfo* backend = reinterpret_cast<const GrVkImageInfo*>(id); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1308 | |
jvanverth | 1e305ba | 2016-06-01 09:39:15 -0700 | [diff] [blame] | 1309 | if (backend && backend->fImage && backend->fAlloc.fMemory) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1310 | VkMemoryRequirements req; |
| 1311 | memset(&req, 0, sizeof(req)); |
| 1312 | GR_VK_CALL(this->vkInterface(), GetImageMemoryRequirements(fDevice, |
| 1313 | backend->fImage, |
| 1314 | &req)); |
| 1315 | // TODO: find a better check |
| 1316 | // This will probably fail with a different driver |
| 1317 | return (req.size > 0) && (req.size <= 8192 * 8192); |
| 1318 | } |
| 1319 | |
| 1320 | return false; |
| 1321 | } |
| 1322 | |
| 1323 | void GrVkGpu::deleteTestingOnlyBackendTexture(GrBackendObject id, bool abandon) { |
jvanverth | 6b6ffc4 | 2016-06-13 14:28:07 -0700 | [diff] [blame] | 1324 | GrVkImageInfo* backend = reinterpret_cast<GrVkImageInfo*>(id); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1325 | if (backend) { |
| 1326 | if (!abandon) { |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 1327 | // something in the command buffer may still be using this, so force submit |
| 1328 | this->submitCommandBuffer(kForce_SyncQueue); |
jvanverth | 6b6ffc4 | 2016-06-13 14:28:07 -0700 | [diff] [blame] | 1329 | GrVkImage::DestroyImageInfo(this, backend); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1330 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 1331 | delete backend; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | //////////////////////////////////////////////////////////////////////////////// |
| 1336 | |
| 1337 | void GrVkGpu::addMemoryBarrier(VkPipelineStageFlags srcStageMask, |
| 1338 | VkPipelineStageFlags dstStageMask, |
| 1339 | bool byRegion, |
| 1340 | VkMemoryBarrier* barrier) const { |
| 1341 | SkASSERT(fCurrentCmdBuffer); |
| 1342 | fCurrentCmdBuffer->pipelineBarrier(this, |
| 1343 | srcStageMask, |
| 1344 | dstStageMask, |
| 1345 | byRegion, |
| 1346 | GrVkCommandBuffer::kMemory_BarrierType, |
| 1347 | barrier); |
| 1348 | } |
| 1349 | |
| 1350 | void GrVkGpu::addBufferMemoryBarrier(VkPipelineStageFlags srcStageMask, |
| 1351 | VkPipelineStageFlags dstStageMask, |
| 1352 | bool byRegion, |
| 1353 | VkBufferMemoryBarrier* barrier) const { |
| 1354 | SkASSERT(fCurrentCmdBuffer); |
| 1355 | fCurrentCmdBuffer->pipelineBarrier(this, |
| 1356 | srcStageMask, |
| 1357 | dstStageMask, |
| 1358 | byRegion, |
| 1359 | GrVkCommandBuffer::kBufferMemory_BarrierType, |
| 1360 | barrier); |
| 1361 | } |
| 1362 | |
| 1363 | void GrVkGpu::addImageMemoryBarrier(VkPipelineStageFlags srcStageMask, |
| 1364 | VkPipelineStageFlags dstStageMask, |
| 1365 | bool byRegion, |
| 1366 | VkImageMemoryBarrier* barrier) const { |
| 1367 | SkASSERT(fCurrentCmdBuffer); |
| 1368 | fCurrentCmdBuffer->pipelineBarrier(this, |
| 1369 | srcStageMask, |
| 1370 | dstStageMask, |
| 1371 | byRegion, |
| 1372 | GrVkCommandBuffer::kImageMemory_BarrierType, |
| 1373 | barrier); |
| 1374 | } |
| 1375 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 1376 | void GrVkGpu::finishOpList() { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1377 | // Submit the current command buffer to the Queue |
| 1378 | this->submitCommandBuffer(kSkip_SyncQueue); |
| 1379 | } |
| 1380 | |
egdaniel | 3d5d9ac | 2016-03-01 12:56:15 -0800 | [diff] [blame] | 1381 | void GrVkGpu::clearStencil(GrRenderTarget* target) { |
| 1382 | if (nullptr == target) { |
| 1383 | return; |
| 1384 | } |
| 1385 | GrStencilAttachment* stencil = target->renderTargetPriv().getStencilAttachment(); |
| 1386 | GrVkStencilAttachment* vkStencil = (GrVkStencilAttachment*)stencil; |
| 1387 | |
| 1388 | |
| 1389 | VkClearDepthStencilValue vkStencilColor; |
| 1390 | memset(&vkStencilColor, 0, sizeof(VkClearDepthStencilValue)); |
| 1391 | |
egdaniel | 3d5d9ac | 2016-03-01 12:56:15 -0800 | [diff] [blame] | 1392 | vkStencil->setImageLayout(this, |
| 1393 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 1394 | VK_ACCESS_TRANSFER_WRITE_BIT, |
| 1395 | VK_PIPELINE_STAGE_TRANSFER_BIT, |
egdaniel | 3d5d9ac | 2016-03-01 12:56:15 -0800 | [diff] [blame] | 1396 | false); |
| 1397 | |
egdaniel | 3d5d9ac | 2016-03-01 12:56:15 -0800 | [diff] [blame] | 1398 | VkImageSubresourceRange subRange; |
| 1399 | memset(&subRange, 0, sizeof(VkImageSubresourceRange)); |
| 1400 | subRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 1401 | subRange.baseMipLevel = 0; |
| 1402 | subRange.levelCount = 1; |
| 1403 | subRange.baseArrayLayer = 0; |
| 1404 | subRange.layerCount = 1; |
| 1405 | |
| 1406 | // TODO: I imagine that most times we want to clear a stencil it will be at the beginning of a |
| 1407 | // draw. Thus we should look into using the load op functions on the render pass to clear out |
| 1408 | // the stencil there. |
| 1409 | fCurrentCmdBuffer->clearDepthStencilImage(this, vkStencil, &vkStencilColor, 1, &subRange); |
| 1410 | } |
| 1411 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1412 | inline bool can_copy_image(const GrSurface* dst, |
| 1413 | const GrSurface* src, |
| 1414 | const GrVkGpu* gpu) { |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 1415 | const GrRenderTarget* dstRT = dst->asRenderTarget(); |
| 1416 | const GrRenderTarget* srcRT = src->asRenderTarget(); |
| 1417 | if (dstRT && srcRT) { |
| 1418 | if (srcRT->numColorSamples() != dstRT->numColorSamples()) { |
| 1419 | return false; |
| 1420 | } |
| 1421 | } else if (dstRT) { |
| 1422 | if (dstRT->numColorSamples() > 1) { |
| 1423 | return false; |
| 1424 | } |
| 1425 | } else if (srcRT) { |
| 1426 | if (srcRT->numColorSamples() > 1) { |
| 1427 | return false; |
| 1428 | } |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
Michael Jurka | 3251ed8 | 2017-04-05 09:52:55 -0700 | [diff] [blame] | 1431 | // We require that all vulkan GrSurfaces have been created with transfer_dst and transfer_src |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1432 | // as image usage flags. |
| 1433 | if (src->origin() == dst->origin() && |
| 1434 | GrBytesPerPixel(src->config()) == GrBytesPerPixel(dst->config())) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1435 | return true; |
| 1436 | } |
| 1437 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1438 | return false; |
| 1439 | } |
| 1440 | |
| 1441 | void GrVkGpu::copySurfaceAsCopyImage(GrSurface* dst, |
| 1442 | GrSurface* src, |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1443 | GrVkImage* dstImage, |
| 1444 | GrVkImage* srcImage, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1445 | const SkIRect& srcRect, |
| 1446 | const SkIPoint& dstPoint) { |
| 1447 | SkASSERT(can_copy_image(dst, src, this)); |
| 1448 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1449 | // These flags are for flushing/invalidating caches and for the dst image it doesn't matter if |
| 1450 | // the cache is flushed since it is only being written to. |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1451 | dstImage->setImageLayout(this, |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 1452 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 1453 | VK_ACCESS_TRANSFER_WRITE_BIT, |
| 1454 | VK_PIPELINE_STAGE_TRANSFER_BIT, |
| 1455 | false); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1456 | |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1457 | srcImage->setImageLayout(this, |
| 1458 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 1459 | VK_ACCESS_TRANSFER_READ_BIT, |
| 1460 | VK_PIPELINE_STAGE_TRANSFER_BIT, |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1461 | false); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1462 | |
| 1463 | // Flip rect if necessary |
| 1464 | SkIRect srcVkRect = srcRect; |
| 1465 | int32_t dstY = dstPoint.fY; |
| 1466 | |
| 1467 | if (kBottomLeft_GrSurfaceOrigin == src->origin()) { |
| 1468 | SkASSERT(kBottomLeft_GrSurfaceOrigin == dst->origin()); |
| 1469 | srcVkRect.fTop = src->height() - srcRect.fBottom; |
| 1470 | srcVkRect.fBottom = src->height() - srcRect.fTop; |
| 1471 | dstY = dst->height() - dstPoint.fY - srcVkRect.height(); |
| 1472 | } |
| 1473 | |
| 1474 | VkImageCopy copyRegion; |
| 1475 | memset(©Region, 0, sizeof(VkImageCopy)); |
| 1476 | copyRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; |
| 1477 | copyRegion.srcOffset = { srcVkRect.fLeft, srcVkRect.fTop, 0 }; |
| 1478 | copyRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; |
| 1479 | copyRegion.dstOffset = { dstPoint.fX, dstY, 0 }; |
egdaniel | c355bc8 | 2016-04-27 11:31:59 -0700 | [diff] [blame] | 1480 | copyRegion.extent = { (uint32_t)srcVkRect.width(), (uint32_t)srcVkRect.height(), 1 }; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1481 | |
| 1482 | fCurrentCmdBuffer->copyImage(this, |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1483 | srcImage, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1484 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1485 | dstImage, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1486 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 1487 | 1, |
| 1488 | ©Region); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 1489 | |
| 1490 | SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, |
| 1491 | srcRect.width(), srcRect.height()); |
| 1492 | this->didWriteToSurface(dst, &dstRect); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1493 | } |
| 1494 | |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1495 | inline bool can_copy_as_blit(const GrSurface* dst, |
| 1496 | const GrSurface* src, |
| 1497 | const GrVkImage* dstImage, |
| 1498 | const GrVkImage* srcImage, |
| 1499 | const GrVkGpu* gpu) { |
egdaniel | 6693355 | 2016-08-24 07:22:19 -0700 | [diff] [blame] | 1500 | // We require that all vulkan GrSurfaces have been created with transfer_dst and transfer_src |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1501 | // as image usage flags. |
| 1502 | const GrVkCaps& caps = gpu->vkCaps(); |
| 1503 | if (!caps.configCanBeDstofBlit(dst->config(), dstImage->isLinearTiled()) || |
| 1504 | !caps.configCanBeSrcofBlit(src->config(), srcImage->isLinearTiled())) { |
| 1505 | return false; |
| 1506 | } |
| 1507 | |
| 1508 | // We cannot blit images that are multisampled. Will need to figure out if we can blit the |
| 1509 | // resolved msaa though. |
| 1510 | if ((dst->asRenderTarget() && dst->asRenderTarget()->numColorSamples() > 1) || |
| 1511 | (src->asRenderTarget() && src->asRenderTarget()->numColorSamples() > 1)) { |
| 1512 | return false; |
| 1513 | } |
| 1514 | |
| 1515 | return true; |
| 1516 | } |
| 1517 | |
| 1518 | void GrVkGpu::copySurfaceAsBlit(GrSurface* dst, |
| 1519 | GrSurface* src, |
| 1520 | GrVkImage* dstImage, |
| 1521 | GrVkImage* srcImage, |
| 1522 | const SkIRect& srcRect, |
| 1523 | const SkIPoint& dstPoint) { |
| 1524 | SkASSERT(can_copy_as_blit(dst, src, dstImage, srcImage, this)); |
| 1525 | |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1526 | dstImage->setImageLayout(this, |
| 1527 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 1528 | VK_ACCESS_TRANSFER_WRITE_BIT, |
| 1529 | VK_PIPELINE_STAGE_TRANSFER_BIT, |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1530 | false); |
| 1531 | |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1532 | srcImage->setImageLayout(this, |
| 1533 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
jvanverth | 50c46c7 | 2016-05-06 12:31:28 -0700 | [diff] [blame] | 1534 | VK_ACCESS_TRANSFER_READ_BIT, |
| 1535 | VK_PIPELINE_STAGE_TRANSFER_BIT, |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1536 | false); |
| 1537 | |
| 1538 | // Flip rect if necessary |
| 1539 | SkIRect srcVkRect; |
egdaniel | 8af936d | 2016-04-07 10:17:47 -0700 | [diff] [blame] | 1540 | srcVkRect.fLeft = srcRect.fLeft; |
| 1541 | srcVkRect.fRight = srcRect.fRight; |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1542 | SkIRect dstRect; |
| 1543 | dstRect.fLeft = dstPoint.fX; |
egdaniel | 8af936d | 2016-04-07 10:17:47 -0700 | [diff] [blame] | 1544 | dstRect.fRight = dstPoint.fX + srcRect.width(); |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1545 | |
| 1546 | if (kBottomLeft_GrSurfaceOrigin == src->origin()) { |
| 1547 | srcVkRect.fTop = src->height() - srcRect.fBottom; |
| 1548 | srcVkRect.fBottom = src->height() - srcRect.fTop; |
| 1549 | } else { |
egdaniel | 8af936d | 2016-04-07 10:17:47 -0700 | [diff] [blame] | 1550 | srcVkRect.fTop = srcRect.fTop; |
| 1551 | srcVkRect.fBottom = srcRect.fBottom; |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | if (kBottomLeft_GrSurfaceOrigin == dst->origin()) { |
| 1555 | dstRect.fTop = dst->height() - dstPoint.fY - srcVkRect.height(); |
| 1556 | } else { |
| 1557 | dstRect.fTop = dstPoint.fY; |
| 1558 | } |
| 1559 | dstRect.fBottom = dstRect.fTop + srcVkRect.height(); |
| 1560 | |
| 1561 | // If we have different origins, we need to flip the top and bottom of the dst rect so that we |
| 1562 | // get the correct origintation of the copied data. |
| 1563 | if (src->origin() != dst->origin()) { |
| 1564 | SkTSwap(dstRect.fTop, dstRect.fBottom); |
| 1565 | } |
| 1566 | |
| 1567 | VkImageBlit blitRegion; |
| 1568 | memset(&blitRegion, 0, sizeof(VkImageBlit)); |
| 1569 | blitRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; |
| 1570 | blitRegion.srcOffsets[0] = { srcVkRect.fLeft, srcVkRect.fTop, 0 }; |
Greg Daniel | e76071c | 2016-11-02 11:57:06 -0400 | [diff] [blame] | 1571 | blitRegion.srcOffsets[1] = { srcVkRect.fRight, srcVkRect.fBottom, 1 }; |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1572 | blitRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; |
| 1573 | blitRegion.dstOffsets[0] = { dstRect.fLeft, dstRect.fTop, 0 }; |
Greg Daniel | e76071c | 2016-11-02 11:57:06 -0400 | [diff] [blame] | 1574 | blitRegion.dstOffsets[1] = { dstRect.fRight, dstRect.fBottom, 1 }; |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1575 | |
| 1576 | fCurrentCmdBuffer->blitImage(this, |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 1577 | *srcImage, |
| 1578 | *dstImage, |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1579 | 1, |
| 1580 | &blitRegion, |
| 1581 | VK_FILTER_NEAREST); // We never scale so any filter works here |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 1582 | |
| 1583 | this->didWriteToSurface(dst, &dstRect); |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 1586 | inline bool can_copy_as_resolve(const GrSurface* dst, |
| 1587 | const GrSurface* src, |
| 1588 | const GrVkGpu* gpu) { |
| 1589 | // Our src must be a multisampled render target |
| 1590 | if (!src->asRenderTarget() || src->asRenderTarget()->numColorSamples() <= 1) { |
| 1591 | return false; |
| 1592 | } |
| 1593 | |
Greg Daniel | 7d6f666 | 2017-04-18 16:40:35 -0400 | [diff] [blame] | 1594 | // The dst must not be a multisampled render target, expect in the case where the dst is the |
| 1595 | // resolve texture connected to the msaa src. We check for this in case we are copying a part of |
| 1596 | // a surface to a different region in the same surface. |
| 1597 | if (dst->asRenderTarget() && dst->asRenderTarget()->numColorSamples() > 1 && dst != src) { |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 1598 | return false; |
| 1599 | } |
| 1600 | |
| 1601 | // Surfaces must have the same origin. |
| 1602 | if (src->origin() != dst->origin()) { |
| 1603 | return false; |
| 1604 | } |
| 1605 | |
| 1606 | return true; |
| 1607 | } |
| 1608 | |
| 1609 | void GrVkGpu::copySurfaceAsResolve(GrSurface* dst, |
| 1610 | GrSurface* src, |
| 1611 | const SkIRect& srcRect, |
| 1612 | const SkIPoint& dstPoint) { |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 1613 | GrVkRenderTarget* srcRT = static_cast<GrVkRenderTarget*>(src->asRenderTarget()); |
Greg Daniel | bc26c39 | 2017-04-18 13:32:10 -0400 | [diff] [blame] | 1614 | this->resolveImage(dst, srcRT, srcRect, dstPoint); |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 1615 | } |
| 1616 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1617 | bool GrVkGpu::onCopySurface(GrSurface* dst, |
| 1618 | GrSurface* src, |
| 1619 | const SkIRect& srcRect, |
| 1620 | const SkIPoint& dstPoint) { |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 1621 | if (can_copy_as_resolve(dst, src, this)) { |
| 1622 | this->copySurfaceAsResolve(dst, src, srcRect, dstPoint); |
egdaniel | ec44099 | 2016-09-13 09:54:11 -0700 | [diff] [blame] | 1623 | return true; |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 1626 | if (this->vkCaps().mustSubmitCommandsBeforeCopyOp()) { |
| 1627 | this->submitCommandBuffer(GrVkGpu::kSkip_SyncQueue); |
| 1628 | } |
| 1629 | |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 1630 | if (fCopyManager.copySurfaceAsDraw(this, dst, src, srcRect, dstPoint)) { |
| 1631 | return true; |
| 1632 | } |
| 1633 | |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1634 | GrVkImage* dstImage; |
| 1635 | GrVkImage* srcImage; |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 1636 | GrRenderTarget* dstRT = dst->asRenderTarget(); |
| 1637 | if (dstRT) { |
| 1638 | GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(dstRT); |
| 1639 | dstImage = vkRT->numColorSamples() > 1 ? vkRT->msaaImage() : vkRT; |
| 1640 | } else { |
| 1641 | SkASSERT(dst->asTexture()); |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1642 | dstImage = static_cast<GrVkTexture*>(dst->asTexture()); |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1643 | } |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 1644 | GrRenderTarget* srcRT = src->asRenderTarget(); |
| 1645 | if (srcRT) { |
| 1646 | GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(srcRT); |
| 1647 | srcImage = vkRT->numColorSamples() > 1 ? vkRT->msaaImage() : vkRT; |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1648 | } else { |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 1649 | SkASSERT(src->asTexture()); |
| 1650 | srcImage = static_cast<GrVkTexture*>(src->asTexture()); |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1653 | if (can_copy_image(dst, src, this)) { |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 1654 | this->copySurfaceAsCopyImage(dst, src, dstImage, srcImage, srcRect, dstPoint); |
| 1655 | return true; |
| 1656 | } |
| 1657 | |
| 1658 | if (can_copy_as_blit(dst, src, dstImage, srcImage, this)) { |
| 1659 | this->copySurfaceAsBlit(dst, src, dstImage, srcImage, srcRect, dstPoint); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1660 | return true; |
| 1661 | } |
| 1662 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1663 | return false; |
| 1664 | } |
| 1665 | |
csmartdalton | c25c5d7 | 2016-11-01 07:03:59 -0700 | [diff] [blame] | 1666 | void GrVkGpu::onQueryMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&, |
| 1667 | int* effectiveSampleCnt, SamplePattern*) { |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 1668 | // TODO: stub. |
| 1669 | SkASSERT(!this->caps()->sampleLocationsSupport()); |
| 1670 | *effectiveSampleCnt = rt->desc().fSampleCnt; |
| 1671 | } |
| 1672 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1673 | bool GrVkGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height, size_t rowBytes, |
| 1674 | GrPixelConfig readConfig, DrawPreference* drawPreference, |
| 1675 | ReadPixelTempDrawInfo* tempDrawInfo) { |
egdaniel | 88e8aef | 2016-06-27 14:34:55 -0700 | [diff] [blame] | 1676 | // These settings we will always want if a temp draw is performed. |
| 1677 | tempDrawInfo->fTempSurfaceDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 1678 | tempDrawInfo->fTempSurfaceDesc.fWidth = width; |
| 1679 | tempDrawInfo->fTempSurfaceDesc.fHeight = height; |
| 1680 | tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; |
| 1681 | tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU y-flip for TL. |
bsalomon | b117ff1 | 2016-07-19 07:24:40 -0700 | [diff] [blame] | 1682 | tempDrawInfo->fTempSurfaceFit = SkBackingFit::kApprox; |
egdaniel | 88e8aef | 2016-06-27 14:34:55 -0700 | [diff] [blame] | 1683 | |
| 1684 | // For now assume no swizzling, we may change that below. |
| 1685 | tempDrawInfo->fSwizzle = GrSwizzle::RGBA(); |
| 1686 | |
| 1687 | // Depends on why we need/want a temp draw. Start off assuming no change, the surface we read |
| 1688 | // from will be srcConfig and we will read readConfig pixels from it. |
Brian Osman | 3391029 | 2017-04-18 14:38:53 -0400 | [diff] [blame] | 1689 | // Note that if we require a draw and return a non-renderable format for the temp surface the |
egdaniel | 88e8aef | 2016-06-27 14:34:55 -0700 | [diff] [blame] | 1690 | // base class will fail for us. |
| 1691 | tempDrawInfo->fTempSurfaceDesc.fConfig = srcSurface->config(); |
| 1692 | tempDrawInfo->fReadConfig = readConfig; |
| 1693 | |
egdaniel | 4583ec5 | 2016-06-27 12:57:00 -0700 | [diff] [blame] | 1694 | if (srcSurface->config() == readConfig) { |
| 1695 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1696 | } |
| 1697 | |
Brian Osman | 3391029 | 2017-04-18 14:38:53 -0400 | [diff] [blame] | 1698 | // Any config change requires a draw |
| 1699 | ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 1700 | tempDrawInfo->fTempSurfaceDesc.fConfig = readConfig; |
| 1701 | tempDrawInfo->fReadConfig = readConfig; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1702 | |
Brian Osman | 3391029 | 2017-04-18 14:38:53 -0400 | [diff] [blame] | 1703 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | bool GrVkGpu::onReadPixels(GrSurface* surface, |
| 1707 | int left, int top, int width, int height, |
| 1708 | GrPixelConfig config, |
| 1709 | void* buffer, |
| 1710 | size_t rowBytes) { |
| 1711 | VkFormat pixelFormat; |
| 1712 | if (!GrPixelConfigToVkFormat(config, &pixelFormat)) { |
| 1713 | return false; |
| 1714 | } |
| 1715 | |
egdaniel | 6693355 | 2016-08-24 07:22:19 -0700 | [diff] [blame] | 1716 | GrVkImage* image = nullptr; |
| 1717 | GrVkRenderTarget* rt = static_cast<GrVkRenderTarget*>(surface->asRenderTarget()); |
| 1718 | if (rt) { |
| 1719 | // resolve the render target if necessary |
| 1720 | switch (rt->getResolveType()) { |
| 1721 | case GrVkRenderTarget::kCantResolve_ResolveType: |
| 1722 | return false; |
| 1723 | case GrVkRenderTarget::kAutoResolves_ResolveType: |
| 1724 | break; |
| 1725 | case GrVkRenderTarget::kCanResolve_ResolveType: |
Greg Daniel | 69d4992 | 2017-02-23 09:44:02 -0500 | [diff] [blame] | 1726 | this->internalResolveRenderTarget(rt, false); |
egdaniel | 6693355 | 2016-08-24 07:22:19 -0700 | [diff] [blame] | 1727 | break; |
| 1728 | default: |
| 1729 | SkFAIL("Unknown resolve type"); |
| 1730 | } |
| 1731 | image = rt; |
| 1732 | } else { |
| 1733 | image = static_cast<GrVkTexture*>(surface->asTexture()); |
| 1734 | } |
| 1735 | |
| 1736 | if (!image) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1737 | return false; |
| 1738 | } |
| 1739 | |
| 1740 | // Change layout of our target so it can be used as copy |
egdaniel | 6693355 | 2016-08-24 07:22:19 -0700 | [diff] [blame] | 1741 | image->setImageLayout(this, |
| 1742 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
| 1743 | VK_ACCESS_TRANSFER_READ_BIT, |
| 1744 | VK_PIPELINE_STAGE_TRANSFER_BIT, |
| 1745 | false); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1746 | |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 1747 | size_t bpp = GrBytesPerPixel(config); |
| 1748 | size_t tightRowBytes = bpp * width; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1749 | bool flipY = kBottomLeft_GrSurfaceOrigin == surface->origin(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1750 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1751 | VkBufferImageCopy region; |
| 1752 | memset(®ion, 0, sizeof(VkBufferImageCopy)); |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 1753 | |
| 1754 | bool copyFromOrigin = this->vkCaps().mustDoCopiesFromOrigin(); |
| 1755 | if (copyFromOrigin) { |
| 1756 | region.imageOffset = { 0, 0, 0 }; |
| 1757 | region.imageExtent = { (uint32_t)(left + width), |
| 1758 | (uint32_t)(flipY ? surface->height() - top : top + height), |
| 1759 | 1 |
| 1760 | }; |
| 1761 | } else { |
| 1762 | VkOffset3D offset = { |
| 1763 | left, |
| 1764 | flipY ? surface->height() - top - height : top, |
| 1765 | 0 |
| 1766 | }; |
| 1767 | region.imageOffset = offset; |
| 1768 | region.imageExtent = { (uint32_t)width, (uint32_t)height, 1 }; |
| 1769 | } |
| 1770 | |
| 1771 | size_t transBufferRowBytes = bpp * region.imageExtent.width; |
| 1772 | GrVkTransferBuffer* transferBuffer = |
| 1773 | static_cast<GrVkTransferBuffer*>(this->createBuffer(transBufferRowBytes * height, |
| 1774 | kXferGpuToCpu_GrBufferType, |
| 1775 | kStream_GrAccessPattern)); |
| 1776 | |
| 1777 | // Copy the image to a buffer so we can map it to cpu memory |
jvanverth | db37909 | 2016-07-07 11:18:46 -0700 | [diff] [blame] | 1778 | region.bufferOffset = transferBuffer->offset(); |
egdaniel | 88e8aef | 2016-06-27 14:34:55 -0700 | [diff] [blame] | 1779 | region.bufferRowLength = 0; // Forces RowLength to be width. We handle the rowBytes below. |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1780 | region.bufferImageHeight = 0; // Forces height to be tightly packed. Only useful for 3d images. |
| 1781 | region.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1782 | |
| 1783 | fCurrentCmdBuffer->copyImageToBuffer(this, |
egdaniel | 6693355 | 2016-08-24 07:22:19 -0700 | [diff] [blame] | 1784 | image, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1785 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
| 1786 | transferBuffer, |
| 1787 | 1, |
| 1788 | ®ion); |
| 1789 | |
| 1790 | // make sure the copy to buffer has finished |
| 1791 | transferBuffer->addMemoryBarrier(this, |
| 1792 | VK_ACCESS_TRANSFER_WRITE_BIT, |
| 1793 | VK_ACCESS_HOST_READ_BIT, |
| 1794 | VK_PIPELINE_STAGE_TRANSFER_BIT, |
| 1795 | VK_PIPELINE_STAGE_HOST_BIT, |
| 1796 | false); |
| 1797 | |
| 1798 | // We need to submit the current command buffer to the Queue and make sure it finishes before |
| 1799 | // we can copy the data out of the buffer. |
| 1800 | this->submitCommandBuffer(kForce_SyncQueue); |
jvanverth | 9d54afc | 2016-09-20 09:20:03 -0700 | [diff] [blame] | 1801 | GrVkMemory::InvalidateMappedAlloc(this, transferBuffer->alloc()); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1802 | void* mappedMemory = transferBuffer->map(); |
| 1803 | |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 1804 | if (copyFromOrigin) { |
| 1805 | uint32_t skipRows = region.imageExtent.height - height; |
| 1806 | mappedMemory = (char*)mappedMemory + transBufferRowBytes * skipRows + bpp * left; |
| 1807 | } |
| 1808 | |
egdaniel | 88e8aef | 2016-06-27 14:34:55 -0700 | [diff] [blame] | 1809 | if (flipY) { |
| 1810 | const char* srcRow = reinterpret_cast<const char*>(mappedMemory); |
| 1811 | char* dstRow = reinterpret_cast<char*>(buffer)+(height - 1) * rowBytes; |
| 1812 | for (int y = 0; y < height; y++) { |
| 1813 | memcpy(dstRow, srcRow, tightRowBytes); |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 1814 | srcRow += transBufferRowBytes; |
egdaniel | 88e8aef | 2016-06-27 14:34:55 -0700 | [diff] [blame] | 1815 | dstRow -= rowBytes; |
| 1816 | } |
| 1817 | } else { |
Matt Sarett | cf3525a | 2017-01-24 12:43:41 -0500 | [diff] [blame] | 1818 | SkRectMemcpy(buffer, rowBytes, mappedMemory, transBufferRowBytes, tightRowBytes, height); |
egdaniel | 88e8aef | 2016-06-27 14:34:55 -0700 | [diff] [blame] | 1819 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1820 | |
| 1821 | transferBuffer->unmap(); |
| 1822 | transferBuffer->unref(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1823 | return true; |
| 1824 | } |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 1825 | |
egdaniel | 27bb284 | 2016-07-07 11:58:35 -0700 | [diff] [blame] | 1826 | // The RenderArea bounds we pass into BeginRenderPass must have a start x value that is a multiple |
| 1827 | // of the granularity. The width must also be a multiple of the granularity or eaqual to the width |
| 1828 | // the the entire attachment. Similar requirements for the y and height components. |
| 1829 | void adjust_bounds_to_granularity(SkIRect* dstBounds, const SkIRect& srcBounds, |
| 1830 | const VkExtent2D& granularity, int maxWidth, int maxHeight) { |
| 1831 | // Adjust Width |
egdaniel | d5797b3 | 2016-09-20 12:57:45 -0700 | [diff] [blame] | 1832 | if ((0 != granularity.width && 1 != granularity.width)) { |
| 1833 | // Start with the right side of rect so we know if we end up going pass the maxWidth. |
| 1834 | int rightAdj = srcBounds.fRight % granularity.width; |
| 1835 | if (rightAdj != 0) { |
| 1836 | rightAdj = granularity.width - rightAdj; |
| 1837 | } |
| 1838 | dstBounds->fRight = srcBounds.fRight + rightAdj; |
| 1839 | if (dstBounds->fRight > maxWidth) { |
| 1840 | dstBounds->fRight = maxWidth; |
| 1841 | dstBounds->fLeft = 0; |
| 1842 | } else { |
| 1843 | dstBounds->fLeft = srcBounds.fLeft - srcBounds.fLeft % granularity.width; |
| 1844 | } |
egdaniel | 27bb284 | 2016-07-07 11:58:35 -0700 | [diff] [blame] | 1845 | } else { |
egdaniel | d5797b3 | 2016-09-20 12:57:45 -0700 | [diff] [blame] | 1846 | dstBounds->fLeft = srcBounds.fLeft; |
| 1847 | dstBounds->fRight = srcBounds.fRight; |
egdaniel | 27bb284 | 2016-07-07 11:58:35 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | // Adjust height |
egdaniel | d5797b3 | 2016-09-20 12:57:45 -0700 | [diff] [blame] | 1851 | if ((0 != granularity.height && 1 != granularity.height)) { |
| 1852 | // Start with the bottom side of rect so we know if we end up going pass the maxHeight. |
| 1853 | int bottomAdj = srcBounds.fBottom % granularity.height; |
| 1854 | if (bottomAdj != 0) { |
| 1855 | bottomAdj = granularity.height - bottomAdj; |
| 1856 | } |
| 1857 | dstBounds->fBottom = srcBounds.fBottom + bottomAdj; |
| 1858 | if (dstBounds->fBottom > maxHeight) { |
| 1859 | dstBounds->fBottom = maxHeight; |
| 1860 | dstBounds->fTop = 0; |
| 1861 | } else { |
| 1862 | dstBounds->fTop = srcBounds.fTop - srcBounds.fTop % granularity.height; |
| 1863 | } |
egdaniel | 27bb284 | 2016-07-07 11:58:35 -0700 | [diff] [blame] | 1864 | } else { |
egdaniel | d5797b3 | 2016-09-20 12:57:45 -0700 | [diff] [blame] | 1865 | dstBounds->fTop = srcBounds.fTop; |
| 1866 | dstBounds->fBottom = srcBounds.fBottom; |
egdaniel | 27bb284 | 2016-07-07 11:58:35 -0700 | [diff] [blame] | 1867 | } |
| 1868 | } |
| 1869 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 1870 | void GrVkGpu::submitSecondaryCommandBuffer(const SkTArray<GrVkSecondaryCommandBuffer*>& buffers, |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 1871 | const GrVkRenderPass* renderPass, |
| 1872 | const VkClearValue* colorClear, |
| 1873 | GrVkRenderTarget* target, |
| 1874 | const SkIRect& bounds) { |
egdaniel | e7d1b24 | 2016-07-01 08:06:45 -0700 | [diff] [blame] | 1875 | const SkIRect* pBounds = &bounds; |
| 1876 | SkIRect flippedBounds; |
| 1877 | if (kBottomLeft_GrSurfaceOrigin == target->origin()) { |
| 1878 | flippedBounds = bounds; |
| 1879 | flippedBounds.fTop = target->height() - bounds.fBottom; |
| 1880 | flippedBounds.fBottom = target->height() - bounds.fTop; |
| 1881 | pBounds = &flippedBounds; |
| 1882 | } |
| 1883 | |
egdaniel | 27bb284 | 2016-07-07 11:58:35 -0700 | [diff] [blame] | 1884 | // The bounds we use for the render pass should be of the granularity supported |
| 1885 | // by the device. |
| 1886 | const VkExtent2D& granularity = renderPass->granularity(); |
| 1887 | SkIRect adjustedBounds; |
| 1888 | if ((0 != granularity.width && 1 != granularity.width) || |
| 1889 | (0 != granularity.height && 1 != granularity.height)) { |
| 1890 | adjust_bounds_to_granularity(&adjustedBounds, *pBounds, granularity, |
| 1891 | target->width(), target->height()); |
| 1892 | pBounds = &adjustedBounds; |
| 1893 | } |
| 1894 | |
Greg Daniel | 77a86f8 | 2017-01-23 11:04:45 -0500 | [diff] [blame] | 1895 | fCurrentCmdBuffer->beginRenderPass(this, renderPass, colorClear, *target, *pBounds, true); |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 1896 | for (int i = 0; i < buffers.count(); ++i) { |
| 1897 | fCurrentCmdBuffer->executeCommands(this, buffers[i]); |
| 1898 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1899 | fCurrentCmdBuffer->endRenderPass(this); |
egdaniel | 6693355 | 2016-08-24 07:22:19 -0700 | [diff] [blame] | 1900 | |
egdaniel | ce3bfb1 | 2016-08-26 11:05:13 -0700 | [diff] [blame] | 1901 | this->didWriteToSurface(target, &bounds); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1902 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 1903 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 1904 | GrFence SK_WARN_UNUSED_RESULT GrVkGpu::insertFence() { |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 1905 | VkFenceCreateInfo createInfo; |
| 1906 | memset(&createInfo, 0, sizeof(VkFenceCreateInfo)); |
| 1907 | createInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1908 | createInfo.pNext = nullptr; |
| 1909 | createInfo.flags = 0; |
| 1910 | VkFence fence = VK_NULL_HANDLE; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 1911 | |
| 1912 | VK_CALL_ERRCHECK(CreateFence(this->device(), &createInfo, nullptr, &fence)); |
| 1913 | VK_CALL(QueueSubmit(this->queue(), 0, nullptr, fence)); |
| 1914 | |
| 1915 | GR_STATIC_ASSERT(sizeof(GrFence) >= sizeof(VkFence)); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 1916 | return (GrFence)fence; |
| 1917 | } |
| 1918 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 1919 | bool GrVkGpu::waitFence(GrFence fence, uint64_t timeout) { |
| 1920 | SkASSERT(VK_NULL_HANDLE != (VkFence)fence); |
| 1921 | |
| 1922 | VkResult result = VK_CALL(WaitForFences(this->device(), 1, (VkFence*)&fence, VK_TRUE, timeout)); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 1923 | return (VK_SUCCESS == result); |
| 1924 | } |
| 1925 | |
| 1926 | void GrVkGpu::deleteFence(GrFence fence) const { |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 1927 | VK_CALL(DestroyFence(this->device(), (VkFence)fence, nullptr)); |
| 1928 | } |
| 1929 | |
| 1930 | sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT GrVkGpu::makeSemaphore() { |
| 1931 | return GrVkSemaphore::Make(this); |
| 1932 | } |
| 1933 | |
Brian Osman | dc87c95 | 2017-04-28 13:57:38 -0400 | [diff] [blame] | 1934 | void GrVkGpu::insertSemaphore(sk_sp<GrSemaphore> semaphore, bool /*flush*/) { |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 1935 | GrVkSemaphore* vkSem = static_cast<GrVkSemaphore*>(semaphore.get()); |
| 1936 | |
Brian Osman | dc87c95 | 2017-04-28 13:57:38 -0400 | [diff] [blame] | 1937 | // We *always* flush, so ignore that parameter |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 1938 | this->submitCommandBuffer(kSkip_SyncQueue, vkSem->getResource()); |
| 1939 | } |
| 1940 | |
| 1941 | void GrVkGpu::waitSemaphore(sk_sp<GrSemaphore> semaphore) { |
| 1942 | GrVkSemaphore* vkSem = static_cast<GrVkSemaphore*>(semaphore.get()); |
| 1943 | |
| 1944 | const GrVkSemaphore::Resource* resource = vkSem->getResource(); |
| 1945 | resource->ref(); |
| 1946 | fSemaphoresToWaitOn.push_back(resource); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 1947 | } |