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

Unified Diff: src/gpu/vk/GrVkPipelineStateBuilder.cpp

Issue 1984363002: initial checkin of SkSL compiler (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: fixed CMake build Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/vk/GrVkGpu.cpp ('k') | src/sksl/GLSL.std.450.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/vk/GrVkPipelineStateBuilder.cpp
diff --git a/src/gpu/vk/GrVkPipelineStateBuilder.cpp b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
index a191505a38c89375626622625305b3629278c94a..323ea669463c35b1b897194d54f4ecdbe1a5f3ac 100644
--- a/src/gpu/vk/GrVkPipelineStateBuilder.cpp
+++ b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
@@ -9,6 +9,9 @@
#include "vk/GrVkGpu.h"
#include "vk/GrVkRenderPass.h"
+#if USE_SKSL
+#include "SkSLCompiler.h"
+#endif
GrVkPipelineState* GrVkPipelineStateBuilder::CreatePipelineState(
GrVkGpu* gpu,
@@ -72,6 +75,15 @@ VkShaderStageFlags visibility_to_vk_stage_flags(uint32_t visibility) {
return flags;
}
+#if USE_SKSL
+SkSL::Program::Kind vk_shader_stage_to_skiasl_kind(VkShaderStageFlagBits stage) {
+ if (VK_SHADER_STAGE_VERTEX_BIT == stage) {
+ return SkSL::Program::kVertex_Kind;
+ }
+ SkASSERT(VK_SHADER_STAGE_FRAGMENT_BIT == stage);
+ return SkSL::Program::kFragment_Kind;
+}
+#else
shaderc_shader_kind vk_shader_stage_to_shaderc_kind(VkShaderStageFlagBits stage) {
if (VK_SHADER_STAGE_VERTEX_BIT == stage) {
return shaderc_glsl_vertex_shader;
@@ -79,7 +91,10 @@ shaderc_shader_kind vk_shader_stage_to_shaderc_kind(VkShaderStageFlagBits stage)
SkASSERT(VK_SHADER_STAGE_FRAGMENT_BIT == stage);
return shaderc_glsl_fragment_shader;
}
+#endif
+#include <fstream>
+#include <sstream>
bool GrVkPipelineStateBuilder::CreateVkShaderModule(const GrVkGpu* gpu,
VkShaderStageFlagBits stage,
const GrGLSLShaderBuilder& builder,
@@ -99,13 +114,28 @@ bool GrVkPipelineStateBuilder::CreateVkShaderModule(const GrVkGpu* gpu,
moduleCreateInfo.pNext = nullptr;
moduleCreateInfo.flags = 0;
+#if USE_SKSL
+ std::string code;
+#else
shaderc_compilation_result_t result = nullptr;
+#endif
if (gpu->vkCaps().canUseGLSLForShaderModule()) {
moduleCreateInfo.codeSize = strlen(shaderString.c_str());
moduleCreateInfo.pCode = (const uint32_t*)shaderString.c_str();
} else {
+#if USE_SKSL
+ bool result = gpu->shaderCompiler()->toSPIRV(vk_shader_stage_to_skiasl_kind(stage),
+ std::string(shaderString.c_str()),
+ &code);
+ if (!result) {
+ SkDebugf("%s\n", gpu->shaderCompiler()->errorText().c_str());
+ return false;
+ }
+ moduleCreateInfo.codeSize = code.size();
+ moduleCreateInfo.pCode = (const uint32_t*) code.c_str();
+#else
shaderc_compiler_t compiler = gpu->shadercCompiler();
shaderc_compile_options_t options = shaderc_compile_options_initialize();
@@ -125,18 +155,22 @@ bool GrVkPipelineStateBuilder::CreateVkShaderModule(const GrVkGpu* gpu,
SkDebugf("%s\n", shaderc_result_get_error_message(result));
return false;
}
-#endif
+#endif // SK_DEBUG
moduleCreateInfo.codeSize = shaderc_result_get_length(result);
moduleCreateInfo.pCode = (const uint32_t*)shaderc_result_get_bytes(result);
+#endif // USE_SKSL
}
VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateShaderModule(gpu->device(),
&moduleCreateInfo,
nullptr,
shaderModule));
+
if (!gpu->vkCaps().canUseGLSLForShaderModule()) {
+#if !USE_SKSL
shaderc_result_release(result);
+#endif
}
if (err) {
return false;
« no previous file with comments | « src/gpu/vk/GrVkGpu.cpp ('k') | src/sksl/GLSL.std.450.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698