Commit 033dae67 by Jamie Madill

Move OutputHLSL utility methods to other files.

OutputHLSL was become a large, unweildy file. Some were also useful to other classes, even on the GL back-end, but were inacessible. Refactoring patch only. BUG=angle:466 Change-Id: Id216147122ca105c6ccdf0ba0c5f6c5038726965 Reviewed-on: https://chromium-review.googlesource.com/203459Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarNicolas Capens <nicolascapens@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 05b05028
...@@ -137,6 +137,7 @@ ...@@ -137,6 +137,7 @@
<ClInclude Include="..\..\src\compiler\translator\FlagStd140Structs.h"/> <ClInclude Include="..\..\src\compiler\translator\FlagStd140Structs.h"/>
<ClInclude Include="..\..\src\compiler\translator\length_limits.h"/> <ClInclude Include="..\..\src\compiler\translator\length_limits.h"/>
<ClInclude Include="..\..\src\compiler\translator\PoolAlloc.h"/> <ClInclude Include="..\..\src\compiler\translator\PoolAlloc.h"/>
<ClInclude Include="..\..\src\compiler\translator\OutputHLSL.h"/>
<ClInclude Include="..\..\src\compiler\translator\BuiltInFunctionEmulator.h"/> <ClInclude Include="..\..\src\compiler\translator\BuiltInFunctionEmulator.h"/>
<ClInclude Include="..\..\src\compiler\translator\DetectDiscontinuity.h"/> <ClInclude Include="..\..\src\compiler\translator\DetectDiscontinuity.h"/>
<ClInclude Include="..\..\src\compiler\translator\UnfoldShortCircuit.h"/> <ClInclude Include="..\..\src\compiler\translator\UnfoldShortCircuit.h"/>
...@@ -174,7 +175,7 @@ ...@@ -174,7 +175,7 @@
<ClInclude Include="..\..\src\compiler\translator\VariablePacker.h"/> <ClInclude Include="..\..\src\compiler\translator\VariablePacker.h"/>
<ClInclude Include="..\..\src\compiler\translator\glslang.h"/> <ClInclude Include="..\..\src\compiler\translator\glslang.h"/>
<ClInclude Include="..\..\src\compiler\translator\SearchSymbol.h"/> <ClInclude Include="..\..\src\compiler\translator\SearchSymbol.h"/>
<ClInclude Include="..\..\src\compiler\translator\OutputHLSL.h"/> <ClInclude Include="..\..\src\compiler\translator\UtilsHLSL.h"/>
<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"/>
...@@ -241,6 +242,7 @@ ...@@ -241,6 +242,7 @@
<ClCompile Include="..\..\src\compiler\translator\ForLoopUnroll.cpp"/> <ClCompile Include="..\..\src\compiler\translator\ForLoopUnroll.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\SearchSymbol.cpp"/> <ClCompile Include="..\..\src\compiler\translator\SearchSymbol.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\UnfoldShortCircuitAST.cpp"/> <ClCompile Include="..\..\src\compiler\translator\UnfoldShortCircuitAST.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\UtilsHLSL.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\TranslatorGLSL.cpp"/> <ClCompile Include="..\..\src\compiler\translator\TranslatorGLSL.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\SymbolTable.cpp"/> <ClCompile Include="..\..\src\compiler\translator\SymbolTable.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\FlagStd140Structs.cpp"/> <ClCompile Include="..\..\src\compiler\translator\FlagStd140Structs.cpp"/>
......
...@@ -159,6 +159,9 @@ ...@@ -159,6 +159,9 @@
<ClInclude Include="..\..\src\compiler\translator\PoolAlloc.h"> <ClInclude Include="..\..\src\compiler\translator\PoolAlloc.h">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\compiler\translator\OutputHLSL.h">
<Filter>src\compiler\translator</Filter>
</ClInclude>
<ClInclude Include="..\..\src\compiler\translator\BuiltInFunctionEmulator.h"> <ClInclude Include="..\..\src\compiler\translator\BuiltInFunctionEmulator.h">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</ClInclude> </ClInclude>
...@@ -339,6 +342,9 @@ ...@@ -339,6 +342,9 @@
<None Include="..\..\src\compiler\translator\glslang.l"> <None Include="..\..\src\compiler\translator\glslang.l">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</None> </None>
<ClInclude Include="..\..\src\compiler\translator\UtilsHLSL.h">
<Filter>src\compiler\translator</Filter>
</ClInclude>
<ClCompile Include="..\..\src\compiler\translator\intermOut.cpp"> <ClCompile Include="..\..\src\compiler\translator\intermOut.cpp">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</ClCompile> </ClCompile>
...@@ -354,9 +360,9 @@ ...@@ -354,9 +360,9 @@
<ClCompile Include="..\..\src\compiler\translator\UnfoldShortCircuitAST.cpp"> <ClCompile Include="..\..\src\compiler\translator\UnfoldShortCircuitAST.cpp">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</ClCompile> </ClCompile>
<ClInclude Include="..\..\src\compiler\translator\OutputHLSL.h"> <ClCompile Include="..\..\src\compiler\translator\UtilsHLSL.cpp">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</ClInclude> </ClCompile>
<ClCompile Include="..\..\src\compiler\translator\TranslatorGLSL.cpp"> <ClCompile Include="..\..\src\compiler\translator\TranslatorGLSL.cpp">
<Filter>src\compiler\translator</Filter> <Filter>src\compiler\translator</Filter>
</ClCompile> </ClCompile>
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
namespace sh namespace sh
{ {
class UnfoldShortCircuit; class UnfoldShortCircuit;
class Std140PaddingHelper;
class OutputHLSL : public TIntermTraverser class OutputHLSL : public TIntermTraverser
{ {
...@@ -37,18 +38,9 @@ class OutputHLSL : public TIntermTraverser ...@@ -37,18 +38,9 @@ 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;
TString typeString(const TType &type); static TString defineNamelessStruct(const TStructure &structure);
TString textureString(const TType &type); TString defineQualifiedStruct(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing);
TString samplerString(const TType &type);
TString interpolationString(TQualifier qualifier);
TString structureString(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing);
static TString structureTypeName(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing);
static TString qualifierString(TQualifier qualifier);
static TString arrayString(const TType &type);
static TString initializer(const TType &type); static TString initializer(const TType &type);
static TString decorate(const TString &string); // Prepends an underscore to avoid naming clashes
static TString decorateUniform(const TString &string, const TType &type);
static TString decorateField(const TString &string, const TStructure &structure);
protected: protected:
void header(); void header();
...@@ -76,8 +68,6 @@ class OutputHLSL : public TIntermTraverser ...@@ -76,8 +68,6 @@ class OutputHLSL : public TIntermTraverser
void storeStd140ElementIndex(const TStructure &structure, bool useHLSLRowMajorPacking); 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);
static TString structNameString(const TStructure &structure);
TParseContext &mContext; TParseContext &mContext;
const ShShaderOutput mOutputType; const ShShaderOutput mOutputType;
UnfoldShortCircuit *mUnfoldShortCircuit; UnfoldShortCircuit *mUnfoldShortCircuit;
...@@ -187,7 +177,6 @@ class OutputHLSL : public TIntermTraverser ...@@ -187,7 +177,6 @@ class OutputHLSL : public TIntermTraverser
int declareUniformAndAssignRegister(const TType &type, const TString &name); int declareUniformAndAssignRegister(const TType &type, const TString &name);
TString interfaceBlockFieldString(const TInterfaceBlock &interfaceBlock, const TField &field); TString interfaceBlockFieldString(const TInterfaceBlock &interfaceBlock, const TField &field);
TString decoratePrivate(const TString &privateText);
TString interfaceBlockStructNameString(const TInterfaceBlock &interfaceBlockType); TString interfaceBlockStructNameString(const TInterfaceBlock &interfaceBlockType);
TString interfaceBlockInstanceString(const TInterfaceBlock& interfaceBlock, unsigned int arrayIndex); TString interfaceBlockInstanceString(const TInterfaceBlock& interfaceBlock, unsigned int arrayIndex);
TString interfaceBlockFieldTypeString(const TField &field, TLayoutBlockStorage blockStorage); TString interfaceBlockFieldTypeString(const TField &field, TLayoutBlockStorage blockStorage);
...@@ -195,14 +184,8 @@ class OutputHLSL : public TIntermTraverser ...@@ -195,14 +184,8 @@ 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,
class Std140PaddingHelper; bool useStd140Packing, Std140PaddingHelper *padHelper);
static GLenum glVariableType(const TType &type);
static GLenum glVariablePrecision(const TType &type);
static bool isVaryingIn(TQualifier qualifier);
static bool isVaryingOut(TQualifier qualifier);
static bool isVarying(TQualifier qualifier);
std::vector<gl::Uniform> mActiveUniforms; std::vector<gl::Uniform> mActiveUniforms;
std::vector<gl::InterfaceBlock> mActiveInterfaceBlocks; std::vector<gl::InterfaceBlock> mActiveInterfaceBlocks;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "compiler/translator/InfoSink.h" #include "compiler/translator/InfoSink.h"
#include "compiler/translator/OutputHLSL.h" #include "compiler/translator/OutputHLSL.h"
#include "compiler/translator/UtilsHLSL.h"
namespace sh namespace sh
{ {
...@@ -117,7 +118,7 @@ bool UnfoldShortCircuit::visitSelection(Visit visit, TIntermSelection *node) ...@@ -117,7 +118,7 @@ bool UnfoldShortCircuit::visitSelection(Visit visit, TIntermSelection *node)
{ {
int i = mTemporaryIndex; int i = mTemporaryIndex;
out << mOutputHLSL->typeString(node->getType()) << " s" << i << ";\n"; out << TypeString(node->getType()) << " s" << i << ";\n";
out << "{\n"; out << "{\n";
......
//
// 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.
//
// UtilsHLSL.cpp:
// Utility methods for GLSL to HLSL translation.
//
#include "compiler/translator/UtilsHLSL.h"
#include "compiler/translator/OutputHLSL.h"
#include "compiler/translator/SymbolTable.h"
namespace sh
{
TString SamplerString(const TType &type)
{
if (IsShadowSampler(type.getBasicType()))
{
return "SamplerComparisonState";
}
else
{
return "SamplerState";
}
}
TString TextureString(const TType &type)
{
switch (type.getBasicType())
{
case EbtSampler2D: return "Texture2D";
case EbtSamplerCube: return "TextureCube";
case EbtSamplerExternalOES: return "Texture2D";
case EbtSampler2DArray: return "Texture2DArray";
case EbtSampler3D: return "Texture3D";
case EbtISampler2D: return "Texture2D<int4>";
case EbtISampler3D: return "Texture3D<int4>";
case EbtISamplerCube: return "Texture2DArray<int4>";
case EbtISampler2DArray: return "Texture2DArray<int4>";
case EbtUSampler2D: return "Texture2D<uint4>";
case EbtUSampler3D: return "Texture3D<uint4>";
case EbtUSamplerCube: return "Texture2DArray<uint4>";
case EbtUSampler2DArray: return "Texture2DArray<uint4>";
case EbtSampler2DShadow: return "Texture2D";
case EbtSamplerCubeShadow: return "TextureCube";
case EbtSampler2DArrayShadow: return "Texture2DArray";
default: UNREACHABLE();
}
return "<unknown texture type>";
}
TString DecorateUniform(const TString &string, const TType &type)
{
if (type.getBasicType() == EbtSamplerExternalOES)
{
return "ex_" + string;
}
return Decorate(string);
}
TString DecorateField(const TString &string, const TStructure &structure)
{
if (structure.name().compare(0, 3, "gl_") != 0)
{
return Decorate(string);
}
return string;
}
TString DecoratePrivate(const TString &privateText)
{
return "dx_" + privateText;
}
TString Decorate(const TString &string)
{
if (string.compare(0, 3, "gl_"))
{
return "_" + string;
}
return string;
}
TString TypeString(const TType &type)
{
const TStructure* structure = type.getStruct();
if (structure)
{
const TString& typeName = structure->name();
if (typeName != "")
{
return StructNameString(*structure);
}
else // Nameless structure, define in place
{
return OutputHLSL::defineNamelessStruct(*structure);
}
}
else if (type.isMatrix())
{
int cols = type.getCols();
int rows = type.getRows();
return "float" + str(cols) + "x" + str(rows);
}
else
{
switch (type.getBasicType())
{
case EbtFloat:
switch (type.getNominalSize())
{
case 1: return "float";
case 2: return "float2";
case 3: return "float3";
case 4: return "float4";
}
case EbtInt:
switch (type.getNominalSize())
{
case 1: return "int";
case 2: return "int2";
case 3: return "int3";
case 4: return "int4";
}
case EbtUInt:
switch (type.getNominalSize())
{
case 1: return "uint";
case 2: return "uint2";
case 3: return "uint3";
case 4: return "uint4";
}
case EbtBool:
switch (type.getNominalSize())
{
case 1: return "bool";
case 2: return "bool2";
case 3: return "bool3";
case 4: return "bool4";
}
case EbtVoid:
return "void";
case EbtSampler2D:
case EbtISampler2D:
case EbtUSampler2D:
case EbtSampler2DArray:
case EbtISampler2DArray:
case EbtUSampler2DArray:
return "sampler2D";
case EbtSamplerCube:
case EbtISamplerCube:
case EbtUSamplerCube:
return "samplerCUBE";
case EbtSamplerExternalOES:
return "sampler2D";
default:
break;
}
}
UNREACHABLE();
return "<unknown type>";
}
TString StructNameString(const TStructure &structure)
{
if (structure.name().empty())
{
return "";
}
return "ss_" + str(structure.uniqueId()) + structure.name();
}
TString QualifiedStructNameString(const TStructure &structure, bool useHLSLRowMajorPacking,
bool useStd140Packing)
{
if (structure.name() == "")
{
return "";
}
TString prefix = "";
// Structs packed with row-major matrices in HLSL are prefixed with "rm"
// GLSL column-major maps to HLSL row-major, and the converse is true
if (useStd140Packing)
{
prefix += "std";
}
if (useHLSLRowMajorPacking)
{
if (prefix != "") prefix += "_";
prefix += "rm";
}
return prefix + StructNameString(structure);
}
TString InterpolationString(TQualifier qualifier)
{
switch (qualifier)
{
case EvqVaryingIn: return "";
case EvqFragmentIn: return "";
case EvqInvariantVaryingIn: return "";
case EvqSmoothIn: return "linear";
case EvqFlatIn: return "nointerpolation";
case EvqCentroidIn: return "centroid";
case EvqVaryingOut: return "";
case EvqVertexOut: return "";
case EvqInvariantVaryingOut: return "";
case EvqSmoothOut: return "linear";
case EvqFlatOut: return "nointerpolation";
case EvqCentroidOut: return "centroid";
default: UNREACHABLE();
}
return "";
}
TString QualifierString(TQualifier qualifier)
{
switch (qualifier)
{
case EvqIn: return "in";
case EvqOut: return "inout"; // 'out' results in an HLSL error if not all fields are written, for GLSL it's undefined
case EvqInOut: return "inout";
case EvqConstReadOnly: return "const";
default: UNREACHABLE();
}
return "";
}
}
//
// 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.
//
// UtilsHLSL.h:
// Utility methods for GLSL to HLSL translation.
//
#ifndef TRANSLATOR_UTILSHLSL_H_
#define TRANSLATOR_UTILSHLSL_H_
#include <vector>
#include "compiler/translator/Types.h"
#include <GLES3/gl3.h>
#include <GLES2/gl2.h>
namespace sh
{
TString TextureString(const TType &type);
TString SamplerString(const TType &type);
// Prepends an underscore to avoid naming clashes
TString Decorate(const TString &string);
TString DecorateUniform(const TString &string, const TType &type);
TString DecorateField(const TString &string, const TStructure &structure);
TString DecoratePrivate(const TString &privateText);
TString TypeString(const TType &type);
TString StructNameString(const TStructure &structure);
TString QualifiedStructNameString(const TStructure &structure, bool useHLSLRowMajorPacking,
bool useStd140Packing);
TString InterpolationString(TQualifier qualifier);
TString QualifierString(TQualifier qualifier);
}
#endif // TRANSLATOR_UTILSHLSL_H_
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <limits> #include <limits>
#include "compiler/preprocessor/numeric_lex.h" #include "compiler/preprocessor/numeric_lex.h"
#include "common/shadervars.h"
bool atof_clamp(const char *str, float *value) bool atof_clamp(const char *str, float *value)
{ {
...@@ -26,3 +27,254 @@ bool atoi_clamp(const char *str, int *value) ...@@ -26,3 +27,254 @@ bool atoi_clamp(const char *str, int *value)
return success; return success;
} }
namespace sh
{
GLenum GLVariableType(const TType &type)
{
if (type.getBasicType() == EbtFloat)
{
if (type.isScalar())
{
return GL_FLOAT;
}
else if (type.isVector())
{
switch (type.getNominalSize())
{
case 2: return GL_FLOAT_VEC2;
case 3: return GL_FLOAT_VEC3;
case 4: return GL_FLOAT_VEC4;
default: UNREACHABLE();
}
}
else if (type.isMatrix())
{
switch (type.getCols())
{
case 2:
switch (type.getRows())
{
case 2: return GL_FLOAT_MAT2;
case 3: return GL_FLOAT_MAT2x3;
case 4: return GL_FLOAT_MAT2x4;
default: UNREACHABLE();
}
case 3:
switch (type.getRows())
{
case 2: return GL_FLOAT_MAT3x2;
case 3: return GL_FLOAT_MAT3;
case 4: return GL_FLOAT_MAT3x4;
default: UNREACHABLE();
}
case 4:
switch (type.getRows())
{
case 2: return GL_FLOAT_MAT4x2;
case 3: return GL_FLOAT_MAT4x3;
case 4: return GL_FLOAT_MAT4;
default: UNREACHABLE();
}
default: UNREACHABLE();
}
}
else UNREACHABLE();
}
else if (type.getBasicType() == EbtInt)
{
if (type.isScalar())
{
return GL_INT;
}
else if (type.isVector())
{
switch (type.getNominalSize())
{
case 2: return GL_INT_VEC2;
case 3: return GL_INT_VEC3;
case 4: return GL_INT_VEC4;
default: UNREACHABLE();
}
}
else UNREACHABLE();
}
else if (type.getBasicType() == EbtUInt)
{
if (type.isScalar())
{
return GL_UNSIGNED_INT;
}
else if (type.isVector())
{
switch (type.getNominalSize())
{
case 2: return GL_UNSIGNED_INT_VEC2;
case 3: return GL_UNSIGNED_INT_VEC3;
case 4: return GL_UNSIGNED_INT_VEC4;
default: UNREACHABLE();
}
}
else UNREACHABLE();
}
else if (type.getBasicType() == EbtBool)
{
if (type.isScalar())
{
return GL_BOOL;
}
else if (type.isVector())
{
switch (type.getNominalSize())
{
case 2: return GL_BOOL_VEC2;
case 3: return GL_BOOL_VEC3;
case 4: return GL_BOOL_VEC4;
default: UNREACHABLE();
}
}
else UNREACHABLE();
}
switch (type.getBasicType())
{
case EbtSampler2D: return GL_SAMPLER_2D;
case EbtSampler3D: return GL_SAMPLER_3D;
case EbtSamplerCube: return GL_SAMPLER_CUBE;
case EbtSampler2DArray: return GL_SAMPLER_2D_ARRAY;
case EbtISampler2D: return GL_INT_SAMPLER_2D;
case EbtISampler3D: return GL_INT_SAMPLER_3D;
case EbtISamplerCube: return GL_INT_SAMPLER_CUBE;
case EbtISampler2DArray: return GL_INT_SAMPLER_2D_ARRAY;
case EbtUSampler2D: return GL_UNSIGNED_INT_SAMPLER_2D;
case EbtUSampler3D: return GL_UNSIGNED_INT_SAMPLER_3D;
case EbtUSamplerCube: return GL_UNSIGNED_INT_SAMPLER_CUBE;
case EbtUSampler2DArray: return GL_UNSIGNED_INT_SAMPLER_2D_ARRAY;
case EbtSampler2DShadow: return GL_SAMPLER_2D_SHADOW;
case EbtSamplerCubeShadow: return GL_SAMPLER_CUBE_SHADOW;
case EbtSampler2DArrayShadow: return GL_SAMPLER_2D_ARRAY_SHADOW;
default: UNREACHABLE();
}
return GL_NONE;
}
GLenum GLVariablePrecision(const TType &type)
{
if (type.getBasicType() == EbtFloat)
{
switch (type.getPrecision())
{
case EbpHigh:
return GL_HIGH_FLOAT;
case EbpMedium:
return GL_MEDIUM_FLOAT;
case EbpLow:
return GL_LOW_FLOAT;
case EbpUndefined:
// Should be defined as the default precision by the parser
default:
UNREACHABLE();
}
}
else if (type.getBasicType() == EbtInt || type.getBasicType() == EbtUInt)
{
switch (type.getPrecision())
{
case EbpHigh:
return GL_HIGH_INT;
case EbpMedium:
return GL_MEDIUM_INT;
case EbpLow:
return GL_LOW_INT;
case EbpUndefined:
// Should be defined as the default precision by the parser
default:
UNREACHABLE();
}
}
// Other types (boolean, sampler) don't have a precision
return GL_NONE;
}
TString ArrayString(const TType &type)
{
if (!type.isArray())
{
return "";
}
return "[" + str(type.getArraySize()) + "]";
}
bool IsVaryingOut(TQualifier qualifier)
{
switch (qualifier)
{
case EvqVaryingOut:
case EvqInvariantVaryingOut:
case EvqSmoothOut:
case EvqFlatOut:
case EvqCentroidOut:
case EvqVertexOut:
return true;
default: break;
}
return false;
}
bool IsVaryingIn(TQualifier qualifier)
{
switch (qualifier)
{
case EvqVaryingIn:
case EvqInvariantVaryingIn:
case EvqSmoothIn:
case EvqFlatIn:
case EvqCentroidIn:
case EvqFragmentIn:
return true;
default: break;
}
return false;
}
bool IsVarying(TQualifier qualifier)
{
return IsVaryingIn(qualifier) || IsVaryingOut(qualifier);
}
gl::InterpolationType GetInterpolationType(TQualifier qualifier)
{
switch (qualifier)
{
case EvqFlatIn:
case EvqFlatOut:
return gl::INTERPOLATION_FLAT;
case EvqSmoothIn:
case EvqSmoothOut:
case EvqVertexOut:
case EvqFragmentIn:
case EvqVaryingIn:
case EvqVaryingOut:
return gl::INTERPOLATION_SMOOTH;
case EvqCentroidIn:
case EvqCentroidOut:
return gl::INTERPOLATION_CENTROID;
default: UNREACHABLE();
return gl::INTERPOLATION_SMOOTH;
}
}
}
...@@ -7,6 +7,11 @@ ...@@ -7,6 +7,11 @@
#ifndef COMPILER_UTIL_H #ifndef COMPILER_UTIL_H
#define COMPILER_UTIL_H #define COMPILER_UTIL_H
#include "compiler/translator/Types.h"
#include <GLES3/gl3.h>
#include <GLES2/gl2.h>
#include "common/shadervars.h"
// atof_clamp is like atof but // atof_clamp is like atof but
// 1. it forces C locale, i.e. forcing '.' as decimal point. // 1. it forces C locale, i.e. forcing '.' as decimal point.
// 2. it clamps the value to -FLT_MAX or FLT_MAX if overflow happens. // 2. it clamps the value to -FLT_MAX or FLT_MAX if overflow happens.
...@@ -17,4 +22,17 @@ extern bool atof_clamp(const char *str, float *value); ...@@ -17,4 +22,17 @@ extern bool atof_clamp(const char *str, float *value);
// Return false if overflow happens. // Return false if overflow happens.
extern bool atoi_clamp(const char *str, int *value); extern bool atoi_clamp(const char *str, int *value);
namespace sh
{
GLenum GLVariableType(const TType &type);
GLenum GLVariablePrecision(const TType &type);
bool IsVaryingIn(TQualifier qualifier);
bool IsVaryingOut(TQualifier qualifier);
bool IsVarying(TQualifier qualifier);
gl::InterpolationType GetInterpolationType(TQualifier qualifier);
TString ArrayString(const TType &type);
}
#endif // COMPILER_UTIL_H #endif // COMPILER_UTIL_H
...@@ -1034,7 +1034,7 @@ std::string DynamicHLSL::generatePointSpriteHLSL(int registers, FragmentShader * ...@@ -1034,7 +1034,7 @@ std::string DynamicHLSL::generatePointSpriteHLSL(int registers, FragmentShader *
// This method needs to match OutputHLSL::decorate // This method needs to match OutputHLSL::decorate
std::string DynamicHLSL::decorateVariable(const std::string &name) std::string DynamicHLSL::decorateVariable(const std::string &name)
{ {
if (name.compare(0, 3, "gl_") != 0 && name.compare(0, 3, "dx_") != 0) if (name.compare(0, 3, "gl_"))
{ {
return "_" + name; return "_" + name;
} }
......
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