Commit f91ce811 by Jamie Madill

Split OutputHLSL uniform code into new module.

Refactoring patch only, should have no externally visible changes. BUG=angle:466 Change-Id: I01088a3b2979b96702d0a3c424d26928eb72b5b2 Reviewed-on: https://chromium-review.googlesource.com/203731Reviewed-by: 's avatarNicolas Capens <nicolascapens@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 8daaba15
...@@ -180,6 +180,7 @@ ...@@ -180,6 +180,7 @@
<ClInclude Include="..\..\src\compiler\translator\InitializeParseContext.h"/> <ClInclude Include="..\..\src\compiler\translator\InitializeParseContext.h"/>
<ClInclude Include="..\..\src\compiler\translator\VariableInfo.h"/> <ClInclude Include="..\..\src\compiler\translator\VariableInfo.h"/>
<ClInclude Include="..\..\src\compiler\translator\LoopInfo.h"/> <ClInclude Include="..\..\src\compiler\translator\LoopInfo.h"/>
<ClInclude Include="..\..\src\compiler\translator\UniformHLSL.h"/>
<ClInclude Include="..\..\src\compiler\translator\glslang_tab.h"/> <ClInclude Include="..\..\src\compiler\translator\glslang_tab.h"/>
<ClInclude Include="..\..\src\compiler\translator\RewriteElseBlocks.h"/> <ClInclude Include="..\..\src\compiler\translator\RewriteElseBlocks.h"/>
<ClInclude Include="..\..\src\compiler\translator\ExtensionBehavior.h"/> <ClInclude Include="..\..\src\compiler\translator\ExtensionBehavior.h"/>
...@@ -252,6 +253,7 @@ ...@@ -252,6 +253,7 @@
<ClCompile Include="..\..\src\compiler\translator\DetectDiscontinuity.cpp"/> <ClCompile Include="..\..\src\compiler\translator\DetectDiscontinuity.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\StructureHLSL.cpp"/> <ClCompile Include="..\..\src\compiler\translator\StructureHLSL.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\UnfoldShortCircuit.cpp"/> <ClCompile Include="..\..\src\compiler\translator\UnfoldShortCircuit.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\UniformHLSL.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\compilerdebug.cpp"/> <ClCompile Include="..\..\src\compiler\translator\compilerdebug.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\VariableInfo.cpp"/> <ClCompile Include="..\..\src\compiler\translator\VariableInfo.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\Compiler.cpp"/> <ClCompile Include="..\..\src\compiler\translator\Compiler.cpp"/>
......
...@@ -390,6 +390,9 @@ ...@@ -390,6 +390,9 @@
<ClInclude Include="..\..\src\compiler\translator\LoopInfo.h"> <ClInclude Include="..\..\src\compiler\translator\LoopInfo.h">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\compiler\translator\UniformHLSL.h">
<Filter>src\compiler\translator</Filter>
</ClInclude>
<ClCompile Include="..\..\src\compiler\translator\DetectDiscontinuity.cpp"> <ClCompile Include="..\..\src\compiler\translator\DetectDiscontinuity.cpp">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</ClCompile> </ClCompile>
...@@ -405,6 +408,9 @@ ...@@ -405,6 +408,9 @@
<ClInclude Include="..\..\src\compiler\translator\RewriteElseBlocks.h"> <ClInclude Include="..\..\src\compiler\translator\RewriteElseBlocks.h">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</ClInclude> </ClInclude>
<ClCompile Include="..\..\src\compiler\translator\UniformHLSL.cpp">
<Filter>src\compiler\translator</Filter>
</ClCompile>
<ClCompile Include="..\..\src\compiler\translator\compilerdebug.cpp"> <ClCompile Include="..\..\src\compiler\translator\compilerdebug.cpp">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</ClCompile> </ClCompile>
......
...@@ -69,7 +69,7 @@ class Std140BlockEncoder : public BlockLayoutEncoder ...@@ -69,7 +69,7 @@ class Std140BlockEncoder : public BlockLayoutEncoder
// Block layout packed according to the D3D9 or default D3D10+ register packing rules // Block layout packed according to the D3D9 or default D3D10+ register packing rules
// See http://msdn.microsoft.com/en-us/library/windows/desktop/bb509632(v=vs.85).aspx // See http://msdn.microsoft.com/en-us/library/windows/desktop/bb509632(v=vs.85).aspx
// The strategy should be ENCODE_LOOSE for D3D9 constnat blocks, and ENCODE_PACKED // The strategy should be ENCODE_LOOSE for D3D9 constant blocks, and ENCODE_PACKED
// for everything else (D3D10+ constant blocks and all attributes/varyings). // for everything else (D3D10+ constant blocks and all attributes/varyings).
class HLSLBlockEncoder : public BlockLayoutEncoder class HLSLBlockEncoder : public BlockLayoutEncoder
......
...@@ -58,9 +58,11 @@ struct ShaderVariable ...@@ -58,9 +58,11 @@ struct ShaderVariable
// Uniform registers (and element indices) are assigned when outputting shader code // Uniform registers (and element indices) are assigned when outputting shader code
struct Uniform : public ShaderVariable struct Uniform : public ShaderVariable
{ {
std::vector<Uniform> fields;
// HLSL-specific members
unsigned int registerIndex; unsigned int registerIndex;
unsigned int elementIndex; // Offset within a register, for struct members unsigned int elementIndex; // Offset within a register, for struct members
std::vector<Uniform> fields;
Uniform(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, Uniform(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn,
unsigned int registerIndexIn, unsigned int elementIndexIn) unsigned int registerIndexIn, unsigned int elementIndexIn)
...@@ -146,6 +148,7 @@ struct InterfaceBlock ...@@ -146,6 +148,7 @@ struct InterfaceBlock
std::vector<InterfaceBlockField> fields; std::vector<InterfaceBlockField> fields;
std::vector<BlockMemberInfo> blockInfo; std::vector<BlockMemberInfo> blockInfo;
// HLSL-specific members
unsigned int registerIndex; unsigned int registerIndex;
InterfaceBlock(const char *name, unsigned int arraySize, unsigned int registerIndex) InterfaceBlock(const char *name, unsigned int arraySize, unsigned int registerIndex)
......
...@@ -22,6 +22,9 @@ namespace sh ...@@ -22,6 +22,9 @@ namespace sh
{ {
class UnfoldShortCircuit; class UnfoldShortCircuit;
class StructureHLSL; class StructureHLSL;
class UniformHLSL;
typedef std::map<TString, TIntermSymbol*> ReferencedSymbols;
class OutputHLSL : public TIntermTraverser class OutputHLSL : public TIntermTraverser
{ {
...@@ -74,7 +77,6 @@ class OutputHLSL : public TIntermTraverser ...@@ -74,7 +77,6 @@ class OutputHLSL : public TIntermTraverser
TInfoSinkBase mBody; TInfoSinkBase mBody;
TInfoSinkBase mFooter; TInfoSinkBase mFooter;
typedef std::map<TString, TIntermSymbol*> ReferencedSymbols;
ReferencedSymbols mReferencedUniforms; ReferencedSymbols mReferencedUniforms;
ReferencedSymbols mReferencedInterfaceBlocks; ReferencedSymbols mReferencedInterfaceBlocks;
ReferencedSymbols mReferencedAttributes; ReferencedSymbols mReferencedAttributes;
...@@ -82,6 +84,7 @@ class OutputHLSL : public TIntermTraverser ...@@ -82,6 +84,7 @@ class OutputHLSL : public TIntermTraverser
ReferencedSymbols mReferencedOutputVariables; ReferencedSymbols mReferencedOutputVariables;
StructureHLSL *mStructureHLSL; StructureHLSL *mStructureHLSL;
UniformHLSL *mUniformHLSL;
struct TextureFunction struct TextureFunction
{ {
...@@ -150,32 +153,10 @@ class OutputHLSL : public TIntermTraverser ...@@ -150,32 +153,10 @@ class OutputHLSL : public TIntermTraverser
TIntermSymbol *mExcessiveLoopIndex; TIntermSymbol *mExcessiveLoopIndex;
int mUniformRegister;
int mInterfaceBlockRegister;
int mSamplerRegister;
TString registerString(TIntermSymbol *operand);
int samplerRegister(TIntermSymbol *sampler);
int uniformRegister(TIntermSymbol *uniform);
void declareInterfaceBlockField(const TType &type, const TString &name, std::vector<gl::InterfaceBlockField>& output);
gl::Uniform declareUniformToList(const TType &type, const TString &name, int registerIndex, std::vector<gl::Uniform>& output);
void declareUniform(const TType &type, const TString &name, int index);
void declareVaryingToList(const TType &type, TQualifier baseTypeQualifier, const TString &name, std::vector<gl::Varying>& fieldsOut); void declareVaryingToList(const TType &type, TQualifier baseTypeQualifier, const TString &name, std::vector<gl::Varying>& fieldsOut);
// Returns the uniform's register index
int declareUniformAndAssignRegister(const TType &type, const TString &name);
TString interfaceBlockFieldString(const TInterfaceBlock &interfaceBlock, const TField &field);
TString interfaceBlockStructNameString(const TInterfaceBlock &interfaceBlockType);
TString interfaceBlockInstanceString(const TInterfaceBlock& interfaceBlock, unsigned int arrayIndex);
TString interfaceBlockFieldTypeString(const TField &field, TLayoutBlockStorage blockStorage);
TString interfaceBlockFieldString(const TInterfaceBlock &interfaceBlock, TLayoutBlockStorage blockStorage);
TString interfaceBlockStructString(const TInterfaceBlock &interfaceBlock);
TString interfaceBlockString(const TInterfaceBlock &interfaceBlock, unsigned int registerIndex, unsigned int arrayIndex);
TString structInitializerString(int indent, const TStructure &structure, const TString &rhsStructName); TString structInitializerString(int indent, const TStructure &structure, const TString &rhsStructName);
std::vector<gl::Uniform> mActiveUniforms;
std::vector<gl::InterfaceBlock> mActiveInterfaceBlocks;
std::vector<gl::Attribute> mActiveOutputVariables; std::vector<gl::Attribute> mActiveOutputVariables;
std::vector<gl::Attribute> mActiveAttributes; std::vector<gl::Attribute> mActiveAttributes;
std::vector<gl::Varying> mActiveVaryings; std::vector<gl::Varying> mActiveVaryings;
......
//
// Copyright (c) 2014 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.
//
// UniformHLSL.h:
// Methods for GLSL to HLSL translation for uniforms and interface blocks.
//
#ifndef TRANSLATOR_UNIFORMHLSL_H_
#define TRANSLATOR_UNIFORMHLSL_H_
#include "common/shadervars.h"
#include "compiler/translator/Types.h"
namespace sh
{
class StructureHLSL;
class UniformHLSL
{
public:
UniformHLSL(StructureHLSL *structureHLSL, ShShaderOutput outputType);
void reserveUniformRegisters(unsigned int registerCount);
void reserveInterfaceBlockRegisters(unsigned int registerCount);
TString uniformsHeader(ShShaderOutput outputType, const ReferencedSymbols &referencedUniforms);
TString interfaceBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks);
// Used for direct index references
static TString interfaceBlockInstanceString(const TInterfaceBlock& interfaceBlock, unsigned int arrayIndex);
const std::vector<gl::Uniform> &getUniforms() const { return mActiveUniforms; }
const std::vector<gl::InterfaceBlock> &getInterfaceBlocks() const { return mActiveInterfaceBlocks; }
private:
TString interfaceBlockString(const TInterfaceBlock &interfaceBlock, unsigned int registerIndex, unsigned int arrayIndex);
TString interfaceBlockMembersString(const TInterfaceBlock &interfaceBlock, TLayoutBlockStorage blockStorage);
TString interfaceBlockStructString(const TInterfaceBlock &interfaceBlock);
// Returns the uniform's register index
int declareUniformAndAssignRegister(const TType &type, const TString &name);
void declareInterfaceBlockField(const TType &type, const TString &name, std::vector<gl::InterfaceBlockField>& output);
gl::Uniform declareUniformToList(const TType &type, const TString &name, int registerIndex, std::vector<gl::Uniform> *output);
unsigned int mUniformRegister;
unsigned int mInterfaceBlockRegister;
unsigned int mSamplerRegister;
StructureHLSL *mStructureHLSL;
ShShaderOutput mOutputType;
std::vector<gl::Uniform> mActiveUniforms;
std::vector<gl::InterfaceBlock> mActiveInterfaceBlocks;
};
}
#endif // TRANSLATOR_UNIFORMHLSL_H_
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