Removed SkSL SymbolTable aliases

Now that we have first class Type aliases, we no longer need this
obsolete SymbolTable mechanism.

Change-Id: Ibfb21ed153d1cbca59679659254e4d58d18f5c7c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/491441
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2022-01-05 12:06:46 -05:00 committed by SkCQ
parent 44e712a6a9
commit 84d6cf9b5b
18 changed files with 1836 additions and 1894 deletions

View File

@ -22,7 +22,6 @@ public:
kExternal = (int) ProgramElement::Kind::kLast + 1,
kField,
kFunctionDeclaration,
kSymbolAlias,
kType,
kUnresolvedFunction,
kVariable,

View File

@ -88,6 +88,15 @@ BuiltinTypes::BuiltinTypes()
, fMat2(Type::MakeAliasType("mat2", *fFloat2x2))
, fMat3(Type::MakeAliasType("mat3", *fFloat3x3))
, fMat4(Type::MakeAliasType("mat4", *fFloat4x4))
, fMat2x2(Type::MakeAliasType("mat2x2", *fFloat2x2))
, fMat2x3(Type::MakeAliasType("mat2x3", *fFloat2x3))
, fMat2x4(Type::MakeAliasType("mat2x4", *fFloat2x4))
, fMat3x2(Type::MakeAliasType("mat3x2", *fFloat3x2))
, fMat3x3(Type::MakeAliasType("mat3x3", *fFloat3x3))
, fMat3x4(Type::MakeAliasType("mat3x4", *fFloat3x4))
, fMat4x2(Type::MakeAliasType("mat4x2", *fFloat4x2))
, fMat4x3(Type::MakeAliasType("mat4x3", *fFloat4x3))
, fMat4x4(Type::MakeAliasType("mat4x4", *fFloat4x4))
, fTexture1D(Type::MakeTextureType("texture1D",
SpvDim1D,
/*isDepth=*/false,

View File

@ -98,6 +98,16 @@ public:
const std::unique_ptr<Type> fMat3;
const std::unique_ptr<Type> fMat4;
const std::unique_ptr<Type> fMat2x2;
const std::unique_ptr<Type> fMat2x3;
const std::unique_ptr<Type> fMat2x4;
const std::unique_ptr<Type> fMat3x2;
const std::unique_ptr<Type> fMat3x3;
const std::unique_ptr<Type> fMat3x4;
const std::unique_ptr<Type> fMat4x2;
const std::unique_ptr<Type> fMat4x3;
const std::unique_ptr<Type> fMat4x4;
const std::unique_ptr<Type> fTexture1D;
const std::unique_ptr<Type> fTexture2D;
const std::unique_ptr<Type> fTexture3D;

View File

@ -268,7 +268,7 @@ static void add_glsl_type_aliases(SkSL::SymbolTable* symbols, const SkSL::Builti
// Alias every private type to "invalid". This will prevent code from using built-in names like
// `sampler2D` as variable names.
for (BuiltinTypePtr privateType : kPrivateTypes) {
symbols->addAlias((types.*privateType)->name(), types.fInvalid.get());
symbols->add(Type::MakeAliasType((types.*privateType)->name(), *types.fInvalid));
}
}

View File

@ -48,7 +48,6 @@
#include "src/sksl/ir/SkSLSwitchCase.h"
#include "src/sksl/ir/SkSLSwitchStatement.h"
#include "src/sksl/ir/SkSLSwizzle.h"
#include "src/sksl/ir/SkSLSymbolAlias.h"
#include "src/sksl/ir/SkSLSymbolTable.h"
#include "src/sksl/ir/SkSLTernaryExpression.h"
#include "src/sksl/ir/SkSLUnresolvedFunction.h"
@ -157,14 +156,6 @@ void Dehydrator::write(const Symbol& s) {
this->write(f.returnType());
break;
}
case Symbol::Kind::kSymbolAlias: {
const SymbolAlias& alias = s.as<SymbolAlias>();
this->writeCommand(Rehydrator::kSymbolAlias_Command);
this->writeId(&alias);
this->write(alias.name());
this->write(*alias.origSymbol());
break;
}
case Symbol::Kind::kUnresolvedFunction: {
const UnresolvedFunction& f = s.as<UnresolvedFunction>();
this->writeCommand(Rehydrator::kUnresolvedFunction_Command);

View File

@ -49,7 +49,6 @@
#include "src/sksl/ir/SkSLSwitchCase.h"
#include "src/sksl/ir/SkSLSwitchStatement.h"
#include "src/sksl/ir/SkSLSwizzle.h"
#include "src/sksl/ir/SkSLSymbolAlias.h"
#include "src/sksl/ir/SkSLSymbolTable.h"
#include "src/sksl/ir/SkSLTernaryExpression.h"
#include "src/sksl/ir/SkSLType.h"
@ -203,15 +202,6 @@ const Symbol* Rehydrator::symbol() {
SkASSERT(fSymbols.size() > id);
return fSymbols[id];
}
case kSymbolAlias_Command: {
uint16_t id = this->readU16();
skstd::string_view name = this->readString();
const Symbol* origSymbol = this->symbol();
const SymbolAlias* symbolAlias = fSymbolTable->takeOwnershipOfSymbol(
std::make_unique<SymbolAlias>(/*line=*/-1, name, origSymbol));
this->addSymbol(id, symbolAlias);
return symbolAlias;
}
case kSystemType_Command: {
uint16_t id = this->readU16();
skstd::string_view name = this->readString();

View File

@ -118,8 +118,6 @@ public:
kSwizzle_Command,
// uint16 id
kSymbolRef_Command,
// String name, uint16 origSymbolId
kSymbolAlias_Command,
// uint16 owned symbol count, Symbol[] ownedSymbols, uint16 symbol count,
// (String, uint16/*index*/)[].
kSymbolTable_Command,

View File

@ -82,44 +82,44 @@ void ThreadContext::setupSymbolTable() {
if (runtimeEffect && !context.fConfig->fSettings.fEnforceES2Restrictions) {
// We're compiling a runtime effect, but we're not enforcing ES2 restrictions. Add various
// non-ES2 types to our symbol table to allow them to be tested.
symbols.addAlias("mat2x2", context.fTypes.fFloat2x2.get());
symbols.addAlias("mat2x3", context.fTypes.fFloat2x3.get());
symbols.addAlias("mat2x4", context.fTypes.fFloat2x4.get());
symbols.addAlias("mat3x2", context.fTypes.fFloat3x2.get());
symbols.addAlias("mat3x3", context.fTypes.fFloat3x3.get());
symbols.addAlias("mat3x4", context.fTypes.fFloat3x4.get());
symbols.addAlias("mat4x2", context.fTypes.fFloat4x2.get());
symbols.addAlias("mat4x3", context.fTypes.fFloat4x3.get());
symbols.addAlias("mat4x4", context.fTypes.fFloat4x4.get());
symbols.addWithoutOwnership(context.fTypes.fMat2x2.get());
symbols.addWithoutOwnership(context.fTypes.fMat2x3.get());
symbols.addWithoutOwnership(context.fTypes.fMat2x4.get());
symbols.addWithoutOwnership(context.fTypes.fMat3x2.get());
symbols.addWithoutOwnership(context.fTypes.fMat3x3.get());
symbols.addWithoutOwnership(context.fTypes.fMat3x4.get());
symbols.addWithoutOwnership(context.fTypes.fMat4x2.get());
symbols.addWithoutOwnership(context.fTypes.fMat4x3.get());
symbols.addWithoutOwnership(context.fTypes.fMat4x4.get());
symbols.addAlias("float2x3", context.fTypes.fFloat2x3.get());
symbols.addAlias("float2x4", context.fTypes.fFloat2x4.get());
symbols.addAlias("float3x2", context.fTypes.fFloat3x2.get());
symbols.addAlias("float3x4", context.fTypes.fFloat3x4.get());
symbols.addAlias("float4x2", context.fTypes.fFloat4x2.get());
symbols.addAlias("float4x3", context.fTypes.fFloat4x3.get());
symbols.addWithoutOwnership(context.fTypes.fFloat2x3.get());
symbols.addWithoutOwnership(context.fTypes.fFloat2x4.get());
symbols.addWithoutOwnership(context.fTypes.fFloat3x2.get());
symbols.addWithoutOwnership(context.fTypes.fFloat3x4.get());
symbols.addWithoutOwnership(context.fTypes.fFloat4x2.get());
symbols.addWithoutOwnership(context.fTypes.fFloat4x3.get());
symbols.addAlias("half2x3", context.fTypes.fHalf2x3.get());
symbols.addAlias("half2x4", context.fTypes.fHalf2x4.get());
symbols.addAlias("half3x2", context.fTypes.fHalf3x2.get());
symbols.addAlias("half3x4", context.fTypes.fHalf3x4.get());
symbols.addAlias("half4x2", context.fTypes.fHalf4x2.get());
symbols.addAlias("half4x3", context.fTypes.fHalf4x3.get());
symbols.addWithoutOwnership(context.fTypes.fHalf2x3.get());
symbols.addWithoutOwnership(context.fTypes.fHalf2x4.get());
symbols.addWithoutOwnership(context.fTypes.fHalf3x2.get());
symbols.addWithoutOwnership(context.fTypes.fHalf3x4.get());
symbols.addWithoutOwnership(context.fTypes.fHalf4x2.get());
symbols.addWithoutOwnership(context.fTypes.fHalf4x3.get());
symbols.addAlias("uint", context.fTypes.fUInt.get());
symbols.addAlias("uint2", context.fTypes.fUInt2.get());
symbols.addAlias("uint3", context.fTypes.fUInt3.get());
symbols.addAlias("uint4", context.fTypes.fUInt4.get());
symbols.addWithoutOwnership(context.fTypes.fUInt.get());
symbols.addWithoutOwnership(context.fTypes.fUInt2.get());
symbols.addWithoutOwnership(context.fTypes.fUInt3.get());
symbols.addWithoutOwnership(context.fTypes.fUInt4.get());
symbols.addAlias("short", context.fTypes.fShort.get());
symbols.addAlias("short2", context.fTypes.fShort2.get());
symbols.addAlias("short3", context.fTypes.fShort3.get());
symbols.addAlias("short4", context.fTypes.fShort4.get());
symbols.addWithoutOwnership(context.fTypes.fShort.get());
symbols.addWithoutOwnership(context.fTypes.fShort2.get());
symbols.addWithoutOwnership(context.fTypes.fShort3.get());
symbols.addWithoutOwnership(context.fTypes.fShort4.get());
symbols.addAlias("ushort", context.fTypes.fUShort.get());
symbols.addAlias("ushort2", context.fTypes.fUShort2.get());
symbols.addAlias("ushort3", context.fTypes.fUShort3.get());
symbols.addAlias("ushort4", context.fTypes.fUShort4.get());
symbols.addWithoutOwnership(context.fTypes.fUShort.get());
symbols.addWithoutOwnership(context.fTypes.fUShort2.get());
symbols.addWithoutOwnership(context.fTypes.fUShort3.get());
symbols.addWithoutOwnership(context.fTypes.fUShort4.get());
}
}

View File

@ -7,24 +7,24 @@ static uint8_t SKSL_INCLUDE_sksl_frag[] = {96,0,
5,104,97,108,102,52,
16,115,107,95,76,97,115,116,70,114,97,103,67,111,108,111,114,
21,115,107,95,83,101,99,111,110,100,97,114,121,70,114,97,103,67,111,108,111,114,
48,5,0,
52,1,0,
47,5,0,
51,1,0,
36,
35,0,2,0,0,255,255,255,255,255,15,0,255,16,2,0,
49,2,0,15,0,0,
52,3,0,
48,2,0,15,0,0,
51,3,0,
36,
35,0,2,0,0,255,255,255,255,255,17,0,255,16,22,0,
49,4,0,35,0,0,
52,5,0,
48,4,0,35,0,0,
51,5,0,
36,
35,144,2,0,0,0,255,255,0,255,17,39,255,32,40,0,
49,6,0,53,0,0,
52,7,0,
48,6,0,53,0,0,
51,7,0,
36,
35,0,2,0,0,255,255,255,255,255,24,39,255,0,59,0,
46,6,0,0,
52,8,0,
51,8,0,
36,
35,0,2,0,0,255,255,255,255,255,28,39,255,32,76,0,
46,6,0,0,5,0,
@ -34,25 +34,25 @@ static uint8_t SKSL_INCLUDE_sksl_frag[] = {96,0,
3,0,
4,0,
20,
54,
53,1,0,
53,
52,1,0,
46,2,0,0,
56,
54,
53,3,0,
55,
53,
52,3,0,
46,4,0,0,
56,
54,
53,5,0,
55,
53,
52,5,0,
46,6,0,0,
56,
54,
53,7,0,
55,
53,
52,7,0,
46,6,0,0,
56,
54,
53,8,0,
55,
53,
52,8,0,
46,6,0,0,
56,
55,
21,};
static constexpr size_t SKSL_INCLUDE_sksl_frag_LENGTH = sizeof(SKSL_INCLUDE_sksl_frag);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,16 @@
static uint8_t SKSL_INCLUDE_sksl_rt_shader[] = {20,0,
12,115,107,95,70,114,97,103,67,111,111,114,100,
6,102,108,111,97,116,52,
48,1,0,
52,1,0,
47,1,0,
51,1,0,
36,
35,0,2,0,0,255,255,255,255,255,15,0,255,0,2,0,
49,2,0,15,0,0,1,0,
48,2,0,15,0,0,1,0,
0,0,
20,
54,
53,1,0,
53,
52,1,0,
46,2,0,0,
56,
55,
21,};
static constexpr size_t SKSL_INCLUDE_sksl_rt_shader_LENGTH = sizeof(SKSL_INCLUDE_sksl_rt_shader);

View File

@ -8,25 +8,25 @@ static uint8_t SKSL_INCLUDE_sksl_vert[] = {82,0,
3,105,110,116,
13,115,107,95,73,110,115,116,97,110,99,101,73,68,
0,
48,6,0,
47,6,0,
43,1,0,2,0,2,
36,
35,0,2,0,0,255,255,255,255,255,0,0,255,0,15,0,
49,2,0,27,0,
48,2,0,27,0,
36,
35,0,2,0,0,255,255,255,255,255,1,0,255,0,34,0,
49,3,0,47,0,1,
52,4,0,
48,3,0,47,0,1,
51,4,0,
36,
16,32,2,0,
46,1,0,0,
23,4,0,0,
23,4,0,1,
52,5,0,
51,5,0,
36,
35,0,2,0,0,255,255,255,255,255,42,0,255,16,53,0,
49,6,0,65,0,0,
52,7,0,
48,6,0,65,0,0,
51,7,0,
36,
35,0,2,0,0,255,255,255,255,255,43,0,255,16,69,0,
46,6,0,0,4,0,
@ -37,13 +37,13 @@ static uint8_t SKSL_INCLUDE_sksl_vert[] = {82,0,
20,
33,
46,4,0,2,0,83,0,0,
54,
53,5,0,
53,
52,5,0,
46,6,0,0,
56,
54,
53,7,0,
55,
53,
52,7,0,
46,6,0,0,
56,
55,
21,};
static constexpr size_t SKSL_INCLUDE_sksl_vert_LENGTH = sizeof(SKSL_INCLUDE_sksl_vert);

View File

@ -1,42 +0,0 @@
/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_SYMBOLALIAS
#define SKSL_SYMBOLALIAS
#include "include/private/SkSLSymbol.h"
namespace SkSL {
/**
* A symbol representing a new name for an existing symbol.
*/
class SymbolAlias final : public Symbol {
public:
inline static constexpr Kind kSymbolKind = Kind::kSymbolAlias;
SymbolAlias(int line, skstd::string_view name, const Symbol* origSymbol)
: INHERITED(line, kSymbolKind, name)
, fOrigSymbol(origSymbol) {}
const Symbol* origSymbol() const {
return fOrigSymbol;
}
String description() const override {
return String(this->name());
}
private:
const Symbol* fOrigSymbol;
using INHERITED = Symbol;
};
} // namespace SkSL
#endif

View File

@ -8,7 +8,6 @@
#include "src/sksl/ir/SkSLSymbolTable.h"
#include "src/sksl/SkSLContext.h"
#include "src/sksl/ir/SkSLSymbolAlias.h"
#include "src/sksl/ir/SkSLType.h"
#include "src/sksl/ir/SkSLUnresolvedFunction.h"
@ -76,9 +75,6 @@ const Symbol* SymbolTable::lookup(SymbolTable* writableSymbolTable, const Symbol
}
}
}
while (symbol && symbol->is<SymbolAlias>()) {
symbol = symbol->as<SymbolAlias>().origSymbol();
}
return symbol;
}
@ -88,10 +84,6 @@ const String* SymbolTable::takeOwnershipOfString(String str) {
return &fOwnedStrings.front();
}
void SymbolTable::addAlias(skstd::string_view name, const Symbol* symbol) {
this->add(std::make_unique<SymbolAlias>(symbol->fLine, name, symbol));
}
void SymbolTable::addWithoutOwnership(const Symbol* symbol) {
const skstd::string_view& name = symbol->name();

View File

@ -76,11 +76,6 @@ public:
*/
const Symbol* operator[](skstd::string_view name);
/**
* Creates a new name for a symbol which already exists; does not take ownership of Symbol*.
*/
void addAlias(skstd::string_view name, const Symbol* symbol);
void addWithoutOwnership(const Symbol* symbol);
template <typename T>

View File

@ -517,7 +517,7 @@ String Type::getArrayName(int arraySize) const {
return String::printf("%.*s[%d]", (int)name.size(), name.data(), arraySize);
}
std::unique_ptr<Type> Type::MakeAliasType(const char* name, const Type& targetType) {
std::unique_ptr<Type> Type::MakeAliasType(skstd::string_view name, const Type& targetType) {
return std::make_unique<AliasType>(std::move(name), targetType);
}

View File

@ -114,7 +114,7 @@ public:
/**
* Creates an alias which maps to another type.
*/
static std::unique_ptr<Type> MakeAliasType(const char* name, const Type& targetType);
static std::unique_ptr<Type> MakeAliasType(skstd::string_view name, const Type& targetType);
/**
* Create a generic type which maps to the listed types--e.g. $genType is a generic type which