blob: 52798f25f4c62da4e2e6f54c458d79a75ba197b8 [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&,
82 sk_sp<GrRefCntedCallback> finishedCallback) override;
83
84 bool setBackendRenderTargetState(const GrBackendRenderTarget&,
85 const GrBackendSurfaceMutableState&,
86 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 Osman2d010b62018-08-09 10:55:09 -040095 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
Brian Salomonf865b052018-03-09 09:01:53 -050096 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
97
Greg Daniel26b50a42018-03-08 09:49:58 -050098 void testingOnly_flushGpuAndSync() override;
Brian Osmanfd7657c2019-04-25 11:34:07 -040099
100 void resetShaderCacheForTesting() const override {
101 fResourceProvider.resetShaderCacheForTesting();
102 }
Brian Salomonf865b052018-03-09 09:01:53 -0500103#endif
Greg Daniel26b50a42018-03-08 09:49:58 -0500104
Chris Daltoneffee202019-07-01 22:28:03 -0600105 GrStencilAttachment* createStencilAttachmentForRenderTarget(
106 const GrRenderTarget*, int width, int height, int numStencilSamples) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500107
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400108 GrOpsRenderPass* getOpsRenderPass(
Robert Phillips96f22372020-05-20 12:31:18 -0400109 GrRenderTarget*, GrStencilAttachment*,
110 GrSurfaceOrigin, const SkIRect&,
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400111 const GrOpsRenderPass::LoadAndStoreInfo&,
Greg Danielb20d7e52019-09-03 13:54:39 -0400112 const GrOpsRenderPass::StencilLoadAndStoreInfo&,
Greg Daniel9a18b082020-08-14 14:03:50 -0400113 const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
114 bool usesXferBarriers) override;
egdaniel066df7c2016-06-08 14:02:27 -0700115
Jim Van Verth3e192162020-03-10 16:23:16 -0400116 void addBufferMemoryBarrier(const GrManagedResource*,
Greg Daniel59dc1482019-02-22 10:46:38 -0500117 VkPipelineStageFlags srcStageMask,
Greg Daniel164a9f02016-02-22 09:56:40 -0500118 VkPipelineStageFlags dstStageMask,
119 bool byRegion,
120 VkBufferMemoryBarrier* barrier) const;
Jim Van Verth3e192162020-03-10 16:23:16 -0400121 void addImageMemoryBarrier(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 VkImageMemoryBarrier* barrier) const;
halcanary9d524f22016-03-29 09:03:52 -0700126
ethannicholasb3058bd2016-07-01 08:22:01 -0700127 SkSL::Compiler* shaderCompiler() const {
128 return fCompiler;
129 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500130
Brian Salomon930f9392018-06-20 16:25:26 -0400131 bool onRegenerateMipMapLevels(GrTexture* tex) override;
132
Jim Van Verthbb61fe32020-07-07 16:39:04 -0400133 void onResolveRenderTarget(GrRenderTarget* target, const SkIRect& resolveRect) override;
egdaniel66933552016-08-24 07:22:19 -0700134
Greg Danielf0c681e2019-09-05 14:07:41 -0400135 void submitSecondaryCommandBuffer(std::unique_ptr<GrVkSecondaryCommandBuffer>);
egdaniel066df7c2016-06-08 14:02:27 -0700136
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400137 void submit(GrOpsRenderPass*) override;
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400138
Greg Daniel6be35232017-03-01 17:01:09 -0500139 GrFence SK_WARN_UNUSED_RESULT insertFence() override;
Stephen Whiteb353c9b2020-04-16 14:14:13 -0400140 bool waitFence(GrFence) override;
jvanverth84741b32016-09-30 08:39:02 -0700141 void deleteFence(GrFence) const override;
142
Greg Daniel301015c2019-11-18 14:06:46 -0500143 std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override;
144 std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
145 GrResourceProvider::SemaphoreWrapType wrapType, GrWrapOwnership ownership) override;
146 void insertSemaphore(GrSemaphore* semaphore) override;
147 void waitSemaphore(GrSemaphore* semaphore) override;
Greg Daniel48661b82018-01-22 16:11:35 -0500148
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400149 // These match the definitions in SkDrawable, from whence they came
150 typedef void* SubmitContext;
151 typedef void (*SubmitProc)(SubmitContext submitContext);
152
153 // Adds an SkDrawable::GpuDrawHandler that we will delete the next time we submit the primary
154 // command buffer to the gpu.
155 void addDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable);
156
Brian Salomonb0d8b762019-05-06 16:58:22 -0400157 void checkFinishProcs() override { fResourceProvider.checkCommandBuffers(); }
158
Greg Daniel301015c2019-11-18 14:06:46 -0500159 std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override;
Brian Osman13dddce2017-05-09 13:19:50 -0400160
Greg Daniel6888c0d2017-08-25 11:55:50 -0400161 void copyBuffer(GrVkBuffer* srcBuffer, GrVkBuffer* dstBuffer, VkDeviceSize srcOffset,
162 VkDeviceSize dstOffset, VkDeviceSize size);
jvanverthdb379092016-07-07 11:18:46 -0700163 bool updateBuffer(GrVkBuffer* buffer, const void* src, VkDeviceSize offset, VkDeviceSize size);
jvanvertha584de92016-06-30 09:10:52 -0700164
Greg Daniela870b462019-01-08 15:49:46 -0500165 enum PersistentCacheKeyType : uint32_t {
166 kShader_PersistentCacheKeyType = 0,
167 kPipelineCache_PersistentCacheKeyType = 1,
168 };
169
170 void storeVkPipelineCacheData() override;
171
Greg Danielfa3adf72019-11-07 09:53:41 -0500172 bool beginRenderPass(const GrVkRenderPass*,
Greg Danielf0c681e2019-09-05 14:07:41 -0400173 const VkClearValue* colorClear,
174 GrVkRenderTarget*, GrSurfaceOrigin,
Greg Daniel28d40b22019-09-09 15:00:15 +0000175 const SkIRect& bounds, bool forSecondaryCB);
Greg Danielf0c681e2019-09-05 14:07:41 -0400176 void endRenderPass(GrRenderTarget* target, GrSurfaceOrigin origin, const SkIRect& bounds);
177
Brian Salomon864562f2020-08-11 16:22:34 -0400178 // Returns true if VkResult indicates success and also checks for device lost or OOM. Every
179 // Vulkan call (and GrVkMemoryAllocator call that returns VkResult) made on behalf of the
180 // GrVkGpu should be processed by this function so that we respond to OOMs and lost devices.
181 bool checkVkResult(VkResult);
Brian Salomon24069eb2020-06-24 10:19:52 -0400182
Greg Daniel164a9f02016-02-22 09:56:40 -0500183private:
Greg Daniele1185582019-12-04 11:29:44 -0500184 enum SyncQueue {
185 kForce_SyncQueue,
186 kSkip_SyncQueue
187 };
188
Greg Danielb2b4cc82020-08-21 14:59:00 -0400189 GrVkGpu(GrDirectContext*, const GrVkBackendContext&, const sk_sp<GrVkCaps> caps,
Greg Danielb16beb92020-04-27 14:26:21 +0000190 sk_sp<const GrVkInterface>, uint32_t instanceVersion, uint32_t physicalDeviceVersion,
191 sk_sp<GrVkMemoryAllocator>);
jvanverth633b3562016-03-23 11:01:22 -0700192
egdanielcfcd1812016-03-22 07:16:10 -0700193 void onResetContext(uint32_t resetBits) override {}
Greg Daniel164a9f02016-02-22 09:56:40 -0500194
Greg Daniel8606cf82017-05-08 16:17:53 -0400195 void destroyResources();
196
Robert Phillipsb915c942019-12-17 14:44:37 -0500197 GrBackendTexture onCreateBackendTexture(SkISize dimensions,
Brian Salomon85c3d682019-11-04 15:04:54 -0500198 const GrBackendFormat&,
199 GrRenderable,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400200 GrMipmapped,
Greg Daniel16032b32020-05-06 15:31:10 -0400201 GrProtected) override;
Robert Phillipsb915c942019-12-17 14:44:37 -0500202 GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions,
203 const GrBackendFormat&,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400204 GrMipmapped,
Greg Danielaaf738c2020-07-10 09:30:33 -0400205 GrProtected) override;
Robert Phillipsb915c942019-12-17 14:44:37 -0500206
Greg Daniel16032b32020-05-06 15:31:10 -0400207 bool onUpdateBackendTexture(const GrBackendTexture&,
208 sk_sp<GrRefCntedCallback> finishedCallback,
209 const BackendTextureData*) override;
210
Greg Danielaaf738c2020-07-10 09:30:33 -0400211 bool onUpdateCompressedBackendTexture(const GrBackendTexture&,
212 sk_sp<GrRefCntedCallback> finishedCallback,
213 const BackendTextureData*) override;
214
Greg Daniel1db8e792020-06-09 17:29:32 -0400215 bool setBackendSurfaceState(GrVkImageInfo info,
216 sk_sp<GrBackendSurfaceMutableStateImpl> currentState,
217 SkISize dimensions,
218 const GrVkSharedImageInfo& newInfo);
219
Brian Salomona56a7462020-02-07 14:17:25 -0500220 sk_sp<GrTexture> onCreateTexture(SkISize,
Robert Phillips3a833922020-01-21 15:25:58 -0500221 const GrBackendFormat&,
Brian Salomon81536f22019-08-08 16:30:49 -0400222 GrRenderable,
223 int renderTargetSampleCnt,
224 SkBudgeted,
225 GrProtected,
Brian Salomond2a8ae22019-09-10 16:03:59 -0400226 int mipLevelCount,
227 uint32_t levelClearMask) override;
Robert Phillips3a833922020-01-21 15:25:58 -0500228 sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions,
229 const GrBackendFormat&,
230 SkBudgeted,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400231 GrMipmapped,
Robert Phillips3a833922020-01-21 15:25:58 -0500232 GrProtected,
233 const void* data, size_t dataSize) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500234
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400235 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
236 GrWrapOwnership,
237 GrWrapCacheable,
238 GrIOType) override;
239 sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&,
240 GrWrapOwnership,
Robert Phillipsb915c942019-12-17 14:44:37 -0500241 GrWrapCacheable) override;
Brian Salomond17f6582017-07-19 18:28:58 -0400242 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
Brian Salomond17f6582017-07-19 18:28:58 -0400243 int sampleCnt,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500244 GrWrapOwnership,
245 GrWrapCacheable) override;
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400246 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
Greg Daniel7ef28f32017-04-20 16:41:55 +0000247
248 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400249 int sampleCnt) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500250
Greg Danielb46add82019-01-02 14:51:29 -0500251 sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
252 const GrVkDrawableInfo&) override;
253
Brian Salomondbf70722019-02-07 11:31:24 -0500254 sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern,
255 const void* data) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500256
Brian Salomonf77c1462019-08-01 15:19:29 -0400257 bool onReadPixels(GrSurface* surface, int left, int top, int width, int height,
258 GrColorType surfaceColorType, GrColorType dstColorType, void* buffer,
259 size_t rowBytes) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500260
Brian Salomonf77c1462019-08-01 15:19:29 -0400261 bool onWritePixels(GrSurface* surface, int left, int top, int width, int height,
262 GrColorType surfaceColorType, GrColorType srcColorType,
Greg Danielb20d7e52019-09-03 13:54:39 -0400263 const GrMipLevel texels[], int mipLevelCount,
264 bool prepForTexSampling) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500265
Brian Salomonf77c1462019-08-01 15:19:29 -0400266 bool onTransferPixelsTo(GrTexture*, int left, int top, int width, int height,
267 GrColorType textureColorType, GrColorType bufferColorType,
Brian Salomone05ba5a2019-04-08 11:59:07 -0400268 GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override;
Brian Salomon26de56e2019-04-10 12:14:26 -0400269 bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
Brian Salomonf77c1462019-08-01 15:19:29 -0400270 GrColorType surfaceColorType, GrColorType bufferColorType,
271 GrGpuBuffer* transferBuffer, size_t offset) override;
Greg Daniel164a9f02016-02-22 09:56:40 -0500272
Greg Daniel46cfbc62019-06-07 11:43:30 -0400273 bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
Greg Daniele227fe42019-08-21 13:52:24 -0400274 const SkIPoint& dstPoint) override;
Brian Salomon9b009bb2018-02-14 13:53:55 -0500275
Greg Danielfe159622020-04-10 17:43:51 +0000276 void addFinishedProc(GrGpuFinishedProc finishedProc,
277 GrGpuFinishedContext finishedContext) override;
278
Greg Daniel288ecf62020-06-05 10:22:26 -0400279 void addFinishedCallback(sk_sp<GrRefCntedCallback> finishedCallback);
280
Greg Daniel9efe3862020-06-11 11:51:06 -0400281 void prepareSurfacesForBackendAccessAndStateUpdates(
282 GrSurfaceProxy* proxies[],
283 int numProxies,
284 SkSurface::BackendSurfaceAccess access,
285 const GrBackendSurfaceMutableState* newState) override;
Greg Danielfe159622020-04-10 17:43:51 +0000286
287 bool onSubmitToGpu(bool syncCpu) override;
Greg Daniel51316782017-08-02 15:10:09 +0000288
Greg Daniel164a9f02016-02-22 09:56:40 -0500289 // Ends and submits the current command buffer to the queue and then creates a new command
halcanary9d524f22016-03-29 09:03:52 -0700290 // buffer and begins it. If sync is set to kForce_SyncQueue, the function will wait for all
Greg Daniela5cb7812017-06-16 09:45:32 -0400291 // work in the queue to finish before returning. If this GrVkGpu object has any semaphores in
292 // fSemaphoreToSignal, we will add those signal semaphores to the submission of this command
293 // buffer. If this GrVkGpu object has any semaphores in fSemaphoresToWaitOn, we will add those
294 // wait semaphores to the submission of this command buffer.
Greg Danielfe159622020-04-10 17:43:51 +0000295 bool submitCommandBuffer(SyncQueue sync);
Greg Daniel164a9f02016-02-22 09:56:40 -0500296
Greg Daniel46cfbc62019-06-07 11:43:30 -0400297 void copySurfaceAsCopyImage(GrSurface* dst, GrSurface* src, GrVkImage* dstImage,
298 GrVkImage* srcImage, const SkIRect& srcRect,
Greg Daniel164a9f02016-02-22 09:56:40 -0500299 const SkIPoint& dstPoint);
300
Greg Daniel46cfbc62019-06-07 11:43:30 -0400301 void copySurfaceAsBlit(GrSurface* dst, GrSurface* src, GrVkImage* dstImage, GrVkImage* srcImage,
302 const SkIRect& srcRect, const SkIPoint& dstPoint);
egdaniel17b89252016-04-05 07:23:38 -0700303
Greg Daniel46cfbc62019-06-07 11:43:30 -0400304 void copySurfaceAsResolve(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
egdaniel4bcd62e2016-08-31 07:37:31 -0700305 const SkIPoint& dstPoint);
306
jvanverth900bd4a2016-04-29 13:53:12 -0700307 // helpers for onCreateTexture and writeTexturePixels
Brian Salomona9b04b92018-06-01 15:04:28 -0400308 bool uploadTexDataLinear(GrVkTexture* tex, int left, int top, int width, int height,
309 GrColorType colorType, const void* data, size_t rowBytes);
310 bool uploadTexDataOptimal(GrVkTexture* tex, int left, int top, int width, int height,
311 GrColorType colorType, const GrMipLevel texels[], int mipLevelCount);
Greg Daniel01f278c2020-06-12 16:58:17 -0400312 bool uploadTexDataCompressed(GrVkTexture* tex, SkImage::CompressionType compression,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400313 VkFormat vkFormat, SkISize dimensions, GrMipmapped mipMapped,
Greg Daniel01f278c2020-06-12 16:58:17 -0400314 const void* data, size_t dataSize);
Brian Salomon1fabd512018-02-09 09:54:25 -0500315 void resolveImage(GrSurface* dst, GrVkRenderTarget* src, const SkIRect& srcRect,
316 const SkIPoint& dstPoint);
egdaniel4bcd62e2016-08-31 07:37:31 -0700317
Brian Salomon85c3d682019-11-04 15:04:54 -0500318 bool createVkImageForBackendSurface(VkFormat,
Robert Phillips4277f012020-01-21 14:28:34 -0500319 SkISize dimensions,
Robert Phillipsb8757352020-01-21 13:05:25 -0500320 GrTexturable,
Robert Phillips0d7e2f12019-12-18 13:01:04 -0500321 GrRenderable,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400322 GrMipmapped,
Brian Salomon85c3d682019-11-04 15:04:54 -0500323 GrVkImageInfo*,
Greg Daniel16032b32020-05-06 15:31:10 -0400324 GrProtected);
Brian Salomon52e943a2018-03-13 09:32:39 -0400325
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400326 sk_sp<const GrVkInterface> fInterface;
327 sk_sp<GrVkMemoryAllocator> fMemoryAllocator;
328 sk_sp<GrVkCaps> fVkCaps;
Greg Daniele643da62019-11-05 12:36:42 -0500329 bool fDeviceIsLost = false;
jvanverth633b3562016-03-23 11:01:22 -0700330
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400331 VkPhysicalDevice fPhysicalDevice;
332 VkDevice fDevice;
333 VkQueue fQueue; // Must be Graphics queue
334 uint32_t fQueueIndex;
jvanverth633b3562016-03-23 11:01:22 -0700335
336 // Created by GrVkGpu
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400337 GrVkResourceProvider fResourceProvider;
Greg Daniela58db7f2020-07-15 09:17:59 -0400338 GrStagingBufferManager fStagingBufferManager;
Greg Daniel164a9f02016-02-22 09:56:40 -0500339
Greg Danield922f332020-04-27 11:21:36 -0400340 GrVkCommandPool* fMainCmdPool;
Ethan Nicholas8e265a72018-12-12 16:22:40 -0500341 // just a raw pointer; object's lifespan is managed by fCmdPool
Greg Danield922f332020-04-27 11:21:36 -0400342 GrVkPrimaryCommandBuffer* fMainCmdBuffer;
343
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400344 SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToWaitOn;
345 SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToSignal;
Greg Daniel6be35232017-03-01 17:01:09 -0500346
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400347 SkTArray<std::unique_ptr<SkDrawable::GpuDrawHandler>> fDrawables;
Greg Daniel6be35232017-03-01 17:01:09 -0500348
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400349 VkPhysicalDeviceProperties fPhysDevProps;
350 VkPhysicalDeviceMemoryProperties fPhysDevMemProps;
351
Ethan Nicholas941e7e22016-12-12 15:33:30 -0500352 // compiler used for compiling sksl into spirv. We only want to create the compiler once since
353 // there is significant overhead to the first compile of any compiler.
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400354 SkSL::Compiler* fCompiler;
Greg Daniel164a9f02016-02-22 09:56:40 -0500355
Greg Daniel8606cf82017-05-08 16:17:53 -0400356 // We need a bool to track whether or not we've already disconnected all the gpu resources from
357 // vulkan context.
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400358 bool fDisconnected;
Greg Daniel8606cf82017-05-08 16:17:53 -0400359
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400360 GrProtected fProtectedContext;
361
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400362 std::unique_ptr<GrVkOpsRenderPass> fCachedOpsRenderPass;
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400363
Greg Daniel164a9f02016-02-22 09:56:40 -0500364 typedef GrGpu INHERITED;
365};
366
367#endif