Commit 8daaba15 by Jamie Madill

Split OutputHLSL structure code into new module.

Refactoring patch only. BUG=angle:466 Change-Id: I2c57096e1e24574e7de3d35d608645fde3b0c681 Reviewed-on: https://chromium-review.googlesource.com/203730Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarNicolas Capens <nicolascapens@chromium.org>
parent 033dae67
...@@ -159,6 +159,7 @@ ...@@ -159,6 +159,7 @@
<ClInclude Include="..\..\src\compiler\translator\InitializeVariables.h"/> <ClInclude Include="..\..\src\compiler\translator\InitializeVariables.h"/>
<ClInclude Include="..\..\src\compiler\translator\localintermediate.h"/> <ClInclude Include="..\..\src\compiler\translator\localintermediate.h"/>
<ClInclude Include="..\..\src\compiler\translator\ShHandle.h"/> <ClInclude Include="..\..\src\compiler\translator\ShHandle.h"/>
<ClInclude Include="..\..\src\compiler\translator\StructureHLSL.h"/>
<ClInclude Include="..\..\src\compiler\translator\OutputGLSLBase.h"/> <ClInclude Include="..\..\src\compiler\translator\OutputGLSLBase.h"/>
<ClInclude Include="..\..\src\compiler\translator\ForLoopUnroll.h"/> <ClInclude Include="..\..\src\compiler\translator\ForLoopUnroll.h"/>
<ClInclude Include="..\..\src\compiler\translator\Pragma.h"/> <ClInclude Include="..\..\src\compiler\translator\Pragma.h"/>
...@@ -249,6 +250,7 @@ ...@@ -249,6 +250,7 @@
<ClCompile Include="..\..\src\compiler\translator\LoopInfo.cpp"/> <ClCompile Include="..\..\src\compiler\translator\LoopInfo.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\OutputHLSL.cpp"/> <ClCompile Include="..\..\src\compiler\translator\OutputHLSL.cpp"/>
<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\UnfoldShortCircuit.cpp"/> <ClCompile Include="..\..\src\compiler\translator\UnfoldShortCircuit.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"/>
......
...@@ -261,6 +261,9 @@ ...@@ -261,6 +261,9 @@
<ClInclude Include="..\..\src\compiler\translator\ShHandle.h"> <ClInclude Include="..\..\src\compiler\translator\ShHandle.h">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\compiler\translator\StructureHLSL.h">
<Filter>src\compiler\translator</Filter>
</ClInclude>
<ClInclude Include="..\..\src\compiler\translator\OutputGLSLBase.h"> <ClInclude Include="..\..\src\compiler\translator\OutputGLSLBase.h">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</ClInclude> </ClInclude>
...@@ -390,6 +393,9 @@ ...@@ -390,6 +393,9 @@
<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>
<ClCompile Include="..\..\src\compiler\translator\StructureHLSL.cpp">
<Filter>src\compiler\translator</Filter>
</ClCompile>
<ClInclude Include="..\..\src\compiler\translator\glslang_tab.h"> <ClInclude Include="..\..\src\compiler\translator\glslang_tab.h">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</ClInclude> </ClInclude>
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
namespace sh namespace sh
{ {
class UnfoldShortCircuit; class UnfoldShortCircuit;
class Std140PaddingHelper; class StructureHLSL;
class OutputHLSL : public TIntermTraverser class OutputHLSL : public TIntermTraverser
{ {
...@@ -38,8 +38,6 @@ class OutputHLSL : public TIntermTraverser ...@@ -38,8 +38,6 @@ class OutputHLSL : public TIntermTraverser
const std::vector<gl::Attribute> &getAttributes() const; const std::vector<gl::Attribute> &getAttributes() const;
const std::vector<gl::Varying> &getVaryings() const; const std::vector<gl::Varying> &getVaryings() const;
static TString defineNamelessStruct(const TStructure &structure);
TString defineQualifiedStruct(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing);
static TString initializer(const TType &type); static TString initializer(const TType &type);
protected: protected:
...@@ -64,8 +62,6 @@ class OutputHLSL : public TIntermTraverser ...@@ -64,8 +62,6 @@ class OutputHLSL : public TIntermTraverser
int vectorSize(const TType &type) const; int vectorSize(const TType &type) const;
void outputConstructor(Visit visit, const TType &type, const TString &name, const TIntermSequence *parameters); void outputConstructor(Visit visit, const TType &type, const TString &name, const TIntermSequence *parameters);
void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters);
void storeStd140ElementIndex(const TStructure &structure, bool useHLSLRowMajorPacking);
const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *constUnion); const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *constUnion);
TParseContext &mContext; TParseContext &mContext;
...@@ -85,6 +81,8 @@ class OutputHLSL : public TIntermTraverser ...@@ -85,6 +81,8 @@ class OutputHLSL : public TIntermTraverser
ReferencedSymbols mReferencedVaryings; ReferencedSymbols mReferencedVaryings;
ReferencedSymbols mReferencedOutputVariables; ReferencedSymbols mReferencedOutputVariables;
StructureHLSL *mStructureHLSL;
struct TextureFunction struct TextureFunction
{ {
enum Method enum Method
...@@ -143,15 +141,6 @@ class OutputHLSL : public TIntermTraverser ...@@ -143,15 +141,6 @@ class OutputHLSL : public TIntermTraverser
int mNumRenderTargets; int mNumRenderTargets;
typedef std::set<TString> Constructors;
Constructors mConstructors;
typedef std::set<TString> StructNames;
StructNames mStructNames;
typedef std::list<TString> StructDeclarations;
StructDeclarations mStructDeclarations;
int mUniqueIndex; // For creating unique names int mUniqueIndex; // For creating unique names
bool mContainsLoopDiscontinuity; bool mContainsLoopDiscontinuity;
...@@ -184,20 +173,18 @@ class OutputHLSL : public TIntermTraverser ...@@ -184,20 +173,18 @@ class OutputHLSL : public TIntermTraverser
TString interfaceBlockStructString(const TInterfaceBlock &interfaceBlock); TString interfaceBlockStructString(const TInterfaceBlock &interfaceBlock);
TString interfaceBlockString(const TInterfaceBlock &interfaceBlock, unsigned int registerIndex, unsigned int arrayIndex); 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);
static TString defineStruct(const TStructure &structure, bool useHLSLRowMajorPacking,
bool useStd140Packing, Std140PaddingHelper *padHelper);
std::vector<gl::Uniform> mActiveUniforms; std::vector<gl::Uniform> mActiveUniforms;
std::vector<gl::InterfaceBlock> mActiveInterfaceBlocks; 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;
std::map<TString, int> mStd140StructElementIndexes;
std::map<TIntermTyped*, TString> mFlaggedStructMappedNames; std::map<TIntermTyped*, TString> mFlaggedStructMappedNames;
std::map<TIntermTyped*, TString> mFlaggedStructOriginalNames; std::map<TIntermTyped*, TString> mFlaggedStructOriginalNames;
void makeFlaggedStructMaps(const std::vector<TIntermTyped *> &flaggedStructs); void makeFlaggedStructMaps(const std::vector<TIntermTyped *> &flaggedStructs);
}; };
} }
#endif // COMPILER_OUTPUTHLSL_H_ #endif // COMPILER_OUTPUTHLSL_H_
//
// 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.
//
// StructureHLSL.h:
// Interfaces of methods for HLSL translation of GLSL structures.
//
#ifndef TRANSLATOR_STRUCTUREHLSL_H_
#define TRANSLATOR_STRUCTUREHLSL_H_
#include "compiler/translator/Common.h"
#include "compiler/translator/intermediate.h"
#include <set>
class TInfoSinkBase;
class TScopeBracket;
namespace sh
{
// This helper class assists structure and interface block definitions in determining
// how to pack std140 structs within HLSL's packing rules.
class Std140PaddingHelper
{
public:
explicit Std140PaddingHelper(const std::map<TString, int> &structElementIndexes);
int elementIndex() const { return mElementIndex; }
int prePadding(const TType &type);
TString prePaddingString(const TType &type);
TString postPaddingString(const TType &type, bool useHLSLRowMajorPacking);
private:
int mPaddingCounter;
int mElementIndex;
const std::map<TString, int> &mStructElementIndexes;
};
class StructureHLSL
{
public:
StructureHLSL();
void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters);
std::string structsHeader() const;
TString defineQualified(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing);
static TString defineNameless(const TStructure &structure);
Std140PaddingHelper getPaddingHelper() const { return Std140PaddingHelper(mStd140StructElementIndexes); }
private:
std::map<TString, int> mStd140StructElementIndexes;
typedef std::set<TString> StructNames;
StructNames mStructNames;
typedef std::set<TString> Constructors;
Constructors mConstructors;
typedef std::vector<TString> StructDeclarations;
StructDeclarations mStructDeclarations;
void storeStd140ElementIndex(const TStructure &structure, bool useHLSLRowMajorPacking);
static TString define(const TStructure &structure, bool useHLSLRowMajorPacking,
bool useStd140Packing, Std140PaddingHelper *padHelper);
};
}
#endif // COMPILER_STRUCTUREHLSL_H_
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// //
#include "compiler/translator/UtilsHLSL.h" #include "compiler/translator/UtilsHLSL.h"
#include "compiler/translator/OutputHLSL.h" #include "compiler/translator/StructureHLSL.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
namespace sh namespace sh
...@@ -99,7 +99,7 @@ TString TypeString(const TType &type) ...@@ -99,7 +99,7 @@ TString TypeString(const TType &type)
} }
else // Nameless structure, define in place else // Nameless structure, define in place
{ {
return OutputHLSL::defineNamelessStruct(*structure); return StructureHLSL::defineNameless(*structure);
} }
} }
else if (type.isMatrix()) else if (type.isMatrix())
...@@ -175,7 +175,7 @@ TString StructNameString(const TStructure &structure) ...@@ -175,7 +175,7 @@ TString StructNameString(const TStructure &structure)
return ""; return "";
} }
return "ss_" + str(structure.uniqueId()) + structure.name(); return "ss" + str(structure.uniqueId()) + "_" + structure.name();
} }
TString QualifiedStructNameString(const TStructure &structure, bool useHLSLRowMajorPacking, TString QualifiedStructNameString(const TStructure &structure, bool useHLSLRowMajorPacking,
...@@ -193,13 +193,12 @@ TString QualifiedStructNameString(const TStructure &structure, bool useHLSLRowMa ...@@ -193,13 +193,12 @@ TString QualifiedStructNameString(const TStructure &structure, bool useHLSLRowMa
if (useStd140Packing) if (useStd140Packing)
{ {
prefix += "std"; prefix += "std_";
} }
if (useHLSLRowMajorPacking) if (useHLSLRowMajorPacking)
{ {
if (prefix != "") prefix += "_"; prefix += "rm_";
prefix += "rm";
} }
return prefix + StructNameString(structure); return prefix + StructNameString(structure);
......
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