Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/gpu/vk/GrVkPipelineState.cpp

Issue 2163673002: Setup system in Vulkan to reuse VkDescriptorSet allocations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/vk/GrVkPipelineState.h ('k') | src/gpu/vk/GrVkResource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "GrTexturePriv.h" 11 #include "GrTexturePriv.h"
12 #include "GrVkCommandBuffer.h" 12 #include "GrVkCommandBuffer.h"
13 #include "GrVkDescriptorPool.h" 13 #include "GrVkDescriptorPool.h"
14 #include "GrVkDescriptorSet.h"
14 #include "GrVkGpu.h" 15 #include "GrVkGpu.h"
15 #include "GrVkImageView.h" 16 #include "GrVkImageView.h"
16 #include "GrVkMemory.h" 17 #include "GrVkMemory.h"
17 #include "GrVkPipeline.h" 18 #include "GrVkPipeline.h"
18 #include "GrVkRenderTarget.h" 19 #include "GrVkRenderTarget.h"
19 #include "GrVkSampler.h" 20 #include "GrVkSampler.h"
20 #include "GrVkTexture.h" 21 #include "GrVkTexture.h"
21 #include "GrVkUniformBuffer.h" 22 #include "GrVkUniformBuffer.h"
22 #include "glsl/GrGLSLFragmentProcessor.h" 23 #include "glsl/GrGLSLFragmentProcessor.h"
23 #include "glsl/GrGLSLGeometryProcessor.h" 24 #include "glsl/GrGLSLGeometryProcessor.h"
24 #include "glsl/GrGLSLXferProcessor.h" 25 #include "glsl/GrGLSLXferProcessor.h"
25 #include "SkMipMap.h" 26 #include "SkMipMap.h"
26 27
27 GrVkPipelineState::GrVkPipelineState(GrVkGpu* gpu, 28 GrVkPipelineState::GrVkPipelineState(GrVkGpu* gpu,
28 const GrVkPipelineState::Desc& desc, 29 const GrVkPipelineState::Desc& desc,
29 GrVkPipeline* pipeline, 30 GrVkPipeline* pipeline,
30 VkPipelineLayout layout, 31 VkPipelineLayout layout,
31 VkDescriptorSetLayout dsSamplerLayout, 32 VkDescriptorSetLayout dsSamplerLayout,
32 const BuiltinUniformHandles& builtinUniform Handles, 33 const BuiltinUniformHandles& builtinUniform Handles,
33 const UniformInfoArray& uniforms, 34 const UniformInfoArray& uniforms,
34 uint32_t vertexUniformSize, 35 uint32_t vertexUniformSize,
35 uint32_t fragmentUniformSize, 36 uint32_t fragmentUniformSize,
36 uint32_t numSamplers, 37 uint32_t numSamplers,
37 GrGLSLPrimitiveProcessor* geometryProcessor , 38 GrGLSLPrimitiveProcessor* geometryProcessor ,
38 GrGLSLXferProcessor* xferProcessor, 39 GrGLSLXferProcessor* xferProcessor,
39 const GrGLSLFragProcs& fragmentProcessors) 40 const GrGLSLFragProcs& fragmentProcessors)
40 : fPipeline(pipeline) 41 : fPipeline(pipeline)
41 , fPipelineLayout(layout) 42 , fPipelineLayout(layout)
43 , fUniformDescriptorSet(nullptr)
42 , fStartDS(SK_MaxS32) 44 , fStartDS(SK_MaxS32)
43 , fDSCount(0) 45 , fDSCount(0)
44 , fBuiltinUniformHandles(builtinUniformHandles) 46 , fBuiltinUniformHandles(builtinUniformHandles)
45 , fGeometryProcessor(geometryProcessor) 47 , fGeometryProcessor(geometryProcessor)
46 , fXferProcessor(xferProcessor) 48 , fXferProcessor(xferProcessor)
47 , fFragmentProcessors(fragmentProcessors) 49 , fFragmentProcessors(fragmentProcessors)
48 , fDesc(desc) 50 , fDesc(desc)
49 , fDataManager(uniforms, vertexUniformSize, fragmentUniformSize) 51 , fDataManager(uniforms, vertexUniformSize, fragmentUniformSize)
50 , fSamplerPoolManager(dsSamplerLayout, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAM PLER, 52 , fSamplerPoolManager(dsSamplerLayout, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAM PLER,
51 numSamplers, gpu) 53 numSamplers, gpu) {
52 , fCurrentUniformDescPool(nullptr) {
53 fSamplers.setReserve(numSamplers); 54 fSamplers.setReserve(numSamplers);
54 fTextureViews.setReserve(numSamplers); 55 fTextureViews.setReserve(numSamplers);
55 fTextures.setReserve(numSamplers); 56 fTextures.setReserve(numSamplers);
56 57
57 fDescriptorSets[0] = VK_NULL_HANDLE; 58 fDescriptorSets[0] = VK_NULL_HANDLE;
58 fDescriptorSets[1] = VK_NULL_HANDLE; 59 fDescriptorSets[1] = VK_NULL_HANDLE;
59 60
60 // Currently we are always binding a descriptor set for uniform buffers. 61 // Currently we are always binding a descriptor set for uniform buffers.
61 if (vertexUniformSize || fragmentUniformSize) { 62 if (vertexUniformSize || fragmentUniformSize) {
62 fDSCount++; 63 fDSCount++;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 118
118 if (fVertexUniformBuffer) { 119 if (fVertexUniformBuffer) {
119 fVertexUniformBuffer->release(gpu); 120 fVertexUniformBuffer->release(gpu);
120 } 121 }
121 122
122 if (fFragmentUniformBuffer) { 123 if (fFragmentUniformBuffer) {
123 fFragmentUniformBuffer->release(gpu); 124 fFragmentUniformBuffer->release(gpu);
124 } 125 }
125 126
126 fSamplerPoolManager.freeGPUResources(gpu); 127 fSamplerPoolManager.freeGPUResources(gpu);
127 if (fCurrentUniformDescPool) { 128
128 fCurrentUniformDescPool->unref(gpu); 129 if (fUniformDescriptorSet) {
129 fCurrentUniformDescPool = nullptr; 130 fUniformDescriptorSet->recycle(const_cast<GrVkGpu*>(gpu));
131 fUniformDescriptorSet = nullptr;
130 } 132 }
131 133
132 this->freeTempResources(gpu); 134 this->freeTempResources(gpu);
133 } 135 }
134 136
135 void GrVkPipelineState::abandonGPUResources() { 137 void GrVkPipelineState::abandonGPUResources() {
136 fPipeline->unrefAndAbandon(); 138 fPipeline->unrefAndAbandon();
137 fPipeline = nullptr; 139 fPipeline = nullptr;
138 140
139 fPipelineLayout = VK_NULL_HANDLE; 141 fPipelineLayout = VK_NULL_HANDLE;
(...skipping 10 matching lines...) Expand all
150 fTextureViews[i]->unrefAndAbandon(); 152 fTextureViews[i]->unrefAndAbandon();
151 } 153 }
152 fTextureViews.rewind(); 154 fTextureViews.rewind();
153 155
154 for (int i = 0; i < fTextures.count(); ++i) { 156 for (int i = 0; i < fTextures.count(); ++i) {
155 fTextures[i]->unrefAndAbandon(); 157 fTextures[i]->unrefAndAbandon();
156 } 158 }
157 fTextures.rewind(); 159 fTextures.rewind();
158 160
159 fSamplerPoolManager.abandonGPUResources(); 161 fSamplerPoolManager.abandonGPUResources();
160 if (fCurrentUniformDescPool) { 162
161 fCurrentUniformDescPool->unrefAndAbandon(); 163 if (fUniformDescriptorSet) {
162 fCurrentUniformDescPool = nullptr; 164 fUniformDescriptorSet->unrefAndAbandon();
165 fUniformDescriptorSet = nullptr;
163 } 166 }
164 } 167 }
165 168
166 static void append_texture_bindings(const GrProcessor& processor, 169 static void append_texture_bindings(const GrProcessor& processor,
167 SkTArray<const GrTextureAccess*>* textureBin dings) { 170 SkTArray<const GrTextureAccess*>* textureBin dings) {
168 if (int numTextures = processor.numTextures()) { 171 if (int numTextures = processor.numTextures()) {
169 const GrTextureAccess** bindings = textureBindings->push_back_n(numTextu res); 172 const GrTextureAccess** bindings = textureBindings->push_back_n(numTextu res);
170 int i = 0; 173 int i = 0;
171 do { 174 do {
172 bindings[i] = &processor.textureAccess(i); 175 bindings[i] = &processor.textureAccess(i);
(...skipping 28 matching lines...) Expand all
201 204
202 // Get new descriptor sets 205 // Get new descriptor sets
203 if (fNumSamplers) { 206 if (fNumSamplers) {
204 fSamplerPoolManager.getNewDescriptorSet(gpu, 207 fSamplerPoolManager.getNewDescriptorSet(gpu,
205 &fDescriptorSets[GrVkUniformHandler ::kSamplerDescSet]); 208 &fDescriptorSets[GrVkUniformHandler ::kSamplerDescSet]);
206 this->writeSamplers(gpu, textureBindings, pipeline.getAllowSRGBInputs()) ; 209 this->writeSamplers(gpu, textureBindings, pipeline.getAllowSRGBInputs()) ;
207 } 210 }
208 211
209 if (fVertexUniformBuffer.get() || fFragmentUniformBuffer.get()) { 212 if (fVertexUniformBuffer.get() || fFragmentUniformBuffer.get()) {
210 if (fDataManager.uploadUniformBuffers(gpu, fVertexUniformBuffer, fFragme ntUniformBuffer) || 213 if (fDataManager.uploadUniformBuffers(gpu, fVertexUniformBuffer, fFragme ntUniformBuffer) ||
211 VK_NULL_HANDLE == fDescriptorSets[GrVkUniformHandler::kUniformBuffer DescSet]) { 214 !fUniformDescriptorSet) {
212 const GrVkDescriptorPool* pool; 215 if (fUniformDescriptorSet) {
216 fUniformDescriptorSet->recycle(gpu);
217 }
218 fUniformDescriptorSet = gpu->resourceProvider().getUniformDescriptor Set();
213 int uniformDSIdx = GrVkUniformHandler::kUniformBufferDescSet; 219 int uniformDSIdx = GrVkUniformHandler::kUniformBufferDescSet;
214 gpu->resourceProvider().getUniformDescriptorSet(&fDescriptorSets[uni formDSIdx], 220 fDescriptorSets[uniformDSIdx] = fUniformDescriptorSet->descriptorSet ();
215 &pool);
216 if (pool != fCurrentUniformDescPool) {
217 if (fCurrentUniformDescPool) {
218 fCurrentUniformDescPool->unref(gpu);
219 }
220 fCurrentUniformDescPool = pool;
221 fCurrentUniformDescPool->ref();
222 }
223 this->writeUniformBuffers(gpu); 221 this->writeUniformBuffers(gpu);
224 } 222 }
225 } 223 }
226 } 224 }
227 225
228 void GrVkPipelineState::writeUniformBuffers(const GrVkGpu* gpu) { 226 void GrVkPipelineState::writeUniformBuffers(const GrVkGpu* gpu) {
229 VkWriteDescriptorSet descriptorWrites[2]; 227 VkWriteDescriptorSet descriptorWrites[2];
230 memset(descriptorWrites, 0, 2 * sizeof(VkWriteDescriptorSet)); 228 memset(descriptorWrites, 0, 2 * sizeof(VkWriteDescriptorSet));
231 229
232 uint32_t firstUniformWrite = 0; 230 uint32_t firstUniformWrite = 0;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if (fDSCount) { 361 if (fDSCount) {
364 commandBuffer->bindDescriptorSets(gpu, this, fPipelineLayout, fStartDS, fDSCount, 362 commandBuffer->bindDescriptorSets(gpu, this, fPipelineLayout, fStartDS, fDSCount,
365 &fDescriptorSets[fStartDS], 0, nullptr ); 363 &fDescriptorSets[fStartDS], 0, nullptr );
366 } 364 }
367 } 365 }
368 366
369 void GrVkPipelineState::addUniformResources(GrVkCommandBuffer& commandBuffer) { 367 void GrVkPipelineState::addUniformResources(GrVkCommandBuffer& commandBuffer) {
370 if (fSamplerPoolManager.fPool) { 368 if (fSamplerPoolManager.fPool) {
371 commandBuffer.addResource(fSamplerPoolManager.fPool); 369 commandBuffer.addResource(fSamplerPoolManager.fPool);
372 } 370 }
373 if (fCurrentUniformDescPool) { 371
374 commandBuffer.addResource(fCurrentUniformDescPool); 372 if (fUniformDescriptorSet) {
373 commandBuffer.addRecycledResource(fUniformDescriptorSet);
375 } 374 }
376 375
377 if (fVertexUniformBuffer.get()) { 376 if (fVertexUniformBuffer.get()) {
378 commandBuffer.addResource(fVertexUniformBuffer->resource()); 377 commandBuffer.addResource(fVertexUniformBuffer->resource());
379 } 378 }
380 if (fFragmentUniformBuffer.get()) { 379 if (fFragmentUniformBuffer.get()) {
381 commandBuffer.addResource(fFragmentUniformBuffer->resource()); 380 commandBuffer.addResource(fFragmentUniformBuffer->resource());
382 } 381 }
383 for (int i = 0; i < fSamplers.count(); ++i) { 382 for (int i = 0; i < fSamplers.count(); ++i) {
384 commandBuffer.addResource(fSamplers[i]); 383 commandBuffer.addResource(fSamplers[i]);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 491
493 b.add32(get_blend_info_key(pipeline)); 492 b.add32(get_blend_info_key(pipeline));
494 493
495 b.add32(primitiveType); 494 b.add32(primitiveType);
496 495
497 // Set key length 496 // Set key length
498 int keyLength = key->count(); 497 int keyLength = key->count();
499 SkASSERT(0 == (keyLength % 4)); 498 SkASSERT(0 == (keyLength % 4));
500 *reinterpret_cast<uint32_t*>(key->begin()) = SkToU32(keyLength); 499 *reinterpret_cast<uint32_t*>(key->begin()) = SkToU32(keyLength);
501 } 500 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkPipelineState.h ('k') | src/gpu/vk/GrVkResource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698