| 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 "vk/GrVkPipelineStateBuilder.h" | 8 #include "vk/GrVkPipelineStateBuilder.h" |
| 9 | 9 |
| 10 #include "vk/GrVkDescriptorSetManager.h" |
| 10 #include "vk/GrVkGpu.h" | 11 #include "vk/GrVkGpu.h" |
| 11 #include "vk/GrVkRenderPass.h" | 12 #include "vk/GrVkRenderPass.h" |
| 12 #if USE_SKSL | 13 #if USE_SKSL |
| 13 #include "SkSLCompiler.h" | 14 #include "SkSLCompiler.h" |
| 14 #endif | 15 #endif |
| 15 | 16 |
| 16 GrVkPipelineState* GrVkPipelineStateBuilder::CreatePipelineState( | 17 GrVkPipelineState* GrVkPipelineStateBuilder::CreatePipelineState( |
| 17 GrVkGpu* gpu, | 18 GrVkGpu* gpu, |
| 18 const GrPipeline&
pipeline, | 19 const GrPipeline&
pipeline, |
| 19 const GrPrimitive
Processor& primProc, | 20 const GrPrimitive
Processor& primProc, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 54 } |
| 54 | 55 |
| 55 void GrVkPipelineStateBuilder::finalizeFragmentOutputColor(GrGLSLShaderVar& outp
utColor) { | 56 void GrVkPipelineStateBuilder::finalizeFragmentOutputColor(GrGLSLShaderVar& outp
utColor) { |
| 56 outputColor.setLayoutQualifier("location = 0, index = 0"); | 57 outputColor.setLayoutQualifier("location = 0, index = 0"); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void GrVkPipelineStateBuilder::finalizeFragmentSecondaryColor(GrGLSLShaderVar& o
utputColor) { | 60 void GrVkPipelineStateBuilder::finalizeFragmentSecondaryColor(GrGLSLShaderVar& o
utputColor) { |
| 60 outputColor.setLayoutQualifier("location = 0, index = 1"); | 61 outputColor.setLayoutQualifier("location = 0, index = 1"); |
| 61 } | 62 } |
| 62 | 63 |
| 63 VkShaderStageFlags visibility_to_vk_stage_flags(uint32_t visibility) { | |
| 64 VkShaderStageFlags flags = 0; | |
| 65 | |
| 66 if (visibility & kVertex_GrShaderFlag) { | |
| 67 flags |= VK_SHADER_STAGE_VERTEX_BIT; | |
| 68 } | |
| 69 if (visibility & kGeometry_GrShaderFlag) { | |
| 70 flags |= VK_SHADER_STAGE_GEOMETRY_BIT; | |
| 71 } | |
| 72 if (visibility & kFragment_GrShaderFlag) { | |
| 73 flags |= VK_SHADER_STAGE_FRAGMENT_BIT; | |
| 74 } | |
| 75 return flags; | |
| 76 } | |
| 77 | |
| 78 #if USE_SKSL | 64 #if USE_SKSL |
| 79 SkSL::Program::Kind vk_shader_stage_to_skiasl_kind(VkShaderStageFlagBits stage)
{ | 65 SkSL::Program::Kind vk_shader_stage_to_skiasl_kind(VkShaderStageFlagBits stage)
{ |
| 80 if (VK_SHADER_STAGE_VERTEX_BIT == stage) { | 66 if (VK_SHADER_STAGE_VERTEX_BIT == stage) { |
| 81 return SkSL::Program::kVertex_Kind; | 67 return SkSL::Program::kVertex_Kind; |
| 82 } | 68 } |
| 83 SkASSERT(VK_SHADER_STAGE_FRAGMENT_BIT == stage); | 69 SkASSERT(VK_SHADER_STAGE_FRAGMENT_BIT == stage); |
| 84 return SkSL::Program::kFragment_Kind; | 70 return SkSL::Program::kFragment_Kind; |
| 85 } | 71 } |
| 86 #else | 72 #else |
| 87 shaderc_shader_kind vk_shader_stage_to_shaderc_kind(VkShaderStageFlagBits stage)
{ | 73 shaderc_shader_kind vk_shader_stage_to_shaderc_kind(VkShaderStageFlagBits stage)
{ |
| (...skipping 29 matching lines...) Expand all Loading... |
| 117 #else | 103 #else |
| 118 shaderc_compilation_result_t result = nullptr; | 104 shaderc_compilation_result_t result = nullptr; |
| 119 #endif | 105 #endif |
| 120 | 106 |
| 121 if (gpu->vkCaps().canUseGLSLForShaderModule()) { | 107 if (gpu->vkCaps().canUseGLSLForShaderModule()) { |
| 122 moduleCreateInfo.codeSize = strlen(shaderString.c_str()); | 108 moduleCreateInfo.codeSize = strlen(shaderString.c_str()); |
| 123 moduleCreateInfo.pCode = (const uint32_t*)shaderString.c_str(); | 109 moduleCreateInfo.pCode = (const uint32_t*)shaderString.c_str(); |
| 124 } else { | 110 } else { |
| 125 | 111 |
| 126 #if USE_SKSL | 112 #if USE_SKSL |
| 127 bool result = gpu->shaderCompiler()->toSPIRV(vk_shader_stage_to_skiasl_k
ind(stage), | 113 bool result = gpu->shaderCompiler()->toSPIRV(vk_shader_stage_to_skiasl_k
ind(stage), |
| 128 std::string(shaderString.c_
str()), | 114 std::string(shaderString.c_
str()), |
| 129 &code); | 115 &code); |
| 130 if (!result) { | 116 if (!result) { |
| 131 SkDebugf("%s\n", gpu->shaderCompiler()->errorText().c_str()); | 117 SkDebugf("%s\n", gpu->shaderCompiler()->errorText().c_str()); |
| 132 return false; | 118 return false; |
| 133 } | 119 } |
| 134 moduleCreateInfo.codeSize = code.size(); | 120 moduleCreateInfo.codeSize = code.size(); |
| 135 moduleCreateInfo.pCode = (const uint32_t*) code.c_str(); | 121 moduleCreateInfo.pCode = (const uint32_t*) code.c_str(); |
| 136 #else | 122 #else |
| 137 shaderc_compiler_t compiler = gpu->shadercCompiler(); | 123 shaderc_compiler_t compiler = gpu->shadercCompiler(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 173 } |
| 188 | 174 |
| 189 GrVkPipelineState* GrVkPipelineStateBuilder::finalize(GrPrimitiveType primitiveT
ype, | 175 GrVkPipelineState* GrVkPipelineStateBuilder::finalize(GrPrimitiveType primitiveT
ype, |
| 190 const GrVkRenderPass& rend
erPass, | 176 const GrVkRenderPass& rend
erPass, |
| 191 const GrVkPipelineState::D
esc& desc) { | 177 const GrVkPipelineState::D
esc& desc) { |
| 192 VkDescriptorSetLayout dsLayout[2]; | 178 VkDescriptorSetLayout dsLayout[2]; |
| 193 VkPipelineLayout pipelineLayout; | 179 VkPipelineLayout pipelineLayout; |
| 194 VkShaderModule vertShaderModule; | 180 VkShaderModule vertShaderModule; |
| 195 VkShaderModule fragShaderModule; | 181 VkShaderModule fragShaderModule; |
| 196 | 182 |
| 197 uint32_t numSamplers = (uint32_t)fUniformHandler.numSamplers(); | 183 GrVkResourceProvider& resourceProvider = fGpu->resourceProvider(); |
| 184 // This layout is not owned by the PipelineStateBuilder and thus should no b
e destroyed |
| 185 dsLayout[GrVkUniformHandler::kUniformBufferDescSet] = resourceProvider.getUn
iformDSLayout(); |
| 198 | 186 |
| 199 SkAutoTDeleteArray<VkDescriptorSetLayoutBinding> dsSamplerBindings( | 187 GrVkDescriptorSetManager::Handle samplerDSHandle; |
| 200 new VkDescriptorSetLayoutBi
nding[numSamplers]); | 188 resourceProvider.getSamplerDescriptorSetHandle(fUniformHandler, &samplerDSHa
ndle); |
| 201 for (uint32_t i = 0; i < numSamplers; ++i) { | 189 dsLayout[GrVkUniformHandler::kSamplerDescSet] = |
| 202 const GrVkGLSLSampler& sampler = | 190 resourceProvider.getSamplerDSLayout(samplerDSHandle); |
| 203 static_cast<const GrVkGLSLSampler&>(fUniformHandler.getSampler(i)); | |
| 204 SkASSERT(sampler.binding() == i); | |
| 205 dsSamplerBindings[i].binding = sampler.binding(); | |
| 206 dsSamplerBindings[i].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_
SAMPLER; | |
| 207 dsSamplerBindings[i].descriptorCount = 1; | |
| 208 dsSamplerBindings[i].stageFlags = visibility_to_vk_stage_flags(sampler.v
isibility()); | |
| 209 dsSamplerBindings[i].pImmutableSamplers = nullptr; | |
| 210 } | |
| 211 | |
| 212 VkDescriptorSetLayoutCreateInfo dsSamplerLayoutCreateInfo; | |
| 213 memset(&dsSamplerLayoutCreateInfo, 0, sizeof(VkDescriptorSetLayoutCreateInfo
)); | |
| 214 dsSamplerLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CR
EATE_INFO; | |
| 215 dsSamplerLayoutCreateInfo.pNext = nullptr; | |
| 216 dsSamplerLayoutCreateInfo.flags = 0; | |
| 217 dsSamplerLayoutCreateInfo.bindingCount = numSamplers; | |
| 218 // Setting to nullptr fixes an error in the param checker validation layer.
Even though | |
| 219 // bindingCount is 0 (which is valid), it still tries to validate pBindings
unless it is null. | |
| 220 dsSamplerLayoutCreateInfo.pBindings = numSamplers ? dsSamplerBindings.get()
: nullptr; | |
| 221 | |
| 222 GR_VK_CALL_ERRCHECK(fGpu->vkInterface(), | |
| 223 CreateDescriptorSetLayout(fGpu->device(), | |
| 224 &dsSamplerLayoutCreateInfo, | |
| 225 nullptr, | |
| 226 &dsLayout[GrVkUniformHandler::
kSamplerDescSet])); | |
| 227 | |
| 228 // This layout is not owned by the PipelineStateBuilder and thus should no b
e destroyed | |
| 229 dsLayout[GrVkUniformHandler::kUniformBufferDescSet] = fGpu->resourceProvider
().getUniDSLayout(); | |
| 230 | 191 |
| 231 // Create the VkPipelineLayout | 192 // Create the VkPipelineLayout |
| 232 VkPipelineLayoutCreateInfo layoutCreateInfo; | 193 VkPipelineLayoutCreateInfo layoutCreateInfo; |
| 233 memset(&layoutCreateInfo, 0, sizeof(VkPipelineLayoutCreateFlags)); | 194 memset(&layoutCreateInfo, 0, sizeof(VkPipelineLayoutCreateFlags)); |
| 234 layoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; | 195 layoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 235 layoutCreateInfo.pNext = 0; | 196 layoutCreateInfo.pNext = 0; |
| 236 layoutCreateInfo.flags = 0; | 197 layoutCreateInfo.flags = 0; |
| 237 layoutCreateInfo.setLayoutCount = 2; | 198 layoutCreateInfo.setLayoutCount = 2; |
| 238 layoutCreateInfo.pSetLayouts = dsLayout; | 199 layoutCreateInfo.pSetLayouts = dsLayout; |
| 239 layoutCreateInfo.pushConstantRangeCount = 0; | 200 layoutCreateInfo.pushConstantRangeCount = 0; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 259 fVS, | 220 fVS, |
| 260 &vertShaderModule, | 221 &vertShaderModule, |
| 261 &shaderStageInfo[0])); | 222 &shaderStageInfo[0])); |
| 262 | 223 |
| 263 SkAssertResult(CreateVkShaderModule(fGpu, | 224 SkAssertResult(CreateVkShaderModule(fGpu, |
| 264 VK_SHADER_STAGE_FRAGMENT_BIT, | 225 VK_SHADER_STAGE_FRAGMENT_BIT, |
| 265 fFS, | 226 fFS, |
| 266 &fragShaderModule, | 227 &fragShaderModule, |
| 267 &shaderStageInfo[1])); | 228 &shaderStageInfo[1])); |
| 268 | 229 |
| 269 GrVkResourceProvider& resourceProvider = fGpu->resourceProvider(); | |
| 270 GrVkPipeline* pipeline = resourceProvider.createPipeline(fPipeline, | 230 GrVkPipeline* pipeline = resourceProvider.createPipeline(fPipeline, |
| 271 fPrimProc, | 231 fPrimProc, |
| 272 shaderStageInfo, | 232 shaderStageInfo, |
| 273 2, | 233 2, |
| 274 primitiveType, | 234 primitiveType, |
| 275 renderPass, | 235 renderPass, |
| 276 pipelineLayout); | 236 pipelineLayout); |
| 277 GR_VK_CALL(fGpu->vkInterface(), DestroyShaderModule(fGpu->device(), vertShad
erModule, | 237 GR_VK_CALL(fGpu->vkInterface(), DestroyShaderModule(fGpu->device(), vertShad
erModule, |
| 278 nullptr)); | 238 nullptr)); |
| 279 GR_VK_CALL(fGpu->vkInterface(), DestroyShaderModule(fGpu->device(), fragShad
erModule, | 239 GR_VK_CALL(fGpu->vkInterface(), DestroyShaderModule(fGpu->device(), fragShad
erModule, |
| 280 nullptr)); | 240 nullptr)); |
| 281 | 241 |
| 282 if (!pipeline) { | 242 if (!pipeline) { |
| 283 GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineLayout(fGpu->device(), pi
pelineLayout, | 243 GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineLayout(fGpu->device(), pi
pelineLayout, |
| 284 nullptr)); | 244 nullptr)); |
| 285 GR_VK_CALL(fGpu->vkInterface(), | 245 GR_VK_CALL(fGpu->vkInterface(), |
| 286 DestroyDescriptorSetLayout(fGpu->device(), | 246 DestroyDescriptorSetLayout(fGpu->device(), |
| 287 dsLayout[GrVkUniformHandler::kSamp
lerDescSet], | 247 dsLayout[GrVkUniformHandler::kSamp
lerDescSet], |
| 288 nullptr)); | 248 nullptr)); |
| 289 | 249 |
| 290 this->cleanupFragmentProcessors(); | 250 this->cleanupFragmentProcessors(); |
| 291 return nullptr; | 251 return nullptr; |
| 292 } | 252 } |
| 293 | 253 |
| 294 return new GrVkPipelineState(fGpu, | 254 return new GrVkPipelineState(fGpu, |
| 295 desc, | 255 desc, |
| 296 pipeline, | 256 pipeline, |
| 297 pipelineLayout, | 257 pipelineLayout, |
| 298 dsLayout[GrVkUniformHandler::kSamplerDescSet], | 258 samplerDSHandle, |
| 299 fUniformHandles, | 259 fUniformHandles, |
| 300 fUniformHandler.fUniforms, | 260 fUniformHandler.fUniforms, |
| 301 fUniformHandler.fCurrentVertexUBOOffset, | 261 fUniformHandler.fCurrentVertexUBOOffset, |
| 302 fUniformHandler.fCurrentFragmentUBOOffset, | 262 fUniformHandler.fCurrentFragmentUBOOffset, |
| 303 numSamplers, | 263 (uint32_t)fUniformHandler.numSamplers(), |
| 304 fGeometryProcessor, | 264 fGeometryProcessor, |
| 305 fXferProcessor, | 265 fXferProcessor, |
| 306 fFragmentProcessors); | 266 fFragmentProcessors); |
| 307 } | 267 } |
| 268 |
| OLD | NEW |