Commit 5228d3c7 by Alexis Hetu Committed by Alexis Hétu

Uniform buffer related fixes

- Added an actual offset, in registers, to the Uniform structure to take into account that types can have different register sizes. - Fixed the array check in OutputASM::declareUniform() so that it doesn't make an array of blocks when declaring a member as an array in the default uniform block. - Fixed arrayStride and matrixStride in the BlockInfo constructor. - Fixed memberUniformIndexes to use uniform index instead of register index. Change-Id: Id8ba23b5fef71c772bb45a45bb897ca5e2fae385 Reviewed-on: https://swiftshader-review.googlesource.com/3750Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent e04b5cfb
......@@ -75,8 +75,8 @@ namespace glsl
ConstantUnion constants[4];
};
Uniform::Uniform(GLenum type, GLenum precision, const std::string &name, int arraySize, int registerIndex, int blockId) :
type(type), precision(precision), name(name), arraySize(arraySize), registerIndex(registerIndex), blockId(blockId)
Uniform::Uniform(GLenum type, GLenum precision, const std::string &name, int arraySize, int registerIndex, int offset, int blockId) :
type(type), precision(precision), name(name), arraySize(arraySize), registerIndex(registerIndex), offset(offset), blockId(blockId)
{
}
......@@ -2402,7 +2402,7 @@ namespace glsl
}
}
void OutputASM::declareUniform(const TType &type, const TString &name, int offset, int blockId)
void OutputASM::declareUniform(const TType &type, const TString &name, int registerIndex, int offset, int blockId)
{
const TStructure *structure = type.getStruct();
const TInterfaceBlock *block = (type.isInterfaceBlock() || (blockId == -1)) ? type.getInterfaceBlock() : nullptr;
......@@ -2414,7 +2414,7 @@ namespace glsl
blockId = activeUniformBlocks.size();
unsigned int dataSize = block->objectSize() * 4; // FIXME: assuming 4 bytes per element
activeUniformBlocks.push_back(UniformBlock(block->name().c_str(), block->hasInstanceName() ? block->instanceName().c_str() : std::string(), dataSize,
block->arraySize(), block->blockStorage(), block->matrixPacking() == EmpRowMajor, offset, blockId));
block->arraySize(), block->blockStorage(), block->matrixPacking() == EmpRowMajor, registerIndex, blockId));
}
if(!structure && !block)
......@@ -2423,13 +2423,13 @@ namespace glsl
{
shaderObject->activeUniformBlocks[blockId].fields.push_back(activeUniforms.size());
}
activeUniforms.push_back(Uniform(glVariableType(type), glVariablePrecision(type), name.c_str(), type.getArraySize(), offset, blockId));
activeUniforms.push_back(Uniform(glVariableType(type), glVariablePrecision(type), name.c_str(), type.getArraySize(), registerIndex, offset, blockId));
if(isSamplerRegister(type))
{
for(int i = 0; i < type.totalRegisterCount(); i++)
{
shader->declareSampler(offset + i);
shader->declareSampler(registerIndex + i);
}
}
}
......@@ -2438,28 +2438,30 @@ namespace glsl
const TFieldList& fields = structure ? structure->fields() : block->fields();
const bool containerHasName = structure || block->hasInstanceName();
const TString &containerName = structure ? name : (containerHasName ? block->instanceName() : TString());
if(type.isArray())
if(type.isArray() && (structure || type.isInterfaceBlock()))
{
int elementOffset = offset;
int fieldRegisterIndex = (blockId == -1) ? registerIndex : 0;
int fieldOffset = 0;
for(int i = 0; i < type.getArraySize(); i++)
{
int fieldOffset = (blockId == -1) ? elementOffset : 0;
for(size_t j = 0; j < fields.size(); j++)
{
const TType &fieldType = *(fields[j]->type());
const TString &fieldName = fields[j]->name();
const TString uniformName = containerHasName ? containerName + "[" + str(i) + "]." + fieldName : fieldName;
declareUniform(fieldType, uniformName, fieldOffset, blockId);
fieldOffset += fieldType.totalRegisterCount();
declareUniform(fieldType, uniformName, fieldRegisterIndex, fieldOffset, blockId);
int registerCount = fieldType.totalRegisterCount();
fieldRegisterIndex += registerCount;
fieldOffset += registerCount * fieldType.registerSize();
}
elementOffset = fieldOffset;
}
}
else
{
int fieldOffset = (blockId == -1) ? offset : 0;
int fieldRegisterIndex = (blockId == -1) ? registerIndex : 0;
int fieldOffset = 0;
for(size_t i = 0; i < fields.size(); i++)
{
......@@ -2467,8 +2469,10 @@ namespace glsl
const TString &fieldName = fields[i]->name();
const TString uniformName = containerHasName ? containerName + "." + fieldName : fieldName;
declareUniform(fieldType, uniformName, fieldOffset, blockId);
fieldOffset += fieldType.totalRegisterCount();
declareUniform(fieldType, uniformName, fieldRegisterIndex, fieldOffset, blockId);
int registerCount = fieldType.totalRegisterCount();
fieldRegisterIndex += registerCount;
fieldOffset += registerCount * fieldType.registerSize();
}
}
}
......
......@@ -32,7 +32,7 @@ namespace glsl
{
struct Uniform
{
Uniform(GLenum type, GLenum precision, const std::string &name, int arraySize, int registerIndex, int blockId);
Uniform(GLenum type, GLenum precision, const std::string &name, int arraySize, int registerIndex, int offset, int blockId);
GLenum type;
GLenum precision;
......@@ -40,6 +40,7 @@ namespace glsl
int arraySize;
int registerIndex;
int offset;
int blockId;
};
......@@ -205,7 +206,7 @@ namespace glsl
int allocate(VariableArray &list, TIntermTyped *variable);
void free(VariableArray &list, TIntermTyped *variable);
void declareUniform(const TType &type, const TString &name, int offset, int blockId = -1);
void declareUniform(const TType &type, const TString &name, int registerIndex, int offset = 0, int blockId = -1);
GLenum glVariableType(const TType &type);
GLenum glVariablePrecision(const TType &type);
......
......@@ -15,6 +15,7 @@
#include "Program.h"
#include "main.h"
#include "Buffer.h"
#include "Shader.h"
#include "utilities.h"
#include "common/debug.h"
......@@ -37,14 +38,28 @@ namespace es2
Uniform::BlockInfo::BlockInfo(const glsl::Uniform& uniform, int blockIndex, bool rowMajorLayout)
{
static unsigned int registerSizeStd140 = 4; // std140 packing requires dword alignment
if(blockIndex >= 0)
{
index = blockIndex;
offset = uniform.registerIndex;
arrayStride = UniformTypeSize(uniform.type) * uniform.arraySize;
offset = uniform.offset * registerSizeStd140;
isRowMajorMatrix = rowMajorLayout;
int componentSize = UniformTypeSize(UniformComponentType(uniform.type));
int rowCount = VariableRowCount(uniform.type);
matrixStride = (rowCount > 1) ? (isRowMajorMatrix ? rowCount : VariableColumnCount(uniform.type)) * UniformTypeSize(UniformComponentType(uniform.type)) : 0;
if(rowCount > 1)
{
int colCount = VariableColumnCount(uniform.type);
int matrixComponentCount = (isRowMajorMatrix ? colCount : rowCount);
matrixStride = (rowCount > 1) ? matrixComponentCount * componentSize : 0;
arrayStride = (uniform.arraySize > 0) ? matrixStride * (isRowMajorMatrix ? rowCount : colCount) : 0;
}
else
{
matrixStride = 0;
int componentCount = UniformComponentCount(uniform.type);
arrayStride = (uniform.arraySize > 0) ? componentSize * componentCount : 0;
}
}
else
{
......@@ -1691,7 +1706,7 @@ namespace es2
std::vector<unsigned int> memberUniformIndexes;
for(size_t i = 0; i < fields.size(); ++i)
{
memberUniformIndexes.push_back(activeUniforms[fields[i]].registerIndex);
memberUniformIndexes.push_back(fields[i]);
}
if(block.arraySize > 0)
......
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