OverviewFilesCommitsIssuesDocsReleasesPeers

nvidia-rtx-godot commits / 03825b4

Skip CUSTOM fetching entirely on surfaces that carry no custom arrays
The custom-hit-group path re-derived the triangle indices and called fetch_custom four times on every hit, even though fetch_custom's own early-out meant three or four of those did nothing. The index re-derivation ran unconditionally. Gate the whole block on the geometry actually declaring a CUSTOM array, so a surface without one pays a single packed-word test instead of three buffer reads plus four calls -- per hit, per bounce, per sample. This only reduces cost I added earlier today; it is not a fix for the wider path-tracing slowdown, where even the default hit group is affected. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
03825b460ede2e3ad8dfe4bcf25cd85a8929bb24
by plankatron <fleeky@gmail.com> · 2026-07-29T17:31:03.000Z

Changed files (1) +16 -7

servers/rendering/renderer_rd/shaders/raytracing/scene_raytracing_raygen.glsl +16 -7
……@@ -332,14 +332,23 @@ void main() {
332332 // live state cost register pressure (and so occupancy) on every hit shader,
333333 // including the ones that never touch CUSTOM. fetch_custom early-outs on
334334 // surfaces without the array, so this is cheap when unused.
335 // Skip the whole block -- including re-deriving the triangle indices -- when
336 // the surface carries no CUSTOM arrays at all, which is the common case.
335337 GeometryData rt_cgeom = geometries[h.geometry_idx];
336 uint rt_ci0, rt_ci1, rt_ci2;
337 get_triangle_indices(rt_cgeom, rt_ci0, rt_ci1, rt_ci2);
338 vec3 rt_cbary = vec3(1.0 - attribs.x - attribs.y, attribs.x, attribs.y);
339 vec4 rt_custom0 = fetch_custom(rt_cgeom, 0u, rt_ci0, rt_ci1, rt_ci2, rt_cbary);
340 vec4 rt_custom1 = fetch_custom(rt_cgeom, 1u, rt_ci0, rt_ci1, rt_ci2, rt_cbary);
341 vec4 rt_custom2 = fetch_custom(rt_cgeom, 2u, rt_ci0, rt_ci1, rt_ci2, rt_cbary);
342 vec4 rt_custom3 = fetch_custom(rt_cgeom, 3u, rt_ci0, rt_ci1, rt_ci2, rt_cbary);
338 vec4 rt_custom0 = vec4(0.0);
339 vec4 rt_custom1 = vec4(0.0);
340 vec4 rt_custom2 = vec4(0.0);
341 vec4 rt_custom3 = vec4(0.0);
342 if (rt_cgeom.custom_packed[0] != OFFSET_NONE || rt_cgeom.custom_packed[1] != OFFSET_NONE ||
343 rt_cgeom.custom_packed[2] != OFFSET_NONE || rt_cgeom.custom_packed[3] != OFFSET_NONE) {
344 uint rt_ci0, rt_ci1, rt_ci2;
345 get_triangle_indices(rt_cgeom, rt_ci0, rt_ci1, rt_ci2);
346 vec3 rt_cbary = vec3(1.0 - attribs.x - attribs.y, attribs.x, attribs.y);
347 rt_custom0 = fetch_custom(rt_cgeom, 0u, rt_ci0, rt_ci1, rt_ci2, rt_cbary);
348 rt_custom1 = fetch_custom(rt_cgeom, 1u, rt_ci0, rt_ci1, rt_ci2, rt_cbary);
349 rt_custom2 = fetch_custom(rt_cgeom, 2u, rt_ci0, rt_ci1, rt_ci2, rt_cbary);
350 rt_custom3 = fetch_custom(rt_cgeom, 3u, rt_ci0, rt_ci1, rt_ci2, rt_cbary);
351 }
343352 vec3 rt_normal = h.geometry_normal;
344353 vec3 rt_tangent = h.tangent;
345354 vec3 rt_bitangent = h.bitangent;