renderer: fix DCC fast clears for images with more than one mip level (cp2077) #1946
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1946
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1946/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ArtyomZabroda on GitHub · 2026-10-27 22:26 UTC · original
ArtyomZabroda:pr/dcc-fast-clear→main· +393 −18 · 6 files · 1 commits · closed without mergingAddresses #182
Cyberpunk 2077 uses DCC fast clears on render targets that have more than one mip level. Before this patch, TileGetDccSize simply returned false for any surface with more than one mip level, and ResolveRenderColorTarget ignored that result:
As a result, the image got a DCC metadata range of size 0, and MaterializeColorClear returned early. It also rejects every image with more than one mip level:
These missed clears cause graphics artifacts in the main menu: the UI render target is never cleared, so the previous frame's menu and cursor stay visible under the new one:
There is also another problem. In Cyberpunk 2077 a render target with more than one mip level



is sometimes sampled without any draw into it: its first use in the frame is a compute pass that
reads level 0 and writes the other levels, while level 0's DCC metadata holds the clear code 0x00.
The emulator creates a new image on that texture binding and fills it from guest memory, which
still holds the bytes of a previous resource, and the clear is never applied, so the generated
mip chain contains garbage. Example:
Changes
tile.cpp / tile.h
TileGetDccSizeintoTileGetDccBlockSize, so every DCC function computes the block raster the same way.TileGetDccLevelRange, which returns the offset and size of one mip level inside the DCC metadata. Like guest color data, the metadata of a mip chain runs backwards: the smallest level comes first and level 0 comes last.TileGetDccSizenow supports single-layer images with more than one mip level by summing the sizes of all levels. Images with more than one mip level and more than one layer (arrays, cube maps) still return false, because the order of layers and levels in their metadata is not verified.colorRenderTarget.cpp
ResolveRenderColorTargetnow checks the result ofTileGetDccSize. If the layout is unsupported, it logsRenderColorTarget: unsupported DCC layout, fast clears are ignored(at most 16 times per run) instead of silently dropping the clears.textureCache.cpp / textureCache.h
MaterializeColorClearno longer rejects every image with more than one mip level. For a render target it checks only the metadata of the bound mip level (fromTileGetDccLevelRange), clears that level and writes0xffonly into its range. The whole chain cannot be checked at once: the game fast clears only level 0 and fills the other levels with a compute shader, so the metadata of the whole chain never holds one uniform code. The GPU path added inb540579checks the same per-level range. Images with one mip level behave exactly as before.MaterializeFreshTextureClearfor the second problem. When a DCC render-target image (tile modekRenderTarget, single layer, single sample) with more than one mip level is bound as a texture and the GPU has not written to it yet, every bound level whose metadata holds one uniform clear code is cleared.0xffthere corrupted the game's heap and crashed it during testing.ClearImagemarks the image as GPU-modified, so later calls return early. The same happens after compute writes the generated mips through a storage binding.@coderabbitai[bot] on GitHub · 2026-10-27 22:31 UTC · original · edited 2026-10-28 11:41 UTC
Walkthrough
The DCC layout API now calculates metadata ranges for mip levels and supports eligible mip chains. Texture clear materialization uses the selected mip’s metadata range for render-target and sampled-texture views. Tests cover layout calculations, clear behavior, metadata updates, and unsupported inputs. The render-target path also logs failed DCC size calculations.
Suggested reviewers:
nmzik,claxten10Priority:
Normal
Change: Bug fix
Merge Risk:
Moderate · up to
7c88eSampling a multi-mip render target through views of different mip levels can leave some levels with stale contents instead of the expected clear. This is a rendering-correctness problem in a narrow case and should be fixed before merge.
Pre-merge checks:
4
Full details: Description check
Explanation
The description states the problem (DCC fast clears skipped for render targets with multiple mip levels), the changed functions (TileGetDccSize, ResolveRenderColorTarget, MaterializeColorClear, the new MaterializeFreshTextureClear), and the test scenario. It is specific and clearly related to the changeset, so it passes this lenient check.
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 helpto get the list of available commands.@ -1184,0 +1221,4 @@std::scoped_lock lock {m_lock};if (m_slot_images[id].IsGpuModified()) {return;}@coderabbitai[bot] on GitHub · 2026-10-27 22:31 UTC · original
Preserve fresh clears for levels outside the first texture view.
If a fresh DCC mip chain is sampled through a view of level 0, the helper checks only level 0. A clear of that level marks the whole image GPU-modified. When a later view selects level 1, this guard skips its clear, so level 1 retains older resource bytes despite a valid clear key. Track materialization or GPU ownership per level, or apply all eligible level clears before setting the image-wide flag. (raw.githubusercontent.com)
@coderabbitai[bot] on GitHub · 2026-10-27 22:31 UTC · original · reviewed
Actionable comments posted: 1
e1dabfff-f246-4110-8409-bf9db795a978Reviewing files that changed from the base of the PR and between
1be1c6c4f9and7c88e3eaee.src/graphics/guest_gpu/tile.cppsrc/graphics/guest_gpu/tile.hsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/colorRenderTarget.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@Nmzik on GitHub · 2026-10-30 04:27 UTC · original
@ArtyomZabroda Credited! Thanks. multi mipmap logic inside MaterializeColorClear
Pull request closed