Permalink
Browse files

hand-merge from https://github.com/jims/hlsl2glslfork

Not everything was taken as-is; and right now does not fully work!
  • Loading branch information...
2 parents ed1548d + bc3eecb commit 40e2c4a255e37a503857ee4b9387cbd64f6d9fe1 @aras-p committed Sep 26, 2012
Showing with 3,047 additions and 3,965 deletions.
  1. +10 −2 README.md
  2. +0 −4 hlslang.vcproj
  3. +0 −6 hlslang.xcodeproj/project.pbxproj
  4. +12 −4 hlslang/GLSLCodeGen/glslCommon.cpp
  5. +3 −1 hlslang/GLSLCodeGen/glslCommon.h
  6. +10 −138 hlslang/GLSLCodeGen/glslFunction.cpp
  7. +15 −18 hlslang/GLSLCodeGen/glslFunction.h
  8. +395 −253 hlslang/GLSLCodeGen/glslOutput.cpp
  9. +6 −3 hlslang/GLSLCodeGen/glslOutput.h
  10. +36 −210 hlslang/GLSLCodeGen/glslSymbol.cpp
  11. +51 −56 hlslang/GLSLCodeGen/glslSymbol.h
  12. +2 −2 hlslang/GLSLCodeGen/hlslCrossCompiler.cpp
  13. +1 −1 hlslang/GLSLCodeGen/hlslCrossCompiler.h
  14. +418 −430 hlslang/GLSLCodeGen/hlslLinker.cpp
  15. +6 −0 hlslang/GLSLCodeGen/hlslLinker.h
  16. +1 −1 hlslang/GLSLCodeGen/hlslSupportLib.cpp
  17. +0 −265 hlslang/Include/ConstantUnion.h
  18. +6 −0 hlslang/Include/PoolAlloc.h
  19. +36 −36 hlslang/Include/Types.h
  20. +393 −323 hlslang/Include/intermediate.h
  21. +8 −3 hlslang/MachineIndependent/HLSL2GLSL.cpp
  22. +9 −3 hlslang/MachineIndependent/Initialize.cpp
  23. +12 −1 hlslang/MachineIndependent/IntermTraverse.cpp
  24. +163 −594 hlslang/MachineIndependent/Intermediate.cpp
  25. +284 −613 hlslang/MachineIndependent/ParseHelper.cpp
  26. +2 −8 hlslang/MachineIndependent/ParseHelper.h
  27. +36 −11 hlslang/MachineIndependent/PoolAlloc.cpp
  28. +1 −1 hlslang/MachineIndependent/RemoveTree.cpp
  29. +10 −10 hlslang/MachineIndependent/SymbolTable.cpp
  30. +144 −156 hlslang/MachineIndependent/SymbolTable.h
  31. +3 −1 hlslang/MachineIndependent/hlslang.l
  32. +364 −405 hlslang/MachineIndependent/hlslang.y
  33. +7 −8 hlslang/MachineIndependent/intermOut.cpp
  34. +33 −29 hlslang/MachineIndependent/localintermediate.h
  35. +0 −251 hlslang/MachineIndependent/parseConst.cpp
  36. +99 −66 include/hlsl2glsl.h
  37. +46 −0 tests/combined/index-matrix-assignment-fragment-out.txt
  38. +46 −0 tests/combined/index-matrix-assignment-fragment-outES.txt
  39. +48 −0 tests/combined/index-matrix-assignment-in.txt
  40. +96 −0 tests/combined/index-matrix-assignment-vertex-out.txt
  41. +96 −0 tests/combined/index-matrix-assignment-vertex-outES.txt
  42. +86 −52 tests/hlsl2glsltest/hlsl2glsltest.cpp
  43. +53 −0 tests/minimal/combined/simple-in.txt
