diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp index 512a401650..1b18daf06d 100644 --- a/src/sksl/SkSLCompiler.cpp +++ b/src/sksl/SkSLCompiler.cpp @@ -137,49 +137,65 @@ Compiler::Compiler(const ShaderCapsClass* caps) Compiler::~Compiler() {} -#define TYPE(t) fContext->fTypes.f ## t .get() +#define TYPE(t) &BuiltinTypes::f ## t + +using BuiltinTypePtr = const std::unique_ptr BuiltinTypes::*; + +inline static constexpr BuiltinTypePtr kRootTypes[] = { + TYPE(Void), + + TYPE( Float), TYPE( Float2), TYPE( Float3), TYPE( Float4), + TYPE( Half), TYPE( Half2), TYPE( Half3), TYPE( Half4), + TYPE( Int), TYPE( Int2), TYPE( Int3), TYPE( Int4), + TYPE( UInt), TYPE( UInt2), TYPE( UInt3), TYPE( UInt4), + TYPE( Short), TYPE( Short2), TYPE( Short3), TYPE( Short4), + TYPE(UShort), TYPE(UShort2), TYPE(UShort3), TYPE(UShort4), + TYPE( Bool), TYPE( Bool2), TYPE( Bool3), TYPE( Bool4), + + TYPE(Float2x2), TYPE(Float2x3), TYPE(Float2x4), + TYPE(Float3x2), TYPE(Float3x3), TYPE(Float3x4), + TYPE(Float4x2), TYPE(Float4x3), TYPE(Float4x4), + + TYPE(Half2x2), TYPE(Half2x3), TYPE(Half2x4), + TYPE(Half3x2), TYPE(Half3x3), TYPE(Half3x4), + TYPE(Half4x2), TYPE(Half4x3), TYPE(Half4x4), + + TYPE(SquareMat), TYPE(SquareHMat), + TYPE(Mat), TYPE(HMat), + + // TODO(skia:12349): generic short/ushort + TYPE(GenType), TYPE(GenIType), TYPE(GenUType), + TYPE(GenHType), /* (GenSType) (GenUSType) */ + TYPE(GenBType), + + TYPE(Vec), TYPE(IVec), TYPE(UVec), + TYPE(HVec), TYPE(SVec), TYPE(USVec), + TYPE(BVec), + + TYPE(ColorFilter), + TYPE(Shader), + TYPE(Blender), +}; + +inline static constexpr BuiltinTypePtr kPrivateTypes[] = { + TYPE(Sampler1D), TYPE(Sampler2D), TYPE(Sampler3D), + TYPE(SamplerExternalOES), + TYPE(Sampler2DRect), + + TYPE(ISampler2D), + TYPE(SubpassInput), TYPE(SubpassInputMS), + + TYPE(Sampler), + TYPE(Texture2D), +}; + +#undef TYPE std::shared_ptr Compiler::makeRootSymbolTable() { auto rootSymbolTable = std::make_shared(*fContext, /*builtin=*/true); - const SkSL::Symbol* rootTypes[] = { - TYPE(Void), - - TYPE( Float), TYPE( Float2), TYPE( Float3), TYPE( Float4), - TYPE( Half), TYPE( Half2), TYPE( Half3), TYPE( Half4), - TYPE( Int), TYPE( Int2), TYPE( Int3), TYPE( Int4), - TYPE( UInt), TYPE( UInt2), TYPE( UInt3), TYPE( UInt4), - TYPE( Short), TYPE( Short2), TYPE( Short3), TYPE( Short4), - TYPE(UShort), TYPE(UShort2), TYPE(UShort3), TYPE(UShort4), - TYPE( Bool), TYPE( Bool2), TYPE( Bool3), TYPE( Bool4), - - TYPE(Float2x2), TYPE(Float2x3), TYPE(Float2x4), - TYPE(Float3x2), TYPE(Float3x3), TYPE(Float3x4), - TYPE(Float4x2), TYPE(Float4x3), TYPE(Float4x4), - - TYPE(Half2x2), TYPE(Half2x3), TYPE(Half2x4), - TYPE(Half3x2), TYPE(Half3x3), TYPE(Half3x4), - TYPE(Half4x2), TYPE(Half4x3), TYPE(Half4x4), - - TYPE(SquareMat), TYPE(SquareHMat), - TYPE(Mat), TYPE(HMat), - - // TODO(skia:12349): generic short/ushort - TYPE(GenType), TYPE(GenIType), TYPE(GenUType), - TYPE(GenHType), /* (GenSType) (GenUSType) */ - TYPE(GenBType), - - TYPE(Vec), TYPE(IVec), TYPE(UVec), - TYPE(HVec), TYPE(SVec), TYPE(USVec), - TYPE(BVec), - - TYPE(ColorFilter), - TYPE(Shader), - TYPE(Blender), - }; - - for (const SkSL::Symbol* type : rootTypes) { - rootSymbolTable->addWithoutOwnership(type); + for (BuiltinTypePtr rootType : kRootTypes) { + rootSymbolTable->addWithoutOwnership((fContext->fTypes.*rootType).get()); } return rootSymbolTable; @@ -188,20 +204,8 @@ std::shared_ptr Compiler::makeRootSymbolTable() { std::shared_ptr Compiler::makePrivateSymbolTable(std::shared_ptr parent) { auto privateSymbolTable = std::make_shared(parent, /*builtin=*/true); - const SkSL::Symbol* privateTypes[] = { - TYPE(Sampler1D), TYPE(Sampler2D), TYPE(Sampler3D), - TYPE(SamplerExternalOES), - TYPE(Sampler2DRect), - - TYPE(ISampler2D), - TYPE(SubpassInput), TYPE(SubpassInputMS), - - TYPE(Sampler), - TYPE(Texture2D), - }; - - for (const SkSL::Symbol* type : privateTypes) { - privateSymbolTable->addWithoutOwnership(type); + for (BuiltinTypePtr privateType : kPrivateTypes) { + privateSymbolTable->addWithoutOwnership((fContext->fTypes.*privateType).get()); } // sk_Caps is "builtin", but all references to it are resolved to Settings, so we don't need to @@ -212,12 +216,9 @@ std::shared_ptr Compiler::makePrivateSymbolTable(std::shared_ptrfTypes.fSkCaps.get(), /*builtin=*/false, Variable::Storage::kGlobal)); - return privateSymbolTable; } -#undef TYPE - const ParsedModule& Compiler::loadGPUModule() { if (!fGPUModule.fSymbols) { fGPUModule = this->parseModule(ProgramKind::kFragment, MODULE_DATA(gpu), fPrivateModule);