2
// Copyright 2019 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.
6
// Wrapper for Khronos glslang compiler. This file is used by Vulkan and Metal backends.
9
#ifndef LIBANGLE_RENDERER_GLSLANG_WRAPPER_UTILS_H_
10
#define LIBANGLE_RENDERER_GLSLANG_WRAPPER_UTILS_H_
14
#include "libANGLE/renderer/ProgramImpl.h"
18
enum class GlslangError
24
struct GlslangSourceOptions
26
// Uniforms set index:
27
uint32_t uniformsAndXfbDescriptorSetIndex = 0;
28
// Textures set index:
29
uint32_t textureDescriptorSetIndex = 1;
30
// Other shader resources set index:
31
uint32_t shaderResourceDescriptorSetIndex = 2;
32
// ANGLE driver uniforms set index:
33
uint32_t driverUniformsDescriptorSetIndex = 3;
35
// Binding index start for transform feedback buffers:
36
uint32_t xfbBindingIndexStart = 16;
38
bool useOldRewriteStructSamplers = false;
39
bool supportsTransformFeedbackExtension = false;
40
bool emulateTransformFeedback = false;
41
bool emulateBresenhamLines = false;
44
using SpirvBlob = std::vector<uint32_t>;
46
using GlslangErrorCallback = std::function<angle::Result(GlslangError)>;
48
// Information for each shader interface variable. Not all fields are relevant to each shader
49
// interface variable. For example opaque uniforms require a set and binding index, while vertex
50
// attributes require a location.
51
struct ShaderInterfaceVariableInfo
53
ShaderInterfaceVariableInfo();
55
static constexpr uint32_t kInvalid = std::numeric_limits<uint32_t>::max();
57
// Used for interface blocks and opaque uniforms.
58
uint32_t descriptorSet = kInvalid;
59
uint32_t binding = kInvalid;
60
// Used for vertex attributes, fragment shader outputs and varyings. There could be different
61
// variables that share the same name, such as a vertex attribute and a fragment output. They
62
// will share this object since they have the same name, but will find possibly different
63
// locations in their respective slots.
64
gl::ShaderMap<uint32_t> location;
65
gl::ShaderMap<uint32_t> component;
66
// The stages this shader interface variable is active.
67
gl::ShaderBitSet activeStages;
68
// Used for transform feedback extension to decorate vertex shader output.
69
uint32_t xfbBuffer = kInvalid;
70
uint32_t xfbOffset = kInvalid;
71
uint32_t xfbStride = kInvalid;
74
using ShaderInterfaceVariableInfoMap = std::unordered_map<std::string, ShaderInterfaceVariableInfo>;
76
void GlslangInitialize();
77
void GlslangRelease();
79
// Get the mapped sampler name after the soure is transformed by GlslangGetShaderSource()
80
std::string GlslangGetMappedSamplerName(const std::string &originalName);
82
// Transform the source to include actual binding points for various shader resources (textures,
83
// buffers, xfb, etc). For some variables, these values are instead output to the variableInfoMap
84
// to be set during a SPIR-V transformation. This is a transitory step towards moving all variables
85
// to this map, at which point GlslangGetShaderSpirvCode will also be called by this function.
86
void GlslangGetShaderSource(const GlslangSourceOptions &options,
87
const gl::ProgramState &programState,
88
const gl::ProgramLinkedResources &resources,
89
gl::ShaderMap<std::string> *shaderSourcesOut,
90
ShaderInterfaceVariableInfoMap *variableInfoMapOut);
92
angle::Result GlslangGetShaderSpirvCode(GlslangErrorCallback callback,
93
const gl::Caps &glCaps,
94
const gl::ShaderMap<std::string> &shaderSources,
95
const ShaderInterfaceVariableInfoMap &variableInfoMap,
96
gl::ShaderMap<SpirvBlob> *spirvBlobsOut);
100
#endif // LIBANGLE_RENDERER_GLSLANG_WRAPPER_UTILS_H_