1 /* 2 * Copyright 2016 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 GrVkResourceProvider_DEFINED 9 #define GrVkResourceProvider_DEFINED 10 11 #include "GrVkDescriptorPool.h" 12 #include "GrVkResource.h" 13 #include "GrVkUtil.h" 14 #include "SkTArray.h" 15 16 #include "vulkan/vulkan.h" 17 18 class GrPipeline; 19 class GrPrimitiveProcessor; 20 class GrVkCommandBuffer; 21 class GrVkGpu; 22 class GrVkPipeline; 23 class GrVkRenderPass; 24 class GrVkRenderTarget; 25 26 class GrVkResourceProvider { 27 public: 28 GrVkResourceProvider(GrVkGpu* gpu); 29 ~GrVkResourceProvider(); 30 31 GrVkPipeline* createPipeline(const GrPipeline& pipeline, 32 const GrPrimitiveProcessor& primProc, 33 VkPipelineShaderStageCreateInfo* shaderStageInfo, 34 int shaderStageCount, 35 GrPrimitiveType primitiveType, 36 const GrVkRenderPass& renderPass, 37 VkPipelineLayout layout); 38 39 // Finds or creates a simple render pass that matches the target, increments the refcount, 40 // and returns. 41 const GrVkRenderPass* findOrCreateCompatibleRenderPass(const GrVkRenderTarget& target); 42 43 GrVkCommandBuffer* createCommandBuffer(); 44 void checkCommandBuffers(); 45 46 // Finds or creates a compatible GrVkDescriptorPool for the requested DescriptorTypeCount. 47 // The refcount is incremented and a pointer returned. 48 // TODO: Currently this will just create a descriptor pool without holding onto a ref itself 49 // so we currently do not reuse them. Rquires knowing if another draw is currently using 50 // the GrVkDescriptorPool, the ability to reset pools, and the ability to purge pools out 51 // of our cache of GrVkDescriptorPools. 52 GrVkDescriptorPool* findOrCreateCompatibleDescriptorPool( 53 const GrVkDescriptorPool::DescriptorTypeCounts& typeCounts); 54 55 // Destroy any cached resources. To be called before destroying the VkDevice. 56 // The assumption is that all queues are idle and all command buffers are finished. 57 // For resource tracing to work properly, this should be called after unrefing all other 58 // resource usages. 59 void destroyResources(); 60 61 // Abandon any cached resources. To be used when the context/VkDevice is lost. 62 // For resource tracing to work properly, this should be called after unrefing all other 63 // resource usages. 64 void abandonResources(); 65 66 private: 67 GrVkGpu* fGpu; 68 69 // Array of RenderPasses that only have a single color attachment, optional stencil attachment, 70 // optional resolve attachment, and only one subpass 71 SkSTArray<4, GrVkRenderPass*> fSimpleRenderPasses; 72 73 // Array of CommandBuffers that are currently in flight 74 SkSTArray<4, GrVkCommandBuffer*> fActiveCommandBuffers; 75 }; 76 77 #endif 78