Commit 07d68856 by Jamie Madill

Move the implementations of shader var init to the header.

Making the contructors for shader variables inline saves us from exporting them across DLL boundaries. This makes it easier to use them in the translator when building the translator as a DLL. BUG=angle:466 Change-Id: Iee0556e06dc1f9e98fe9eea6577819305de0dd0b Reviewed-on: https://chromium-review.googlesource.com/198555Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarNicolas Capens <nicolascapens@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent d127d8e6
......@@ -152,7 +152,6 @@
<ClCompile Include="..\..\src\common\debug.cpp"/>
<ClCompile Include="..\..\src\common\event_tracer.cpp"/>
<ClCompile Include="..\..\src\common\utilities.cpp"/>
<ClCompile Include="..\..\src\common\shadervars.cpp"/>
<ClCompile Include="..\..\src\common\blocklayout.cpp"/>
</ItemGroup>
<ItemGroup>
......
......@@ -102,9 +102,6 @@
<ClCompile Include="..\..\src\common\utilities.cpp">
<Filter>src\common</Filter>
</ClCompile>
<ClCompile Include="..\..\src\common\shadervars.cpp">
<Filter>src\common</Filter>
</ClCompile>
<ClInclude Include="..\..\src\common\angleutils.h">
<Filter>src\common</Filter>
</ClInclude>
......
......@@ -204,7 +204,6 @@
<ClCompile Include="..\..\src\common\RefCountObject.cpp"/>
<ClCompile Include="..\..\src\common\mathutil.cpp"/>
<ClCompile Include="..\..\src\common\debug.cpp"/>
<ClCompile Include="..\..\src\common\shadervars.cpp"/>
<ClCompile Include="..\..\src\common\blocklayout.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\InfoSink.cpp"/>
<ClCompile Include="..\..\src\compiler\translator\OutputESSL.cpp"/>
......
......@@ -96,9 +96,6 @@
<ClInclude Include="..\..\src\common\utilities.h">
<Filter>src\common</Filter>
</ClInclude>
<ClCompile Include="..\..\src\common\shadervars.cpp">
<Filter>src\common</Filter>
</ClCompile>
<ClCompile Include="..\..\src\common\blocklayout.cpp">
<Filter>src\common</Filter>
</ClCompile>
......
//
// Copyright (c) 2013-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.
//
// shadervars.cpp:
// Implementation for GL shader variable member functions.
//
#include "common/shadervars.h"
namespace gl
{
ShaderVariable::ShaderVariable(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn)
: type(typeIn),
precision(precisionIn),
name(nameIn),
arraySize(arraySizeIn)
{
}
Uniform::Uniform(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, unsigned int registerIndexIn, unsigned int elementIndexIn)
: ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
registerIndex(registerIndexIn),
elementIndex(elementIndexIn)
{
}
Attribute::Attribute()
: ShaderVariable(GL_NONE, GL_NONE, "", 0),
location(-1)
{
}
Attribute::Attribute(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, int locationIn)
: ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
location(locationIn)
{
}
InterfaceBlockField::InterfaceBlockField(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, bool isRowMajorMatrix)
: ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
isRowMajorMatrix(isRowMajorMatrix)
{
}
Varying::Varying(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, InterpolationType interpolationIn)
: ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
interpolation(interpolationIn),
registerIndex(GL_INVALID_INDEX),
elementIndex(GL_INVALID_INDEX)
{
}
void Varying::resetRegisterAssignment()
{
registerIndex = GL_INVALID_INDEX;
elementIndex = GL_INVALID_INDEX;
}
BlockMemberInfo::BlockMemberInfo(int offset, int arrayStride, int matrixStride, bool isRowMajorMatrix)
: offset(offset),
arrayStride(arrayStride),
matrixStride(matrixStride),
isRowMajorMatrix(isRowMajorMatrix)
{
}
BlockMemberInfo BlockMemberInfo::getDefaultBlockInfo()
{
return BlockMemberInfo(-1, -1, -1, false);
}
InterfaceBlock::InterfaceBlock(const char *name, unsigned int arraySize, unsigned int registerIndex)
: name(name),
arraySize(arraySize),
layout(BLOCKLAYOUT_SHARED),
registerIndex(registerIndex),
isRowMajorLayout(false)
{
}
}
......@@ -21,6 +21,7 @@
namespace gl
{
// Varying interpolation qualifier, see section 4.3.9 of the ESSL 3.00.4 spec
enum InterpolationType
{
INTERPOLATION_SMOOTH,
......@@ -28,6 +29,15 @@ enum InterpolationType
INTERPOLATION_FLAT
};
// Uniform block layout qualifier, see section 4.3.8.3 of the ESSL 3.00.4 spec
enum BlockLayoutType
{
BLOCKLAYOUT_STANDARD,
BLOCKLAYOUT_PACKED,
BLOCKLAYOUT_SHARED
};
// Base class for all variables defined in shaders, including Varyings, Uniforms, etc
struct ShaderVariable
{
GLenum type;
......@@ -35,11 +45,18 @@ struct ShaderVariable
std::string name;
unsigned int arraySize;
ShaderVariable(GLenum type, GLenum precision, const char *name, unsigned int arraySize);
ShaderVariable(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn)
: type(typeIn),
precision(precisionIn),
name(nameIn),
arraySize(arraySizeIn)
{}
bool isArray() const { return arraySize > 0; }
unsigned int elementCount() const { return std::max(1u, arraySize); }
};
// Uniform registers (and element indices) are assigned when outputting shader code
struct Uniform : public ShaderVariable
{
unsigned int registerIndex;
......@@ -47,7 +64,11 @@ struct Uniform : public ShaderVariable
std::vector<Uniform> fields;
Uniform(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn,
unsigned int registerIndexIn, unsigned int elementIndexIn);
unsigned int registerIndexIn, unsigned int elementIndexIn)
: ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
registerIndex(registerIndexIn),
elementIndex(elementIndexIn)
{}
bool isStruct() const { return !fields.empty(); }
};
......@@ -56,8 +77,15 @@ struct Attribute : public ShaderVariable
{
int location;
Attribute();
Attribute(GLenum type, GLenum precision, const char *name, unsigned int arraySize, int location);
Attribute()
: ShaderVariable(GL_NONE, GL_NONE, "", 0),
location(-1)
{}
Attribute(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, int locationIn)
: ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
location(locationIn)
{}
};
struct InterfaceBlockField : public ShaderVariable
......@@ -65,7 +93,10 @@ struct InterfaceBlockField : public ShaderVariable
bool isRowMajorMatrix;
std::vector<InterfaceBlockField> fields;
InterfaceBlockField(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, bool isRowMajorMatrix);
InterfaceBlockField(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, bool isRowMajorMatrix)
: ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
isRowMajorMatrix(isRowMajorMatrix)
{}
bool isStruct() const { return !fields.empty(); }
};
......@@ -78,39 +109,47 @@ struct Varying : public ShaderVariable
unsigned int elementIndex; // First register element for varyings, assigned during link
std::string structName;
Varying(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, InterpolationType interpolationIn);
Varying(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, InterpolationType interpolationIn)
: ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
interpolation(interpolationIn),
registerIndex(GL_INVALID_INDEX),
elementIndex(GL_INVALID_INDEX)
{}
bool isStruct() const { return !fields.empty(); }
bool registerAssigned() const { return registerIndex != GL_INVALID_INDEX; }
void resetRegisterAssignment();
void resetRegisterAssignment()
{
registerIndex = GL_INVALID_INDEX;
elementIndex = GL_INVALID_INDEX;
}
};
struct BlockMemberInfo
{
BlockMemberInfo(int offset, int arrayStride, int matrixStride, bool isRowMajorMatrix);
int offset;
int arrayStride;
int matrixStride;
bool isRowMajorMatrix;
static BlockMemberInfo getDefaultBlockInfo();
static BlockMemberInfo getDefaultBlockInfo()
{
return BlockMemberInfo(-1, -1, -1, false);
}
BlockMemberInfo(int offset, int arrayStride, int matrixStride, bool isRowMajorMatrix)
: offset(offset),
arrayStride(arrayStride),
matrixStride(matrixStride),
isRowMajorMatrix(isRowMajorMatrix)
{}
};
typedef std::vector<BlockMemberInfo> BlockMemberInfoArray;
enum BlockLayoutType
{
BLOCKLAYOUT_STANDARD,
BLOCKLAYOUT_PACKED,
BLOCKLAYOUT_SHARED
};
struct InterfaceBlock
{
InterfaceBlock(const char *name, unsigned int arraySize, unsigned int registerIndex);
std::string name;
unsigned int arraySize;
size_t dataSize;
......@@ -120,6 +159,14 @@ struct InterfaceBlock
std::vector<BlockMemberInfo> blockInfo;
unsigned int registerIndex;
InterfaceBlock(const char *name, unsigned int arraySize, unsigned int registerIndex)
: name(name),
arraySize(arraySize),
layout(BLOCKLAYOUT_SHARED),
registerIndex(registerIndex),
isRowMajorLayout(false)
{}
};
}
......
......@@ -1574,9 +1574,9 @@ bool ProgramBinary::link(InfoLog &infoLog, const AttributeBindings &attributeBin
// special case for gl_DepthRange, the only built-in uniform (also a struct)
if (vertexShader->usesDepthRange() || fragmentShader->usesDepthRange())
{
mUniforms.push_back(new LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.near", 0, -1, gl::BlockMemberInfo::getDefaultBlockInfo()));
mUniforms.push_back(new LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.far", 0, -1, gl::BlockMemberInfo::getDefaultBlockInfo()));
mUniforms.push_back(new LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.diff", 0, -1, gl::BlockMemberInfo::getDefaultBlockInfo()));
mUniforms.push_back(new LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.near", 0, -1, BlockMemberInfo::getDefaultBlockInfo()));
mUniforms.push_back(new LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.far", 0, -1, BlockMemberInfo::getDefaultBlockInfo()));
mUniforms.push_back(new LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.diff", 0, -1, BlockMemberInfo::getDefaultBlockInfo()));
}
if (!linkUniformBlocks(infoLog, vertexShader->getInterfaceBlocks(), fragmentShader->getInterfaceBlocks()))
......@@ -2022,7 +2022,8 @@ bool ProgramBinary::defineUniform(GLenum shader, const gl::Uniform &constant, In
}
else
{
uniform = new LinkedUniform(constant.type, constant.precision, constant.name, constant.arraySize, -1, gl::BlockMemberInfo::getDefaultBlockInfo());
uniform = new LinkedUniform(constant.type, constant.precision, constant.name, constant.arraySize,
-1, BlockMemberInfo::getDefaultBlockInfo());
uniform->registerElement = constant.elementIndex;
}
......
......@@ -179,7 +179,7 @@ class ProgramBinary : public RefCountObject
bool linkVaryings(InfoLog &infoLog, FragmentShader *fragmentShader, VertexShader *vertexShader);
bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader);
typedef BlockMemberInfoArray::const_iterator BlockInfoItr;
typedef std::vector<BlockMemberInfo>::const_iterator BlockInfoItr;
template <class ShaderVarType>
bool linkValidateFields(InfoLog &infoLog, const std::string &varName, const ShaderVarType &vertexVar, const ShaderVarType &fragmentVar);
......
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