| OLD | NEW |
| (Empty) |
| 1 /* | |
| 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 | |
| 9 #ifndef GrVkProgram_DEFINED | |
| 10 #define GrVkProgram_DEFINED | |
| 11 | |
| 12 #include "GrVkImage.h" | |
| 13 #include "GrVkProgramDesc.h" | |
| 14 #include "GrVkProgramDataManager.h" | |
| 15 #include "glsl/GrGLSLProgramBuilder.h" | |
| 16 | |
| 17 #include "vulkan/vulkan.h" | |
| 18 | |
| 19 class GrPipeline; | |
| 20 class GrVkCommandBuffer; | |
| 21 class GrVkDescriptorPool; | |
| 22 class GrVkGpu; | |
| 23 class GrVkImageView; | |
| 24 class GrVkPipeline; | |
| 25 class GrVkSampler; | |
| 26 class GrVkUniformBuffer; | |
| 27 | |
| 28 class GrVkProgram : public SkRefCnt { | |
| 29 public: | |
| 30 typedef GrGLSLProgramBuilder::BuiltinUniformHandles BuiltinUniformHandles; | |
| 31 | |
| 32 ~GrVkProgram(); | |
| 33 | |
| 34 GrVkPipeline* vkPipeline() const { return fPipeline; } | |
| 35 | |
| 36 void setData(GrVkGpu*, const GrPrimitiveProcessor&, const GrPipeline&); | |
| 37 | |
| 38 void bind(const GrVkGpu* gpu, GrVkCommandBuffer* commandBuffer); | |
| 39 | |
| 40 void addUniformResources(GrVkCommandBuffer&); | |
| 41 | |
| 42 void freeGPUResources(const GrVkGpu* gpu); | |
| 43 | |
| 44 // This releases resources the only a given instance of a GrVkProgram needs
to hold onto and do | |
| 45 // don't need to survive across new uses of the program. | |
| 46 void freeTempResources(const GrVkGpu* gpu); | |
| 47 | |
| 48 void abandonGPUResources(); | |
| 49 | |
| 50 private: | |
| 51 typedef GrVkProgramDataManager::UniformInfoArray UniformInfoArray; | |
| 52 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | |
| 53 | |
| 54 GrVkProgram(GrVkGpu* gpu, | |
| 55 GrVkPipeline* pipeline, | |
| 56 VkPipelineLayout layout, | |
| 57 VkDescriptorSetLayout dsLayout[2], | |
| 58 const BuiltinUniformHandles& builtinUniformHandles, | |
| 59 const UniformInfoArray& uniforms, | |
| 60 uint32_t vertexUniformSize, | |
| 61 uint32_t fragmentUniformSize, | |
| 62 uint32_t numSamplers, | |
| 63 GrGLSLPrimitiveProcessor* geometryProcessor, | |
| 64 GrGLSLXferProcessor* xferProcessor, | |
| 65 const GrGLSLFragProcs& fragmentProcessors); | |
| 66 | |
| 67 // Each pool will manage one type of descriptor. Thus each descriptor set we
use will all be of | |
| 68 // one VkDescriptorType. | |
| 69 struct DescriptorPoolManager { | |
| 70 DescriptorPoolManager(VkDescriptorSetLayout layout, VkDescriptorType typ
e, | |
| 71 uint32_t descCount, GrVkGpu* gpu) | |
| 72 : fDescLayout(layout) | |
| 73 , fDescType(type) | |
| 74 , fCurrentDescriptorSet(0) | |
| 75 , fPool(nullptr) { | |
| 76 SkASSERT(descCount < (SK_MaxU32 >> 2)); | |
| 77 fMaxDescriptorSets = descCount << 2; | |
| 78 this->getNewPool(gpu); | |
| 79 } | |
| 80 | |
| 81 ~DescriptorPoolManager() { | |
| 82 SkASSERT(!fDescLayout); | |
| 83 SkASSERT(!fPool); | |
| 84 } | |
| 85 | |
| 86 void getNewDescriptorSet(GrVkGpu* gpu, VkDescriptorSet* ds); | |
| 87 | |
| 88 void freeGPUResources(const GrVkGpu* gpu); | |
| 89 void abandonGPUResources(); | |
| 90 | |
| 91 VkDescriptorSetLayout fDescLayout; | |
| 92 VkDescriptorType fDescType; | |
| 93 uint32_t fMaxDescriptorSets; | |
| 94 uint32_t fCurrentDescriptorSet; | |
| 95 GrVkDescriptorPool* fPool; | |
| 96 | |
| 97 private: | |
| 98 void getNewPool(GrVkGpu* gpu); | |
| 99 }; | |
| 100 | |
| 101 void writeUniformBuffers(const GrVkGpu* gpu); | |
| 102 | |
| 103 void writeSamplers(GrVkGpu* gpu, const SkTArray<const GrTextureAccess*>& tex
tureBindings); | |
| 104 | |
| 105 | |
| 106 /** | |
| 107 * We use the RT's size and origin to adjust from Skia device space to OpenGL
normalized device | |
| 108 * space and to make device space positions have the correct origin for proce
ssors that require | |
| 109 * them. | |
| 110 */ | |
| 111 struct RenderTargetState { | |
| 112 SkISize fRenderTargetSize; | |
| 113 GrSurfaceOrigin fRenderTargetOrigin; | |
| 114 | |
| 115 RenderTargetState() { this->invalidate(); } | |
| 116 void invalidate() { | |
| 117 fRenderTargetSize.fWidth = -1; | |
| 118 fRenderTargetSize.fHeight = -1; | |
| 119 fRenderTargetOrigin = (GrSurfaceOrigin)-1; | |
| 120 } | |
| 121 | |
| 122 /** | |
| 123 * Gets a vec4 that adjusts the position from Skia device coords to GL's
normalized device | |
| 124 * coords. Assuming the transformed position, pos, is a homogeneous vec3,
the vec, v, is | |
| 125 * applied as such: | |
| 126 * pos.x = dot(v.xy, pos.xz) | |
| 127 * pos.y = dot(v.zw, pos.yz) | |
| 128 */ | |
| 129 void getRTAdjustmentVec(float* destVec) { | |
| 130 destVec[0] = 2.f / fRenderTargetSize.fWidth; | |
| 131 destVec[1] = -1.f; | |
| 132 if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) { | |
| 133 destVec[2] = -2.f / fRenderTargetSize.fHeight; | |
| 134 destVec[3] = 1.f; | |
| 135 } else { | |
| 136 destVec[2] = 2.f / fRenderTargetSize.fHeight; | |
| 137 destVec[3] = -1.f; | |
| 138 } | |
| 139 } | |
| 140 }; | |
| 141 | |
| 142 // Helper for setData() that sets the view matrix and loads the render targe
t height uniform | |
| 143 void setRenderTargetState(const GrPipeline&); | |
| 144 | |
| 145 // GrVkResources | |
| 146 GrVkPipeline* fPipeline; | |
| 147 | |
| 148 // Used for binding DescriptorSets to the command buffer but does not need t
o survive during | |
| 149 // command buffer execution. Thus this is not need to be a GrVkResource. | |
| 150 VkPipelineLayout fPipelineLayout; | |
| 151 | |
| 152 // The DescriptorSets need to survive until the gpu has finished all draws t
hat use them. | |
| 153 // However, they will only be freed by the descriptor pool. Thus by simply k
eeping the | |
| 154 // descriptor pool alive through the draw, the descritor sets will also stay
alive. Thus we do | |
| 155 // not need a GrVkResource versions of VkDescriptorSet. We hold on to these
in the program since | |
| 156 // we update the descriptor sets and bind them at separate times; | |
| 157 VkDescriptorSet fDescriptorSets[2]; | |
| 158 | |
| 159 // Meta data so we know which descriptor sets we are using and need to bind. | |
| 160 int fStartDS; | |
| 161 int fDSCount; | |
| 162 | |
| 163 SkAutoTDelete<GrVkUniformBuffer> fVertexUniformBuffer; | |
| 164 SkAutoTDelete<GrVkUniformBuffer> fFragmentUniformBuffer; | |
| 165 | |
| 166 // GrVkResources used for sampling textures | |
| 167 SkTDArray<GrVkSampler*> fSamplers; | |
| 168 SkTDArray<const GrVkImageView*> fTextureViews; | |
| 169 SkTDArray<const GrVkImage::Resource*> fTextures; | |
| 170 | |
| 171 // Tracks the current render target uniforms stored in the vertex buffer. | |
| 172 RenderTargetState fRenderTargetState; | |
| 173 BuiltinUniformHandles fBuiltinUniformHandles; | |
| 174 | |
| 175 // Processors in the program | |
| 176 SkAutoTDelete<GrGLSLPrimitiveProcessor> fGeometryProcessor; | |
| 177 SkAutoTDelete<GrGLSLXferProcessor> fXferProcessor; | |
| 178 GrGLSLFragProcs fFragmentProcessors; | |
| 179 | |
| 180 GrVkProgramDataManager fProgramDataManager; | |
| 181 | |
| 182 DescriptorPoolManager fSamplerPoolManager; | |
| 183 DescriptorPoolManager fUniformPoolManager; | |
| 184 | |
| 185 int fNumSamplers; | |
| 186 | |
| 187 friend class GrVkProgramBuilder; | |
| 188 }; | |
| 189 | |
| 190 #endif | |
| OLD | NEW |