//
#include "compiler/translator/BuiltInFunctionEmulator.h"
+#include "compiler/translator/Compiler.h"
#include "compiler/translator/DetectCallDepth.h"
#include "compiler/translator/ForLoopUnroll.h"
#include "compiler/translator/Initialize.h"
#include "compiler/translator/InitializeParseContext.h"
#include "compiler/translator/InitializeVariables.h"
#include "compiler/translator/ParseContext.h"
+#include "compiler/translator/RegenerateStructNames.h"
#include "compiler/translator/RenameFunction.h"
-#include "compiler/translator/ShHandle.h"
+#include "compiler/translator/ScalarizeVecAndMatConstructorArgs.h"
#include "compiler/translator/UnfoldShortCircuitAST.h"
#include "compiler/translator/ValidateLimitations.h"
#include "compiler/translator/ValidateOutputs.h"
#include "compiler/translator/timing/RestrictFragmentShaderTiming.h"
#include "compiler/translator/timing/RestrictVertexShaderTiming.h"
#include "third_party/compiler/ArrayBoundsClamper.h"
+#include "angle_gl.h"
+#include "common/utilities.h"
bool IsWebGLBasedSpec(ShShaderSpec spec)
{
allocator.popAll();
}
-TCompiler::TCompiler(ShShaderType type, ShShaderSpec spec, ShShaderOutput output)
+TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output)
: shaderType(type),
shaderSpec(spec),
outputType(output),
bool TCompiler::Init(const ShBuiltInResources& resources)
{
shaderVersion = 100;
- maxUniformVectors = (shaderType == SH_VERTEX_SHADER) ?
+ maxUniformVectors = (shaderType == GL_VERTEX_SHADER) ?
resources.MaxVertexUniformVectors :
resources.MaxFragmentUniformVectors;
maxExpressionComplexity = resources.MaxExpressionComplexity;
if (success)
success = detectCallDepth(root, infoSink, (compileOptions & SH_LIMIT_CALL_STACK_DEPTH) != 0);
- if (success && shaderVersion == 300 && shaderType == SH_FRAGMENT_SHADER)
+ if (success && shaderVersion == 300 && shaderType == GL_FRAGMENT_SHADER)
success = validateOutputs(root);
if (success && (compileOptions & SH_VALIDATE_LOOP_INDEXING))
if (success && (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS))
arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root);
- if (success && shaderType == SH_VERTEX_SHADER && (compileOptions & SH_INIT_GL_POSITION))
+ if (success && shaderType == GL_VERTEX_SHADER && (compileOptions & SH_INIT_GL_POSITION))
initializeGLPosition(root);
if (success && (compileOptions & SH_UNFOLD_SHORT_CIRCUIT))
infoSink.info << "too many uniforms";
}
}
- if (success && shaderType == SH_VERTEX_SHADER &&
+ if (success && shaderType == GL_VERTEX_SHADER &&
(compileOptions & SH_INIT_VARYINGS_WITHOUT_STATIC_USE))
initializeVaryingsWithoutStaticUse(root);
}
+ if (success && (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS))
+ {
+ ScalarizeVecAndMatConstructorArgs scalarizer(
+ shaderType, fragmentPrecisionHigh);
+ root->traverse(&scalarizer);
+ }
+
+ if (success && (compileOptions & SH_REGENERATE_STRUCT_NAMES))
+ {
+ RegenerateStructNames gen(symbolTable, shaderVersion);
+ root->traverse(&gen);
+ }
+
if (success && (compileOptions & SH_INTERMEDIATE_TREE))
intermediate.outputTree(root);
switch(shaderType)
{
- case SH_FRAGMENT_SHADER:
+ case GL_FRAGMENT_SHADER:
symbolTable.setDefaultPrecision(integer, EbpMedium);
break;
- case SH_VERTEX_SHADER:
+ case GL_VERTEX_SHADER:
symbolTable.setDefaultPrecision(integer, EbpHigh);
symbolTable.setDefaultPrecision(floatingPoint, EbpHigh);
break;
infoSink.obj.erase();
infoSink.debug.erase();
- attribs.clear();
+ attributes.clear();
+ outputVariables.clear();
uniforms.clear();
+ expandedUniforms.clear();
varyings.clear();
+ expandedVaryings.clear();
+ interfaceBlocks.clear();
builtInFunctionEmulator.Cleanup();
return false;
}
- if (shaderType == SH_FRAGMENT_SHADER)
+ if (shaderType == GL_FRAGMENT_SHADER)
{
TDependencyGraph graph(root);
void TCompiler::collectVariables(TIntermNode* root)
{
- CollectVariables collect(attribs, uniforms, varyings, hashFunction);
+ CollectVariables collect(&attributes,
+ &outputVariables,
+ &uniforms,
+ &varyings,
+ &interfaceBlocks,
+ hashFunction);
root->traverse(&collect);
+
+ // For backwards compatiblity with ShGetVariableInfo, expand struct
+ // uniforms and varyings into separate variables for each field.
+ ExpandVariables(uniforms, &expandedUniforms);
+ ExpandVariables(varyings, &expandedVaryings);
}
bool TCompiler::enforcePackingRestrictions()
{
VariablePacker packer;
- return packer.CheckVariablesWithinPackingLimits(maxUniformVectors, uniforms);
+ return packer.CheckVariablesWithinPackingLimits(maxUniformVectors, expandedUniforms);
}
void TCompiler::initializeGLPosition(TIntermNode* root)
InitializeVariables::InitVariableInfoList variables;
for (size_t ii = 0; ii < varyings.size(); ++ii)
{
- const TVariableInfo& varying = varyings[ii];
+ const sh::Varying& varying = varyings[ii];
if (varying.staticUse)
continue;
- unsigned char primarySize = 1, secondarySize = 1;
- switch (varying.type)
- {
- case SH_FLOAT:
- break;
- case SH_FLOAT_VEC2:
- primarySize = 2;
- break;
- case SH_FLOAT_VEC3:
- primarySize = 3;
- break;
- case SH_FLOAT_VEC4:
- primarySize = 4;
- break;
- case SH_FLOAT_MAT2:
- primarySize = 2;
- secondarySize = 2;
- break;
- case SH_FLOAT_MAT3:
- primarySize = 3;
- secondarySize = 3;
- break;
- case SH_FLOAT_MAT4:
- primarySize = 4;
- secondarySize = 4;
- break;
- default:
- ASSERT(false);
- }
- TType type(EbtFloat, EbpUndefined, EvqVaryingOut, primarySize, secondarySize, varying.isArray);
+ unsigned char primarySize = static_cast<unsigned char>(gl::VariableColumnCount(varying.type));
+ unsigned char secondarySize = static_cast<unsigned char>(gl::VariableRowCount(varying.type));
+ TType type(EbtFloat, EbpUndefined, EvqVaryingOut, primarySize, secondarySize, varying.isArray());
TString name = varying.name.c_str();
- if (varying.isArray)
+ if (varying.isArray())
{
- type.setArraySize(varying.size);
+ type.setArraySize(varying.arraySize);
name = name.substr(0, name.find_first_of('['));
}