Commit 912cbfe8 by Jamie Madill

Allow the block encoder classes to encode types directly passed by value,…

Allow the block encoder classes to encode types directly passed by value, instead of as a compound type. TRAC #23754 Signed-off-by: Nicolas Capens Signed-off-by: Shannon Woods
parent bcb6a1e0
...@@ -47,12 +47,26 @@ void BlockLayoutEncoder::encodeType(const Uniform &uniform) ...@@ -47,12 +47,26 @@ void BlockLayoutEncoder::encodeType(const Uniform &uniform)
int arrayStride; int arrayStride;
int matrixStride; int matrixStride;
getBlockLayoutInfo(uniform, &arrayStride, &matrixStride); ASSERT(uniform.fields.empty());
getBlockLayoutInfo(uniform.type, uniform.arraySize, uniform.isRowMajorMatrix, &arrayStride, &matrixStride);
const BlockMemberInfo memberInfo(mCurrentOffset * ComponentSize, arrayStride * ComponentSize, matrixStride * ComponentSize, uniform.isRowMajorMatrix); const BlockMemberInfo memberInfo(mCurrentOffset * ComponentSize, arrayStride * ComponentSize, matrixStride * ComponentSize, uniform.isRowMajorMatrix);
mBlockInfoOut->push_back(memberInfo); mBlockInfoOut->push_back(memberInfo);
advanceOffset(uniform, arrayStride, matrixStride); advanceOffset(uniform.type, uniform.arraySize, uniform.isRowMajorMatrix, arrayStride, matrixStride);
}
void BlockLayoutEncoder::encodeType(GLenum type, unsigned int arraySize, bool isRowMajorMatrix)
{
int arrayStride;
int matrixStride;
getBlockLayoutInfo(type, arraySize, isRowMajorMatrix, &arrayStride, &matrixStride);
const BlockMemberInfo memberInfo(mCurrentOffset * ComponentSize, arrayStride * ComponentSize, matrixStride * ComponentSize, isRowMajorMatrix);
mBlockInfoOut->push_back(memberInfo);
advanceOffset(type, arraySize, isRowMajorMatrix, arrayStride, matrixStride);
} }
void BlockLayoutEncoder::nextRegister() void BlockLayoutEncoder::nextRegister()
...@@ -75,37 +89,35 @@ void Std140BlockEncoder::exitAggregateType() ...@@ -75,37 +89,35 @@ void Std140BlockEncoder::exitAggregateType()
nextRegister(); nextRegister();
} }
void Std140BlockEncoder::getBlockLayoutInfo(const Uniform &uniform, int *arrayStrideOut, int *matrixStrideOut) void Std140BlockEncoder::getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut)
{ {
ASSERT(uniform.fields.empty());
// We assume we are only dealing with 4 byte components (no doubles or half-words currently) // We assume we are only dealing with 4 byte components (no doubles or half-words currently)
ASSERT(gl::UniformComponentSize(gl::UniformComponentType(uniform.type)) == ComponentSize); ASSERT(gl::UniformComponentSize(gl::UniformComponentType(type)) == ComponentSize);
int numComponents = gl::UniformComponentCount(uniform.type); int numComponents = gl::UniformComponentCount(type);
size_t baseAlignment = 0; size_t baseAlignment = 0;
int matrixStride = 0; int matrixStride = 0;
int arrayStride = 0; int arrayStride = 0;
if (gl::IsMatrixType(uniform.type)) if (gl::IsMatrixType(type))
{ {
baseAlignment = RegisterSize; baseAlignment = RegisterSize;
matrixStride = RegisterSize; matrixStride = RegisterSize;
if (uniform.arraySize > 0) if (arraySize > 0)
{ {
const int numRegisters = gl::MatrixRegisterCount(uniform.type, uniform.isRowMajorMatrix); const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
arrayStride = RegisterSize * numRegisters; arrayStride = RegisterSize * numRegisters;
} }
} }
else if (uniform.arraySize > 0) else if (arraySize > 0)
{ {
baseAlignment = RegisterSize; baseAlignment = RegisterSize;
arrayStride = RegisterSize; arrayStride = RegisterSize;
} }
else else
{ {
const int numComponents = gl::UniformComponentCount(uniform.type); const int numComponents = gl::UniformComponentCount(type);
baseAlignment = (numComponents == 3 ? 4u : static_cast<size_t>(numComponents)); baseAlignment = (numComponents == 3 ? 4u : static_cast<size_t>(numComponents));
} }
...@@ -115,21 +127,21 @@ void Std140BlockEncoder::getBlockLayoutInfo(const Uniform &uniform, int *arraySt ...@@ -115,21 +127,21 @@ void Std140BlockEncoder::getBlockLayoutInfo(const Uniform &uniform, int *arraySt
*arrayStrideOut = arrayStride; *arrayStrideOut = arrayStride;
} }
void Std140BlockEncoder::advanceOffset(const Uniform &uniform, int arrayStride, int matrixStride) void Std140BlockEncoder::advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride)
{ {
if (uniform.arraySize > 0) if (arraySize > 0)
{ {
mCurrentOffset += arrayStride * uniform.arraySize; mCurrentOffset += arrayStride * arraySize;
} }
else if (gl::IsMatrixType(uniform.type)) else if (gl::IsMatrixType(type))
{ {
ASSERT(matrixStride == RegisterSize); ASSERT(matrixStride == RegisterSize);
const int numRegisters = gl::MatrixRegisterCount(uniform.type, uniform.isRowMajorMatrix); const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
mCurrentOffset += RegisterSize * numRegisters; mCurrentOffset += RegisterSize * numRegisters;
} }
else else
{ {
mCurrentOffset += gl::UniformComponentCount(uniform.type); mCurrentOffset += gl::UniformComponentCount(type);
} }
} }
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#define TRANSLATOR_COMMON_BLOCKLAYOUTENCODER_H_ #define TRANSLATOR_COMMON_BLOCKLAYOUTENCODER_H_
#include <vector> #include <vector>
#define GL_APICALL
#include <GLES3/gl3.h>
#include <GLES2/gl2.h>
namespace sh namespace sh
{ {
...@@ -22,6 +25,7 @@ class BlockLayoutEncoder ...@@ -22,6 +25,7 @@ class BlockLayoutEncoder
void encodeFields(const std::vector<Uniform> &fields); void encodeFields(const std::vector<Uniform> &fields);
void encodeType(const Uniform &uniform); void encodeType(const Uniform &uniform);
void encodeType(GLenum type, unsigned int arraySize, bool isRowMajorMatrix);
size_t getBlockSize() { return mCurrentOffset * ComponentSize; } size_t getBlockSize() { return mCurrentOffset * ComponentSize; }
static const size_t ComponentSize = 4u; static const size_t ComponentSize = 4u;
...@@ -34,8 +38,8 @@ class BlockLayoutEncoder ...@@ -34,8 +38,8 @@ class BlockLayoutEncoder
virtual void enterAggregateType() = 0; virtual void enterAggregateType() = 0;
virtual void exitAggregateType() = 0; virtual void exitAggregateType() = 0;
virtual void getBlockLayoutInfo(const Uniform &uniform, int *arrayStrideOut, int *matrixStrideOut) = 0; virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut) = 0;
virtual void advanceOffset(const Uniform &uniform, int arrayStride, int matrixStride) = 0; virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride) = 0;
private: private:
std::vector<BlockMemberInfo> *mBlockInfoOut; std::vector<BlockMemberInfo> *mBlockInfoOut;
...@@ -52,8 +56,8 @@ class Std140BlockEncoder : public BlockLayoutEncoder ...@@ -52,8 +56,8 @@ class Std140BlockEncoder : public BlockLayoutEncoder
protected: protected:
virtual void enterAggregateType(); virtual void enterAggregateType();
virtual void exitAggregateType(); virtual void exitAggregateType();
virtual void getBlockLayoutInfo(const Uniform &uniform, int *arrayStrideOut, int *matrixStrideOut); virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut);
virtual void advanceOffset(const Uniform &uniform, int arrayStride, int matrixStride); virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride);
}; };
} }
......
...@@ -26,35 +26,33 @@ void HLSLBlockEncoder::exitAggregateType() ...@@ -26,35 +26,33 @@ void HLSLBlockEncoder::exitAggregateType()
{ {
} }
void HLSLBlockEncoder::getBlockLayoutInfo(const sh::Uniform &uniform, int *arrayStrideOut, int *matrixStrideOut) void HLSLBlockEncoder::getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut)
{ {
ASSERT(uniform.fields.empty());
// We assume we are only dealing with 4 byte components (no doubles or half-words currently) // We assume we are only dealing with 4 byte components (no doubles or half-words currently)
ASSERT(gl::UniformComponentSize(gl::UniformComponentType(uniform.type)) == ComponentSize); ASSERT(gl::UniformComponentSize(gl::UniformComponentType(type)) == ComponentSize);
int matrixStride = 0; int matrixStride = 0;
int arrayStride = 0; int arrayStride = 0;
if (gl::IsMatrixType(uniform.type)) if (gl::IsMatrixType(type))
{ {
nextRegister(); nextRegister();
matrixStride = RegisterSize; matrixStride = RegisterSize;
if (uniform.arraySize > 0) if (arraySize > 0)
{ {
const int numRegisters = gl::MatrixRegisterCount(uniform.type, uniform.isRowMajorMatrix); const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
arrayStride = RegisterSize * numRegisters; arrayStride = RegisterSize * numRegisters;
} }
} }
else if (uniform.arraySize > 0) else if (arraySize > 0)
{ {
nextRegister(); nextRegister();
arrayStride = RegisterSize; arrayStride = RegisterSize;
} }
else else
{ {
int numComponents = gl::UniformComponentCount(uniform.type); int numComponents = gl::UniformComponentCount(type);
if ((numComponents + (mCurrentOffset % RegisterSize)) > RegisterSize) if ((numComponents + (mCurrentOffset % RegisterSize)) > RegisterSize)
{ {
nextRegister(); nextRegister();
...@@ -65,24 +63,24 @@ void HLSLBlockEncoder::getBlockLayoutInfo(const sh::Uniform &uniform, int *array ...@@ -65,24 +63,24 @@ void HLSLBlockEncoder::getBlockLayoutInfo(const sh::Uniform &uniform, int *array
*arrayStrideOut = arrayStride; *arrayStrideOut = arrayStride;
} }
void HLSLBlockEncoder::advanceOffset(const sh::Uniform &uniform, int arrayStride, int matrixStride) void HLSLBlockEncoder::advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride)
{ {
if (uniform.arraySize > 0) if (arraySize > 0)
{ {
mCurrentOffset += arrayStride * (uniform.arraySize - 1); mCurrentOffset += arrayStride * (arraySize - 1);
} }
if (gl::IsMatrixType(uniform.type)) if (gl::IsMatrixType(type))
{ {
ASSERT(matrixStride == RegisterSize); ASSERT(matrixStride == RegisterSize);
const int numRegisters = gl::MatrixRegisterCount(uniform.type, uniform.isRowMajorMatrix); const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
const int numComponents = gl::MatrixComponentCount(uniform.type, uniform.isRowMajorMatrix); const int numComponents = gl::MatrixComponentCount(type, isRowMajorMatrix);
mCurrentOffset += RegisterSize * (numRegisters - 1); mCurrentOffset += RegisterSize * (numRegisters - 1);
mCurrentOffset += numComponents; mCurrentOffset += numComponents;
} }
else else
{ {
mCurrentOffset += gl::UniformComponentCount(uniform.type); mCurrentOffset += gl::UniformComponentCount(type);
} }
} }
......
...@@ -23,8 +23,8 @@ class HLSLBlockEncoder : public BlockLayoutEncoder ...@@ -23,8 +23,8 @@ class HLSLBlockEncoder : public BlockLayoutEncoder
protected: protected:
virtual void enterAggregateType(); virtual void enterAggregateType();
virtual void exitAggregateType(); virtual void exitAggregateType();
virtual void getBlockLayoutInfo(const sh::Uniform &uniform, int *arrayStrideOut, int *matrixStrideOut); virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut);
virtual void advanceOffset(const sh::Uniform &uniform, int arrayStride, int matrixStride); virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride);
}; };
} }
......
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