mirror of
https://github.com/godotengine/godot-angle-static.git
synced 2026-01-06 02:09:55 +03:00
Embed ActiveVariable into BufferVariable and ShaderVariableBuffer
This CL embeds ActiveVariable into BufferVariable and ShaderVariableBuffer struct instead of subclass. This allows us to remove the virtual function of ~ActiveVariable(), which means ActiveVariable is a simple struct with basic types and memcpy can be used for load/save. Thus, in this CL, I also moved activeVariables to LinkedUniform::mFixedSizeData structure and let memcpy handle the load/save. Bug: b/275102061 Change-Id: I8d21080cfdd72d4d22cef927d136ca428d9b12e4 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4722265 Reviewed-by: Roman Lavrov <romanl@google.com> Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
This commit is contained in:
committed by
Angle LUCI CQ
parent
ee019f5809
commit
22438ad8e2
@@ -425,7 +425,7 @@ void LoadActiveVariable(BinaryInputStream *stream, ActiveVariable *var)
|
||||
|
||||
void WriteShaderVariableBuffer(BinaryOutputStream *stream, const ShaderVariableBuffer &var)
|
||||
{
|
||||
WriteActiveVariable(stream, var);
|
||||
WriteActiveVariable(stream, var.activeVariable);
|
||||
|
||||
stream->writeInt(var.binding);
|
||||
stream->writeInt(var.dataSize);
|
||||
@@ -439,7 +439,7 @@ void WriteShaderVariableBuffer(BinaryOutputStream *stream, const ShaderVariableB
|
||||
|
||||
void LoadShaderVariableBuffer(BinaryInputStream *stream, ShaderVariableBuffer *var)
|
||||
{
|
||||
LoadActiveVariable(stream, var);
|
||||
LoadActiveVariable(stream, &var->activeVariable);
|
||||
|
||||
var->binding = stream->readInt<int>();
|
||||
var->dataSize = stream->readInt<unsigned int>();
|
||||
@@ -454,7 +454,7 @@ void LoadShaderVariableBuffer(BinaryInputStream *stream, ShaderVariableBuffer *v
|
||||
void WriteBufferVariable(BinaryOutputStream *stream, const BufferVariable &var)
|
||||
{
|
||||
WriteShaderVar(stream, var);
|
||||
WriteActiveVariable(stream, var);
|
||||
WriteActiveVariable(stream, var.activeVariable);
|
||||
|
||||
stream->writeInt(var.bufferIndex);
|
||||
WriteBlockMemberInfo(stream, var.blockInfo);
|
||||
@@ -464,7 +464,7 @@ void WriteBufferVariable(BinaryOutputStream *stream, const BufferVariable &var)
|
||||
void LoadBufferVariable(BinaryInputStream *stream, BufferVariable *var)
|
||||
{
|
||||
LoadShaderVar(stream, var);
|
||||
LoadActiveVariable(stream, var);
|
||||
LoadActiveVariable(stream, &(var->activeVariable));
|
||||
|
||||
var->bufferIndex = stream->readInt<int>();
|
||||
LoadBlockMemberInfo(stream, &var->blockInfo);
|
||||
|
||||
@@ -1652,7 +1652,7 @@ bool ProgramExecutable::linkAtomicCounterBuffers(const Context *context, InfoLog
|
||||
buffer.memberIndexes.push_back(index);
|
||||
uniform.setBufferIndex(bufferIndex);
|
||||
found = true;
|
||||
buffer.unionReferencesWith(uniform.activeVariable);
|
||||
buffer.unionReferencesWith(uniform.getActiveVariable());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1661,7 +1661,7 @@ bool ProgramExecutable::linkAtomicCounterBuffers(const Context *context, InfoLog
|
||||
AtomicCounterBuffer atomicCounterBuffer;
|
||||
atomicCounterBuffer.binding = uniform.getBinding();
|
||||
atomicCounterBuffer.memberIndexes.push_back(index);
|
||||
atomicCounterBuffer.unionReferencesWith(uniform.activeVariable);
|
||||
atomicCounterBuffer.unionReferencesWith(uniform.getActiveVariable());
|
||||
mAtomicCounterBuffers.push_back(atomicCounterBuffer);
|
||||
uniform.setBufferIndex(static_cast<int>(getActiveAtomicCounterBufferCount() - 1));
|
||||
}
|
||||
|
||||
@@ -123,23 +123,22 @@ LinkedUniform::LinkedUniform(const UsedUniform &usedUniform)
|
||||
mFixedSizeData.blockInfo = usedUniform.blockInfo;
|
||||
mFixedSizeData.outerArraySizeProduct = ArraySizeProduct(usedUniform.outerArraySizes);
|
||||
mFixedSizeData.outerArrayOffset = usedUniform.outerArrayOffset;
|
||||
mFixedSizeData.activeVariable = usedUniform.activeVariable;
|
||||
|
||||
name = usedUniform.name;
|
||||
mappedName = usedUniform.mappedName;
|
||||
arraySizes = usedUniform.arraySizes;
|
||||
activeVariable = usedUniform.activeVariable;
|
||||
typeInfo = usedUniform.typeInfo;
|
||||
name = usedUniform.name;
|
||||
mappedName = usedUniform.mappedName;
|
||||
arraySizes = usedUniform.arraySizes;
|
||||
typeInfo = usedUniform.typeInfo;
|
||||
}
|
||||
|
||||
LinkedUniform &LinkedUniform::operator=(const LinkedUniform &other)
|
||||
{
|
||||
mFixedSizeData = other.mFixedSizeData;
|
||||
|
||||
name = other.name;
|
||||
mappedName = other.mappedName;
|
||||
arraySizes = other.arraySizes;
|
||||
activeVariable = other.activeVariable;
|
||||
typeInfo = other.typeInfo;
|
||||
name = other.name;
|
||||
mappedName = other.mappedName;
|
||||
arraySizes = other.arraySizes;
|
||||
typeInfo = other.typeInfo;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -156,13 +155,6 @@ void LinkedUniform::save(BinaryOutputStream *stream) const
|
||||
stream->writeString(name);
|
||||
stream->writeString(mappedName);
|
||||
stream->writeIntVector(arraySizes);
|
||||
|
||||
// Active shader info
|
||||
for (ShaderType shaderType : gl::AllShaderTypes())
|
||||
{
|
||||
stream->writeBool(isActive(shaderType));
|
||||
stream->writeInt(isActive(shaderType) ? getIds()[shaderType] : 0);
|
||||
}
|
||||
}
|
||||
|
||||
void LinkedUniform::load(BinaryInputStream *stream)
|
||||
@@ -176,13 +168,6 @@ void LinkedUniform::load(BinaryInputStream *stream)
|
||||
stream->readIntVector<unsigned int>(&arraySizes);
|
||||
|
||||
typeInfo = &GetUniformTypeInfo(getType());
|
||||
// Active shader info
|
||||
for (ShaderType shaderType : gl::AllShaderTypes())
|
||||
{
|
||||
const bool isActive = stream->readBool();
|
||||
const uint32_t id = stream->readInt<uint32_t>();
|
||||
setActive(shaderType, isActive, id);
|
||||
}
|
||||
}
|
||||
|
||||
BufferVariable::BufferVariable()
|
||||
|
||||
@@ -24,11 +24,14 @@ class BinaryOutputStream;
|
||||
struct UniformTypeInfo;
|
||||
struct UsedUniform;
|
||||
|
||||
// Note: keep this struct memcpy-able: i.e, a simple struct with basic types only and no virtual
|
||||
// functions. LinkedUniform relies on this so that it can use memcpy to initialize uniform for
|
||||
// performance.
|
||||
struct ActiveVariable
|
||||
{
|
||||
ActiveVariable();
|
||||
ActiveVariable(const ActiveVariable &rhs);
|
||||
virtual ~ActiveVariable();
|
||||
~ActiveVariable();
|
||||
|
||||
ActiveVariable &operator=(const ActiveVariable &rhs);
|
||||
|
||||
@@ -140,17 +143,24 @@ struct LinkedUniform
|
||||
|
||||
ShaderType getFirstActiveShaderType() const
|
||||
{
|
||||
return activeVariable.getFirstActiveShaderType();
|
||||
return mFixedSizeData.activeVariable.getFirstActiveShaderType();
|
||||
}
|
||||
void setActive(ShaderType shaderType, bool used, uint32_t _id)
|
||||
{
|
||||
activeVariable.setActive(shaderType, used, _id);
|
||||
mFixedSizeData.activeVariable.setActive(shaderType, used, _id);
|
||||
}
|
||||
bool isActive(ShaderType shaderType) const { return activeVariable.isActive(shaderType); }
|
||||
const ShaderMap<uint32_t> &getIds() const { return activeVariable.getIds(); }
|
||||
uint32_t getId(ShaderType shaderType) const { return activeVariable.getId(shaderType); }
|
||||
ShaderBitSet activeShaders() const { return activeVariable.activeShaders(); }
|
||||
GLuint activeShaderCount() const { return activeVariable.activeShaderCount(); }
|
||||
bool isActive(ShaderType shaderType) const
|
||||
{
|
||||
return mFixedSizeData.activeVariable.isActive(shaderType);
|
||||
}
|
||||
const ShaderMap<uint32_t> &getIds() const { return mFixedSizeData.activeVariable.getIds(); }
|
||||
uint32_t getId(ShaderType shaderType) const
|
||||
{
|
||||
return mFixedSizeData.activeVariable.getId(shaderType);
|
||||
}
|
||||
ShaderBitSet activeShaders() const { return mFixedSizeData.activeVariable.activeShaders(); }
|
||||
GLuint activeShaderCount() const { return mFixedSizeData.activeVariable.activeShaderCount(); }
|
||||
const ActiveVariable &getActiveVariable() const { return mFixedSizeData.activeVariable; }
|
||||
|
||||
void save(BinaryOutputStream *stream) const;
|
||||
void load(BinaryInputStream *stream);
|
||||
@@ -161,8 +171,6 @@ struct LinkedUniform
|
||||
|
||||
std::vector<unsigned int> arraySizes;
|
||||
|
||||
ActiveVariable activeVariable;
|
||||
|
||||
const UniformTypeInfo *typeInfo;
|
||||
|
||||
private:
|
||||
@@ -182,6 +190,7 @@ struct LinkedUniform
|
||||
sh::BlockMemberInfo blockInfo;
|
||||
unsigned int outerArraySizeProduct;
|
||||
unsigned int outerArrayOffset;
|
||||
ActiveVariable activeVariable;
|
||||
|
||||
union
|
||||
{
|
||||
@@ -203,7 +212,7 @@ struct LinkedUniform
|
||||
} mFixedSizeData;
|
||||
};
|
||||
|
||||
struct BufferVariable : public sh::ShaderVariable, public ActiveVariable
|
||||
struct BufferVariable : public sh::ShaderVariable
|
||||
{
|
||||
BufferVariable();
|
||||
BufferVariable(GLenum type,
|
||||
@@ -212,8 +221,17 @@ struct BufferVariable : public sh::ShaderVariable, public ActiveVariable
|
||||
const std::vector<unsigned int> &arraySizes,
|
||||
const int bufferIndex,
|
||||
const sh::BlockMemberInfo &blockInfo);
|
||||
~BufferVariable() override;
|
||||
~BufferVariable();
|
||||
|
||||
void setActive(ShaderType shaderType, bool used, uint32_t _id)
|
||||
{
|
||||
activeVariable.setActive(shaderType, used, _id);
|
||||
}
|
||||
bool isActive(ShaderType shaderType) const { return activeVariable.isActive(shaderType); }
|
||||
uint32_t getId(ShaderType shaderType) const { return activeVariable.getId(shaderType); }
|
||||
ShaderBitSet activeShaders() const { return activeVariable.activeShaders(); }
|
||||
|
||||
ActiveVariable activeVariable;
|
||||
int bufferIndex;
|
||||
sh::BlockMemberInfo blockInfo;
|
||||
|
||||
@@ -222,13 +240,31 @@ struct BufferVariable : public sh::ShaderVariable, public ActiveVariable
|
||||
|
||||
// Parent struct for atomic counter, uniform block, and shader storage block buffer, which all
|
||||
// contain a group of shader variables, and have a GL buffer backed.
|
||||
struct ShaderVariableBuffer : public ActiveVariable
|
||||
struct ShaderVariableBuffer
|
||||
{
|
||||
ShaderVariableBuffer();
|
||||
ShaderVariableBuffer(const ShaderVariableBuffer &other);
|
||||
~ShaderVariableBuffer() override;
|
||||
~ShaderVariableBuffer();
|
||||
|
||||
ShaderType getFirstActiveShaderType() const
|
||||
{
|
||||
return activeVariable.getFirstActiveShaderType();
|
||||
}
|
||||
void setActive(ShaderType shaderType, bool used, uint32_t _id)
|
||||
{
|
||||
activeVariable.setActive(shaderType, used, _id);
|
||||
}
|
||||
void unionReferencesWith(const ActiveVariable &other)
|
||||
{
|
||||
activeVariable.unionReferencesWith(other);
|
||||
}
|
||||
bool isActive(ShaderType shaderType) const { return activeVariable.isActive(shaderType); }
|
||||
const ShaderMap<uint32_t> &getIds() const { return activeVariable.getIds(); }
|
||||
uint32_t getId(ShaderType shaderType) const { return activeVariable.getId(shaderType); }
|
||||
ShaderBitSet activeShaders() const { return activeVariable.activeShaders(); }
|
||||
int numActiveVariables() const;
|
||||
|
||||
ActiveVariable activeVariable;
|
||||
int binding;
|
||||
unsigned int dataSize;
|
||||
std::vector<unsigned int> memberIndexes;
|
||||
|
||||
@@ -1022,7 +1022,7 @@ void SerializeBufferVariablesVector(JsonSerializer *json,
|
||||
json->addScalar("BufferIndex", bufferVariable.bufferIndex);
|
||||
SerializeBlockMemberInfo(json, bufferVariable.blockInfo);
|
||||
json->addScalar("TopLevelArraySize", bufferVariable.topLevelArraySize);
|
||||
SerializeActiveVariable(json, bufferVariable);
|
||||
SerializeActiveVariable(json, bufferVariable.activeVariable);
|
||||
SerializeShaderVariable(json, bufferVariable);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user