summaryrefslogtreecommitdiffstats
path: root/src/plugins/renderers/rhi/renderer/rhishader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/renderers/rhi/renderer/rhishader.cpp')
-rw-r--r--src/plugins/renderers/rhi/renderer/rhishader.cpp52
1 files changed, 34 insertions, 18 deletions
diff --git a/src/plugins/renderers/rhi/renderer/rhishader.cpp b/src/plugins/renderers/rhi/renderer/rhishader.cpp
index 5684e27ce..6509746ab 100644
--- a/src/plugins/renderers/rhi/renderer/rhishader.cpp
+++ b/src/plugins/renderers/rhi/renderer/rhishader.cpp
@@ -332,7 +332,14 @@ void RHIShader::recordAllUniforms(UBO_Member &uboMember,
// We iterate through all the [l][n][m] by building [0][0][0] and incrementing
forEachArrayAccessor(member.arrayDims, [&](const QString &str) {
// "foo.bar[1][2]"
- m_unqualifiedUniformNames << (fullMemberName + str);
+ const QString unqualifiedMemberName = (fullMemberName + str);
+ m_unqualifiedUniformNames << unqualifiedMemberName;
+
+ // Record as an individual uniform
+ m_uniformsNames.push_back(unqualifiedMemberName);
+ const int nameId = StringToInt::lookupId(unqualifiedMemberName);
+ m_uniformsNamesIds.push_back(nameId);
+
// Question : does it make sense to also record foo[0], foo[0][0], etc...
// if there are e.g. 3 dimensions ?
});
@@ -344,20 +351,29 @@ void RHIShader::recordAllUniforms(UBO_Member &uboMember,
m_structNamesIds.push_back(StringToInt::lookupId(m_structNames.back()));
});
- // Record the struct members
- for (const QShaderDescription::BlockVariable& bv : member.structMembers) {
- forEachArrayAccessor(member.arrayDims, [&] (const QString& str) {
+ // Record the array times the struct members => entry[i].struct_member
+ forEachArrayAccessor(member.arrayDims, [&] (const QString& str) {
+ UBO_Member arrayMember {StringToInt::lookupId(fullMemberName + str), {}, {}};
+ // Record all struct member into the array member[i]
+ for (const QShaderDescription::BlockVariable& bv : member.structMembers) {
//recordAllUniforms("baz", "foo.bar[1][2].")
const QString structMemberNamePrefix = fullMemberName + str + QLatin1Char('.');
UBO_Member innerMember {StringToInt::lookupId(structMemberNamePrefix), bv, {}};
recordAllUniforms(innerMember, structMemberNamePrefix);
- uboMember.structMembers.push_back(innerMember);
- });
- }
+ arrayMember.structMembers.push_back(innerMember);
+ }
+ // When dealing with an array of structs, we treat structMembers as arrayMembers
+ uboMember.structMembers.push_back(arrayMember);
+ });
} else {
// Final member (not array or struct)
// Replace nameId with final nameId name
uboMember.nameId = StringToInt::lookupId(fullMemberName);
+
+ // Record as an individual uniform
+ m_uniformsNames.push_back(fullMemberName);
+ const int nameId = StringToInt::lookupId(fullMemberName);
+ m_uniformsNamesIds.push_back(nameId);
}
}
@@ -492,7 +508,7 @@ QHash<QString, ShaderUniform> RHIShader::activeUniformsForUniformBlock(int block
ShaderUniformBlock RHIShader::uniformBlockForBlockIndex(int blockIndex) const noexcept
{
- for (int i = 0, m = m_uniformBlocks.size(); i < m; ++i) {
+ for (size_t i = 0, m = m_uniformBlocks.size(); i < m; ++i) {
if (m_uniformBlocks[i].m_index == blockIndex) {
return m_uniformBlocks[i];
}
@@ -502,7 +518,7 @@ ShaderUniformBlock RHIShader::uniformBlockForBlockIndex(int blockIndex) const no
ShaderUniformBlock RHIShader::uniformBlockForBlockNameId(int blockNameId) const noexcept
{
- for (int i = 0, m = m_uniformBlocks.size(); i < m; ++i) {
+ for (size_t i = 0, m = m_uniformBlocks.size(); i < m; ++i) {
if (m_uniformBlocks[i].m_nameId == blockNameId) {
return m_uniformBlocks[i];
}
@@ -512,7 +528,7 @@ ShaderUniformBlock RHIShader::uniformBlockForBlockNameId(int blockNameId) const
ShaderUniformBlock RHIShader::uniformBlockForBlockName(const QString &blockName) const noexcept
{
- for (int i = 0, m = m_uniformBlocks.size(); i < m; ++i) {
+ for (size_t i = 0, m = m_uniformBlocks.size(); i < m; ++i) {
if (m_uniformBlocks[i].m_name == blockName) {
return m_uniformBlocks[i];
}
@@ -539,7 +555,7 @@ ShaderUniformBlock RHIShader::uniformBlockForInstanceNameId(int instanceNameId)
ShaderStorageBlock RHIShader::storageBlockForBlockIndex(int blockIndex) const noexcept
{
- for (int i = 0, m = m_shaderStorageBlockNames.size(); i < m; ++i) {
+ for (size_t i = 0, m = m_shaderStorageBlockNames.size(); i < m; ++i) {
if (m_shaderStorageBlocks[i].m_index == blockIndex)
return m_shaderStorageBlocks[i];
}
@@ -548,7 +564,7 @@ ShaderStorageBlock RHIShader::storageBlockForBlockIndex(int blockIndex) const no
ShaderStorageBlock RHIShader::storageBlockForBlockNameId(int blockNameId) const noexcept
{
- for (int i = 0, m = m_shaderStorageBlockNames.size(); i < m; ++i) {
+ for (size_t i = 0, m = m_shaderStorageBlockNames.size(); i < m; ++i) {
if (m_shaderStorageBlocks[i].m_nameId == blockNameId)
return m_shaderStorageBlocks[i];
}
@@ -557,7 +573,7 @@ ShaderStorageBlock RHIShader::storageBlockForBlockNameId(int blockNameId) const
ShaderStorageBlock RHIShader::storageBlockForBlockName(const QString &blockName) const noexcept
{
- for (int i = 0, m = m_shaderStorageBlockNames.size(); i < m; ++i) {
+ for (size_t i = 0, m = m_shaderStorageBlockNames.size(); i < m; ++i) {
if (m_shaderStorageBlocks[i].m_name == blockName)
return m_shaderStorageBlocks[i];
}
@@ -612,7 +628,7 @@ void RHIShader::initializeAttributes(const std::vector<ShaderAttribute> &attribu
m_attributes = attributesDescription;
m_attributesNames.resize(attributesDescription.size());
m_attributeNamesIds.resize(attributesDescription.size());
- for (int i = 0, m = attributesDescription.size(); i < m; i++) {
+ for (size_t i = 0, m = attributesDescription.size(); i < m; i++) {
m_attributesNames[i] = attributesDescription[i].m_name;
m_attributes[i].m_nameId = StringToInt::lookupId(m_attributesNames[i]);
m_attributeNamesIds[i] = m_attributes[i].m_nameId;
@@ -625,7 +641,7 @@ void RHIShader::initializeSamplers(const std::vector<ShaderAttribute> &samplersD
m_samplers = samplersDescription;
m_samplerNames.resize(samplersDescription.size());
m_samplerIds.resize(samplersDescription.size());
- for (int i = 0, m = samplersDescription.size(); i < m; i++) {
+ for (size_t i = 0, m = samplersDescription.size(); i < m; i++) {
m_samplerNames[i] = samplersDescription[i].m_name;
m_samplers[i].m_nameId = StringToInt::lookupId(m_samplerNames[i]);
m_samplerIds[i] = m_samplers[i].m_nameId;
@@ -638,7 +654,7 @@ void RHIShader::initializeImages(const std::vector<ShaderAttribute> &imagesDescr
m_images = imagesDescription;
m_imageNames.resize(imagesDescription.size());
m_imageIds.resize(imagesDescription.size());
- for (int i = 0, m = imagesDescription.size(); i < m; i++) {
+ for (size_t i = 0, m = imagesDescription.size(); i < m; i++) {
m_imageNames[i] = imagesDescription[i].m_name;
m_images[i].m_nameId = StringToInt::lookupId(m_imageNames[i]);
m_imageIds[i] = m_images[i].m_nameId;
@@ -651,7 +667,7 @@ void RHIShader::initializeUniformBlocks(const std::vector<ShaderUniformBlock> &u
m_uniformBlocks = uniformBlockDescription;
m_uniformBlockNames.resize(uniformBlockDescription.size());
m_uniformBlockNamesIds.resize(uniformBlockDescription.size());
- for (int i = 0, m = uniformBlockDescription.size(); i < m; ++i) {
+ for (size_t i = 0, m = uniformBlockDescription.size(); i < m; ++i) {
m_uniformBlockNames[i] = m_uniformBlocks[i].m_name;
m_uniformBlockNamesIds[i] = StringToInt::lookupId(m_uniformBlockNames[i]);
m_uniformBlocks[i].m_nameId = m_uniformBlockNamesIds[i];
@@ -692,7 +708,7 @@ void RHIShader::initializeShaderStorageBlocks(
m_shaderStorageBlockNames.resize(shaderStorageBlockDescription.size());
m_shaderStorageBlockNamesIds.resize(shaderStorageBlockDescription.size());
- for (int i = 0, m = shaderStorageBlockDescription.size(); i < m; ++i) {
+ for (size_t i = 0, m = shaderStorageBlockDescription.size(); i < m; ++i) {
m_shaderStorageBlockNames[i] = m_shaderStorageBlocks[i].m_name;
m_shaderStorageBlockNamesIds[i] = StringToInt::lookupId(m_shaderStorageBlockNames[i]);
m_shaderStorageBlocks[i].m_nameId = m_shaderStorageBlockNamesIds[i];