OverviewFilesCommitsIssuesDocsReleasesPeers

nvidia-rtx-godot commits / 9f65fe1

Shade with the default hit group while a custom one is still compiling
Custom hit-group shaders are compiled on a WorkerThreadPool task, so for the first frames after a material appears its HG is not ready. build_tlas dropped those surfaces from the TLAS entirely, which made the geometry INVISIBLE until the compile landed -- several seconds for a large shader with multiple pipeline variants (dc_level and dc_terrain each compile two). Fall back to hit group 0 instead of skipping: the surface enters the TLAS immediately and shades with standard material data, then upgrades to its own shader once that is ready. Pop-in of shading detail rather than of geometry. This also keeps a permanently-failed hit group (HGState::Failed, which never becomes ready) visible rather than silently absent -- the failure mode that made the previous three shader bugs present as "the level does not render" with no indication that anything had been dropped. The instance-flag branch below now keys off the same fallen-back offset, so a surface shading through the default HG takes the standard-material alpha path. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
9f65fe1cfa0df2779d784d01186908f6cc323ec2
by plankatron <fleeky@gmail.com> · 2026-07-29T15:06:38.000Z

Changed files (1) +18 -7

servers/rendering/renderer_rd/forward_clustered/render_raytracing.cpp +18 -7
……@@ -1741,10 +1741,19 @@ RTViewportState *RenderRaytracing::build_tlas(const RenderDataRD *p_render_data,
17411741 uint16_t material_counter = material_storage->material_get_rt_invalidation_counter(material_rid);
17421742 RTMaterialData *mat_data = process_material(material_rid, material_counter);
17431743
1744 if (mat_data->rt_sbt_offset > 0 &&
1745 !rt_shader_singleton->is_hg_ready_in_bundle(mat_data->rt_sbt_offset, p_rt_flags)) {
1746 surf = surf->next;
1747 continue;
1744 // Custom hit groups compile on a worker thread, so a surface's HG is
1745 // typically not ready for the first frames after a material appears.
1746 // Dropping the surface from the TLAS meanwhile makes the geometry
1747 // INVISIBLE until the compile lands (seconds, for a large shader with
1748 // several pipeline variants). Fall back to the default hit group
1749 // instead: the surface renders immediately with standard material
1750 // shading and upgrades to its own shader once that is ready.
1751 //
1752 // A permanently-failed HG (HGState::Failed) never becomes ready, so
1753 // this also keeps such geometry visible rather than silently absent.
1754 uint32_t sbt_offset = mat_data->rt_sbt_offset;
1755 if (sbt_offset > 0 && !rt_shader_singleton->is_hg_ready_in_bundle(sbt_offset, p_rt_flags)) {
1756 sbt_offset = 0;
17481757 }
17491758
17501759 // Compute or reuse cached final transform (instance * aabb_transform for compressed meshes).
……@@ -1785,7 +1794,7 @@ RTViewportState *RenderRaytracing::build_tlas(const RenderDataRD *p_render_data,
17851794 }
17861795#endif
17871796
1788 sbt_offsets.push_back(mat_data->rt_sbt_offset);
1797 sbt_offsets.push_back(sbt_offset);
17891798 material_data.push_back(mat_data->data);
17901799
17911800 // Determine per-instance TLAS flags from material properties.
……@@ -1807,10 +1816,12 @@ RTViewportState *RenderRaytracing::build_tlas(const RenderDataRD *p_render_data,
18071816 inst_flags |= RD::ACCELERATION_STRUCTURE_INSTANCE_TRIANGLE_FLIP_FACING_BIT;
18081817 }
18091818
1810 if (mat_data->rt_sbt_offset > 0) {
1819 // Uses the possibly-fallen-back offset: a surface shading through the
1820 // default hit group must take the standard-material branch below.
1821 if (sbt_offset > 0) {
18111822 // Custom shader: only enable any-hit if the shader uses alpha clip.
18121823 const SceneShaderRaytracing::CustomShaderEntry *cse =
1813 rt_shader_singleton->get_custom_shader_entry(mat_data->rt_sbt_offset);
1824 rt_shader_singleton->get_custom_shader_entry(sbt_offset);
18141825 if (!cse || !cse->uses_alpha_clip) {
18151826 inst_flags |= RD::ACCELERATION_STRUCTURE_INSTANCE_FORCE_OPAQUE_BIT;
18161827 }