Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #ifndef GrVkProgram_DEFINED | 9 #ifndef GrVkProgram_DEFINED |
| 10 #define GrVkProgram_DEFINED | 10 #define GrVkProgram_DEFINED |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 void abandonGPUResources(); | 48 void abandonGPUResources(); |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 typedef GrVkProgramDataManager::UniformInfoArray UniformInfoArray; | 51 typedef GrVkProgramDataManager::UniformInfoArray UniformInfoArray; |
| 52 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 52 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
| 53 | 53 |
| 54 GrVkProgram(GrVkGpu* gpu, | 54 GrVkProgram(GrVkGpu* gpu, |
| 55 GrVkPipeline* pipeline, | 55 GrVkPipeline* pipeline, |
| 56 VkPipelineLayout layout, | 56 VkPipelineLayout layout, |
| 57 VkDescriptorSetLayout dsLayout[2], | 57 VkDescriptorSetLayout dsLayout[2], |
| 58 GrVkDescriptorPool* descriptorPool, | |
| 59 VkDescriptorSet descriptorSets[2], | |
| 60 const BuiltinUniformHandles& builtinUniformHandles, | 58 const BuiltinUniformHandles& builtinUniformHandles, |
| 61 const UniformInfoArray& uniforms, | 59 const UniformInfoArray& uniforms, |
| 62 uint32_t vertexUniformSize, | 60 uint32_t vertexUniformSize, |
| 63 uint32_t fragmentUniformSize, | 61 uint32_t fragmentUniformSize, |
| 64 uint32_t numSamplers, | 62 uint32_t numSamplers, |
| 65 GrGLSLPrimitiveProcessor* geometryProcessor, | 63 GrGLSLPrimitiveProcessor* geometryProcessor, |
| 66 GrGLSLXferProcessor* xferProcessor, | 64 GrGLSLXferProcessor* xferProcessor, |
| 67 const GrGLSLFragProcs& fragmentProcessors); | 65 const GrGLSLFragProcs& fragmentProcessors); |
| 68 | 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 uint8_t descCount, GrVkGpu* gpu) | |
| 72 : fDescLayout(layout) | |
| 73 , fDescType(type) | |
| 74 , fDescCount(descCount) | |
| 75 , fMaxDescriptorSets(4) | |
| 76 , fCurrentDescriptorSet(0) | |
| 77 , fPool(nullptr) { | |
| 78 if (fDescCount * fMaxDescriptorSets > 1 << 8) { | |
|
jvanverth1
2016/03/07 19:04:11
Use a constant rather than 1 << 8? And why 256?
egdaniel
2016/03/07 20:02:25
The descriptorpool type count struct I made previo
| |
| 79 fMaxDescriptorSets = 1; | |
| 80 } | |
| 81 this->getNewPool(gpu); | |
| 82 } | |
| 83 | |
| 84 ~DescriptorPoolManager() { | |
| 85 SkASSERT(!fDescLayout); | |
| 86 SkASSERT(!fPool); | |
| 87 } | |
| 88 | |
| 89 void getNewDescriptorSet(GrVkGpu* gpu, VkDescriptorSet* ds); | |
| 90 | |
| 91 void freeGPUResources(const GrVkGpu* gpu); | |
| 92 void abandonGPUResources(); | |
| 93 | |
| 94 VkDescriptorSetLayout fDescLayout; | |
| 95 VkDescriptorType fDescType; | |
| 96 uint8_t fDescCount; | |
| 97 uint8_t fMaxDescriptorSets; | |
| 98 uint8_t fCurrentDescriptorSet; | |
| 99 GrVkDescriptorPool* fPool; | |
| 100 | |
| 101 private: | |
| 102 void getNewPool(GrVkGpu* gpu); | |
| 103 }; | |
| 104 | |
| 69 void writeUniformBuffers(const GrVkGpu* gpu); | 105 void writeUniformBuffers(const GrVkGpu* gpu); |
| 70 | 106 |
| 71 void writeSamplers(GrVkGpu* gpu, const SkTArray<const GrTextureAccess*>& tex tureBindings); | 107 void writeSamplers(GrVkGpu* gpu, const SkTArray<const GrTextureAccess*>& tex tureBindings); |
| 72 | 108 |
| 73 | 109 |
| 74 /** | 110 /** |
| 75 * We use the RT's size and origin to adjust from Skia device space to OpenGL normalized device | 111 * We use the RT's size and origin to adjust from Skia device space to OpenGL normalized device |
| 76 * space and to make device space positions have the correct origin for proce ssors that require | 112 * space and to make device space positions have the correct origin for proce ssors that require |
| 77 * them. | 113 * them. |
| 78 */ | 114 */ |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 103 } else { | 139 } else { |
| 104 destVec[2] = 2.f / fRenderTargetSize.fHeight; | 140 destVec[2] = 2.f / fRenderTargetSize.fHeight; |
| 105 destVec[3] = -1.f; | 141 destVec[3] = -1.f; |
| 106 } | 142 } |
| 107 } | 143 } |
| 108 }; | 144 }; |
| 109 | 145 |
| 110 // Helper for setData() that sets the view matrix and loads the render targe t height uniform | 146 // Helper for setData() that sets the view matrix and loads the render targe t height uniform |
| 111 void setRenderTargetState(const GrPipeline&); | 147 void setRenderTargetState(const GrPipeline&); |
| 112 | 148 |
| 113 // GrVkGpu* fGpu; | |
| 114 | |
| 115 // GrVkResources | 149 // GrVkResources |
| 116 GrVkDescriptorPool* fDescriptorPool; | |
| 117 GrVkPipeline* fPipeline; | 150 GrVkPipeline* fPipeline; |
| 118 | 151 |
| 119 // Used for binding DescriptorSets to the command buffer but does not need t o survive during | 152 // Used for binding DescriptorSets to the command buffer but does not need t o survive during |
| 120 // command buffer execution. Thus this is not need to be a GrVkResource. | 153 // command buffer execution. Thus this is not need to be a GrVkResource. |
| 121 VkPipelineLayout fPipelineLayout; | 154 VkPipelineLayout fPipelineLayout; |
| 122 | 155 |
| 123 // The first set (index 0) will be used for samplers and the second set (ind ex 1) will be | |
| 124 // used for uniform buffers. | |
| 125 // The DSLayouts only are needed for allocating the descriptor sets and must survive until after | |
| 126 // descriptor sets have been updated. Thus the lifetime of the layouts will just be the life of | |
| 127 //the GrVkProgram. | |
| 128 VkDescriptorSetLayout fDSLayout[2]; | |
| 129 // The DescriptorSets need to survive until the gpu has finished all draws t hat use them. | 156 // The DescriptorSets need to survive until the gpu has finished all draws t hat use them. |
| 130 // However, they will only be freed by the descriptor pool. Thus by simply k eeping the | 157 // However, they will only be freed by the descriptor pool. Thus by simply k eeping the |
| 131 // descriptor pool alive through the draw, the descritor sets will also stay alive. Thus we do | 158 // descriptor pool alive through the draw, the descritor sets will also stay alive. Thus we do |
| 132 // not need a GrVkResource versions of VkDescriptorSet. | 159 // not need a GrVkResource versions of VkDescriptorSet. We hold on to these in the program since |
| 160 // we update the descriptor sets and bind them at separate times; | |
| 133 VkDescriptorSet fDescriptorSets[2]; | 161 VkDescriptorSet fDescriptorSets[2]; |
| 134 | 162 |
| 163 // Meta data so we know which descriptor sets we are using and need to bind. | |
| 164 int fStartDS; | |
| 165 int fDSCount; | |
| 166 | |
| 135 SkAutoTDelete<GrVkUniformBuffer> fVertexUniformBuffer; | 167 SkAutoTDelete<GrVkUniformBuffer> fVertexUniformBuffer; |
| 136 SkAutoTDelete<GrVkUniformBuffer> fFragmentUniformBuffer; | 168 SkAutoTDelete<GrVkUniformBuffer> fFragmentUniformBuffer; |
| 137 | 169 |
| 138 // GrVkResources used for sampling textures | 170 // GrVkResources used for sampling textures |
| 139 SkTDArray<GrVkSampler*> fSamplers; | 171 SkTDArray<GrVkSampler*> fSamplers; |
| 140 SkTDArray<const GrVkImageView*> fTextureViews; | 172 SkTDArray<const GrVkImageView*> fTextureViews; |
| 141 SkTDArray<const GrVkImage::Resource*> fTextures; | 173 SkTDArray<const GrVkImage::Resource*> fTextures; |
| 142 | 174 |
| 143 // Tracks the current render target uniforms stored in the vertex buffer. | 175 // Tracks the current render target uniforms stored in the vertex buffer. |
| 144 RenderTargetState fRenderTargetState; | 176 RenderTargetState fRenderTargetState; |
| 145 BuiltinUniformHandles fBuiltinUniformHandles; | 177 BuiltinUniformHandles fBuiltinUniformHandles; |
| 146 | 178 |
| 147 // Processors in the program | 179 // Processors in the program |
| 148 SkAutoTDelete<GrGLSLPrimitiveProcessor> fGeometryProcessor; | 180 SkAutoTDelete<GrGLSLPrimitiveProcessor> fGeometryProcessor; |
| 149 SkAutoTDelete<GrGLSLXferProcessor> fXferProcessor; | 181 SkAutoTDelete<GrGLSLXferProcessor> fXferProcessor; |
| 150 GrGLSLFragProcs fFragmentProcessors; | 182 GrGLSLFragProcs fFragmentProcessors; |
| 151 | 183 |
| 152 GrVkProgramDataManager fProgramDataManager; | 184 GrVkProgramDataManager fProgramDataManager; |
| 153 | 185 |
| 186 DescriptorPoolManager fSamplerPoolManager; | |
| 187 DescriptorPoolManager fUniformPoolManager; | |
| 188 | |
| 154 #ifdef SK_DEBUG | 189 #ifdef SK_DEBUG |
| 155 int fNumSamplers; | 190 int fNumSamplers; |
| 156 #endif | 191 #endif |
| 157 | 192 |
| 158 friend class GrVkProgramBuilder; | 193 friend class GrVkProgramBuilder; |
| 159 }; | 194 }; |
| 160 | 195 |
| 161 #endif | 196 #endif |
| OLD | NEW |