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) ...@@ -1096,8 +1096,16 @@ Error Program::link(const gl::Context *context)
if (mState.mAttachedShaders[ShaderType::Compute]) if (mState.mAttachedShaders[ShaderType::Compute])
{ {
ProgramLinkedResources resources = {
{0, PackMode::ANGLE_RELAXED},
{&mState.mUniformBlocks, &mState.mUniforms},
{&mState.mShaderStorageBlocks, &mState.mBufferVariables},
{&mState.mAtomicCounterBuffers},
{}};
GLuint combinedImageUniforms = 0u; GLuint combinedImageUniforms = 0u;
if (!linkUniforms(context, mInfoLog, mUniformLocationBindings, &combinedImageUniforms)) if (!linkUniforms(context, mInfoLog, mUniformLocationBindings, &combinedImageUniforms,
&resources.unusedUniforms))
{ {
return NoError(); return NoError();
} }
...@@ -1124,12 +1132,6 @@ Error Program::link(const gl::Context *context) ...@@ -1124,12 +1132,6 @@ Error Program::link(const gl::Context *context)
return NoError(); return NoError();
} }
ProgramLinkedResources resources = {
{0, PackMode::ANGLE_RELAXED},
{&mState.mUniformBlocks, &mState.mUniforms},
{&mState.mShaderStorageBlocks, &mState.mBufferVariables},
{&mState.mAtomicCounterBuffers}};
InitUniformBlockLinker(context, mState, &resources.uniformBlockLinker); InitUniformBlockLinker(context, mState, &resources.uniformBlockLinker);
InitShaderStorageBlockLinker(context, mState, &resources.shaderStorageBlockLinker); InitShaderStorageBlockLinker(context, mState, &resources.shaderStorageBlockLinker);
...@@ -1141,6 +1143,26 @@ Error Program::link(const gl::Context *context) ...@@ -1141,6 +1143,26 @@ Error Program::link(const gl::Context *context)
} }
else 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)) if (!linkAttributes(context, mInfoLog))
{ {
return NoError(); return NoError();
...@@ -1152,7 +1174,8 @@ Error Program::link(const gl::Context *context) ...@@ -1152,7 +1174,8 @@ Error Program::link(const gl::Context *context)
} }
GLuint combinedImageUniforms = 0u; GLuint combinedImageUniforms = 0u;
if (!linkUniforms(context, mInfoLog, mUniformLocationBindings, &combinedImageUniforms)) if (!linkUniforms(context, mInfoLog, mUniformLocationBindings, &combinedImageUniforms,
&resources.unusedUniforms))
{ {
return NoError(); return NoError();
} }
...@@ -1178,25 +1201,6 @@ Error Program::link(const gl::Context *context) ...@@ -1178,25 +1201,6 @@ Error Program::link(const gl::Context *context)
ASSERT(mState.mAttachedShaders[ShaderType::Vertex]); ASSERT(mState.mAttachedShaders[ShaderType::Vertex]);
mState.mNumViews = mState.mAttachedShaders[ShaderType::Vertex]->getNumViews(context); 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); InitUniformBlockLinker(context, mState, &resources.uniformBlockLinker);
InitShaderStorageBlockLinker(context, mState, &resources.shaderStorageBlockLinker); InitShaderStorageBlockLinker(context, mState, &resources.shaderStorageBlockLinker);
...@@ -2558,7 +2562,8 @@ bool Program::linkValidateFragmentInputBindings(const Context *context, gl::Info ...@@ -2558,7 +2562,8 @@ bool Program::linkValidateFragmentInputBindings(const Context *context, gl::Info
bool Program::linkUniforms(const Context *context, bool Program::linkUniforms(const Context *context,
InfoLog &infoLog, InfoLog &infoLog,
const ProgramBindings &uniformLocationBindings, const ProgramBindings &uniformLocationBindings,
GLuint *combinedImageUniformsCount) GLuint *combinedImageUniformsCount,
std::vector<UnusedUniform> *unusedUniforms)
{ {
UniformLinker linker(mState); UniformLinker linker(mState);
if (!linker.link(context, infoLog, uniformLocationBindings)) if (!linker.link(context, infoLog, uniformLocationBindings))
...@@ -2566,7 +2571,7 @@ bool Program::linkUniforms(const Context *context, ...@@ -2566,7 +2571,7 @@ bool Program::linkUniforms(const Context *context,
return false; return false;
} }
linker.getResults(&mState.mUniforms, &mState.mUniformLocations); linker.getResults(&mState.mUniforms, unusedUniforms, &mState.mUniformLocations);
linkSamplerAndImageBindings(combinedImageUniformsCount); linkSamplerAndImageBindings(combinedImageUniformsCount);
......
...@@ -40,6 +40,7 @@ struct TranslatedAttribute; ...@@ -40,6 +40,7 @@ struct TranslatedAttribute;
namespace gl namespace gl
{ {
struct UnusedUniform;
struct Caps; struct Caps;
class Context; class Context;
class ContextState; class ContextState;
...@@ -747,7 +748,8 @@ class Program final : angle::NonCopyable, public LabeledObject ...@@ -747,7 +748,8 @@ class Program final : angle::NonCopyable, public LabeledObject
bool linkUniforms(const Context *context, bool linkUniforms(const Context *context,
InfoLog &infoLog, InfoLog &infoLog,
const ProgramBindings &uniformLocationBindings, const ProgramBindings &uniformLocationBindings,
GLuint *combinedImageUniformsCount); GLuint *combinedImageUniformsCount,
std::vector<UnusedUniform> *unusedUniforms);
void linkSamplerAndImageBindings(GLuint *combinedImageUniformsCount); void linkSamplerAndImageBindings(GLuint *combinedImageUniformsCount);
bool linkAtomicCounterBuffers(); bool linkAtomicCounterBuffers();
......
...@@ -38,8 +38,9 @@ struct LinkedUniform; ...@@ -38,8 +38,9 @@ struct LinkedUniform;
class ProgramState; class ProgramState;
class ProgramBindings; class ProgramBindings;
class Shader; class Shader;
struct VariableLocation;
struct ShaderVariableBuffer; struct ShaderVariableBuffer;
struct UnusedUniform;
struct VariableLocation;
using AtomicCounterBuffer = ShaderVariableBuffer; using AtomicCounterBuffer = ShaderVariableBuffer;
...@@ -54,6 +55,7 @@ class UniformLinker final : angle::NonCopyable ...@@ -54,6 +55,7 @@ class UniformLinker final : angle::NonCopyable
const ProgramBindings &uniformLocationBindings); const ProgramBindings &uniformLocationBindings);
void getResults(std::vector<LinkedUniform> *uniforms, void getResults(std::vector<LinkedUniform> *uniforms,
std::vector<UnusedUniform> *unusedUniforms,
std::vector<VariableLocation> *uniformLocations); std::vector<VariableLocation> *uniformLocations);
private: private:
...@@ -88,6 +90,7 @@ class UniformLinker final : angle::NonCopyable ...@@ -88,6 +90,7 @@ class UniformLinker final : angle::NonCopyable
std::vector<LinkedUniform> &samplerUniforms, std::vector<LinkedUniform> &samplerUniforms,
std::vector<LinkedUniform> &imageUniforms, std::vector<LinkedUniform> &imageUniforms,
std::vector<LinkedUniform> &atomicCounterUniforms, std::vector<LinkedUniform> &atomicCounterUniforms,
std::vector<UnusedUniform> &unusedUniforms,
InfoLog &infoLog); InfoLog &infoLog);
bool flattenUniformsAndCheckCaps(const Context *context, InfoLog &infoLog); bool flattenUniformsAndCheckCaps(const Context *context, InfoLog &infoLog);
...@@ -97,6 +100,7 @@ class UniformLinker final : angle::NonCopyable ...@@ -97,6 +100,7 @@ class UniformLinker final : angle::NonCopyable
std::vector<LinkedUniform> *samplerUniforms, std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms, std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms, std::vector<LinkedUniform> *atomicCounterUniforms,
std::vector<UnusedUniform> *unusedUniforms,
ShaderType shaderType); ShaderType shaderType);
ShaderUniformCount flattenArrayOfStructsUniform( ShaderUniformCount flattenArrayOfStructsUniform(
...@@ -107,7 +111,7 @@ class UniformLinker final : angle::NonCopyable ...@@ -107,7 +111,7 @@ class UniformLinker final : angle::NonCopyable
std::vector<LinkedUniform> *samplerUniforms, std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms, std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms, std::vector<LinkedUniform> *atomicCounterUniforms,
std::vector<UnusedUniform> *unusedUniforms,
ShaderType shaderType, ShaderType shaderType,
bool markActive, bool markActive,
bool markStaticUse, bool markStaticUse,
...@@ -121,6 +125,7 @@ class UniformLinker final : angle::NonCopyable ...@@ -121,6 +125,7 @@ class UniformLinker final : angle::NonCopyable
std::vector<LinkedUniform> *samplerUniforms, std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms, std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms, std::vector<LinkedUniform> *atomicCounterUniforms,
std::vector<UnusedUniform> *unusedUniforms,
ShaderType shaderType, ShaderType shaderType,
bool markActive, bool markActive,
bool markStaticUse, bool markStaticUse,
...@@ -134,6 +139,7 @@ class UniformLinker final : angle::NonCopyable ...@@ -134,6 +139,7 @@ class UniformLinker final : angle::NonCopyable
std::vector<LinkedUniform> *samplerUniforms, std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms, std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms, std::vector<LinkedUniform> *atomicCounterUniforms,
std::vector<UnusedUniform> *unusedUniforms,
ShaderType shaderType, ShaderType shaderType,
bool markActive, bool markActive,
bool markStaticUse, bool markStaticUse,
...@@ -149,6 +155,7 @@ class UniformLinker final : angle::NonCopyable ...@@ -149,6 +155,7 @@ class UniformLinker final : angle::NonCopyable
std::vector<LinkedUniform> *samplerUniforms, std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms, std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms, std::vector<LinkedUniform> *atomicCounterUniforms,
std::vector<UnusedUniform> *unusedUniforms,
ShaderType shaderType, ShaderType shaderType,
bool markActive, bool markActive,
bool markStaticUse, bool markStaticUse,
...@@ -165,6 +172,7 @@ class UniformLinker final : angle::NonCopyable ...@@ -165,6 +172,7 @@ class UniformLinker final : angle::NonCopyable
const ProgramState &mState; const ProgramState &mState;
std::vector<LinkedUniform> mUniforms; std::vector<LinkedUniform> mUniforms;
std::vector<UnusedUniform> mUnusedUniforms;
std::vector<VariableLocation> mUniformLocations; std::vector<VariableLocation> mUniformLocations;
}; };
...@@ -303,12 +311,25 @@ class AtomicCounterBufferLinker final : angle::NonCopyable ...@@ -303,12 +311,25 @@ class AtomicCounterBufferLinker final : angle::NonCopyable
// The link operation is responsible for finishing the link of uniform and interface blocks. // 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. // 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. // 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 struct ProgramLinkedResources
{ {
VaryingPacking varyingPacking; VaryingPacking varyingPacking;
UniformBlockLinker uniformBlockLinker; UniformBlockLinker uniformBlockLinker;
ShaderStorageBlockLinker shaderStorageBlockLinker; ShaderStorageBlockLinker shaderStorageBlockLinker;
AtomicCounterBufferLinker atomicCounterBufferLinker; AtomicCounterBufferLinker atomicCounterBufferLinker;
std::vector<UnusedUniform> unusedUniforms;
}; };
} // namespace gl } // namespace gl
......
...@@ -41,7 +41,7 @@ void InsertLayoutSpecifierString(std::string *shaderString, ...@@ -41,7 +41,7 @@ void InsertLayoutSpecifierString(std::string *shaderString,
searchStringBuilder << kLayoutMarkerBegin << variableName << kMarkerEnd; searchStringBuilder << kLayoutMarkerBegin << variableName << kMarkerEnd;
std::string searchString = searchStringBuilder.str(); std::string searchString = searchStringBuilder.str();
if (layoutString != "") if (!layoutString.empty())
{ {
angle::ReplaceSubstring(shaderString, searchString, "layout(" + layoutString + ")"); angle::ReplaceSubstring(shaderString, searchString, "layout(" + layoutString + ")");
} }
...@@ -193,7 +193,6 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext, ...@@ -193,7 +193,6 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext,
for (unsigned int uniformIndex : programState.getSamplerUniformRange()) for (unsigned int uniformIndex : programState.getSamplerUniformRange())
{ {
const gl::LinkedUniform &samplerUniform = uniforms[uniformIndex]; const gl::LinkedUniform &samplerUniform = uniforms[uniformIndex];
std::string setBindingString = "set = 1, binding = " + Str(textureCount); std::string setBindingString = "set = 1, binding = " + Str(textureCount);
ASSERT(samplerUniform.isActive(gl::ShaderType::Vertex) || ASSERT(samplerUniform.isActive(gl::ShaderType::Vertex) ||
...@@ -221,6 +220,16 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext, ...@@ -221,6 +220,16 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext,
textureCount += samplerUniform.getBasicTypeElementCount(); 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<const char *, 2> strings = {{vertexSource.c_str(), fragmentSource.c_str()}};
std::array<int, 2> lengths = { std::array<int, 2> lengths = {
{static_cast<int>(vertexSource.length()), static_cast<int>(fragmentSource.length())}}; {static_cast<int>(vertexSource.length()), static_cast<int>(fragmentSource.length())}};
......
...@@ -216,12 +216,6 @@ ...@@ -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.different_size = SKIP
2580 VULKAN : dEQP-GLES2.functional.buffer.write.recreate_store.random_* = SKIP 2580 VULKAN : dEQP-GLES2.functional.buffer.write.recreate_store.random_* = SKIP
2580 VULKAN : dEQP-GLES2.functional.buffer.write.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 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.depth_range* = SKIP
2592 VULKAN : dEQP-GLES2.functional.shaders.builtin_variable.pointcoord = 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