Commit 2857f489 by Jamie Madill

Fix struct uniform packing.

Our current code would not adapt properly for members that did not fit in the previous register. Instead, use the correct adjusted value as returned from the block layout encoder. This fixes a dEQP WebGL test: gles2/shaders/linkage. BUG=angle:910 Change-Id: Id77d0c76ce767665b3db97cb4d14e8008254fd9f Reviewed-on: https://chromium-review.googlesource.com/247241Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 55e79e09
...@@ -34,6 +34,18 @@ BlockMemberInfo BlockLayoutEncoder::encodeType(GLenum type, unsigned int arraySi ...@@ -34,6 +34,18 @@ BlockMemberInfo BlockLayoutEncoder::encodeType(GLenum type, unsigned int arraySi
return memberInfo; return memberInfo;
} }
// static
size_t BlockLayoutEncoder::getBlockRegister(const BlockMemberInfo &info)
{
return (info.offset / BytesPerComponent) / ComponentsPerRegister;
}
// static
size_t BlockLayoutEncoder::getBlockRegisterElement(const BlockMemberInfo &info)
{
return (info.offset / BytesPerComponent) % ComponentsPerRegister;
}
void BlockLayoutEncoder::nextRegister() void BlockLayoutEncoder::nextRegister()
{ {
mCurrentOffset = rx::roundUp<size_t>(mCurrentOffset, ComponentsPerRegister); mCurrentOffset = rx::roundUp<size_t>(mCurrentOffset, ComponentsPerRegister);
......
...@@ -61,6 +61,9 @@ class COMPILER_EXPORT BlockLayoutEncoder ...@@ -61,6 +61,9 @@ class COMPILER_EXPORT BlockLayoutEncoder
static const size_t BytesPerComponent = 4u; static const size_t BytesPerComponent = 4u;
static const unsigned int ComponentsPerRegister = 4u; static const unsigned int ComponentsPerRegister = 4u;
static size_t getBlockRegister(const BlockMemberInfo &info);
static size_t getBlockRegisterElement(const BlockMemberInfo &info);
protected: protected:
size_t mCurrentOffset; size_t mCurrentOffset;
......
...@@ -1463,30 +1463,28 @@ void ProgramD3D::defineUniform(const ShaderD3D *shader, const sh::ShaderVariable ...@@ -1463,30 +1463,28 @@ void ProgramD3D::defineUniform(const ShaderD3D *shader, const sh::ShaderVariable
gl::LinkedUniform *linkedUniform = getUniformByName(fullName); gl::LinkedUniform *linkedUniform = getUniformByName(fullName);
// Advance the uniform offset, to track registers allocation for structs
sh::BlockMemberInfo blockInfo = encoder->encodeType(uniform.type, uniform.arraySize, false);
if (!linkedUniform) if (!linkedUniform)
{ {
linkedUniform = new gl::LinkedUniform(uniform.type, uniform.precision, fullName, uniform.arraySize, linkedUniform = new gl::LinkedUniform(uniform.type, uniform.precision, fullName, uniform.arraySize,
-1, sh::BlockMemberInfo::getDefaultBlockInfo()); -1, sh::BlockMemberInfo::getDefaultBlockInfo());
ASSERT(linkedUniform); ASSERT(linkedUniform);
linkedUniform->registerElement = encoder->getCurrentElement(); linkedUniform->registerElement = sh::HLSLBlockEncoder::getBlockRegisterElement(blockInfo);
mUniforms.push_back(linkedUniform); mUniforms.push_back(linkedUniform);
} }
ASSERT(linkedUniform->registerElement == encoder->getCurrentElement());
if (shader->getShaderType() == GL_FRAGMENT_SHADER) if (shader->getShaderType() == GL_FRAGMENT_SHADER)
{ {
linkedUniform->psRegisterIndex = encoder->getCurrentRegister(); linkedUniform->psRegisterIndex = sh::HLSLBlockEncoder::getBlockRegister(blockInfo);
} }
else if (shader->getShaderType() == GL_VERTEX_SHADER) else if (shader->getShaderType() == GL_VERTEX_SHADER)
{ {
linkedUniform->vsRegisterIndex = encoder->getCurrentRegister(); linkedUniform->vsRegisterIndex = sh::HLSLBlockEncoder::getBlockRegister(blockInfo);
} }
else UNREACHABLE(); else UNREACHABLE();
// Advance the uniform offset, to track registers allocation for structs
encoder->encodeType(uniform.type, uniform.arraySize, false);
// Arrays are treated as aggregate types // Arrays are treated as aggregate types
if (uniform.isArray()) if (uniform.isArray())
{ {
......
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