blob: db8fa0ba9e0d7bce799358bef5fefa940db5091a [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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/gpu/vk/GrVkMemory.h"
Chris Dalton10ee0b22020-04-02 16:28:52 -060017#include "src/gpu/vk/GrVkMeshBuffer.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#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
25class GrVkBufferImpl;
Ethan Nicholas8e265a72018-12-12 16:22:40 -050026class GrVkCommandPool;
Greg Daniel81df0412018-05-31 13:13:33 -040027class GrVkMemoryAllocator;
Greg Daniel164a9f02016-02-22 09:56:40 -050028class GrVkPipeline;
egdaniel22281c12016-03-23 13:49:40 -070029class GrVkPipelineState;
egdaniel066df7c2016-06-08 14:02:27 -070030class GrVkPrimaryCommandBuffer;
Greg Daniel2d41d0d2019-08-26 11:08:51 -040031class GrVkOpsRenderPass;
Greg Daniel164a9f02016-02-22 09:56:40 -050032class GrVkRenderPass;
egdaniel066df7c2016-06-08 14:02:27 -070033class GrVkSecondaryCommandBuffer;
Greg Daniel164a9f02016-02-22 09:56:40 -050034class GrVkTexture;
35struct GrVkInterface;
36
Ethan Nicholas941e7e22016-12-12 15:33:30 -050037namespace SkSL {
38 class Compiler;
John Stilesa6841be2020-08-06 14:11:56 -040039} // namespace SkSL
Ethan Nicholas941e7e22016-12-12 15:33:30 -050040
Greg Daniel164a9f02016-02-22 09:56:40 -050041class GrVkGpu : public GrGpu {
42public:
Adlai Holler3d0359a2020-07-09 15:35:55 -040043 static sk_sp<GrGpu> Make(const GrVkBackendContext&, const GrContextOptions&, GrDirectContext*);
jvanverth633b3562016-03-23 11:01:22 -070044
Greg Daniel164a9f02016-02-22 09:56:40 -050045 ~GrVkGpu() override;
46
Greg Daniel8606cf82017-05-08 16:17:53 -040047 void disconnect(DisconnectType) override;
48
Greg Danielf730c182018-07-02 20:15:37 +000049 const GrVkInterface* vkInterface() const { return fInterface.get(); }
Greg Daniel164a9f02016-02-22 09:56:40 -050050 const GrVkCaps& vkCaps() const { return *fVkCaps; }
51
Greg Daniela58db7f2020-07-15 09:17:59 -040052 GrStagingBufferManager* stagingBufferManager() override { return &fStagingBufferManager; }
Jim Van Verth1aaf41b2020-07-29 09:24:29 -040053 void takeOwnershipOfBuffer(sk_sp<GrGpuBuffer>) override;
Greg Daniela58db7f2020-07-15 09:17:59 -040054
Greg Daniel6e35a002020-04-01 13:29:59 -040055 bool isDeviceLost() const override { return fDeviceIsLost; }
Greg Daniele643da62019-11-05 12:36:42 -050056
Greg Daniel81df0412018-05-31 13:13:33 -040057 GrVkMemoryAllocator* memoryAllocator() const { return fMemoryAllocator.get(); }
58
Greg Daniel637c06a2018-09-12 09:44:25 -040059 VkPhysicalDevice physicalDevice() const { return fPhysicalDevice; }
Greg Daniel164a9f02016-02-22 09:56:40 -050060 VkDevice device() const { return fDevice; }
61 VkQueue queue() const { return fQueue; }
Greg Danielecddbc02018-08-30 16:39:34 -040062 uint32_t queueIndex() const { return fQueueIndex; }
Greg Daniel288ecf62020-06-05 10:22:26 -040063 GrVkCommandPool* cmdPool() const { return fMainCmdPool; }
Greg Daniela870b462019-01-08 15:49:46 -050064 const VkPhysicalDeviceProperties& physicalDeviceProperties() const {
Greg Daniel8385a8a2018-02-26 13:29:37 -050065 return fPhysDevProps;
66 }
Greg Daniela870b462019-01-08 15:49:46 -050067 const VkPhysicalDeviceMemoryProperties& physicalDeviceMemoryProperties() const {
Greg Daniel164a9f02016-02-22 09:56:40 -050068 return fPhysDevMemProps;
69 }
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040070 bool protectedContext() const { return fProtectedContext == GrProtected::kYes; }
Greg Daniel164a9f02016-02-22 09:56:40 -050071
egdanielbc9b2962016-09-27 08:00:53 -070072 GrVkResourceProvider& resourceProvider() { return fResourceProvider; }
73
Greg Daniel288ecf62020-06-05 10:22:26 -040074 GrVkPrimaryCommandBuffer* currentCommandBuffer() const { return fMainCmdBuffer; }
Greg Daniel164a9f02016-02-22 09:56:40 -050075
Chris Dalton2284aab2019-11-15 11:02:24 -070076 void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>*) override;
Chris Daltond7291ba2019-03-07 14:17:03 -070077
Greg Daniel9a18b082020-08-14 14:03:50 -040078 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override;
Greg Daniel164a9f02016-02-22 09:56:40 -050079
Greg Daniel1db8e792020-06-09 17:29:32 -040080 bool setBackendTextureState(const GrBackendTexture&,
81 const GrBackendSurfaceMutableState&,
Greg Daniel1d3c8c12020-09-23 14:23:36 -040082 GrBackendSurfaceMutableState* previousState,
Greg Daniel1db8e792020-06-09 17:29:32 -040083 sk_sp<GrRefCntedCallback> finishedCallback) override;
84
85 bool setBackendRenderTargetState(const GrBackendRenderTarget&,
86 const GrBackendSurfaceMutableState&,
Greg Daniel1d3c8c12020-09-23 14:23:36 -040087 GrBackendSurfaceMutableState* previousState,
Greg Daniel1db8e792020-06-09 17:29:32 -040088 sk_sp<GrRefCntedCallback> finishedCallback) override;
89
Robert Phillipsf0313ee2019-05-21 13:51:11 -040090 void deleteBackendTexture(const GrBackendTexture&) override;
Robert Phillips979b2232020-02-20 10:47:29 -050091
92 bool compile(const GrProgramDesc&, const GrProgramInfo&) override;
93
Robert Phillipsf0ced622019-05-16 09:06:25 -040094#if GR_TEST_UTILS
95 bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
Greg Daniel164a9f02016-02-22 09:56:40 -050096
Brian Salomonf9b00422020-10-08 16:00:14 -040097 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(SkISize dimensions,
Brian Salomon72c7b982020-10-06 10:07:38 -040098 GrColorType,
Brian Salomonf9b00422020-10-08 16:00:14 -040099 int sampleCnt,
100 GrProtected) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500101 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
102
Greg Daniel26b50a42018-03-08 09:49:58 -0500103 void testingOnly_flushGpuAndSync() override;
Brian Osmanfd7657c2019-04-25 11:34:07 -0400104
105 void resetShaderCacheForTesting() const override {
106 fResourceProvider.resetShaderCacheForTesting();
107 }
Brian Salomonf865b052018-03-09 09:01:53 -0500108#endif
Greg Daniel26b50a42018-03-08 09:49:58 -0500109
Greg Danielc0d69152020-10-08 14:59:00 -0400110 sk_sp<GrAttachment> makeStencilAttachmentForRenderTarget(const GrRenderTarget*,
111 SkISize dimensions,
112 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;
Jim Van Verth3e192162020-03-10 16:23:16 -0400128 void addImageMemoryBarrier(const GrManagedResource*,
Greg Daniel59dc1482019-02-22 10:46:38 -0500129 VkPipelineStageFlags srcStageMask,
Greg Daniel164a9f02016-02-22 09:56:40 -0500130 VkPipelineStageFlags dstStageMask,
131 bool byRegion,
132 VkImageMemoryBarrier* barrier) const;
halcanary9d524f22016-03-29 09:03:52 -0700133
ethannicholasb3058bd2016-07-01 08:22:01 -0700134 SkSL::Compiler* shaderCompiler() const {
135 return fCompiler;
136 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500137
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(); }
165
Greg Daniel301015c2019-11-18 14:06:46 -0500166 std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override;
Brian Osman13dddce2017-05-09 13:19:50 -0400167
Greg Daniel6888c0d2017-08-25 11:55:50 -0400168 void copyBuffer(GrVkBuffer* srcBuffer, GrVkBuffer* dstBuffer, VkDeviceSize srcOffset,
169 VkDeviceSize dstOffset, VkDeviceSize size);
jvanverthdb379092016-07-07 11:18:46 -0700170 bool updateBuffer(GrVkBuffer* buffer, const void* src, VkDeviceSize offset, VkDeviceSize size);
jvanvertha584de92016-06-30 09:10:52 -0700171
Greg Daniela870b462019-01-08 15:49:46 -0500172 enum PersistentCacheKeyType : uint32_t {
173 kShader_PersistentCacheKeyType = 0,
174 kPipelineCache_PersistentCacheKeyType = 1,
175 };
176
177 void storeVkPipelineCacheData() override;
178
Greg Danielfa3adf72019-11-07 09:53:41 -0500179 bool beginRenderPass(const GrVkRenderPass*,
Greg Danielf0c681e2019-09-05 14:07:41 -0400180 const VkClearValue* colorClear,
181 GrVkRenderTarget*, GrSurfaceOrigin,
Greg Daniel28d40b22019-09-09 15:00:15 +0000182 const SkIRect& bounds, bool forSecondaryCB);
Greg Danielf0c681e2019-09-05 14:07:41 -0400183 void endRenderPass(GrRenderTarget* target, GrSurfaceOrigin origin, const SkIRect& bounds);
184
Brian Salomon864562f2020-08-11 16:22:34 -0400185 // Returns true if VkResult indicates success and also checks for device lost or OOM. Every
186 // Vulkan call (and GrVkMemoryAllocator call that returns VkResult) made on behalf of the
187 // GrVkGpu should be processed by this function so that we respond to OOMs and lost devices.
188 bool checkVkResult(VkResult);
Brian Salomon24069eb2020-06-24 10:19:52 -0400189
Greg Daniel164a9f02016-02-22 09:56:40 -0500190private:
Greg Daniele1185582019-12-04 11:29:44 -0500191 enum SyncQueue {
192 kForce_SyncQueue,
193 kSkip_SyncQueue
194 };
195
Greg Danielb2b4cc82020-08-21 14:59:00 -0400196 GrVkGpu(GrDirectContext*, const GrVkBackendContext&, const sk_sp<GrVkCaps> caps,
Greg Danielb16beb92020-04-27 14:26:21 +0000197 sk_sp<const GrVkInterface>, uint32_t instanceVersion, uint32_t physicalDeviceVersion,
198 sk_sp<GrVkMemoryAllocator>);
jvanverth633b3562016-03-23 11:01:22 -0700199
egdanielcfcd1812016-03-22 07:16:10 -0700200 void onResetContext(uint32_t resetBits) override {}
Greg Daniel164a9f02016-02-22 09:56:40 -0500201
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,
Brian Salomone05ba5a2019-04-08 11:59:07 -0400273 GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override;
Brian Salomon26de56e2019-04-10 12:14:26 -0400274 bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
Brian Salomonf77c1462019-08-01 15:19:29 -0400275 GrColorType surfaceColorType, GrColorType bufferColorType,
276 GrGpuBuffer* transferBuffer, size_t offset) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500277
Greg Daniel46cfbc62019-06-07 11:43:30 -0400278 bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
Greg Daniele227fe42019-08-21 13:52:24 -0400279 const SkIPoint& dstPoint) override;
Brian Salomon9b009bb2018-02-14 13:53:55 -0500280
Greg Danielfe159622020-04-10 17:43:51 +0000281 void addFinishedProc(GrGpuFinishedProc finishedProc,
282 GrGpuFinishedContext finishedContext) override;
283
Greg Daniel288ecf62020-06-05 10:22:26 -0400284 void addFinishedCallback(sk_sp<GrRefCntedCallback> finishedCallback);
285
Greg Daniel65476e02020-10-27 09:20:20 -0400286 GrOpsRenderPass* onGetOpsRenderPass(GrRenderTarget*,
287 GrAttachment*,
288 GrSurfaceOrigin,
289 const SkIRect&,
290 const GrOpsRenderPass::LoadAndStoreInfo&,
291 const GrOpsRenderPass::StencilLoadAndStoreInfo&,
292 const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
293 GrXferBarrierFlags renderPassXferBarriers) override;
294
Greg Daniel9efe3862020-06-11 11:51:06 -0400295 void prepareSurfacesForBackendAccessAndStateUpdates(
Adlai Hollerc2bfcff2020-11-06 15:39:36 -0500296 SkSpan<GrSurfaceProxy*> proxies,
Greg Daniel9efe3862020-06-11 11:51:06 -0400297 SkSurface::BackendSurfaceAccess access,
298 const GrBackendSurfaceMutableState* newState) override;
Greg Danielfe159622020-04-10 17:43:51 +0000299
300 bool onSubmitToGpu(bool syncCpu) override;
Greg Daniel51316782017-08-02 15:10:09 +0000301
Greg Daniel164a9f02016-02-22 09:56:40 -0500302 // Ends and submits the current command buffer to the queue and then creates a new command
halcanary9d524f22016-03-29 09:03:52 -0700303 // buffer and begins it. If sync is set to kForce_SyncQueue, the function will wait for all
Greg Daniela5cb7812017-06-16 09:45:32 -0400304 // work in the queue to finish before returning. If this GrVkGpu object has any semaphores in
305 // fSemaphoreToSignal, we will add those signal semaphores to the submission of this command
306 // buffer. If this GrVkGpu object has any semaphores in fSemaphoresToWaitOn, we will add those
307 // wait semaphores to the submission of this command buffer.
Greg Danielfe159622020-04-10 17:43:51 +0000308 bool submitCommandBuffer(SyncQueue sync);
Greg Daniel164a9f02016-02-22 09:56:40 -0500309
Greg Daniel46cfbc62019-06-07 11:43:30 -0400310 void copySurfaceAsCopyImage(GrSurface* dst, GrSurface* src, GrVkImage* dstImage,
311 GrVkImage* srcImage, const SkIRect& srcRect,
Greg Daniel164a9f02016-02-22 09:56:40 -0500312 const SkIPoint& dstPoint);
313
Greg Daniel46cfbc62019-06-07 11:43:30 -0400314 void copySurfaceAsBlit(GrSurface* dst, GrSurface* src, GrVkImage* dstImage, GrVkImage* srcImage,
315 const SkIRect& srcRect, const SkIPoint& dstPoint);
egdaniel17b89252016-04-05 07:23:38 -0700316
Greg Daniel46cfbc62019-06-07 11:43:30 -0400317 void copySurfaceAsResolve(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
egdaniel4bcd62e2016-08-31 07:37:31 -0700318 const SkIPoint& dstPoint);
319
jvanverth900bd4a2016-04-29 13:53:12 -0700320 // helpers for onCreateTexture and writeTexturePixels
Brian Salomona9b04b92018-06-01 15:04:28 -0400321 bool uploadTexDataLinear(GrVkTexture* tex, int left, int top, int width, int height,
322 GrColorType colorType, const void* data, size_t rowBytes);
323 bool uploadTexDataOptimal(GrVkTexture* tex, int left, int top, int width, int height,
324 GrColorType colorType, const GrMipLevel texels[], int mipLevelCount);
Greg Daniel01f278c2020-06-12 16:58:17 -0400325 bool uploadTexDataCompressed(GrVkTexture* tex, SkImage::CompressionType compression,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400326 VkFormat vkFormat, SkISize dimensions, GrMipmapped mipMapped,
Greg Daniel01f278c2020-06-12 16:58:17 -0400327 const void* data, size_t dataSize);
Brian Salomon1fabd512018-02-09 09:54:25 -0500328 void resolveImage(GrSurface* dst, GrVkRenderTarget* src, const SkIRect& srcRect,
329 const SkIPoint& dstPoint);
egdaniel4bcd62e2016-08-31 07:37:31 -0700330
Brian Salomon85c3d682019-11-04 15:04:54 -0500331 bool createVkImageForBackendSurface(VkFormat,
Robert Phillips4277f012020-01-21 14:28:34 -0500332 SkISize dimensions,
Brian Salomon72c7b982020-10-06 10:07:38 -0400333 int sampleCnt,
Robert Phillipsb8757352020-01-21 13:05:25 -0500334 GrTexturable,
Robert Phillips0d7e2f12019-12-18 13:01:04 -0500335 GrRenderable,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400336 GrMipmapped,
Brian Salomon85c3d682019-11-04 15:04:54 -0500337 GrVkImageInfo*,
Greg Daniel16032b32020-05-06 15:31:10 -0400338 GrProtected);
Brian Salomon52e943a2018-03-13 09:32:39 -0400339
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400340 sk_sp<const GrVkInterface> fInterface;
341 sk_sp<GrVkMemoryAllocator> fMemoryAllocator;
342 sk_sp<GrVkCaps> fVkCaps;
Greg Daniele643da62019-11-05 12:36:42 -0500343 bool fDeviceIsLost = false;
jvanverth633b3562016-03-23 11:01:22 -0700344
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400345 VkPhysicalDevice fPhysicalDevice;
346 VkDevice fDevice;
347 VkQueue fQueue; // Must be Graphics queue
348 uint32_t fQueueIndex;
jvanverth633b3562016-03-23 11:01:22 -0700349
350 // Created by GrVkGpu
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400351 GrVkResourceProvider fResourceProvider;
Greg Daniela58db7f2020-07-15 09:17:59 -0400352 GrStagingBufferManager fStagingBufferManager;
Greg Daniel164a9f02016-02-22 09:56:40 -0500353
Greg Danield922f332020-04-27 11:21:36 -0400354 GrVkCommandPool* fMainCmdPool;
Ethan Nicholas8e265a72018-12-12 16:22:40 -0500355 // just a raw pointer; object's lifespan is managed by fCmdPool
Greg Danield922f332020-04-27 11:21:36 -0400356 GrVkPrimaryCommandBuffer* fMainCmdBuffer;
357
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400358 SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToWaitOn;
359 SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToSignal;
Greg Daniel6be35232017-03-01 17:01:09 -0500360
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400361 SkTArray<std::unique_ptr<SkDrawable::GpuDrawHandler>> fDrawables;
Greg Daniel6be35232017-03-01 17:01:09 -0500362
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400363 VkPhysicalDeviceProperties fPhysDevProps;
364 VkPhysicalDeviceMemoryProperties fPhysDevMemProps;
365
Ethan Nicholas941e7e22016-12-12 15:33:30 -0500366 // compiler used for compiling sksl into spirv. We only want to create the compiler once since
367 // there is significant overhead to the first compile of any compiler.
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400368 SkSL::Compiler* fCompiler;
Greg Daniel164a9f02016-02-22 09:56:40 -0500369
Greg Daniel8606cf82017-05-08 16:17:53 -0400370 // We need a bool to track whether or not we've already disconnected all the gpu resources from
371 // vulkan context.
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400372 bool fDisconnected;
Greg Daniel8606cf82017-05-08 16:17:53 -0400373
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400374 GrProtected fProtectedContext;
375
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400376 std::unique_ptr<GrVkOpsRenderPass> fCachedOpsRenderPass;
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400377
John Stiles7571f9e2020-09-02 22:42:33 -0400378 using INHERITED = GrGpu;
Greg Daniel164a9f02016-02-22 09:56:40 -0500379};
380
381#endif