diff options
Diffstat (limited to 'servers/rendering/shader_compiler.cpp')
| -rw-r--r-- | servers/rendering/shader_compiler.cpp | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/servers/rendering/shader_compiler.cpp b/servers/rendering/shader_compiler.cpp index 4ea06afe79..1e95cdde0c 100644 --- a/servers/rendering/shader_compiler.cpp +++ b/servers/rendering/shader_compiler.cpp @@ -178,7 +178,7 @@ static String _mkid(const String &p_id) { } static String f2sp0(float p_float) { - String num = rtoss(p_float); + String num = rtos(p_float); if (!num.contains(".") && !num.contains("e")) { num += ".0"; } @@ -283,14 +283,28 @@ String ShaderCompiler::_get_sampler_name(ShaderLanguage::TextureFilter p_filter, ERR_FAIL_COND_V(actions.default_repeat == ShaderLanguage::REPEAT_DEFAULT, String()); p_repeat = actions.default_repeat; } - return actions.sampler_array_name + "[" + itos(p_filter + (p_repeat == ShaderLanguage::REPEAT_ENABLE ? ShaderLanguage::FILTER_DEFAULT : 0)) + "]"; + constexpr const char *name_mapping[] = { + "SAMPLER_NEAREST_CLAMP", + "SAMPLER_LINEAR_CLAMP", + "SAMPLER_NEAREST_WITH_MIPMAPS_CLAMP", + "SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP", + "SAMPLER_NEAREST_WITH_MIPMAPS_ANISOTROPIC_CLAMP", + "SAMPLER_LINEAR_WITH_MIPMAPS_ANISOTROPIC_CLAMP", + "SAMPLER_NEAREST_REPEAT", + "SAMPLER_LINEAR_REPEAT", + "SAMPLER_NEAREST_WITH_MIPMAPS_REPEAT", + "SAMPLER_LINEAR_WITH_MIPMAPS_REPEAT", + "SAMPLER_NEAREST_WITH_MIPMAPS_ANISOTROPIC_REPEAT", + "SAMPLER_LINEAR_WITH_MIPMAPS_ANISOTROPIC_REPEAT" + }; + return String(name_mapping[p_filter + (p_repeat == ShaderLanguage::REPEAT_ENABLE ? ShaderLanguage::FILTER_DEFAULT : 0)]); } void ShaderCompiler::_dump_function_deps(const SL::ShaderNode *p_node, const StringName &p_for_func, const HashMap<StringName, String> &p_func_code, String &r_to_add, HashSet<StringName> &added) { int fidx = -1; - for (int i = 0; i < p_node->functions.size(); i++) { - if (p_node->functions[i].name == p_for_func) { + for (int i = 0; i < p_node->vfunctions.size(); i++) { + if (p_node->vfunctions[i].name == p_for_func) { fidx = i; break; } @@ -300,7 +314,7 @@ void ShaderCompiler::_dump_function_deps(const SL::ShaderNode *p_node, const Str Vector<StringName> uses_functions; - for (const StringName &E : p_node->functions[fidx].uses_function) { + for (const StringName &E : p_node->vfunctions[fidx].uses_function) { uses_functions.push_back(E); } uses_functions.sort_custom<StringName::AlphCompare>(); //ensure order is deterministic so the same shader is always produced @@ -314,14 +328,14 @@ void ShaderCompiler::_dump_function_deps(const SL::ShaderNode *p_node, const Str SL::FunctionNode *fnode = nullptr; - for (int i = 0; i < p_node->functions.size(); i++) { - if (p_node->functions[i].name == uses_functions[k]) { - fnode = p_node->functions[i].function; + for (int i = 0; i < p_node->vfunctions.size(); i++) { + if (p_node->vfunctions[i].name == uses_functions[k]) { + fnode = p_node->vfunctions[i].function; break; } } - ERR_FAIL_COND(!fnode); + ERR_FAIL_NULL(fnode); r_to_add += "\n"; @@ -418,13 +432,13 @@ static String _get_global_shader_uniform_from_type_and_index(const String &p_buf return "(" + p_buffer + "[" + p_index + "].xyzw)"; } case ShaderLanguage::TYPE_MAT2: { - return "mat2(" + p_buffer + "[" + p_index + "].xy," + p_buffer + "[" + p_index + "+1].xy)"; + return "mat2(" + p_buffer + "[" + p_index + "].xy," + p_buffer + "[" + p_index + "+1u].xy)"; } case ShaderLanguage::TYPE_MAT3: { - return "mat3(" + p_buffer + "[" + p_index + "].xyz," + p_buffer + "[" + p_index + "+1].xyz," + p_buffer + "[" + p_index + "+2].xyz)"; + return "mat3(" + p_buffer + "[" + p_index + "].xyz," + p_buffer + "[" + p_index + "+1u].xyz," + p_buffer + "[" + p_index + "+2u].xyz)"; } case ShaderLanguage::TYPE_MAT4: { - return "mat4(" + p_buffer + "[" + p_index + "].xyzw," + p_buffer + "[" + p_index + "+1].xyzw," + p_buffer + "[" + p_index + "+2].xyzw," + p_buffer + "[" + p_index + "+3].xyzw)"; + return "mat4(" + p_buffer + "[" + p_index + "].xyzw," + p_buffer + "[" + p_index + "+1u].xyzw," + p_buffer + "[" + p_index + "+2u].xyzw," + p_buffer + "[" + p_index + "+3u].xyzw)"; } default: { ERR_FAIL_V("void"); @@ -751,8 +765,8 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene HashMap<StringName, String> function_code; //code for functions - for (int i = 0; i < pnode->functions.size(); i++) { - SL::FunctionNode *fnode = pnode->functions[i].function; + for (int i = 0; i < pnode->vfunctions.size(); i++) { + SL::FunctionNode *fnode = pnode->vfunctions[i].function; function = fnode; current_func_name = fnode->name; function_code[fnode->name] = _dump_node_code(fnode->body, p_level + 1, r_gen_code, p_actions, p_default_actions, p_assigning); @@ -763,8 +777,8 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene HashSet<StringName> added_funcs_per_stage[STAGE_MAX]; - for (int i = 0; i < pnode->functions.size(); i++) { - SL::FunctionNode *fnode = pnode->functions[i].function; + for (int i = 0; i < pnode->vfunctions.size(); i++) { + SL::FunctionNode *fnode = pnode->vfunctions[i].function; function = fnode; @@ -909,7 +923,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene //its a uniform! const ShaderLanguage::ShaderNode::Uniform &u = shader->uniforms[vnode->name]; if (u.texture_order >= 0) { - StringName name = vnode->name; + StringName name; if (u.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SCREEN_TEXTURE) { name = "color_buffer"; if (u.filter >= ShaderLanguage::FILTER_NEAREST_MIPMAP) { @@ -1136,9 +1150,9 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene const bool is_internal_func = internal_functions.has(vnode->name); if (!is_internal_func) { - for (int i = 0; i < shader->functions.size(); i++) { - if (shader->functions[i].name == vnode->name) { - func = shader->functions[i].function; + for (int i = 0; i < shader->vfunctions.size(); i++) { + if (shader->vfunctions[i].name == vnode->name) { + func = shader->vfunctions[i].function; break; } } |
