Skip to content

Fix Vulkan garbage data in frame (and grammar update =D) - #1316

Merged
JoltedJon merged 1 commit into
Redot-Engine:masterfrom
GeneralProtectionFault:viewport_texture_fix
Aug 2, 2026
Merged

Fix Vulkan garbage data in frame (and grammar update =D)#1316
JoltedJon merged 1 commit into
Redot-Engine:masterfrom
GeneralProtectionFault:viewport_texture_fix

Conversation

@GeneralProtectionFault

@GeneralProtectionFault GeneralProtectionFault commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

fixes #1308
This partially addresses this issue.
The crux is, a (Vulkan) frame is not initialized in the same frame as a scene/subviewport being added to the tree. This might also overlap the previous fix #1303 , which did fix the "hope-based" sibling subviewport ordering. However, immediately when added to the tree, there's a potential for more than 1 sibling subviewport to have no dependencies.

The above basically results in rendering garbage data from the GPU in some cases. This PR just blanks that out so we don't get bugged visuals in the subviewport. Before we could actually see visual artifacts/textures , but this makes it a blank/transparent frame.

If we change the example project so the timout on the background_3d scene is 1.0 instead of 0.1, then we see the blank frame even after this PR, but no garbage data.

It looks like it's more than 1 frame in some cases, so this might be good to note for posterity, if we have non-deterministic behavior in the Vulkan layer, but this should alleviate the problem in the majority of cases.

Anyhoo, also changed "Backup" to "Back up" for the migration pop-up.

Summary by CodeRabbit

  • Bug Fixes

    • Render targets now initialize newly created color textures to transparent black, preventing undefined visual results on first use.
    • Corrected the recovery-mode prompt wording to “Back up project first” across supported languages.
  • Documentation

    • Added clarification for the relationship between internal render-target images and their exposed textures.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The project manager backup prompt now uses “Back up project first” across localized message keys. Newly allocated RD render-target textures are cleared to transparent black and support copy-to usage.

Changes

Backup prompt wording

