Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7bbe497

Browse files
Mohan MaiyaCommit Bot
authored andcommitted
Vulkan: Implement EXT_texture_sRGB_decode
Implement EXT_texture_sRGB_decode. This builds on the existing functionality from EXT_texture_sRGB_override, with 2 major edge cases: 1. sRGB_decode allows the texture state to be overridden by sampler state, which is implemented by forcing a a texture state sync during updateActiveTextures if a texture is bound to the same unit as a sampler with that state 2. texelFetch calls require us to reenable decoding, regardless of decode state. We add a new compiler pass (FlagSamplersWithTexelFetch) to mark samplers that are used with texelFetch in order to support this. This change also re-enables EXT_texture_sRGB_R8, which was disabled due to a dEQP bug that this change will bypass. Bug: angleproject:3609 Bug: angleproject:4503 Test: dEQP.GLES31/functional_srgb_texture_decode_skip_decode_* Test: GLES31/functional_state_query_texture_*_srgb_decode_* Test: GLES31/functional_state_query_sampler_*_srgb_decode_* Test: GLES31/functional_debug_negative_coverage_*_srgb_decode_* Test: GLES31/functional_android_extension_pack_extensions_ext_texture_srgb_decode Test: angle_end2end_tests --gtest_filter=SRGBTextureTest.*Vulkan* Change-Id: I4a67e487dc82e2f57c8c87d4bcd8ef442b6fe220 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2359481 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
1 parent e3a5738 commit 7bbe497

28 files changed

+668
-77
lines changed

include/GLSLANG/ShaderVars.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ struct ShaderVariable
200200
// Deprecated version of isSameVaryingAtLinkTime, which assumes ESSL1.
201201
bool isSameVaryingAtLinkTime(const ShaderVariable &other) const;
202202

203+
// If the variable is a sampler that has ever been statically used with texelFetch
204+
bool texelFetchInvoked;
205+
203206
protected:
204207
bool isSameVariableAtLinkTime(const ShaderVariable &other,
205208
bool matchPrecision,

src/common/utilities.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,19 @@ const char *GetDebugMessageTypeString(GLenum type);
223223
const char *GetDebugMessageSeverityString(GLenum severity);
224224

225225
// For use with EXT_texture_format_sRGB_override and EXT_texture_sRGB_decode
226-
// A texture may either have SRGB decoding forced on, or use whatever decode state is default for
227-
// the texture format.
226+
// A texture may be forced to decode to a nonlinear colorspace, to a linear colorspace, or to the
227+
// default colorspace of its current format.
228+
//
229+
// Default corresponds to "the texture should use the imageview that corresponds to its format"
230+
// Linear corresponds to "the texture has sRGB decoding disabled by extension, and should use a
231+
// linear imageview even if it is in a nonlinear format" NonLinear corresponds to "the texture has
232+
// sRGB override enabled by extension, and should use a nonlinear imageview even if it is in a
233+
// linear format"
228234
enum class SrgbOverride
229235
{
230236
Default = 0,
231-
Enabled
237+
Linear,
238+
NonLinear
232239
};
233240

234241
} // namespace gl

src/compiler.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ angle_translator_sources = [
134134
"src/compiler/translator/tree_ops/EmulatePrecision.h",
135135
"src/compiler/translator/tree_ops/ExpandIntegerPowExpressions.cpp",
136136
"src/compiler/translator/tree_ops/ExpandIntegerPowExpressions.h",
137+
"src/compiler/translator/tree_ops/FlagSamplersWithTexelFetch.cpp",
138+
"src/compiler/translator/tree_ops/FlagSamplersWithTexelFetch.h",
137139
"src/compiler/translator/tree_ops/FoldExpressions.cpp",
138140
"src/compiler/translator/tree_ops/FoldExpressions.h",
139141
"src/compiler/translator/tree_ops/InitializeVariables.cpp",

src/compiler/translator/ShaderVars.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ ShaderVariable::ShaderVariable(GLenum typeIn)
4848
index(-1),
4949
interpolation(INTERPOLATION_SMOOTH),
5050
isInvariant(false),
51+
texelFetchInvoked(false),
5152
flattenedOffsetInParentArrays(-1)
5253
{}
5354

@@ -79,6 +80,7 @@ ShaderVariable::ShaderVariable(const ShaderVariable &other)
7980
index(other.index),
8081
interpolation(other.interpolation),
8182
isInvariant(other.isInvariant),
83+
texelFetchInvoked(other.texelFetchInvoked),
8284
flattenedOffsetInParentArrays(other.flattenedOffsetInParentArrays)
8385
{}
8486

@@ -104,6 +106,7 @@ ShaderVariable &ShaderVariable::operator=(const ShaderVariable &other)
104106
index = other.index;
105107
interpolation = other.interpolation;
106108
isInvariant = other.isInvariant;
109+
texelFetchInvoked = other.texelFetchInvoked;
107110
return *this;
108111
}
109112

