17using namespace blender::gpu::shader::parser;
18using namespace blender::gpu::shader::parser::ast;
20using Token = blender::gpu::shader::parser::Token;
26 register_builtins(
node);
31 std::optional<AstNodeException> err;
40 if (!
list.is_valid()) {
44 if (
list.is_valid()) {
49 else if (
init.next().is_valid()) {
67 std::optional<AstNodeException> err;
82 if (type->template_data) {
90 auto [type_, _, err_] = type->template_data->lookup_inst(list_nested, scope, *
this);
101 result.str +=
"T" + type->identifier;
102 result.str_debug +=
", " + type->identifier;
108 if (!expr_result.is_constexpr()) {
111 int val = expr_result.value.comp_as<
int>(0);
113 if (arg.type().str() ==
"bool") {
114 result.str += string(
"T") + (val ?
"true" :
"false");
121 param = param.
next();
129 bool allow_compilation_constant)
const
131 const char *expr_type = allow_compilation_constant ?
"static branch condition" :
132 "constant expression";
133 std::optional<AstNodeException> error;
135 for (
Node child = start; child.
is_valid(); child = child.next()) {
136 switch (child.type()) {
168 expr_str +=
"SRT_CONSTANT_" + var->
identifier;
195 expr_str += child.str();
207 return {expr_str, error};
214 struct BuiltinBasicType {
239 for (
const auto &t : basic_types) {
240 SymbolClass *cls =
cls_arena.alloc(
root, tok, t.id, t.size, t.align, t.cls);
241 cls->is_std140_compatible = t.align == 4;
242 cls->is_std430_compatible = t.align == 4;
261 const vector<BuiltinBasicType> special_types = {
266 {
"samplerBuffer", 0, 1},
270 {
"isamplerBuffer", 0, 1},
271 {
"isampler1D", 0, 1},
272 {
"isampler2D", 0, 1},
273 {
"isampler3D", 0, 1},
274 {
"usamplerBuffer", 0, 1},
275 {
"usampler1D", 0, 1},
276 {
"usampler2D", 0, 1},
277 {
"usampler3D", 0, 1},
278 {
"sampler1DArray", 0, 1},
279 {
"sampler2DArray", 0, 1},
280 {
"isampler1DArray", 0, 1},
281 {
"isampler2DArray", 0, 1},
282 {
"usampler1DArray", 0, 1},
283 {
"usampler2DArray", 0, 1},
284 {
"samplerCube", 0, 1},
285 {
"isamplerCube", 0, 1},
286 {
"usamplerCube", 0, 1},
287 {
"samplerCubeArray", 0, 1},
288 {
"isamplerCubeArray", 0, 1},
289 {
"usamplerCubeArray", 0, 1},
290 {
"usampler1DAtomic", 0, 1},
291 {
"usampler2DAtomic", 0, 1},
292 {
"usampler2DArrayAtomic", 0, 1},
293 {
"usampler3DAtomic", 0, 1},
294 {
"isampler1DAtomic", 0, 1},
295 {
"isampler2DAtomic", 0, 1},
296 {
"isampler2DArrayAtomic", 0, 1},
297 {
"isampler3DAtomic", 0, 1},
298 {
"sampler2DDepth", 0, 1},
299 {
"sampler2DArrayDepth", 0, 1},
300 {
"samplerCubeDepth", 0, 1},
301 {
"samplerCubeArrayDepth", 0, 1},
311 {
"image1DArray", 0, 1},
312 {
"image2DArray", 0, 1},
313 {
"iimage1DArray", 0, 1},
314 {
"iimage2DArray", 0, 1},
315 {
"uimage1DArray", 0, 1},
316 {
"uimage2DArray", 0, 1},
317 {
"iimage2DAtomic", 0, 1},
318 {
"iimage3DAtomic", 0, 1},
319 {
"uimage2DAtomic", 0, 1},
320 {
"uimage3DAtomic", 0, 1},
321 {
"iimage2DArrayAtomic", 0, 1},
322 {
"uimage2DArrayAtomic", 0, 1},
325 {
"accelerationStructure", 0, 1},
327 {
"ShaderCreateInfo", 1, 1},
330 for (
const auto &t : special_types) {
333 sym->is_opaque =
true;
340 struct BuiltinVector {
345 builtin::ClassId cls_id;
348 const char *swizzle_xyzw[4] = {
"x",
"y",
"z",
"w"};
349 const char *swizzle_rgba[4] = {
"r",
"g",
"b",
"a"};
351 auto generate_vector = [&](
const BuiltinVector &t,
const bool do_swizzle) {
352 SymbolClass *base = t.base;
353 SymbolClass *cls =
cls_arena.alloc(
root, tok, t.id, t.comp * base->size, t.align, t.cls_id);
357 cls->is_std140_compatible = t.align >= 8 && t.id !=
"float3" && base->is_std140_compatible;
358 cls->is_std430_compatible = cls->is_std140_compatible;
360 SymbolFunction *sub_op =
fun_arena.alloc(
363 cls->operator_subscript = sub_op;
365 cls->comp_len = t.comp * base->comp_len;
367 for (
int i = 0; i < t.comp && do_swizzle; i++) {
368 string id_xyzw(swizzle_xyzw[i]);
369 cls->variables.emplace(id_xyzw,
var_arena.alloc(cls, base, tok, id_xyzw));
370 string id_rgba(swizzle_rgba[i]);
371 cls->variables.emplace(id_rgba,
var_arena.alloc(cls, base, tok, id_rgba));
375 const std::vector<BuiltinVector> vectors = {
411 for (
const auto &t : vectors) {
412 generate_vector(t,
true);
447 const std::vector<BuiltinVector> matrices = {
459 for (
const auto &t : matrices) {
460 generate_vector(t,
false);
480 for (
const auto &[name, base, comp, __, ___] : vectors) {
482 auto generate_swizzles =
483 [&](
auto &self,
string current,
int target_length,
auto swizzle) ->
void {
484 if (current.length() == target_length) {
486 string return_type_id = base->identifier +
to_string(target_length);
488 SymbolVariable var(type,
root->
classes[return_type_id], tok, current);
492 type->variables.emplace(current,
var_arena.alloc(var));
493 type->functions.emplace(current,
fun_arena.alloc(fun));
497 for (
int i = 0; i <
comp; i++) {
498 self(self, current + swizzle[i], target_length, swizzle);
503 generate_swizzles(generate_swizzles,
"",
len, swizzle_xyzw);
504 generate_swizzles(generate_swizzles,
"",
len, swizzle_rgba);
508 auto builtin_function_decl =
509 [&](
const BuiltinFunc &fn,
bool allow_vector_promotion,
bool is_constexpr) {
513 sym->allow_vector_promotion = allow_vector_promotion;
514 sym->is_constexpr = is_constexpr;
515 sym->is_builtin =
true;
516 sym->reserve_arguments(fn.arg_types.size());
517 for (SymbolClass *arg : fn.arg_types) {
518 sym->add_argument(
true, arg);
523 const vector<BuiltinFunc> functions = generate_all_builtin_functions();
525 for (
const auto &f : functions) {
526 builtin_function_decl(f,
false,
false);
529 const vector<BuiltinFunc> functions_constexpr = generate_all_builtin_constexpr_functions();
530 for (
const auto &f : functions_constexpr) {
531 builtin_function_decl(f,
false,
true);
534 const vector<BuiltinType> builtin_types = generate_builtin_types();
536 const vector<BuiltinFunc> builtin_constructors = generate_all_constructors(builtin_types);
537 for (
const auto &fn : builtin_constructors) {
538 builtin_function_decl(fn,
true,
true);
542 {0,
"SNORM_8"}, {1,
"SNORM_8_8"}, {2,
"SNORM_8_8_8_8"},
543 {3,
"SNORM_16"}, {4,
"SNORM_16_16"}, {5,
"SNORM_16_16_16_16"},
544 {6,
"UNORM_8"}, {7,
"UNORM_8_8"}, {8,
"UNORM_8_8_8_8"},
545 {9,
"UNORM_16"}, {10,
"UNORM_16_16"}, {11,
"UNORM_16_16_16_16"},
546 {12,
"SINT_8"}, {13,
"SINT_8_8"}, {14,
"SINT_8_8_8_8"},
547 {15,
"SINT_16"}, {16,
"SINT_16_16"}, {17,
"SINT_16_16_16_16"},
548 {18,
"SINT_32"}, {19,
"SINT_32_32"}, {20,
"SINT_32_32_32_32"},
549 {21,
"UINT_8"}, {22,
"UINT_8_8"}, {23,
"UINT_8_8_8_8"},
550 {24,
"UINT_16"}, {25,
"UINT_16_16"}, {26,
"UINT_16_16_16_16"},
551 {27,
"UINT_32"}, {28,
"UINT_32_32"}, {29,
"UINT_32_32_32_32"},
552 {30,
"SFLOAT_16"}, {31,
"SFLOAT_16_16"}, {32,
"SFLOAT_16_16_16_16"},
553 {33,
"SFLOAT_32"}, {34,
"SFLOAT_32_32"}, {35,
"SFLOAT_32_32_32_32"},
554 {36,
"UNORM_10_10_10_2"}, {37,
"UINT_10_10_10_2"}, {38,
"UFLOAT_11_11_10"},
557 struct BuiltinConst {
561 ConstexprValue value;
564 std::vector<BuiltinConst> consts = {
577 {
"gpu_RayFlagsTerminateOnFirstHit",
"uint",
false,
ConstexprValue(0)},
578 {
"gpu_RayFlagsSkipClosestHitShader",
"uint",
false,
ConstexprValue(0)},
579 {
"gpu_RayFlagsCullBackFacingTriangles",
"uint",
false,
ConstexprValue(0)},
580 {
"gpu_RayFlagsCullFrontFacingTriangles",
"uint",
false,
ConstexprValue(0)},
583 {
"gpu_RayQueryCommittedIntersectionNone",
"uint",
false,
ConstexprValue(0)},
584 {
"gpu_RayQueryCommittedIntersectionTriangle",
"uint",
false,
ConstexprValue(0)},
585 {
"gpu_RayQueryCommittedIntersectionGenerated",
"uint",
false,
ConstexprValue(0)},
586 {
"gpu_RayQueryCandidateIntersectionTriangle",
"uint",
false,
ConstexprValue(0)},
587 {
"gpu_RayQueryCandidateIntersectionAABB",
"uint",
false,
ConstexprValue(0)},
589 {
"FLT_MAX",
"float",
true,
ConstexprValue(std::bit_cast<float>(0x7F7FFFFFu))},
590 {
"FLT_MIN",
"float",
true,
ConstexprValue(std::bit_cast<float>(0x00800000u))},
602 {
"M_TAU",
"float",
true,
ConstexprValue(6.28318530717958647692f)},
603 {
"M_PI_2",
"float",
true,
ConstexprValue(1.57079632679489661923f)},
604 {
"M_PI_4",
"float",
true,
ConstexprValue(0.78539816339744830962f)},
605 {
"M_SQRT2",
"float",
true,
ConstexprValue(1.41421356237309504880f)},
606 {
"M_SQRT1_2",
"float",
true,
ConstexprValue(0.70710678118654752440f)},
607 {
"M_SQRT3",
"float",
true,
ConstexprValue(1.73205080756887729352f)},
608 {
"M_SQRT1_3",
"float",
true,
ConstexprValue(0.57735026918962576450f)},
609 {
"M_1_PI",
"float",
true,
ConstexprValue(0.318309886183790671538f)},
611 {
"M_LOG2E",
"float",
true,
ConstexprValue(1.4426950408889634074f)},
612 {
"M_LOG10E",
"float",
true,
ConstexprValue(0.43429448190325182765f)},
613 {
"M_LN2",
"float",
true,
ConstexprValue(0.69314718055994530942f)},
614 {
"M_LN10",
"float",
true,
ConstexprValue(2.30258509299404568402f)},
622 for (
auto c : consts) {
625 sym->is_static = c.is_constexpr;
626 sym->is_constexpr = c.is_constexpr;
627 sym->value = c.value;
637 if (lit ==
"true" || lit ==
"false") {
643 str.reserve(lit.size());
645 str.push_back(tolower(
static_cast<unsigned char>(c)));
648 bool is_hex =
str.starts_with(
"0x");
650 bool has_decimal = (
str.find(
'.') != string::npos);
651 bool has_exponent = !is_hex && (
str.find(
'e') != string::npos);
652 bool has_float_suffix = !is_hex && (
str.back() ==
'f');
654 if (has_decimal || has_exponent || has_float_suffix) {
657 if (
str.back() ==
'u') {
665 const bool ctor_conversion)
const
689 const uint16_t from_len = from_raw & LEN_MASK;
690 const uint16_t to_len = to_raw & LEN_MASK;
692 const bool both_numeric = (from_raw & FLAG_NUMERIC) && (to_raw & FLAG_NUMERIC);
694 const uint16_t PROMOTE_MASK = FLAG_INTEGER | FLAG_SIGN;
695 const bool is_promotion = (from_raw & PROMOTE_MASK) == (to_raw & PROMOTE_MASK);
697 if (from_len == to_len) {
699 if (both_numeric || ctor_conversion) {
704 if (ctor_conversion) {
714vector<SymbolTable::BuiltinFunc> SymbolTable::generate_all_builtin_functions()
737 functions.push_back({
bool_cls,
"in_range_inclusive", {type, type, type}});
738 functions.push_back({
bool_cls,
"in_range_exclusive", {type, type, type}});
801 auto add_unary = [&](
const string &name,
const vector<SymbolClass *> &types) {
802 for (
const auto &t : types) {
803 functions.push_back({t, name, {t}});
808 auto add_binary = [&](
const string &name,
const vector<SymbolClass *> &types) {
809 for (
const auto &t : types) {
810 functions.push_back({t, name, {t, t}});
815 auto add_ternary = [&](
const string &name,
const vector<SymbolClass *> &types) {
816 for (
const auto &t : types) {
817 functions.push_back({t, name, {t, t, t}});
823 auto add_vec_scalar_binary = [&](
const string &name,
const vector<SymbolClass *> &types) {
824 SymbolClass *scalar = types[0];
825 for (
size_t i = 1; i < types.size(); ++i) {
826 functions.push_back({types[i], name, {types[i], scalar}});
830 auto add_scalar_vec_binary = [&](
const string &name,
const vector<SymbolClass *> &types) {
831 SymbolClass *scalar = types[0];
832 for (
size_t i = 1; i < types.size(); ++i) {
833 functions.push_back({types[i], name, {scalar, types[i]}});
837 auto add_vec_scalar_scalar_ternary = [&](
const string &name,
838 const vector<SymbolClass *> &types) {
839 SymbolClass *scalar = types[0];
840 for (
size_t i = 1; i < types.size(); ++i) {
841 functions.push_back({types[i], name, {types[i], scalar, scalar}});
845 auto add_vec_vec_scalar_ternary = [&](
const string &name,
const vector<SymbolClass *> &types) {
846 SymbolClass *scalar = types[0];
847 for (
size_t i = 1; i < types.size(); ++i) {
848 functions.push_back({types[i], name, {types[i], types[i], scalar}});
852 auto add_scalar_scalar_vec_ternary = [&](
const string &name,
853 const vector<SymbolClass *> &types) {
854 SymbolClass *scalar = types[0];
855 for (
size_t i = 1; i < types.size(); ++i) {
856 functions.push_back({types[i], name, {types[i], scalar, scalar}});
860 const vector<string> trig_unary = {
881 for (
const auto &name : trig_unary) {
882 add_unary(name, f_types);
885 add_binary(
"atan", f_types);
887 for (
string fn : {
"EXPECT_EQ",
"EXPECT_NE",
"EXPECT_LE",
"EXPECT_LT",
"EXPECT_GE",
"EXPECT_GT"})
889 add_binary(fn, f_types);
890 add_binary(fn, i_types);
891 add_binary(fn, u_types);
894 add_unary(
"EXPECT_TRUE", b_types);
895 add_unary(
"EXPECT_FALSE", b_types);
896 add_ternary(
"EXPECT_NEAR", f_types);
897 add_vec_vec_scalar_ternary(
"EXPECT_NEAR", f_types);
899 const vector<string> exp_unary = {
910 for (
const auto &name : exp_unary) {
911 add_unary(name, f_types);
913 add_binary(
"pow", f_types);
915 const vector<string> common_float_unary = {
927 for (
const auto &name : common_float_unary) {
928 add_unary(name, f_types);
931 for (
size_t i = 0; i < f_types.size(); ++i) {
932 functions.push_back({b_types[i],
"isnan", {f_types[i]}});
933 functions.push_back({b_types[i],
"isinf", {f_types[i]}});
936 add_unary(
"abs", f_types);
937 add_unary(
"abs", i_types);
939 add_unary(
"sign", f_types);
940 add_unary(
"sign", i_types);
942 add_binary(
"mod", f_types);
943 add_binary(
"modf", f_types);
944 add_vec_scalar_binary(
"mod", f_types);
946 for (
const auto &tlist : {f_types, i_types, u_types}) {
947 add_binary(
"min", tlist);
948 add_vec_scalar_binary(
"min", tlist);
949 add_binary(
"max", tlist);
950 add_vec_scalar_binary(
"max", tlist);
951 add_ternary(
"clamp", tlist);
952 add_vec_scalar_scalar_ternary(
"clamp", tlist);
955 add_ternary(
"mix", f_types);
956 add_vec_vec_scalar_ternary(
"mix", f_types);
957 for (
size_t i = 0; i < f_types.size(); ++i) {
958 functions.push_back({f_types[i],
"mix", {f_types[i], f_types[i], b_types[i]}});
959 functions.push_back({f_types[i],
"select", {f_types[i], f_types[i], b_types[i]}});
962 add_binary(
"step", f_types);
963 add_scalar_vec_binary(
"step", f_types);
964 add_ternary(
"smoothstep", f_types);
965 add_scalar_scalar_vec_ternary(
"smoothstep", f_types);
967 add_ternary(
"fma", f_types);
990 for (
size_t i = 1; i < f_types.size(); ++i) {
991 functions.push_back({
float_cls,
"length", {f_types[i]}});
992 functions.push_back({
float_cls,
"distance", {f_types[i], f_types[i]}});
993 functions.push_back({
float_cls,
"dot", {f_types[i], f_types[i]}});
994 functions.push_back({f_types[i],
"normalize", {f_types[i]}});
995 functions.push_back({f_types[i],
"faceforward", {f_types[i], f_types[i], f_types[i]}});
996 functions.push_back({f_types[i],
"reflect", {f_types[i], f_types[i]}});
997 functions.push_back({f_types[i],
"refract", {f_types[i], f_types[i],
float_cls}});
1002 const vector<SymbolClass *> all_mats = {
1014 for (
const auto &m : all_mats) {
1015 functions.push_back({m,
"transpose", {m}});
1018 for (
const auto &m : square_mats) {
1019 functions.push_back({
float_cls,
"determinant", {m}});
1020 functions.push_back({m,
"inverse", {m}});
1023 for (
size_t i = 1; i < b_types.size(); ++i) {
1024 functions.push_back({
bool_cls,
"any", {b_types[i]}});
1025 functions.push_back({
bool_cls,
"all", {b_types[i]}});
1026 functions.push_back({b_types[i],
"not", {b_types[i]}});
1029 const vector<string> bit_unary = {
"bitfieldReverse"};
1030 for (
const auto &op : bit_unary) {
1031 add_unary(op, i_types);
1032 add_unary(op, u_types);
1035 for (
int i : {0, 1, 2, 3}) {
1036 SymbolClass *u_type = u_types[i];
1037 SymbolClass *i_type = i_types[i];
1039 for (SymbolClass *input : {u_type, i_type}) {
1040 functions.push_back({i_type,
"bitCount", {input}});
1041 functions.push_back({i_type,
"findLSB", {input}});
1042 functions.push_back({i_type,
"findMSB", {input}});
1046 for (
const auto &tlist : {i_types, u_types}) {
1047 for (
const auto &t : tlist) {
1048 functions.push_back({t,
"bitfieldExtract", {t,
int_cls,
int_cls}});
1049 functions.push_back({t,
"bitfieldInsert", {t, t,
int_cls,
int_cls}});
1053 const vector<string> atomic_2arg = {
"atomicAdd",
1061 for (
const auto &op : atomic_2arg) {
1068 const vector<string> deriv_funcs = {
"gpu_dfdx",
"gpu_dfdy",
"gpu_fwidth"};
1070 for (
const auto &op : deriv_funcs) {
1071 add_unary(op, f_types);
1074 functions.push_back({
void_cls,
"gpu_discard_fragment", {}});
1075 functions.push_back({
void_cls,
"barrier", {}});
1078 const vector<pair<SymbolClass *, string>> image_types = {
1084 for (
auto [type, prefix] : image_types) {
1086 functions.push_back({type,
"texelFetch", {
sampler, i_types[0]}});
1089 for (
auto [type, prefix] : image_types) {
1090 vector<tuple<SymbolClass *, int, int>> samplers = {
1098 {
root->
classes[prefix +
"samplerCubeArray"], 4, 3},
1101 if (prefix.empty()) {
1102 samplers.emplace_back(
root->
classes[
"sampler2DDepth"], 2, 2);
1103 samplers.emplace_back(
root->
classes[
"samplerCubeDepth"], 3, 3);
1104 samplers.emplace_back(
root->
classes[
"sampler2DArrayDepth"], 3, 2);
1105 samplers.emplace_back(
root->
classes[
"samplerCubeArrayDepth"], 4, 3);
1108 samplers.emplace_back(
root->
classes[prefix +
"sampler2DAtomic"], 2, 2);
1109 samplers.emplace_back(
root->
classes[prefix +
"sampler3DAtomic"], 3, 3);
1110 samplers.emplace_back(
root->
classes[prefix +
"sampler2DArrayAtomic"], 3, 2);
1113 for (
auto [
sampler, coord_dim, deriv_dim] : samplers) {
1114 SymbolClass *coord_type = f_types[coord_dim - 1];
1115 SymbolClass *icoord_type = i_types[coord_dim - 1];
1116 SymbolClass *deriv_type = f_types[deriv_dim - 1];
1118 functions.push_back({type,
"texture", {
sampler, coord_type}});
1120 functions.push_back({type,
"textureLod", {
sampler, coord_type,
float_cls}});
1121 functions.push_back({type,
"textureGather", {
sampler, coord_type}});
1122 functions.push_back({type,
"textureGather", {
sampler, coord_type,
int_cls}});
1123 functions.push_back({type,
"textureGrad", {
sampler, coord_type, deriv_type, deriv_type}});
1124 functions.push_back({icoord_type,
"textureSize", {
sampler,
int_cls}});
1125 functions.push_back({type,
"texelFetch", {
sampler, icoord_type,
int_cls}});
1126 functions.push_back({type,
"texelFetchExtend", {
sampler, icoord_type,
int_cls}});
1129 vector<tuple<SymbolClass *, int>> images = {
1135 if (!prefix.empty()) {
1136 images.emplace_back(
root->
classes[prefix +
"image2DAtomic"], 2);
1137 images.emplace_back(
root->
classes[prefix +
"image3DAtomic"], 3);
1138 images.emplace_back(
root->
classes[prefix +
"image2DArrayAtomic"], 3);
1141 for (
auto [
image, coord_dim] : images) {
1142 SymbolClass *coord_type = i_types[coord_dim - 1];
1143 functions.push_back({type,
"imageLoad", {
image, coord_type}});
1144 functions.push_back({type,
"imageLoadFast", {
image, coord_type}});
1145 functions.push_back({
void_cls,
"imageStore", {
image, coord_type, type}});
1146 functions.push_back({
void_cls,
"imageStoreFast", {
image, coord_type, type}});
1147 functions.push_back({coord_type,
"imageSize", {
image}});
1150 if (
image->identifier.ends_with(
"Atomic")) {
1151 SymbolClass *scalar = prefix ==
"u" ? i_types[0] : u_types[0];
1152 functions.push_back({scalar,
"imageAtomicAdd", {
image, coord_type, scalar}});
1153 functions.push_back({scalar,
"imageAtomicMin", {
image, coord_type, scalar}});
1154 functions.push_back({scalar,
"imageAtomicMax", {
image, coord_type, scalar}});
1155 functions.push_back({scalar,
"imageAtomicAnd", {
image, coord_type, scalar}});
1156 functions.push_back({scalar,
"imageAtomicOr", {
image, coord_type, scalar}});
1157 functions.push_back({scalar,
"imageAtomicXor", {
image, coord_type, scalar}});
1158 functions.push_back({scalar,
"imageAtomicExchange", {
image, coord_type, scalar}});
1159 functions.push_back({scalar,
"imageAtomicCompSwap", {
image, coord_type, scalar, scalar}});
1166 SymbolClass *accelerationStructure_cls =
root->
lookup_class(
"accelerationStructure");
1168 "rayQueryInitialize",
1170 accelerationStructure_cls,
1177 functions.push_back({
bool_cls,
"rayQueryProceed", {rayQuery_cls}});
1178 functions.push_back({
void_cls,
"rayQueryTerminate", {rayQuery_cls}});
1179 functions.push_back({
void_cls,
"rayQueryGenerateIntersection", {rayQuery_cls,
float_cls}});
1180 functions.push_back({
void_cls,
"rayQueryConfirmIntersection", {rayQuery_cls}});
1181 functions.push_back({
uint_cls,
"rayQueryGetIntersectionType", {rayQuery_cls,
bool_cls}});
1182 functions.push_back({
float_cls,
"rayQueryGetRayTMin", {rayQuery_cls}});
1183 functions.push_back({
float3_cls,
"rayQueryGetWorldRayOrigin", {rayQuery_cls}});
1184 functions.push_back({
float3_cls,
"rayQueryGetWorldRayDirection", {rayQuery_cls}});
1185 functions.push_back({
float_cls,
"rayQueryGetIntersectionT", {rayQuery_cls,
bool_cls}});
1186 functions.push_back({
uint_cls,
"rayQueryGetIntersectionInstanceId", {rayQuery_cls,
bool_cls}});
1187 functions.push_back(
1188 {
uint_cls,
"rayQueryGetIntersectionInstanceCustomIndex", {rayQuery_cls,
bool_cls}});
1189 functions.push_back(
1190 {
uint_cls,
"rayQueryGetIntersectionGeometryIndex", {rayQuery_cls,
bool_cls}});
1191 functions.push_back(
1192 {
uint_cls,
"rayQueryGetIntersectionPrimitiveIndex", {rayQuery_cls,
bool_cls}});
1193 functions.push_back(
1195 functions.push_back({
bool_cls,
"rayQueryGetIntersectionFrontFace", {rayQuery_cls,
bool_cls}});
1196 functions.push_back({
bool_cls,
"rayQueryGetIntersectionCandidateAABBOpaque", {rayQuery_cls}});
1197 functions.push_back(
1198 {
float3_cls,
"rayQueryGetIntersectionObjectRayDirection", {rayQuery_cls,
bool_cls}});
1199 functions.push_back(
1201 functions.push_back(
1203 functions.push_back(
1216vector<SymbolTable::BuiltinFunc> SymbolTable::generate_all_builtin_constexpr_functions()
1219 vector<BuiltinFunc> functions;
1227 const vector<string> rel_ops = {
1228 "lessThan",
"lessThanEqual",
"greaterThan",
"greaterThanEqual",
"equal",
"notEqual"};
1230 for (
const auto &op : rel_ops) {
1231 for (
size_t i = 1; i < f_types.size(); ++i) {
1232 functions.push_back({b_types[i], op, {f_types[i], f_types[i]}});
1233 functions.push_back({b_types[i], op, {i_types[i], i_types[i]}});
1234 functions.push_back({b_types[i], op, {u_types[i], u_types[i]}});
1239 for (
size_t i = 0; i < f_types.size(); ++i) {
1240 functions.push_back({i_types[i],
"floatBitsToInt", {f_types[i]}});
1241 functions.push_back({u_types[i],
"floatBitsToUint", {f_types[i]}});
1242 functions.push_back({f_types[i],
"intBitsToFloat", {i_types[i]}});
1243 functions.push_back({f_types[i],
"uintBitsToFloat", {u_types[i]}});
#define image(slot, qualifiers, format)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
SymEdge< T > * sym(const SymEdge< T > *se)
ConstexprValue ConstexprError
@ TemplateParameterNotConstexpr
@ AutoTypeNestedInitializer
@ TemplateMissingArgument
@ AutoTypeMultipleExpressions
@ ExprCannotContainFunctionCalls
@ TemplateMissingParametersForType
@ UnsupportedSymbolInExpr
PipelineCompute comp(comp_main)
string to_string(const char *str)
InitializerList initializer_list() const
TemplateParamList template_params() const
IdQualified identifier() const
ChildRange children_range() const
std::string_view str() const
AstNodeException(ast::Node node, Diag diag, const string ¶m1="", const string ¶m2="", const string ¶m3="")
ConstexprValue(int32_t s)
builtin::ClassId builtin_class
unordered_map< string, SymbolScope * > scopes
SymbolVariable * lookup_variable(const SymbolTable &table, ast::IdQualified id) const
bool function_emplace(SymbolFunction *fn, bool builtin=false)
SymbolMap< SymbolVariable > variables
SymbolMap< SymbolClass > classes
Result< SymbolFunction * > lookup_function(const SymbolTable &table, ast::IdQualified id, optional< SourceLocation > loc=nullopt) const
SymbolClass * lookup_class_base(const SymbolTable &table, ast::IdQualified id) const
Result< SymbolClass * > lookup_class(const SymbolTable &table, ast::IdQualified id, optional< SourceLocation > loc=nullopt) const
SymbolClass * float3x2_cls
SymbolClass * float4x3_cls
static constexpr const char * err_symbol
SymbolClass * float3x3_cls
SymbolClass * packed_float2_cls
SymbolClass * float2x2_cls
Result< StringPair > mangle_identifier(ast::TemplateArgList args, ast::TemplateParamList list, const SymbolScope &scope) const
SymbolTable(ParserBase &builtin_parser)
Allocator< SymbolFunction > fun_arena
SymbolClass * get_literal_type(string_view lit) const
SymbolClass * float2x3_cls
Result< string > expr_to_string(const SymbolScope &scope, ast::Node start, int &node_count, bool allow_compilation_constant=false) const
Result< SymbolClass * > resolve_auto_type(SymbolScope &scope, ast::Declarator decl) const
SymbolClass * float2x4_cls
static constexpr const char * subscript_operator_id
Allocator< SymbolClass > cls_arena
SymbolClass * bool32_t_cls
Allocator< SymbolScope > scp_arena
SymbolClass * packed_float3_cls
SymbolClass * float3x4_cls
SymbolClass * float4x2_cls
Result< ExpressionResult > expr_type_analysis(const SymbolScope &scope, ast::Node start_node, bool is_reference=false) const
SymbolClass * ushort2_cls
SymbolClass * packed_float4_cls
Allocator< SymbolVariable > var_arena
MatchRank get_conversion_rank(const SymbolClass *from, const SymbolClass *to, const bool ctor_conversion=false) const
SymbolClass * ushort4_cls
SymbolClass * ushort3_cls
SymbolClass * float4x4_cls
SymbolFunction * err_func
unordered_map< int, string > image_formats
bool is_compilation_const