Commit 40b1c770 by Olli Etuaho Committed by Commit Bot

Fix asserts related to writing nameless parameters in HLSL

We rely on TSymbol::name() to generate names also for nameless parameters. Fix asserts to reflect this. BUG=chromium:823041 TEST=angle_unittests Change-Id: Ie9b8253a150e79965bf85d8a7f36643ada6c54cc Reviewed-on: https://chromium-review.googlesource.com/968242Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent d2fa07e4
...@@ -46,11 +46,13 @@ TSymbol::TSymbol(TSymbolTable *symbolTable, ...@@ -46,11 +46,13 @@ TSymbol::TSymbol(TSymbolTable *symbolTable,
ImmutableString TSymbol::name() const ImmutableString TSymbol::name() const
{ {
if (mName != "") if (!mName.empty())
{ {
return mName; return mName;
} }
ASSERT(mSymbolType == SymbolType::AngleInternal); // This can be called for nameless function parameters in HLSL.
ASSERT(mSymbolType == SymbolType::AngleInternal ||
(mSymbolType == SymbolType::Empty && isVariable()));
int uniqueId = mUniqueId.get(); int uniqueId = mUniqueId.get();
ImmutableStringBuilder symbolNameOut(sizeof(uniqueId) * 2u + 1u); ImmutableStringBuilder symbolNameOut(sizeof(uniqueId) * 2u + 1u);
symbolNameOut << 's'; symbolNameOut << 's';
......
...@@ -42,8 +42,10 @@ class TSymbol : angle::NonCopyable ...@@ -42,8 +42,10 @@ class TSymbol : angle::NonCopyable
// either statically allocated or pool allocated. // either statically allocated or pool allocated.
~TSymbol() = default; ~TSymbol() = default;
// Don't call name() or getMangledName() for empty symbols (symbolType == SymbolType::Empty). // Calling name() for empty symbols (symbolType == SymbolType::Empty) generates a similar name
// as for internal variables.
ImmutableString name() const; ImmutableString name() const;
// Don't call getMangledName() for empty symbols (symbolType == SymbolType::Empty).
virtual ImmutableString getMangledName() const; virtual ImmutableString getMangledName() const;
virtual bool isFunction() const { return false; } virtual bool isFunction() const { return false; }
......
...@@ -829,8 +829,10 @@ TString Decorate(const ImmutableString &string) ...@@ -829,8 +829,10 @@ TString Decorate(const ImmutableString &string)
TString DecorateVariableIfNeeded(const TVariable &variable) TString DecorateVariableIfNeeded(const TVariable &variable)
{ {
if (variable.symbolType() == SymbolType::AngleInternal) if (variable.symbolType() == SymbolType::AngleInternal ||
variable.symbolType() == SymbolType::Empty)
{ {
// Besides handling internal variables, we generate names for nameless parameters here.
const ImmutableString &name = variable.name(); const ImmutableString &name = variable.name();
// The name should not have a prefix reserved for user-defined variables or functions. // The name should not have a prefix reserved for user-defined variables or functions.
ASSERT(!name.beginsWith("f_")); ASSERT(!name.beginsWith("f_"));
......
...@@ -156,3 +156,22 @@ TEST_F(HLSLOutputTest, ArrayReturnValue) ...@@ -156,3 +156,22 @@ TEST_F(HLSLOutputTest, ArrayReturnValue)
})"; })";
compile(shaderString); compile(shaderString);
} }
// Test that writing parameters without a name doesn't assert.
TEST_F(HLSLOutputTest, ParameterWithNoName)
{
const std::string &shaderString =
R"(precision mediump float;
uniform vec4 v;
vec4 s(vec4)
{
return v;
}
void main()
{
gl_FragColor = s(v);
})";
compile(shaderString);
}
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