| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 #include "GrVkPipelineState.h" | 8 #include "GrVkPipelineState.h" |
| 9 | 9 |
| 10 #include "GrPipeline.h" | 10 #include "GrPipeline.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "GrVkUniformBuffer.h" | 22 #include "GrVkUniformBuffer.h" |
| 23 #include "glsl/GrGLSLFragmentProcessor.h" | 23 #include "glsl/GrGLSLFragmentProcessor.h" |
| 24 #include "glsl/GrGLSLGeometryProcessor.h" | 24 #include "glsl/GrGLSLGeometryProcessor.h" |
| 25 #include "glsl/GrGLSLXferProcessor.h" | 25 #include "glsl/GrGLSLXferProcessor.h" |
| 26 #include "SkMipMap.h" | 26 #include "SkMipMap.h" |
| 27 | 27 |
| 28 GrVkPipelineState::GrVkPipelineState(GrVkGpu* gpu, | 28 GrVkPipelineState::GrVkPipelineState(GrVkGpu* gpu, |
| 29 const GrVkPipelineState::Desc& desc, | 29 const GrVkPipelineState::Desc& desc, |
| 30 GrVkPipeline* pipeline, | 30 GrVkPipeline* pipeline, |
| 31 VkPipelineLayout layout, | 31 VkPipelineLayout layout, |
| 32 VkDescriptorSetLayout dsSamplerLayout, | 32 const GrVkDescriptorSetManager::Handle& sam
plerDSHandle, |
| 33 const BuiltinUniformHandles& builtinUniform
Handles, | 33 const BuiltinUniformHandles& builtinUniform
Handles, |
| 34 const UniformInfoArray& uniforms, | 34 const UniformInfoArray& uniforms, |
| 35 uint32_t vertexUniformSize, | 35 uint32_t vertexUniformSize, |
| 36 uint32_t fragmentUniformSize, | 36 uint32_t fragmentUniformSize, |
| 37 uint32_t numSamplers, | 37 uint32_t numSamplers, |
| 38 GrGLSLPrimitiveProcessor* geometryProcessor
, | 38 GrGLSLPrimitiveProcessor* geometryProcessor
, |
| 39 GrGLSLXferProcessor* xferProcessor, | 39 GrGLSLXferProcessor* xferProcessor, |
| 40 const GrGLSLFragProcs& fragmentProcessors) | 40 const GrGLSLFragProcs& fragmentProcessors) |
| 41 : fPipeline(pipeline) | 41 : fPipeline(pipeline) |
| 42 , fPipelineLayout(layout) | 42 , fPipelineLayout(layout) |
| 43 , fUniformDescriptorSet(nullptr) | 43 , fUniformDescriptorSet(nullptr) |
| 44 , fSamplerDescriptorSet(nullptr) |
| 45 , fSamplerDSHandle(samplerDSHandle) |
| 44 , fStartDS(SK_MaxS32) | 46 , fStartDS(SK_MaxS32) |
| 45 , fDSCount(0) | 47 , fDSCount(0) |
| 46 , fBuiltinUniformHandles(builtinUniformHandles) | 48 , fBuiltinUniformHandles(builtinUniformHandles) |
| 47 , fGeometryProcessor(geometryProcessor) | 49 , fGeometryProcessor(geometryProcessor) |
| 48 , fXferProcessor(xferProcessor) | 50 , fXferProcessor(xferProcessor) |
| 49 , fFragmentProcessors(fragmentProcessors) | 51 , fFragmentProcessors(fragmentProcessors) |
| 50 , fDesc(desc) | 52 , fDesc(desc) |
| 51 , fDataManager(uniforms, vertexUniformSize, fragmentUniformSize) | 53 , fDataManager(uniforms, vertexUniformSize, fragmentUniformSize) { |
| 52 , fSamplerPoolManager(dsSamplerLayout, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAM
PLER, | |
| 53 numSamplers, gpu) { | |
| 54 fSamplers.setReserve(numSamplers); | 54 fSamplers.setReserve(numSamplers); |
| 55 fTextureViews.setReserve(numSamplers); | 55 fTextureViews.setReserve(numSamplers); |
| 56 fTextures.setReserve(numSamplers); | 56 fTextures.setReserve(numSamplers); |
| 57 | 57 |
| 58 fDescriptorSets[0] = VK_NULL_HANDLE; | 58 fDescriptorSets[0] = VK_NULL_HANDLE; |
| 59 fDescriptorSets[1] = VK_NULL_HANDLE; | 59 fDescriptorSets[1] = VK_NULL_HANDLE; |
| 60 | 60 |
| 61 // Currently we are always binding a descriptor set for uniform buffers. | 61 // Currently we are always binding a descriptor set for uniform buffers. |
| 62 if (vertexUniformSize || fragmentUniformSize) { | 62 if (vertexUniformSize || fragmentUniformSize) { |
| 63 fDSCount++; | 63 fDSCount++; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 119 if (fVertexUniformBuffer) { | 119 if (fVertexUniformBuffer) { |
| 120 fVertexUniformBuffer->release(gpu); | 120 fVertexUniformBuffer->release(gpu); |
| 121 } | 121 } |
| 122 | 122 |
| 123 if (fFragmentUniformBuffer) { | 123 if (fFragmentUniformBuffer) { |
| 124 fFragmentUniformBuffer->release(gpu); | 124 fFragmentUniformBuffer->release(gpu); |
| 125 } | 125 } |
| 126 | 126 |
| 127 fSamplerPoolManager.freeGPUResources(gpu); | |
| 128 | |
| 129 if (fUniformDescriptorSet) { | 127 if (fUniformDescriptorSet) { |
| 130 fUniformDescriptorSet->recycle(const_cast<GrVkGpu*>(gpu)); | 128 fUniformDescriptorSet->recycle(const_cast<GrVkGpu*>(gpu)); |
| 131 fUniformDescriptorSet = nullptr; | 129 fUniformDescriptorSet = nullptr; |
| 132 } | 130 } |
| 133 | 131 |
| 132 if (fSamplerDescriptorSet) { |
| 133 fSamplerDescriptorSet->recycle(const_cast<GrVkGpu*>(gpu)); |
| 134 fSamplerDescriptorSet = nullptr; |
| 135 } |
| 136 |
| 134 this->freeTempResources(gpu); | 137 this->freeTempResources(gpu); |
| 135 } | 138 } |
| 136 | 139 |
| 137 void GrVkPipelineState::abandonGPUResources() { | 140 void GrVkPipelineState::abandonGPUResources() { |
| 138 fPipeline->unrefAndAbandon(); | 141 fPipeline->unrefAndAbandon(); |
| 139 fPipeline = nullptr; | 142 fPipeline = nullptr; |
| 140 | 143 |
| 141 fPipelineLayout = VK_NULL_HANDLE; | 144 fPipelineLayout = VK_NULL_HANDLE; |
| 142 | 145 |
| 143 fVertexUniformBuffer->abandon(); | 146 fVertexUniformBuffer->abandon(); |
| 144 fFragmentUniformBuffer->abandon(); | 147 fFragmentUniformBuffer->abandon(); |
| 145 | 148 |
| 146 for (int i = 0; i < fSamplers.count(); ++i) { | 149 for (int i = 0; i < fSamplers.count(); ++i) { |
| 147 fSamplers[i]->unrefAndAbandon(); | 150 fSamplers[i]->unrefAndAbandon(); |
| 148 } | 151 } |
| 149 fSamplers.rewind(); | 152 fSamplers.rewind(); |
| 150 | 153 |
| 151 for (int i = 0; i < fTextureViews.count(); ++i) { | 154 for (int i = 0; i < fTextureViews.count(); ++i) { |
| 152 fTextureViews[i]->unrefAndAbandon(); | 155 fTextureViews[i]->unrefAndAbandon(); |
| 153 } | 156 } |
| 154 fTextureViews.rewind(); | 157 fTextureViews.rewind(); |
| 155 | 158 |
| 156 for (int i = 0; i < fTextures.count(); ++i) { | 159 for (int i = 0; i < fTextures.count(); ++i) { |
| 157 fTextures[i]->unrefAndAbandon(); | 160 fTextures[i]->unrefAndAbandon(); |
| 158 } | 161 } |
| 159 fTextures.rewind(); | 162 fTextures.rewind(); |
| 160 | 163 |
| 161 fSamplerPoolManager.abandonGPUResources(); | |
| 162 | |
| 163 if (fUniformDescriptorSet) { | 164 if (fUniformDescriptorSet) { |
| 164 fUniformDescriptorSet->unrefAndAbandon(); | 165 fUniformDescriptorSet->unrefAndAbandon(); |
| 165 fUniformDescriptorSet = nullptr; | 166 fUniformDescriptorSet = nullptr; |
| 166 } | 167 } |
| 168 |
| 169 if (fSamplerDescriptorSet) { |
| 170 fSamplerDescriptorSet->unrefAndAbandon(); |
| 171 fSamplerDescriptorSet = nullptr; |
| 172 } |
| 167 } | 173 } |
| 168 | 174 |
| 169 static void append_texture_bindings(const GrProcessor& processor, | 175 static void append_texture_bindings(const GrProcessor& processor, |
| 170 SkTArray<const GrTextureAccess*>* textureBin
dings) { | 176 SkTArray<const GrTextureAccess*>* textureBin
dings) { |
| 171 if (int numTextures = processor.numTextures()) { | 177 if (int numTextures = processor.numTextures()) { |
| 172 const GrTextureAccess** bindings = textureBindings->push_back_n(numTextu
res); | 178 const GrTextureAccess** bindings = textureBindings->push_back_n(numTextu
res); |
| 173 int i = 0; | 179 int i = 0; |
| 174 do { | 180 do { |
| 175 bindings[i] = &processor.textureAccess(i); | 181 bindings[i] = &processor.textureAccess(i); |
| 176 } while (++i < numTextures); | 182 } while (++i < numTextures); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 197 fGeometryProcessor->setTransformData(primProc, fDataManager, i, | 203 fGeometryProcessor->setTransformData(primProc, fDataManager, i, |
| 198 processor.coordTransforms()); | 204 processor.coordTransforms()); |
| 199 append_texture_bindings(processor, &textureBindings); | 205 append_texture_bindings(processor, &textureBindings); |
| 200 } | 206 } |
| 201 | 207 |
| 202 fXferProcessor->setData(fDataManager, pipeline.getXferProcessor()); | 208 fXferProcessor->setData(fDataManager, pipeline.getXferProcessor()); |
| 203 append_texture_bindings(pipeline.getXferProcessor(), &textureBindings); | 209 append_texture_bindings(pipeline.getXferProcessor(), &textureBindings); |
| 204 | 210 |
| 205 // Get new descriptor sets | 211 // Get new descriptor sets |
| 206 if (fNumSamplers) { | 212 if (fNumSamplers) { |
| 207 fSamplerPoolManager.getNewDescriptorSet(gpu, | 213 if (fSamplerDescriptorSet) { |
| 208 &fDescriptorSets[GrVkUniformHandler
::kSamplerDescSet]); | 214 fSamplerDescriptorSet->recycle(gpu); |
| 215 } |
| 216 fSamplerDescriptorSet = gpu->resourceProvider().getSamplerDescriptorSet(
fSamplerDSHandle); |
| 217 int samplerDSIdx = GrVkUniformHandler::kSamplerDescSet; |
| 218 fDescriptorSets[samplerDSIdx] = fSamplerDescriptorSet->descriptorSet(); |
| 209 this->writeSamplers(gpu, textureBindings, pipeline.getAllowSRGBInputs())
; | 219 this->writeSamplers(gpu, textureBindings, pipeline.getAllowSRGBInputs())
; |
| 210 } | 220 } |
| 211 | 221 |
| 212 if (fVertexUniformBuffer.get() || fFragmentUniformBuffer.get()) { | 222 if (fVertexUniformBuffer.get() || fFragmentUniformBuffer.get()) { |
| 213 if (fDataManager.uploadUniformBuffers(gpu, fVertexUniformBuffer, fFragme
ntUniformBuffer) || | 223 if (fDataManager.uploadUniformBuffers(gpu, fVertexUniformBuffer, fFragme
ntUniformBuffer) || |
| 214 !fUniformDescriptorSet) { | 224 !fUniformDescriptorSet) { |
| 215 if (fUniformDescriptorSet) { | 225 if (fUniformDescriptorSet) { |
| 216 fUniformDescriptorSet->recycle(gpu); | 226 fUniformDescriptorSet->recycle(gpu); |
| 217 } | 227 } |
| 218 fUniformDescriptorSet = gpu->resourceProvider().getUniformDescriptor
Set(); | 228 fUniformDescriptorSet = gpu->resourceProvider().getUniformDescriptor
Set(); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 void GrVkPipelineState::bind(const GrVkGpu* gpu, GrVkCommandBuffer* commandBuffe
r) { | 368 void GrVkPipelineState::bind(const GrVkGpu* gpu, GrVkCommandBuffer* commandBuffe
r) { |
| 359 commandBuffer->bindPipeline(gpu, fPipeline); | 369 commandBuffer->bindPipeline(gpu, fPipeline); |
| 360 | 370 |
| 361 if (fDSCount) { | 371 if (fDSCount) { |
| 362 commandBuffer->bindDescriptorSets(gpu, this, fPipelineLayout, fStartDS,
fDSCount, | 372 commandBuffer->bindDescriptorSets(gpu, this, fPipelineLayout, fStartDS,
fDSCount, |
| 363 &fDescriptorSets[fStartDS], 0, nullptr
); | 373 &fDescriptorSets[fStartDS], 0, nullptr
); |
| 364 } | 374 } |
| 365 } | 375 } |
| 366 | 376 |
| 367 void GrVkPipelineState::addUniformResources(GrVkCommandBuffer& commandBuffer) { | 377 void GrVkPipelineState::addUniformResources(GrVkCommandBuffer& commandBuffer) { |
| 368 if (fSamplerPoolManager.fPool) { | |
| 369 commandBuffer.addResource(fSamplerPoolManager.fPool); | |
| 370 } | |
| 371 | |
| 372 if (fUniformDescriptorSet) { | 378 if (fUniformDescriptorSet) { |
| 373 commandBuffer.addRecycledResource(fUniformDescriptorSet); | 379 commandBuffer.addRecycledResource(fUniformDescriptorSet); |
| 374 } | 380 } |
| 381 if (fSamplerDescriptorSet) { |
| 382 commandBuffer.addRecycledResource(fSamplerDescriptorSet); |
| 383 } |
| 384 |
| 375 | 385 |
| 376 if (fVertexUniformBuffer.get()) { | 386 if (fVertexUniformBuffer.get()) { |
| 377 commandBuffer.addResource(fVertexUniformBuffer->resource()); | 387 commandBuffer.addResource(fVertexUniformBuffer->resource()); |
| 378 } | 388 } |
| 379 if (fFragmentUniformBuffer.get()) { | 389 if (fFragmentUniformBuffer.get()) { |
| 380 commandBuffer.addResource(fFragmentUniformBuffer->resource()); | 390 commandBuffer.addResource(fFragmentUniformBuffer->resource()); |
| 381 } | 391 } |
| 382 for (int i = 0; i < fSamplers.count(); ++i) { | 392 for (int i = 0; i < fSamplers.count(); ++i) { |
| 383 commandBuffer.addResource(fSamplers[i]); | 393 commandBuffer.addResource(fSamplers[i]); |
| 384 } | 394 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 | 501 |
| 492 b.add32(get_blend_info_key(pipeline)); | 502 b.add32(get_blend_info_key(pipeline)); |
| 493 | 503 |
| 494 b.add32(primitiveType); | 504 b.add32(primitiveType); |
| 495 | 505 |
| 496 // Set key length | 506 // Set key length |
| 497 int keyLength = key->count(); | 507 int keyLength = key->count(); |
| 498 SkASSERT(0 == (keyLength % 4)); | 508 SkASSERT(0 == (keyLength % 4)); |
| 499 *reinterpret_cast<uint32_t*>(key->begin()) = SkToU32(keyLength); | 509 *reinterpret_cast<uint32_t*>(key->begin()) = SkToU32(keyLength); |
| 500 } | 510 } |
| OLD | NEW |