blob: 18439d56ced80b48051de2a0509a61cb277e88ca [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/vk/GrVkBackendContext.h"
12#include "include/gpu/vk/GrVkTypes.h"
13#include "src/gpu/GrGpu.h"
Greg Daniela58db7f2020-07-15 09:17:59 -040014#include "src/gpu/GrStagingBufferManager.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/vk/GrVkCaps.h"
Greg Daniela8c32102020-12-30 15:09:32 -050016#include "src/gpu/vk/GrVkMSAALoadManager.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#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 Daniel164a9f02016-02-22 09:56:40 -050021
Adlai Holler3d0359a2020-07-09 15:35:55 -040022class GrDirectContext;
Greg Daniel164a9f02016-02-22 09:56:40 -050023class GrPipeline;
Greg Daniel164a9f02016-02-22 09:56:40 -050024
Greg Danielaf1d1932021-02-08 13:55:26 -050025class GrVkBuffer;
Ethan Nicholas8e265a72018-12-12 16:22:40 -050026class GrVkCommandPool;
Greg Daniel60ec6172021-04-16 11:31:58 -040027class GrVkFramebuffer;
Greg Daniel81df0412018-05-31 13:13:33 -040028class GrVkMemoryAllocator;
Greg Daniel164a9f02016-02-22 09:56:40 -050029class GrVkPipeline;
egdaniel22281c12016-03-23 13:49:40 -070030class GrVkPipelineState;
egdaniel066df7c2016-06-08 14:02:27 -070031class GrVkPrimaryCommandBuffer;
Greg Daniel2d41d0d2019-08-26 11:08:51 -040032class GrVkOpsRenderPass;
Greg Daniel164a9f02016-02-22 09:56:40 -050033class GrVkRenderPass;
egdaniel066df7c2016-06-08 14:02:27 -070034class GrVkSecondaryCommandBuffer;
Greg Daniel164a9f02016-02-22 09:56:40 -050035class GrVkTexture;
36struct GrVkInterface;
37
38class GrVkGpu : public GrGpu {
39public:
Adlai Holler3d0359a2020-07-09 15:35:55 -040040 static sk_sp<GrGpu> Make(const GrVkBackendContext&, const GrContextOptions&, GrDirectContext*);
jvanverth633b3562016-03-23 11:01:22 -070041
Greg Daniel164a9f02016-02-22 09:56:40 -050042 ~GrVkGpu() override;
43
Greg Daniel8606cf82017-05-08 16:17:53 -040044 void disconnect(DisconnectType) override;
Greg Danielee792d62020-11-24 14:02:04 -050045 bool disconnected() const { return fDisconnected; }
Greg Daniel8606cf82017-05-08 16:17:53 -040046
Greg Daniel428523f2021-03-30 14:22:54 -040047 void releaseUnlockedBackendObjects() override {
48 fResourceProvider.releaseUnlockedBackendObjects();
49 }
50
Robert Phillipsae67c522021-03-03 11:03:38 -050051 GrThreadSafePipelineBuilder* pipelineBuilder() override;
52 sk_sp<GrThreadSafePipelineBuilder> refPipelineBuilder() override;
53
Greg Danielf730c182018-07-02 20:15:37 +000054 const GrVkInterface* vkInterface() const { return fInterface.get(); }
Greg Daniel164a9f02016-02-22 09:56:40 -050055 const GrVkCaps& vkCaps() const { return *fVkCaps; }
56
Greg Daniela58db7f2020-07-15 09:17:59 -040057 GrStagingBufferManager* stagingBufferManager() override { return &fStagingBufferManager; }
Jim Van Verth1aaf41b2020-07-29 09:24:29 -040058 void takeOwnershipOfBuffer(sk_sp<GrGpuBuffer>) override;
Greg Daniela58db7f2020-07-15 09:17:59 -040059
Greg Daniel6e35a002020-04-01 13:29:59 -040060 bool isDeviceLost() const override { return fDeviceIsLost; }
Greg Daniele643da62019-11-05 12:36:42 -050061
Greg Daniel81df0412018-05-31 13:13:33 -040062 GrVkMemoryAllocator* memoryAllocator() const { return fMemoryAllocator.get(); }
63
Greg Daniel637c06a2018-09-12 09:44:25 -040064 VkPhysicalDevice physicalDevice() const { return fPhysicalDevice; }
Greg Daniel164a9f02016-02-22 09:56:40 -050065 VkDevice device() const { return fDevice; }
66 VkQueue queue() const { return fQueue; }
Greg Danielecddbc02018-08-30 16:39:34 -040067 uint32_t queueIndex() const { return fQueueIndex; }
Greg Daniel288ecf62020-06-05 10:22:26 -040068 GrVkCommandPool* cmdPool() const { return fMainCmdPool; }
Greg Daniela870b462019-01-08 15:49:46 -050069 const VkPhysicalDeviceProperties& physicalDeviceProperties() const {
Greg Daniel8385a8a2018-02-26 13:29:37 -050070 return fPhysDevProps;
71 }
Greg Daniela870b462019-01-08 15:49:46 -050072 const VkPhysicalDeviceMemoryProperties& physicalDeviceMemoryProperties() const {
Greg Daniel164a9f02016-02-22 09:56:40 -050073 return fPhysDevMemProps;
74 }
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040075 bool protectedContext() const { return fProtectedContext == GrProtected::kYes; }
Greg Daniel164a9f02016-02-22 09:56:40 -050076
egdanielbc9b2962016-09-27 08:00:53 -070077 GrVkResourceProvider& resourceProvider() { return fResourceProvider; }
78
Greg Daniel288ecf62020-06-05 10:22:26 -040079 GrVkPrimaryCommandBuffer* currentCommandBuffer() const { return fMainCmdBuffer; }
Greg Daniel164a9f02016-02-22 09:56:40 -050080
Greg Daniel9a18b082020-08-14 14:03:50 -040081 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override;
Greg Daniel164a9f02016-02-22 09:56:40 -050082
Greg Daniel1db8e792020-06-09 17:29:32 -040083 bool setBackendTextureState(const GrBackendTexture&,
84 const GrBackendSurfaceMutableState&,
Greg Daniel1d3c8c12020-09-23 14:23:36 -040085 GrBackendSurfaceMutableState* previousState,
Greg Daniel1db8e792020-06-09 17:29:32 -040086 sk_sp<GrRefCntedCallback> finishedCallback) override;
87
88 bool setBackendRenderTargetState(const GrBackendRenderTarget&,
89 const GrBackendSurfaceMutableState&,
Greg Daniel1d3c8c12020-09-23 14:23:36 -040090 GrBackendSurfaceMutableState* previousState,
Greg Daniel1db8e792020-06-09 17:29:32 -040091 sk_sp<GrRefCntedCallback> finishedCallback) override;
92
Robert Phillipsf0313ee2019-05-21 13:51:11 -040093 void deleteBackendTexture(const GrBackendTexture&) override;
Robert Phillips979b2232020-02-20 10:47:29 -050094
95 bool compile(const GrProgramDesc&, const GrProgramInfo&) override;
96
Robert Phillipsf0ced622019-05-16 09:06:25 -040097#if GR_TEST_UTILS
98 bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
Greg Daniel164a9f02016-02-22 09:56:40 -050099
Brian Salomonf9b00422020-10-08 16:00:14 -0400100 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(SkISize dimensions,
Brian Salomon72c7b982020-10-06 10:07:38 -0400101 GrColorType,
Brian Salomonf9b00422020-10-08 16:00:14 -0400102 int sampleCnt,
103 GrProtected) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500104 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
105
Brian Osmanfd7657c2019-04-25 11:34:07 -0400106 void resetShaderCacheForTesting() const override {
107 fResourceProvider.resetShaderCacheForTesting();
108 }
Brian Salomonf865b052018-03-09 09:01:53 -0500109#endif
Greg Daniel26b50a42018-03-08 09:49:58 -0500110
Chris Daltone0fe23a2021-04-23 13:11:44 -0600111 sk_sp<GrAttachment> makeStencilAttachment(const GrBackendFormat& /*colorFormat*/,
112 SkISize dimensions, int numStencilSamples) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500113
Greg Danielb8949bd2020-10-12 15:21:02 -0400114 GrBackendFormat getPreferredStencilFormat(const GrBackendFormat&) override {
115 return GrBackendFormat::MakeVk(this->vkCaps().preferredStencilFormat());
116 }
117
Greg Daniel5d0330e2020-10-12 16:05:21 -0400118 sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions,
119 const GrBackendFormat& format,
120 int numSamples,
121 GrProtected isProtected) override;
122
Jim Van Verth3e192162020-03-10 16:23:16 -0400123 void addBufferMemoryBarrier(const GrManagedResource*,
Greg Daniel59dc1482019-02-22 10:46:38 -0500124 VkPipelineStageFlags srcStageMask,
Greg Daniel164a9f02016-02-22 09:56:40 -0500125 VkPipelineStageFlags dstStageMask,
126 bool byRegion,
127 VkBufferMemoryBarrier* barrier) const;
Greg Daniel87d784f2021-02-02 15:36:06 -0500128 void addBufferMemoryBarrier(VkPipelineStageFlags srcStageMask,
129 VkPipelineStageFlags dstStageMask,
130 bool byRegion,
131 VkBufferMemoryBarrier* barrier) const;
Jim Van Verth3e192162020-03-10 16:23:16 -0400132 void addImageMemoryBarrier(const GrManagedResource*,
Greg Daniel59dc1482019-02-22 10:46:38 -0500133 VkPipelineStageFlags srcStageMask,
Greg Daniel164a9f02016-02-22 09:56:40 -0500134 VkPipelineStageFlags dstStageMask,
135 bool byRegion,
136 VkImageMemoryBarrier* barrier) const;
halcanary9d524f22016-03-29 09:03:52 -0700137
Greg Daniela8c32102020-12-30 15:09:32 -0500138 bool loadMSAAFromResolve(GrVkCommandBuffer* commandBuffer,
139 const GrVkRenderPass& renderPass,
Greg Daniel10344252021-04-22 09:52:25 -0400140 GrAttachment* dst,
Greg Daniel2bc96d62021-09-13 13:08:02 -0400141 GrVkImage* src,
Greg Daniela8c32102020-12-30 15:09:32 -0500142 const SkIRect& srcRect);
143
Brian Salomon930f9392018-06-20 16:25:26 -0400144 bool onRegenerateMipMapLevels(GrTexture* tex) override;
145
Jim Van Verthbb61fe32020-07-07 16:39:04 -0400146 void onResolveRenderTarget(GrRenderTarget* target, const SkIRect& resolveRect) override;
egdaniel66933552016-08-24 07:22:19 -0700147
Greg Danielf0c681e2019-09-05 14:07:41 -0400148 void submitSecondaryCommandBuffer(std::unique_ptr<GrVkSecondaryCommandBuffer>);
egdaniel066df7c2016-06-08 14:02:27 -0700149
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400150 void submit(GrOpsRenderPass*) override;
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400151
Greg Daniel6be35232017-03-01 17:01:09 -0500152 GrFence SK_WARN_UNUSED_RESULT insertFence() override;
Stephen Whiteb353c9b2020-04-16 14:14:13 -0400153 bool waitFence(GrFence) override;
jvanverth84741b32016-09-30 08:39:02 -0700154 void deleteFence(GrFence) const override;
155
Greg Daniel301015c2019-11-18 14:06:46 -0500156 std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override;
Robert Phillips1a82a4e2021-07-01 10:27:44 -0400157 std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore&,
158 GrSemaphoreWrapType,
159 GrWrapOwnership) override;
Greg Daniel301015c2019-11-18 14:06:46 -0500160 void insertSemaphore(GrSemaphore* semaphore) override;
161 void waitSemaphore(GrSemaphore* semaphore) override;
Greg Daniel48661b82018-01-22 16:11:35 -0500162
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400163 // 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 Salomonb0d8b762019-05-06 16:58:22 -0400171 void checkFinishProcs() override { fResourceProvider.checkCommandBuffers(); }
Greg Daniela89b4302021-01-29 10:48:40 -0500172 void finishOutstandingGpuWork() override;
Brian Salomonb0d8b762019-05-06 16:58:22 -0400173
Greg Daniel301015c2019-11-18 14:06:46 -0500174 std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override;
Brian Osman13dddce2017-05-09 13:19:50 -0400175
Greg Daniel2e967df2021-02-08 10:38:31 -0500176 void copyBuffer(sk_sp<GrGpuBuffer> srcBuffer, sk_sp<GrGpuBuffer> dstBuffer,
177 VkDeviceSize srcOffset, VkDeviceSize dstOffset, VkDeviceSize size);
Greg Danielaf1d1932021-02-08 13:55:26 -0500178 bool updateBuffer(sk_sp<GrVkBuffer> buffer, const void* src, VkDeviceSize offset,
Greg Daniel87d784f2021-02-02 15:36:06 -0500179 VkDeviceSize size);
jvanvertha584de92016-06-30 09:10:52 -0700180
Greg Daniela870b462019-01-08 15:49:46 -0500181 enum PersistentCacheKeyType : uint32_t {
182 kShader_PersistentCacheKeyType = 0,
183 kPipelineCache_PersistentCacheKeyType = 1,
184 };
185
186 void storeVkPipelineCacheData() override;
187
Greg Danielfa3adf72019-11-07 09:53:41 -0500188 bool beginRenderPass(const GrVkRenderPass*,
Greg Daniel60ec6172021-04-16 11:31:58 -0400189 sk_sp<const GrVkFramebuffer>,
Greg Danielf0c681e2019-09-05 14:07:41 -0400190 const VkClearValue* colorClear,
Greg Daniel10344252021-04-22 09:52:25 -0400191 const GrSurface*,
Greg Daniel2f7a7ad2020-12-15 16:02:45 -0500192 const SkIRect& renderPassBounds,
193 bool forSecondaryCB);
Greg Danielf0c681e2019-09-05 14:07:41 -0400194 void endRenderPass(GrRenderTarget* target, GrSurfaceOrigin origin, const SkIRect& bounds);
195
Brian Salomon864562f2020-08-11 16:22:34 -0400196 // 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 Salomon24069eb2020-06-24 10:19:52 -0400200
Greg Daniel164a9f02016-02-22 09:56:40 -0500201private:
Greg Daniele1185582019-12-04 11:29:44 -0500202 enum SyncQueue {
203 kForce_SyncQueue,
204 kSkip_SyncQueue
205 };
206
Greg Danielb2b4cc82020-08-21 14:59:00 -0400207 GrVkGpu(GrDirectContext*, const GrVkBackendContext&, const sk_sp<GrVkCaps> caps,
Greg Danielb16beb92020-04-27 14:26:21 +0000208 sk_sp<const GrVkInterface>, uint32_t instanceVersion, uint32_t physicalDeviceVersion,
209 sk_sp<GrVkMemoryAllocator>);
jvanverth633b3562016-03-23 11:01:22 -0700210
Greg Daniel8606cf82017-05-08 16:17:53 -0400211 void destroyResources();
212
Robert Phillipsb915c942019-12-17 14:44:37 -0500213 GrBackendTexture onCreateBackendTexture(SkISize dimensions,
Brian Salomon85c3d682019-11-04 15:04:54 -0500214 const GrBackendFormat&,
215 GrRenderable,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400216 GrMipmapped,
Greg Daniel16032b32020-05-06 15:31:10 -0400217 GrProtected) override;
Robert Phillipsb915c942019-12-17 14:44:37 -0500218 GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions,
219 const GrBackendFormat&,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400220 GrMipmapped,
Greg Danielaaf738c2020-07-10 09:30:33 -0400221 GrProtected) override;
Robert Phillipsb915c942019-12-17 14:44:37 -0500222
Brian Salomon71283232021-04-08 12:45:58 -0400223 bool onClearBackendTexture(const GrBackendTexture&,
224 sk_sp<GrRefCntedCallback> finishedCallback,
225 std::array<float, 4> color) override;
Greg Daniel16032b32020-05-06 15:31:10 -0400226
Greg Danielaaf738c2020-07-10 09:30:33 -0400227 bool onUpdateCompressedBackendTexture(const GrBackendTexture&,
228 sk_sp<GrRefCntedCallback> finishedCallback,
Brian Salomon71283232021-04-08 12:45:58 -0400229 const void* data,
230 size_t length) override;
Greg Danielaaf738c2020-07-10 09:30:33 -0400231
Greg Daniel1db8e792020-06-09 17:29:32 -0400232 bool setBackendSurfaceState(GrVkImageInfo info,
233 sk_sp<GrBackendSurfaceMutableStateImpl> currentState,
234 SkISize dimensions,
Greg Daniel1d3c8c12020-09-23 14:23:36 -0400235 const GrVkSharedImageInfo& newInfo,
Greg Daniel1ebf23c2021-06-01 15:33:29 -0400236 GrBackendSurfaceMutableState* previousState,
237 sk_sp<GrRefCntedCallback> finishedCallback);
Greg Daniel1db8e792020-06-09 17:29:32 -0400238
Brian Salomona56a7462020-02-07 14:17:25 -0500239 sk_sp<GrTexture> onCreateTexture(SkISize,
Robert Phillips3a833922020-01-21 15:25:58 -0500240 const GrBackendFormat&,
Brian Salomon81536f22019-08-08 16:30:49 -0400241 GrRenderable,
242 int renderTargetSampleCnt,
243 SkBudgeted,
244 GrProtected,
Brian Salomond2a8ae22019-09-10 16:03:59 -0400245 int mipLevelCount,
246 uint32_t levelClearMask) override;
Robert Phillips3a833922020-01-21 15:25:58 -0500247 sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions,
248 const GrBackendFormat&,
249 SkBudgeted,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400250 GrMipmapped,
Robert Phillips3a833922020-01-21 15:25:58 -0500251 GrProtected,
252 const void* data, size_t dataSize) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500253
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400254 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
255 GrWrapOwnership,
256 GrWrapCacheable,
257 GrIOType) override;
258 sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&,
259 GrWrapOwnership,
Robert Phillipsb915c942019-12-17 14:44:37 -0500260 GrWrapCacheable) override;
Brian Salomond17f6582017-07-19 18:28:58 -0400261 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
Brian Salomond17f6582017-07-19 18:28:58 -0400262 int sampleCnt,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500263 GrWrapOwnership,
264 GrWrapCacheable) override;
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400265 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
Greg Daniel7ef28f32017-04-20 16:41:55 +0000266
Greg Danielb46add82019-01-02 14:51:29 -0500267 sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
268 const GrVkDrawableInfo&) override;
269
Brian Salomondbf70722019-02-07 11:31:24 -0500270 sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern,
271 const void* data) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500272
Brian Salomone2078f12021-05-24 12:40:46 -0400273 bool onReadPixels(GrSurface*,
274 SkIRect,
275 GrColorType surfaceColorType,
276 GrColorType dstColorType,
277 void* buffer,
Brian Salomonf77c1462019-08-01 15:19:29 -0400278 size_t rowBytes) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500279
Brian Salomone2078f12021-05-24 12:40:46 -0400280 bool onWritePixels(GrSurface*,
281 SkIRect,
282 GrColorType surfaceColorType,
283 GrColorType srcColorType,
284 const GrMipLevel[],
285 int mipLevelCount,
Greg Danielb20d7e52019-09-03 13:54:39 -0400286 bool prepForTexSampling) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500287
Brian Salomone2078f12021-05-24 12:40:46 -0400288 bool onTransferPixelsTo(GrTexture*,
289 SkIRect,
290 GrColorType textureColorType,
291 GrColorType bufferColorType,
292 sk_sp<GrGpuBuffer>,
293 size_t offset,
Greg Daniel5ad5a372021-02-01 13:34:04 -0500294 size_t rowBytes) override;
Brian Salomone2078f12021-05-24 12:40:46 -0400295
296 bool onTransferPixelsFrom(GrSurface*,
297 SkIRect,
298 GrColorType surfaceColorType,
299 GrColorType bufferColorType,
300 sk_sp<GrGpuBuffer>,
301 size_t offset) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500302
Greg Daniel46cfbc62019-06-07 11:43:30 -0400303 bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
Greg Daniele227fe42019-08-21 13:52:24 -0400304 const SkIPoint& dstPoint) override;
Brian Salomon9b009bb2018-02-14 13:53:55 -0500305
Greg Danielfe159622020-04-10 17:43:51 +0000306 void addFinishedProc(GrGpuFinishedProc finishedProc,
307 GrGpuFinishedContext finishedContext) override;
308
Greg Daniel288ecf62020-06-05 10:22:26 -0400309 void addFinishedCallback(sk_sp<GrRefCntedCallback> finishedCallback);
310
Greg Daniel65476e02020-10-27 09:20:20 -0400311 GrOpsRenderPass* onGetOpsRenderPass(GrRenderTarget*,
Chris Daltonda2b0f42021-04-13 00:19:45 -0600312 bool useMSAASurface,
Greg Daniel2bc96d62021-09-13 13:08:02 -0400313 GrAttachment* stencil,
Greg Daniel65476e02020-10-27 09:20:20 -0400314 GrSurfaceOrigin,
315 const SkIRect&,
316 const GrOpsRenderPass::LoadAndStoreInfo&,
317 const GrOpsRenderPass::StencilLoadAndStoreInfo&,
318 const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
319 GrXferBarrierFlags renderPassXferBarriers) override;
320
Greg Daniel9efe3862020-06-11 11:51:06 -0400321 void prepareSurfacesForBackendAccessAndStateUpdates(
Adlai Hollerc2bfcff2020-11-06 15:39:36 -0500322 SkSpan<GrSurfaceProxy*> proxies,
Greg Daniel9efe3862020-06-11 11:51:06 -0400323 SkSurface::BackendSurfaceAccess access,
324 const GrBackendSurfaceMutableState* newState) override;
Greg Danielfe159622020-04-10 17:43:51 +0000325
326 bool onSubmitToGpu(bool syncCpu) override;
Greg Daniel51316782017-08-02 15:10:09 +0000327
Greg Danielb4327542020-11-20 10:50:50 -0500328 void onReportSubmitHistograms() override;
329
Greg Daniel164a9f02016-02-22 09:56:40 -0500330 // Ends and submits the current command buffer to the queue and then creates a new command
halcanary9d524f22016-03-29 09:03:52 -0700331 // buffer and begins it. If sync is set to kForce_SyncQueue, the function will wait for all
Greg Daniela5cb7812017-06-16 09:45:32 -0400332 // 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 Danielfe159622020-04-10 17:43:51 +0000336 bool submitCommandBuffer(SyncQueue sync);
Greg Daniel164a9f02016-02-22 09:56:40 -0500337
Greg Daniel41a6ace2021-09-07 13:12:48 -0400338 void copySurfaceAsCopyImage(GrSurface* dst,
339 GrSurface* src,
Greg Daniel2bc96d62021-09-13 13:08:02 -0400340 GrVkImage* dstImage,
341 GrVkImage* srcImage,
Greg Daniel41a6ace2021-09-07 13:12:48 -0400342 const SkIRect& srcRect,
Greg Daniel164a9f02016-02-22 09:56:40 -0500343 const SkIPoint& dstPoint);
344
Greg Daniel41a6ace2021-09-07 13:12:48 -0400345 void copySurfaceAsBlit(GrSurface* dst,
346 GrSurface* src,
Greg Daniel2bc96d62021-09-13 13:08:02 -0400347 GrVkImage* dstImage,
348 GrVkImage* srcImage,
Greg Daniel41a6ace2021-09-07 13:12:48 -0400349 const SkIRect& srcRect,
350 const SkIPoint& dstPoint);
egdaniel17b89252016-04-05 07:23:38 -0700351
Greg Daniel46cfbc62019-06-07 11:43:30 -0400352 void copySurfaceAsResolve(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
egdaniel4bcd62e2016-08-31 07:37:31 -0700353 const SkIPoint& dstPoint);
354
jvanverth900bd4a2016-04-29 13:53:12 -0700355 // helpers for onCreateTexture and writeTexturePixels
Greg Daniel2bc96d62021-09-13 13:08:02 -0400356 bool uploadTexDataLinear(GrVkImage* tex,
Brian Salomone2078f12021-05-24 12:40:46 -0400357 SkIRect rect,
358 GrColorType colorType,
359 const void* data,
360 size_t rowBytes);
Greg Daniel2bc96d62021-09-13 13:08:02 -0400361 bool uploadTexDataOptimal(GrVkImage* tex,
Brian Salomone2078f12021-05-24 12:40:46 -0400362 SkIRect rect,
363 GrColorType colorType,
364 const GrMipLevel texels[],
365 int mipLevelCount);
Greg Daniel2bc96d62021-09-13 13:08:02 -0400366 bool uploadTexDataCompressed(GrVkImage* tex, SkImage::CompressionType compression,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400367 VkFormat vkFormat, SkISize dimensions, GrMipmapped mipMapped,
Greg Daniel01f278c2020-06-12 16:58:17 -0400368 const void* data, size_t dataSize);
Brian Salomon1fabd512018-02-09 09:54:25 -0500369 void resolveImage(GrSurface* dst, GrVkRenderTarget* src, const SkIRect& srcRect,
370 const SkIPoint& dstPoint);
egdaniel4bcd62e2016-08-31 07:37:31 -0700371
Brian Salomon85c3d682019-11-04 15:04:54 -0500372 bool createVkImageForBackendSurface(VkFormat,
Robert Phillips4277f012020-01-21 14:28:34 -0500373 SkISize dimensions,
Brian Salomon72c7b982020-10-06 10:07:38 -0400374 int sampleCnt,
Robert Phillipsb8757352020-01-21 13:05:25 -0500375 GrTexturable,
Robert Phillips0d7e2f12019-12-18 13:01:04 -0500376 GrRenderable,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400377 GrMipmapped,
Brian Salomon85c3d682019-11-04 15:04:54 -0500378 GrVkImageInfo*,
Greg Daniel16032b32020-05-06 15:31:10 -0400379 GrProtected);
Brian Salomon52e943a2018-03-13 09:32:39 -0400380
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400381 sk_sp<const GrVkInterface> fInterface;
382 sk_sp<GrVkMemoryAllocator> fMemoryAllocator;
383 sk_sp<GrVkCaps> fVkCaps;
Greg Daniele643da62019-11-05 12:36:42 -0500384 bool fDeviceIsLost = false;
jvanverth633b3562016-03-23 11:01:22 -0700385
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400386 VkPhysicalDevice fPhysicalDevice;
387 VkDevice fDevice;
388 VkQueue fQueue; // Must be Graphics queue
389 uint32_t fQueueIndex;
jvanverth633b3562016-03-23 11:01:22 -0700390
391 // Created by GrVkGpu
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400392 GrVkResourceProvider fResourceProvider;
Greg Daniela58db7f2020-07-15 09:17:59 -0400393 GrStagingBufferManager fStagingBufferManager;
Greg Daniel164a9f02016-02-22 09:56:40 -0500394
Greg Daniela8c32102020-12-30 15:09:32 -0500395 GrVkMSAALoadManager fMSAALoadManager;
396
Greg Danield922f332020-04-27 11:21:36 -0400397 GrVkCommandPool* fMainCmdPool;
Ethan Nicholas8e265a72018-12-12 16:22:40 -0500398 // just a raw pointer; object's lifespan is managed by fCmdPool
Greg Danield922f332020-04-27 11:21:36 -0400399 GrVkPrimaryCommandBuffer* fMainCmdBuffer;
400
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400401 SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToWaitOn;
402 SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToSignal;
Greg Daniel6be35232017-03-01 17:01:09 -0500403
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400404 SkTArray<std::unique_ptr<SkDrawable::GpuDrawHandler>> fDrawables;
Greg Daniel6be35232017-03-01 17:01:09 -0500405
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400406 VkPhysicalDeviceProperties fPhysDevProps;
407 VkPhysicalDeviceMemoryProperties fPhysDevMemProps;
408
Greg Daniel8606cf82017-05-08 16:17:53 -0400409 // We need a bool to track whether or not we've already disconnected all the gpu resources from
410 // vulkan context.
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400411 bool fDisconnected;
Greg Daniel8606cf82017-05-08 16:17:53 -0400412
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400413 GrProtected fProtectedContext;
414
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400415 std::unique_ptr<GrVkOpsRenderPass> fCachedOpsRenderPass;
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400416
John Stiles7571f9e2020-09-02 22:42:33 -0400417 using INHERITED = GrGpu;
Greg Daniel164a9f02016-02-22 09:56:40 -0500418};
419
420#endif