Commit 9b11ea4f by Jiajia Qin Committed by Commit Bot

Gather UniformBlock and ShaderStorageBlock separately

Refactor InterfaceBlocks since it only stands for UniformBlock before ES31. But for ES31, uniform block and shader storage block both belong to interface block. This CL will add GetUniformBlocks and GetShaderStorageBlocks in ShaderLang.h. Meanwhile, keep GetInterfaceBlocks which can return all the interface blocks together. BUG=angleproject:1951 Change-Id: I3036e201aadfbd490575ed03538c81bcc3793ff3 Reviewed-on: https://chromium-review.googlesource.com/582546 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 0d671c9a
......@@ -541,6 +541,8 @@ const std::vector<sh::Varying> *GetOutputVaryings(const ShHandle handle);
const std::vector<sh::Attribute> *GetAttributes(const ShHandle handle);
const std::vector<sh::OutputVariable> *GetOutputVariables(const ShHandle handle);
const std::vector<sh::InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle);
const std::vector<sh::InterfaceBlock> *GetUniformBlocks(const ShHandle handle);
const std::vector<sh::InterfaceBlock> *GetShaderStorageBlocks(const ShHandle handle);
sh::WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle);
// Returns the number of views specified through the num_views layout qualifier. If num_views is
// not set, the function returns -1.
......@@ -556,18 +558,18 @@ int GetVertexShaderNumViews(const ShHandle handle);
bool CheckVariablesWithinPackingLimits(int maxVectors,
const std::vector<sh::ShaderVariable> &variables);
// Gives the compiler-assigned register for an interface block.
// Gives the compiler-assigned register for a uniform block.
// The method writes the value to the output variable "indexOut".
// Returns true if it found a valid interface block, false otherwise.
// Returns true if it found a valid uniform block, false otherwise.
// Parameters:
// handle: Specifies the compiler
// interfaceBlockName: Specifies the interface block
// uniformBlockName: Specifies the uniform block
// indexOut: output variable that stores the assigned register
bool GetInterfaceBlockRegister(const ShHandle handle,
const std::string &interfaceBlockName,
unsigned int *indexOut);
bool GetUniformBlockRegister(const ShHandle handle,
const std::string &uniformBlockName,
unsigned int *indexOut);
// Gives a map from uniform names to compiler-assigned registers in the default interface block.
// Gives a map from uniform names to compiler-assigned registers in the default uniform block.
// Note that the map contains also registers of samplers that have been extracted from structs.
const std::map<std::string, unsigned int> *GetUniformRegisterMap(const ShHandle handle);
......
......@@ -41,6 +41,13 @@ enum BlockLayoutType
BLOCKLAYOUT_SHARED
};
// Interface Blocks, see section 4.3.9 of the ESSL 3.10 spec
enum class BlockType
{
BLOCK_UNIFORM,
BLOCK_BUFFER
};
// Base class for all variables defined in shaders, including Varyings, Uniforms, etc
// Note: we must override the copy constructor and assignment operator so we can
// work around excessive GCC binary bloating:
......@@ -219,6 +226,7 @@ struct InterfaceBlock
bool isRowMajorLayout;
int binding;
bool staticUse;
BlockType blockType;
std::vector<InterfaceBlockField> fields;
};
......
......@@ -474,8 +474,9 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
{
ASSERT(!variablesCollected);
CollectVariables(root, &attributes, &outputVariables, &uniforms, &inputVaryings,
&outputVaryings, &interfaceBlocks, hashFunction, &symbolTable,
shaderVersion, extensionBehavior);
&outputVaryings, &uniformBlocks, &shaderStorageBlocks, hashFunction,
&symbolTable, shaderVersion, extensionBehavior);
collectInterfaceBlocks();
variablesCollected = true;
if (compileOptions & SH_USE_UNUSED_STANDARD_SHARED_BLOCKS)
{
......@@ -749,6 +750,15 @@ void TCompiler::setResourceString()
builtInResourcesString = strstream.str();
}
void TCompiler::collectInterfaceBlocks()
{
ASSERT(interfaceBlocks.empty());
interfaceBlocks.reserve(uniformBlocks.size() + shaderStorageBlocks.size());
interfaceBlocks.insert(interfaceBlocks.end(), uniformBlocks.begin(), uniformBlocks.end());
interfaceBlocks.insert(interfaceBlocks.end(), shaderStorageBlocks.begin(),
shaderStorageBlocks.end());
}
void TCompiler::clearResults()
{
arrayBoundsClamper.Cleanup();
......@@ -763,6 +773,8 @@ void TCompiler::clearResults()
inputVaryings.clear();
outputVaryings.clear();
interfaceBlocks.clear();
uniformBlocks.clear();
shaderStorageBlocks.clear();
variablesCollected = false;
mGLPositionInitialized = false;
......@@ -983,7 +995,7 @@ void TCompiler::useAllMembersInUnusedStandardAndSharedBlocks(TIntermBlock *root)
{
sh::InterfaceBlockList list;
for (auto block : interfaceBlocks)
for (auto block : uniformBlocks)
{
if (!block.staticUse &&
(block.layout == sh::BLOCKLAYOUT_STANDARD || block.layout == sh::BLOCKLAYOUT_SHARED))
......
......@@ -113,6 +113,11 @@ class TCompiler : public TShHandleBase
const std::vector<sh::Varying> &getInputVaryings() const { return inputVaryings; }
const std::vector<sh::Varying> &getOutputVaryings() const { return outputVaryings; }
const std::vector<sh::InterfaceBlock> &getInterfaceBlocks() const { return interfaceBlocks; }
const std::vector<sh::InterfaceBlock> &getUniformBlocks() const { return uniformBlocks; }
const std::vector<sh::InterfaceBlock> &getShaderStorageBlocks() const
{
return shaderStorageBlocks;
}
ShHashFunction64 getHashFunction() const { return hashFunction; }
NameMap &getNameMap() { return nameMap; }
......@@ -188,6 +193,8 @@ class TCompiler : public TShHandleBase
std::vector<sh::Varying> inputVaryings;
std::vector<sh::Varying> outputVaryings;
std::vector<sh::InterfaceBlock> interfaceBlocks;
std::vector<sh::InterfaceBlock> uniformBlocks;
std::vector<sh::InterfaceBlock> shaderStorageBlocks;
private:
// Creates the function call DAG for further analysis, returning false if there is a recursion
......@@ -198,6 +205,8 @@ class TCompiler : public TShHandleBase
void initSamplerDefaultPrecision(TBasicType samplerType);
void collectInterfaceBlocks();
bool variablesCollected;
bool mGLPositionInitialized;
......
......@@ -147,7 +147,7 @@ OutputHLSL::OutputHLSL(sh::GLenum shaderType,
}
// Reserve registers for the default uniform block and driver constants
mUniformHLSL->reserveInterfaceBlockRegisters(2);
mUniformHLSL->reserveUniformBlockRegisters(2);
}
OutputHLSL::~OutputHLSL()
......@@ -231,9 +231,9 @@ void OutputHLSL::makeFlaggedStructMaps(const std::vector<TIntermTyped *> &flagge
}
}
const std::map<std::string, unsigned int> &OutputHLSL::getInterfaceBlockRegisterMap() const
const std::map<std::string, unsigned int> &OutputHLSL::getUniformBlockRegisterMap() const
{
return mUniformHLSL->getInterfaceBlockRegisterMap();
return mUniformHLSL->getUniformBlockRegisterMap();
}
const std::map<std::string, unsigned int> &OutputHLSL::getUniformRegisterMap() const
......@@ -354,7 +354,7 @@ void OutputHLSL::header(TInfoSinkBase &out, const BuiltInFunctionEmulator *built
out << mStructureHLSL->structsHeader();
mUniformHLSL->uniformsHeader(out, mOutputType, mReferencedUniforms);
out << mUniformHLSL->interfaceBlocksHeader(mReferencedInterfaceBlocks);
out << mUniformHLSL->uniformBlocksHeader(mReferencedUniformBlocks);
if (!mEqualityFunctions.empty())
{
......@@ -792,7 +792,7 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
if (interfaceBlock)
{
mReferencedInterfaceBlocks[interfaceBlock->name()] = node;
mReferencedUniformBlocks[interfaceBlock->name()] = node;
}
else
{
......@@ -1138,9 +1138,9 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
{
TInterfaceBlock *interfaceBlock = leftType.getInterfaceBlock();
const int arrayIndex = node->getRight()->getAsConstantUnion()->getIConst(0);
mReferencedInterfaceBlocks[interfaceBlock->instanceName()] =
mReferencedUniformBlocks[interfaceBlock->instanceName()] =
node->getLeft()->getAsSymbolNode();
out << mUniformHLSL->interfaceBlockInstanceString(*interfaceBlock, arrayIndex);
out << mUniformHLSL->uniformBlockInstanceString(*interfaceBlock, arrayIndex);
return false;
}
}
......
......@@ -43,7 +43,7 @@ class OutputHLSL : public TIntermTraverser
void output(TIntermNode *treeRoot, TInfoSinkBase &objSink);
const std::map<std::string, unsigned int> &getInterfaceBlockRegisterMap() const;
const std::map<std::string, unsigned int> &getUniformBlockRegisterMap() const;
const std::map<std::string, unsigned int> &getUniformRegisterMap() const;
static TString initializer(const TType &type);
......@@ -154,7 +154,7 @@ class OutputHLSL : public TIntermTraverser
std::stack<TInfoSinkBase *> mInfoSinkStack;
ReferencedSymbols mReferencedUniforms;
ReferencedSymbols mReferencedInterfaceBlocks;
ReferencedSymbols mReferencedUniformBlocks;
ReferencedSymbols mReferencedAttributes;
ReferencedSymbols mReferencedVaryings;
ReferencedSymbols mReferencedOutputVariables;
......
......@@ -405,6 +405,26 @@ const std::vector<InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle)
return GetShaderVariables<InterfaceBlock>(handle);
}
const std::vector<InterfaceBlock> *GetUniformBlocks(const ShHandle handle)
{
ASSERT(handle);
TShHandleBase *base = static_cast<TShHandleBase *>(handle);
TCompiler *compiler = base->getAsCompiler();
ASSERT(compiler);
return &compiler->getUniformBlocks();
}
const std::vector<InterfaceBlock> *GetShaderStorageBlocks(const ShHandle handle)
{
ASSERT(handle);
TShHandleBase *base = static_cast<TShHandleBase *>(handle);
TCompiler *compiler = base->getAsCompiler();
ASSERT(compiler);
return &compiler->getShaderStorageBlocks();
}
WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle)
{
ASSERT(handle);
......@@ -432,9 +452,9 @@ bool CheckVariablesWithinPackingLimits(int maxVectors, const std::vector<ShaderV
return packer.CheckVariablesWithinPackingLimits(maxVectors, variables);
}
bool GetInterfaceBlockRegister(const ShHandle handle,
const std::string &interfaceBlockName,
unsigned int *indexOut)
bool GetUniformBlockRegister(const ShHandle handle,
const std::string &uniformBlockName,
unsigned int *indexOut)
{
#ifdef ANGLE_ENABLE_HLSL
ASSERT(indexOut);
......@@ -442,12 +462,12 @@ bool GetInterfaceBlockRegister(const ShHandle handle,
TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
ASSERT(translator);
if (!translator->hasInterfaceBlock(interfaceBlockName))
if (!translator->hasUniformBlock(uniformBlockName))
{
return false;
}
*indexOut = translator->getInterfaceBlockRegister(interfaceBlockName);
*indexOut = translator->getUniformBlockRegister(uniformBlockName);
return true;
#else
return false;
......
......@@ -374,7 +374,8 @@ InterfaceBlock::InterfaceBlock()
layout(BLOCKLAYOUT_PACKED),
isRowMajorLayout(false),
binding(-1),
staticUse(false)
staticUse(false),
blockType(BlockType::BLOCK_UNIFORM)
{
}
......@@ -391,6 +392,7 @@ InterfaceBlock::InterfaceBlock(const InterfaceBlock &other)
isRowMajorLayout(other.isRowMajorLayout),
binding(other.binding),
staticUse(other.staticUse),
blockType(other.blockType),
fields(other.fields)
{
}
......@@ -405,6 +407,7 @@ InterfaceBlock &InterfaceBlock::operator=(const InterfaceBlock &other)
isRowMajorLayout = other.isRowMajorLayout;
binding = other.binding;
staticUse = other.staticUse;
blockType = other.blockType;
fields = other.fields;
return *this;
}
......@@ -418,7 +421,8 @@ bool InterfaceBlock::isSameInterfaceBlockAtLinkTime(const InterfaceBlock &other)
{
if (name != other.name || mappedName != other.mappedName || arraySize != other.arraySize ||
layout != other.layout || isRowMajorLayout != other.isRowMajorLayout ||
binding != other.binding || fields.size() != other.fields.size())
binding != other.binding || blockType != other.blockType ||
fields.size() != other.fields.size())
{
return false;
}
......
......@@ -123,7 +123,7 @@ void TranslatorHLSL::translate(TIntermBlock *root, ShCompileOptions compileOptio
outputHLSL.output(root, getInfoSink().obj);
mInterfaceBlockRegisterMap = outputHLSL.getInterfaceBlockRegisterMap();
mUniformBlockRegisterMap = outputHLSL.getUniformBlockRegisterMap();
mUniformRegisterMap = outputHLSL.getUniformRegisterMap();
}
......@@ -133,15 +133,15 @@ bool TranslatorHLSL::shouldFlattenPragmaStdglInvariantAll()
return false;
}
bool TranslatorHLSL::hasInterfaceBlock(const std::string &interfaceBlockName) const
bool TranslatorHLSL::hasUniformBlock(const std::string &uniformBlockName) const
{
return (mInterfaceBlockRegisterMap.count(interfaceBlockName) > 0);
return (mUniformBlockRegisterMap.count(uniformBlockName) > 0);
}
unsigned int TranslatorHLSL::getInterfaceBlockRegister(const std::string &interfaceBlockName) const
unsigned int TranslatorHLSL::getUniformBlockRegister(const std::string &uniformBlockName) const
{
ASSERT(hasInterfaceBlock(interfaceBlockName));
return mInterfaceBlockRegisterMap.find(interfaceBlockName)->second;
ASSERT(hasUniformBlock(uniformBlockName));
return mUniformBlockRegisterMap.find(uniformBlockName)->second;
}
const std::map<std::string, unsigned int> *TranslatorHLSL::getUniformRegisterMap() const
......
......@@ -18,8 +18,8 @@ class TranslatorHLSL : public TCompiler
TranslatorHLSL(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output);
TranslatorHLSL *getAsTranslatorHLSL() override { return this; }
bool hasInterfaceBlock(const std::string &interfaceBlockName) const;
unsigned int getInterfaceBlockRegister(const std::string &interfaceBlockName) const;
bool hasUniformBlock(const std::string &interfaceBlockName) const;
unsigned int getUniformBlockRegister(const std::string &interfaceBlockName) const;
const std::map<std::string, unsigned int> *getUniformRegisterMap() const;
......@@ -33,7 +33,7 @@ class TranslatorHLSL : public TCompiler
// Globals are initialized in output so it is redundant to initialize them in the AST.
bool needToInitializeGlobalsInAST() const override { return false; }
std::map<std::string, unsigned int> mInterfaceBlockRegisterMap;
std::map<std::string, unsigned int> mUniformBlockRegisterMap;
std::map<std::string, unsigned int> mUniformRegisterMap;
};
......
......@@ -4,7 +4,7 @@
// found in the LICENSE file.
//
// UniformHLSL.cpp:
// Methods for GLSL to HLSL translation for uniforms and interface blocks.
// Methods for GLSL to HLSL translation for uniforms and uniform blocks.
//
#include "compiler/translator/UniformHLSL.h"
......@@ -65,7 +65,7 @@ UniformHLSL::UniformHLSL(StructureHLSL *structureHLSL,
ShShaderOutput outputType,
const std::vector<Uniform> &uniforms)
: mUniformRegister(0),
mInterfaceBlockRegister(0),
mUniformBlockRegister(0),
mSamplerRegister(0),
mStructureHLSL(structureHLSL),
mOutputType(outputType),
......@@ -78,9 +78,9 @@ void UniformHLSL::reserveUniformRegisters(unsigned int registerCount)
mUniformRegister = registerCount;
}
void UniformHLSL::reserveInterfaceBlockRegisters(unsigned int registerCount)
void UniformHLSL::reserveUniformBlockRegisters(unsigned int registerCount)
{
mInterfaceBlockRegister = registerCount;
mUniformBlockRegister = registerCount;
}
const Uniform *UniformHLSL::findUniformByName(const TString &name) const
......@@ -354,7 +354,7 @@ void UniformHLSL::samplerMetadataUniforms(TInfoSinkBase &out, const char *reg)
}
}
TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks)
TString UniformHLSL::uniformBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks)
{
TString interfaceBlocks;
......@@ -365,16 +365,16 @@ TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedIn
const TInterfaceBlock &interfaceBlock = *nodeType.getInterfaceBlock();
unsigned int arraySize = static_cast<unsigned int>(interfaceBlock.arraySize());
unsigned int activeRegister = mInterfaceBlockRegister;
unsigned int activeRegister = mUniformBlockRegister;
mInterfaceBlockRegisterMap[interfaceBlock.name().c_str()] = activeRegister;
mInterfaceBlockRegister += std::max(1u, arraySize);
mUniformBlockRegisterMap[interfaceBlock.name().c_str()] = activeRegister;
mUniformBlockRegister += std::max(1u, arraySize);
// FIXME: interface block field names
if (interfaceBlock.hasInstanceName())
{
interfaceBlocks += interfaceBlockStructString(interfaceBlock);
interfaceBlocks += uniformBlockStructString(interfaceBlock);
}
if (arraySize > 0)
......@@ -382,22 +382,21 @@ TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedIn
for (unsigned int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++)
{
interfaceBlocks +=
interfaceBlockString(interfaceBlock, activeRegister + arrayIndex, arrayIndex);
uniformBlockString(interfaceBlock, activeRegister + arrayIndex, arrayIndex);
}
}
else
{
interfaceBlocks +=
interfaceBlockString(interfaceBlock, activeRegister, GL_INVALID_INDEX);
interfaceBlocks += uniformBlockString(interfaceBlock, activeRegister, GL_INVALID_INDEX);
}
}
return (interfaceBlocks.empty() ? "" : ("// Interface Blocks\n\n" + interfaceBlocks));
return (interfaceBlocks.empty() ? "" : ("// Uniform Blocks\n\n" + interfaceBlocks));
}
TString UniformHLSL::interfaceBlockString(const TInterfaceBlock &interfaceBlock,
unsigned int registerIndex,
unsigned int arrayIndex)
TString UniformHLSL::uniformBlockString(const TInterfaceBlock &interfaceBlock,
unsigned int registerIndex,
unsigned int arrayIndex)
{
const TString &arrayIndexString =
(arrayIndex != GL_INVALID_INDEX ? Decorate(str(arrayIndex)) : "");
......@@ -411,12 +410,12 @@ TString UniformHLSL::interfaceBlockString(const TInterfaceBlock &interfaceBlock,
if (interfaceBlock.hasInstanceName())
{
hlsl += " " + InterfaceBlockStructName(interfaceBlock) + " " +
interfaceBlockInstanceString(interfaceBlock, arrayIndex) + ";\n";
uniformBlockInstanceString(interfaceBlock, arrayIndex) + ";\n";
}
else
{
const TLayoutBlockStorage blockStorage = interfaceBlock.blockStorage();
hlsl += interfaceBlockMembersString(interfaceBlock, blockStorage);
hlsl += uniformBlockMembersString(interfaceBlock, blockStorage);
}
hlsl += "};\n\n";
......@@ -424,8 +423,8 @@ TString UniformHLSL::interfaceBlockString(const TInterfaceBlock &interfaceBlock,
return hlsl;
}
TString UniformHLSL::interfaceBlockInstanceString(const TInterfaceBlock &interfaceBlock,
unsigned int arrayIndex)
TString UniformHLSL::uniformBlockInstanceString(const TInterfaceBlock &interfaceBlock,
unsigned int arrayIndex)
{
if (!interfaceBlock.hasInstanceName())
{
......@@ -441,8 +440,8 @@ TString UniformHLSL::interfaceBlockInstanceString(const TInterfaceBlock &interfa
}
}
TString UniformHLSL::interfaceBlockMembersString(const TInterfaceBlock &interfaceBlock,
TLayoutBlockStorage blockStorage)
TString UniformHLSL::uniformBlockMembersString(const TInterfaceBlock &interfaceBlock,
TLayoutBlockStorage blockStorage)
{
TString hlsl;
......@@ -475,13 +474,13 @@ TString UniformHLSL::interfaceBlockMembersString(const TInterfaceBlock &interfac
return hlsl;
}
TString UniformHLSL::interfaceBlockStructString(const TInterfaceBlock &interfaceBlock)
TString UniformHLSL::uniformBlockStructString(const TInterfaceBlock &interfaceBlock)
{
const TLayoutBlockStorage blockStorage = interfaceBlock.blockStorage();
return "struct " + InterfaceBlockStructName(interfaceBlock) +
"\n"
"{\n" +
interfaceBlockMembersString(interfaceBlock, blockStorage) + "};\n\n";
uniformBlockMembersString(interfaceBlock, blockStorage) + "};\n\n";
}
}
......@@ -4,7 +4,7 @@
// found in the LICENSE file.
//
// UniformHLSL.h:
// Methods for GLSL to HLSL translation for uniforms and interface blocks.
// Methods for GLSL to HLSL translation for uniforms and uniform blocks.
//
#ifndef COMPILER_TRANSLATOR_UNIFORMHLSL_H_
......@@ -25,7 +25,7 @@ class UniformHLSL : angle::NonCopyable
const std::vector<Uniform> &uniforms);
void reserveUniformRegisters(unsigned int registerCount);
void reserveInterfaceBlockRegisters(unsigned int registerCount);
void reserveUniformBlockRegisters(unsigned int registerCount);
void uniformsHeader(TInfoSinkBase &out,
ShShaderOutput outputType,
const ReferencedSymbols &referencedUniforms);
......@@ -33,15 +33,15 @@ class UniformHLSL : angle::NonCopyable
// Must be called after uniformsHeader
void samplerMetadataUniforms(TInfoSinkBase &out, const char *reg);
TString interfaceBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks);
TString uniformBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks);
// Used for direct index references
static TString interfaceBlockInstanceString(const TInterfaceBlock &interfaceBlock,
unsigned int arrayIndex);
static TString uniformBlockInstanceString(const TInterfaceBlock &interfaceBlock,
unsigned int arrayIndex);
const std::map<std::string, unsigned int> &getInterfaceBlockRegisterMap() const
const std::map<std::string, unsigned int> &getUniformBlockRegisterMap() const
{
return mInterfaceBlockRegisterMap;
return mUniformBlockRegisterMap;
}
const std::map<std::string, unsigned int> &getUniformRegisterMap() const
{
......@@ -49,12 +49,12 @@ class UniformHLSL : angle::NonCopyable
}
private:
TString interfaceBlockString(const TInterfaceBlock &interfaceBlock,
unsigned int registerIndex,
unsigned int arrayIndex);
TString interfaceBlockMembersString(const TInterfaceBlock &interfaceBlock,
TLayoutBlockStorage blockStorage);
TString interfaceBlockStructString(const TInterfaceBlock &interfaceBlock);
TString uniformBlockString(const TInterfaceBlock &interfaceBlock,
unsigned int registerIndex,
unsigned int arrayIndex);
TString uniformBlockMembersString(const TInterfaceBlock &interfaceBlock,
TLayoutBlockStorage blockStorage);
TString uniformBlockStructString(const TInterfaceBlock &interfaceBlock);
const Uniform *findUniformByName(const TString &name) const;
void outputHLSL4_0_FL9_3Sampler(TInfoSinkBase &out,
......@@ -83,13 +83,13 @@ class UniformHLSL : angle::NonCopyable
unsigned int *groupTextureRegisterIndex);
unsigned int mUniformRegister;
unsigned int mInterfaceBlockRegister;
unsigned int mUniformBlockRegister;
unsigned int mSamplerRegister;
StructureHLSL *mStructureHLSL;
ShShaderOutput mOutputType;
const std::vector<Uniform> &mUniforms;
std::map<std::string, unsigned int> mInterfaceBlockRegisterMap;
std::map<std::string, unsigned int> mUniformBlockRegisterMap;
std::map<std::string, unsigned int> mUniformRegisterMap;
};
}
......
......@@ -35,6 +35,20 @@ BlockLayoutType GetBlockLayoutType(TLayoutBlockStorage blockStorage)
}
}
BlockType GetBlockType(TQualifier qualifier)
{
switch (qualifier)
{
case EvqUniform:
return BlockType::BLOCK_UNIFORM;
case EvqBuffer:
return BlockType::BLOCK_BUFFER;
default:
UNREACHABLE();
return BlockType::BLOCK_UNIFORM;
}
}
void ExpandUserDefinedVariable(const ShaderVariable &variable,
const std::string &name,
const std::string &mappedName,
......@@ -94,7 +108,8 @@ class CollectVariablesTraverser : public TIntermTraverser
std::vector<Uniform> *uniforms,
std::vector<Varying> *inputVaryings,
std::vector<Varying> *outputVaryings,
std::vector<InterfaceBlock> *interfaceBlocks,
std::vector<InterfaceBlock> *uniformBlocks,
std::vector<InterfaceBlock> *shaderStorageBlocks,
ShHashFunction64 hashFunction,
TSymbolTable *symbolTable,
int shaderVersion,
......@@ -128,7 +143,8 @@ class CollectVariablesTraverser : public TIntermTraverser
std::vector<Uniform> *mUniforms;
std::vector<Varying> *mInputVaryings;
std::vector<Varying> *mOutputVaryings;
std::vector<InterfaceBlock> *mInterfaceBlocks;
std::vector<InterfaceBlock> *mUniformBlocks;
std::vector<InterfaceBlock> *mShaderStorageBlocks;
std::map<std::string, InterfaceBlockField *> mInterfaceBlockFields;
......@@ -161,7 +177,8 @@ CollectVariablesTraverser::CollectVariablesTraverser(
std::vector<sh::Uniform> *uniforms,
std::vector<sh::Varying> *inputVaryings,
std::vector<sh::Varying> *outputVaryings,
std::vector<sh::InterfaceBlock> *interfaceBlocks,
std::vector<sh::InterfaceBlock> *uniformBlocks,
std::vector<sh::InterfaceBlock> *shaderStorageBlocks,
ShHashFunction64 hashFunction,
TSymbolTable *symbolTable,
int shaderVersion,
......@@ -172,7 +189,8 @@ CollectVariablesTraverser::CollectVariablesTraverser(
mUniforms(uniforms),
mInputVaryings(inputVaryings),
mOutputVaryings(outputVaryings),
mInterfaceBlocks(interfaceBlocks),
mUniformBlocks(uniformBlocks),
mShaderStorageBlocks(shaderStorageBlocks),
mDepthRangeAdded(false),
mPointCoordAdded(false),
mFrontFacingAdded(false),
......@@ -347,7 +365,7 @@ void CollectVariablesTraverser::visitSymbol(TIntermSymbol *symbol)
if (interfaceBlock)
{
InterfaceBlock *namedBlock =
FindVariable(interfaceBlock->name(), mInterfaceBlocks);
FindVariable(interfaceBlock->name(), mUniformBlocks);
ASSERT(namedBlock);
var = FindVariable(symbolName, &namedBlock->fields);
......@@ -548,6 +566,7 @@ InterfaceBlock CollectVariablesTraverser::recordInterfaceBlock(const TIntermSymb
interfaceBlock.isRowMajorLayout = (blockType->matrixPacking() == EmpRowMajor);
interfaceBlock.binding = blockType->blockBinding();
interfaceBlock.layout = GetBlockLayoutType(blockType->blockStorage());
interfaceBlock.blockType = GetBlockType(variable.getType().getQualifier());
// Gather field information
for (const TField *field : blockType->fields())
......@@ -605,12 +624,13 @@ bool CollectVariablesTraverser::visitDeclaration(Visit, TIntermDeclaration *node
if (typedNode.getBasicType() == EbtInterfaceBlock)
{
// TODO(jiajia.qin@intel.com): In order not to affect the old set of mInterfaceBlocks,
// only uniform blocks are added into mInterfaceBlocks. Refactor it to gather
// uniformBlocks and shaderStorageBlocks separately.
if (qualifier == EvqUniform)
{
mInterfaceBlocks->push_back(recordInterfaceBlock(variable));
mUniformBlocks->push_back(recordInterfaceBlock(variable));
}
else if (qualifier == EvqBuffer)
{
mShaderStorageBlocks->push_back(recordInterfaceBlock(variable));
}
}
else
......@@ -659,16 +679,16 @@ bool CollectVariablesTraverser::visitBinary(Visit, TIntermBinary *binaryNode)
ASSERT(constantUnion);
const TInterfaceBlock *interfaceBlock = blockNode->getType().getInterfaceBlock();
InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks);
// TODO(jiajia.qin@intel.com): Currently, only uniform blocks are added into
// mInterfaceBlocks.
if (namedBlock)
InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mUniformBlocks);
if (!namedBlock)
{
namedBlock->staticUse = true;
unsigned int fieldIndex = static_cast<unsigned int>(constantUnion->getIConst(0));
ASSERT(fieldIndex < namedBlock->fields.size());
namedBlock->fields[fieldIndex].staticUse = true;
namedBlock = FindVariable(interfaceBlock->name(), mShaderStorageBlocks);
}
ASSERT(namedBlock);
namedBlock->staticUse = true;
unsigned int fieldIndex = static_cast<unsigned int>(constantUnion->getIConst(0));
ASSERT(fieldIndex < namedBlock->fields.size());
namedBlock->fields[fieldIndex].staticUse = true;
return false;
}
......@@ -683,15 +703,16 @@ void CollectVariables(TIntermBlock *root,
std::vector<Uniform> *uniforms,
std::vector<Varying> *inputVaryings,
std::vector<Varying> *outputVaryings,
std::vector<InterfaceBlock> *interfaceBlocks,
std::vector<InterfaceBlock> *uniformBlocks,
std::vector<InterfaceBlock> *shaderStorageBlocks,
ShHashFunction64 hashFunction,
TSymbolTable *symbolTable,
int shaderVersion,
const TExtensionBehavior &extensionBehavior)
{
CollectVariablesTraverser collect(attributes, outputVariables, uniforms, inputVaryings,
outputVaryings, interfaceBlocks, hashFunction, symbolTable,
shaderVersion, extensionBehavior);
outputVaryings, uniformBlocks, shaderStorageBlocks,
hashFunction, symbolTable, shaderVersion, extensionBehavior);
root->traverse(&collect);
}
......
......@@ -23,7 +23,8 @@ void CollectVariables(TIntermBlock *root,
std::vector<Uniform> *uniforms,
std::vector<Varying> *inputVaryings,
std::vector<Varying> *outputVaryings,
std::vector<InterfaceBlock> *interfaceBlocks,
std::vector<InterfaceBlock> *uniformBlocks,
std::vector<InterfaceBlock> *shaderStorageBlocks,
ShHashFunction64 hashFunction,
TSymbolTable *symbolTable,
int shaderVersion,
......
......@@ -2094,7 +2094,7 @@ bool Program::linkUniformBlocks(const Context *context, InfoLog &infoLog)
if (mState.mAttachedComputeShader)
{
Shader &computeShader = *mState.mAttachedComputeShader;
const auto &computeInterfaceBlocks = computeShader.getInterfaceBlocks(context);
const auto &computeInterfaceBlocks = computeShader.getUniformBlocks(context);
if (!validateUniformBlocksCount(
caps.maxComputeUniformBlocks, computeInterfaceBlocks,
......@@ -2109,8 +2109,8 @@ bool Program::linkUniformBlocks(const Context *context, InfoLog &infoLog)
Shader &vertexShader = *mState.mAttachedVertexShader;
Shader &fragmentShader = *mState.mAttachedFragmentShader;
const auto &vertexInterfaceBlocks = vertexShader.getInterfaceBlocks(context);
const auto &fragmentInterfaceBlocks = fragmentShader.getInterfaceBlocks(context);
const auto &vertexInterfaceBlocks = vertexShader.getUniformBlocks(context);
const auto &fragmentInterfaceBlocks = fragmentShader.getUniformBlocks(context);
if (!validateUniformBlocksCount(
caps.maxVertexUniformBlocks, vertexInterfaceBlocks,
......@@ -2674,7 +2674,7 @@ void Program::gatherInterfaceBlockInfo(const Context *context)
{
Shader *computeShader = mState.getAttachedComputeShader();
for (const sh::InterfaceBlock &computeBlock : computeShader->getInterfaceBlocks(context))
for (const sh::InterfaceBlock &computeBlock : computeShader->getUniformBlocks(context))
{
// Only 'packed' blocks are allowed to be considered inactive.
......@@ -2698,7 +2698,7 @@ void Program::gatherInterfaceBlockInfo(const Context *context)
Shader *vertexShader = mState.getAttachedVertexShader();
for (const sh::InterfaceBlock &vertexBlock : vertexShader->getInterfaceBlocks(context))
for (const sh::InterfaceBlock &vertexBlock : vertexShader->getUniformBlocks(context))
{
// Only 'packed' blocks are allowed to be considered inactive.
if (!vertexBlock.staticUse && vertexBlock.layout == sh::BLOCKLAYOUT_PACKED)
......@@ -2713,7 +2713,7 @@ void Program::gatherInterfaceBlockInfo(const Context *context)
Shader *fragmentShader = mState.getAttachedFragmentShader();
for (const sh::InterfaceBlock &fragmentBlock : fragmentShader->getInterfaceBlocks(context))
for (const sh::InterfaceBlock &fragmentBlock : fragmentShader->getUniformBlocks(context))
{
// Only 'packed' blocks are allowed to be considered inactive.
if (!fragmentBlock.staticUse && fragmentBlock.layout == sh::BLOCKLAYOUT_PACKED)
......
......@@ -270,7 +270,8 @@ void Shader::compile(const Context *context)
mState.mShaderVersion = 100;
mState.mVaryings.clear();
mState.mUniforms.clear();
mState.mInterfaceBlocks.clear();
mState.mUniformBlocks.clear();
mState.mShaderStorageBlocks.clear();
mState.mActiveAttributes.clear();
mState.mActiveOutputVariables.clear();
mState.mNumViews = -1;
......@@ -361,7 +362,8 @@ void Shader::resolveCompile(const Context *context)
mState.mVaryings = GetShaderVariables(sh::GetVaryings(compilerHandle));
mState.mUniforms = GetShaderVariables(sh::GetUniforms(compilerHandle));
mState.mInterfaceBlocks = GetShaderVariables(sh::GetInterfaceBlocks(compilerHandle));
mState.mUniformBlocks = GetShaderVariables(sh::GetUniformBlocks(compilerHandle));
mState.mShaderStorageBlocks = GetShaderVariables(sh::GetShaderStorageBlocks(compilerHandle));
switch (mState.mShaderType)
{
......@@ -451,10 +453,16 @@ const std::vector<sh::Uniform> &Shader::getUniforms(const Context *context)
return mState.getUniforms();
}
const std::vector<sh::InterfaceBlock> &Shader::getInterfaceBlocks(const Context *context)
const std::vector<sh::InterfaceBlock> &Shader::getUniformBlocks(const Context *context)
{
resolveCompile(context);
return mState.getInterfaceBlocks();
return mState.getUniformBlocks();
}
const std::vector<sh::InterfaceBlock> &Shader::getShaderStorageBlocks(const Context *context)
{
resolveCompile(context);
return mState.getShaderStorageBlocks();
}
const std::vector<sh::Attribute> &Shader::getActiveAttributes(const Context *context)
......
......@@ -64,7 +64,11 @@ class ShaderState final : angle::NonCopyable
const std::vector<sh::Varying> &getVaryings() const { return mVaryings; }
const std::vector<sh::Uniform> &getUniforms() const { return mUniforms; }
const std::vector<sh::InterfaceBlock> &getInterfaceBlocks() const { return mInterfaceBlocks; }
const std::vector<sh::InterfaceBlock> &getUniformBlocks() const { return mUniformBlocks; }
const std::vector<sh::InterfaceBlock> &getShaderStorageBlocks() const
{
return mShaderStorageBlocks;
}
const std::vector<sh::Attribute> &getActiveAttributes() const { return mActiveAttributes; }
const std::vector<sh::OutputVariable> &getActiveOutputVariables() const
{
......@@ -87,7 +91,8 @@ class ShaderState final : angle::NonCopyable
std::vector<sh::Varying> mVaryings;
std::vector<sh::Uniform> mUniforms;
std::vector<sh::InterfaceBlock> mInterfaceBlocks;
std::vector<sh::InterfaceBlock> mUniformBlocks;
std::vector<sh::InterfaceBlock> mShaderStorageBlocks;
std::vector<sh::Attribute> mActiveAttributes;
std::vector<sh::OutputVariable> mActiveOutputVariables;
......@@ -148,7 +153,8 @@ class Shader final : angle::NonCopyable, public LabeledObject
const std::vector<sh::Varying> &getVaryings(const Context *context);
const std::vector<sh::Uniform> &getUniforms(const Context *context);
const std::vector<sh::InterfaceBlock> &getInterfaceBlocks(const Context *context);
const std::vector<sh::InterfaceBlock> &getUniformBlocks(const Context *context);
const std::vector<sh::InterfaceBlock> &getShaderStorageBlocks(const Context *context);
const std::vector<sh::Attribute> &getActiveAttributes(const Context *context);
const std::vector<sh::OutputVariable> &getActiveOutputVariables(const Context *context);
......
......@@ -1603,7 +1603,7 @@ GLboolean ProgramD3D::validate(const gl::Caps & /*caps*/, gl::InfoLog * /*infoLo
void ProgramD3D::initUniformBlockInfo(const gl::Context *context, gl::Shader *shader)
{
for (const sh::InterfaceBlock &interfaceBlock : shader->getInterfaceBlocks(context))
for (const sh::InterfaceBlock &interfaceBlock : shader->getUniformBlocks(context))
{
if (!interfaceBlock.staticUse && interfaceBlock.layout == sh::BLOCKLAYOUT_PACKED)
continue;
......@@ -1639,8 +1639,7 @@ void ProgramD3D::ensureUniformBlocksInitialized()
if (uniformBlock.vertexStaticUse)
{
ASSERT(vertexShaderD3D != nullptr);
unsigned int baseRegister =
vertexShaderD3D->getInterfaceBlockRegister(uniformBlock.name);
unsigned int baseRegister = vertexShaderD3D->getUniformBlockRegister(uniformBlock.name);
d3dUniformBlock.vsRegisterIndex = baseRegister + uniformBlockElement;
}
......@@ -1648,7 +1647,7 @@ void ProgramD3D::ensureUniformBlocksInitialized()
{
ASSERT(fragmentShaderD3D != nullptr);
unsigned int baseRegister =
fragmentShaderD3D->getInterfaceBlockRegister(uniformBlock.name);
fragmentShaderD3D->getUniformBlockRegister(uniformBlock.name);
d3dUniformBlock.psRegisterIndex = baseRegister + uniformBlockElement;
}
......@@ -1656,7 +1655,7 @@ void ProgramD3D::ensureUniformBlocksInitialized()
{
ASSERT(computeShaderD3D != nullptr);
unsigned int baseRegister =
computeShaderD3D->getInterfaceBlockRegister(uniformBlock.name);
computeShaderD3D->getUniformBlockRegister(uniformBlock.name);
d3dUniformBlock.csRegisterIndex = baseRegister + uniformBlockElement;
}
......
......@@ -138,10 +138,10 @@ unsigned int ShaderD3D::getUniformRegister(const std::string &uniformName) const
return mUniformRegisterMap.find(uniformName)->second;
}
unsigned int ShaderD3D::getInterfaceBlockRegister(const std::string &blockName) const
unsigned int ShaderD3D::getUniformBlockRegister(const std::string &blockName) const
{
ASSERT(mInterfaceBlockRegisterMap.count(blockName) > 0);
return mInterfaceBlockRegisterMap.find(blockName)->second;
ASSERT(mUniformBlockRegisterMap.count(blockName) > 0);
return mUniformBlockRegisterMap.find(blockName)->second;
}
ShShaderOutput ShaderD3D::getCompilerOutputType() const
......@@ -211,16 +211,16 @@ bool ShaderD3D::postTranslateCompile(gl::Compiler *compiler, std::string *infoLo
mUniformRegisterMap = GetUniformRegisterMap(sh::GetUniformRegisterMap(compilerHandle));
for (const sh::InterfaceBlock &interfaceBlock : mData.getInterfaceBlocks())
for (const sh::InterfaceBlock &interfaceBlock : mData.getUniformBlocks())
{
if (interfaceBlock.staticUse)
{
unsigned int index = static_cast<unsigned int>(-1);
bool blockRegisterResult =
sh::GetInterfaceBlockRegister(compilerHandle, interfaceBlock.name, &index);
sh::GetUniformBlockRegister(compilerHandle, interfaceBlock.name, &index);
ASSERT(blockRegisterResult);
mInterfaceBlockRegisterMap[interfaceBlock.name] = index;
mUniformBlockRegisterMap[interfaceBlock.name] = index;
}
}
......
......@@ -46,7 +46,7 @@ class ShaderD3D : public ShaderImpl
// using dot (.) operator.
unsigned int getUniformRegister(const std::string &uniformName) const;
unsigned int getInterfaceBlockRegister(const std::string &blockName) const;
unsigned int getUniformBlockRegister(const std::string &blockName) const;
void appendDebugInfo(const std::string &info) const { mDebugInfo += info; }
void generateWorkarounds(angle::CompilerWorkaroundsD3D *workarounds) const;
......@@ -80,7 +80,7 @@ class ShaderD3D : public ShaderImpl
ShShaderOutput mCompilerOutputType;
mutable std::string mDebugInfo;
std::map<std::string, unsigned int> mUniformRegisterMap;
std::map<std::string, unsigned int> mInterfaceBlockRegisterMap;
std::map<std::string, unsigned int> mUniformBlockRegisterMap;
ShCompileOptions mAdditionalOptions;
};
} // namespace rx
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment