feat: updated engine version to 4.4-rc1

This commit is contained in:
Sara 2025-02-23 14:38:14 +01:00
parent ee00efde1f
commit 21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions

View file

@ -36,6 +36,7 @@
#include "core/string/ustring.h"
#include "core/templates/list.h"
#include "core/templates/rb_map.h"
#include "core/templates/safe_refcount.h"
#include "core/typedefs.h"
#include "core/variant/variant.h"
#include "scene/resources/shader_include.h"
@ -59,6 +60,7 @@ public:
TK_FLOAT_CONSTANT,
TK_INT_CONSTANT,
TK_UINT_CONSTANT,
TK_STRING_CONSTANT,
TK_TYPE_VOID,
TK_TYPE_BOOL,
TK_TYPE_BVEC2,
@ -90,6 +92,7 @@ public:
TK_TYPE_USAMPLER3D,
TK_TYPE_SAMPLERCUBE,
TK_TYPE_SAMPLERCUBEARRAY,
TK_TYPE_SAMPLEREXT,
TK_INTERPOLATION_FLAT,
TK_INTERPOLATION_SMOOTH,
TK_CONST,
@ -175,6 +178,7 @@ public:
TK_HINT_ANISOTROPY_TEXTURE,
TK_HINT_SOURCE_COLOR,
TK_HINT_RANGE,
TK_HINT_ENUM,
TK_HINT_INSTANCE_INDEX,
TK_HINT_SCREEN_TEXTURE,
TK_HINT_NORMAL_ROUGHNESS_TEXTURE,
@ -233,6 +237,7 @@ public:
TYPE_USAMPLER3D,
TYPE_SAMPLERCUBE,
TYPE_SAMPLERCUBEARRAY,
TYPE_SAMPLEREXT,
TYPE_STRUCT,
TYPE_MAX
};
@ -353,6 +358,13 @@ public:
}
};
union Scalar {
bool boolean = false;
float real;
int32_t sint;
uint32_t uint;
};
struct Node {
Node *next = nullptr;
@ -377,6 +389,7 @@ public:
virtual String get_datatype_name() const { return ""; }
virtual int get_array_size() const { return 0; }
virtual bool is_indexed() const { return false; }
virtual Vector<Scalar> get_values() const { return Vector<Scalar>(); }
Node(Type t) :
type(t) {}
@ -400,11 +413,13 @@ public:
Operator op = OP_EQUAL;
StringName struct_name;
Vector<Node *> arguments;
Vector<Scalar> values;
virtual DataType get_datatype() const override { return return_cache; }
virtual String get_datatype_name() const override { return String(struct_name); }
virtual int get_array_size() const override { return return_array_size; }
virtual bool is_indexed() const override { return op == OP_INDEX; }
virtual Vector<Scalar> get_values() const override { return values; }
OperatorNode() :
Node(NODE_TYPE_OPERATOR) {}
@ -413,6 +428,7 @@ public:
struct VariableNode : public Node {
DataType datatype_cache = TYPE_VOID;
StringName name;
StringName rname;
StringName struct_name;
bool is_const = false;
bool is_local = false;
@ -483,19 +499,15 @@ public:
String struct_name = "";
int array_size = 0;
union Value {
bool boolean = false;
float real;
int32_t sint;
uint32_t uint;
};
Vector<Value> values;
Vector<Scalar> values;
Vector<VariableDeclarationNode::Declaration> array_declarations;
virtual DataType get_datatype() const override { return datatype; }
virtual String get_datatype_name() const override { return struct_name; }
virtual int get_array_size() const override { return array_size; }
virtual Vector<Scalar> get_values() const override {
return values;
}
ConstantNode() :
Node(NODE_TYPE_CONSTANT) {}
@ -527,13 +539,17 @@ public:
int line; //for completion
int array_size;
bool is_const;
ConstantNode::Value value;
Vector<Scalar> values;
};
HashMap<StringName, Variable> variables;
List<Node *> statements;
bool single_statement = false;
bool use_comma_between_statements = false;
bool use_op_eval = true;
DataType expected_type = TYPE_VOID;
HashSet<int> constants;
BlockNode() :
Node(NODE_TYPE_BLOCK) {}
@ -590,6 +606,7 @@ public:
struct Function {
StringName name;
StringName rname;
FunctionNode *function = nullptr;
HashSet<StringName> uses_function;
bool callable;
@ -603,10 +620,8 @@ public:
struct Varying {
enum Stage {
STAGE_UNKNOWN,
STAGE_VERTEX, // transition stage to STAGE_VERTEX_TO_FRAGMENT_LIGHT, emits warning if it's not used
STAGE_FRAGMENT, // transition stage to STAGE_FRAGMENT_TO_LIGHT, emits warning if it's not used
STAGE_VERTEX_TO_FRAGMENT_LIGHT,
STAGE_FRAGMENT_TO_LIGHT,
STAGE_VERTEX,
STAGE_FRAGMENT,
};
Stage stage = STAGE_UNKNOWN;
@ -616,6 +631,28 @@ public:
int array_size = 0;
TkPos tkpos;
uint32_t get_size() const {
uint32_t size = 1;
if (array_size > 0) {
size = (uint32_t)array_size;
}
switch (type) {
case TYPE_MAT2:
size *= 2;
break;
case TYPE_MAT3:
size *= 3;
break;
case TYPE_MAT4:
size *= 4;
break;
default:
break;
}
return size;
}
Varying() {}
};
@ -623,6 +660,7 @@ public:
enum Hint {
HINT_NONE,
HINT_RANGE,
HINT_ENUM,
HINT_SOURCE_COLOR,
HINT_NORMAL,
HINT_ROUGHNESS_NORMAL,
@ -648,22 +686,29 @@ public:
};
int order = 0;
int prop_order = 0;
int texture_order = 0;
int texture_binding = 0;
DataType type = TYPE_VOID;
DataPrecision precision = PRECISION_DEFAULT;
int array_size = 0;
Vector<ConstantNode::Value> default_value;
Vector<Scalar> default_value;
Scope scope = SCOPE_LOCAL;
Hint hint = HINT_NONE;
bool use_color = false;
TextureFilter filter = FILTER_DEFAULT;
TextureRepeat repeat = REPEAT_DEFAULT;
float hint_range[3];
PackedStringArray hint_enum_names;
int instance_index = 0;
String group;
String subgroup;
_FORCE_INLINE_ bool is_texture() const {
// Order is assigned to -1 for texture uniforms.
return order < 0;
}
Uniform() {
hint_range[0] = 0.0f;
hint_range[1] = 1.0f;
@ -707,6 +752,7 @@ public:
};
StringName name;
StringName rname;
DataType return_type = TYPE_VOID;
StringName return_struct_name;
DataPrecision return_precision = PRECISION_DEFAULT;
@ -737,6 +783,12 @@ public:
};
};
struct ExpressionInfo {
Vector<Expression> *expression = nullptr;
TokenType tt_break = TK_EMPTY;
bool is_last_expr = false;
};
struct VarInfo {
StringName name;
DataType type;
@ -787,21 +839,23 @@ public:
static bool is_token_operator_assign(TokenType p_type);
static bool is_token_hint(TokenType p_type);
static bool convert_constant(ConstantNode *p_constant, DataType p_to_type, ConstantNode::Value *p_value = nullptr);
static bool convert_constant(ConstantNode *p_constant, DataType p_to_type, Scalar *p_value = nullptr);
static DataType get_scalar_type(DataType p_type);
static int get_cardinality(DataType p_type);
static bool is_scalar_type(DataType p_type);
static bool is_float_type(DataType p_type);
static bool is_sampler_type(DataType p_type);
static Variant constant_value_to_variant(const Vector<ShaderLanguage::ConstantNode::Value> &p_value, DataType p_type, int p_array_size, ShaderLanguage::ShaderNode::Uniform::Hint p_hint = ShaderLanguage::ShaderNode::Uniform::HINT_NONE);
static Variant constant_value_to_variant(const Vector<Scalar> &p_value, DataType p_type, int p_array_size, ShaderLanguage::ShaderNode::Uniform::Hint p_hint = ShaderLanguage::ShaderNode::Uniform::HINT_NONE);
static Variant get_default_datatype_value(DataType p_type, int p_array_size, ShaderLanguage::ShaderNode::Uniform::Hint p_hint);
static PropertyInfo uniform_to_property_info(const ShaderNode::Uniform &p_uniform);
static uint32_t get_datatype_size(DataType p_type);
static uint32_t get_datatype_component_count(DataType p_type);
static void get_keyword_list(List<String> *r_keywords);
static bool is_control_flow_keyword(String p_keyword);
static void get_builtin_funcs(List<String> *r_keywords);
static int instance_counter;
static SafeNumeric<int> instance_counter;
struct BuiltInInfo {
DataType type = TYPE_VOID;
@ -827,6 +881,7 @@ public:
Vector<Argument> arguments;
DataType return_type = TYPE_VOID;
String skip_function;
};
struct ModeInfo {
@ -902,7 +957,7 @@ private:
const char *text;
uint32_t flags;
const Vector<String> excluded_shader_types;
const Vector<String> functions;
const Vector<String> excluded_functions;
};
static const KeyWord keyword_list[];
@ -915,6 +970,7 @@ private:
Vector<FilePosition> include_positions;
HashSet<String> include_markers_handled;
HashMap<StringName, int> function_overload_count;
// Additional function information (eg. call hierarchy). No need to expose it to compiler.
struct CallInfo {
@ -988,6 +1044,7 @@ private:
String current_uniform_subgroup_name;
VaryingFunctionNames varying_function_names;
uint32_t base_varying_index = 0;
TkPos _get_tkpos() {
TkPos tkp;
@ -1037,6 +1094,7 @@ private:
Token _make_token(TokenType p_type, const StringName &p_text = StringName());
Token _get_token();
bool _lookup_next(Token &r_tk);
Token _peek();
ShaderNode *shader = nullptr;
@ -1053,13 +1111,21 @@ private:
IdentifierType last_type = IDENTIFIER_MAX;
bool _find_identifier(const BlockNode *p_block, bool p_allow_reassign, const FunctionInfo &p_function_info, const StringName &p_identifier, DataType *r_data_type = nullptr, IdentifierType *r_type = nullptr, bool *r_is_const = nullptr, int *r_array_size = nullptr, StringName *r_struct_name = nullptr, ConstantNode::Value *r_constant_value = nullptr);
bool _find_identifier(const BlockNode *p_block, bool p_allow_reassign, const FunctionInfo &p_function_info, const StringName &p_identifier, DataType *r_data_type = nullptr, IdentifierType *r_type = nullptr, bool *r_is_const = nullptr, int *r_array_size = nullptr, StringName *r_struct_name = nullptr, Vector<Scalar> *r_constant_values = nullptr);
#ifdef DEBUG_ENABLED
void _parse_used_identifier(const StringName &p_identifier, IdentifierType p_type, const StringName &p_function);
#endif // DEBUG_ENABLED
bool _is_operator_assign(Operator p_op) const;
bool _validate_assign(Node *p_node, const FunctionInfo &p_function_info, String *r_message = nullptr);
bool _validate_operator(OperatorNode *p_op, DataType *r_ret_type = nullptr, int *r_ret_size = nullptr);
bool _validate_operator(const BlockNode *p_block, OperatorNode *p_op, DataType *r_ret_type = nullptr, int *r_ret_size = nullptr);
Vector<Scalar> _get_node_values(const BlockNode *p_block, Node *p_node);
bool _eval_operator(const BlockNode *p_block, OperatorNode *p_op);
Scalar _eval_unary_scalar(const Scalar &p_a, Operator p_op, DataType p_ret_type);
Scalar _eval_scalar(const Scalar &p_a, const Scalar &p_b, Operator p_op, DataType p_ret_type, bool &r_is_valid);
Vector<Scalar> _eval_unary_vector(const Vector<Scalar> &p_va, DataType p_ret_type, Operator p_op);
Vector<Scalar> _eval_vector(const Vector<Scalar> &p_va, const Vector<Scalar> &p_vb, DataType p_left_type, DataType p_right_type, DataType p_ret_type, Operator p_op, bool &r_is_valid);
Vector<Scalar> _eval_vector_transform(const Vector<Scalar> &p_va, const Vector<Scalar> &p_vb, DataType p_left_type, DataType p_right_type, DataType p_ret_type);
struct BuiltinEntry {
const char *name;
@ -1108,6 +1174,7 @@ private:
const HashMap<StringName, FunctionInfo> *stages = nullptr;
bool is_supported_frag_only_funcs = false;
bool is_discard_supported = false;
bool _get_completable_identifier(BlockNode *p_block, CompletionType p_type, StringName &identifier);
static const BuiltinFuncDef builtin_func_defs[];
@ -1132,13 +1199,13 @@ private:
bool _check_restricted_func(const StringName &p_name, const StringName &p_current_function) const;
bool _validate_restricted_func(const StringName &p_call_name, const CallInfo *p_func_info, bool p_is_builtin_hint = false);
Node *_parse_expression(BlockNode *p_block, const FunctionInfo &p_function_info);
Node *_parse_expression(BlockNode *p_block, const FunctionInfo &p_function_info, const ExpressionInfo *p_previous_expression_info = nullptr);
Error _parse_array_size(BlockNode *p_block, const FunctionInfo &p_function_info, bool p_forbid_unknown_size, Node **r_size_expression, int *r_array_size, bool *r_unknown_size);
Node *_parse_array_constructor(BlockNode *p_block, const FunctionInfo &p_function_info);
Node *_parse_array_constructor(BlockNode *p_block, const FunctionInfo &p_function_info, DataType p_type, const StringName &p_struct_name, int p_array_size);
ShaderLanguage::Node *_reduce_expression(BlockNode *p_block, ShaderLanguage::Node *p_node);
Node *_parse_and_reduce_expression(BlockNode *p_block, const FunctionInfo &p_function_info);
Node *_parse_and_reduce_expression(BlockNode *p_block, const FunctionInfo &p_function_info, const ExpressionInfo *p_previous_expression_info = nullptr);
Error _parse_block(BlockNode *p_block, const FunctionInfo &p_function_info, bool p_just_one = false, bool p_can_break = false, bool p_can_continue = false);
String _get_shader_type_list(const HashSet<String> &p_shader_types) const;
String _get_qualifier_str(ArgumentQualifier p_qualifier) const;
@ -1169,10 +1236,11 @@ public:
struct ShaderCompileInfo {
HashMap<StringName, FunctionInfo> functions;
Vector<ModeInfo> render_modes;
VaryingFunctionNames varying_function_names = VaryingFunctionNames();
VaryingFunctionNames varying_function_names;
HashSet<String> shader_types;
GlobalShaderUniformGetTypeFunc global_shader_uniform_type_func = nullptr;
bool is_include = false;
uint32_t base_varying_index = 0;
};
Error compile(const String &p_code, const ShaderCompileInfo &p_info);