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/GrVkGpu.h" | 10 #include "vk/GrVkGpu.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 VkShaderModule* shaderModule
, | 82 VkShaderModule* shaderModule
, |
83 VkPipelineShaderStageCreateI
nfo* stageInfo) { | 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(); | |
93 | |
94 shaderc_compile_options_t options = shaderc_compile_options_initialize(); | |
95 shaderc_compile_options_set_forced_version_profile(options, 140, shaderc_pro
file_none); | |
96 | |
97 shaderc_shader_kind shadercStage = vk_shader_stage_to_shaderc_kind(stage); | |
98 shaderc_compilation_result_t result = shaderc_compile_into_spv(compiler, | |
99 shaderString.
c_str(), | |
100 strlen(shader
String.c_str()), | |
101 shadercStage, | |
102 "shader", | |
103 "main", | |
104 options); | |
105 shaderc_compile_options_release(options); | |
106 #ifdef SK_DEBUG | |
107 if (shaderc_result_get_num_errors(result)) { | |
108 SkDebugf("%s\n", shaderString.c_str()); | |
109 SkDebugf("%s\n", shaderc_result_get_error_message(result)); | |
110 return false; | |
111 } | |
112 #endif | |
113 | |
114 VkShaderModuleCreateInfo moduleCreateInfo; | 92 VkShaderModuleCreateInfo moduleCreateInfo; |
115 memset(&moduleCreateInfo, 0, sizeof(VkShaderModuleCreateInfo)); | 93 memset(&moduleCreateInfo, 0, sizeof(VkShaderModuleCreateInfo)); |
116 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; | 94 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
117 moduleCreateInfo.pNext = nullptr; | 95 moduleCreateInfo.pNext = nullptr; |
118 moduleCreateInfo.flags = 0; | 96 moduleCreateInfo.flags = 0; |
119 moduleCreateInfo.codeSize = shaderc_result_get_length(result); | 97 |
120 moduleCreateInfo.pCode = (const uint32_t*)shaderc_result_get_bytes(result); | 98 shaderc_compilation_result_t result; |
| 99 |
| 100 if (gpu->vkCaps().canUseGLSLForShaderModule()) { |
| 101 moduleCreateInfo.codeSize = strlen(shaderString.c_str()); |
| 102 moduleCreateInfo.pCode = (const uint32_t*)shaderString.c_str(); |
| 103 } else { |
| 104 |
| 105 shaderc_compiler_t compiler = gpu->shadercCompiler(); |
| 106 |
| 107 shaderc_compile_options_t options = shaderc_compile_options_initialize()
; |
| 108 shaderc_compile_options_set_forced_version_profile(options, 140, shaderc
_profile_none); |
| 109 |
| 110 shaderc_shader_kind shadercStage = vk_shader_stage_to_shaderc_kind(stage
); |
| 111 result = shaderc_compile_into_spv(compiler, |
| 112 shaderString.c_str(), |
| 113 strlen(shaderString.c_str()), |
| 114 shadercStage, |
| 115 "shader", |
| 116 "main", |
| 117 options); |
| 118 shaderc_compile_options_release(options); |
| 119 #ifdef SK_DEBUG |
| 120 if (shaderc_result_get_num_errors(result)) { |
| 121 SkDebugf("%s\n", shaderString.c_str()); |
| 122 SkDebugf("%s\n", shaderc_result_get_error_message(result)); |
| 123 return false; |
| 124 } |
| 125 #endif |
| 126 |
| 127 moduleCreateInfo.codeSize = shaderc_result_get_length(result); |
| 128 moduleCreateInfo.pCode = (const uint32_t*)shaderc_result_get_bytes(resul
t); |
| 129 } |
121 | 130 |
122 VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateShaderModule(gpu->device
(), | 131 VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateShaderModule(gpu->device
(), |
123 &moduleCrea
teInfo, | 132 &moduleCrea
teInfo, |
124 nullptr, | 133 nullptr, |
125 shaderModul
e)); | 134 shaderModul
e)); |
126 shaderc_result_release(result); | 135 if (!gpu->vkCaps().canUseGLSLForShaderModule()) { |
| 136 shaderc_result_release(result); |
| 137 } |
127 if (err) { | 138 if (err) { |
128 return false; | 139 return false; |
129 } | 140 } |
130 | 141 |
131 memset(stageInfo, 0, sizeof(VkPipelineShaderStageCreateInfo)); | 142 memset(stageInfo, 0, sizeof(VkPipelineShaderStageCreateInfo)); |
132 stageInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; | 143 stageInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
133 stageInfo->pNext = nullptr; | 144 stageInfo->pNext = nullptr; |
134 stageInfo->flags = 0; | 145 stageInfo->flags = 0; |
135 stageInfo->stage = stage; | 146 stageInfo->stage = stage; |
136 stageInfo->module = *shaderModule; | 147 stageInfo->module = *shaderModule; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 dsLayout, | 291 dsLayout, |
281 fUniformHandles, | 292 fUniformHandles, |
282 fUniformHandler.fUniforms, | 293 fUniformHandler.fUniforms, |
283 fUniformHandler.fCurrentVertexUBOOffset, | 294 fUniformHandler.fCurrentVertexUBOOffset, |
284 fUniformHandler.fCurrentFragmentUBOOffset, | 295 fUniformHandler.fCurrentFragmentUBOOffset, |
285 numSamplers, | 296 numSamplers, |
286 fGeometryProcessor, | 297 fGeometryProcessor, |
287 fXferProcessor, | 298 fXferProcessor, |
288 fFragmentProcessors); | 299 fFragmentProcessors); |
289 } | 300 } |
OLD | NEW |