Layer / File(s) Summary
Backup prompt and localization keys
editor/project_manager/project_manager.cpp, editor/translations/editor/*.po
The prompt and localized msgid entries change from “Backup project first” to “Back up project first”. Existing translations remain unchanged.

Render-target initialization

Layer / File(s) Summary
Render-target clearing and usage
servers/rendering/renderer_rd/storage_rd/texture_storage.cpp, servers/rendering/renderer_rd/storage_rd/texture_storage.h
Newly allocated color and multisample textures are cleared to transparent black. Render-target usage flags include copy-to support. Documentation describes the relationship between RenderTarget::color and RenderTarget::texture.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: shakai-dev

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The render-target clear addresses Vulkan garbage frames in #1308, but no dependency or sibling-ordering changes implement #1303. Either unlink #1303 or add the required subviewport dependency tracking and sibling render-ordering changes.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the Vulkan frame-data fix and the accompanying grammar update.
Out of Scope Changes check ✅ Passed The render-target initialization fix and migration-label grammar update match the stated pull request objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
servers/rendering/renderer_rd/storage_rd/texture_storage.h (1)

465-466: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Fix the grammatical inconsistency in the documentation comment.

Consider updating the comment to use consistent verb forms (e.g., "Allocates" to match "wires").

📝 Proposed fix
-	/// Allocate GPU image (RenderTarget::color) and wires it to RenderTarget::texture,
+	/// Allocates GPU image (RenderTarget::color) and wires it to RenderTarget::texture,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@servers/rendering/renderer_rd/storage_rd/texture_storage.h` around lines 465
- 466, Update the documentation comment above the RenderTarget GPU image
allocation declaration to use consistent third-person verb forms, changing
“Allocate” to “Allocates” while preserving the existing description.
servers/rendering/renderer_viewport.cpp (1)

933-937: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove commented-out debug code.

Commented-out debugging logs should be removed to keep the production codebase clean. If these diagnostics are still needed for future debugging, consider placing them behind a feature flag or a disabled-by-default macro instead of commenting them out.

♻️ Proposed fix
-		// print_verbose(vformat("[DRAW] rt=%d  used_by_vp=%d  was_used=%s",
-		//     vp->render_target.get_id(),
-		//     vp->used_by_viewport.get_id(),
-		//     RSG::texture_storage->render_target_was_used(vp->render_target) ? "Y" : "N"));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@servers/rendering/renderer_viewport.cpp` around lines 933 - 937, Remove the
commented-out print_verbose debug block near the viewport rendering code; do not
replace it with another disabled comment, and leave the surrounding rendering
logic unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@editor/translations/editor/fr.po`:
- Around line 9120-9121: Update the French msgstr for “Back up project first” to
use a fully localized, natural French translation such as “Sauvegarder d'abord
le projet” or “Sauvegardez d'abord le projet,” replacing the mixed English
wording.

---

Nitpick comments:
In `@servers/rendering/renderer_rd/storage_rd/texture_storage.h`:
- Around line 465-466: Update the documentation comment above the RenderTarget
GPU image allocation declaration to use consistent third-person verb forms,
changing “Allocate” to “Allocates” while preserving the existing description.

In `@servers/rendering/renderer_viewport.cpp`:
- Around line 933-937: Remove the commented-out print_verbose debug block near
the viewport rendering code; do not replace it with another disabled comment,
and leave the surrounding rendering logic unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d0adefa3-c20b-4865-a230-82328d96eaf0

📥 Commits

Reviewing files that changed from the base of the PR and between d890d7d and c7e0cd1.

📒 Files selected for processing (21)
  • editor/project_manager/project_manager.cpp
  • editor/translations/editor/de.po
  • editor/translations/editor/es.po
  • editor/translations/editor/fa.po
  • editor/translations/editor/fr.po
  • editor/translations/editor/ga.po
  • editor/translations/editor/it.po
  • editor/translations/editor/ja.po
  • editor/translations/editor/ko.po
  • editor/translations/editor/pl.po
  • editor/translations/editor/pt_BR.po
  • editor/translations/editor/ru.po
  • editor/translations/editor/sv.po
  • editor/translations/editor/ta.po
  • editor/translations/editor/tr.po
  • editor/translations/editor/uk.po
  • editor/translations/editor/zh_Hans.po
  • editor/translations/editor/zh_Hant.po
  • servers/rendering/renderer_rd/storage_rd/texture_storage.cpp
  • servers/rendering/renderer_rd/storage_rd/texture_storage.h
  • servers/rendering/renderer_viewport.cpp

Comment on lines +9120 to 9121
msgid "Back up project first"
msgstr "Backup le projet d'abord"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Update the French translation.

msgstr still says “Backup le projet d'abord,” which mixes English and French and uses an unnatural verb form. Use a fully localized label such as Sauvegarder d'abord le projet or Sauvegardez d'abord le projet.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@editor/translations/editor/fr.po` around lines 9120 - 9121, Update the French
msgstr for “Back up project first” to use a fully localized, natural French
translation such as “Sauvegarder d'abord le projet” or “Sauvegardez d'abord le
projet,” replacing the mixed English wording.

@Shakai-Dev Shakai-Dev added this to the Redot LTS 26.3 milestone Jul 20, 2026
Shakai-Dev
Shakai-Dev previously approved these changes Jul 20, 2026

@Shakai-Dev Shakai-Dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix LGTM

Comment thread servers/rendering/renderer_viewport.cpp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@servers/rendering/renderer_rd/storage_rd/texture_storage.cpp`:
- Line 3386: Update the new texture_clear calls in the render-target setup and
related paths around rt->color and rt->color_multisample (including the
locations near 4336-4339) to run only when the backend reports
API_TRAIT_TEXTURE_OUTPUTS_REQUIRE_CLEARS. Add CAN_COPY_TO_BIT only for the
explicit-usage path, unless an existing in-code consumer requires it, while
preserving the current clear behavior on backends that need output clears.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 258a6ec4-48df-430f-a152-107fb047c26a

📥 Commits

Reviewing files that changed from the base of the PR and between fc3bc59 and 03d85a0.

📒 Files selected for processing (20)
  • editor/project_manager/project_manager.cpp
  • editor/translations/editor/de.po
  • editor/translations/editor/es.po
  • editor/translations/editor/fa.po
  • editor/translations/editor/fr.po
  • editor/translations/editor/ga.po
  • editor/translations/editor/it.po
  • editor/translations/editor/ja.po
  • editor/translations/editor/ko.po
  • editor/translations/editor/pl.po
  • editor/translations/editor/pt_BR.po
  • editor/translations/editor/ru.po
  • editor/translations/editor/sv.po
  • editor/translations/editor/ta.po
  • editor/translations/editor/tr.po
  • editor/translations/editor/uk.po
  • editor/translations/editor/zh_Hans.po
  • editor/translations/editor/zh_Hant.po
  • servers/rendering/renderer_rd/storage_rd/texture_storage.cpp
  • servers/rendering/renderer_rd/storage_rd/texture_storage.h
🚧 Files skipped from review as they are similar to previous changes (19)
  • servers/rendering/renderer_rd/storage_rd/texture_storage.h
  • editor/project_manager/project_manager.cpp
  • editor/translations/editor/ja.po
  • editor/translations/editor/fr.po
  • editor/translations/editor/de.po
  • editor/translations/editor/it.po
  • editor/translations/editor/es.po
  • editor/translations/editor/zh_Hans.po
  • editor/translations/editor/ga.po
  • editor/translations/editor/pl.po
  • editor/translations/editor/tr.po
  • editor/translations/editor/pt_BR.po
  • editor/translations/editor/ko.po
  • editor/translations/editor/sv.po
  • editor/translations/editor/uk.po
  • editor/translations/editor/ru.po
  • editor/translations/editor/fa.po
  • editor/translations/editor/zh_Hant.po
  • editor/translations/editor/ta.po

// explicit clear here, a consumer (e.g. Sprite3D) can sample this texture before
// any draw ever writes to it (e.g. SubViewport with VIEWPORT_UPDATE_WHEN_VISIBLE,
// whose was_used starts false), reading uninitialized VRAM garbage for one frame.
RD::get_singleton()->texture_clear(rt->color, Color(0, 0, 0, 0), 0, 1, 0, rd_color_attachment_format.array_layers);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n -C 10 \
  --glob '*.cpp' \
  --glob '*.h' \
  'API_TRAIT_TEXTURE_OUTPUTS_REQUIRE_CLEARS|texture_clear\(|_texture_check_pending_clear|render_target_get_color_usage_bits|CAN_COPY_TO_BIT'

Repository: Redot-Engine/redot-engine

Length of output: 163


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "Repo files matching texture_storage.cpp:"
fd 'texture_storage\.cpp$' . || true

echo
echo "Targeted symbol search across repo (text):"
rg -n -C 8 \
  'API_TRAIT_TEXTURE_OUTPUTS_REQUIRE_CLEARS|texture_clear\(|_texture_check_pending_clear|render_target_get_color_usage_bits|CAN_COPY_TO_BIT|pending_clear' . || true

echo
echo "Diff stat:"
git diff --stat || true
echo
echo "Relevant diff hits:"
git diff --unified=8 -- servers/rendering/renderer_rd/storage_rd/texture_storage.cpp 2>/dev/null || true

Repository: Redot-Engine/redot-engine

Length of output: 50382


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "Line count and relevant ranges:"
wc -l servers/rendering/renderer_rd/storage_rd/texture_storage.cpp servers/rendering/rendering_device.cpp servers/rendering/rendering_device_driver_d3d12.cpp || true

echo
echo "texture_storage.cpp around changed ranges:"
sed -n '3360,3415p' servers/rendering/renderer_rd/storage_rd/texture_storage.cpp
sed -n '4320,4350p' servers/rendering/renderer_rd/storage_rd/texture_storage.cpp

echo
echo "rendering_device.h API_TRAIT declarations/classes:"
sed -n '700,810p' servers/rendering/rendering_device_driver.h

echo
echo "rendering_device.cpp resource_trait_get and texture_clear implementations:"
rg -n -C 12 'api_trait_get|texture_clear|_texture_check_pending_clear|pending_clear|TextureFormatID' servers/rendering/rendering_device.cpp

echo
echo "D3D12 trait_get implementation:"
sed -n '5745,5790p' drivers/d3d12/rendering_device_driver_d3d12.cpp

echo
echo "Other non-doc/translation CAN_COPY_TO_BIT code usages:"
rg -n --glob '!doc/**' --glob '!drivers/sdl2/**'  \
  'TEXTURE_USAGE_CAN_COPY_TO_BIT|CAN_COPY_TO_BIT' servers modules drivers scripts plugins | head -n 250

Repository: Redot-Engine/redot-engine

Length of output: 50381


Make the new clear path backend-conditional.

RenderingDevice::texture_clear() checks pending clears first, then queues its own implicit clear. D3D12 returns true for API_TRAIT_TEXTURE_OUTPUTS_REQUIRE_CLEARS, so the new texture_clear(rt->color, ...) and texture_clear(rt->color_multisample, ...) add a second full clear after the pending clear. Gate these calls on backends needing API_TRAIT_TEXTURE_OUTPUTS_REQUIRE_CLEARS, and add CAN_COPY_TO_BIT only for the explicit-usage path unless another in-code consumer requires it.

Also applies to: 3404, 4336-4339

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@servers/rendering/renderer_rd/storage_rd/texture_storage.cpp` at line 3386,
Update the new texture_clear calls in the render-target setup and related paths
around rt->color and rt->color_multisample (including the locations near
4336-4339) to run only when the backend reports
API_TRAIT_TEXTURE_OUTPUTS_REQUIRE_CLEARS. Add CAN_COPY_TO_BIT only for the
explicit-usage path, unless an existing in-code consumer requires it, while
preserving the current clear behavior on backends that need output clears.

@JoltedJon
JoltedJon enabled auto-merge (rebase) August 2, 2026 02:43

@Shakai-Dev Shakai-Dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from the rendering side of things

@JoltedJon
JoltedJon merged commit e1fb382 into Redot-Engine:master Aug 2, 2026
17 checks passed
@github-project-automation github-project-automation Bot moved this from Open to Done in Engine Overview Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Additional Subviewport Flicker Bug

3 participants