Commit e17b5ba5 by Luc Ferron Committed by Commit Bot

Vulkan: Keep unused uniforms list to fix glslang issues

We we're unable to cleanup the unused uniforms if we did not keep a list of them while parsing them in ProgramLinkResource. Now that we keep a history of them, we're able to clean them up and fix a few dEQP tests. Bug: angleproject:2582 Bug: angleproject:2585 Bug: angleproject:2587 Bug: angleproject:2589 Bug: angleproject:2590 Bug: angleproject:2593 Change-Id: Ic1f9151e356a3d05e83f1031cc7b187b370284e5 Reviewed-on: https://chromium-review.googlesource.com/1085644 Commit-Queue: Luc Ferron <lucferron@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 45b5a875
......@@ -1096,8 +1096,16 @@ Error Program::link(const gl::Context *context)
if (mState.mAttachedShaders[ShaderType::Compute])
{
ProgramLinkedResources resources = {
{0, PackMode::ANGLE_RELAXED},
{&mState.mUniformBlocks, &mState.mUniforms},
{&mState.mShaderStorageBlocks, &mState.mBufferVariables},
{&mState.mAtomicCounterBuffers},
{}};
GLuint combinedImageUniforms = 0u;
if (!linkUniforms(context, mInfoLog, mUniformLocationBindings, &combinedImageUniforms))
if (!linkUniforms(context, mInfoLog, mUniformLocationBindings, &combinedImageUniforms,
&resources.unusedUniforms))
{
return NoError();
}
......@@ -1124,12 +1132,6 @@ Error Program::link(const gl::Context *context)
return NoError();
}
ProgramLinkedResources resources = {
{0, PackMode::ANGLE_RELAXED},
{&mState.mUniformBlocks, &mState.mUniforms},
{&mState.mShaderStorageBlocks, &mState.mBufferVariables},
{&mState.mAtomicCounterBuffers}};
InitUniformBlockLinker(context, mState, &resources.uniformBlockLinker);
InitShaderStorageBlockLinker(context, mState, &resources.shaderStorageBlockLinker);
......@@ -1141,6 +1143,26 @@ Error Program::link(const gl::Context *context)
}
else
{
// Map the varyings to the register file
// In WebGL, we use a slightly different handling for packing variables.
gl::PackMode packMode = PackMode::ANGLE_RELAXED;
if (data.getLimitations().noFlexibleVaryingPacking)
{
// D3D9 pack mode is strictly more strict than WebGL, so takes priority.
packMode = PackMode::ANGLE_NON_CONFORMANT_D3D9;
}
else if (data.getExtensions().webglCompatibility)
{
packMode = PackMode::WEBGL_STRICT;
}
ProgramLinkedResources resources = {
{data.getCaps().maxVaryingVectors, packMode},
{&mState.mUniformBlocks, &mState.mUniforms},
{&mState.mShaderStorageBlocks, &mState.mBufferVariables},
{&mState.mAtomicCounterBuffers},
{}};
if (!linkAttributes(context, mInfoLog))
{
return NoError();
......@@ -1152,7 +1174,8 @@ Error Program::link(const gl::Context *context)
}
GLuint combinedImageUniforms = 0u;
if (!linkUniforms(context, mInfoLog, mUniformLocationBindings, &combinedImageUniforms))
if (!linkUniforms(context, mInfoLog, mUniformLocationBindings, &combinedImageUniforms,
&resources.unusedUniforms))
{
return NoError();
}
......@@ -1178,25 +1201,6 @@ Error Program::link(const gl::Context *context)
ASSERT(mState.mAttachedShaders[ShaderType::Vertex]);
mState.mNumViews = mState.mAttachedShaders[ShaderType::Vertex]->getNumViews(context);
// Map the varyings to the register file
// In WebGL, we use a slightly different handling for packing variables.
gl::PackMode packMode = PackMode::ANGLE_RELAXED;
if (data.getLimitations().noFlexibleVaryingPacking)
{
// D3D9 pack mode is strictly more strict than WebGL, so takes priority.
packMode = PackMode::ANGLE_NON_CONFORMANT_D3D9;
}
else if (data.getExtensions().webglCompatibility)
{
packMode = PackMode::WEBGL_STRICT;
}
ProgramLinkedResources resources = {
{data.getCaps().maxVaryingVectors, packMode},
{&mState.mUniformBlocks, &mState.mUniforms},
{&mState.mShaderStorageBlocks, &mState.mBufferVariables},
{&mState.mAtomicCounterBuffers}};
InitUniformBlockLinker(context, mState, &resources.uniformBlockLinker);
InitShaderStorageBlockLinker(context, mState, &resources.shaderStorageBlockLinker);
......@@ -2558,7 +2562,8 @@ bool Program::linkValidateFragmentInputBindings(const Context *context, gl::Info
bool Program::linkUniforms(const Context *context,
InfoLog &infoLog,
const ProgramBindings &uniformLocationBindings,
GLuint *combinedImageUniformsCount)
GLuint *combinedImageUniformsCount,
std::vector<UnusedUniform> *unusedUniforms)
{
UniformLinker linker(mState);
if (!linker.link(context, infoLog, uniformLocationBindings))
......@@ -2566,7 +2571,7 @@ bool Program::linkUniforms(const Context *context,
return false;
}
linker.getResults(&mState.mUniforms, &mState.mUniformLocations);
linker.getResults(&mState.mUniforms, unusedUniforms, &mState.mUniformLocations);
linkSamplerAndImageBindings(combinedImageUniformsCount);
......
......@@ -40,6 +40,7 @@ struct TranslatedAttribute;
namespace gl
{
struct UnusedUniform;
struct Caps;
class Context;
class ContextState;
......@@ -747,7 +748,8 @@ class Program final : angle::NonCopyable, public LabeledObject
bool linkUniforms(const Context *context,
InfoLog &infoLog,
const ProgramBindings &uniformLocationBindings,
GLuint *combinedImageUniformsCount);
GLuint *combinedImageUniformsCount,
std::vector<UnusedUniform> *unusedUniforms);
void linkSamplerAndImageBindings(GLuint *combinedImageUniformsCount);
bool linkAtomicCounterBuffers();
......
......@@ -38,8 +38,9 @@ struct LinkedUniform;
class ProgramState;
class ProgramBindings;
class Shader;
struct VariableLocation;
struct ShaderVariableBuffer;
struct UnusedUniform;
struct VariableLocation;
using AtomicCounterBuffer = ShaderVariableBuffer;
......@@ -54,6 +55,7 @@ class UniformLinker final : angle::NonCopyable
const ProgramBindings &uniformLocationBindings);
void getResults(std::vector<LinkedUniform> *uniforms,
std::vector<UnusedUniform> *unusedUniforms,
std::vector<VariableLocation> *uniformLocations);
private:
......@@ -88,6 +90,7 @@ class UniformLinker final : angle::NonCopyable
std::vector<LinkedUniform> &samplerUniforms,
std::vector<LinkedUniform> &imageUniforms,
std::vector<LinkedUniform> &atomicCounterUniforms,
std::vector<UnusedUniform> &unusedUniforms,
InfoLog &infoLog);
bool flattenUniformsAndCheckCaps(const Context *context, InfoLog &infoLog);
......@@ -97,6 +100,7 @@ class UniformLinker final : angle::NonCopyable
std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms,
std::vector<UnusedUniform> *unusedUniforms,
ShaderType shaderType);
ShaderUniformCount flattenArrayOfStructsUniform(
......@@ -107,7 +111,7 @@ class UniformLinker final : angle::NonCopyable
std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms,
std::vector<UnusedUniform> *unusedUniforms,
ShaderType shaderType,
bool markActive,
bool markStaticUse,
......@@ -121,6 +125,7 @@ class UniformLinker final : angle::NonCopyable
std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms,
std::vector<UnusedUniform> *unusedUniforms,
ShaderType shaderType,
bool markActive,
bool markStaticUse,
......@@ -134,6 +139,7 @@ class UniformLinker final : angle::NonCopyable
std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms,
std::vector<UnusedUniform> *unusedUniforms,
ShaderType shaderType,
bool markActive,
bool markStaticUse,
......@@ -149,6 +155,7 @@ class UniformLinker final : angle::NonCopyable
std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms,
std::vector<UnusedUniform> *unusedUniforms,
ShaderType shaderType,
bool markActive,
bool markStaticUse,
......@@ -165,6 +172,7 @@ class UniformLinker final : angle::NonCopyable
const ProgramState &mState;
std::vector<LinkedUniform> mUniforms;
std::vector<UnusedUniform> mUnusedUniforms;
std::vector<VariableLocation> mUniformLocations;
};
......@@ -303,12 +311,25 @@ class AtomicCounterBufferLinker final : angle::NonCopyable
// The link operation is responsible for finishing the link of uniform and interface blocks.
// This way it can filter out unreferenced resources and still have access to the info.
// TODO(jmadill): Integrate uniform linking/filtering as well as interface blocks.
struct UnusedUniform
{
UnusedUniform(std::string name, bool isSampler)
{
this->name = name;
this->isSampler = isSampler;
}
std::string name;
bool isSampler;
};
struct ProgramLinkedResources
{
VaryingPacking varyingPacking;
UniformBlockLinker uniformBlockLinker;
ShaderStorageBlockLinker shaderStorageBlockLinker;
AtomicCounterBufferLinker atomicCounterBufferLinker;
std::vector<UnusedUniform> unusedUniforms;
};
} // namespace gl
......
......@@ -41,7 +41,7 @@ void InsertLayoutSpecifierString(std::string *shaderString,
searchStringBuilder << kLayoutMarkerBegin << variableName << kMarkerEnd;
std::string searchString = searchStringBuilder.str();
if (layoutString != "")
if (!layoutString.empty())
{
angle::ReplaceSubstring(shaderString, searchString, "layout(" + layoutString + ")");
}
......@@ -193,7 +193,6 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext,
for (unsigned int uniformIndex : programState.getSamplerUniformRange())
{
const gl::LinkedUniform &samplerUniform = uniforms[uniformIndex];
std::string setBindingString = "set = 1, binding = " + Str(textureCount);
ASSERT(samplerUniform.isActive(gl::ShaderType::Vertex) ||
......@@ -221,6 +220,16 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext,
textureCount += samplerUniform.getBasicTypeElementCount();
}
for (const gl::UnusedUniform &unusedUniform : resources.unusedUniforms)
{
InsertLayoutSpecifierString(&vertexSource, unusedUniform.name, "");
InsertLayoutSpecifierString(&fragmentSource, unusedUniform.name, "");
std::string qualifierToUse = unusedUniform.isSampler ? kUniformQualifier : "";
InsertQualifierSpecifierString(&vertexSource, unusedUniform.name, qualifierToUse);
InsertQualifierSpecifierString(&fragmentSource, unusedUniform.name, qualifierToUse);
}
std::array<const char *, 2> strings = {{vertexSource.c_str(), fragmentSource.c_str()}};
std::array<int, 2> lengths = {
{static_cast<int>(vertexSource.length()), static_cast<int>(fragmentSource.length())}};
......
......@@ -216,12 +216,6 @@
2580 VULKAN : dEQP-GLES2.functional.buffer.write.recreate_store.different_size = SKIP
2580 VULKAN : dEQP-GLES2.functional.buffer.write.recreate_store.random_* = SKIP
2580 VULKAN : dEQP-GLES2.functional.buffer.write.random.* = SKIP
2582 VULKAN : dEQP-GLES2.functional.shaders.linkage.uniform_struct_fragment* = SKIP
2585 VULKAN : dEQP-GLES2.functional.shaders.qualification_order.variables.valid.* = SKIP
2587 VULKAN : dEQP-GLES2.functional.shaders.loops.* = SKIP
2589 VULKAN : dEQP-GLES2.functional.shaders.return.output_write* = SKIP
2589 VULKAN : dEQP-GLES2.functional.shaders.return.return_in_static_loop* = SKIP
2590 VULKAN : dEQP-GLES2.functional.shaders.discard.* = SKIP
2494 VULKAN : dEQP-GLES2.functional.shaders.struct.uniform.sampler_* = SKIP
2592 VULKAN : dEQP-GLES2.functional.shaders.builtin_variable.depth_range* = SKIP
2592 VULKAN : dEQP-GLES2.functional.shaders.builtin_variable.pointcoord = SKIP
......
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