Use C++ containers for builtin versioning
Removes some of the pointers/"end markes" used in the BuiltInFuntion versioning, replacing them with std::arrays and spans. NOTE: The span class used is a copy of the span class that has been in use in the Vulkan-ValidationLayers as a temporary solution until C++20 is available. NOTE: The std::arrays could be constexprs, but this requires some extra work pre-C++20, and is therefore not included in this change, but could be done in a follow up PR.
This commit is contained in:
parent
a91631b260
commit
0ae8960087
2 changed files with 239 additions and 156 deletions
|
|
@ -52,6 +52,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "Initialize.h"
|
#include "Initialize.h"
|
||||||
|
#include "span.h"
|
||||||
|
|
||||||
namespace glslang {
|
namespace glslang {
|
||||||
|
|
||||||
|
|
@ -139,20 +140,17 @@ struct Versioning {
|
||||||
EProfile EDesktopProfile = static_cast<EProfile>(ENoProfile | ECoreProfile | ECompatibilityProfile);
|
EProfile EDesktopProfile = static_cast<EProfile>(ENoProfile | ECoreProfile | ECompatibilityProfile);
|
||||||
|
|
||||||
// Declare pointers to put into the table for versioning.
|
// Declare pointers to put into the table for versioning.
|
||||||
const Versioning Es300Desktop130Version[] = { { EEsProfile, 0, 300, 0, nullptr },
|
const std::array Es300Desktop130Version = { Versioning{ EEsProfile, 0, 300, 0, nullptr },
|
||||||
{ EDesktopProfile, 0, 130, 0, nullptr },
|
Versioning{ EDesktopProfile, 0, 130, 0, nullptr },
|
||||||
{ EBadProfile } };
|
};
|
||||||
const Versioning* Es300Desktop130 = &Es300Desktop130Version[0];
|
|
||||||
|
|
||||||
const Versioning Es310Desktop400Version[] = { { EEsProfile, 0, 310, 0, nullptr },
|
const std::array Es310Desktop400Version = { Versioning{ EEsProfile, 0, 310, 0, nullptr },
|
||||||
{ EDesktopProfile, 0, 400, 0, nullptr },
|
Versioning{ EDesktopProfile, 0, 400, 0, nullptr },
|
||||||
{ EBadProfile } };
|
};
|
||||||
const Versioning* Es310Desktop400 = &Es310Desktop400Version[0];
|
|
||||||
|
|
||||||
const Versioning Es310Desktop450Version[] = { { EEsProfile, 0, 310, 0, nullptr },
|
const std::array Es310Desktop450Version = { Versioning{ EEsProfile, 0, 310, 0, nullptr },
|
||||||
{ EDesktopProfile, 0, 450, 0, nullptr },
|
Versioning{ EDesktopProfile, 0, 450, 0, nullptr },
|
||||||
{ EBadProfile } };
|
};
|
||||||
const Versioning* Es310Desktop450 = &Es310Desktop450Version[0];
|
|
||||||
|
|
||||||
// The main descriptor of what a set of function prototypes can look like, and
|
// The main descriptor of what a set of function prototypes can look like, and
|
||||||
// a pointer to extra versioning information, when needed.
|
// a pointer to extra versioning information, when needed.
|
||||||
|
|
@ -162,7 +160,7 @@ struct BuiltInFunction {
|
||||||
int numArguments; // number of arguments (overloads with varying arguments need different entries)
|
int numArguments; // number of arguments (overloads with varying arguments need different entries)
|
||||||
ArgType types; // ArgType mask
|
ArgType types; // ArgType mask
|
||||||
ArgClass classes; // the ways this particular function entry manifests
|
ArgClass classes; // the ways this particular function entry manifests
|
||||||
const Versioning* versioning; // nullptr means always a valid version
|
const span<const Versioning> versioning; // An empty span means always a valid version
|
||||||
};
|
};
|
||||||
|
|
||||||
// The tables can have the same built-in function name more than one time,
|
// The tables can have the same built-in function name more than one time,
|
||||||
|
|
@ -174,151 +172,146 @@ struct BuiltInFunction {
|
||||||
//
|
//
|
||||||
// Table is terminated by an OpNull TOperator.
|
// Table is terminated by an OpNull TOperator.
|
||||||
|
|
||||||
const BuiltInFunction BaseFunctions[] = {
|
const std::array BaseFunctions = {
|
||||||
// TOperator, name, arg-count, ArgType, ArgClass, versioning
|
// TOperator, name, arg-count, ArgType, ArgClass, versioning
|
||||||
// --------- ---- --------- ------- -------- ----------
|
// --------- ---- --------- ------- -------- ----------
|
||||||
{ EOpRadians, "radians", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpRadians, "radians", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpDegrees, "degrees", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpDegrees, "degrees", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpSin, "sin", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpSin, "sin", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpCos, "cos", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpCos, "cos", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpTan, "tan", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpTan, "tan", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpAsin, "asin", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpAsin, "asin", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpAcos, "acos", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpAcos, "acos", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpAtan, "atan", 2, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpAtan, "atan", 2, TypeF, ClassRegular, {} },
|
||||||
{ EOpAtan, "atan", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpAtan, "atan", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpPow, "pow", 2, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpPow, "pow", 2, TypeF, ClassRegular, {} },
|
||||||
{ EOpExp, "exp", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpExp, "exp", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpLog, "log", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpLog, "log", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpExp2, "exp2", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpExp2, "exp2", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpLog2, "log2", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpLog2, "log2", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpSqrt, "sqrt", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpSqrt, "sqrt", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpInverseSqrt, "inversesqrt", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpInverseSqrt, "inversesqrt", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpAbs, "abs", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpAbs, "abs", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpSign, "sign", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpSign, "sign", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpFloor, "floor", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpFloor, "floor", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpCeil, "ceil", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpCeil, "ceil", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpFract, "fract", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpFract, "fract", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpMod, "mod", 2, TypeF, ClassLS, nullptr },
|
BuiltInFunction{ EOpMod, "mod", 2, TypeF, ClassLS, {} },
|
||||||
{ EOpMin, "min", 2, TypeF, ClassLS, nullptr },
|
BuiltInFunction{ EOpMin, "min", 2, TypeF, ClassLS, {} },
|
||||||
{ EOpMax, "max", 2, TypeF, ClassLS, nullptr },
|
BuiltInFunction{ EOpMax, "max", 2, TypeF, ClassLS, {} },
|
||||||
{ EOpClamp, "clamp", 3, TypeF, ClassLS2, nullptr },
|
BuiltInFunction{ EOpClamp, "clamp", 3, TypeF, ClassLS2, {} },
|
||||||
{ EOpMix, "mix", 3, TypeF, ClassLS, nullptr },
|
BuiltInFunction{ EOpMix, "mix", 3, TypeF, ClassLS, {} },
|
||||||
{ EOpStep, "step", 2, TypeF, ClassFS, nullptr },
|
BuiltInFunction{ EOpStep, "step", 2, TypeF, ClassFS, {} },
|
||||||
{ EOpSmoothStep, "smoothstep", 3, TypeF, ClassFS2, nullptr },
|
BuiltInFunction{ EOpSmoothStep, "smoothstep", 3, TypeF, ClassFS2, {} },
|
||||||
{ EOpNormalize, "normalize", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpNormalize, "normalize", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpFaceForward, "faceforward", 3, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpFaceForward, "faceforward", 3, TypeF, ClassRegular, {} },
|
||||||
{ EOpReflect, "reflect", 2, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpReflect, "reflect", 2, TypeF, ClassRegular, {} },
|
||||||
{ EOpRefract, "refract", 3, TypeF, ClassXLS, nullptr },
|
BuiltInFunction{ EOpRefract, "refract", 3, TypeF, ClassXLS, {} },
|
||||||
{ EOpLength, "length", 1, TypeF, ClassRS, nullptr },
|
BuiltInFunction{ EOpLength, "length", 1, TypeF, ClassRS, {} },
|
||||||
{ EOpDistance, "distance", 2, TypeF, ClassRS, nullptr },
|
BuiltInFunction{ EOpDistance, "distance", 2, TypeF, ClassRS, {} },
|
||||||
{ EOpDot, "dot", 2, TypeF, ClassRS, nullptr },
|
BuiltInFunction{ EOpDot, "dot", 2, TypeF, ClassRS, {} },
|
||||||
{ EOpCross, "cross", 2, TypeF, ClassV3, nullptr },
|
BuiltInFunction{ EOpCross, "cross", 2, TypeF, ClassV3, {} },
|
||||||
{ EOpLessThan, "lessThan", 2, TypeFI, ClassBNS, nullptr },
|
BuiltInFunction{ EOpLessThan, "lessThan", 2, TypeFI, ClassBNS, {} },
|
||||||
{ EOpLessThanEqual, "lessThanEqual", 2, TypeFI, ClassBNS, nullptr },
|
BuiltInFunction{ EOpLessThanEqual, "lessThanEqual", 2, TypeFI, ClassBNS, {} },
|
||||||
{ EOpGreaterThan, "greaterThan", 2, TypeFI, ClassBNS, nullptr },
|
BuiltInFunction{ EOpGreaterThan, "greaterThan", 2, TypeFI, ClassBNS, {} },
|
||||||
{ EOpGreaterThanEqual, "greaterThanEqual", 2, TypeFI, ClassBNS, nullptr },
|
BuiltInFunction{ EOpGreaterThanEqual, "greaterThanEqual", 2, TypeFI, ClassBNS, {} },
|
||||||
{ EOpVectorEqual, "equal", 2, TypeFIB, ClassBNS, nullptr },
|
BuiltInFunction{ EOpVectorEqual, "equal", 2, TypeFIB, ClassBNS, {} },
|
||||||
{ EOpVectorNotEqual, "notEqual", 2, TypeFIB, ClassBNS, nullptr },
|
BuiltInFunction{ EOpVectorNotEqual, "notEqual", 2, TypeFIB, ClassBNS, {} },
|
||||||
{ EOpAny, "any", 1, TypeB, ClassRSNS, nullptr },
|
BuiltInFunction{ EOpAny, "any", 1, TypeB, ClassRSNS, {} },
|
||||||
{ EOpAll, "all", 1, TypeB, ClassRSNS, nullptr },
|
BuiltInFunction{ EOpAll, "all", 1, TypeB, ClassRSNS, {} },
|
||||||
{ EOpVectorLogicalNot, "not", 1, TypeB, ClassNS, nullptr },
|
BuiltInFunction{ EOpVectorLogicalNot, "not", 1, TypeB, ClassNS, {} },
|
||||||
{ EOpSinh, "sinh", 1, TypeF, ClassRegular, Es300Desktop130 },
|
BuiltInFunction{ EOpSinh, "sinh", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
|
||||||
{ EOpCosh, "cosh", 1, TypeF, ClassRegular, Es300Desktop130 },
|
BuiltInFunction{ EOpCosh, "cosh", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
|
||||||
{ EOpTanh, "tanh", 1, TypeF, ClassRegular, Es300Desktop130 },
|
BuiltInFunction{ EOpTanh, "tanh", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
|
||||||
{ EOpAsinh, "asinh", 1, TypeF, ClassRegular, Es300Desktop130 },
|
BuiltInFunction{ EOpAsinh, "asinh", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
|
||||||
{ EOpAcosh, "acosh", 1, TypeF, ClassRegular, Es300Desktop130 },
|
BuiltInFunction{ EOpAcosh, "acosh", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
|
||||||
{ EOpAtanh, "atanh", 1, TypeF, ClassRegular, Es300Desktop130 },
|
BuiltInFunction{ EOpAtanh, "atanh", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
|
||||||
{ EOpAbs, "abs", 1, TypeI, ClassRegular, Es300Desktop130 },
|
BuiltInFunction{ EOpAbs, "abs", 1, TypeI, ClassRegular, {Es300Desktop130Version} },
|
||||||
{ EOpSign, "sign", 1, TypeI, ClassRegular, Es300Desktop130 },
|
BuiltInFunction{ EOpSign, "sign", 1, TypeI, ClassRegular, {Es300Desktop130Version} },
|
||||||
{ EOpTrunc, "trunc", 1, TypeF, ClassRegular, Es300Desktop130 },
|
BuiltInFunction{ EOpTrunc, "trunc", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
|
||||||
{ EOpRound, "round", 1, TypeF, ClassRegular, Es300Desktop130 },
|
BuiltInFunction{ EOpRound, "round", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
|
||||||
{ EOpRoundEven, "roundEven", 1, TypeF, ClassRegular, Es300Desktop130 },
|
BuiltInFunction{ EOpRoundEven, "roundEven", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
|
||||||
{ EOpModf, "modf", 2, TypeF, ClassLO, Es300Desktop130 },
|
BuiltInFunction{ EOpModf, "modf", 2, TypeF, ClassLO, {Es300Desktop130Version} },
|
||||||
{ EOpMin, "min", 2, TypeIU, ClassLS, Es300Desktop130 },
|
BuiltInFunction{ EOpMin, "min", 2, TypeIU, ClassLS, {Es300Desktop130Version} },
|
||||||
{ EOpMax, "max", 2, TypeIU, ClassLS, Es300Desktop130 },
|
BuiltInFunction{ EOpMax, "max", 2, TypeIU, ClassLS, {Es300Desktop130Version} },
|
||||||
{ EOpClamp, "clamp", 3, TypeIU, ClassLS2, Es300Desktop130 },
|
BuiltInFunction{ EOpClamp, "clamp", 3, TypeIU, ClassLS2, {Es300Desktop130Version} },
|
||||||
{ EOpMix, "mix", 3, TypeF, ClassLB, Es300Desktop130 },
|
BuiltInFunction{ EOpMix, "mix", 3, TypeF, ClassLB, {Es300Desktop130Version} },
|
||||||
{ EOpIsInf, "isinf", 1, TypeF, ClassB, Es300Desktop130 },
|
BuiltInFunction{ EOpIsInf, "isinf", 1, TypeF, ClassB, {Es300Desktop130Version} },
|
||||||
{ EOpIsNan, "isnan", 1, TypeF, ClassB, Es300Desktop130 },
|
BuiltInFunction{ EOpIsNan, "isnan", 1, TypeF, ClassB, {Es300Desktop130Version} },
|
||||||
{ EOpLessThan, "lessThan", 2, TypeU, ClassBNS, Es300Desktop130 },
|
BuiltInFunction{ EOpLessThan, "lessThan", 2, TypeU, ClassBNS, {Es300Desktop130Version} },
|
||||||
{ EOpLessThanEqual, "lessThanEqual", 2, TypeU, ClassBNS, Es300Desktop130 },
|
BuiltInFunction{ EOpLessThanEqual, "lessThanEqual", 2, TypeU, ClassBNS, {Es300Desktop130Version} },
|
||||||
{ EOpGreaterThan, "greaterThan", 2, TypeU, ClassBNS, Es300Desktop130 },
|
BuiltInFunction{ EOpGreaterThan, "greaterThan", 2, TypeU, ClassBNS, {Es300Desktop130Version} },
|
||||||
{ EOpGreaterThanEqual, "greaterThanEqual", 2, TypeU, ClassBNS, Es300Desktop130 },
|
BuiltInFunction{ EOpGreaterThanEqual, "greaterThanEqual", 2, TypeU, ClassBNS, {Es300Desktop130Version} },
|
||||||
{ EOpVectorEqual, "equal", 2, TypeU, ClassBNS, Es300Desktop130 },
|
BuiltInFunction{ EOpVectorEqual, "equal", 2, TypeU, ClassBNS, {Es300Desktop130Version} },
|
||||||
{ EOpVectorNotEqual, "notEqual", 2, TypeU, ClassBNS, Es300Desktop130 },
|
BuiltInFunction{ EOpVectorNotEqual, "notEqual", 2, TypeU, ClassBNS, {Es300Desktop130Version} },
|
||||||
{ EOpAtomicAdd, "atomicAdd", 2, TypeIU, ClassV1FIOCV, Es310Desktop400 },
|
BuiltInFunction{ EOpAtomicAdd, "atomicAdd", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
|
||||||
{ EOpAtomicMin, "atomicMin", 2, TypeIU, ClassV1FIOCV, Es310Desktop400 },
|
BuiltInFunction{ EOpAtomicMin, "atomicMin", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
|
||||||
{ EOpAtomicMax, "atomicMax", 2, TypeIU, ClassV1FIOCV, Es310Desktop400 },
|
BuiltInFunction{ EOpAtomicMax, "atomicMax", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
|
||||||
{ EOpAtomicAnd, "atomicAnd", 2, TypeIU, ClassV1FIOCV, Es310Desktop400 },
|
BuiltInFunction{ EOpAtomicAnd, "atomicAnd", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
|
||||||
{ EOpAtomicOr, "atomicOr", 2, TypeIU, ClassV1FIOCV, Es310Desktop400 },
|
BuiltInFunction{ EOpAtomicOr, "atomicOr", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
|
||||||
{ EOpAtomicXor, "atomicXor", 2, TypeIU, ClassV1FIOCV, Es310Desktop400 },
|
BuiltInFunction{ EOpAtomicXor, "atomicXor", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
|
||||||
{ EOpAtomicExchange, "atomicExchange", 2, TypeIU, ClassV1FIOCV, Es310Desktop400 },
|
BuiltInFunction{ EOpAtomicExchange, "atomicExchange", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
|
||||||
{ EOpAtomicCompSwap, "atomicCompSwap", 3, TypeIU, ClassV1FIOCV, Es310Desktop400 },
|
BuiltInFunction{ EOpAtomicCompSwap, "atomicCompSwap", 3, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
|
||||||
{ EOpMix, "mix", 3, TypeB, ClassRegular, Es310Desktop450 },
|
BuiltInFunction{ EOpMix, "mix", 3, TypeB, ClassRegular, {Es310Desktop450Version} },
|
||||||
{ EOpMix, "mix", 3, TypeIU, ClassLB, Es310Desktop450 },
|
BuiltInFunction{ EOpMix, "mix", 3, TypeIU, ClassLB, {Es310Desktop450Version} },
|
||||||
|
|
||||||
{ EOpNull }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const BuiltInFunction DerivativeFunctions[] = {
|
const std::array DerivativeFunctions = {
|
||||||
{ EOpDPdx, "dFdx", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpDPdx, "dFdx", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpDPdy, "dFdy", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpDPdy, "dFdy", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpFwidth, "fwidth", 1, TypeF, ClassRegular, nullptr },
|
BuiltInFunction{ EOpFwidth, "fwidth", 1, TypeF, ClassRegular, {} },
|
||||||
{ EOpNull }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// For functions declared some other way, but still use the table to relate to operator.
|
// For functions declared some other way, but still use the table to relate to operator.
|
||||||
struct CustomFunction {
|
struct CustomFunction {
|
||||||
TOperator op; // operator to map the name to
|
TOperator op; // operator to map the name to
|
||||||
const char* name; // function name
|
const char* name; // function name
|
||||||
const Versioning* versioning; // nullptr means always a valid version
|
const span<const Versioning> versioning; // An empty span means always a valid version
|
||||||
};
|
};
|
||||||
|
|
||||||
const CustomFunction CustomFunctions[] = {
|
const CustomFunction CustomFunctions[] = {
|
||||||
{ EOpBarrier, "barrier", nullptr },
|
{ EOpBarrier, "barrier", {} },
|
||||||
{ EOpMemoryBarrierShared, "memoryBarrierShared", nullptr },
|
{ EOpMemoryBarrierShared, "memoryBarrierShared", {} },
|
||||||
{ EOpGroupMemoryBarrier, "groupMemoryBarrier", nullptr },
|
{ EOpGroupMemoryBarrier, "groupMemoryBarrier", {} },
|
||||||
{ EOpMemoryBarrier, "memoryBarrier", nullptr },
|
{ EOpMemoryBarrier, "memoryBarrier", {} },
|
||||||
{ EOpMemoryBarrierBuffer, "memoryBarrierBuffer", nullptr },
|
{ EOpMemoryBarrierBuffer, "memoryBarrierBuffer", {} },
|
||||||
|
|
||||||
{ EOpPackSnorm2x16, "packSnorm2x16", nullptr },
|
{ EOpPackSnorm2x16, "packSnorm2x16", {} },
|
||||||
{ EOpUnpackSnorm2x16, "unpackSnorm2x16", nullptr },
|
{ EOpUnpackSnorm2x16, "unpackSnorm2x16", {} },
|
||||||
{ EOpPackUnorm2x16, "packUnorm2x16", nullptr },
|
{ EOpPackUnorm2x16, "packUnorm2x16", {} },
|
||||||
{ EOpUnpackUnorm2x16, "unpackUnorm2x16", nullptr },
|
{ EOpUnpackUnorm2x16, "unpackUnorm2x16", {} },
|
||||||
{ EOpPackHalf2x16, "packHalf2x16", nullptr },
|
{ EOpPackHalf2x16, "packHalf2x16", {} },
|
||||||
{ EOpUnpackHalf2x16, "unpackHalf2x16", nullptr },
|
{ EOpUnpackHalf2x16, "unpackHalf2x16", {} },
|
||||||
|
|
||||||
{ EOpMul, "matrixCompMult", nullptr },
|
{ EOpMul, "matrixCompMult", {} },
|
||||||
{ EOpOuterProduct, "outerProduct", nullptr },
|
{ EOpOuterProduct, "outerProduct", {} },
|
||||||
{ EOpTranspose, "transpose", nullptr },
|
{ EOpTranspose, "transpose", {} },
|
||||||
{ EOpDeterminant, "determinant", nullptr },
|
{ EOpDeterminant, "determinant", {} },
|
||||||
{ EOpMatrixInverse, "inverse", nullptr },
|
{ EOpMatrixInverse, "inverse", {} },
|
||||||
{ EOpFloatBitsToInt, "floatBitsToInt", nullptr },
|
{ EOpFloatBitsToInt, "floatBitsToInt", {} },
|
||||||
{ EOpFloatBitsToUint, "floatBitsToUint", nullptr },
|
{ EOpFloatBitsToUint, "floatBitsToUint", {} },
|
||||||
{ EOpIntBitsToFloat, "intBitsToFloat", nullptr },
|
{ EOpIntBitsToFloat, "intBitsToFloat", {} },
|
||||||
{ EOpUintBitsToFloat, "uintBitsToFloat", nullptr },
|
{ EOpUintBitsToFloat, "uintBitsToFloat", {} },
|
||||||
|
|
||||||
{ EOpTextureQuerySize, "textureSize", nullptr },
|
{ EOpTextureQuerySize, "textureSize", {} },
|
||||||
{ EOpTextureQueryLod, "textureQueryLod", nullptr },
|
{ EOpTextureQueryLod, "textureQueryLod", {} },
|
||||||
{ EOpTextureQueryLod, "textureQueryLOD", nullptr }, // extension GL_ARB_texture_query_lod
|
{ EOpTextureQueryLod, "textureQueryLOD", {} }, // extension GL_ARB_texture_query_lod
|
||||||
{ EOpTextureQueryLevels, "textureQueryLevels", nullptr },
|
{ EOpTextureQueryLevels, "textureQueryLevels", {} },
|
||||||
{ EOpTextureQuerySamples, "textureSamples", nullptr },
|
{ EOpTextureQuerySamples, "textureSamples", {} },
|
||||||
{ EOpTexture, "texture", nullptr },
|
{ EOpTexture, "texture", {} },
|
||||||
{ EOpTextureProj, "textureProj", nullptr },
|
{ EOpTextureProj, "textureProj", {} },
|
||||||
{ EOpTextureLod, "textureLod", nullptr },
|
{ EOpTextureLod, "textureLod", {} },
|
||||||
{ EOpTextureOffset, "textureOffset", nullptr },
|
{ EOpTextureOffset, "textureOffset", {} },
|
||||||
{ EOpTextureFetch, "texelFetch", nullptr },
|
{ EOpTextureFetch, "texelFetch", {} },
|
||||||
{ EOpTextureFetchOffset, "texelFetchOffset", nullptr },
|
{ EOpTextureFetchOffset, "texelFetchOffset", {} },
|
||||||
{ EOpTextureProjOffset, "textureProjOffset", nullptr },
|
{ EOpTextureProjOffset, "textureProjOffset", {} },
|
||||||
{ EOpTextureLodOffset, "textureLodOffset", nullptr },
|
{ EOpTextureLodOffset, "textureLodOffset", {} },
|
||||||
{ EOpTextureProjLod, "textureProjLod", nullptr },
|
{ EOpTextureProjLod, "textureProjLod", {} },
|
||||||
{ EOpTextureProjLodOffset, "textureProjLodOffset", nullptr },
|
{ EOpTextureProjLodOffset, "textureProjLodOffset", {} },
|
||||||
{ EOpTextureGrad, "textureGrad", nullptr },
|
{ EOpTextureGrad, "textureGrad", {} },
|
||||||
{ EOpTextureGradOffset, "textureGradOffset", nullptr },
|
{ EOpTextureGradOffset, "textureGradOffset", {} },
|
||||||
{ EOpTextureProjGrad, "textureProjGrad", nullptr },
|
{ EOpTextureProjGrad, "textureProjGrad", {} },
|
||||||
{ EOpTextureProjGradOffset, "textureProjGradOffset", nullptr },
|
{ EOpTextureProjGradOffset, "textureProjGradOffset", {} },
|
||||||
|
|
||||||
{ EOpNull }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// For the given table of functions, add all the indicated prototypes for each
|
// For the given table of functions, add all the indicated prototypes for each
|
||||||
|
|
@ -403,13 +396,13 @@ void AddTabledBuiltin(TString& decls, const BuiltInFunction& function)
|
||||||
bool ValidVersion(const BuiltInFunction& function, int version, EProfile profile, const SpvVersion& /* spVersion */)
|
bool ValidVersion(const BuiltInFunction& function, int version, EProfile profile, const SpvVersion& /* spVersion */)
|
||||||
{
|
{
|
||||||
// nullptr means always valid
|
// nullptr means always valid
|
||||||
if (function.versioning == nullptr)
|
if (function.versioning.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// check for what is said about our current profile
|
// check for what is said about our current profile
|
||||||
for (const Versioning* v = function.versioning; v->profiles != EBadProfile; ++v) {
|
for (const auto& v : function.versioning) {
|
||||||
if ((v->profiles & profile) != 0) {
|
if ((v.profiles & profile) != 0) {
|
||||||
if (v->minCoreVersion <= version || (v->numExtensions > 0 && v->minExtendedVersion <= version))
|
if (v.minCoreVersion <= version || (v.numExtensions > 0 && v.minExtendedVersion <= version))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -422,12 +415,11 @@ bool ValidVersion(const BuiltInFunction& function, int version, EProfile profile
|
||||||
// called once per stage). This is a performance issue only, not a correctness
|
// called once per stage). This is a performance issue only, not a correctness
|
||||||
// concern. It is done for quality arising from simplicity, as there are subtleties
|
// concern. It is done for quality arising from simplicity, as there are subtleties
|
||||||
// to get correct if instead trying to do it surgically.
|
// to get correct if instead trying to do it surgically.
|
||||||
template<class FunctionT>
|
template<class FunctionContainer>
|
||||||
void RelateTabledBuiltins(const FunctionT* functions, TSymbolTable& symbolTable)
|
void RelateTabledBuiltins(const FunctionContainer& functions, TSymbolTable& symbolTable)
|
||||||
{
|
{
|
||||||
while (functions->op != EOpNull) {
|
for (const auto& fn : functions) {
|
||||||
symbolTable.relateToOperator(functions->name, functions->op);
|
symbolTable.relateToOperator(fn.name, fn.op);
|
||||||
++functions;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -436,11 +428,10 @@ void RelateTabledBuiltins(const FunctionT* functions, TSymbolTable& symbolTable)
|
||||||
// Add declarations for all tables of built-in functions.
|
// Add declarations for all tables of built-in functions.
|
||||||
void TBuiltIns::addTabledBuiltins(int version, EProfile profile, const SpvVersion& spvVersion)
|
void TBuiltIns::addTabledBuiltins(int version, EProfile profile, const SpvVersion& spvVersion)
|
||||||
{
|
{
|
||||||
const auto forEachFunction = [&](TString& decls, const BuiltInFunction* function) {
|
const auto forEachFunction = [&](TString& decls, const span<const BuiltInFunction>& functions) {
|
||||||
while (function->op != EOpNull) {
|
for (const auto& fn : functions) {
|
||||||
if (ValidVersion(*function, version, profile, spvVersion))
|
if (ValidVersion(fn, version, profile, spvVersion))
|
||||||
AddTabledBuiltin(decls, *function);
|
AddTabledBuiltin(decls, fn);
|
||||||
++function;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
92
glslang/MachineIndependent/span.h
Normal file
92
glslang/MachineIndependent/span.h
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//
|
||||||
|
// Copyright (C) 2023 LunarG, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
// Partial implementation of std::span for C++11
|
||||||
|
// Replace with std::span if repo standard is bumped to C++20
|
||||||
|
//
|
||||||
|
// This code was copied from https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/main/layers/containers/custom_containers.h
|
||||||
|
template <typename T>
|
||||||
|
class span {
|
||||||
|
public:
|
||||||
|
using pointer = T *;
|
||||||
|
using const_pointer = T const *;
|
||||||
|
using iterator = pointer;
|
||||||
|
using const_iterator = const_pointer;
|
||||||
|
|
||||||
|
span() = default;
|
||||||
|
span(pointer start, size_t n) : data_(start), count_(n) {}
|
||||||
|
template <typename Iterator>
|
||||||
|
span(Iterator start, Iterator end) : data_(&(*start)), count_(end - start) {}
|
||||||
|
template <typename Container>
|
||||||
|
span(Container &c) : data_(c.data()), count_(c.size()) {}
|
||||||
|
|
||||||
|
iterator begin() { return data_; }
|
||||||
|
const_iterator begin() const { return data_; }
|
||||||
|
|
||||||
|
iterator end() { return data_ + count_; }
|
||||||
|
const_iterator end() const { return data_ + count_; }
|
||||||
|
|
||||||
|
T &operator[](int i) { return data_[i]; }
|
||||||
|
const T &operator[](int i) const { return data_[i]; }
|
||||||
|
|
||||||
|
T &front() { return *data_; }
|
||||||
|
const T &front() const { return *data_; }
|
||||||
|
|
||||||
|
T &back() { return *(data_ + (count_ - 1)); }
|
||||||
|
const T &back() const { return *(data_ + (count_ - 1)); }
|
||||||
|
|
||||||
|
size_t size() const { return count_; }
|
||||||
|
bool empty() const { return count_ == 0; }
|
||||||
|
|
||||||
|
pointer data() { return data_; }
|
||||||
|
const_pointer data() const { return data_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
pointer data_ = {};
|
||||||
|
size_t count_ = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Allow type inference that using the constructor doesn't allow in C++11
|
||||||
|
template <typename T>
|
||||||
|
span<T> make_span(T *begin, size_t count) {
|
||||||
|
return span<T>(begin, count);
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
span<T> make_span(T *begin, T *end) {
|
||||||
|
return make_span<T>(begin, end);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue