/* * Copyright 2016 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef SKSL_CONTEXT #define SKSL_CONTEXT #include "ir/SkSLType.h" #include "ir/SkSLExpression.h" namespace SkSL { /** * Contains compiler-wide objects, which currently means the core types. */ class Context { public: Context() : fInvalid_Type(new Type(String(""))) , fVoid_Type(new Type(String("void"))) , fDouble_Type(new Type(String("double"), true)) , fDouble2_Type(new Type(String("double2"), *fDouble_Type, 2)) , fDouble3_Type(new Type(String("double3"), *fDouble_Type, 3)) , fDouble4_Type(new Type(String("double4"), *fDouble_Type, 4)) , fFloat_Type(new Type(String("float"), true, { fDouble_Type.get() })) , fFloat2_Type(new Type(String("float2"), *fFloat_Type, 2)) , fFloat3_Type(new Type(String("float3"), *fFloat_Type, 3)) , fFloat4_Type(new Type(String("float4"), *fFloat_Type, 4)) , fUInt_Type(new Type(String("uint"), true, { fFloat_Type.get(), fDouble_Type.get() })) , fUInt2_Type(new Type(String("uint2"), *fUInt_Type, 2)) , fUInt3_Type(new Type(String("uint3"), *fUInt_Type, 3)) , fUInt4_Type(new Type(String("uint4"), *fUInt_Type, 4)) , fInt_Type(new Type(String("int"), true, { fUInt_Type.get(), fFloat_Type.get(), fDouble_Type.get() })) , fInt2_Type(new Type(String("int2"), *fInt_Type, 2)) , fInt3_Type(new Type(String("int3"), *fInt_Type, 3)) , fInt4_Type(new Type(String("int4"), *fInt_Type, 4)) , fBool_Type(new Type(String("bool"), false)) , fBool2_Type(new Type(String("bool2"), *fBool_Type, 2)) , fBool3_Type(new Type(String("bool3"), *fBool_Type, 3)) , fBool4_Type(new Type(String("bool4"), *fBool_Type, 4)) , fFloat2x2_Type(new Type(String("float2x2"), *fFloat_Type, 2, 2)) , fFloat2x3_Type(new Type(String("float2x3"), *fFloat_Type, 2, 3)) , fFloat2x4_Type(new Type(String("float2x4"), *fFloat_Type, 2, 4)) , fFloat3x2_Type(new Type(String("float3x2"), *fFloat_Type, 3, 2)) , fFloat3x3_Type(new Type(String("float3x3"), *fFloat_Type, 3, 3)) , fFloat3x4_Type(new Type(String("float3x4"), *fFloat_Type, 3, 4)) , fFloat4x2_Type(new Type(String("float4x2"), *fFloat_Type, 4, 2)) , fFloat4x3_Type(new Type(String("float4x3"), *fFloat_Type, 4, 3)) , fFloat4x4_Type(new Type(String("float4x4"), *fFloat_Type, 4, 4)) , fDouble2x2_Type(new Type(String("double2x2"), *fFloat_Type, 2, 2)) , fDouble2x3_Type(new Type(String("double2x3"), *fFloat_Type, 2, 3)) , fDouble2x4_Type(new Type(String("double2x4"), *fFloat_Type, 2, 4)) , fDouble3x2_Type(new Type(String("double3x2"), *fFloat_Type, 3, 2)) , fDouble3x3_Type(new Type(String("double3x3"), *fFloat_Type, 3, 3)) , fDouble3x4_Type(new Type(String("double3x4"), *fFloat_Type, 3, 4)) , fDouble4x2_Type(new Type(String("double4x2"), *fFloat_Type, 4, 2)) , fDouble4x3_Type(new Type(String("double4x3"), *fFloat_Type, 4, 3)) , fDouble4x4_Type(new Type(String("double4x4"), *fFloat_Type, 4, 4)) , fSampler1D_Type(new Type(String("sampler1D"), SpvDim1D, false, false, false, true)) , fSampler2D_Type(new Type(String("sampler2D"), SpvDim2D, false, false, false, true)) , fSampler3D_Type(new Type(String("sampler3D"), SpvDim3D, false, false, false, true)) , fSamplerExternalOES_Type(new Type(String("samplerExternalOES"), SpvDim2D, false, false, false, true)) , fSamplerCube_Type(new Type(String("samplerCube"), SpvDimCube, false, false, false, true)) , fSampler2DRect_Type(new Type(String("sampler2DRect"), SpvDimRect, false, false, false, true)) , fSampler1DArray_Type(new Type(String("sampler1DArray"))) , fSampler2DArray_Type(new Type(String("sampler2DArray"))) , fSamplerCubeArray_Type(new Type(String("samplerCubeArray"))) , fSamplerBuffer_Type(new Type(String("samplerBuffer"), SpvDimBuffer, false, false, false, true)) , fSampler2DMS_Type(new Type(String("sampler2DMS"))) , fSampler2DMSArray_Type(new Type(String("sampler2DMSArray"))) , fSampler1DShadow_Type(new Type(String("sampler1DShadow"))) , fSampler2DShadow_Type(new Type(String("sampler2DShadow"))) , fSamplerCubeShadow_Type(new Type(String("samplerCubeShadow"))) , fSampler2DRectShadow_Type(new Type(String("sampler2DRectShadow"))) , fSampler1DArrayShadow_Type(new Type(String("sampler1DArrayShadow"))) , fSampler2DArrayShadow_Type(new Type(String("sampler2DArrayShadow"))) , fSamplerCubeArrayShadow_Type(new Type(String("samplerCubeArrayShadow"))) // Related to below FIXME, gsampler*s don't currently expand to cover integer case. , fISampler2D_Type(new Type(String("isampler2D"), SpvDim2D, false, false, false, true)) // FIXME express these as "gimage2D" that expand to image2D, iimage2D, and uimage2D. , fImage2D_Type(new Type(String("image2D"), SpvDim2D, false, false, false, true)) , fIImage2D_Type(new Type(String("iimage2D"), SpvDim2D, false, false, false, true)) // FIXME express these as "gsubpassInput" that expand to subpassInput, isubpassInput, // and usubpassInput. , fSubpassInput_Type(new Type(String("subpassInput"), SpvDimSubpassData, false, false, false, false)) , fSubpassInputMS_Type(new Type(String("subpassInputMS"), SpvDimSubpassData, false, false, true, false)) // FIXME figure out what we're supposed to do with the gsampler et al. types) , fGSampler1D_Type(new Type(String("$gsampler1D"), static_type(*fSampler1D_Type))) , fGSampler2D_Type(new Type(String("$gsampler2D"), static_type(*fSampler2D_Type))) , fGSampler3D_Type(new Type(String("$gsampler3D"), static_type(*fSampler3D_Type))) , fGSamplerCube_Type(new Type(String("$gsamplerCube"), static_type(*fSamplerCube_Type))) , fGSampler2DRect_Type(new Type(String("$gsampler2DRect"), static_type(*fSampler2DRect_Type))) , fGSampler1DArray_Type(new Type(String("$gsampler1DArray"), static_type(*fSampler1DArray_Type))) , fGSampler2DArray_Type(new Type(String("$gsampler2DArray"), static_type(*fSampler2DArray_Type))) , fGSamplerCubeArray_Type(new Type(String("$gsamplerCubeArray"), static_type(*fSamplerCubeArray_Type))) , fGSamplerBuffer_Type(new Type(String("$gsamplerBuffer"), static_type(*fSamplerBuffer_Type))) , fGSampler2DMS_Type(new Type(String("$gsampler2DMS"), static_type(*fSampler2DMS_Type))) , fGSampler2DMSArray_Type(new Type(String("$gsampler2DMSArray"), static_type(*fSampler2DMSArray_Type))) , fGSampler2DArrayShadow_Type(new Type(String("$gsampler2DArrayShadow"), static_type(*fSampler2DArrayShadow_Type))) , fGSamplerCubeArrayShadow_Type(new Type(String("$gsamplerCubeArrayShadow"), static_type(*fSamplerCubeArrayShadow_Type))) , fGenType_Type(new Type(String("$genType"), { fFloat_Type.get(), fFloat2_Type.get(), fFloat3_Type.get(), fFloat4_Type.get() })) , fGenDType_Type(new Type(String("$genDType"), { fDouble_Type.get(), fDouble2_Type.get(), fDouble3_Type.get(), fDouble4_Type.get() })) , fGenIType_Type(new Type(String("$genIType"), { fInt_Type.get(), fInt2_Type.get(), fInt3_Type.get(), fInt4_Type.get() })) , fGenUType_Type(new Type(String("$genUType"), { fUInt_Type.get(), fUInt2_Type.get(), fUInt3_Type.get(), fUInt4_Type.get() })) , fGenBType_Type(new Type(String("$genBType"), { fBool_Type.get(), fBool2_Type.get(), fBool3_Type.get(), fBool4_Type.get() })) , fMat_Type(new Type(String("$mat"), { fFloat2x2_Type.get(), fFloat2x3_Type.get(), fFloat2x4_Type.get(), fFloat3x2_Type.get(), fFloat3x3_Type.get(), fFloat3x4_Type.get(), fFloat4x2_Type.get(), fFloat4x3_Type.get(), fFloat4x4_Type.get(), fDouble2x2_Type.get(), fDouble2x3_Type.get(), fDouble2x4_Type.get(), fDouble3x2_Type.get(), fDouble3x3_Type.get(), fDouble3x4_Type.get(), fDouble4x2_Type.get(), fDouble4x3_Type.get(), fDouble4x4_Type.get() })) , fVec_Type(new Type(String("$vec"), { fInvalid_Type.get(), fFloat2_Type.get(), fFloat3_Type.get(), fFloat4_Type.get() })) , fGVec_Type(new Type(String("$gvec"))) , fGVec2_Type(new Type(String("$gfloat2"))) , fGVec3_Type(new Type(String("$gfloat3"))) , fGVec4_Type(new Type(String("$gfloat4"), static_type(*fFloat4_Type))) , fDVec_Type(new Type(String("$dvec"), { fInvalid_Type.get(), fDouble2_Type.get(), fDouble3_Type.get(), fDouble4_Type.get() })) , fIVec_Type(new Type(String("$ivec"), { fInvalid_Type.get(), fInt2_Type.get(), fInt3_Type.get(), fInt4_Type.get() })) , fUVec_Type(new Type(String("$uvec"), { fInvalid_Type.get(), fUInt2_Type.get(), fUInt3_Type.get(), fUInt4_Type.get() })) , fBVec_Type(new Type(String("$bvec"), { fInvalid_Type.get(), fBool2_Type.get(), fBool3_Type.get(), fBool4_Type.get() })) , fSkCaps_Type(new Type(String("$sk_Caps"))) , fSkArgs_Type(new Type(String("$sk_Args"))) , fColorSpaceXform_Type(new Type(String("colorSpaceXform"), *fFloat_Type, 4, 4)) , fDefined_Expression(new Defined(*fInvalid_Type)) {} static std::vector static_type(const Type& t) { return { &t, &t, &t, &t }; } const std::unique_ptr fInvalid_Type; const std::unique_ptr fVoid_Type; const std::unique_ptr fDouble_Type; const std::unique_ptr fDouble2_Type; const std::unique_ptr fDouble3_Type; const std::unique_ptr fDouble4_Type; const std::unique_ptr fFloat_Type; const std::unique_ptr fFloat2_Type; const std::unique_ptr fFloat3_Type; const std::unique_ptr fFloat4_Type; const std::unique_ptr fUInt_Type; const std::unique_ptr fUInt2_Type; const std::unique_ptr fUInt3_Type; const std::unique_ptr fUInt4_Type; const std::unique_ptr fInt_Type; const std::unique_ptr fInt2_Type; const std::unique_ptr fInt3_Type; const std::unique_ptr fInt4_Type; const std::unique_ptr fBool_Type; const std::unique_ptr fBool2_Type; const std::unique_ptr fBool3_Type; const std::unique_ptr fBool4_Type; const std::unique_ptr fFloat2x2_Type; const std::unique_ptr fFloat2x3_Type; const std::unique_ptr fFloat2x4_Type; const std::unique_ptr fFloat3x2_Type; const std::unique_ptr fFloat3x3_Type; const std::unique_ptr fFloat3x4_Type; const std::unique_ptr fFloat4x2_Type; const std::unique_ptr fFloat4x3_Type; const std::unique_ptr fFloat4x4_Type; const std::unique_ptr fDouble2x2_Type; const std::unique_ptr fDouble2x3_Type; const std::unique_ptr fDouble2x4_Type; const std::unique_ptr fDouble3x2_Type; const std::unique_ptr fDouble3x3_Type; const std::unique_ptr fDouble3x4_Type; const std::unique_ptr fDouble4x2_Type; const std::unique_ptr fDouble4x3_Type; const std::unique_ptr fDouble4x4_Type; const std::unique_ptr fSampler1D_Type; const std::unique_ptr fSampler2D_Type; const std::unique_ptr fSampler3D_Type; const std::unique_ptr fSamplerExternalOES_Type; const std::unique_ptr fSamplerCube_Type; const std::unique_ptr fSampler2DRect_Type; const std::unique_ptr fSampler1DArray_Type; const std::unique_ptr fSampler2DArray_Type; const std::unique_ptr fSamplerCubeArray_Type; const std::unique_ptr fSamplerBuffer_Type; const std::unique_ptr fSampler2DMS_Type; const std::unique_ptr fSampler2DMSArray_Type; const std::unique_ptr fSampler1DShadow_Type; const std::unique_ptr fSampler2DShadow_Type; const std::unique_ptr fSamplerCubeShadow_Type; const std::unique_ptr fSampler2DRectShadow_Type; const std::unique_ptr fSampler1DArrayShadow_Type; const std::unique_ptr fSampler2DArrayShadow_Type; const std::unique_ptr fSamplerCubeArrayShadow_Type; const std::unique_ptr fISampler2D_Type; const std::unique_ptr fImage2D_Type; const std::unique_ptr fIImage2D_Type; const std::unique_ptr fSubpassInput_Type; const std::unique_ptr fSubpassInputMS_Type; const std::unique_ptr fGSampler1D_Type; const std::unique_ptr fGSampler2D_Type; const std::unique_ptr fGSampler3D_Type; const std::unique_ptr fGSamplerCube_Type; const std::unique_ptr fGSampler2DRect_Type; const std::unique_ptr fGSampler1DArray_Type; const std::unique_ptr fGSampler2DArray_Type; const std::unique_ptr fGSamplerCubeArray_Type; const std::unique_ptr fGSamplerBuffer_Type; const std::unique_ptr fGSampler2DMS_Type; const std::unique_ptr fGSampler2DMSArray_Type; const std::unique_ptr fGSampler2DArrayShadow_Type; const std::unique_ptr fGSamplerCubeArrayShadow_Type; const std::unique_ptr fGenType_Type; const std::unique_ptr fGenDType_Type; const std::unique_ptr fGenIType_Type; const std::unique_ptr fGenUType_Type; const std::unique_ptr fGenBType_Type; const std::unique_ptr fMat_Type; const std::unique_ptr fVec_Type; const std::unique_ptr fGVec_Type; const std::unique_ptr fGVec2_Type; const std::unique_ptr fGVec3_Type; const std::unique_ptr fGVec4_Type; const std::unique_ptr fDVec_Type; const std::unique_ptr fIVec_Type; const std::unique_ptr fUVec_Type; const std::unique_ptr fBVec_Type; const std::unique_ptr fSkCaps_Type; const std::unique_ptr fSkArgs_Type; const std::unique_ptr fColorSpaceXform_Type; // dummy expression used to mark that a variable has a value during dataflow analysis (when it // could have several different values, or the analyzer is otherwise unable to assign it a // specific expression) const std::unique_ptr fDefined_Expression; private: class Defined : public Expression { public: Defined(const Type& type) : INHERITED(Position(), kDefined_Kind, type) {} bool hasSideEffects() const override { return false; } String description() const override { return String(""); } typedef Expression INHERITED; }; }; } // namespace #endif