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
diff --git a/src/compiler/BlockLayoutEncoder.cpp b/src/compiler/BlockLayoutEncoder.cpp
index 7d31d70..ef2a0e9 100644
--- a/src/compiler/BlockLayoutEncoder.cpp
+++ b/src/compiler/BlockLayoutEncoder.cpp
@@ -47,12 +47,26 @@
int arrayStride;
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);
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()
@@ -75,37 +89,35 @@
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)
- 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;
int matrixStride = 0;
int arrayStride = 0;
- if (gl::IsMatrixType(uniform.type))
+ if (gl::IsMatrixType(type))
{
baseAlignment = 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;
}
}
- else if (uniform.arraySize > 0)
+ else if (arraySize > 0)
{
baseAlignment = RegisterSize;
arrayStride = RegisterSize;
}
else
{
- const int numComponents = gl::UniformComponentCount(uniform.type);
+ const int numComponents = gl::UniformComponentCount(type);
baseAlignment = (numComponents == 3 ? 4u : static_cast<size_t>(numComponents));
}
@@ -115,21 +127,21 @@
*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);
- const int numRegisters = gl::MatrixRegisterCount(uniform.type, uniform.isRowMajorMatrix);
+ const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
mCurrentOffset += RegisterSize * numRegisters;
}
else
{
- mCurrentOffset += gl::UniformComponentCount(uniform.type);
+ mCurrentOffset += gl::UniformComponentCount(type);
}
}
diff --git a/src/compiler/BlockLayoutEncoder.h b/src/compiler/BlockLayoutEncoder.h
index 01e611d..57a8d81 100644
--- a/src/compiler/BlockLayoutEncoder.h
+++ b/src/compiler/BlockLayoutEncoder.h
@@ -8,6 +8,9 @@
#define TRANSLATOR_COMMON_BLOCKLAYOUTENCODER_H_
#include <vector>
+#define GL_APICALL
+#include <GLES3/gl3.h>
+#include <GLES2/gl2.h>
namespace sh
{
@@ -22,6 +25,7 @@
void encodeFields(const std::vector<Uniform> &fields);
void encodeType(const Uniform &uniform);
+ void encodeType(GLenum type, unsigned int arraySize, bool isRowMajorMatrix);
size_t getBlockSize() { return mCurrentOffset * ComponentSize; }
static const size_t ComponentSize = 4u;
@@ -34,8 +38,8 @@
virtual void enterAggregateType() = 0;
virtual void exitAggregateType() = 0;
- virtual void getBlockLayoutInfo(const Uniform &uniform, int *arrayStrideOut, int *matrixStrideOut) = 0;
- virtual void advanceOffset(const Uniform &uniform, int arrayStride, int matrixStride) = 0;
+ virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut) = 0;
+ virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride) = 0;
private:
std::vector<BlockMemberInfo> *mBlockInfoOut;
@@ -52,8 +56,8 @@
protected:
virtual void enterAggregateType();
virtual void exitAggregateType();
- virtual void getBlockLayoutInfo(const Uniform &uniform, int *arrayStrideOut, int *matrixStrideOut);
- virtual void advanceOffset(const Uniform &uniform, int arrayStride, int matrixStride);
+ virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut);
+ virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride);
};
}
diff --git a/src/compiler/HLSLLayoutEncoder.cpp b/src/compiler/HLSLLayoutEncoder.cpp
index d422732..8c35f47 100644
--- a/src/compiler/HLSLLayoutEncoder.cpp
+++ b/src/compiler/HLSLLayoutEncoder.cpp
@@ -26,35 +26,33 @@
{
}
-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)
- ASSERT(gl::UniformComponentSize(gl::UniformComponentType(uniform.type)) == ComponentSize);
+ ASSERT(gl::UniformComponentSize(gl::UniformComponentType(type)) == ComponentSize);
int matrixStride = 0;
int arrayStride = 0;
- if (gl::IsMatrixType(uniform.type))
+ if (gl::IsMatrixType(type))
{
nextRegister();
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;
}
}
- else if (uniform.arraySize > 0)
+ else if (arraySize > 0)
{
nextRegister();
arrayStride = RegisterSize;
}
else
{
- int numComponents = gl::UniformComponentCount(uniform.type);
+ int numComponents = gl::UniformComponentCount(type);
if ((numComponents + (mCurrentOffset % RegisterSize)) > RegisterSize)
{
nextRegister();
@@ -65,24 +63,24 @@
*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);
- const int numRegisters = gl::MatrixRegisterCount(uniform.type, uniform.isRowMajorMatrix);
- const int numComponents = gl::MatrixComponentCount(uniform.type, uniform.isRowMajorMatrix);
+ const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
+ const int numComponents = gl::MatrixComponentCount(type, isRowMajorMatrix);
mCurrentOffset += RegisterSize * (numRegisters - 1);
mCurrentOffset += numComponents;
}
else
{
- mCurrentOffset += gl::UniformComponentCount(uniform.type);
+ mCurrentOffset += gl::UniformComponentCount(type);
}
}
diff --git a/src/compiler/HLSLLayoutEncoder.h b/src/compiler/HLSLLayoutEncoder.h
index cecd29e..7012ba0 100644
--- a/src/compiler/HLSLLayoutEncoder.h
+++ b/src/compiler/HLSLLayoutEncoder.h
@@ -23,8 +23,8 @@
protected:
virtual void enterAggregateType();
virtual void exitAggregateType();
- virtual void getBlockLayoutInfo(const sh::Uniform &uniform, int *arrayStrideOut, int *matrixStrideOut);
- virtual void advanceOffset(const sh::Uniform &uniform, int arrayStride, int matrixStride);
+ virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut);
+ virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride);
};
}