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

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

Issue 2355493002: Move vulkan spir-v compile call to GrVkUtil (Closed)
Patch Set: Created 4 years, 3 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/GrVkUtil.h ('k') | no next file » | 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 2015 Google Inc. 2 * Copyright 2015 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 "GrVkUtil.h" 8 #include "GrVkUtil.h"
9 9
10 #include "vk/GrVkGpu.h"
11 #if USE_SKSL
12 #include "SkSLCompiler.h"
13 #endif
14
10 bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format) { 15 bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format) {
11 VkFormat dontCare; 16 VkFormat dontCare;
12 if (!format) { 17 if (!format) {
13 format = &dontCare; 18 format = &dontCare;
14 } 19 }
15 20
16 switch (config) { 21 switch (config) {
17 case kRGBA_8888_GrPixelConfig: 22 case kRGBA_8888_GrPixelConfig:
18 *format = VK_FORMAT_R8G8B8A8_UNORM; 23 *format = VK_FORMAT_R8G8B8A8_UNORM;
19 break; 24 break;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 case 32: 247 case 32:
243 *vkSamples = VK_SAMPLE_COUNT_32_BIT; 248 *vkSamples = VK_SAMPLE_COUNT_32_BIT;
244 return true; 249 return true;
245 case 64: 250 case 64:
246 *vkSamples = VK_SAMPLE_COUNT_64_BIT; 251 *vkSamples = VK_SAMPLE_COUNT_64_BIT;
247 return true; 252 return true;
248 default: 253 default:
249 return false; 254 return false;
250 } 255 }
251 } 256 }
257
258 #if USE_SKSL
259 SkSL::Program::Kind vk_shader_stage_to_skiasl_kind(VkShaderStageFlagBits stage) {
260 if (VK_SHADER_STAGE_VERTEX_BIT == stage) {
261 return SkSL::Program::kVertex_Kind;
262 }
263 SkASSERT(VK_SHADER_STAGE_FRAGMENT_BIT == stage);
264 return SkSL::Program::kFragment_Kind;
265 }
266 #else
267 shaderc_shader_kind vk_shader_stage_to_shaderc_kind(VkShaderStageFlagBits stage) {
268 if (VK_SHADER_STAGE_VERTEX_BIT == stage) {
269 return shaderc_glsl_vertex_shader;
270 }
271 SkASSERT(VK_SHADER_STAGE_FRAGMENT_BIT == stage);
272 return shaderc_glsl_fragment_shader;
273 }
274 #endif
275
276 bool GrCompileVkShaderModule(const GrVkGpu* gpu,
277 const char* shaderString,
278 VkShaderStageFlagBits stage,
279 VkShaderModule* shaderModule,
280 VkPipelineShaderStageCreateInfo* stageInfo) {
281 VkShaderModuleCreateInfo moduleCreateInfo;
282 memset(&moduleCreateInfo, 0, sizeof(VkShaderModuleCreateInfo));
283 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
284 moduleCreateInfo.pNext = nullptr;
285 moduleCreateInfo.flags = 0;
286
287 #if USE_SKSL
288 std::string code;
289 #else
290 shaderc_compilation_result_t result = nullptr;
291 #endif
292
293 if (gpu->vkCaps().canUseGLSLForShaderModule()) {
294 moduleCreateInfo.codeSize = strlen(shaderString);
295 moduleCreateInfo.pCode = (const uint32_t*)shaderString;
296 } else {
297
298 #if USE_SKSL
299 bool result = gpu->shaderCompiler()->toSPIRV(vk_shader_stage_to_skiasl_k ind(stage),
300 std::string(shaderString),
301 &code);
302 if (!result) {
303 SkDebugf("%s\n", gpu->shaderCompiler()->errorText().c_str());
304 return false;
305 }
306 moduleCreateInfo.codeSize = code.size();
307 moduleCreateInfo.pCode = (const uint32_t*)code.c_str();
308 #else
309 shaderc_compiler_t compiler = gpu->shadercCompiler();
310
311 shaderc_compile_options_t options = shaderc_compile_options_initialize() ;
312
313 shaderc_shader_kind shadercStage = vk_shader_stage_to_shaderc_kind(stage );
314 result = shaderc_compile_into_spv(compiler,
315 shaderString.c_str(),
316 strlen(shaderString),
317 shadercStage,
318 "shader",
319 "main",
320 options);
321 shaderc_compile_options_release(options);
322 #ifdef SK_DEBUG
323 if (shaderc_result_get_num_errors(result)) {
324 SkDebugf("%s\n", shaderString);
325 SkDebugf("%s\n", shaderc_result_get_error_message(result));
326 return false;
327 }
328 #endif // SK_DEBUG
329
330 moduleCreateInfo.codeSize = shaderc_result_get_length(result);
331 moduleCreateInfo.pCode = (const uint32_t*)shaderc_result_get_bytes(resul t);
332 #endif // USE_SKSL
333 }
334
335 VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateShaderModule(gpu->device (),
336 &moduleCrea teInfo,
337 nullptr,
338 shaderModul e));
339
340 if (!gpu->vkCaps().canUseGLSLForShaderModule()) {
341 #if !USE_SKSL
342 shaderc_result_release(result);
343 #endif
344 }
345 if (err) {
346 return false;
347 }
348
349 memset(stageInfo, 0, sizeof(VkPipelineShaderStageCreateInfo));
350 stageInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
351 stageInfo->pNext = nullptr;
352 stageInfo->flags = 0;
353 stageInfo->stage = stage;
354 stageInfo->module = *shaderModule;
355 stageInfo->pName = "main";
356 stageInfo->pSpecializationInfo = nullptr;
357
358 return true;
359 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkUtil.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698