@@ -117,7 +120,7 @@ bool ShaderVariable::operator==(const ShaderVariable &other) const
117120
binding != other.binding || imageUnitFormat != other.imageUnitFormat ||
118121
offset != other.offset || readonly != other.readonly || writeonly != other.writeonly ||
119122
index != other.index || interpolation != other.interpolation ||
120-
isInvariant != other.isInvariant)
123+
isInvariant != other.isInvariant || texelFetchInvoked != other.texelFetchInvoked)
121124
{
122125
return false;
123126
}

src/compiler/translator/TranslatorVulkan.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "compiler/translator/ImmutableStringBuilder.h"
1919
#include "compiler/translator/OutputVulkanGLSL.h"
2020
#include "compiler/translator/StaticType.h"
21+
#include "compiler/translator/tree_ops/FlagSamplersWithTexelFetch.h"
2122
#include "compiler/translator/tree_ops/NameEmbeddedUniformStructs.h"
2223
#include "compiler/translator/tree_ops/RemoveAtomicCounterBuiltins.h"
2324
#include "compiler/translator/tree_ops/RemoveInactiveInterfaceVariables.h"
@@ -848,6 +849,11 @@ bool TranslatorVulkan::translateImpl(TIntermBlock *root,
848849
}
849850
}
850851

852+
if (!FlagSamplersForTexelFetch(this, root, &getSymbolTable(), &mUniforms))
853+
{
854+
return false;
855+
}
856+
851857
if (defaultUniformCount > 0)
852858
{
853859
gl::ShaderType shaderType = gl::FromGLenum<gl::ShaderType>(getShaderType());
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//
2+
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
//
6+
// FlagSamplersForTexelFetch.cpp: finds all instances of texelFetch used with a static reference to
7+
// a sampler uniform, and flag that uniform as having been used with texelFetch
8+
//
9+
10+
#include "compiler/translator/tree_ops/FlagSamplersWithTexelFetch.h"
11+
12+
#include "angle_gl.h"
13+
#include "common/utilities.h"
14+
15+
#include "compiler/translator/SymbolTable.h"
16+
#include "compiler/translator/tree_util/IntermNode_util.h"
17+
#include "compiler/translator/tree_util/IntermTraverse.h"
18+
#include "compiler/translator/tree_util/ReplaceVariable.h"
19+
20+
namespace sh
21+
{
22+
namespace
23+
{
24+
25+
// gvec4 texelFetch(gsamplerXD sampler, ivecX P, int lod)
26+
constexpr uint32_t kTexelFetchSequenceLength = 3u;
27+
28+
// gvec4 texelFetchOffset(gsamplerXD sampler, ivecX P, int lod, ivecX offset)
29+
constexpr uint32_t kTexelFetchOffsetSequenceLength = 4u;
30+
31+
class FlagSamplersWithTexelFetchTraverser : public TIntermTraverser
32+
{
33+
public:
34+
FlagSamplersWithTexelFetchTraverser(TSymbolTable *symbolTable,
35+
std::vector<ShaderVariable> *uniforms)
36+
: TIntermTraverser(true, true, true, symbolTable), mUniforms(uniforms)
37+
{}
38+
39+
bool visitAggregate(Visit visit, TIntermAggregate *node) override
40+
{
41+
// Decide if the node is a call to texelFetch[Offset]
42+
if (node->getOp() != EOpCallBuiltInFunction)
43+
{
44+
return true;
45+
}
46+
47+
ASSERT(node->getFunction()->symbolType() == SymbolType::BuiltIn);
48+
if (node->getFunction()->name() != "texelFetch" &&
49+
node->getFunction()->name() != "texelFetchOffset")
50+
{
51+
return true;
52+
}
53+
54+
const TIntermSequence *sequence = node->getSequence();
55+
56+
// This must be a valid texelFetch invokation with the required number of arguments
57+
ASSERT(sequence->size() == (node->getFunction()->name() == "texelFetch"
58+
? kTexelFetchSequenceLength
59+
: kTexelFetchOffsetSequenceLength));
60+
61+
TIntermSymbol *samplerSymbol = sequence->at(0)->getAsSymbolNode();
62+
ASSERT(samplerSymbol != nullptr);
63+
64+
const TVariable &samplerVariable = samplerSymbol->variable();
65+
66+
for (ShaderVariable &uniform : *mUniforms)
67+
{
68+
if (samplerVariable.name() == uniform.name)
69+
{
70+
ASSERT(gl::IsSamplerType(uniform.type));
71+
uniform.texelFetchInvoked = true;
72+
break;
73+
}
74+
}
75+
76+
return true;
77+
}
78+
79+
private:
80+
std::vector<ShaderVariable> *mUniforms;
81+
};
82+
83+
} // anonymous namespace
84+
85+
bool FlagSamplersForTexelFetch(TCompiler *compiler,
86+
TIntermBlock *root,
87+
TSymbolTable *symbolTable,
88+
std::vector<ShaderVariable> *uniforms)
89+
{
90+
ASSERT(uniforms != nullptr);
91+
if (uniforms->size() > 0)
92+
{
93+
FlagSamplersWithTexelFetchTraverser traverser(symbolTable, uniforms);
94+
root->traverse(&traverser);
95+
}
96+
97+
return true;
98+
}
99+
100+
} // namespace sh
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
//
6+
// FlagSamplersForTexelFetch.h: finds all instances of texelFetch used with a static reference to a
7+
// sampler uniform, and flag that uniform as having been used with texelFetch
8+
//
9+
10+
#ifndef COMPILER_TRANSLATOR_TREEOPS_FLAGSAMPLERSWITHTEXELFETCH_H_
11+
#define COMPILER_TRANSLATOR_TREEOPS_FLAGSAMPLERSWITHTEXELFETCH_H_
12+
13+
#include "GLSLANG/ShaderVars.h"
14+
#include "common/angleutils.h"
15+
16+
namespace sh
17+
{
18+
class TCompiler;
19+
class TIntermBlock;
20+
class TSymbolTable;
21+
22+
// This flags all samplers which are statically accessed by a texelFetch invokation- that is, the
23+
// sampler is used as a direct argument to the call to texelFetch. Dynamic accesses, or accesses
24+
// with any amount of indirection, are not counted.
25+
ANGLE_NO_DISCARD bool FlagSamplersForTexelFetch(TCompiler *compiler,
26+
TIntermBlock *root,
27+
TSymbolTable *symbolTable,
28+
std::vector<sh::ShaderVariable> *uniforms);
29+
} // namespace sh
30+
31+
#endif // COMPILER_TRANSLATOR_TREEOPS_FLAGSAMPLERSWITHTEXELFETCH_H_

src/libANGLE/Context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5611,7 +5611,7 @@ void Context::texImage2DExternal(TextureTarget target,
56115611
void Context::invalidateTexture(TextureType target)
56125612
{
56135613
mImplementation->invalidateTexture(target);
5614-
mState.invalidateTexture(target);
5614+
mState.invalidateTextureBindings(target);
56155615
}
56165616

56175617
void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)

src/libANGLE/Program.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,7 @@ void WriteShaderVar(BinaryOutputStream *stream, const sh::ShaderVariable &var)
889889
stream->writeInt(var.offset);
890890
stream->writeInt(var.readonly);
891891
stream->writeInt(var.writeonly);
892+
stream->writeInt(var.texelFetchInvoked);
892893

893894
ASSERT(var.fields.empty());
894895
}
@@ -906,10 +907,11 @@ void LoadShaderVar(BinaryInputStream *stream, sh::ShaderVariable *var)
906907
var->structName = stream->readString();
907908
var->setParentArrayIndex(stream->readInt<int>());
908909

