blob: 313f6a51da93b4814019fda52535d8ab77dfb976 [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"
Chris Dalton10ee0b22020-04-02 16:28:52 -060018#include "src/gpu/vk/GrVkMeshBuffer.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "src/gpu/vk/GrVkResourceProvider.h"
20#include "src/gpu/vk/GrVkSemaphore.h"
21#include "src/gpu/vk/GrVkUtil.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050022
Adlai Holler3d0359a2020-07-09 15:35:55 -040023class GrDirectContext;
Greg Daniel164a9f02016-02-22 09:56:40 -050024class GrPipeline;
Greg Daniel164a9f02016-02-22 09:56:40 -050025
26class GrVkBufferImpl;
Ethan Nicholas8e265a72018-12-12 16:22:40 -050027class GrVkCommandPool;
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 Danielf730c182018-07-02 20:15:37 +000047 const GrVkInterface* vkInterface() const { return fInterface.get(); }
Greg Daniel164a9f02016-02-22 09:56:40 -050048 const GrVkCaps& vkCaps() const { return *fVkCaps; }
49
Greg Daniela58db7f2020-07-15 09:17:59 -040050 GrStagingBufferManager* stagingBufferManager() override { return &fStagingBufferManager; }
Jim Van Verth1aaf41b2020-07-29 09:24:29 -040051 void takeOwnershipOfBuffer(sk_sp<GrGpuBuffer>) override;
Greg Daniela58db7f2020-07-15 09:17:59 -040052
Greg Daniel6e35a002020-04-01 13:29:59 -040053 bool isDeviceLost() const override { return fDeviceIsLost; }
Greg Daniele643da62019-11-05 12:36:42 -050054
Greg Daniel81df0412018-05-31 13:13:33 -040055 GrVkMemoryAllocator* memoryAllocator() const { return fMemoryAllocator.get(); }
56
Greg Daniel637c06a2018-09-12 09:44:25 -040057 VkPhysicalDevice physicalDevice() const { return fPhysicalDevice; }
Greg Daniel164a9f02016-02-22 09:56:40 -050058 VkDevice device() const { return fDevice; }
59 VkQueue queue() const { return fQueue; }
Greg Danielecddbc02018-08-30 16:39:34 -040060 uint32_t queueIndex() const { return fQueueIndex; }
Greg Daniel288ecf62020-06-05 10:22:26 -040061 GrVkCommandPool* cmdPool() const { return fMainCmdPool; }
Greg Daniela870b462019-01-08 15:49:46 -050062 const VkPhysicalDeviceProperties& physicalDeviceProperties() const {
Greg Daniel8385a8a2018-02-26 13:29:37 -050063 return fPhysDevProps;
64 }
Greg Daniela870b462019-01-08 15:49:46 -050065 const VkPhysicalDeviceMemoryProperties& physicalDeviceMemoryProperties() const {
Greg Daniel164a9f02016-02-22 09:56:40 -050066 return fPhysDevMemProps;
67 }
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040068 bool protectedContext() const { return fProtectedContext == GrProtected::kYes; }
Greg Daniel164a9f02016-02-22 09:56:40 -050069
egdanielbc9b2962016-09-27 08:00:53 -070070 GrVkResourceProvider& resourceProvider() { return fResourceProvider; }
71
Greg Daniel288ecf62020-06-05 10:22:26 -040072 GrVkPrimaryCommandBuffer* currentCommandBuffer() const { return fMainCmdBuffer; }
Greg Daniel164a9f02016-02-22 09:56:40 -050073
Chris Dalton2284aab2019-11-15 11:02:24 -070074 void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>*) override;
Chris Daltond7291ba2019-03-07 14:17:03 -070075
Greg Daniel9a18b082020-08-14 14:03:50 -040076 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override;
Greg Daniel164a9f02016-02-22 09:56:40 -050077
Greg Daniel1db8e792020-06-09 17:29:32 -040078 bool setBackendTextureState(const GrBackendTexture&,
79 const GrBackendSurfaceMutableState&,
Greg Daniel1d3c8c12020-09-23 14:23:36 -040080 GrBackendSurfaceMutableState* previousState,
Greg Daniel1db8e792020-06-09 17:29:32 -040081 sk_sp<GrRefCntedCallback> finishedCallback) override;
82
83 bool setBackendRenderTargetState(const GrBackendRenderTarget&,
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
Robert Phillipsf0313ee2019-05-21 13:51:11 -040088 void deleteBackendTexture(const GrBackendTexture&) override;
Robert Phillips979b2232020-02-20 10:47:29 -050089
90 bool compile(const GrProgramDesc&, const GrProgramInfo&) override;
91
Robert Phillipsf0ced622019-05-16 09:06:25 -040092#if GR_TEST_UTILS
93 bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
Greg Daniel164a9f02016-02-22 09:56:40 -050094
Brian Salomonf9b00422020-10-08 16:00:14 -040095 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(SkISize dimensions,
Brian Salomon72c7b982020-10-06 10:07:38 -040096 GrColorType,
Brian Salomonf9b00422020-10-08 16:00:14 -040097 int sampleCnt,
98 GrProtected) override;
Brian Salomonf865b052018-03-09 09:01:53 -050099 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
100
Greg Daniel26b50a42018-03-08 09:49:58 -0500101 void testingOnly_flushGpuAndSync() override;
Brian Osmanfd7657c2019-04-25 11:34:07 -0400102
103 void resetShaderCacheForTesting() const override {
104 fResourceProvider.resetShaderCacheForTesting();
105 }
Brian Salomonf865b052018-03-09 09:01:53 -0500106#endif
Greg Daniel26b50a42018-03-08 09:49:58 -0500107
Greg Danielc0d69152020-10-08 14:59:00 -0400108 sk_sp<GrAttachment> makeStencilAttachmentForRenderTarget(const GrRenderTarget*,
109 SkISize dimensions,
110 int numStencilSamples) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500111
Greg Danielb8949bd2020-10-12 15:21:02 -0400112 GrBackendFormat getPreferredStencilFormat(const GrBackendFormat&) override {
113 return GrBackendFormat::MakeVk(this->vkCaps().preferredStencilFormat());
114 }
115
Greg Daniel5d0330e2020-10-12 16:05:21 -0400116 sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions,
117 const GrBackendFormat& format,
118 int numSamples,
119 GrProtected isProtected) override;
120
Jim Van Verth3e192162020-03-10 16:23:16 -0400121 void addBufferMemoryBarrier(const GrManagedResource*,
Greg Daniel59dc1482019-02-22 10:46:38 -0500122 VkPipelineStageFlags srcStageMask,
Greg Daniel164a9f02016-02-22 09:56:40 -0500123 VkPipelineStageFlags dstStageMask,
124 bool byRegion,
125 VkBufferMemoryBarrier* barrier) const;
Jim Van Verth3e192162020-03-10 16:23:16 -0400126 void addImageMemoryBarrier(const GrManagedResource*,
Greg Daniel59dc1482019-02-22 10:46:38 -0500127 VkPipelineStageFlags srcStageMask,
Greg Daniel164a9f02016-02-22 09:56:40 -0500128 VkPipelineStageFlags dstStageMask,
129 bool byRegion,
130 VkImageMemoryBarrier* barrier) const;
halcanary9d524f22016-03-29 09:03:52 -0700131
Greg Daniela8c32102020-12-30 15:09:32 -0500132 bool loadMSAAFromResolve(GrVkCommandBuffer* commandBuffer,
133 const GrVkRenderPass& renderPass,
134 GrSurface* dst,
135 GrSurface* src,
136 const SkIRect& srcRect);
137
Brian Salomon930f9392018-06-20 16:25:26 -0400138 bool onRegenerateMipMapLevels(GrTexture* tex) override;
139
Jim Van Verthbb61fe32020-07-07 16:39:04 -0400140 void onResolveRenderTarget(GrRenderTarget* target, const SkIRect& resolveRect) override;
egdaniel66933552016-08-24 07:22:19 -0700141
Greg Danielf0c681e2019-09-05 14:07:41 -0400142 void submitSecondaryCommandBuffer(std::unique_ptr<GrVkSecondaryCommandBuffer>);
egdaniel066df7c2016-06-08 14:02:27 -0700143
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400144 void submit(GrOpsRenderPass*) override;
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400145
Greg Daniel6be35232017-03-01 17:01:09 -0500146 GrFence SK_WARN_UNUSED_RESULT insertFence() override;
Stephen Whiteb353c9b2020-04-16 14:14:13 -0400147 bool waitFence(GrFence) override;
jvanverth84741b32016-09-30 08:39:02 -0700148 void deleteFence(GrFence) const override;
149
Greg Daniel301015c2019-11-18 14:06:46 -0500150 std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override;
151 std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
152 GrResourceProvider::SemaphoreWrapType wrapType, GrWrapOwnership ownership) override;
153 void insertSemaphore(GrSemaphore* semaphore) override;
154 void waitSemaphore(GrSemaphore* semaphore) override;
Greg Daniel48661b82018-01-22 16:11:35 -0500155
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400156 // These match the definitions in SkDrawable, from whence they came
157 typedef void* SubmitContext;
158 typedef void (*SubmitProc)(SubmitContext submitContext);
159
160 // Adds an SkDrawable::GpuDrawHandler that we will delete the next time we submit the primary
161 // command buffer to the gpu.
162 void addDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable);
163
Brian Salomonb0d8b762019-05-06 16:58:22 -0400164 void checkFinishProcs() override { fResourceProvider.checkCommandBuffers(); }
Greg Daniela89b4302021-01-29 10:48:40 -0500165 void finishOutstandingGpuWork() override;
Brian Salomonb0d8b762019-05-06 16:58:22 -0400166
Greg Daniel301015c2019-11-18 14:06:46 -0500167 std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override;
Brian Osman13dddce2017-05-09 13:19:50 -0400168
Greg Daniel6888c0d2017-08-25 11:55:50 -0400169 void copyBuffer(GrVkBuffer* srcBuffer, GrVkBuffer* dstBuffer, VkDeviceSize srcOffset,
170 VkDeviceSize dstOffset, VkDeviceSize size);
jvanverthdb379092016-07-07 11:18:46 -0700171 bool updateBuffer(GrVkBuffer* buffer, const void* src, VkDeviceSize offset, VkDeviceSize size);
jvanvertha584de92016-06-30 09:10:52 -0700172
Greg Daniela870b462019-01-08 15:49:46 -0500173 enum PersistentCacheKeyType : uint32_t {
174 kShader_PersistentCacheKeyType = 0,
175 kPipelineCache_PersistentCacheKeyType = 1,
176 };
177
178 void storeVkPipelineCacheData() override;
179
Greg Danielfa3adf72019-11-07 09:53:41 -0500180 bool beginRenderPass(const GrVkRenderPass*,
Greg Danielf0c681e2019-09-05 14:07:41 -0400181 const VkClearValue* colorClear,
Greg Daniel2f7a7ad2020-12-15 16:02:45 -0500182 GrVkRenderTarget*,
183 const SkIRect& renderPassBounds,
184 bool forSecondaryCB);
Greg Danielf0c681e2019-09-05 14:07:41 -0400185 void endRenderPass(GrRenderTarget* target, GrSurfaceOrigin origin, const SkIRect& bounds);
186
Brian Salomon864562f2020-08-11 16:22:34 -0400187 // Returns true if VkResult indicates success and also checks for device lost or OOM. Every
188 // Vulkan call (and GrVkMemoryAllocator call that returns VkResult) made on behalf of the
189 // GrVkGpu should be processed by this function so that we respond to OOMs and lost devices.
190 bool checkVkResult(VkResult);
Brian Salomon24069eb2020-06-24 10:19:52 -0400191
Greg Daniel164a9f02016-02-22 09:56:40 -0500192private:
Greg Daniele1185582019-12-04 11:29:44 -0500193 enum SyncQueue {
194 kForce_SyncQueue,
195 kSkip_SyncQueue
196 };
197
Greg Danielb2b4cc82020-08-21 14:59:00 -0400198 GrVkGpu(GrDirectContext*, const GrVkBackendContext&, const sk_sp<GrVkCaps> caps,
Greg Danielb16beb92020-04-27 14:26:21 +0000199 sk_sp<const GrVkInterface>, uint32_t instanceVersion, uint32_t physicalDeviceVersion,
200 sk_sp<GrVkMemoryAllocator>);
jvanverth633b3562016-03-23 11:01:22 -0700201
Greg Daniel8606cf82017-05-08 16:17:53 -0400202 void destroyResources();
203
Robert Phillipsb915c942019-12-17 14:44:37 -0500204 GrBackendTexture onCreateBackendTexture(SkISize dimensions,
Brian Salomon85c3d682019-11-04 15:04:54 -0500205 const GrBackendFormat&,
206 GrRenderable,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400207 GrMipmapped,
Greg Daniel16032b32020-05-06 15:31:10 -0400208 GrProtected) override;
Robert Phillipsb915c942019-12-17 14:44:37 -0500209 GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions,
210 const GrBackendFormat&,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400211 GrMipmapped,
Greg Danielaaf738c2020-07-10 09:30:33 -0400212 GrProtected) override;
Robert Phillipsb915c942019-12-17 14:44:37 -0500213
Greg Daniel16032b32020-05-06 15:31:10 -0400214 bool onUpdateBackendTexture(const GrBackendTexture&,
215 sk_sp<GrRefCntedCallback> finishedCallback,
216 const BackendTextureData*) override;
217
Greg Danielaaf738c2020-07-10 09:30:33 -0400218 bool onUpdateCompressedBackendTexture(const GrBackendTexture&,
219 sk_sp<GrRefCntedCallback> finishedCallback,
220 const BackendTextureData*) override;
221
Greg Daniel1db8e792020-06-09 17:29:32 -0400222 bool setBackendSurfaceState(GrVkImageInfo info,
223 sk_sp<GrBackendSurfaceMutableStateImpl> currentState,
224 SkISize dimensions,
Greg Daniel1d3c8c12020-09-23 14:23:36 -0400225 const GrVkSharedImageInfo& newInfo,
226 GrBackendSurfaceMutableState* previousState);
Greg Daniel1db8e792020-06-09 17:29:32 -0400227
Brian Salomona56a7462020-02-07 14:17:25 -0500228 sk_sp<GrTexture> onCreateTexture(SkISize,
Robert Phillips3a833922020-01-21 15:25:58 -0500229 const GrBackendFormat&,
Brian Salomon81536f22019-08-08 16:30:49 -0400230 GrRenderable,
231 int renderTargetSampleCnt,
232 SkBudgeted,
233 GrProtected,
Brian Salomond2a8ae22019-09-10 16:03:59 -0400234 int mipLevelCount,
235 uint32_t levelClearMask) override;
Robert Phillips3a833922020-01-21 15:25:58 -0500236 sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions,
237 const GrBackendFormat&,
238 SkBudgeted,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400239 GrMipmapped,
Robert Phillips3a833922020-01-21 15:25:58 -0500240 GrProtected,
241 const void* data, size_t dataSize) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500242
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400243 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
244 GrWrapOwnership,
245 GrWrapCacheable,
246 GrIOType) override;
247 sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&,
248 GrWrapOwnership,
Robert Phillipsb915c942019-12-17 14:44:37 -0500249 GrWrapCacheable) override;
Brian Salomond17f6582017-07-19 18:28:58 -0400250 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
Brian Salomond17f6582017-07-19 18:28:58 -0400251 int sampleCnt,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500252 GrWrapOwnership,
253 GrWrapCacheable) override;
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400254 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
Greg Daniel7ef28f32017-04-20 16:41:55 +0000255
Greg Danielb46add82019-01-02 14:51:29 -0500256 sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
257 const GrVkDrawableInfo&) override;
258
Brian Salomondbf70722019-02-07 11:31:24 -0500259 sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern,
260 const void* data) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500261
Brian Salomonf77c1462019-08-01 15:19:29 -0400262 bool onReadPixels(GrSurface* surface, int left, int top, int width, int height,
263 GrColorType surfaceColorType, GrColorType dstColorType, void* buffer,
264 size_t rowBytes) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500265
Brian Salomonf77c1462019-08-01 15:19:29 -0400266 bool onWritePixels(GrSurface* surface, int left, int top, int width, int height,
267 GrColorType surfaceColorType, GrColorType srcColorType,
Greg Danielb20d7e52019-09-03 13:54:39 -0400268 const GrMipLevel texels[], int mipLevelCount,
269 bool prepForTexSampling) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500270
Brian Salomonf77c1462019-08-01 15:19:29 -0400271 bool onTransferPixelsTo(GrTexture*, int left, int top, int width, int height,
272 GrColorType textureColorType, GrColorType bufferColorType,
Greg Daniel5ad5a372021-02-01 13:34:04 -0500273 sk_sp<GrGpuBuffer> transferBuffer, size_t offset,
274 size_t rowBytes) override;
Brian Salomon26de56e2019-04-10 12:14:26 -0400275 bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
Brian Salomonf77c1462019-08-01 15:19:29 -0400276 GrColorType surfaceColorType, GrColorType bufferColorType,
Greg Daniel5ad5a372021-02-01 13:34:04 -0500277 sk_sp<GrGpuBuffer> transferBuffer, size_t offset) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500278
Greg Daniel46cfbc62019-06-07 11:43:30 -0400279 bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
Greg Daniele227fe42019-08-21 13:52:24 -0400280 const SkIPoint& dstPoint) override;
Brian Salomon9b009bb2018-02-14 13:53:55 -0500281
Greg Danielfe159622020-04-10 17:43:51 +0000282 void addFinishedProc(GrGpuFinishedProc finishedProc,
283 GrGpuFinishedContext finishedContext) override;
284
Greg Daniel288ecf62020-06-05 10:22:26 -0400285 void addFinishedCallback(sk_sp<GrRefCntedCallback> finishedCallback);
286
Greg Daniel65476e02020-10-27 09:20:20 -0400287 GrOpsRenderPass* onGetOpsRenderPass(GrRenderTarget*,
288 GrAttachment*,
289 GrSurfaceOrigin,
290 const SkIRect&,
291 const GrOpsRenderPass::LoadAndStoreInfo&,
292 const GrOpsRenderPass::StencilLoadAndStoreInfo&,
293 const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
294 GrXferBarrierFlags renderPassXferBarriers) override;
295
Greg Daniel9efe3862020-06-11 11:51:06 -0400296 void prepareSurfacesForBackendAccessAndStateUpdates(
Adlai Hollerc2bfcff2020-11-06 15:39:36 -0500297 SkSpan<GrSurfaceProxy*> proxies,
Greg Daniel9efe3862020-06-11 11:51:06 -0400298 SkSurface::BackendSurfaceAccess access,
299 const GrBackendSurfaceMutableState* newState) override;
Greg Danielfe159622020-04-10 17:43:51 +0000300
301 bool onSubmitToGpu(bool syncCpu) override;
Greg Daniel51316782017-08-02 15:10:09 +0000302
Greg Danielb4327542020-11-20 10:50:50 -0500303 void onReportSubmitHistograms() override;
304
Greg Daniel164a9f02016-02-22 09:56:40 -0500305 // Ends and submits the current command buffer to the queue and then creates a new command
halcanary9d524f22016-03-29 09:03:52 -0700306 // buffer and begins it. If sync is set to kForce_SyncQueue, the function will wait for all
Greg Daniela5cb7812017-06-16 09:45:32 -0400307 // work in the queue to finish before returning. If this GrVkGpu object has any semaphores in
308 // fSemaphoreToSignal, we will add those signal semaphores to the submission of this command
309 // buffer. If this GrVkGpu object has any semaphores in fSemaphoresToWaitOn, we will add those
310 // wait semaphores to the submission of this command buffer.
Greg Danielfe159622020-04-10 17:43:51 +0000311 bool submitCommandBuffer(SyncQueue sync);
Greg Daniel164a9f02016-02-22 09:56:40 -0500312
Greg Daniel46cfbc62019-06-07 11:43:30 -0400313 void copySurfaceAsCopyImage(GrSurface* dst, GrSurface* src, GrVkImage* dstImage,
314 GrVkImage* srcImage, const SkIRect& srcRect,
Greg Daniel164a9f02016-02-22 09:56:40 -0500315 const SkIPoint& dstPoint);
316
Greg Daniel46cfbc62019-06-07 11:43:30 -0400317 void copySurfaceAsBlit(GrSurface* dst, GrSurface* src, GrVkImage* dstImage, GrVkImage* srcImage,
318 const SkIRect& srcRect, const SkIPoint& dstPoint);
egdaniel17b89252016-04-05 07:23:38 -0700319
Greg Daniel46cfbc62019-06-07 11:43:30 -0400320 void copySurfaceAsResolve(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
egdaniel4bcd62e2016-08-31 07:37:31 -0700321 const SkIPoint& dstPoint);
322
jvanverth900bd4a2016-04-29 13:53:12 -0700323 // helpers for onCreateTexture and writeTexturePixels
Brian Salomona9b04b92018-06-01 15:04:28 -0400324 bool uploadTexDataLinear(GrVkTexture* tex, int left, int top, int width, int height,
325 GrColorType colorType, const void* data, size_t rowBytes);
326 bool uploadTexDataOptimal(GrVkTexture* tex, int left, int top, int width, int height,
327 GrColorType colorType, const GrMipLevel texels[], int mipLevelCount);
Greg Daniel01f278c2020-06-12 16:58:17 -0400328 bool uploadTexDataCompressed(GrVkTexture* tex, SkImage::CompressionType compression,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400329 VkFormat vkFormat, SkISize dimensions, GrMipmapped mipMapped,
Greg Daniel01f278c2020-06-12 16:58:17 -0400330 const void* data, size_t dataSize);
Brian Salomon1fabd512018-02-09 09:54:25 -0500331 void resolveImage(GrSurface* dst, GrVkRenderTarget* src, const SkIRect& srcRect,
332 const SkIPoint& dstPoint);
egdaniel4bcd62e2016-08-31 07:37:31 -0700333
Brian Salomon85c3d682019-11-04 15:04:54 -0500334 bool createVkImageForBackendSurface(VkFormat,
Robert Phillips4277f012020-01-21 14:28:34 -0500335 SkISize dimensions,
Brian Salomon72c7b982020-10-06 10:07:38 -0400336 int sampleCnt,
Robert Phillipsb8757352020-01-21 13:05:25 -0500337 GrTexturable,
Robert Phillips0d7e2f12019-12-18 13:01:04 -0500338 GrRenderable,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400339 GrMipmapped,
Brian Salomon85c3d682019-11-04 15:04:54 -0500340 GrVkImageInfo*,
Greg Daniel16032b32020-05-06 15:31:10 -0400341 GrProtected);
Brian Salomon52e943a2018-03-13 09:32:39 -0400342
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400343 sk_sp<const GrVkInterface> fInterface;
344 sk_sp<GrVkMemoryAllocator> fMemoryAllocator;
345 sk_sp<GrVkCaps> fVkCaps;
Greg Daniele643da62019-11-05 12:36:42 -0500346 bool fDeviceIsLost = false;
jvanverth633b3562016-03-23 11:01:22 -0700347
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400348 VkPhysicalDevice fPhysicalDevice;
349 VkDevice fDevice;
350 VkQueue fQueue; // Must be Graphics queue
351 uint32_t fQueueIndex;
jvanverth633b3562016-03-23 11:01:22 -0700352
353 // Created by GrVkGpu
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400354 GrVkResourceProvider fResourceProvider;
Greg Daniela58db7f2020-07-15 09:17:59 -0400355 GrStagingBufferManager fStagingBufferManager;
Greg Daniel164a9f02016-02-22 09:56:40 -0500356
Greg Daniela8c32102020-12-30 15:09:32 -0500357 GrVkMSAALoadManager fMSAALoadManager;
358
Greg Danield922f332020-04-27 11:21:36 -0400359 GrVkCommandPool* fMainCmdPool;
Ethan Nicholas8e265a72018-12-12 16:22:40 -0500360 // just a raw pointer; object's lifespan is managed by fCmdPool
Greg Danield922f332020-04-27 11:21:36 -0400361 GrVkPrimaryCommandBuffer* fMainCmdBuffer;
362
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400363 SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToWaitOn;
364 SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToSignal;
Greg Daniel6be35232017-03-01 17:01:09 -0500365
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400366 SkTArray<std::unique_ptr<SkDrawable::GpuDrawHandler>> fDrawables;
Greg Daniel6be35232017-03-01 17:01:09 -0500367
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400368 VkPhysicalDeviceProperties fPhysDevProps;
369 VkPhysicalDeviceMemoryProperties fPhysDevMemProps;
370
Greg Daniel8606cf82017-05-08 16:17:53 -0400371 // We need a bool to track whether or not we've already disconnected all the gpu resources from
372 // vulkan context.
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400373 bool fDisconnected;
Greg Daniel8606cf82017-05-08 16:17:53 -0400374
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400375 GrProtected fProtectedContext;
376
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400377 std::unique_ptr<GrVkOpsRenderPass> fCachedOpsRenderPass;
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400378
John Stiles7571f9e2020-09-02 22:42:33 -0400379 using INHERITED = GrGpu;
Greg Daniel164a9f02016-02-22 09:56:40 -0500380};
381
382#endif