View
@@ -22,6 +22,12 @@ Changes from original HLSL2GLSL 0.9
* Cleaner and more deterministic generated GLSL output
* Unit testing suite
* Simplified interface, code cleanup, unused code removal, merge copy-n-pasted code, simplify implementation etc.
+* Added support for emission of const initializers (including struct and array initializers using GLSL 1.20 array syntax).
+* Removed all constant folding functionality as it was completely broken.
+* A myriad of smaller bug fixes.
+* Support DX10 SV_VertexID, SV_PrimitiveID and SV_InstanceID semantics.
+* Support for shadow sampler types (samplerRECTShadow/sampler2DShadow etc.) which generate appropriate shadow2DRect/shadow2D etc. calls.
+* Fixed unaligned swizzled matrix access & assignments (view._m01_m02_m33 = value)
Notes
@@ -36,6 +42,8 @@ Notes
Status
--------
-Seems to work quite well for Unity's shaders. When/if we bump into any issues; we'll just fix them.
+Used in Unity and bitsquid engine, and seems to work quite ok.
-No optimizations are performed on the generated GLSL, so it is expected that your platform will have a decent GLSL compiler. Or, use [GLSL Optimizer](http://github.com/aras-p/glsl-optimizer), we use it to optimize shaders produced by HLSL2GLSL; gives a substantial performance boost on mobile platforms.
+Support for DX11 features will probably not be added due to the bad condition the original code is in (very obscure and inefficient), instead maybe a new cross-compiler will be made.
+
+No optimizations are performed on the generated GLSL, so it is expected that your platform will have a decent GLSL compiler. Or, use [GLSL Optimizer](http://github.com/aras-p/glsl-optimizer), at Unity we use it to optimize shaders produced by HLSL2GLSL; gives a substantial performance boost on mobile platforms.
View
@@ -460,10 +460,6 @@
RelativePath="hlslang\MachineIndependent\localintermediate.h"
>
</File>
- <File
- RelativePath="hlslang\MachineIndependent\parseConst.cpp"
- >
- </File>
<File
RelativePath="hlslang\MachineIndependent\ParseHelper.cpp"
>
@@ -29,7 +29,6 @@
2B951CB11135197300DBAF46 /* IntermTraverse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3AC10E2B0AF106F40045E29C /* IntermTraverse.cpp */; };
2B951CB31135197300DBAF46 /* memory.c in Sources */ = {isa = PBXBuildFile; fileRef = 3AC10EAA0AF109530045E29C /* memory.c */; };
2B951CB41135197300DBAF46 /* ossource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3AC10E480AF107290045E29C /* ossource.cpp */; };
- 2B951CB51135197300DBAF46 /* parseConst.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3AC10E2C0AF106F40045E29C /* parseConst.cpp */; };
2B951CB61135197300DBAF46 /* ParseHelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3AC10E2D0AF106F40045E29C /* ParseHelper.cpp */; };
2B951CB71135197300DBAF46 /* PoolAlloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3AC10E2E0AF106F40045E29C /* PoolAlloc.cpp */; };
2B951CB81135197300DBAF46 /* propagateMutable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3AC10E060AF103660045E29C /* propagateMutable.cpp */; };
@@ -52,7 +51,6 @@
3A9176410A643D5A00E8641B /* InitializeDll.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = InitializeDll.h; sourceTree = "<group>"; };
3AC10DD20AF103020045E29C /* BaseTypes.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = BaseTypes.h; path = hlslang/Include/BaseTypes.h; sourceTree = "<group>"; };
3AC10DD30AF103020045E29C /* Common.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Common.h; path = hlslang/Include/Common.h; sourceTree = "<group>"; };
- 3AC10DD40AF103020045E29C /* ConstantUnion.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ConstantUnion.h; path = hlslang/Include/ConstantUnion.h; sourceTree = "<group>"; };
3AC10DD50AF103020045E29C /* InfoSink.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = InfoSink.h; path = hlslang/Include/InfoSink.h; sourceTree = "<group>"; };
3AC10DD60AF103020045E29C /* InitializeGlobals.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = InitializeGlobals.h; path = hlslang/Include/InitializeGlobals.h; sourceTree = "<group>"; };
3AC10DD70AF103020045E29C /* InitializeParseContext.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = InitializeParseContext.h; path = hlslang/Include/InitializeParseContext.h; sourceTree = "<group>"; };
@@ -91,7 +89,6 @@
3AC10E290AF106F40045E29C /* Intermediate.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Intermediate.cpp; path = hlslang/MachineIndependent/Intermediate.cpp; sourceTree = "<group>"; };
3AC10E2A0AF106F40045E29C /* intermOut.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = intermOut.cpp; path = hlslang/MachineIndependent/intermOut.cpp; sourceTree = "<group>"; };
3AC10E2B0AF106F40045E29C /* IntermTraverse.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = IntermTraverse.cpp; path = hlslang/MachineIndependent/IntermTraverse.cpp; sourceTree = "<group>"; };
- 3AC10E2C0AF106F40045E29C /* parseConst.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = parseConst.cpp; path = hlslang/MachineIndependent/parseConst.cpp; sourceTree = "<group>"; };
3AC10E2D0AF106F40045E29C /* ParseHelper.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseHelper.cpp; path = hlslang/MachineIndependent/ParseHelper.cpp; sourceTree = "<group>"; };
3AC10E2E0AF106F40045E29C /* PoolAlloc.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = PoolAlloc.cpp; path = hlslang/MachineIndependent/PoolAlloc.cpp; sourceTree = "<group>"; };
3AC10E300AF106F40045E29C /* RemoveTree.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = RemoveTree.cpp; path = hlslang/MachineIndependent/RemoveTree.cpp; sourceTree = "<group>"; };
@@ -209,7 +206,6 @@
children = (
3AC10DD20AF103020045E29C /* BaseTypes.h */,
3AC10DD30AF103020045E29C /* Common.h */,
- 3AC10DD40AF103020045E29C /* ConstantUnion.h */,
3AC10DD50AF103020045E29C /* InfoSink.h */,
3AC10DD60AF103020045E29C /* InitializeGlobals.h */,
3AC10DD70AF103020045E29C /* InitializeParseContext.h */,
@@ -234,7 +230,6 @@
3AC10E290AF106F40045E29C /* Intermediate.cpp */,
3AC10E2A0AF106F40045E29C /* intermOut.cpp */,
3AC10E2B0AF106F40045E29C /* IntermTraverse.cpp */,
- 3AC10E2C0AF106F40045E29C /* parseConst.cpp */,
3AC10E2D0AF106F40045E29C /* ParseHelper.cpp */,
3AC10E2E0AF106F40045E29C /* PoolAlloc.cpp */,
3AC10E300AF106F40045E29C /* RemoveTree.cpp */,
@@ -417,7 +412,6 @@
2B951CB11135197300DBAF46 /* IntermTraverse.cpp in Sources */,
2B951CB31135197300DBAF46 /* memory.c in Sources */,
2B951CB41135197300DBAF46 /* ossource.cpp in Sources */,
- 2B951CB51135197300DBAF46 /* parseConst.cpp in Sources */,
2B951CB61135197300DBAF46 /* ParseHelper.cpp in Sources */,
2B951CB71135197300DBAF46 /* PoolAlloc.cpp in Sources */,
2B951CB81135197300DBAF46 /* propagateMutable.cpp in Sources */,
@@ -26,11 +26,13 @@ const char typeString[EgstTypeCount][32] =
"mat4",
"sampler",
"sampler1D",
+ "sampler1DShadow",
"sampler2D",
+ "sampler2DShadow",
"sampler3D",
"samplerCube",
"sampler2DRect",
- "sampler2DShadow",
+ "sampler2DRectShadow",
"struct"
};
@@ -77,11 +79,13 @@ void writeType (std::stringstream &out, EGlslSymbolType type, GlslStruct *s, TPr
case EgstFloat4x4:
case EgstSamplerGeneric:
case EgstSampler1D:
+ case EgstSampler1DShadow:
case EgstSampler2D:
+ case EgstSampler2DShadow:
case EgstSampler3D:
case EgstSamplerCube:
case EgstSamplerRect:
- case EgstSampler2DShadow:
+ case EgstSamplerRectShadow:
out << typeString[type];
break;
case EgstStruct:
@@ -128,16 +132,20 @@ EGlslSymbolType translateType( const TType *type )
return EgstSamplerGeneric;
case EbtSampler1D:
return EgstSampler1D;
+ case EbtSampler1DShadow:
+ return EgstSampler1DShadow;
case EbtSampler2D:
return EgstSampler2D;
+ case EbtSampler2DShadow:
+ return EgstSampler2DShadow;
case EbtSampler3D:
return EgstSampler3D;
case EbtSamplerCube:
return EgstSamplerCube;
case EbtSamplerRect:
return EgstSamplerRect;
- case EbtSampler2DShadow:
- return EgstSampler2DShadow;
+ case EbtSamplerRectShadow:
+ return EgstSamplerRectShadow;
case EbtStruct:
return EgstStruct;
}
@@ -31,11 +31,13 @@ enum EGlslSymbolType
EgstFloat4x4,
EgstSamplerGeneric,
EgstSampler1D,
+ EgstSampler1DShadow,
EgstSampler2D,
+ EgstSampler2DShadow,
EgstSampler3D,
EgstSamplerCube,
EgstSamplerRect,
- EgstSampler2DShadow,
+ EgstSamplerRectShadow,
EgstStruct,
EgstTypeCount
};
@@ -17,15 +17,19 @@ GlslFunction::GlslFunction( const std::string &n, const std::string &m, EGlslSym
depth(0),
inStatement(false)
{
- active.setf ( std::stringstream::showpoint );
- active.unsetf(std::ios::fixed);
- active.unsetf(std::ios::scientific);
- active.precision (6);
+ active = new std::stringstream();
+ active->setf ( std::stringstream::showpoint );
+ active->unsetf(std::ios::fixed);
+ active->unsetf(std::ios::scientific);
+ active->precision (6);
+ pushDepth(0);
}
GlslFunction::~GlslFunction()
{
+ popDepth();
+ delete active;
for (std::vector<GlslSymbol*>::iterator it = symbols.begin(); it < symbols.end(); it++)
{
(*it)->releaseRef ();
@@ -36,6 +40,8 @@ GlslFunction::~GlslFunction()
}
}
+void GlslFunction::pushDepth(int depth) { this->depth.push_back(depth); }
+void GlslFunction::popDepth() { depth.pop_back(); }
bool GlslFunction::hasSymbol( int id )
{
@@ -118,137 +124,3 @@ std::string GlslFunction::getPrototype()
return out.str();
}
-
-std::string GlslFunction::getLocalDecls( int indentLevel )
-{
- std::stringstream out;
- int oldDepth;
-
- // Make sure that decimal points are printed to the output string. Otherwise, the following:
- // float fTemp = 1.0;
- // will come out:
- // float fTemp = 1;
- // causing a GLSL parse error
- out.setf ( std::stringstream::showpoint );
- out.unsetf(std::ios::fixed);
- out.unsetf(std::ios::scientific);
- out.precision (6);
-
- //save off the old depth, to restore later, this is probably unnecessary
- oldDepth = depth;
- depth = indentLevel;
-
- for (std::vector<GlslSymbol*>::iterator it = symbols.begin(); it < symbols.end(); it++)
- {
- if ( (!(*it)->getIsParameter() && !(*it)->getIsGlobal() && !(*it)->getIsMutable()) )
- {
- indent(out);
- if ((*it)->hasInitializer())
- {
- (*it)->writeDecl(out, true, false);
- if ((*it)->isArray())
- {
- out <<";\n";
- for (int ii = 0; ii < (*it)->getArraySize(); ii++)
- {
- indent(out);
- out << (*it)->getName() << "[" << ii << "] = ";
- (*it)->writeInitializer(out,ii);
- if ( (ii+1) != (*it)->getArraySize())
- out << ";\n";
- }
- }
- else
- {
- out << " = ";
- (*it)->writeInitializer(out);
- }
- }
- else
- {
- (*it)->writeDecl(out, true, false);
- }
- out << ";\n";
- }
- }
-
- depth = oldDepth;
-
- return out.str();
-}
-
-
-std::string GlslFunction::getMutableDecls( int indentLevel, std::vector<GlslFunction*>::iterator funcBegin,
- std::vector<GlslFunction*>::iterator funcEnd )
-{
- std::stringstream out;
- int oldDepth;
-
- // Make sure that decimal points are printed to the output string. Otherwise, the following:
- // float fTemp = 1.0;
- // will come out:
- // float fTemp = 1;
- // causing a GLSL parse error
- out.setf ( std::stringstream::showpoint );
- out.precision (6);
-
- //save off the old depth, to restore later, this is probably unnecessary
- oldDepth = depth;
- depth = indentLevel;
-
- for (std::vector<GlslSymbol*>::iterator it = symbols.begin(); it < symbols.end(); it++)
- {
- if ( (*it)->getIsMutable() )
- {
- bool bMutableAlreadyProcessed = false;
-
- // Check the set of already processed functions to see if the mutable was already
- // written out
- std::vector<GlslFunction*>::iterator fit = funcBegin;
- while ( fit != funcEnd && bMutableAlreadyProcessed == false)
- {
- std::vector<GlslSymbol*> funcSymbols = (*fit)->getSymbols();
-
- for (size_t i = 0; i < funcSymbols.size(); i++ )
- {
- if ( (*it)->getName() == funcSymbols[i]->getName() )
- {
- // Symbol found, this mutable has already been processed. Don't do it again.
- bMutableAlreadyProcessed = true;
- break;
- }
- }
- fit++;
- }
-
- if ( bMutableAlreadyProcessed == false )
- {
- indent(out);
- if ((*it)->isArray())
- {
- for (int ii = 0; ii < (*it)->getArraySize(); ii++)
- {
- out << (*it)->getName() << "[" << ii << "] = ";
- out << (*it)->getName(false) << "[" << ii << "]";
- if ( (ii+1) != (*it)->getArraySize())
- {
- out << ";\n";
- indent(out);
- }
- }
- }
- else
- {
- out << (*it)->getName() << " = " << (*it)->getName(false);
- }
-
- out << ";\n";
- }
- }
- }
-
- depth = oldDepth;
-
- return out.str();
-}
-
@@ -27,15 +27,9 @@ class GlslFunction
GlslSymbol& getSymbol( int id );
std::string getPrototype();
- std::string getLocalDecls( int indentLevel );
-
- /// Returns, as a string, the mutable declarations in the function. Takes a set of other functions to
- /// check whether the mutable has already been declared.
- std::string getMutableDecls( int indentLevel, std::vector<GlslFunction*>::iterator funcBegin,
- std::vector<GlslFunction*>::iterator funcEnd );
/// Returns the active scope
- std::string getCode() { return active.str(); }
+ std::string getCode() { return active->str(); }
int getParameterCount() { return (int)parameters.size();}
GlslSymbol* getParameter( int i ) { return parameters[i];}
@@ -48,17 +42,20 @@ class GlslFunction
const std::vector<GlslSymbol*>& getSymbols() { return symbols; }
- void increaseDepth() { depth++; }
- void decreaseDepth() { depth = depth ? depth-1 : depth; }
+ void increaseDepth() { depth.back()++; }
+ void decreaseDepth() { depth.back() = depth.back() ? depth.back()-1 : depth.back(); }
+
+ void pushDepth(int depth);
+ void popDepth();
- void indent( std::stringstream &s ) { for (int ii = 0; ii < depth; ii++) s << " "; }
- void indent() { indent(active); }
+ void indent( std::stringstream &s ) { for (int ii = 0; ii < depth.back(); ii++) s << " "; }
+ void indent() { indent(*active); }
- void beginBlock( bool brace = true) { if (brace) active << "{\n"; increaseDepth(); inStatement = false; }
- void endBlock() { endStatement(); decreaseDepth(); indent(); active << "}\n"; }
+ void beginBlock( bool brace = true) { if (brace) *active << "{\n"; increaseDepth(); inStatement = false; }
+ void endBlock() { endStatement(); decreaseDepth(); indent(); *active << "}\n"; }
void beginStatement() { if (!inStatement) { indent(); inStatement = true;}}
- void endStatement() { if (inStatement) { active << ";\n"; inStatement = false;}}
+ void endStatement() { if (inStatement) { *active << ";\n"; inStatement = false;}}
const std::string &getName() { return name; }
const std::string &getMangledName() { return mangledName; }
@@ -68,8 +65,8 @@ class GlslFunction
const std::string& getSemantic() const { return semantic; }
GlslStruct* getStruct() { return structPtr; }
void setStruct( GlslStruct *s ) { structPtr = s;}
-
- std::stringstream& getActiveOutput () { return active; }
+ void setActiveOutput(std::stringstream* output) { active = output; }
+ std::stringstream& getActiveOutput () { return *active; }
const TSourceLoc& getLine() const { return line; }
protected:
@@ -86,7 +83,7 @@ class GlslFunction
GlslStruct *structPtr;
// Present indent depth
- int depth;
+ std::vector<int> depth;
// These are the symbols referenced
std::vector<GlslSymbol*> symbols;
@@ -101,7 +98,7 @@ class GlslFunction
std::set<TOperator> libFunctions;
// Stores the active output of the function
- std::stringstream active;
+ std::stringstream* active;
bool inStatement;
Oops, something went wrong.

0 comments on commit 40e2c4a

Please sign in to comment.