1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2015 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#ifndef GrVkGpu_DEFINED 9cb93a386Sopenharmony_ci#define GrVkGpu_DEFINED 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "include/gpu/vk/GrVkBackendContext.h" 12cb93a386Sopenharmony_ci#include "include/gpu/vk/GrVkTypes.h" 13cb93a386Sopenharmony_ci#include "src/gpu/GrGpu.h" 14cb93a386Sopenharmony_ci#include "src/gpu/GrStagingBufferManager.h" 15cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkCaps.h" 16cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkMSAALoadManager.h" 17cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkMemory.h" 18cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkMemoryReclaimer.h" 19cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkResourceProvider.h" 20cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkSemaphore.h" 21cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkUtil.h" 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_ciclass GrDirectContext; 24cb93a386Sopenharmony_ciclass GrPipeline; 25cb93a386Sopenharmony_ci 26cb93a386Sopenharmony_ciclass GrVkBuffer; 27cb93a386Sopenharmony_ciclass GrVkCommandPool; 28cb93a386Sopenharmony_ciclass GrVkFramebuffer; 29cb93a386Sopenharmony_ciclass GrVkMemoryAllocator; 30cb93a386Sopenharmony_ciclass GrVkPipeline; 31cb93a386Sopenharmony_ciclass GrVkPipelineState; 32cb93a386Sopenharmony_ciclass GrVkPrimaryCommandBuffer; 33cb93a386Sopenharmony_ciclass GrVkOpsRenderPass; 34cb93a386Sopenharmony_ciclass GrVkRenderPass; 35cb93a386Sopenharmony_ciclass GrVkSecondaryCommandBuffer; 36cb93a386Sopenharmony_ciclass GrVkTexture; 37cb93a386Sopenharmony_cistruct GrVkInterface; 38cb93a386Sopenharmony_ci 39cb93a386Sopenharmony_ciclass GrVkGpu : public GrGpu { 40cb93a386Sopenharmony_cipublic: 41cb93a386Sopenharmony_ci static sk_sp<GrGpu> Make(const GrVkBackendContext&, const GrContextOptions&, GrDirectContext*); 42cb93a386Sopenharmony_ci 43cb93a386Sopenharmony_ci ~GrVkGpu() override; 44cb93a386Sopenharmony_ci 45cb93a386Sopenharmony_ci void disconnect(DisconnectType) override; 46cb93a386Sopenharmony_ci bool disconnected() const { return fDisconnected; } 47cb93a386Sopenharmony_ci 48cb93a386Sopenharmony_ci void releaseUnlockedBackendObjects() override { 49cb93a386Sopenharmony_ci fResourceProvider.releaseUnlockedBackendObjects(); 50cb93a386Sopenharmony_ci } 51cb93a386Sopenharmony_ci 52cb93a386Sopenharmony_ci GrThreadSafePipelineBuilder* pipelineBuilder() override; 53cb93a386Sopenharmony_ci sk_sp<GrThreadSafePipelineBuilder> refPipelineBuilder() override; 54cb93a386Sopenharmony_ci 55cb93a386Sopenharmony_ci const GrVkInterface* vkInterface() const { return fInterface.get(); } 56cb93a386Sopenharmony_ci const GrVkCaps& vkCaps() const { return *fVkCaps; } 57cb93a386Sopenharmony_ci 58cb93a386Sopenharmony_ci GrStagingBufferManager* stagingBufferManager() override { return &fStagingBufferManager; } 59cb93a386Sopenharmony_ci void takeOwnershipOfBuffer(sk_sp<GrGpuBuffer>) override; 60cb93a386Sopenharmony_ci 61cb93a386Sopenharmony_ci bool isDeviceLost() const override { return fDeviceIsLost; } 62cb93a386Sopenharmony_ci 63cb93a386Sopenharmony_ci GrVkMemoryAllocator* memoryAllocator() const { return fMemoryAllocator.get(); } 64cb93a386Sopenharmony_ci GrVkMemoryAllocator* memoryAllocatorCacheImage() const { return fMemoryAllocatorCacheImage.get(); } 65cb93a386Sopenharmony_ci 66cb93a386Sopenharmony_ci VkPhysicalDevice physicalDevice() const { return fPhysicalDevice; } 67cb93a386Sopenharmony_ci VkDevice device() const { return fDevice; } 68cb93a386Sopenharmony_ci VkQueue queue() const { return fQueue; } 69cb93a386Sopenharmony_ci uint32_t queueIndex() const { return fQueueIndex; } 70cb93a386Sopenharmony_ci GrVkCommandPool* cmdPool() const { return fMainCmdPool; } 71cb93a386Sopenharmony_ci const VkPhysicalDeviceProperties& physicalDeviceProperties() const { 72cb93a386Sopenharmony_ci return fPhysDevProps; 73cb93a386Sopenharmony_ci } 74cb93a386Sopenharmony_ci const VkPhysicalDeviceMemoryProperties& physicalDeviceMemoryProperties() const { 75cb93a386Sopenharmony_ci return fPhysDevMemProps; 76cb93a386Sopenharmony_ci } 77cb93a386Sopenharmony_ci bool protectedContext() const { return fProtectedContext == GrProtected::kYes; } 78cb93a386Sopenharmony_ci 79cb93a386Sopenharmony_ci GrVkResourceProvider& resourceProvider() { return fResourceProvider; } 80cb93a386Sopenharmony_ci 81cb93a386Sopenharmony_ci GrVkPrimaryCommandBuffer* currentCommandBuffer() const { return fMainCmdBuffer; } 82cb93a386Sopenharmony_ci 83cb93a386Sopenharmony_ci void xferBarrier(GrRenderTarget*, GrXferBarrierType) override; 84cb93a386Sopenharmony_ci 85cb93a386Sopenharmony_ci bool setBackendTextureState(const GrBackendTexture&, 86cb93a386Sopenharmony_ci const GrBackendSurfaceMutableState&, 87cb93a386Sopenharmony_ci GrBackendSurfaceMutableState* previousState, 88cb93a386Sopenharmony_ci sk_sp<GrRefCntedCallback> finishedCallback) override; 89cb93a386Sopenharmony_ci 90cb93a386Sopenharmony_ci bool setBackendRenderTargetState(const GrBackendRenderTarget&, 91cb93a386Sopenharmony_ci const GrBackendSurfaceMutableState&, 92cb93a386Sopenharmony_ci GrBackendSurfaceMutableState* previousState, 93cb93a386Sopenharmony_ci sk_sp<GrRefCntedCallback> finishedCallback) override; 94cb93a386Sopenharmony_ci 95cb93a386Sopenharmony_ci void deleteBackendTexture(const GrBackendTexture&) override; 96cb93a386Sopenharmony_ci 97cb93a386Sopenharmony_ci bool compile(const GrProgramDesc&, const GrProgramInfo&) override; 98cb93a386Sopenharmony_ci 99cb93a386Sopenharmony_ci static void AsyncFreeVMAMemoryBetweenFrames(std::function<bool(void)> nextFrameHasArrived); 100cb93a386Sopenharmony_ci 101cb93a386Sopenharmony_ci#if GR_TEST_UTILS 102cb93a386Sopenharmony_ci bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; 103cb93a386Sopenharmony_ci 104cb93a386Sopenharmony_ci GrBackendRenderTarget createTestingOnlyBackendRenderTarget(SkISize dimensions, 105cb93a386Sopenharmony_ci GrColorType, 106cb93a386Sopenharmony_ci int sampleCnt, 107cb93a386Sopenharmony_ci GrProtected) override; 108cb93a386Sopenharmony_ci void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; 109cb93a386Sopenharmony_ci 110cb93a386Sopenharmony_ci void resetShaderCacheForTesting() const override { 111cb93a386Sopenharmony_ci fResourceProvider.resetShaderCacheForTesting(); 112cb93a386Sopenharmony_ci } 113cb93a386Sopenharmony_ci#endif 114cb93a386Sopenharmony_ci 115cb93a386Sopenharmony_ci sk_sp<GrAttachment> makeStencilAttachment(const GrBackendFormat& /*colorFormat*/, 116cb93a386Sopenharmony_ci SkISize dimensions, int numStencilSamples) override; 117cb93a386Sopenharmony_ci 118cb93a386Sopenharmony_ci GrBackendFormat getPreferredStencilFormat(const GrBackendFormat&) override { 119cb93a386Sopenharmony_ci return GrBackendFormat::MakeVk(this->vkCaps().preferredStencilFormat()); 120cb93a386Sopenharmony_ci } 121cb93a386Sopenharmony_ci 122cb93a386Sopenharmony_ci sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions, 123cb93a386Sopenharmony_ci const GrBackendFormat& format, 124cb93a386Sopenharmony_ci int numSamples, 125cb93a386Sopenharmony_ci GrProtected isProtected, 126cb93a386Sopenharmony_ci GrMemoryless isMemoryless) override; 127cb93a386Sopenharmony_ci 128cb93a386Sopenharmony_ci void addBufferMemoryBarrier(const GrManagedResource*, 129cb93a386Sopenharmony_ci VkPipelineStageFlags srcStageMask, 130cb93a386Sopenharmony_ci VkPipelineStageFlags dstStageMask, 131cb93a386Sopenharmony_ci bool byRegion, 132cb93a386Sopenharmony_ci VkBufferMemoryBarrier* barrier) const; 133cb93a386Sopenharmony_ci void addBufferMemoryBarrier(VkPipelineStageFlags srcStageMask, 134cb93a386Sopenharmony_ci VkPipelineStageFlags dstStageMask, 135cb93a386Sopenharmony_ci bool byRegion, 136cb93a386Sopenharmony_ci VkBufferMemoryBarrier* barrier) const; 137cb93a386Sopenharmony_ci void addImageMemoryBarrier(const GrManagedResource*, 138cb93a386Sopenharmony_ci VkPipelineStageFlags srcStageMask, 139cb93a386Sopenharmony_ci VkPipelineStageFlags dstStageMask, 140cb93a386Sopenharmony_ci bool byRegion, 141cb93a386Sopenharmony_ci VkImageMemoryBarrier* barrier) const; 142cb93a386Sopenharmony_ci 143cb93a386Sopenharmony_ci bool loadMSAAFromResolve(GrVkCommandBuffer* commandBuffer, 144cb93a386Sopenharmony_ci const GrVkRenderPass& renderPass, 145cb93a386Sopenharmony_ci GrAttachment* dst, 146cb93a386Sopenharmony_ci GrVkImage* src, 147cb93a386Sopenharmony_ci const SkIRect& srcRect); 148cb93a386Sopenharmony_ci 149cb93a386Sopenharmony_ci bool onRegenerateMipMapLevels(GrTexture* tex) override; 150cb93a386Sopenharmony_ci 151cb93a386Sopenharmony_ci void onResolveRenderTarget(GrRenderTarget* target, const SkIRect& resolveRect) override; 152cb93a386Sopenharmony_ci 153cb93a386Sopenharmony_ci void submitSecondaryCommandBuffer(std::unique_ptr<GrVkSecondaryCommandBuffer>); 154cb93a386Sopenharmony_ci 155cb93a386Sopenharmony_ci void submit(GrOpsRenderPass*) override; 156cb93a386Sopenharmony_ci 157cb93a386Sopenharmony_ci GrFence SK_WARN_UNUSED_RESULT insertFence() override; 158cb93a386Sopenharmony_ci bool waitFence(GrFence) override; 159cb93a386Sopenharmony_ci void deleteFence(GrFence) const override; 160cb93a386Sopenharmony_ci 161cb93a386Sopenharmony_ci std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override; 162cb93a386Sopenharmony_ci std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore&, 163cb93a386Sopenharmony_ci GrSemaphoreWrapType, 164cb93a386Sopenharmony_ci GrWrapOwnership) override; 165cb93a386Sopenharmony_ci void insertSemaphore(GrSemaphore* semaphore) override; 166cb93a386Sopenharmony_ci void waitSemaphore(GrSemaphore* semaphore) override; 167cb93a386Sopenharmony_ci 168cb93a386Sopenharmony_ci // These match the definitions in SkDrawable, from whence they came 169cb93a386Sopenharmony_ci typedef void* SubmitContext; 170cb93a386Sopenharmony_ci typedef void (*SubmitProc)(SubmitContext submitContext); 171cb93a386Sopenharmony_ci 172cb93a386Sopenharmony_ci // Adds an SkDrawable::GpuDrawHandler that we will delete the next time we submit the primary 173cb93a386Sopenharmony_ci // command buffer to the gpu. 174cb93a386Sopenharmony_ci void addDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable); 175cb93a386Sopenharmony_ci 176cb93a386Sopenharmony_ci void checkFinishProcs() override { fResourceProvider.checkCommandBuffers(); } 177cb93a386Sopenharmony_ci void finishOutstandingGpuWork() override; 178cb93a386Sopenharmony_ci 179cb93a386Sopenharmony_ci std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override; 180cb93a386Sopenharmony_ci 181cb93a386Sopenharmony_ci void copyBuffer(sk_sp<GrGpuBuffer> srcBuffer, sk_sp<GrGpuBuffer> dstBuffer, 182cb93a386Sopenharmony_ci VkDeviceSize srcOffset, VkDeviceSize dstOffset, VkDeviceSize size); 183cb93a386Sopenharmony_ci bool updateBuffer(sk_sp<GrVkBuffer> buffer, const void* src, VkDeviceSize offset, 184cb93a386Sopenharmony_ci VkDeviceSize size); 185cb93a386Sopenharmony_ci 186cb93a386Sopenharmony_ci enum PersistentCacheKeyType : uint32_t { 187cb93a386Sopenharmony_ci kShader_PersistentCacheKeyType = 0, 188cb93a386Sopenharmony_ci kPipelineCache_PersistentCacheKeyType = 1, 189cb93a386Sopenharmony_ci }; 190cb93a386Sopenharmony_ci 191cb93a386Sopenharmony_ci void storeVkPipelineCacheData() override; 192cb93a386Sopenharmony_ci 193cb93a386Sopenharmony_ci bool beginRenderPass(const GrVkRenderPass*, 194cb93a386Sopenharmony_ci sk_sp<const GrVkFramebuffer>, 195cb93a386Sopenharmony_ci const VkClearValue* colorClear, 196cb93a386Sopenharmony_ci const GrSurface*, 197cb93a386Sopenharmony_ci const SkIRect& renderPassBounds, 198cb93a386Sopenharmony_ci bool forSecondaryCB); 199cb93a386Sopenharmony_ci void endRenderPass(GrRenderTarget* target, GrSurfaceOrigin origin, const SkIRect& bounds); 200cb93a386Sopenharmony_ci 201cb93a386Sopenharmony_ci // Returns true if VkResult indicates success and also checks for device lost or OOM. Every 202cb93a386Sopenharmony_ci // Vulkan call (and GrVkMemoryAllocator call that returns VkResult) made on behalf of the 203cb93a386Sopenharmony_ci // GrVkGpu should be processed by this function so that we respond to OOMs and lost devices. 204cb93a386Sopenharmony_ci bool checkVkResult(VkResult); 205cb93a386Sopenharmony_ci 206cb93a386Sopenharmony_ci std::array<int, 2> GetHpsDimension(const SkBlurArg& blurArg) const override; 207cb93a386Sopenharmony_ci 208cb93a386Sopenharmony_ci void vmaDefragment() override { fMemoryAllocatorCacheImage->vmaDefragment(); } 209cb93a386Sopenharmony_ci void dumpVmaStats(SkString *out) override; 210cb93a386Sopenharmony_ci 211cb93a386Sopenharmony_ci // OH ISSUE: asyn memory reclaimer 212cb93a386Sopenharmony_ci void setGpuMemoryAsyncReclaimerSwitch(bool enabled) override; 213cb93a386Sopenharmony_ci void flushGpuMemoryInWaitQueue() override; 214cb93a386Sopenharmony_ci GrVkMemoryReclaimer* memoryReclaimer() const { return fMemoryReclaimer.get(); } 215cb93a386Sopenharmony_ci 216cb93a386Sopenharmony_ci#ifdef SKIA_DFX_FOR_OHOS 217cb93a386Sopenharmony_ci void addAllocImageBytes(size_t bytes); 218cb93a386Sopenharmony_ci void removeAllocImageBytes(size_t bytes); 219cb93a386Sopenharmony_ci void addAllocBufferBytes(size_t bytes); 220cb93a386Sopenharmony_ci void removeAllocBufferBytes(size_t bytes); 221cb93a386Sopenharmony_ci#endif 222cb93a386Sopenharmony_ci 223cb93a386Sopenharmony_ciprivate: 224cb93a386Sopenharmony_ci enum SyncQueue { 225cb93a386Sopenharmony_ci kForce_SyncQueue, 226cb93a386Sopenharmony_ci kSkip_SyncQueue 227cb93a386Sopenharmony_ci }; 228cb93a386Sopenharmony_ci 229cb93a386Sopenharmony_ci GrVkGpu(GrDirectContext*, const GrVkBackendContext&, const sk_sp<GrVkCaps> caps, 230cb93a386Sopenharmony_ci sk_sp<const GrVkInterface>, uint32_t instanceVersion, uint32_t physicalDeviceVersion, 231cb93a386Sopenharmony_ci sk_sp<GrVkMemoryAllocator>, sk_sp<GrVkMemoryAllocator>); 232cb93a386Sopenharmony_ci 233cb93a386Sopenharmony_ci void destroyResources(); 234cb93a386Sopenharmony_ci 235cb93a386Sopenharmony_ci GrBackendTexture onCreateBackendTexture(SkISize dimensions, 236cb93a386Sopenharmony_ci const GrBackendFormat&, 237cb93a386Sopenharmony_ci GrRenderable, 238cb93a386Sopenharmony_ci GrMipmapped, 239cb93a386Sopenharmony_ci GrProtected) override; 240cb93a386Sopenharmony_ci GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions, 241cb93a386Sopenharmony_ci const GrBackendFormat&, 242cb93a386Sopenharmony_ci GrMipmapped, 243cb93a386Sopenharmony_ci GrProtected) override; 244cb93a386Sopenharmony_ci 245cb93a386Sopenharmony_ci bool onClearBackendTexture(const GrBackendTexture&, 246cb93a386Sopenharmony_ci sk_sp<GrRefCntedCallback> finishedCallback, 247cb93a386Sopenharmony_ci std::array<float, 4> color) override; 248cb93a386Sopenharmony_ci 249cb93a386Sopenharmony_ci bool onUpdateCompressedBackendTexture(const GrBackendTexture&, 250cb93a386Sopenharmony_ci sk_sp<GrRefCntedCallback> finishedCallback, 251cb93a386Sopenharmony_ci const void* data, 252cb93a386Sopenharmony_ci size_t length) override; 253cb93a386Sopenharmony_ci 254cb93a386Sopenharmony_ci bool setBackendSurfaceState(GrVkImageInfo info, 255cb93a386Sopenharmony_ci sk_sp<GrBackendSurfaceMutableStateImpl> currentState, 256cb93a386Sopenharmony_ci SkISize dimensions, 257cb93a386Sopenharmony_ci const GrVkSharedImageInfo& newInfo, 258cb93a386Sopenharmony_ci GrBackendSurfaceMutableState* previousState, 259cb93a386Sopenharmony_ci sk_sp<GrRefCntedCallback> finishedCallback); 260cb93a386Sopenharmony_ci 261cb93a386Sopenharmony_ci sk_sp<GrTexture> onCreateTexture(SkISize, 262cb93a386Sopenharmony_ci const GrBackendFormat&, 263cb93a386Sopenharmony_ci GrRenderable, 264cb93a386Sopenharmony_ci int renderTargetSampleCnt, 265cb93a386Sopenharmony_ci SkBudgeted, 266cb93a386Sopenharmony_ci GrProtected, 267cb93a386Sopenharmony_ci int mipLevelCount, 268cb93a386Sopenharmony_ci uint32_t levelClearMask) override; 269cb93a386Sopenharmony_ci sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions, 270cb93a386Sopenharmony_ci const GrBackendFormat&, 271cb93a386Sopenharmony_ci SkBudgeted, 272cb93a386Sopenharmony_ci GrMipmapped, 273cb93a386Sopenharmony_ci GrProtected, 274cb93a386Sopenharmony_ci const void* data, size_t dataSize) override; 275cb93a386Sopenharmony_ci sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions, 276cb93a386Sopenharmony_ci const GrBackendFormat&, 277cb93a386Sopenharmony_ci SkBudgeted, 278cb93a386Sopenharmony_ci GrMipmapped, 279cb93a386Sopenharmony_ci GrProtected, 280cb93a386Sopenharmony_ci OH_NativeBuffer* nativeBuffer, 281cb93a386Sopenharmony_ci size_t bufferSize) override; 282cb93a386Sopenharmony_ci 283cb93a386Sopenharmony_ci sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, 284cb93a386Sopenharmony_ci GrWrapOwnership, 285cb93a386Sopenharmony_ci GrWrapCacheable, 286cb93a386Sopenharmony_ci GrIOType) override; 287cb93a386Sopenharmony_ci sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&, 288cb93a386Sopenharmony_ci GrWrapOwnership, 289cb93a386Sopenharmony_ci GrWrapCacheable) override; 290cb93a386Sopenharmony_ci sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, 291cb93a386Sopenharmony_ci int sampleCnt, 292cb93a386Sopenharmony_ci GrWrapOwnership, 293cb93a386Sopenharmony_ci GrWrapCacheable) override; 294cb93a386Sopenharmony_ci sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; 295cb93a386Sopenharmony_ci 296cb93a386Sopenharmony_ci sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&, 297cb93a386Sopenharmony_ci const GrVkDrawableInfo&) override; 298cb93a386Sopenharmony_ci 299cb93a386Sopenharmony_ci sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern, 300cb93a386Sopenharmony_ci const void* data) override; 301cb93a386Sopenharmony_ci 302cb93a386Sopenharmony_ci bool onReadPixels(GrSurface*, 303cb93a386Sopenharmony_ci SkIRect, 304cb93a386Sopenharmony_ci GrColorType surfaceColorType, 305cb93a386Sopenharmony_ci GrColorType dstColorType, 306cb93a386Sopenharmony_ci void* buffer, 307cb93a386Sopenharmony_ci size_t rowBytes) override; 308cb93a386Sopenharmony_ci 309cb93a386Sopenharmony_ci bool onWritePixels(GrSurface*, 310cb93a386Sopenharmony_ci SkIRect, 311cb93a386Sopenharmony_ci GrColorType surfaceColorType, 312cb93a386Sopenharmony_ci GrColorType srcColorType, 313cb93a386Sopenharmony_ci const GrMipLevel[], 314cb93a386Sopenharmony_ci int mipLevelCount, 315cb93a386Sopenharmony_ci bool prepForTexSampling) override; 316cb93a386Sopenharmony_ci 317cb93a386Sopenharmony_ci bool onTransferPixelsTo(GrTexture*, 318cb93a386Sopenharmony_ci SkIRect, 319cb93a386Sopenharmony_ci GrColorType textureColorType, 320cb93a386Sopenharmony_ci GrColorType bufferColorType, 321cb93a386Sopenharmony_ci sk_sp<GrGpuBuffer>, 322cb93a386Sopenharmony_ci size_t offset, 323cb93a386Sopenharmony_ci size_t rowBytes) override; 324cb93a386Sopenharmony_ci 325cb93a386Sopenharmony_ci bool onTransferPixelsFrom(GrSurface*, 326cb93a386Sopenharmony_ci SkIRect, 327cb93a386Sopenharmony_ci GrColorType surfaceColorType, 328cb93a386Sopenharmony_ci GrColorType bufferColorType, 329cb93a386Sopenharmony_ci sk_sp<GrGpuBuffer>, 330cb93a386Sopenharmony_ci size_t offset) override; 331cb93a386Sopenharmony_ci 332cb93a386Sopenharmony_ci bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, 333cb93a386Sopenharmony_ci const SkIPoint& dstPoint) override; 334cb93a386Sopenharmony_ci 335cb93a386Sopenharmony_ci void addFinishedProc(GrGpuFinishedProc finishedProc, 336cb93a386Sopenharmony_ci GrGpuFinishedContext finishedContext) override; 337cb93a386Sopenharmony_ci 338cb93a386Sopenharmony_ci void addFinishedCallback(sk_sp<GrRefCntedCallback> finishedCallback); 339cb93a386Sopenharmony_ci 340cb93a386Sopenharmony_ci GrOpsRenderPass* onGetOpsRenderPass(GrRenderTarget*, 341cb93a386Sopenharmony_ci bool useMSAASurface, 342cb93a386Sopenharmony_ci GrAttachment* stencil, 343cb93a386Sopenharmony_ci GrSurfaceOrigin, 344cb93a386Sopenharmony_ci const SkIRect&, 345cb93a386Sopenharmony_ci const GrOpsRenderPass::LoadAndStoreInfo&, 346cb93a386Sopenharmony_ci const GrOpsRenderPass::StencilLoadAndStoreInfo&, 347cb93a386Sopenharmony_ci const SkTArray<GrSurfaceProxy*, true>& sampledProxies, 348cb93a386Sopenharmony_ci GrXferBarrierFlags renderPassXferBarriers) override; 349cb93a386Sopenharmony_ci 350cb93a386Sopenharmony_ci void prepareSurfacesForBackendAccessAndStateUpdates( 351cb93a386Sopenharmony_ci SkSpan<GrSurfaceProxy*> proxies, 352cb93a386Sopenharmony_ci SkSurface::BackendSurfaceAccess access, 353cb93a386Sopenharmony_ci const GrBackendSurfaceMutableState* newState) override; 354cb93a386Sopenharmony_ci 355cb93a386Sopenharmony_ci bool onSubmitToGpu(bool syncCpu) override; 356cb93a386Sopenharmony_ci 357cb93a386Sopenharmony_ci void onReportSubmitHistograms() override; 358cb93a386Sopenharmony_ci 359cb93a386Sopenharmony_ci // Ends and submits the current command buffer to the queue and then creates a new command 360cb93a386Sopenharmony_ci // buffer and begins it. If sync is set to kForce_SyncQueue, the function will wait for all 361cb93a386Sopenharmony_ci // work in the queue to finish before returning. If this GrVkGpu object has any semaphores in 362cb93a386Sopenharmony_ci // fSemaphoreToSignal, we will add those signal semaphores to the submission of this command 363cb93a386Sopenharmony_ci // buffer. If this GrVkGpu object has any semaphores in fSemaphoresToWaitOn, we will add those 364cb93a386Sopenharmony_ci // wait semaphores to the submission of this command buffer. 365cb93a386Sopenharmony_ci bool submitCommandBuffer(SyncQueue sync); 366cb93a386Sopenharmony_ci 367cb93a386Sopenharmony_ci void copySurfaceAsCopyImage(GrSurface* dst, 368cb93a386Sopenharmony_ci GrSurface* src, 369cb93a386Sopenharmony_ci GrVkImage* dstImage, 370cb93a386Sopenharmony_ci GrVkImage* srcImage, 371cb93a386Sopenharmony_ci const SkIRect& srcRect, 372cb93a386Sopenharmony_ci const SkIPoint& dstPoint); 373cb93a386Sopenharmony_ci 374cb93a386Sopenharmony_ci void copySurfaceAsBlit(GrSurface* dst, 375cb93a386Sopenharmony_ci GrSurface* src, 376cb93a386Sopenharmony_ci GrVkImage* dstImage, 377cb93a386Sopenharmony_ci GrVkImage* srcImage, 378cb93a386Sopenharmony_ci const SkIRect& srcRect, 379cb93a386Sopenharmony_ci const SkIPoint& dstPoint); 380cb93a386Sopenharmony_ci 381cb93a386Sopenharmony_ci void copySurfaceAsResolve(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, 382cb93a386Sopenharmony_ci const SkIPoint& dstPoint); 383cb93a386Sopenharmony_ci 384cb93a386Sopenharmony_ci // helpers for onCreateTexture and writeTexturePixels 385cb93a386Sopenharmony_ci bool uploadTexDataLinear(GrVkImage* tex, 386cb93a386Sopenharmony_ci SkIRect rect, 387cb93a386Sopenharmony_ci GrColorType colorType, 388cb93a386Sopenharmony_ci const void* data, 389cb93a386Sopenharmony_ci size_t rowBytes); 390cb93a386Sopenharmony_ci bool uploadTexDataOptimal(GrVkImage* tex, 391cb93a386Sopenharmony_ci SkIRect rect, 392cb93a386Sopenharmony_ci GrColorType colorType, 393cb93a386Sopenharmony_ci const GrMipLevel texels[], 394cb93a386Sopenharmony_ci int mipLevelCount); 395cb93a386Sopenharmony_ci bool uploadTexDataCompressed(GrVkImage* tex, SkImage::CompressionType compression, 396cb93a386Sopenharmony_ci VkFormat vkFormat, SkISize dimensions, GrMipmapped mipMapped, 397cb93a386Sopenharmony_ci const void* data, size_t dataSize); 398cb93a386Sopenharmony_ci bool uploadTexDataCompressed(GrVkImage* tex, SkImage::CompressionType compression, 399cb93a386Sopenharmony_ci VkFormat vkFormat, SkISize dimensions, GrMipmapped mipMapped, 400cb93a386Sopenharmony_ci OH_NativeBuffer* nativeBuffer, size_t bufferSize); 401cb93a386Sopenharmony_ci 402cb93a386Sopenharmony_ci void resolveImage(GrSurface* dst, GrVkRenderTarget* src, const SkIRect& srcRect, 403cb93a386Sopenharmony_ci const SkIPoint& dstPoint); 404cb93a386Sopenharmony_ci 405cb93a386Sopenharmony_ci bool createVkImageForBackendSurface(VkFormat, 406cb93a386Sopenharmony_ci SkISize dimensions, 407cb93a386Sopenharmony_ci int sampleCnt, 408cb93a386Sopenharmony_ci GrTexturable, 409cb93a386Sopenharmony_ci GrRenderable, 410cb93a386Sopenharmony_ci GrMipmapped, 411cb93a386Sopenharmony_ci GrVkImageInfo*, 412cb93a386Sopenharmony_ci GrProtected); 413cb93a386Sopenharmony_ci 414cb93a386Sopenharmony_ci sk_sp<const GrVkInterface> fInterface; 415cb93a386Sopenharmony_ci sk_sp<GrVkMemoryAllocator> fMemoryAllocator; 416cb93a386Sopenharmony_ci sk_sp<GrVkMemoryAllocator> fMemoryAllocatorCacheImage; 417cb93a386Sopenharmony_ci sk_sp<GrVkCaps> fVkCaps; 418cb93a386Sopenharmony_ci bool fDeviceIsLost = false; 419cb93a386Sopenharmony_ci 420cb93a386Sopenharmony_ci VkPhysicalDevice fPhysicalDevice; 421cb93a386Sopenharmony_ci VkDevice fDevice; 422cb93a386Sopenharmony_ci VkQueue fQueue; // Must be Graphics queue 423cb93a386Sopenharmony_ci uint32_t fQueueIndex; 424cb93a386Sopenharmony_ci 425cb93a386Sopenharmony_ci // Created by GrVkGpu 426cb93a386Sopenharmony_ci GrVkResourceProvider fResourceProvider; 427cb93a386Sopenharmony_ci GrStagingBufferManager fStagingBufferManager; 428cb93a386Sopenharmony_ci 429cb93a386Sopenharmony_ci GrVkMSAALoadManager fMSAALoadManager; 430cb93a386Sopenharmony_ci 431cb93a386Sopenharmony_ci GrVkCommandPool* fMainCmdPool; 432cb93a386Sopenharmony_ci // just a raw pointer; object's lifespan is managed by fCmdPool 433cb93a386Sopenharmony_ci GrVkPrimaryCommandBuffer* fMainCmdBuffer; 434cb93a386Sopenharmony_ci 435cb93a386Sopenharmony_ci SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToWaitOn; 436cb93a386Sopenharmony_ci SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToSignal; 437cb93a386Sopenharmony_ci 438cb93a386Sopenharmony_ci SkTArray<std::unique_ptr<SkDrawable::GpuDrawHandler>> fDrawables; 439cb93a386Sopenharmony_ci 440cb93a386Sopenharmony_ci VkPhysicalDeviceProperties fPhysDevProps; 441cb93a386Sopenharmony_ci VkPhysicalDeviceMemoryProperties fPhysDevMemProps; 442cb93a386Sopenharmony_ci 443cb93a386Sopenharmony_ci // We need a bool to track whether or not we've already disconnected all the gpu resources from 444cb93a386Sopenharmony_ci // vulkan context. 445cb93a386Sopenharmony_ci bool fDisconnected; 446cb93a386Sopenharmony_ci 447cb93a386Sopenharmony_ci GrProtected fProtectedContext; 448cb93a386Sopenharmony_ci 449cb93a386Sopenharmony_ci std::unique_ptr<GrVkOpsRenderPass> fCachedOpsRenderPass; 450cb93a386Sopenharmony_ci 451cb93a386Sopenharmony_ci std::unique_ptr<GrVkMemoryReclaimer> fMemoryReclaimer; 452cb93a386Sopenharmony_ci 453cb93a386Sopenharmony_ci using INHERITED = GrGpu; 454cb93a386Sopenharmony_ci}; 455cb93a386Sopenharmony_ci 456cb93a386Sopenharmony_ci#endif 457