1*8975f5c5SAndroid Build Coastguard Worker // 2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2017 The ANGLE Project Authors. All rights reserved. 3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file. 5*8975f5c5SAndroid Build Coastguard Worker // 6*8975f5c5SAndroid Build Coastguard Worker 7*8975f5c5SAndroid Build Coastguard Worker // ProgramLinkedResources.h: implements link-time checks for default block uniforms, and generates 8*8975f5c5SAndroid Build Coastguard Worker // uniform locations. Populates data structures related to uniforms so that they can be stored in 9*8975f5c5SAndroid Build Coastguard Worker // program state. 10*8975f5c5SAndroid Build Coastguard Worker 11*8975f5c5SAndroid Build Coastguard Worker #ifndef LIBANGLE_UNIFORMLINKER_H_ 12*8975f5c5SAndroid Build Coastguard Worker #define LIBANGLE_UNIFORMLINKER_H_ 13*8975f5c5SAndroid Build Coastguard Worker 14*8975f5c5SAndroid Build Coastguard Worker #include <GLSLANG/ShaderVars.h> 15*8975f5c5SAndroid Build Coastguard Worker 16*8975f5c5SAndroid Build Coastguard Worker #include "angle_gl.h" 17*8975f5c5SAndroid Build Coastguard Worker #include "common/PackedEnums.h" 18*8975f5c5SAndroid Build Coastguard Worker #include "common/angleutils.h" 19*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Uniform.h" 20*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/VaryingPacking.h" 21*8975f5c5SAndroid Build Coastguard Worker 22*8975f5c5SAndroid Build Coastguard Worker #include <functional> 23*8975f5c5SAndroid Build Coastguard Worker 24*8975f5c5SAndroid Build Coastguard Worker namespace sh 25*8975f5c5SAndroid Build Coastguard Worker { 26*8975f5c5SAndroid Build Coastguard Worker class BlockLayoutEncoder; 27*8975f5c5SAndroid Build Coastguard Worker struct BlockMemberInfo; 28*8975f5c5SAndroid Build Coastguard Worker struct InterfaceBlock; 29*8975f5c5SAndroid Build Coastguard Worker struct ShaderVariable; 30*8975f5c5SAndroid Build Coastguard Worker class BlockEncoderVisitor; 31*8975f5c5SAndroid Build Coastguard Worker class ShaderVariableVisitor; 32*8975f5c5SAndroid Build Coastguard Worker struct ShaderVariable; 33*8975f5c5SAndroid Build Coastguard Worker } // namespace sh 34*8975f5c5SAndroid Build Coastguard Worker 35*8975f5c5SAndroid Build Coastguard Worker namespace gl 36*8975f5c5SAndroid Build Coastguard Worker { 37*8975f5c5SAndroid Build Coastguard Worker struct BufferVariable; 38*8975f5c5SAndroid Build Coastguard Worker struct Caps; 39*8975f5c5SAndroid Build Coastguard Worker class Context; 40*8975f5c5SAndroid Build Coastguard Worker class InfoLog; 41*8975f5c5SAndroid Build Coastguard Worker struct InterfaceBlock; 42*8975f5c5SAndroid Build Coastguard Worker enum class LinkMismatchError; 43*8975f5c5SAndroid Build Coastguard Worker class ProgramState; 44*8975f5c5SAndroid Build Coastguard Worker class ProgramPipelineState; 45*8975f5c5SAndroid Build Coastguard Worker class ProgramBindings; 46*8975f5c5SAndroid Build Coastguard Worker class ProgramAliasedBindings; 47*8975f5c5SAndroid Build Coastguard Worker class Shader; 48*8975f5c5SAndroid Build Coastguard Worker struct AtomicCounterBuffer; 49*8975f5c5SAndroid Build Coastguard Worker struct VariableLocation; 50*8975f5c5SAndroid Build Coastguard Worker struct Version; 51*8975f5c5SAndroid Build Coastguard Worker 52*8975f5c5SAndroid Build Coastguard Worker using ShaderUniform = std::pair<ShaderType, const sh::ShaderVariable *>; 53*8975f5c5SAndroid Build Coastguard Worker 54*8975f5c5SAndroid Build Coastguard Worker // The link operation is responsible for finishing the link of uniform and interface blocks. 55*8975f5c5SAndroid Build Coastguard Worker // This way it can filter out unreferenced resources and still have access to the info. 56*8975f5c5SAndroid Build Coastguard Worker // TODO(jmadill): Integrate uniform linking/filtering as well as interface blocks. 57*8975f5c5SAndroid Build Coastguard Worker struct UnusedUniform 58*8975f5c5SAndroid Build Coastguard Worker { UnusedUniformUnusedUniform59*8975f5c5SAndroid Build Coastguard Worker UnusedUniform(std::string name, 60*8975f5c5SAndroid Build Coastguard Worker bool isSampler, 61*8975f5c5SAndroid Build Coastguard Worker bool isImage, 62*8975f5c5SAndroid Build Coastguard Worker bool isAtomicCounter, 63*8975f5c5SAndroid Build Coastguard Worker bool isFragmentInOut) 64*8975f5c5SAndroid Build Coastguard Worker { 65*8975f5c5SAndroid Build Coastguard Worker this->name = name; 66*8975f5c5SAndroid Build Coastguard Worker this->isSampler = isSampler; 67*8975f5c5SAndroid Build Coastguard Worker this->isImage = isImage; 68*8975f5c5SAndroid Build Coastguard Worker this->isAtomicCounter = isAtomicCounter; 69*8975f5c5SAndroid Build Coastguard Worker this->isFragmentInOut = isFragmentInOut; 70*8975f5c5SAndroid Build Coastguard Worker } 71*8975f5c5SAndroid Build Coastguard Worker 72*8975f5c5SAndroid Build Coastguard Worker std::string name; 73*8975f5c5SAndroid Build Coastguard Worker bool isSampler; 74*8975f5c5SAndroid Build Coastguard Worker bool isImage; 75*8975f5c5SAndroid Build Coastguard Worker bool isAtomicCounter; 76*8975f5c5SAndroid Build Coastguard Worker bool isFragmentInOut; 77*8975f5c5SAndroid Build Coastguard Worker }; 78*8975f5c5SAndroid Build Coastguard Worker 79*8975f5c5SAndroid Build Coastguard Worker struct UsedUniform : public sh::ShaderVariable 80*8975f5c5SAndroid Build Coastguard Worker { 81*8975f5c5SAndroid Build Coastguard Worker UsedUniform(); 82*8975f5c5SAndroid Build Coastguard Worker UsedUniform(GLenum type, 83*8975f5c5SAndroid Build Coastguard Worker GLenum precision, 84*8975f5c5SAndroid Build Coastguard Worker const std::string &name, 85*8975f5c5SAndroid Build Coastguard Worker const std::vector<unsigned int> &arraySizes, 86*8975f5c5SAndroid Build Coastguard Worker const int binding, 87*8975f5c5SAndroid Build Coastguard Worker const int offset, 88*8975f5c5SAndroid Build Coastguard Worker const int location, 89*8975f5c5SAndroid Build Coastguard Worker const int bufferIndex, 90*8975f5c5SAndroid Build Coastguard Worker const sh::BlockMemberInfo &blockInfo); 91*8975f5c5SAndroid Build Coastguard Worker UsedUniform(const UsedUniform &other); 92*8975f5c5SAndroid Build Coastguard Worker UsedUniform &operator=(const UsedUniform &other); 93*8975f5c5SAndroid Build Coastguard Worker ~UsedUniform(); 94*8975f5c5SAndroid Build Coastguard Worker isSamplerUsedUniform95*8975f5c5SAndroid Build Coastguard Worker bool isSampler() const { return typeInfo->isSampler; } isImageUsedUniform96*8975f5c5SAndroid Build Coastguard Worker bool isImage() const { return typeInfo->isImageType; } isAtomicCounterUsedUniform97*8975f5c5SAndroid Build Coastguard Worker bool isAtomicCounter() const { return IsAtomicCounterType(type); } getElementSizeUsedUniform98*8975f5c5SAndroid Build Coastguard Worker size_t getElementSize() const { return typeInfo->externalSize; } 99*8975f5c5SAndroid Build Coastguard Worker setActiveUsedUniform100*8975f5c5SAndroid Build Coastguard Worker void setActive(ShaderType shaderType, bool used, uint32_t _id) 101*8975f5c5SAndroid Build Coastguard Worker { 102*8975f5c5SAndroid Build Coastguard Worker activeVariable.setActive(shaderType, used, _id); 103*8975f5c5SAndroid Build Coastguard Worker } 104*8975f5c5SAndroid Build Coastguard Worker 105*8975f5c5SAndroid Build Coastguard Worker ActiveVariable activeVariable; 106*8975f5c5SAndroid Build Coastguard Worker const UniformTypeInfo *typeInfo; 107*8975f5c5SAndroid Build Coastguard Worker 108*8975f5c5SAndroid Build Coastguard Worker // Identifies the containing buffer backed resource -- interface block or atomic counter buffer. 109*8975f5c5SAndroid Build Coastguard Worker int bufferIndex; 110*8975f5c5SAndroid Build Coastguard Worker sh::BlockMemberInfo blockInfo; 111*8975f5c5SAndroid Build Coastguard Worker std::vector<unsigned int> outerArraySizes; 112*8975f5c5SAndroid Build Coastguard Worker unsigned int outerArrayOffset; 113*8975f5c5SAndroid Build Coastguard Worker }; 114*8975f5c5SAndroid Build Coastguard Worker 115*8975f5c5SAndroid Build Coastguard Worker class UniformLinker final : angle::NonCopyable 116*8975f5c5SAndroid Build Coastguard Worker { 117*8975f5c5SAndroid Build Coastguard Worker public: 118*8975f5c5SAndroid Build Coastguard Worker UniformLinker(const ShaderBitSet &activeShaderStages, 119*8975f5c5SAndroid Build Coastguard Worker const ShaderMap<std::vector<sh::ShaderVariable>> &shaderUniforms); 120*8975f5c5SAndroid Build Coastguard Worker ~UniformLinker(); 121*8975f5c5SAndroid Build Coastguard Worker 122*8975f5c5SAndroid Build Coastguard Worker bool link(const Caps &caps, 123*8975f5c5SAndroid Build Coastguard Worker InfoLog &infoLog, 124*8975f5c5SAndroid Build Coastguard Worker const ProgramAliasedBindings &uniformLocationBindings); 125*8975f5c5SAndroid Build Coastguard Worker 126*8975f5c5SAndroid Build Coastguard Worker void getResults(std::vector<LinkedUniform> *uniforms, 127*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> *uniformNames, 128*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> *uniformMappedNames, 129*8975f5c5SAndroid Build Coastguard Worker std::vector<UnusedUniform> *unusedUniformsOutOrNull, 130*8975f5c5SAndroid Build Coastguard Worker std::vector<VariableLocation> *uniformLocationsOutOrNull); 131*8975f5c5SAndroid Build Coastguard Worker 132*8975f5c5SAndroid Build Coastguard Worker private: 133*8975f5c5SAndroid Build Coastguard Worker bool validateGraphicsUniforms(InfoLog &infoLog) const; 134*8975f5c5SAndroid Build Coastguard Worker bool validateGraphicsUniformsPerShader(ShaderType shaderToLink, 135*8975f5c5SAndroid Build Coastguard Worker bool extendLinkedUniforms, 136*8975f5c5SAndroid Build Coastguard Worker std::map<std::string, ShaderUniform> *linkedUniforms, 137*8975f5c5SAndroid Build Coastguard Worker InfoLog &infoLog) const; 138*8975f5c5SAndroid Build Coastguard Worker bool flattenUniformsAndCheckCapsForShader(ShaderType shaderType, 139*8975f5c5SAndroid Build Coastguard Worker const Caps &caps, 140*8975f5c5SAndroid Build Coastguard Worker std::vector<UsedUniform> &samplerUniforms, 141*8975f5c5SAndroid Build Coastguard Worker std::vector<UsedUniform> &imageUniforms, 142*8975f5c5SAndroid Build Coastguard Worker std::vector<UsedUniform> &atomicCounterUniforms, 143*8975f5c5SAndroid Build Coastguard Worker std::vector<UsedUniform> &inputAttachmentUniforms, 144*8975f5c5SAndroid Build Coastguard Worker std::vector<UnusedUniform> &unusedUniforms, 145*8975f5c5SAndroid Build Coastguard Worker InfoLog &infoLog); 146*8975f5c5SAndroid Build Coastguard Worker 147*8975f5c5SAndroid Build Coastguard Worker bool flattenUniformsAndCheckCaps(const Caps &caps, InfoLog &infoLog); 148*8975f5c5SAndroid Build Coastguard Worker bool checkMaxCombinedAtomicCounters(const Caps &caps, InfoLog &infoLog); 149*8975f5c5SAndroid Build Coastguard Worker 150*8975f5c5SAndroid Build Coastguard Worker bool indexUniforms(InfoLog &infoLog, const ProgramAliasedBindings &uniformLocationBindings); 151*8975f5c5SAndroid Build Coastguard Worker bool gatherUniformLocationsAndCheckConflicts( 152*8975f5c5SAndroid Build Coastguard Worker InfoLog &infoLog, 153*8975f5c5SAndroid Build Coastguard Worker const ProgramAliasedBindings &uniformLocationBindings, 154*8975f5c5SAndroid Build Coastguard Worker std::set<GLuint> *ignoredLocations, 155*8975f5c5SAndroid Build Coastguard Worker int *maxUniformLocation); 156*8975f5c5SAndroid Build Coastguard Worker void pruneUnusedUniforms(); 157*8975f5c5SAndroid Build Coastguard Worker 158*8975f5c5SAndroid Build Coastguard Worker ShaderBitSet mActiveShaderStages; 159*8975f5c5SAndroid Build Coastguard Worker const ShaderMap<std::vector<sh::ShaderVariable>> &mShaderUniforms; 160*8975f5c5SAndroid Build Coastguard Worker std::vector<UsedUniform> mUniforms; 161*8975f5c5SAndroid Build Coastguard Worker std::vector<UnusedUniform> mUnusedUniforms; 162*8975f5c5SAndroid Build Coastguard Worker std::vector<VariableLocation> mUniformLocations; 163*8975f5c5SAndroid Build Coastguard Worker }; 164*8975f5c5SAndroid Build Coastguard Worker 165*8975f5c5SAndroid Build Coastguard Worker using GetBlockSizeFunc = std::function< 166*8975f5c5SAndroid Build Coastguard Worker bool(const std::string &blockName, const std::string &blockMappedName, size_t *sizeOut)>; 167*8975f5c5SAndroid Build Coastguard Worker using GetBlockMemberInfoFunc = std::function< 168*8975f5c5SAndroid Build Coastguard Worker bool(const std::string &name, const std::string &mappedName, sh::BlockMemberInfo *infoOut)>; 169*8975f5c5SAndroid Build Coastguard Worker 170*8975f5c5SAndroid Build Coastguard Worker // This class is intended to be used during the link step to store interface block information. 171*8975f5c5SAndroid Build Coastguard Worker // It is called by the Impl class during ProgramImpl::link so that it has access to the 172*8975f5c5SAndroid Build Coastguard Worker // real block size and layout. 173*8975f5c5SAndroid Build Coastguard Worker class InterfaceBlockLinker : angle::NonCopyable 174*8975f5c5SAndroid Build Coastguard Worker { 175*8975f5c5SAndroid Build Coastguard Worker public: 176*8975f5c5SAndroid Build Coastguard Worker virtual ~InterfaceBlockLinker(); 177*8975f5c5SAndroid Build Coastguard Worker 178*8975f5c5SAndroid Build Coastguard Worker // This is called once per shader stage. It stores a pointer to the block vector, so it's 179*8975f5c5SAndroid Build Coastguard Worker // important that this class does not persist longer than the duration of Program::link. 180*8975f5c5SAndroid Build Coastguard Worker void addShaderBlocks(ShaderType shader, const std::vector<sh::InterfaceBlock> *blocks); 181*8975f5c5SAndroid Build Coastguard Worker 182*8975f5c5SAndroid Build Coastguard Worker // This is called once during a link operation, after all shader blocks are added. 183*8975f5c5SAndroid Build Coastguard Worker void linkBlocks(const GetBlockSizeFunc &getBlockSize, 184*8975f5c5SAndroid Build Coastguard Worker const GetBlockMemberInfoFunc &getMemberInfo) const; 185*8975f5c5SAndroid Build Coastguard Worker getShaderBlocks(ShaderType shaderType)186*8975f5c5SAndroid Build Coastguard Worker const std::vector<sh::InterfaceBlock> &getShaderBlocks(ShaderType shaderType) const 187*8975f5c5SAndroid Build Coastguard Worker { 188*8975f5c5SAndroid Build Coastguard Worker ASSERT(mShaderBlocks[shaderType]); 189*8975f5c5SAndroid Build Coastguard Worker return *mShaderBlocks[shaderType]; 190*8975f5c5SAndroid Build Coastguard Worker } 191*8975f5c5SAndroid Build Coastguard Worker 192*8975f5c5SAndroid Build Coastguard Worker protected: 193*8975f5c5SAndroid Build Coastguard Worker InterfaceBlockLinker(); 194*8975f5c5SAndroid Build Coastguard Worker void init(std::vector<InterfaceBlock> *blocksOut, 195*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> *unusedInterfaceBlocksOut); 196*8975f5c5SAndroid Build Coastguard Worker void defineInterfaceBlock(const GetBlockSizeFunc &getBlockSize, 197*8975f5c5SAndroid Build Coastguard Worker const GetBlockMemberInfoFunc &getMemberInfo, 198*8975f5c5SAndroid Build Coastguard Worker const sh::InterfaceBlock &interfaceBlock, 199*8975f5c5SAndroid Build Coastguard Worker ShaderType shaderType) const; 200*8975f5c5SAndroid Build Coastguard Worker 201*8975f5c5SAndroid Build Coastguard Worker virtual size_t getCurrentBlockMemberIndex() const = 0; 202*8975f5c5SAndroid Build Coastguard Worker 203*8975f5c5SAndroid Build Coastguard Worker virtual sh::ShaderVariableVisitor *getVisitor(const GetBlockMemberInfoFunc &getMemberInfo, 204*8975f5c5SAndroid Build Coastguard Worker const std::string &namePrefix, 205*8975f5c5SAndroid Build Coastguard Worker const std::string &mappedNamePrefix, 206*8975f5c5SAndroid Build Coastguard Worker ShaderType shaderType, 207*8975f5c5SAndroid Build Coastguard Worker int blockIndex) const = 0; 208*8975f5c5SAndroid Build Coastguard Worker 209*8975f5c5SAndroid Build Coastguard Worker ShaderMap<const std::vector<sh::InterfaceBlock> *> mShaderBlocks = {}; 210*8975f5c5SAndroid Build Coastguard Worker 211*8975f5c5SAndroid Build Coastguard Worker std::vector<InterfaceBlock> *mBlocksOut = nullptr; 212*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> *mUnusedInterfaceBlocksOut = nullptr; 213*8975f5c5SAndroid Build Coastguard Worker }; 214*8975f5c5SAndroid Build Coastguard Worker 215*8975f5c5SAndroid Build Coastguard Worker class UniformBlockLinker final : public InterfaceBlockLinker 216*8975f5c5SAndroid Build Coastguard Worker { 217*8975f5c5SAndroid Build Coastguard Worker public: 218*8975f5c5SAndroid Build Coastguard Worker UniformBlockLinker(); 219*8975f5c5SAndroid Build Coastguard Worker ~UniformBlockLinker() override; 220*8975f5c5SAndroid Build Coastguard Worker 221*8975f5c5SAndroid Build Coastguard Worker void init(std::vector<InterfaceBlock> *blocksOut, 222*8975f5c5SAndroid Build Coastguard Worker std::vector<LinkedUniform> *uniformsOut, 223*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> *uniformNamesOut, 224*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> *uniformMappedNamesOut, 225*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> *unusedInterfaceBlocksOut); 226*8975f5c5SAndroid Build Coastguard Worker 227*8975f5c5SAndroid Build Coastguard Worker private: 228*8975f5c5SAndroid Build Coastguard Worker size_t getCurrentBlockMemberIndex() const override; 229*8975f5c5SAndroid Build Coastguard Worker 230*8975f5c5SAndroid Build Coastguard Worker sh::ShaderVariableVisitor *getVisitor(const GetBlockMemberInfoFunc &getMemberInfo, 231*8975f5c5SAndroid Build Coastguard Worker const std::string &namePrefix, 232*8975f5c5SAndroid Build Coastguard Worker const std::string &mappedNamePrefix, 233*8975f5c5SAndroid Build Coastguard Worker ShaderType shaderType, 234*8975f5c5SAndroid Build Coastguard Worker int blockIndex) const override; 235*8975f5c5SAndroid Build Coastguard Worker 236*8975f5c5SAndroid Build Coastguard Worker std::vector<LinkedUniform> *mUniformsOut = nullptr; 237*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> *mUniformNamesOut = nullptr; 238*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> *mUniformMappedNamesOut = nullptr; 239*8975f5c5SAndroid Build Coastguard Worker }; 240*8975f5c5SAndroid Build Coastguard Worker 241*8975f5c5SAndroid Build Coastguard Worker class ShaderStorageBlockLinker final : public InterfaceBlockLinker 242*8975f5c5SAndroid Build Coastguard Worker { 243*8975f5c5SAndroid Build Coastguard Worker public: 244*8975f5c5SAndroid Build Coastguard Worker ShaderStorageBlockLinker(); 245*8975f5c5SAndroid Build Coastguard Worker ~ShaderStorageBlockLinker() override; 246*8975f5c5SAndroid Build Coastguard Worker 247*8975f5c5SAndroid Build Coastguard Worker void init(std::vector<InterfaceBlock> *blocksOut, 248*8975f5c5SAndroid Build Coastguard Worker std::vector<BufferVariable> *bufferVariablesOut, 249*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> *unusedInterfaceBlocksOut); 250*8975f5c5SAndroid Build Coastguard Worker 251*8975f5c5SAndroid Build Coastguard Worker private: 252*8975f5c5SAndroid Build Coastguard Worker size_t getCurrentBlockMemberIndex() const override; 253*8975f5c5SAndroid Build Coastguard Worker 254*8975f5c5SAndroid Build Coastguard Worker sh::ShaderVariableVisitor *getVisitor(const GetBlockMemberInfoFunc &getMemberInfo, 255*8975f5c5SAndroid Build Coastguard Worker const std::string &namePrefix, 256*8975f5c5SAndroid Build Coastguard Worker const std::string &mappedNamePrefix, 257*8975f5c5SAndroid Build Coastguard Worker ShaderType shaderType, 258*8975f5c5SAndroid Build Coastguard Worker int blockIndex) const override; 259*8975f5c5SAndroid Build Coastguard Worker 260*8975f5c5SAndroid Build Coastguard Worker std::vector<BufferVariable> *mBufferVariablesOut = nullptr; 261*8975f5c5SAndroid Build Coastguard Worker }; 262*8975f5c5SAndroid Build Coastguard Worker 263*8975f5c5SAndroid Build Coastguard Worker class AtomicCounterBufferLinker final : angle::NonCopyable 264*8975f5c5SAndroid Build Coastguard Worker { 265*8975f5c5SAndroid Build Coastguard Worker public: 266*8975f5c5SAndroid Build Coastguard Worker AtomicCounterBufferLinker(); 267*8975f5c5SAndroid Build Coastguard Worker ~AtomicCounterBufferLinker(); 268*8975f5c5SAndroid Build Coastguard Worker 269*8975f5c5SAndroid Build Coastguard Worker void init(std::vector<AtomicCounterBuffer> *atomicCounterBuffersOut); 270*8975f5c5SAndroid Build Coastguard Worker void link(const std::map<int, unsigned int> &sizeMap) const; 271*8975f5c5SAndroid Build Coastguard Worker 272*8975f5c5SAndroid Build Coastguard Worker private: 273*8975f5c5SAndroid Build Coastguard Worker std::vector<AtomicCounterBuffer> *mAtomicCounterBuffersOut = nullptr; 274*8975f5c5SAndroid Build Coastguard Worker }; 275*8975f5c5SAndroid Build Coastguard Worker 276*8975f5c5SAndroid Build Coastguard Worker class PixelLocalStorageLinker final : angle::NonCopyable 277*8975f5c5SAndroid Build Coastguard Worker { 278*8975f5c5SAndroid Build Coastguard Worker public: 279*8975f5c5SAndroid Build Coastguard Worker PixelLocalStorageLinker(); 280*8975f5c5SAndroid Build Coastguard Worker ~PixelLocalStorageLinker(); 281*8975f5c5SAndroid Build Coastguard Worker 282*8975f5c5SAndroid Build Coastguard Worker void init(std::vector<ShPixelLocalStorageFormat> *pixelLocalStorageFormatsOut); 283*8975f5c5SAndroid Build Coastguard Worker void link(const std::vector<ShPixelLocalStorageFormat> &pixelLocalStorageFormats) const; 284*8975f5c5SAndroid Build Coastguard Worker 285*8975f5c5SAndroid Build Coastguard Worker private: 286*8975f5c5SAndroid Build Coastguard Worker std::vector<ShPixelLocalStorageFormat> *mPixelLocalStorageFormatsOut = nullptr; 287*8975f5c5SAndroid Build Coastguard Worker }; 288*8975f5c5SAndroid Build Coastguard Worker 289*8975f5c5SAndroid Build Coastguard Worker struct ProgramLinkedResources 290*8975f5c5SAndroid Build Coastguard Worker { 291*8975f5c5SAndroid Build Coastguard Worker ProgramLinkedResources(); 292*8975f5c5SAndroid Build Coastguard Worker ~ProgramLinkedResources(); 293*8975f5c5SAndroid Build Coastguard Worker 294*8975f5c5SAndroid Build Coastguard Worker void init(std::vector<InterfaceBlock> *uniformBlocksOut, 295*8975f5c5SAndroid Build Coastguard Worker std::vector<LinkedUniform> *uniformsOut, 296*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> *uniformNamesOut, 297*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> *uniformMappedNamesOut, 298*8975f5c5SAndroid Build Coastguard Worker std::vector<InterfaceBlock> *shaderStorageBlocksOut, 299*8975f5c5SAndroid Build Coastguard Worker std::vector<BufferVariable> *bufferVariablesOut, 300*8975f5c5SAndroid Build Coastguard Worker std::vector<AtomicCounterBuffer> *atomicCounterBuffersOut, 301*8975f5c5SAndroid Build Coastguard Worker std::vector<ShPixelLocalStorageFormat> *pixelLocalStorageFormatsOut); 302*8975f5c5SAndroid Build Coastguard Worker 303*8975f5c5SAndroid Build Coastguard Worker ProgramVaryingPacking varyingPacking; 304*8975f5c5SAndroid Build Coastguard Worker UniformBlockLinker uniformBlockLinker; 305*8975f5c5SAndroid Build Coastguard Worker ShaderStorageBlockLinker shaderStorageBlockLinker; 306*8975f5c5SAndroid Build Coastguard Worker AtomicCounterBufferLinker atomicCounterBufferLinker; 307*8975f5c5SAndroid Build Coastguard Worker PixelLocalStorageLinker pixelLocalStorageLinker; 308*8975f5c5SAndroid Build Coastguard Worker std::vector<UnusedUniform> unusedUniforms; 309*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> unusedInterfaceBlocks; 310*8975f5c5SAndroid Build Coastguard Worker }; 311*8975f5c5SAndroid Build Coastguard Worker 312*8975f5c5SAndroid Build Coastguard Worker struct LinkingVariables final : private angle::NonCopyable 313*8975f5c5SAndroid Build Coastguard Worker { 314*8975f5c5SAndroid Build Coastguard Worker LinkingVariables(); 315*8975f5c5SAndroid Build Coastguard Worker ~LinkingVariables(); 316*8975f5c5SAndroid Build Coastguard Worker 317*8975f5c5SAndroid Build Coastguard Worker void initForProgram(const ProgramState &state); 318*8975f5c5SAndroid Build Coastguard Worker void initForProgramPipeline(const ProgramPipelineState &state); 319*8975f5c5SAndroid Build Coastguard Worker 320*8975f5c5SAndroid Build Coastguard Worker ShaderMap<std::vector<sh::ShaderVariable>> outputVaryings; 321*8975f5c5SAndroid Build Coastguard Worker ShaderMap<std::vector<sh::ShaderVariable>> inputVaryings; 322*8975f5c5SAndroid Build Coastguard Worker ShaderMap<std::vector<sh::ShaderVariable>> uniforms; 323*8975f5c5SAndroid Build Coastguard Worker ShaderMap<std::vector<sh::InterfaceBlock>> uniformBlocks; 324*8975f5c5SAndroid Build Coastguard Worker ShaderBitSet isShaderStageUsedBitset; 325*8975f5c5SAndroid Build Coastguard Worker }; 326*8975f5c5SAndroid Build Coastguard Worker 327*8975f5c5SAndroid Build Coastguard Worker class CustomBlockLayoutEncoderFactory : angle::NonCopyable 328*8975f5c5SAndroid Build Coastguard Worker { 329*8975f5c5SAndroid Build Coastguard Worker public: ~CustomBlockLayoutEncoderFactory()330*8975f5c5SAndroid Build Coastguard Worker virtual ~CustomBlockLayoutEncoderFactory() {} 331*8975f5c5SAndroid Build Coastguard Worker 332*8975f5c5SAndroid Build Coastguard Worker virtual sh::BlockLayoutEncoder *makeEncoder() = 0; 333*8975f5c5SAndroid Build Coastguard Worker }; 334*8975f5c5SAndroid Build Coastguard Worker 335*8975f5c5SAndroid Build Coastguard Worker // Used by the backends in Program*::linkResources to parse interface blocks and provide 336*8975f5c5SAndroid Build Coastguard Worker // information to ProgramLinkedResources' linkers. 337*8975f5c5SAndroid Build Coastguard Worker class ProgramLinkedResourcesLinker final : angle::NonCopyable 338*8975f5c5SAndroid Build Coastguard Worker { 339*8975f5c5SAndroid Build Coastguard Worker public: ProgramLinkedResourcesLinker(CustomBlockLayoutEncoderFactory * customEncoderFactory)340*8975f5c5SAndroid Build Coastguard Worker ProgramLinkedResourcesLinker(CustomBlockLayoutEncoderFactory *customEncoderFactory) 341*8975f5c5SAndroid Build Coastguard Worker : mCustomEncoderFactory(customEncoderFactory) 342*8975f5c5SAndroid Build Coastguard Worker {} 343*8975f5c5SAndroid Build Coastguard Worker 344*8975f5c5SAndroid Build Coastguard Worker void linkResources(const ProgramState &programState, 345*8975f5c5SAndroid Build Coastguard Worker const ProgramLinkedResources &resources) const; 346*8975f5c5SAndroid Build Coastguard Worker 347*8975f5c5SAndroid Build Coastguard Worker private: 348*8975f5c5SAndroid Build Coastguard Worker void getAtomicCounterBufferSizeMap(const ProgramExecutable &executable, 349*8975f5c5SAndroid Build Coastguard Worker std::map<int, unsigned int> &sizeMapOut) const; 350*8975f5c5SAndroid Build Coastguard Worker 351*8975f5c5SAndroid Build Coastguard Worker CustomBlockLayoutEncoderFactory *mCustomEncoderFactory; 352*8975f5c5SAndroid Build Coastguard Worker }; 353*8975f5c5SAndroid Build Coastguard Worker 354*8975f5c5SAndroid Build Coastguard Worker using ShaderInterfaceBlock = std::pair<ShaderType, const sh::InterfaceBlock *>; 355*8975f5c5SAndroid Build Coastguard Worker using InterfaceBlockMap = std::map<std::string, ShaderInterfaceBlock>; 356*8975f5c5SAndroid Build Coastguard Worker 357*8975f5c5SAndroid Build Coastguard Worker bool LinkValidateProgramGlobalNames(InfoLog &infoLog, 358*8975f5c5SAndroid Build Coastguard Worker const ProgramExecutable &executable, 359*8975f5c5SAndroid Build Coastguard Worker const LinkingVariables &linkingVariables); 360*8975f5c5SAndroid Build Coastguard Worker bool LinkValidateShaderInterfaceMatching(const std::vector<sh::ShaderVariable> &outputVaryings, 361*8975f5c5SAndroid Build Coastguard Worker const std::vector<sh::ShaderVariable> &inputVaryings, 362*8975f5c5SAndroid Build Coastguard Worker ShaderType frontShaderType, 363*8975f5c5SAndroid Build Coastguard Worker ShaderType backShaderType, 364*8975f5c5SAndroid Build Coastguard Worker int frontShaderVersion, 365*8975f5c5SAndroid Build Coastguard Worker int backShaderVersion, 366*8975f5c5SAndroid Build Coastguard Worker bool isSeparable, 367*8975f5c5SAndroid Build Coastguard Worker InfoLog &infoLog); 368*8975f5c5SAndroid Build Coastguard Worker bool LinkValidateBuiltInVaryingsInvariant(const std::vector<sh::ShaderVariable> &vertexVaryings, 369*8975f5c5SAndroid Build Coastguard Worker const std::vector<sh::ShaderVariable> &fragmentVaryings, 370*8975f5c5SAndroid Build Coastguard Worker int vertexShaderVersion, 371*8975f5c5SAndroid Build Coastguard Worker InfoLog &infoLog); 372*8975f5c5SAndroid Build Coastguard Worker bool LinkValidateBuiltInVaryings(const std::vector<sh::ShaderVariable> &inputVaryings, 373*8975f5c5SAndroid Build Coastguard Worker const std::vector<sh::ShaderVariable> &outputVaryings, 374*8975f5c5SAndroid Build Coastguard Worker ShaderType inputShaderType, 375*8975f5c5SAndroid Build Coastguard Worker ShaderType outputShaderType, 376*8975f5c5SAndroid Build Coastguard Worker int inputShaderVersion, 377*8975f5c5SAndroid Build Coastguard Worker int outputShaderVersion, 378*8975f5c5SAndroid Build Coastguard Worker InfoLog &infoLog); 379*8975f5c5SAndroid Build Coastguard Worker LinkMismatchError LinkValidateProgramVariables(const sh::ShaderVariable &variable1, 380*8975f5c5SAndroid Build Coastguard Worker const sh::ShaderVariable &variable2, 381*8975f5c5SAndroid Build Coastguard Worker bool validatePrecision, 382*8975f5c5SAndroid Build Coastguard Worker bool treatVariable1AsNonArray, 383*8975f5c5SAndroid Build Coastguard Worker bool treatVariable2AsNonArray, 384*8975f5c5SAndroid Build Coastguard Worker std::string *mismatchedStructOrBlockMemberName); 385*8975f5c5SAndroid Build Coastguard Worker void AddProgramVariableParentPrefix(const std::string &parentName, 386*8975f5c5SAndroid Build Coastguard Worker std::string *mismatchedFieldName); 387*8975f5c5SAndroid Build Coastguard Worker bool LinkValidateProgramInterfaceBlocks(const Caps &caps, 388*8975f5c5SAndroid Build Coastguard Worker const Version &clientVersion, 389*8975f5c5SAndroid Build Coastguard Worker bool webglCompatibility, 390*8975f5c5SAndroid Build Coastguard Worker ShaderBitSet activeProgramStages, 391*8975f5c5SAndroid Build Coastguard Worker const ProgramLinkedResources &resources, 392*8975f5c5SAndroid Build Coastguard Worker InfoLog &infoLog, 393*8975f5c5SAndroid Build Coastguard Worker GLuint *combinedShaderStorageBlocksCountOut); 394*8975f5c5SAndroid Build Coastguard Worker } // namespace gl 395*8975f5c5SAndroid Build Coastguard Worker 396*8975f5c5SAndroid Build Coastguard Worker #endif // LIBANGLE_UNIFORMLINKER_H_ 397