1 //
2 // Copyright 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // GlslangWrapperVk: Wrapper for Vulkan's glslang compiler.
7 //
8
9 #include "libANGLE/renderer/vulkan/GlslangWrapperVk.h"
10
11 #include "libANGLE/renderer/vulkan/ContextVk.h"
12 #include "libANGLE/renderer/vulkan/vk_cache_utils.h"
13
14 namespace rx
15 {
16 namespace
17 {
ErrorHandler(vk::Context * context,GlslangError)18 angle::Result ErrorHandler(vk::Context *context, GlslangError)
19 {
20 ANGLE_VK_CHECK(context, false, VK_ERROR_INVALID_SHADER_NV);
21 return angle::Result::Stop;
22 }
23
24 } // namespace
25
26 // static
CreateSourceOptions(const angle::FeaturesVk & features)27 GlslangSourceOptions GlslangWrapperVk::CreateSourceOptions(const angle::FeaturesVk &features)
28 {
29 GlslangSourceOptions options;
30
31 options.useOldRewriteStructSamplers = features.forceOldRewriteStructSamplers.enabled;
32 options.supportsTransformFeedbackExtension =
33 features.supportsTransformFeedbackExtension.enabled;
34 options.emulateTransformFeedback = features.emulateTransformFeedback.enabled;
35 options.emulateBresenhamLines = features.basicGLLineRasterization.enabled;
36
37 return options;
38 }
39
40 // static
ResetGlslangProgramInterfaceInfo(GlslangProgramInterfaceInfo * glslangProgramInterfaceInfo)41 void GlslangWrapperVk::ResetGlslangProgramInterfaceInfo(
42 GlslangProgramInterfaceInfo *glslangProgramInterfaceInfo)
43 {
44 glslangProgramInterfaceInfo->uniformsAndXfbDescriptorSetIndex =
45 kUniformsAndXfbDescriptorSetIndex;
46 glslangProgramInterfaceInfo->currentUniformBindingIndex = 0;
47 glslangProgramInterfaceInfo->textureDescriptorSetIndex = kTextureDescriptorSetIndex;
48 glslangProgramInterfaceInfo->currentTextureBindingIndex = 0;
49 glslangProgramInterfaceInfo->shaderResourceDescriptorSetIndex =
50 kShaderResourceDescriptorSetIndex;
51 glslangProgramInterfaceInfo->currentShaderResourceBindingIndex = 0;
52 glslangProgramInterfaceInfo->driverUniformsDescriptorSetIndex =
53 kDriverUniformsDescriptorSetIndex;
54
55 glslangProgramInterfaceInfo->locationsUsedForXfbExtension = 0;
56 }
57
58 // static
GetShaderSource(const angle::FeaturesVk & features,const gl::ProgramState & programState,const gl::ProgramLinkedResources & resources,GlslangProgramInterfaceInfo * programInterfaceInfo,gl::ShaderMap<std::string> * shaderSourcesOut,ShaderMapInterfaceVariableInfoMap * variableInfoMapOut)59 void GlslangWrapperVk::GetShaderSource(const angle::FeaturesVk &features,
60 const gl::ProgramState &programState,
61 const gl::ProgramLinkedResources &resources,
62 GlslangProgramInterfaceInfo *programInterfaceInfo,
63 gl::ShaderMap<std::string> *shaderSourcesOut,
64 ShaderMapInterfaceVariableInfoMap *variableInfoMapOut)
65 {
66 GlslangSourceOptions options = CreateSourceOptions(features);
67 GlslangGetShaderSource(options, programState, resources, programInterfaceInfo, shaderSourcesOut,
68 variableInfoMapOut);
69 }
70
71 // static
GetShaderCode(vk::Context * context,const gl::Caps & glCaps,const gl::ShaderMap<std::string> & shaderSources,const ShaderMapInterfaceVariableInfoMap & variableInfoMap,gl::ShaderMap<std::vector<uint32_t>> * shaderCodeOut)72 angle::Result GlslangWrapperVk::GetShaderCode(
73 vk::Context *context,
74 const gl::Caps &glCaps,
75 const gl::ShaderMap<std::string> &shaderSources,
76 const ShaderMapInterfaceVariableInfoMap &variableInfoMap,
77 gl::ShaderMap<std::vector<uint32_t>> *shaderCodeOut)
78 {
79 return GlslangGetShaderSpirvCode(
80 [context](GlslangError error) { return ErrorHandler(context, error); }, glCaps,
81 shaderSources, variableInfoMap, shaderCodeOut);
82 }
83
84 // static
TransformSpirV(vk::Context * context,const gl::ShaderType shaderType,bool removeEarlyFragmentTestsOptimization,const ShaderInterfaceVariableInfoMap & variableInfoMap,const SpirvBlob & initialSpirvBlob,SpirvBlob * shaderCodeOut)85 angle::Result GlslangWrapperVk::TransformSpirV(
86 vk::Context *context,
87 const gl::ShaderType shaderType,
88 bool removeEarlyFragmentTestsOptimization,
89 const ShaderInterfaceVariableInfoMap &variableInfoMap,
90 const SpirvBlob &initialSpirvBlob,
91 SpirvBlob *shaderCodeOut)
92 {
93 return GlslangTransformSpirvCode(
94 [context](GlslangError error) { return ErrorHandler(context, error); }, shaderType,
95 removeEarlyFragmentTestsOptimization, variableInfoMap, initialSpirvBlob, shaderCodeOut);
96 }
97 } // namespace rx
98