909-
var->imageUnitFormat = stream->readInt<GLenum>();
910-
var->offset = stream->readInt<int>();
911-
var->readonly = stream->readBool();
912-
var->writeonly = stream->readBool();
910+
var->imageUnitFormat = stream->readInt<GLenum>();
911+
var->offset = stream->readInt<int>();
912+
var->readonly = stream->readBool();
913+
var->writeonly = stream->readBool();
914+
var->texelFetchInvoked = stream->readBool();
913915
}
914916

915917
// VariableLocation implementation.

src/libANGLE/ProgramLinkedResources.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,11 @@ class FlattenUniformVisitor : public sh::VariableNameVisitor
469469
LinkedUniform linkedUniform(variable.type, variable.precision, fullNameWithArrayIndex,
470470
variable.arraySizes, getBinding(), getOffset(), mLocation,
471471
-1, sh::kDefaultBlockMemberInfo);
472-
linkedUniform.mappedName = fullMappedNameWithArrayIndex;
473-
linkedUniform.active = mMarkActive;
474-
linkedUniform.staticUse = mMarkStaticUse;
475-
linkedUniform.outerArraySizes = arraySizes;
472+
linkedUniform.mappedName = fullMappedNameWithArrayIndex;
473+
linkedUniform.active = mMarkActive;
474+
linkedUniform.staticUse = mMarkStaticUse;
475+
linkedUniform.outerArraySizes = arraySizes;
476+
linkedUniform.texelFetchInvoked = variable.texelFetchInvoked;
476477
if (variable.hasParentArrayIndex())
477478
{
478479
linkedUniform.setParentArrayIndex(variable.parentArrayIndex());

0 commit comments

Comments
 (0)