~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/ThirdParty/ANGLE/src/libANGLE/renderer/glslang_wrapper_utils.h

  • Committer: mmach
  • Date: 2023-06-16 17:21:37 UTC
  • Revision ID: netbit73@gmail.com-20230616172137-2rqx6yr96ga9g3kp
1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
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.
 
5
//
 
6
// Wrapper for Khronos glslang compiler. This file is used by Vulkan and Metal backends.
 
7
//
 
8
 
 
9
#ifndef LIBANGLE_RENDERER_GLSLANG_WRAPPER_UTILS_H_
 
10
#define LIBANGLE_RENDERER_GLSLANG_WRAPPER_UTILS_H_
 
11
 
 
12
#include <functional>
 
13
 
 
14
#include "libANGLE/renderer/ProgramImpl.h"
 
15
 
 
16
namespace rx
 
17
{
 
18
enum class GlslangError
 
19
{
 
20
    InvalidShader,
 
21
    InvalidSpirv,
 
22
};
 
23
 
 
24
struct GlslangSourceOptions
 
25
{
 
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;
 
34
 
 
35
    // Binding index start for transform feedback buffers:
 
36
    uint32_t xfbBindingIndexStart = 16;
 
37
 
 
38
    bool useOldRewriteStructSamplers        = false;
 
39
    bool supportsTransformFeedbackExtension = false;
 
40
    bool emulateTransformFeedback           = false;
 
41
    bool emulateBresenhamLines              = false;
 
42
};
 
43
 
 
44
using SpirvBlob = std::vector<uint32_t>;
 
45
 
 
46
using GlslangErrorCallback = std::function<angle::Result(GlslangError)>;
 
47
 
 
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
 
52
{
 
53
    ShaderInterfaceVariableInfo();
 
54
 
 
55
    static constexpr uint32_t kInvalid = std::numeric_limits<uint32_t>::max();
 
56
 
 
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;
 
72
};
 
73
 
 
74
using ShaderInterfaceVariableInfoMap = std::unordered_map<std::string, ShaderInterfaceVariableInfo>;
 
75
 
 
76
void GlslangInitialize();
 
77
void GlslangRelease();
 
78
 
 
79
// Get the mapped sampler name after the soure is transformed by GlslangGetShaderSource()
 
80
std::string GlslangGetMappedSamplerName(const std::string &originalName);
 
81
 
 
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);
 
91
 
 
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);
 
97
 
 
98
}  // namespace rx
 
99
 
 
100
#endif  // LIBANGLE_RENDERER_GLSLANG_WRAPPER_UTILS_H_