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" |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrStagingBufferManager.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/vk/GrVkCaps.h" |
Greg Daniel | a8c3210 | 2020-12-30 15:09:32 -0500 | [diff] [blame] | 16 | #include "src/gpu/vk/GrVkMSAALoadManager.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/vk/GrVkMemory.h" |
| 18 | #include "src/gpu/vk/GrVkResourceProvider.h" |
| 19 | #include "src/gpu/vk/GrVkSemaphore.h" |
| 20 | #include "src/gpu/vk/GrVkUtil.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 21 | |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 22 | class GrDirectContext; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 23 | class GrPipeline; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 24 | |
Greg Daniel | af1d193 | 2021-02-08 13:55:26 -0500 | [diff] [blame] | 25 | class GrVkBuffer; |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 26 | class GrVkCommandPool; |
Greg Daniel | 60ec617 | 2021-04-16 11:31:58 -0400 | [diff] [blame] | 27 | class GrVkFramebuffer; |
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 | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 32 | class GrVkOpsRenderPass; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 33 | class GrVkRenderPass; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 34 | class GrVkSecondaryCommandBuffer; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 35 | class GrVkTexture; |
| 36 | struct GrVkInterface; |
| 37 | |
| 38 | class GrVkGpu : public GrGpu { |
| 39 | public: |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 40 | static sk_sp<GrGpu> Make(const GrVkBackendContext&, const GrContextOptions&, GrDirectContext*); |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 41 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 42 | ~GrVkGpu() override; |
| 43 | |
Greg Daniel | 8606cf8 | 2017-05-08 16:17:53 -0400 | [diff] [blame] | 44 | void disconnect(DisconnectType) override; |
Greg Daniel | ee792d6 | 2020-11-24 14:02:04 -0500 | [diff] [blame] | 45 | bool disconnected() const { return fDisconnected; } |
Greg Daniel | 8606cf8 | 2017-05-08 16:17:53 -0400 | [diff] [blame] | 46 | |
Greg Daniel | 428523f | 2021-03-30 14:22:54 -0400 | [diff] [blame] | 47 | void releaseUnlockedBackendObjects() override { |
| 48 | fResourceProvider.releaseUnlockedBackendObjects(); |
| 49 | } |
| 50 | |
Robert Phillips | ae67c52 | 2021-03-03 11:03:38 -0500 | [diff] [blame] | 51 | GrThreadSafePipelineBuilder* pipelineBuilder() override; |
| 52 | sk_sp<GrThreadSafePipelineBuilder> refPipelineBuilder() override; |
| 53 | |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 54 | const GrVkInterface* vkInterface() const { return fInterface.get(); } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 55 | const GrVkCaps& vkCaps() const { return *fVkCaps; } |
| 56 | |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 57 | GrStagingBufferManager* stagingBufferManager() override { return &fStagingBufferManager; } |
Jim Van Verth | 1aaf41b | 2020-07-29 09:24:29 -0400 | [diff] [blame] | 58 | void takeOwnershipOfBuffer(sk_sp<GrGpuBuffer>) override; |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 59 | |
Greg Daniel | 6e35a00 | 2020-04-01 13:29:59 -0400 | [diff] [blame] | 60 | bool isDeviceLost() const override { return fDeviceIsLost; } |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 61 | |
Greg Daniel | 81df041 | 2018-05-31 13:13:33 -0400 | [diff] [blame] | 62 | GrVkMemoryAllocator* memoryAllocator() const { return fMemoryAllocator.get(); } |
| 63 | |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 64 | VkPhysicalDevice physicalDevice() const { return fPhysicalDevice; } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 65 | VkDevice device() const { return fDevice; } |
| 66 | VkQueue queue() const { return fQueue; } |
Greg Daniel | ecddbc0 | 2018-08-30 16:39:34 -0400 | [diff] [blame] | 67 | uint32_t queueIndex() const { return fQueueIndex; } |
Greg Daniel | 288ecf6 | 2020-06-05 10:22:26 -0400 | [diff] [blame] | 68 | GrVkCommandPool* cmdPool() const { return fMainCmdPool; } |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 69 | const VkPhysicalDeviceProperties& physicalDeviceProperties() const { |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 70 | return fPhysDevProps; |
| 71 | } |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 72 | const VkPhysicalDeviceMemoryProperties& physicalDeviceMemoryProperties() const { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 73 | return fPhysDevMemProps; |
| 74 | } |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 75 | bool protectedContext() const { return fProtectedContext == GrProtected::kYes; } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 76 | |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 77 | GrVkResourceProvider& resourceProvider() { return fResourceProvider; } |
| 78 | |
Greg Daniel | 288ecf6 | 2020-06-05 10:22:26 -0400 | [diff] [blame] | 79 | GrVkPrimaryCommandBuffer* currentCommandBuffer() const { return fMainCmdBuffer; } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 80 | |
Greg Daniel | 9a18b08 | 2020-08-14 14:03:50 -0400 | [diff] [blame] | 81 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 82 | |
Greg Daniel | 1db8e79 | 2020-06-09 17:29:32 -0400 | [diff] [blame] | 83 | bool setBackendTextureState(const GrBackendTexture&, |
| 84 | const GrBackendSurfaceMutableState&, |
Greg Daniel | 1d3c8c1 | 2020-09-23 14:23:36 -0400 | [diff] [blame] | 85 | GrBackendSurfaceMutableState* previousState, |
Greg Daniel | 1db8e79 | 2020-06-09 17:29:32 -0400 | [diff] [blame] | 86 | sk_sp<GrRefCntedCallback> finishedCallback) override; |
| 87 | |
| 88 | bool setBackendRenderTargetState(const GrBackendRenderTarget&, |
| 89 | const GrBackendSurfaceMutableState&, |
Greg Daniel | 1d3c8c1 | 2020-09-23 14:23:36 -0400 | [diff] [blame] | 90 | GrBackendSurfaceMutableState* previousState, |
Greg Daniel | 1db8e79 | 2020-06-09 17:29:32 -0400 | [diff] [blame] | 91 | sk_sp<GrRefCntedCallback> finishedCallback) override; |
| 92 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 93 | void deleteBackendTexture(const GrBackendTexture&) override; |
Robert Phillips | 979b223 | 2020-02-20 10:47:29 -0500 | [diff] [blame] | 94 | |
| 95 | bool compile(const GrProgramDesc&, const GrProgramInfo&) override; |
| 96 | |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 97 | #if GR_TEST_UTILS |
| 98 | bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 99 | |
Brian Salomon | f9b0042 | 2020-10-08 16:00:14 -0400 | [diff] [blame] | 100 | GrBackendRenderTarget createTestingOnlyBackendRenderTarget(SkISize dimensions, |
Brian Salomon | 72c7b98 | 2020-10-06 10:07:38 -0400 | [diff] [blame] | 101 | GrColorType, |
Brian Salomon | f9b0042 | 2020-10-08 16:00:14 -0400 | [diff] [blame] | 102 | int sampleCnt, |
| 103 | GrProtected) override; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 104 | void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; |
| 105 | |
Brian Osman | fd7657c | 2019-04-25 11:34:07 -0400 | [diff] [blame] | 106 | void resetShaderCacheForTesting() const override { |
| 107 | fResourceProvider.resetShaderCacheForTesting(); |
| 108 | } |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 109 | #endif |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 110 | |
Chris Dalton | e0fe23a | 2021-04-23 13:11:44 -0600 | [diff] [blame] | 111 | sk_sp<GrAttachment> makeStencilAttachment(const GrBackendFormat& /*colorFormat*/, |
| 112 | SkISize dimensions, int numStencilSamples) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 113 | |
Greg Daniel | b8949bd | 2020-10-12 15:21:02 -0400 | [diff] [blame] | 114 | GrBackendFormat getPreferredStencilFormat(const GrBackendFormat&) override { |
| 115 | return GrBackendFormat::MakeVk(this->vkCaps().preferredStencilFormat()); |
| 116 | } |
| 117 | |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 118 | sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions, |
| 119 | const GrBackendFormat& format, |
| 120 | int numSamples, |
| 121 | GrProtected isProtected) override; |
| 122 | |
Jim Van Verth | 3e19216 | 2020-03-10 16:23:16 -0400 | [diff] [blame] | 123 | void addBufferMemoryBarrier(const GrManagedResource*, |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 124 | VkPipelineStageFlags srcStageMask, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 125 | VkPipelineStageFlags dstStageMask, |
| 126 | bool byRegion, |
| 127 | VkBufferMemoryBarrier* barrier) const; |
Greg Daniel | 87d784f | 2021-02-02 15:36:06 -0500 | [diff] [blame] | 128 | void addBufferMemoryBarrier(VkPipelineStageFlags srcStageMask, |
| 129 | VkPipelineStageFlags dstStageMask, |
| 130 | bool byRegion, |
| 131 | VkBufferMemoryBarrier* barrier) const; |
Jim Van Verth | 3e19216 | 2020-03-10 16:23:16 -0400 | [diff] [blame] | 132 | void addImageMemoryBarrier(const GrManagedResource*, |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 133 | VkPipelineStageFlags srcStageMask, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 134 | VkPipelineStageFlags dstStageMask, |
| 135 | bool byRegion, |
| 136 | VkImageMemoryBarrier* barrier) const; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 137 | |
Greg Daniel | a8c3210 | 2020-12-30 15:09:32 -0500 | [diff] [blame] | 138 | bool loadMSAAFromResolve(GrVkCommandBuffer* commandBuffer, |
| 139 | const GrVkRenderPass& renderPass, |
Greg Daniel | 1034425 | 2021-04-22 09:52:25 -0400 | [diff] [blame] | 140 | GrAttachment* dst, |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 141 | GrVkImage* src, |
Greg Daniel | a8c3210 | 2020-12-30 15:09:32 -0500 | [diff] [blame] | 142 | const SkIRect& srcRect); |
| 143 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 144 | bool onRegenerateMipMapLevels(GrTexture* tex) override; |
| 145 | |
Jim Van Verth | bb61fe3 | 2020-07-07 16:39:04 -0400 | [diff] [blame] | 146 | void onResolveRenderTarget(GrRenderTarget* target, const SkIRect& resolveRect) override; |
egdaniel | 6693355 | 2016-08-24 07:22:19 -0700 | [diff] [blame] | 147 | |
Greg Daniel | f0c681e | 2019-09-05 14:07:41 -0400 | [diff] [blame] | 148 | void submitSecondaryCommandBuffer(std::unique_ptr<GrVkSecondaryCommandBuffer>); |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 149 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 150 | void submit(GrOpsRenderPass*) override; |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 151 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 152 | GrFence SK_WARN_UNUSED_RESULT insertFence() override; |
Stephen White | b353c9b | 2020-04-16 14:14:13 -0400 | [diff] [blame] | 153 | bool waitFence(GrFence) override; |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 154 | void deleteFence(GrFence) const override; |
| 155 | |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 156 | std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override; |
Robert Phillips | 1a82a4e | 2021-07-01 10:27:44 -0400 | [diff] [blame] | 157 | std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore&, |
| 158 | GrSemaphoreWrapType, |
| 159 | GrWrapOwnership) override; |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 160 | void insertSemaphore(GrSemaphore* semaphore) override; |
| 161 | void waitSemaphore(GrSemaphore* semaphore) override; |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 162 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 163 | // These match the definitions in SkDrawable, from whence they came |
| 164 | typedef void* SubmitContext; |
| 165 | typedef void (*SubmitProc)(SubmitContext submitContext); |
| 166 | |
| 167 | // Adds an SkDrawable::GpuDrawHandler that we will delete the next time we submit the primary |
| 168 | // command buffer to the gpu. |
| 169 | void addDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable); |
| 170 | |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 171 | void checkFinishProcs() override { fResourceProvider.checkCommandBuffers(); } |
Greg Daniel | a89b430 | 2021-01-29 10:48:40 -0500 | [diff] [blame] | 172 | void finishOutstandingGpuWork() override; |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 173 | |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 174 | std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override; |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 175 | |
Greg Daniel | 2e967df | 2021-02-08 10:38:31 -0500 | [diff] [blame] | 176 | void copyBuffer(sk_sp<GrGpuBuffer> srcBuffer, sk_sp<GrGpuBuffer> dstBuffer, |
| 177 | VkDeviceSize srcOffset, VkDeviceSize dstOffset, VkDeviceSize size); |
Greg Daniel | af1d193 | 2021-02-08 13:55:26 -0500 | [diff] [blame] | 178 | bool updateBuffer(sk_sp<GrVkBuffer> buffer, const void* src, VkDeviceSize offset, |
Greg Daniel | 87d784f | 2021-02-02 15:36:06 -0500 | [diff] [blame] | 179 | VkDeviceSize size); |
jvanverth | a584de9 | 2016-06-30 09:10:52 -0700 | [diff] [blame] | 180 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 181 | enum PersistentCacheKeyType : uint32_t { |
| 182 | kShader_PersistentCacheKeyType = 0, |
| 183 | kPipelineCache_PersistentCacheKeyType = 1, |
| 184 | }; |
| 185 | |
| 186 | void storeVkPipelineCacheData() override; |
| 187 | |
Greg Daniel | fa3adf7 | 2019-11-07 09:53:41 -0500 | [diff] [blame] | 188 | bool beginRenderPass(const GrVkRenderPass*, |
Greg Daniel | 60ec617 | 2021-04-16 11:31:58 -0400 | [diff] [blame] | 189 | sk_sp<const GrVkFramebuffer>, |
Greg Daniel | f0c681e | 2019-09-05 14:07:41 -0400 | [diff] [blame] | 190 | const VkClearValue* colorClear, |
Greg Daniel | 1034425 | 2021-04-22 09:52:25 -0400 | [diff] [blame] | 191 | const GrSurface*, |
Greg Daniel | 2f7a7ad | 2020-12-15 16:02:45 -0500 | [diff] [blame] | 192 | const SkIRect& renderPassBounds, |
| 193 | bool forSecondaryCB); |
Greg Daniel | f0c681e | 2019-09-05 14:07:41 -0400 | [diff] [blame] | 194 | void endRenderPass(GrRenderTarget* target, GrSurfaceOrigin origin, const SkIRect& bounds); |
| 195 | |
Brian Salomon | 864562f | 2020-08-11 16:22:34 -0400 | [diff] [blame] | 196 | // Returns true if VkResult indicates success and also checks for device lost or OOM. Every |
| 197 | // Vulkan call (and GrVkMemoryAllocator call that returns VkResult) made on behalf of the |
| 198 | // GrVkGpu should be processed by this function so that we respond to OOMs and lost devices. |
| 199 | bool checkVkResult(VkResult); |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 200 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 201 | private: |
Greg Daniel | e118558 | 2019-12-04 11:29:44 -0500 | [diff] [blame] | 202 | enum SyncQueue { |
| 203 | kForce_SyncQueue, |
| 204 | kSkip_SyncQueue |
| 205 | }; |
| 206 | |
Greg Daniel | b2b4cc8 | 2020-08-21 14:59:00 -0400 | [diff] [blame] | 207 | GrVkGpu(GrDirectContext*, const GrVkBackendContext&, const sk_sp<GrVkCaps> caps, |
Greg Daniel | b16beb9 | 2020-04-27 14:26:21 +0000 | [diff] [blame] | 208 | sk_sp<const GrVkInterface>, uint32_t instanceVersion, uint32_t physicalDeviceVersion, |
| 209 | sk_sp<GrVkMemoryAllocator>); |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 210 | |
Greg Daniel | 8606cf8 | 2017-05-08 16:17:53 -0400 | [diff] [blame] | 211 | void destroyResources(); |
| 212 | |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 213 | GrBackendTexture onCreateBackendTexture(SkISize dimensions, |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 214 | const GrBackendFormat&, |
| 215 | GrRenderable, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 216 | GrMipmapped, |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 217 | GrProtected) override; |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 218 | GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions, |
| 219 | const GrBackendFormat&, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 220 | GrMipmapped, |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 221 | GrProtected) override; |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 222 | |
Brian Salomon | 7128323 | 2021-04-08 12:45:58 -0400 | [diff] [blame] | 223 | bool onClearBackendTexture(const GrBackendTexture&, |
| 224 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 225 | std::array<float, 4> color) override; |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 226 | |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 227 | bool onUpdateCompressedBackendTexture(const GrBackendTexture&, |
| 228 | sk_sp<GrRefCntedCallback> finishedCallback, |
Brian Salomon | 7128323 | 2021-04-08 12:45:58 -0400 | [diff] [blame] | 229 | const void* data, |
| 230 | size_t length) override; |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 231 | |
Greg Daniel | 1db8e79 | 2020-06-09 17:29:32 -0400 | [diff] [blame] | 232 | bool setBackendSurfaceState(GrVkImageInfo info, |
| 233 | sk_sp<GrBackendSurfaceMutableStateImpl> currentState, |
| 234 | SkISize dimensions, |
Greg Daniel | 1d3c8c1 | 2020-09-23 14:23:36 -0400 | [diff] [blame] | 235 | const GrVkSharedImageInfo& newInfo, |
Greg Daniel | 1ebf23c | 2021-06-01 15:33:29 -0400 | [diff] [blame] | 236 | GrBackendSurfaceMutableState* previousState, |
| 237 | sk_sp<GrRefCntedCallback> finishedCallback); |
Greg Daniel | 1db8e79 | 2020-06-09 17:29:32 -0400 | [diff] [blame] | 238 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 239 | sk_sp<GrTexture> onCreateTexture(SkISize, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 240 | const GrBackendFormat&, |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 241 | GrRenderable, |
| 242 | int renderTargetSampleCnt, |
| 243 | SkBudgeted, |
| 244 | GrProtected, |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 245 | int mipLevelCount, |
| 246 | uint32_t levelClearMask) override; |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 247 | sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions, |
| 248 | const GrBackendFormat&, |
| 249 | SkBudgeted, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 250 | GrMipmapped, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 251 | GrProtected, |
| 252 | const void* data, size_t dataSize) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 253 | |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 254 | sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, |
| 255 | GrWrapOwnership, |
| 256 | GrWrapCacheable, |
| 257 | GrIOType) override; |
| 258 | sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&, |
| 259 | GrWrapOwnership, |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 260 | GrWrapCacheable) override; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 261 | sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 262 | int sampleCnt, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 263 | GrWrapOwnership, |
| 264 | GrWrapCacheable) override; |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 265 | sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 266 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 267 | sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&, |
| 268 | const GrVkDrawableInfo&) override; |
| 269 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 270 | sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern, |
| 271 | const void* data) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 272 | |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 273 | bool onReadPixels(GrSurface*, |
| 274 | SkIRect, |
| 275 | GrColorType surfaceColorType, |
| 276 | GrColorType dstColorType, |
| 277 | void* buffer, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 278 | size_t rowBytes) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 279 | |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 280 | bool onWritePixels(GrSurface*, |
| 281 | SkIRect, |
| 282 | GrColorType surfaceColorType, |
| 283 | GrColorType srcColorType, |
| 284 | const GrMipLevel[], |
| 285 | int mipLevelCount, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 286 | bool prepForTexSampling) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 287 | |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 288 | bool onTransferPixelsTo(GrTexture*, |
| 289 | SkIRect, |
| 290 | GrColorType textureColorType, |
| 291 | GrColorType bufferColorType, |
| 292 | sk_sp<GrGpuBuffer>, |
| 293 | size_t offset, |
Greg Daniel | 5ad5a37 | 2021-02-01 13:34:04 -0500 | [diff] [blame] | 294 | size_t rowBytes) override; |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 295 | |
| 296 | bool onTransferPixelsFrom(GrSurface*, |
| 297 | SkIRect, |
| 298 | GrColorType surfaceColorType, |
| 299 | GrColorType bufferColorType, |
| 300 | sk_sp<GrGpuBuffer>, |
| 301 | size_t offset) override; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 302 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 303 | bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 304 | const SkIPoint& dstPoint) override; |
Brian Salomon | 9b009bb | 2018-02-14 13:53:55 -0500 | [diff] [blame] | 305 | |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 306 | void addFinishedProc(GrGpuFinishedProc finishedProc, |
| 307 | GrGpuFinishedContext finishedContext) override; |
| 308 | |
Greg Daniel | 288ecf6 | 2020-06-05 10:22:26 -0400 | [diff] [blame] | 309 | void addFinishedCallback(sk_sp<GrRefCntedCallback> finishedCallback); |
| 310 | |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 311 | GrOpsRenderPass* onGetOpsRenderPass(GrRenderTarget*, |
Chris Dalton | da2b0f4 | 2021-04-13 00:19:45 -0600 | [diff] [blame] | 312 | bool useMSAASurface, |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 313 | GrAttachment* stencil, |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 314 | GrSurfaceOrigin, |
| 315 | const SkIRect&, |
| 316 | const GrOpsRenderPass::LoadAndStoreInfo&, |
| 317 | const GrOpsRenderPass::StencilLoadAndStoreInfo&, |
| 318 | const SkTArray<GrSurfaceProxy*, true>& sampledProxies, |
| 319 | GrXferBarrierFlags renderPassXferBarriers) override; |
| 320 | |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 321 | void prepareSurfacesForBackendAccessAndStateUpdates( |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 322 | SkSpan<GrSurfaceProxy*> proxies, |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 323 | SkSurface::BackendSurfaceAccess access, |
| 324 | const GrBackendSurfaceMutableState* newState) override; |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 325 | |
| 326 | bool onSubmitToGpu(bool syncCpu) override; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 327 | |
Greg Daniel | b432754 | 2020-11-20 10:50:50 -0500 | [diff] [blame] | 328 | void onReportSubmitHistograms() override; |
| 329 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 330 | // 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] | 331 | // 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] | 332 | // work in the queue to finish before returning. If this GrVkGpu object has any semaphores in |
| 333 | // fSemaphoreToSignal, we will add those signal semaphores to the submission of this command |
| 334 | // buffer. If this GrVkGpu object has any semaphores in fSemaphoresToWaitOn, we will add those |
| 335 | // wait semaphores to the submission of this command buffer. |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 336 | bool submitCommandBuffer(SyncQueue sync); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 337 | |
Greg Daniel | 41a6ace | 2021-09-07 13:12:48 -0400 | [diff] [blame] | 338 | void copySurfaceAsCopyImage(GrSurface* dst, |
| 339 | GrSurface* src, |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 340 | GrVkImage* dstImage, |
| 341 | GrVkImage* srcImage, |
Greg Daniel | 41a6ace | 2021-09-07 13:12:48 -0400 | [diff] [blame] | 342 | const SkIRect& srcRect, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 343 | const SkIPoint& dstPoint); |
| 344 | |
Greg Daniel | 41a6ace | 2021-09-07 13:12:48 -0400 | [diff] [blame] | 345 | void copySurfaceAsBlit(GrSurface* dst, |
| 346 | GrSurface* src, |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 347 | GrVkImage* dstImage, |
| 348 | GrVkImage* srcImage, |
Greg Daniel | 41a6ace | 2021-09-07 13:12:48 -0400 | [diff] [blame] | 349 | const SkIRect& srcRect, |
| 350 | const SkIPoint& dstPoint); |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 351 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 352 | void copySurfaceAsResolve(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 353 | const SkIPoint& dstPoint); |
| 354 | |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 355 | // helpers for onCreateTexture and writeTexturePixels |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 356 | bool uploadTexDataLinear(GrVkImage* tex, |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 357 | SkIRect rect, |
| 358 | GrColorType colorType, |
| 359 | const void* data, |
| 360 | size_t rowBytes); |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 361 | bool uploadTexDataOptimal(GrVkImage* tex, |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 362 | SkIRect rect, |
| 363 | GrColorType colorType, |
| 364 | const GrMipLevel texels[], |
| 365 | int mipLevelCount); |
Greg Daniel | 2bc96d6 | 2021-09-13 13:08:02 -0400 | [diff] [blame^] | 366 | bool uploadTexDataCompressed(GrVkImage* tex, SkImage::CompressionType compression, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 367 | VkFormat vkFormat, SkISize dimensions, GrMipmapped mipMapped, |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 368 | const void* data, size_t dataSize); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 369 | void resolveImage(GrSurface* dst, GrVkRenderTarget* src, const SkIRect& srcRect, |
| 370 | const SkIPoint& dstPoint); |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 371 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 372 | bool createVkImageForBackendSurface(VkFormat, |
Robert Phillips | 4277f01 | 2020-01-21 14:28:34 -0500 | [diff] [blame] | 373 | SkISize dimensions, |
Brian Salomon | 72c7b98 | 2020-10-06 10:07:38 -0400 | [diff] [blame] | 374 | int sampleCnt, |
Robert Phillips | b875735 | 2020-01-21 13:05:25 -0500 | [diff] [blame] | 375 | GrTexturable, |
Robert Phillips | 0d7e2f1 | 2019-12-18 13:01:04 -0500 | [diff] [blame] | 376 | GrRenderable, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 377 | GrMipmapped, |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 378 | GrVkImageInfo*, |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 379 | GrProtected); |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 380 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 381 | sk_sp<const GrVkInterface> fInterface; |
| 382 | sk_sp<GrVkMemoryAllocator> fMemoryAllocator; |
| 383 | sk_sp<GrVkCaps> fVkCaps; |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 384 | bool fDeviceIsLost = false; |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 385 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 386 | VkPhysicalDevice fPhysicalDevice; |
| 387 | VkDevice fDevice; |
| 388 | VkQueue fQueue; // Must be Graphics queue |
| 389 | uint32_t fQueueIndex; |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 390 | |
| 391 | // Created by GrVkGpu |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 392 | GrVkResourceProvider fResourceProvider; |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 393 | GrStagingBufferManager fStagingBufferManager; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 394 | |
Greg Daniel | a8c3210 | 2020-12-30 15:09:32 -0500 | [diff] [blame] | 395 | GrVkMSAALoadManager fMSAALoadManager; |
| 396 | |
Greg Daniel | d922f33 | 2020-04-27 11:21:36 -0400 | [diff] [blame] | 397 | GrVkCommandPool* fMainCmdPool; |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 398 | // just a raw pointer; object's lifespan is managed by fCmdPool |
Greg Daniel | d922f33 | 2020-04-27 11:21:36 -0400 | [diff] [blame] | 399 | GrVkPrimaryCommandBuffer* fMainCmdBuffer; |
| 400 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 401 | SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToWaitOn; |
| 402 | SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToSignal; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 403 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 404 | SkTArray<std::unique_ptr<SkDrawable::GpuDrawHandler>> fDrawables; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 405 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 406 | VkPhysicalDeviceProperties fPhysDevProps; |
| 407 | VkPhysicalDeviceMemoryProperties fPhysDevMemProps; |
| 408 | |
Greg Daniel | 8606cf8 | 2017-05-08 16:17:53 -0400 | [diff] [blame] | 409 | // We need a bool to track whether or not we've already disconnected all the gpu resources from |
| 410 | // vulkan context. |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 411 | bool fDisconnected; |
Greg Daniel | 8606cf8 | 2017-05-08 16:17:53 -0400 | [diff] [blame] | 412 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 413 | GrProtected fProtectedContext; |
| 414 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 415 | std::unique_ptr<GrVkOpsRenderPass> fCachedOpsRenderPass; |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 416 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 417 | using INHERITED = GrGpu; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 418 | }; |
| 419 | |
| 420 | #endif |