Hash :
d524157f
Author :
Date :
2022-09-28T23:16:02
GLES1/Vulkan: Don't validate SPIR-V as VVL does the same Improves TexCombine runtime by ~15%. Bug: angleproject:6644 Change-Id: I01f580fef0caa91ebf600cfc0bbbeca1aa20eb06 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3926037 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Wrapper for Khronos glslang compiler. This file is used by Vulkan and Metal backends.
//
#ifndef LIBANGLE_RENDERER_GLSLANG_WRAPPER_UTILS_H_
#define LIBANGLE_RENDERER_GLSLANG_WRAPPER_UTILS_H_
#include <functional>
#include "common/spirv/spirv_types.h"
#include "libANGLE/renderer/ProgramImpl.h"
#include "libANGLE/renderer/renderer_utils.h"
namespace rx
{
class ShaderInterfaceVariableInfoMap;
constexpr gl::ShaderMap<const char *> kDefaultUniformNames = {
{gl::ShaderType::Vertex, sh::vk::kDefaultUniformsNameVS},
{gl::ShaderType::TessControl, sh::vk::kDefaultUniformsNameTCS},
{gl::ShaderType::TessEvaluation, sh::vk::kDefaultUniformsNameTES},
{gl::ShaderType::Geometry, sh::vk::kDefaultUniformsNameGS},
{gl::ShaderType::Fragment, sh::vk::kDefaultUniformsNameFS},
{gl::ShaderType::Compute, sh::vk::kDefaultUniformsNameCS},
};
struct GlslangProgramInterfaceInfo
{
// Uniforms set index:
uint32_t uniformsAndXfbDescriptorSetIndex;
uint32_t currentUniformBindingIndex;
// Textures set index:
uint32_t textureDescriptorSetIndex;
uint32_t currentTextureBindingIndex;
// Other shader resources set index:
uint32_t shaderResourceDescriptorSetIndex;
uint32_t currentShaderResourceBindingIndex;
// ANGLE driver uniforms set index:
uint32_t driverUniformsDescriptorSetIndex;
uint32_t locationsUsedForXfbExtension;
};
struct GlslangSourceOptions
{
bool supportsTransformFeedbackExtension = false;
bool supportsTransformFeedbackEmulation = false;
bool enableTransformFeedbackEmulation = false;
};
struct GlslangSpirvOptions
{
gl::ShaderType shaderType = gl::ShaderType::InvalidEnum;
bool negativeViewportSupported = false;
bool removeDebugInfo = false;
bool isLastPreFragmentStage = false;
bool isTransformFeedbackStage = false;
bool isTransformFeedbackEmulated = false;
bool isMultisampledFramebufferFetch = false;
bool validate = true;
};
struct UniformBindingInfo final
{
UniformBindingInfo();
UniformBindingInfo(uint32_t bindingIndex,
gl::ShaderBitSet shaderBitSet,
gl::ShaderType frontShaderType);
uint32_t bindingIndex = 0;
gl::ShaderBitSet shaderBitSet = gl::ShaderBitSet();
gl::ShaderType frontShaderType = gl::ShaderType::InvalidEnum;
};
using UniformBindingIndexMap = angle::HashMap<std::string, UniformBindingInfo>;
struct ShaderInterfaceVariableXfbInfo
{
static constexpr uint32_t kInvalid = std::numeric_limits<uint32_t>::max();
// Used by both extension and emulation
uint32_t buffer = kInvalid;
uint32_t offset = kInvalid;
uint32_t stride = kInvalid;
// Used only by emulation (array index support is missing from VK_EXT_transform_feedback)
uint32_t arraySize = kInvalid;
uint32_t columnCount = kInvalid;
uint32_t rowCount = kInvalid;
uint32_t arrayIndex = kInvalid;
GLenum componentType = GL_FLOAT;
// If empty, the whole array is captured. Otherwise only the specified members are captured.
std::vector<ShaderInterfaceVariableXfbInfo> arrayElements;
};
// Information for each shader interface variable. Not all fields are relevant to each shader
// interface variable. For example opaque uniforms require a set and binding index, while vertex
// attributes require a location.
struct ShaderInterfaceVariableInfo
{
ShaderInterfaceVariableInfo();
static constexpr uint32_t kInvalid = std::numeric_limits<uint32_t>::max();
// Used for interface blocks and opaque uniforms.
uint32_t descriptorSet = kInvalid;
uint32_t binding = kInvalid;
// Used for vertex attributes, fragment shader outputs and varyings. There could be different
// variables that share the same name, such as a vertex attribute and a fragment output. They
// will share this object since they have the same name, but will find possibly different
// locations in their respective slots.
uint32_t location = kInvalid;
uint32_t component = kInvalid;
uint32_t index = kInvalid;
// The stages this shader interface variable is active.
gl::ShaderBitSet activeStages;
// Used for transform feedback extension to decorate vertex shader output.
ShaderInterfaceVariableXfbInfo xfb;
std::vector<ShaderInterfaceVariableXfbInfo> fieldXfb;
// Indicate if varying is input or output, or both (in case of for example gl_Position in a
// geometry shader)
bool builtinIsInput = false;
bool builtinIsOutput = false;
// For vertex attributes, this is the number of components / locations. These are used by the
// vertex attribute aliasing transformation only.
uint8_t attributeComponentCount = 0;
uint8_t attributeLocationCount = 0;
// Indicate if this variable has been deduplicated.
bool isDuplicate = false;
};
bool GetImageNameWithoutIndices(std::string *name);
// Get the mapped sampler name.
std::string GlslangGetMappedSamplerName(const std::string &originalName);
std::string GetXfbBufferName(const uint32_t bufferIndex);
void GlslangAssignLocations(const GlslangSourceOptions &options,
const gl::ProgramExecutable &programExecutable,
const gl::ProgramVaryingPacking &varyingPacking,
const gl::ShaderType shaderType,
const gl::ShaderType frontShaderType,
bool isTransformFeedbackStage,
GlslangProgramInterfaceInfo *programInterfaceInfo,
UniformBindingIndexMap *uniformBindingIndexMapOut,
ShaderInterfaceVariableInfoMap *variableInfoMapOut);
void GlslangAssignTransformFeedbackLocations(gl::ShaderType shaderType,
const gl::ProgramExecutable &programExecutable,
bool isTransformFeedbackStage,
GlslangProgramInterfaceInfo *programInterfaceInfo,
ShaderInterfaceVariableInfoMap *variableInfoMapOut);
// Retrieves the compiled SPIR-V code for each shader stage, and calls |GlslangAssignLocations|.
void GlslangGetShaderSpirvCode(const gl::Context *context,
const GlslangSourceOptions &options,
const gl::ProgramState &programState,
const gl::ProgramLinkedResources &resources,
GlslangProgramInterfaceInfo *programInterfaceInfo,
gl::ShaderMap<const angle::spirv::Blob *> *spirvBlobsOut,
ShaderInterfaceVariableInfoMap *variableInfoMapOut);
angle::Result GlslangTransformSpirvCode(const GlslangSpirvOptions &options,
const ShaderInterfaceVariableInfoMap &variableInfoMap,
const angle::spirv::Blob &initialSpirvBlob,
angle::spirv::Blob *spirvBlobOut);
} // namespace rx
#endif // LIBANGLE_RENDERER_GLSLANG_WRAPPER_UTILS_H_