diff options
Diffstat (limited to 'servers/rendering')
-rw-r--r-- | servers/rendering/renderer_rd/renderer_scene_render_rd.cpp | 3 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp | 5 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/storage_rd/texture_storage.cpp | 5 | ||||
-rw-r--r-- | servers/rendering/renderer_viewport.cpp | 6 | ||||
-rw-r--r-- | servers/rendering/shader_compiler.cpp | 3 | ||||
-rw-r--r-- | servers/rendering/shader_language.cpp | 38 | ||||
-rw-r--r-- | servers/rendering/shader_preprocessor.cpp | 62 | ||||
-rw-r--r-- | servers/rendering/shader_preprocessor.h | 16 |
8 files changed, 121 insertions, 17 deletions
diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index 13f8d1ab75..6c219933b0 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -2459,8 +2459,7 @@ void RendererSceneRenderRD::render_buffers_configure(RID p_render_buffers, RID p p_internal_width = p_width; } - const float texture_mipmap_bias = -log2f(p_width / p_internal_width) + p_texture_mipmap_bias; - material_storage->sampler_rd_configure_custom(texture_mipmap_bias); + material_storage->sampler_rd_configure_custom(p_texture_mipmap_bias); update_uniform_sets(); RenderBuffers *rb = render_buffers_owner.get_or_null(p_render_buffers); diff --git a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp b/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp index dc3f35f942..585c42b2d8 100644 --- a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp @@ -416,7 +416,10 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) mesh->bone_aabbs.resize(p_surface.bone_aabbs.size()); } for (int i = 0; i < p_surface.bone_aabbs.size(); i++) { - mesh->bone_aabbs.write[i].merge_with(p_surface.bone_aabbs[i]); + const AABB &bone = p_surface.bone_aabbs[i]; + if (!bone.has_no_volume()) { + mesh->bone_aabbs.write[i].merge_with(bone); + } } mesh->aabb.merge_with(p_surface.aabb); } diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp index e20a04ff2a..84427e1c93 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp @@ -416,7 +416,10 @@ TextureStorage::TextureStorage() { tformat.format = RD::DATA_FORMAT_R8_UINT; tformat.width = 4; tformat.height = 4; - tformat.usage_bits = RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_VRS_ATTACHMENT_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_STORAGE_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT; + tformat.usage_bits = RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_STORAGE_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT; + if (RD::get_singleton()->has_feature(RD::SUPPORTS_ATTACHMENT_VRS)) { + tformat.usage_bits |= RD::TEXTURE_USAGE_VRS_ATTACHMENT_BIT; + } tformat.texture_type = RD::TEXTURE_TYPE_2D; Vector<uint8_t> pv; diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 118bf532b3..73b03966c5 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -138,7 +138,11 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { p_viewport->internal_size = Size2(render_width, render_height); - RSG::scene->render_buffers_configure(p_viewport->render_buffers, p_viewport->render_target, render_width, render_height, width, height, p_viewport->fsr_sharpness, p_viewport->texture_mipmap_bias, p_viewport->msaa, p_viewport->screen_space_aa, p_viewport->use_taa, p_viewport->use_debanding, p_viewport->get_view_count()); + // At resolution scales lower than 1.0, use negative texture mipmap bias + // to compensate for the loss of sharpness. + const float texture_mipmap_bias = log2f(MIN(scaling_3d_scale, 1.0)) + p_viewport->texture_mipmap_bias; + + RSG::scene->render_buffers_configure(p_viewport->render_buffers, p_viewport->render_target, render_width, render_height, width, height, p_viewport->fsr_sharpness, texture_mipmap_bias, p_viewport->msaa, p_viewport->screen_space_aa, p_viewport->use_taa, p_viewport->use_debanding, p_viewport->get_view_count()); } } } diff --git a/servers/rendering/shader_compiler.cpp b/servers/rendering/shader_compiler.cpp index 7637eae4a6..c2cf08812c 100644 --- a/servers/rendering/shader_compiler.cpp +++ b/servers/rendering/shader_compiler.cpp @@ -1434,8 +1434,11 @@ void ShaderCompiler::initialize(DefaultIdentifierActions p_actions) { texture_functions.insert("textureLod"); texture_functions.insert("textureProjLod"); texture_functions.insert("textureGrad"); + texture_functions.insert("textureProjGrad"); texture_functions.insert("textureGather"); texture_functions.insert("textureSize"); + texture_functions.insert("textureQueryLod"); + texture_functions.insert("textureQueryLevels"); texture_functions.insert("texelFetch"); } diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index 839f5b8eea..81e4d5e217 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -2732,6 +2732,18 @@ const ShaderLanguage::BuiltinFuncDef ShaderLanguage::builtin_func_defs[] = { { "textureGrad", TYPE_VEC4, { TYPE_SAMPLERCUBE, TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID }, { "sampler", "coords", "dPdx", "dPdy" }, TAG_GLOBAL, false }, { "textureGrad", TYPE_VEC4, { TYPE_SAMPLERCUBEARRAY, TYPE_VEC4, TYPE_VEC3, TYPE_VEC3, TYPE_VOID }, { "sampler", "coords", "dPdx", "dPdy" }, TAG_GLOBAL, false }, + // textureProjGrad + + { "textureProjGrad", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC3, TYPE_VEC2, TYPE_VEC2, TYPE_VOID }, { "sampler", "coords", "dPdx", "dPdy" }, TAG_GLOBAL, false }, + { "textureProjGrad", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC4, TYPE_VEC2, TYPE_VEC2, TYPE_VOID }, { "sampler", "coords", "dPdx", "dPdy" }, TAG_GLOBAL, false }, + { "textureProjGrad", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC3, TYPE_VEC2, TYPE_VEC2, TYPE_VOID }, { "sampler", "coords", "dPdx", "dPdy" }, TAG_GLOBAL, false }, + { "textureProjGrad", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC4, TYPE_VEC2, TYPE_VEC2, TYPE_VOID }, { "sampler", "coords", "dPdx", "dPdy" }, TAG_GLOBAL, false }, + { "textureProjGrad", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC3, TYPE_VEC2, TYPE_VEC2, TYPE_VOID }, { "sampler", "coords", "dPdx", "dPdy" }, TAG_GLOBAL, false }, + { "textureProjGrad", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC4, TYPE_VEC2, TYPE_VEC2, TYPE_VOID }, { "sampler", "coords", "dPdx", "dPdy" }, TAG_GLOBAL, false }, + { "textureProjGrad", TYPE_VEC4, { TYPE_SAMPLER3D, TYPE_VEC4, TYPE_VEC3, TYPE_VEC3, TYPE_VOID }, { "sampler", "coords", "dPdx", "dPdy" }, TAG_GLOBAL, false }, + { "textureProjGrad", TYPE_IVEC4, { TYPE_ISAMPLER3D, TYPE_VEC4, TYPE_VEC3, TYPE_VEC3, TYPE_VOID }, { "sampler", "coords", "dPdx", "dPdy" }, TAG_GLOBAL, false }, + { "textureProjGrad", TYPE_UVEC4, { TYPE_USAMPLER3D, TYPE_VEC4, TYPE_VEC3, TYPE_VEC3, TYPE_VOID }, { "sampler", "coords", "dPdx", "dPdy" }, TAG_GLOBAL, false }, + // textureGather { "textureGather", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC2, TYPE_VOID }, { "sampler", "coords" }, TAG_GLOBAL, false }, @@ -2749,6 +2761,32 @@ const ShaderLanguage::BuiltinFuncDef ShaderLanguage::builtin_func_defs[] = { { "textureGather", TYPE_VEC4, { TYPE_SAMPLERCUBE, TYPE_VEC3, TYPE_VOID }, { "sampler", "coords" }, TAG_GLOBAL, false }, { "textureGather", TYPE_VEC4, { TYPE_SAMPLERCUBE, TYPE_VEC3, TYPE_INT, TYPE_VOID }, { "sampler", "coords", "comp" }, TAG_GLOBAL, false }, + // textureQueryLod + + { "textureQueryLod", TYPE_VEC2, { TYPE_SAMPLER2D, TYPE_VEC2 }, { "sampler", "coords" }, TAG_GLOBAL, true }, + { "textureQueryLod", TYPE_VEC2, { TYPE_ISAMPLER2D, TYPE_VEC2 }, { "sampler", "coords" }, TAG_GLOBAL, true }, + { "textureQueryLod", TYPE_VEC2, { TYPE_USAMPLER2D, TYPE_VEC2 }, { "sampler", "coords" }, TAG_GLOBAL, true }, + { "textureQueryLod", TYPE_VEC2, { TYPE_SAMPLER2DARRAY, TYPE_VEC2 }, { "sampler", "coords" }, TAG_GLOBAL, true }, + { "textureQueryLod", TYPE_VEC2, { TYPE_ISAMPLER2DARRAY, TYPE_VEC2 }, { "sampler", "coords" }, TAG_GLOBAL, true }, + { "textureQueryLod", TYPE_VEC2, { TYPE_USAMPLER2DARRAY, TYPE_VEC2 }, { "sampler", "coords" }, TAG_GLOBAL, true }, + { "textureQueryLod", TYPE_VEC2, { TYPE_SAMPLER3D, TYPE_VEC3 }, { "sampler", "coords" }, TAG_GLOBAL, true }, + { "textureQueryLod", TYPE_VEC2, { TYPE_ISAMPLER3D, TYPE_VEC3 }, { "sampler", "coords" }, TAG_GLOBAL, true }, + { "textureQueryLod", TYPE_VEC2, { TYPE_USAMPLER3D, TYPE_VEC3 }, { "sampler", "coords" }, TAG_GLOBAL, true }, + { "textureQueryLod", TYPE_VEC2, { TYPE_SAMPLERCUBE, TYPE_VEC3 }, { "sampler", "coords" }, TAG_GLOBAL, true }, + + // textureQueryLevels + + { "textureQueryLevels", TYPE_INT, { TYPE_SAMPLER2D }, { "sampler" }, TAG_GLOBAL, true }, + { "textureQueryLevels", TYPE_INT, { TYPE_ISAMPLER2D }, { "sampler" }, TAG_GLOBAL, true }, + { "textureQueryLevels", TYPE_INT, { TYPE_USAMPLER2D }, { "sampler" }, TAG_GLOBAL, true }, + { "textureQueryLevels", TYPE_INT, { TYPE_SAMPLER2DARRAY }, { "sampler" }, TAG_GLOBAL, true }, + { "textureQueryLevels", TYPE_INT, { TYPE_ISAMPLER2DARRAY }, { "sampler" }, TAG_GLOBAL, true }, + { "textureQueryLevels", TYPE_INT, { TYPE_USAMPLER2DARRAY }, { "sampler" }, TAG_GLOBAL, true }, + { "textureQueryLevels", TYPE_INT, { TYPE_SAMPLER3D }, { "sampler" }, TAG_GLOBAL, true }, + { "textureQueryLevels", TYPE_INT, { TYPE_ISAMPLER3D }, { "sampler" }, TAG_GLOBAL, true }, + { "textureQueryLevels", TYPE_INT, { TYPE_USAMPLER3D }, { "sampler" }, TAG_GLOBAL, true }, + { "textureQueryLevels", TYPE_INT, { TYPE_SAMPLERCUBE }, { "sampler" }, TAG_GLOBAL, true }, + // dFdx { "dFdx", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID }, { "p" }, TAG_GLOBAL, false }, diff --git a/servers/rendering/shader_preprocessor.cpp b/servers/rendering/shader_preprocessor.cpp index a7b274b3e2..d118c73c4a 100644 --- a/servers/rendering/shader_preprocessor.cpp +++ b/servers/rendering/shader_preprocessor.cpp @@ -416,16 +416,22 @@ void ShaderPreprocessor::process_define(Tokenizer *p_tokenizer) { } void ShaderPreprocessor::process_else(Tokenizer *p_tokenizer) { + const int line = p_tokenizer->get_line(); + if (state->skip_stack_else.is_empty()) { - set_error(RTR("Unmatched else."), p_tokenizer->get_line()); + set_error(RTR("Unmatched else."), line); return; } + if (state->previous_region != nullptr) { + state->previous_region->to_line = line - 1; + } + p_tokenizer->advance('\n'); bool skip = state->skip_stack_else[state->skip_stack_else.size() - 1]; state->skip_stack_else.remove_at(state->skip_stack_else.size() - 1); - Vector<SkippedCondition *> vec = state->skipped_conditions[state->current_include]; + Vector<SkippedCondition *> vec = state->skipped_conditions[state->current_filename]; int index = vec.size() - 1; if (index >= 0) { SkippedCondition *cond = vec[index]; @@ -434,6 +440,10 @@ void ShaderPreprocessor::process_else(Tokenizer *p_tokenizer) { } } + if (state->save_regions) { + add_region(line + 1, !skip, state->previous_region->parent); + } + if (skip) { Vector<String> ends; ends.push_back("endif"); @@ -447,8 +457,12 @@ void ShaderPreprocessor::process_endif(Tokenizer *p_tokenizer) { set_error(RTR("Unmatched endif."), p_tokenizer->get_line()); return; } + if (state->previous_region != nullptr) { + state->previous_region->to_line = p_tokenizer->get_line() - 1; + state->previous_region = state->previous_region->parent; + } - Vector<SkippedCondition *> vec = state->skipped_conditions[state->current_include]; + Vector<SkippedCondition *> vec = state->skipped_conditions[state->current_filename]; int index = vec.size() - 1; if (index >= 0) { SkippedCondition *cond = vec[index]; @@ -461,7 +475,7 @@ void ShaderPreprocessor::process_endif(Tokenizer *p_tokenizer) { } void ShaderPreprocessor::process_if(Tokenizer *p_tokenizer) { - int line = p_tokenizer->get_line(); + const int line = p_tokenizer->get_line(); String body = tokens_to_string(p_tokenizer->advance('\n')).strip_edges(); if (body.is_empty()) { @@ -490,6 +504,10 @@ void ShaderPreprocessor::process_if(Tokenizer *p_tokenizer) { bool success = v.booleanize(); start_branch_condition(p_tokenizer, success); + + if (state->save_regions) { + add_region(line + 1, success, state->previous_region); + } } void ShaderPreprocessor::process_ifdef(Tokenizer *p_tokenizer) { @@ -510,6 +528,10 @@ void ShaderPreprocessor::process_ifdef(Tokenizer *p_tokenizer) { bool success = state->defines.has(label); start_branch_condition(p_tokenizer, success); + + if (state->save_regions) { + add_region(line + 1, success, state->previous_region); + } } void ShaderPreprocessor::process_ifndef(Tokenizer *p_tokenizer) { @@ -530,6 +552,10 @@ void ShaderPreprocessor::process_ifndef(Tokenizer *p_tokenizer) { bool success = !state->defines.has(label); start_branch_condition(p_tokenizer, success); + + if (state->save_regions) { + add_region(line + 1, success, state->previous_region); + } } void ShaderPreprocessor::process_include(Tokenizer *p_tokenizer) { @@ -594,15 +620,15 @@ void ShaderPreprocessor::process_include(Tokenizer *p_tokenizer) { return; } - String old_include = state->current_include; - state->current_include = real_path; + String old_filename = state->current_filename; + state->current_filename = real_path; ShaderPreprocessor processor; int prev_condition_depth = state->condition_depth; state->condition_depth = 0; FilePosition fp; - fp.file = state->current_include; + fp.file = state->current_filename; fp.line = line; state->include_positions.push_back(fp); @@ -614,7 +640,7 @@ void ShaderPreprocessor::process_include(Tokenizer *p_tokenizer) { // Reset to last include if there are no errors. We want to use this as context. if (state->error.is_empty()) { - state->current_include = old_include; + state->current_filename = old_filename; state->include_positions.pop_back(); } else { return; @@ -668,6 +694,15 @@ void ShaderPreprocessor::process_undef(Tokenizer *p_tokenizer) { state->defines.erase(label); } +void ShaderPreprocessor::add_region(int p_line, bool p_enabled, Region *p_parent_region) { + Region region; + region.file = state->current_filename; + region.enabled = p_enabled; + region.from_line = p_line; + region.parent = p_parent_region; + state->previous_region = &state->regions[region.file].push_back(region)->get(); +} + void ShaderPreprocessor::start_branch_condition(Tokenizer *p_tokenizer, bool p_success) { state->condition_depth++; @@ -676,7 +711,7 @@ void ShaderPreprocessor::start_branch_condition(Tokenizer *p_tokenizer, bool p_s } else { SkippedCondition *cond = memnew(SkippedCondition()); cond->start_line = p_tokenizer->get_line(); - state->skipped_conditions[state->current_include].push_back(cond); + state->skipped_conditions[state->current_filename].push_back(cond); Vector<String> ends; ends.push_back("else"); @@ -969,8 +1004,12 @@ Error ShaderPreprocessor::preprocess(State *p_state, const String &p_code, Strin return OK; } -Error ShaderPreprocessor::preprocess(const String &p_code, String &r_result, String *r_error_text, List<FilePosition> *r_error_position, HashSet<Ref<ShaderInclude>> *r_includes, List<ScriptLanguage::CodeCompletionOption> *r_completion_options, IncludeCompletionFunction p_include_completion_func) { +Error ShaderPreprocessor::preprocess(const String &p_code, const String &p_filename, String &r_result, String *r_error_text, List<FilePosition> *r_error_position, List<Region> *r_regions, HashSet<Ref<ShaderInclude>> *r_includes, List<ScriptLanguage::CodeCompletionOption> *r_completion_options, IncludeCompletionFunction p_include_completion_func) { State pp_state; + if (!p_filename.is_empty()) { + pp_state.current_filename = p_filename; + pp_state.save_regions = r_regions != nullptr; + } Error err = preprocess(&pp_state, p_code, r_result); if (err != OK) { if (r_error_text) { @@ -980,6 +1019,9 @@ Error ShaderPreprocessor::preprocess(const String &p_code, String &r_result, Str *r_error_position = pp_state.include_positions; } } + if (r_regions) { + *r_regions = pp_state.regions[p_filename]; + } if (r_includes) { *r_includes = pp_state.shader_includes; } diff --git a/servers/rendering/shader_preprocessor.h b/servers/rendering/shader_preprocessor.h index a93fb680dd..41b574298d 100644 --- a/servers/rendering/shader_preprocessor.h +++ b/servers/rendering/shader_preprocessor.h @@ -58,6 +58,14 @@ public: int line = 0; }; + struct Region { + String file; + int from_line = -1; + int to_line = -1; + bool enabled = false; + Region *parent = nullptr; + }; + private: struct Token { char32_t text; @@ -134,10 +142,13 @@ private: RBSet<String> includes; List<uint64_t> cyclic_include_hashes; // Holds code hash of includes. int include_depth = 0; - String current_include; + String current_filename; String current_shader_type; String error; List<FilePosition> include_positions; + bool save_regions = false; + RBMap<String, List<Region>> regions; + Region *previous_region = nullptr; RBMap<String, Vector<SkippedCondition *>> skipped_conditions; bool disabled = false; CompletionType completion_type = COMPLETION_TYPE_NONE; @@ -167,6 +178,7 @@ private: void process_pragma(Tokenizer *p_tokenizer); void process_undef(Tokenizer *p_tokenizer); + void add_region(int p_line, bool p_enabled, Region *p_parent_region); void start_branch_condition(Tokenizer *p_tokenizer, bool p_success); void expand_output_macros(int p_start, int p_line); @@ -188,7 +200,7 @@ private: public: typedef void (*IncludeCompletionFunction)(List<ScriptLanguage::CodeCompletionOption> *); - Error preprocess(const String &p_code, String &r_result, String *r_error_text = nullptr, List<FilePosition> *r_error_position = nullptr, HashSet<Ref<ShaderInclude>> *r_includes = nullptr, List<ScriptLanguage::CodeCompletionOption> *r_completion_options = nullptr, IncludeCompletionFunction p_include_completion_func = nullptr); + Error preprocess(const String &p_code, const String &p_filename, String &r_result, String *r_error_text = nullptr, List<FilePosition> *r_error_position = nullptr, List<Region> *r_regions = nullptr, HashSet<Ref<ShaderInclude>> *r_includes = nullptr, List<ScriptLanguage::CodeCompletionOption> *r_completion_options = nullptr, IncludeCompletionFunction p_include_completion_func = nullptr); static void get_keyword_list(List<String> *r_keywords, bool p_include_shader_keywords); static void get_pragma_list(List<String> *r_pragmas); |