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 | #ifndef GrVkGpu_DEFINED |
| 9 | #define GrVkGpu_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/vk/GrVkBackendContext.h" |
| 12 | #include "include/gpu/vk/GrVkTypes.h" |
| 13 | #include "src/gpu/GrGpu.h" |
| 14 | #include "src/gpu/vk/GrVkCaps.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/vk/GrVkIndexBuffer.h" |
| 16 | #include "src/gpu/vk/GrVkMemory.h" |
| 17 | #include "src/gpu/vk/GrVkResourceProvider.h" |
| 18 | #include "src/gpu/vk/GrVkSemaphore.h" |
| 19 | #include "src/gpu/vk/GrVkUtil.h" |
| 20 | #include "src/gpu/vk/GrVkVertexBuffer.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 21 | |
| 22 | class GrPipeline; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 23 | |
| 24 | class GrVkBufferImpl; |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 25 | class GrVkCommandPool; |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 26 | class GrVkGpuRTCommandBuffer; |
| 27 | class GrVkGpuTextureCommandBuffer; |
Greg Daniel | 81df041 | 2018-05-31 13:13:33 -0400 | [diff] [blame] | 28 | class GrVkMemoryAllocator; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 29 | class GrVkPipeline; |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 30 | class GrVkPipelineState; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 31 | class GrVkPrimaryCommandBuffer; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 32 | class GrVkRenderPass; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 33 | class GrVkSecondaryCommandBuffer; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 34 | class GrVkTexture; |
| 35 | struct GrVkInterface; |
| 36 | |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 37 | namespace SkSL { |
| 38 | class Compiler; |
| 39 | } |
| 40 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 41 | class GrVkGpu : public GrGpu { |
| 42 | public: |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 43 | static sk_sp<GrGpu> Make(const GrVkBackendContext&, const GrContextOptions&, GrContext*); |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 44 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 45 | ~GrVkGpu() override; |
| 46 | |
Greg Daniel | 8606cf8 | 2017-05-08 16:17:53 -0400 | [diff] [blame] | 47 | void disconnect(DisconnectType) override; |
| 48 | |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 49 | const GrVkInterface* vkInterface() const { return fInterface.get(); } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 50 | const GrVkCaps& vkCaps() const { return *fVkCaps; } |
| 51 | |
Greg Daniel | 81df041 | 2018-05-31 13:13:33 -0400 | [diff] [blame] | 52 | GrVkMemoryAllocator* memoryAllocator() const { return fMemoryAllocator.get(); } |
| 53 | |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 54 | VkPhysicalDevice physicalDevice() const { return fPhysicalDevice; } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 55 | VkDevice device() const { return fDevice; } |
| 56 | VkQueue queue() const { return fQueue; } |
Greg Daniel | ecddbc0 | 2018-08-30 16:39:34 -0400 | [diff] [blame] | 57 | uint32_t queueIndex() const { return fQueueIndex; } |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 58 | GrVkCommandPool* cmdPool() const { return fCmdPool; } |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 59 | const VkPhysicalDeviceProperties& physicalDeviceProperties() const { |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 60 | return fPhysDevProps; |
| 61 | } |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 62 | const VkPhysicalDeviceMemoryProperties& physicalDeviceMemoryProperties() const { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 63 | return fPhysDevMemProps; |
| 64 | } |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 65 | bool protectedContext() const { return fProtectedContext == GrProtected::kYes; } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 66 | |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 67 | GrVkResourceProvider& resourceProvider() { return fResourceProvider; } |
| 68 | |
| 69 | GrVkPrimaryCommandBuffer* currentCommandBuffer() { return fCurrentCmdBuffer; } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 70 | |
| 71 | enum SyncQueue { |
| 72 | kForce_SyncQueue, |
| 73 | kSkip_SyncQueue |
| 74 | }; |
| 75 | |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 76 | void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>*) override { |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 77 | SkASSERT(!this->caps()->sampleLocationsSupport()); |
| 78 | SK_ABORT("Sample locations not yet implemented for Vulkan."); |
| 79 | } |
| 80 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 81 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} |
| 82 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 83 | GrBackendTexture createBackendTexture(int w, int h, const GrBackendFormat&, |
| 84 | GrMipMapped, GrRenderable, |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 85 | const void* pixels, size_t rowBytes, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 86 | const SkColor4f* color, |
| 87 | GrProtected isProtected) override; |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 88 | void deleteBackendTexture(const GrBackendTexture&) override; |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 89 | #if GR_TEST_UTILS |
| 90 | bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 91 | |
Brian Osman | 2d010b6 | 2018-08-09 10:55:09 -0400 | [diff] [blame] | 92 | GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 93 | void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; |
| 94 | |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 95 | void testingOnly_flushGpuAndSync() override; |
Brian Osman | fd7657c | 2019-04-25 11:34:07 -0400 | [diff] [blame] | 96 | |
| 97 | void resetShaderCacheForTesting() const override { |
| 98 | fResourceProvider.resetShaderCacheForTesting(); |
| 99 | } |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 100 | #endif |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 101 | |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 102 | GrStencilAttachment* createStencilAttachmentForRenderTarget( |
| 103 | const GrRenderTarget*, int width, int height, int numStencilSamples) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 104 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 105 | GrGpuRTCommandBuffer* getCommandBuffer( |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 106 | GrRenderTarget*, GrSurfaceOrigin, const SkRect&, |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 107 | const GrGpuRTCommandBuffer::LoadAndStoreInfo&, |
| 108 | const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override; |
| 109 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 110 | GrGpuTextureCommandBuffer* getCommandBuffer(GrTexture*, GrSurfaceOrigin) override; |
| 111 | |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 112 | |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 113 | void addBufferMemoryBarrier(const GrVkResource*, |
| 114 | VkPipelineStageFlags srcStageMask, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 115 | VkPipelineStageFlags dstStageMask, |
| 116 | bool byRegion, |
| 117 | VkBufferMemoryBarrier* barrier) const; |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 118 | void addImageMemoryBarrier(const GrVkResource*, |
| 119 | VkPipelineStageFlags srcStageMask, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 120 | VkPipelineStageFlags dstStageMask, |
| 121 | bool byRegion, |
| 122 | VkImageMemoryBarrier* barrier) const; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 123 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 124 | SkSL::Compiler* shaderCompiler() const { |
| 125 | return fCompiler; |
| 126 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 127 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 128 | bool onRegenerateMipMapLevels(GrTexture* tex) override; |
| 129 | |
Greg Daniel | 0a77f43 | 2018-12-06 11:23:32 -0500 | [diff] [blame] | 130 | void resolveRenderTargetNoFlush(GrRenderTarget* target) { |
| 131 | this->internalResolveRenderTarget(target, false); |
| 132 | } |
| 133 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 134 | void onResolveRenderTarget(GrRenderTarget* target) override { |
Greg Daniel | 0a77f43 | 2018-12-06 11:23:32 -0500 | [diff] [blame] | 135 | // This resolve is called when we are preparing an msaa surface for external I/O. It is |
| 136 | // called after flushing, so we need to make sure we submit the command buffer after doing |
| 137 | // the resolve so that the resolve actually happens. |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 138 | this->internalResolveRenderTarget(target, true); |
Greg Daniel | 69d4992 | 2017-02-23 09:44:02 -0500 | [diff] [blame] | 139 | } |
egdaniel | 6693355 | 2016-08-24 07:22:19 -0700 | [diff] [blame] | 140 | |
Greg Daniel | 8daf3b7 | 2019-07-30 09:57:26 -0400 | [diff] [blame] | 141 | void submitSecondaryCommandBuffer(SkTArray<std::unique_ptr<GrVkSecondaryCommandBuffer>>&, |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 142 | const GrVkRenderPass*, |
Robert Phillips | 8c326e9 | 2017-08-10 13:50:17 -0400 | [diff] [blame] | 143 | const VkClearValue* colorClear, |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 144 | GrVkRenderTarget*, GrSurfaceOrigin, |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 145 | const SkIRect& bounds); |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 146 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 147 | void submit(GrGpuCommandBuffer*) override; |
| 148 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 149 | GrFence SK_WARN_UNUSED_RESULT insertFence() override; |
| 150 | bool waitFence(GrFence, uint64_t timeout) override; |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 151 | void deleteFence(GrFence) const override; |
| 152 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 153 | sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override; |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 154 | sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore, |
| 155 | GrResourceProvider::SemaphoreWrapType wrapType, |
| 156 | GrWrapOwnership ownership) override; |
Greg Daniel | 858e12c | 2018-12-06 11:11:37 -0500 | [diff] [blame] | 157 | void insertSemaphore(sk_sp<GrSemaphore> semaphore) override; |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 158 | void waitSemaphore(sk_sp<GrSemaphore> semaphore) override; |
| 159 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 160 | // These match the definitions in SkDrawable, from whence they came |
| 161 | typedef void* SubmitContext; |
| 162 | typedef void (*SubmitProc)(SubmitContext submitContext); |
| 163 | |
| 164 | // Adds an SkDrawable::GpuDrawHandler that we will delete the next time we submit the primary |
| 165 | // command buffer to the gpu. |
| 166 | void addDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable); |
| 167 | |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 168 | void checkFinishProcs() override { fResourceProvider.checkCommandBuffers(); } |
| 169 | |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 170 | sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override; |
| 171 | |
Greg Daniel | 6888c0d | 2017-08-25 11:55:50 -0400 | [diff] [blame] | 172 | void copyBuffer(GrVkBuffer* srcBuffer, GrVkBuffer* dstBuffer, VkDeviceSize srcOffset, |
| 173 | VkDeviceSize dstOffset, VkDeviceSize size); |
jvanverth | db37909 | 2016-07-07 11:18:46 -0700 | [diff] [blame] | 174 | bool updateBuffer(GrVkBuffer* buffer, const void* src, VkDeviceSize offset, VkDeviceSize size); |
jvanverth | a584de9 | 2016-06-30 09:10:52 -0700 | [diff] [blame] | 175 | |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 176 | uint32_t getExtraSamplerKeyForProgram(const GrSamplerState&, |
| 177 | const GrBackendFormat& format) override; |
| 178 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 179 | enum PersistentCacheKeyType : uint32_t { |
| 180 | kShader_PersistentCacheKeyType = 0, |
| 181 | kPipelineCache_PersistentCacheKeyType = 1, |
| 182 | }; |
| 183 | |
| 184 | void storeVkPipelineCacheData() override; |
| 185 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 186 | private: |
Greg Daniel | 98bffae | 2018-08-01 13:25:41 -0400 | [diff] [blame] | 187 | GrVkGpu(GrContext*, const GrContextOptions&, const GrVkBackendContext&, |
Greg Daniel | 41f0e28 | 2019-01-28 13:15:05 -0500 | [diff] [blame] | 188 | sk_sp<const GrVkInterface>, uint32_t instanceVersion, uint32_t physicalDeviceVersion); |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 189 | |
egdaniel | cfcd181 | 2016-03-22 07:16:10 -0700 | [diff] [blame] | 190 | void onResetContext(uint32_t resetBits) override {} |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 191 | |
Greg Daniel | 8606cf8 | 2017-05-08 16:17:53 -0400 | [diff] [blame] | 192 | void destroyResources(); |
| 193 | |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 194 | sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc&, GrRenderable, int renderTargetSampleCnt, |
| 195 | SkBudgeted, GrProtected, const GrMipLevel[], |
| 196 | int mipLevelCount) override; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 197 | sk_sp<GrTexture> onCreateCompressedTexture(int width, int height, SkImage::CompressionType, |
| 198 | SkBudgeted, const void* data) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 199 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 200 | sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership, |
| 201 | GrWrapCacheable, GrIOType) override; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 202 | sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 203 | int sampleCnt, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 204 | GrColorType colorType, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 205 | GrWrapOwnership, |
| 206 | GrWrapCacheable) override; |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 207 | sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&, |
| 208 | GrColorType) override; |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 209 | |
| 210 | sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 211 | int sampleCnt, GrColorType) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 212 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 213 | sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&, |
| 214 | const GrVkDrawableInfo&) override; |
| 215 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 216 | sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern, |
| 217 | const void* data) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 218 | |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame^] | 219 | bool onReadPixels(GrSurface* surface, int left, int top, int width, int height, |
| 220 | GrColorType surfaceColorType, GrColorType dstColorType, void* buffer, |
| 221 | size_t rowBytes) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 222 | |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame^] | 223 | bool onWritePixels(GrSurface* surface, int left, int top, int width, int height, |
| 224 | GrColorType surfaceColorType, GrColorType srcColorType, |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 225 | const GrMipLevel texels[], int mipLevelCount) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 226 | |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame^] | 227 | bool onTransferPixelsTo(GrTexture*, int left, int top, int width, int height, |
| 228 | GrColorType textureColorType, GrColorType bufferColorType, |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 229 | GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override; |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 230 | bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame^] | 231 | GrColorType surfaceColorType, GrColorType bufferColorType, |
| 232 | GrGpuBuffer* transferBuffer, size_t offset) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 233 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 234 | bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | 55fa647 | 2018-03-16 16:13:10 -0400 | [diff] [blame] | 235 | const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) override; |
Brian Salomon | 9b009bb | 2018-02-14 13:53:55 -0500 | [diff] [blame] | 236 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 237 | void onFinishFlush(GrSurfaceProxy*[], int, SkSurface::BackendSurfaceAccess access, |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 238 | const GrFlushInfo&, const GrPrepareForExternalIORequests&) override; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 239 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 240 | // Ends and submits the current command buffer to the queue and then creates a new command |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 241 | // buffer and begins it. If sync is set to kForce_SyncQueue, the function will wait for all |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 242 | // work in the queue to finish before returning. If this GrVkGpu object has any semaphores in |
| 243 | // fSemaphoreToSignal, we will add those signal semaphores to the submission of this command |
| 244 | // buffer. If this GrVkGpu object has any semaphores in fSemaphoresToWaitOn, we will add those |
| 245 | // wait semaphores to the submission of this command buffer. |
Greg Daniel | a3aa75a | 2019-04-12 14:24:55 -0400 | [diff] [blame] | 246 | void submitCommandBuffer(SyncQueue sync, GrGpuFinishedProc finishedProc = nullptr, |
| 247 | GrGpuFinishedContext finishedContext = nullptr); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 248 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 249 | void internalResolveRenderTarget(GrRenderTarget*, bool requiresSubmit); |
Greg Daniel | 69d4992 | 2017-02-23 09:44:02 -0500 | [diff] [blame] | 250 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 251 | void copySurfaceAsCopyImage(GrSurface* dst, GrSurface* src, GrVkImage* dstImage, |
| 252 | GrVkImage* srcImage, const SkIRect& srcRect, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 253 | const SkIPoint& dstPoint); |
| 254 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 255 | void copySurfaceAsBlit(GrSurface* dst, GrSurface* src, GrVkImage* dstImage, GrVkImage* srcImage, |
| 256 | const SkIRect& srcRect, const SkIPoint& dstPoint); |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 257 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 258 | void copySurfaceAsResolve(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 259 | const SkIPoint& dstPoint); |
| 260 | |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 261 | // helpers for onCreateTexture and writeTexturePixels |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 262 | bool uploadTexDataLinear(GrVkTexture* tex, int left, int top, int width, int height, |
| 263 | GrColorType colorType, const void* data, size_t rowBytes); |
| 264 | bool uploadTexDataOptimal(GrVkTexture* tex, int left, int top, int width, int height, |
| 265 | GrColorType colorType, const GrMipLevel texels[], int mipLevelCount); |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 266 | bool uploadTexDataCompressed(GrVkTexture* tex, int left, int top, int width, int height, |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 267 | SkImage::CompressionType, const void* data); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 268 | void resolveImage(GrSurface* dst, GrVkRenderTarget* src, const SkIRect& srcRect, |
| 269 | const SkIPoint& dstPoint); |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 270 | |
Brian Salomon | b450f3b | 2019-07-09 09:36:51 -0400 | [diff] [blame] | 271 | bool createVkImageForBackendSurface(VkFormat vkFormat, int w, int h, bool texturable, |
| 272 | bool renderable, GrMipMapped mipMapped, const void* srcData, |
| 273 | size_t srcRowBytes, const SkColor4f* color, |
| 274 | GrVkImageInfo* info, GrProtected isProtected); |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 275 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 276 | sk_sp<const GrVkInterface> fInterface; |
| 277 | sk_sp<GrVkMemoryAllocator> fMemoryAllocator; |
| 278 | sk_sp<GrVkCaps> fVkCaps; |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 279 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 280 | VkInstance fInstance; |
| 281 | VkPhysicalDevice fPhysicalDevice; |
| 282 | VkDevice fDevice; |
| 283 | VkQueue fQueue; // Must be Graphics queue |
| 284 | uint32_t fQueueIndex; |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 285 | |
| 286 | // Created by GrVkGpu |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 287 | GrVkResourceProvider fResourceProvider; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 288 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 289 | GrVkCommandPool* fCmdPool; |
| 290 | |
| 291 | // just a raw pointer; object's lifespan is managed by fCmdPool |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 292 | GrVkPrimaryCommandBuffer* fCurrentCmdBuffer; |
jvanverth | 6b6ffc4 | 2016-06-13 14:28:07 -0700 | [diff] [blame] | 293 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 294 | SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToWaitOn; |
| 295 | SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToSignal; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 296 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 297 | SkTArray<std::unique_ptr<SkDrawable::GpuDrawHandler>> fDrawables; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 298 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 299 | VkPhysicalDeviceProperties fPhysDevProps; |
| 300 | VkPhysicalDeviceMemoryProperties fPhysDevMemProps; |
| 301 | |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 302 | // compiler used for compiling sksl into spirv. We only want to create the compiler once since |
| 303 | // there is significant overhead to the first compile of any compiler. |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 304 | SkSL::Compiler* fCompiler; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 305 | |
Greg Daniel | 8606cf8 | 2017-05-08 16:17:53 -0400 | [diff] [blame] | 306 | // We need a bool to track whether or not we've already disconnected all the gpu resources from |
| 307 | // vulkan context. |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 308 | bool fDisconnected; |
Greg Daniel | 8606cf8 | 2017-05-08 16:17:53 -0400 | [diff] [blame] | 309 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 310 | GrProtected fProtectedContext; |
| 311 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 312 | std::unique_ptr<GrVkGpuRTCommandBuffer> fCachedRTCommandBuffer; |
| 313 | std::unique_ptr<GrVkGpuTextureCommandBuffer> fCachedTexCommandBuffer; |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 314 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 315 | typedef GrGpu INHERITED; |
| 316 | }; |
| 317 | |
| 318 | #endif |