Skip to content

Commit

Permalink
Vulkan: No inactive samplers left to cleanup in glslang wrapper
Browse files Browse the repository at this point in the history
Loose inactive samplers are already removed in
RemoveInactiveInterfaceVariables.  In-struct samplers are always marked
active by CollectVariables if the uniform is active.  If the uniform is
inactive, it is removed entirely by the translator.  Thus no inactive
samplers are left for glslang wrapper to clean up.

Bug: angleproject:3394
Change-Id: Ic0fef052afa992bd612fd22ffa1e5b9aa72a17bc
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1999488
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
  • Loading branch information
ShabbyX authored and Commit Bot committed Jan 24, 2020
1 parent 8dfe472 commit f3b4e6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
4 changes: 3 additions & 1 deletion src/compiler/translator/TranslatorVulkan.cpp
Expand Up @@ -730,7 +730,9 @@ bool TranslatorVulkan::translateImpl(TIntermBlock *root,

// Remove declarations of inactive shader interface variables so glslang wrapper doesn't need to
// replace them. Note: this is done before extracting samplers from structs, as removing such
// inactive samplers is not yet supported.
// inactive samplers is not yet supported. Note also that currently, CollectVariables marks
// every field of an active uniform that's of struct type as active, i.e. no extracted sampler
// is inactive.
if (!RemoveInactiveInterfaceVariables(this, root, getUniforms(), getInterfaceBlocks()))
{
return false;
Expand Down
40 changes: 5 additions & 35 deletions src/libANGLE/renderer/glslang_wrapper_utils.cpp
Expand Up @@ -845,22 +845,14 @@ void AssignUniformBindings(const GlslangSourceOptions &options,
void AssignResourceBinding(gl::ShaderBitSet activeShaders,
const std::string &name,
const std::string &bindingString,
bool eraseLayoutIfInactive,
gl::ShaderMap<IntermediateShaderSource> *shaderSources)
{
for (const gl::ShaderType shaderType : gl::AllShaderTypes())
{
IntermediateShaderSource &shaderSource = (*shaderSources)[shaderType];
if (!shaderSource.empty())
if (activeShaders[shaderType] && !shaderSource.empty())
{
if (activeShaders[shaderType])
{
shaderSource.insertLayoutSpecifier(name, bindingString);
}
else if (eraseLayoutIfInactive)
{
shaderSource.eraseLayoutAndQualifierSpecifiers(name, kInactiveVariableSubstitution);
}
shaderSource.insertLayoutSpecifier(name, bindingString);
}
}
}
Expand All @@ -881,8 +873,7 @@ uint32_t AssignInterfaceBlockBindings(const GlslangSourceOptions &options,
const std::string bindingString =
resourcesDescriptorSet + ", binding = " + Str(bindingIndex++);

AssignResourceBinding(block.activeShaders(), block.name, bindingString, false,
shaderSources);
AssignResourceBinding(block.activeShaders(), block.name, bindingString, shaderSources);
}
}

Expand Down Expand Up @@ -938,8 +929,7 @@ uint32_t AssignImageBindings(const GlslangSourceOptions &options,
name = name.substr(0, name.find('['));
}

AssignResourceBinding(imageUniform.activeShaders(), name, bindingString, false,
shaderSources);
AssignResourceBinding(imageUniform.activeShaders(), name, bindingString, shaderSources);
}

return bindingIndex;
Expand Down Expand Up @@ -998,7 +988,7 @@ void AssignTextureBindings(const GlslangSourceOptions &options,
? GetMappedSamplerNameOld(samplerUniform.name)
: GlslangGetMappedSamplerName(samplerUniform.name);

AssignResourceBinding(samplerUniform.activeShaders(), samplerName, bindingString, true,
AssignResourceBinding(samplerUniform.activeShaders(), samplerName, bindingString,
shaderSources);
}
}
Expand Down Expand Up @@ -1037,26 +1027,6 @@ void CleanupUnusedEntities(bool useOldRewriteStructSamplers,
shaderSource.eraseLayoutAndQualifierSpecifiers(varyingName, "");
}
}

// Comment out inactive samplers. This relies on the fact that the shader compiler outputs
// uniforms to a single line.
for (const gl::UnusedUniform &unusedUniform : resources.unusedUniforms)
{
if (!unusedUniform.isSampler)
{
continue;
}

std::string uniformName = useOldRewriteStructSamplers
? GetMappedSamplerNameOld(unusedUniform.name)
: GlslangGetMappedSamplerName(unusedUniform.name);

for (IntermediateShaderSource &shaderSource : *shaderSources)
{
shaderSource.eraseLayoutAndQualifierSpecifiers(uniformName,
kInactiveVariableSubstitution);
}
}
}

constexpr gl::ShaderMap<EShLanguage> kShLanguageMap = {
Expand Down

0 comments on commit f3b4e6c

Please sign in to comment.