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

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

Issue 1816153002: Set up cache in vulkan to reuse GrVkPrograms (aka VkPipelines) (Closed) Base URL: https://skia.googlesource.com/skia.git@progSamplers
Patch Set: rebase Created 4 years, 9 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/GrVkPipelineStateBuilder.h ('k') | src/gpu/vk/GrVkPipelineStateCache.cpp » ('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 "vk/GrVkProgramBuilder.h" 8 #include "vk/GrVkPipelineStateBuilder.h"
9 9
10 #include "vk/GrVkGpu.h" 10 #include "vk/GrVkGpu.h"
11 #include "vk/GrVkRenderPass.h" 11 #include "vk/GrVkRenderPass.h"
12 #include "vk/GrVkProgram.h"
13 12
14 GrVkProgram* GrVkProgramBuilder::CreateProgram(GrVkGpu* gpu, 13 GrVkPipelineState* GrVkPipelineStateBuilder::CreatePipelineState(
15 const GrPipeline& pipeline, 14 GrVkGpu* gpu,
16 const GrPrimitiveProcessor& primP roc, 15 const GrPipeline& pipeline,
17 GrPrimitiveType primitiveType, 16 const GrPrimitive Processor& primProc,
18 const GrVkProgramDesc& desc, 17 GrPrimitiveType p rimitiveType,
19 const GrVkRenderPass& renderPass) { 18 const GrVkPipelin eState::Desc& desc,
19 const GrVkRenderP ass& renderPass) {
20 // create a builder. This will be handed off to effects so they can use it to add 20 // create a builder. This will be handed off to effects so they can use it to add
21 // uniforms, varyings, textures, etc 21 // uniforms, varyings, textures, etc
22 GrVkProgramBuilder builder(gpu, pipeline, primProc, desc); 22 GrVkPipelineStateBuilder builder(gpu, pipeline, primProc, desc.fProgramDesc) ;
23 23
24 GrGLSLExpr4 inputColor; 24 GrGLSLExpr4 inputColor;
25 GrGLSLExpr4 inputCoverage; 25 GrGLSLExpr4 inputCoverage;
26 26
27 if (!builder.emitAndInstallProcs(&inputColor, &inputCoverage)) { 27 if (!builder.emitAndInstallProcs(&inputColor, &inputCoverage)) {
28 builder.cleanupFragmentProcessors(); 28 builder.cleanupFragmentProcessors();
29 return nullptr; 29 return nullptr;
30 } 30 }
31 31
32 return builder.finalize(primitiveType, renderPass); 32 return builder.finalize(primitiveType, renderPass, desc);
33 } 33 }
34 34
35 GrVkProgramBuilder::GrVkProgramBuilder(GrVkGpu* gpu, 35 GrVkPipelineStateBuilder::GrVkPipelineStateBuilder(GrVkGpu* gpu,
36 const GrPipeline& pipeline, 36 const GrPipeline& pipeline,
37 const GrPrimitiveProcessor& primProc, 37 const GrPrimitiveProcessor& p rimProc,
38 const GrVkProgramDesc& desc) 38 const GrVkProgramDesc& desc)
39 : INHERITED(pipeline, primProc, desc) 39 : INHERITED(pipeline, primProc, desc)
40 , fGpu(gpu) 40 , fGpu(gpu)
41 , fVaryingHandler(this) 41 , fVaryingHandler(this)
42 , fUniformHandler(this) { 42 , fUniformHandler(this) {
43 } 43 }
44 44
45 const GrCaps* GrVkProgramBuilder::caps() const { 45 const GrCaps* GrVkPipelineStateBuilder::caps() const {
46 return fGpu->caps(); 46 return fGpu->caps();
47 } 47 }
48 const GrGLSLCaps* GrVkProgramBuilder::glslCaps() const { 48 const GrGLSLCaps* GrVkPipelineStateBuilder::glslCaps() const {
49 return fGpu->vkCaps().glslCaps(); 49 return fGpu->vkCaps().glslCaps();
50 } 50 }
51 51
52 void GrVkProgramBuilder::finalizeFragmentOutputColor(GrGLSLShaderVar& outputColo r) { 52 void GrVkPipelineStateBuilder::finalizeFragmentOutputColor(GrGLSLShaderVar& outp utColor) {
53 outputColor.setLayoutQualifier("location = 0"); 53 outputColor.setLayoutQualifier("location = 0");
54 } 54 }
55 55
56 VkShaderStageFlags visibility_to_vk_stage_flags(uint32_t visibility) { 56 VkShaderStageFlags visibility_to_vk_stage_flags(uint32_t visibility) {
57 VkShaderStageFlags flags = 0; 57 VkShaderStageFlags flags = 0;
58 58
59 if (visibility & kVertex_GrShaderFlag) { 59 if (visibility & kVertex_GrShaderFlag) {
60 flags |= VK_SHADER_STAGE_VERTEX_BIT; 60 flags |= VK_SHADER_STAGE_VERTEX_BIT;
61 } 61 }
62 if (visibility & kGeometry_GrShaderFlag) { 62 if (visibility & kGeometry_GrShaderFlag) {
63 flags |= VK_SHADER_STAGE_GEOMETRY_BIT; 63 flags |= VK_SHADER_STAGE_GEOMETRY_BIT;
64 } 64 }
65 if (visibility & kFragment_GrShaderFlag) { 65 if (visibility & kFragment_GrShaderFlag) {
66 flags |= VK_SHADER_STAGE_FRAGMENT_BIT; 66 flags |= VK_SHADER_STAGE_FRAGMENT_BIT;
67 } 67 }
68 return flags; 68 return flags;
69 } 69 }
70 70
71 shaderc_shader_kind vk_shader_stage_to_shaderc_kind(VkShaderStageFlagBits stage) { 71 shaderc_shader_kind vk_shader_stage_to_shaderc_kind(VkShaderStageFlagBits stage) {
72 if (VK_SHADER_STAGE_VERTEX_BIT == stage) { 72 if (VK_SHADER_STAGE_VERTEX_BIT == stage) {
73 return shaderc_glsl_vertex_shader; 73 return shaderc_glsl_vertex_shader;
74 } 74 }
75 SkASSERT(VK_SHADER_STAGE_FRAGMENT_BIT == stage); 75 SkASSERT(VK_SHADER_STAGE_FRAGMENT_BIT == stage);
76 return shaderc_glsl_fragment_shader; 76 return shaderc_glsl_fragment_shader;
77 } 77 }
78 78
79 bool GrVkProgramBuilder::CreateVkShaderModule(const GrVkGpu* gpu, 79 bool GrVkPipelineStateBuilder::CreateVkShaderModule(const GrVkGpu* gpu,
80 VkShaderStageFlagBits stage, 80 VkShaderStageFlagBits stage,
81 const GrGLSLShaderBuilder& builder , 81 const GrGLSLShaderBuilder& b uilder,
82 VkShaderModule* shaderModule, 82 VkShaderModule* shaderModule ,
83 VkPipelineShaderStageCreateInfo* s tageInfo) { 83 VkPipelineShaderStageCreateI nfo* stageInfo) {
84 SkString shaderString; 84 SkString shaderString;
85 for (int i = 0; i < builder.fCompilerStrings.count(); ++i) { 85 for (int i = 0; i < builder.fCompilerStrings.count(); ++i) {
86 if (builder.fCompilerStrings[i]) { 86 if (builder.fCompilerStrings[i]) {
87 shaderString.append(builder.fCompilerStrings[i]); 87 shaderString.append(builder.fCompilerStrings[i]);
88 shaderString.append("\n"); 88 shaderString.append("\n");
89 } 89 }
90 } 90 }
91 91
92 shaderc_compiler_t compiler = gpu->shadercCompiler(); 92 shaderc_compiler_t compiler = gpu->shadercCompiler();
93 93
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 stageInfo->pNext = nullptr; 133 stageInfo->pNext = nullptr;
134 stageInfo->flags = 0; 134 stageInfo->flags = 0;
135 stageInfo->stage = stage; 135 stageInfo->stage = stage;
136 stageInfo->module = *shaderModule; 136 stageInfo->module = *shaderModule;
137 stageInfo->pName = "main"; 137 stageInfo->pName = "main";
138 stageInfo->pSpecializationInfo = nullptr; 138 stageInfo->pSpecializationInfo = nullptr;
139 139
140 return true; 140 return true;
141 } 141 }
142 142
143 GrVkProgram* GrVkProgramBuilder::finalize(GrPrimitiveType primitiveType, 143 GrVkPipelineState* GrVkPipelineStateBuilder::finalize(GrPrimitiveType primitiveT ype,
144 const GrVkRenderPass& renderPass) { 144 const GrVkRenderPass& rend erPass,
145 const GrVkPipelineState::D esc& desc) {
145 VkDescriptorSetLayout dsLayout[2]; 146 VkDescriptorSetLayout dsLayout[2];
146 VkPipelineLayout pipelineLayout; 147 VkPipelineLayout pipelineLayout;
147 VkShaderModule vertShaderModule; 148 VkShaderModule vertShaderModule;
148 VkShaderModule fragShaderModule; 149 VkShaderModule fragShaderModule;
149 150
150 uint32_t numSamplers = fSamplerUniforms.count(); 151 uint32_t numSamplers = fSamplerUniforms.count();
151 152
152 SkAutoTDeleteArray<VkDescriptorSetLayoutBinding> dsSamplerBindings( 153 SkAutoTDeleteArray<VkDescriptorSetLayoutBinding> dsSamplerBindings(
153 new VkDescriptorSetLayoutBi nding[numSamplers]); 154 new VkDescriptorSetLayoutBi nding[numSamplers]);
154 for (uint32_t i = 0; i < numSamplers; ++i) { 155 for (uint32_t i = 0; i < numSamplers; ++i) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 if (!pipeline) { 266 if (!pipeline) {
266 GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineLayout(fGpu->device(), pi pelineLayout, 267 GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineLayout(fGpu->device(), pi pelineLayout,
267 nullptr)); 268 nullptr));
268 GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorSetLayout(fGpu->device( ), dsLayout[0], 269 GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorSetLayout(fGpu->device( ), dsLayout[0],
269 nullptr)); 270 nullptr));
270 GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorSetLayout(fGpu->device( ), dsLayout[1], 271 GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorSetLayout(fGpu->device( ), dsLayout[1],
271 nullptr)); 272 nullptr));
272 return nullptr; 273 return nullptr;
273 } 274 }
274 275
275 return new GrVkProgram(fGpu, 276 return new GrVkPipelineState(fGpu,
276 pipeline, 277 desc,
277 pipelineLayout, 278 pipeline,
278 dsLayout, 279 pipelineLayout,
279 fUniformHandles, 280 dsLayout,
280 fUniformHandler.fUniforms, 281 fUniformHandles,
281 fUniformHandler.fCurrentVertexUBOOffset, 282 fUniformHandler.fUniforms,
282 fUniformHandler.fCurrentFragmentUBOOffset, 283 fUniformHandler.fCurrentVertexUBOOffset,
283 numSamplers, 284 fUniformHandler.fCurrentFragmentUBOOffset,
284 fGeometryProcessor, 285 numSamplers,
285 fXferProcessor, 286 fGeometryProcessor,
286 fFragmentProcessors); 287 fXferProcessor,
288 fFragmentProcessors);
287 } 289 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkPipelineStateBuilder.h ('k') | src/gpu/vk/GrVkPipelineStateCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698