[PR #471] d3d12: implement LEONIDA_TEXTURE_MIP_DROP quality switch (#6043) #522

Open
opened 2026-11-26 20:18:09 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/471
Author: @antikohza
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: feature/texture-mip-drop-6043


📝 Commits (1)

  • 87064bf d3d12: implement LEONIDA_TEXTURE_MIP_DROP quality switch (#6043)

📊 Changes

8 files changed (+1205 additions, -16 deletions)

View changed files

📝 docs/boot.md (+3 -0)
📝 docs/d3d12_vulkan.md (+4 -1)
📝 runtime/CMakeLists.txt (+7 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+119 -9)
📝 runtime/src/vulkan_replay.h (+98 -6)
➕ runtime/test/d3d12_texture_mip_drop_test.cpp (+374 -0)
➕ tests/test_command_list_mip_skip.py (+71 -0)
➕ tests/test_texture_mip_drop.py (+529 -0)

📄 Description

Fixes: #6043 (original tracking issue #6043 / low-VRAM memory pressure #2375)

What and why

Adds a configurable low-VRAM quality switch LEONIDA_TEXTURE_MIP_DROP=N (0..3, default 0) to drop top mip level(s) of pure sampled textures at creation time.

  • Pure sampled textures (textures without RenderTarget, DepthStencil, or UAV flags) have their top N mips dropped, reducing physical texture allocation size by ~75% (drop 1) or ~93.75% (drop 2).
  • Dimensions are dynamically shifted (Width >> drop, Height >> drop, Depth >> drop) with a minimum clamp of 1.
  • Mip count is reduced to MipLevels - drop in the underlying VkImageCreateInfo and allocation query.
  • Replaces function-local static initialization guards with a constant-initialized atomic (std::atomic<int> s_texture_mip_drop{-1}) to avoid thread-safety init guards on guest threads (RT-488).
  • Subresource remapping:
    • Map() / Unmap() cleanly rebinds subresources to the reduced mip structure and validates bounds against original descriptor counts.
    • cpu_copy() ignores CPU writes to dropped mips (returns S_OK) and zeroes destination buffers on read; validates box offsets and format blocks.
  • Shader Resource Views (SRVs):
    • Automatically rebases MostDetailedMip down by dropped mips and adjusts ResourceMinLODClamp.
  • Command Lists & Replay (vulkan_replay.h):
    • Copies to/from dropped mips (prepare_texture_copy, prepare_resource_copy) are skipped (p.skip = true).
    • Retained mip subresources are remapped to match the reduced image.
    • Resource barriers (TransitionBarrier, TextureBarrier) skip dropped mips and rebase subresource ranges.

Tested

  • Python semantic test suite tests/test_texture_mip_drop.py: 22/22 tests passed (validates dimension scaling, SRV clamp remapping, CPU copy skipping/zeroing, and sentinel handling).
  • Python command list test suite tests/test_command_list_mip_skip.py: 2/2 tests passed (validates command list dropped mip copy skipping).
  • D3D12 device fixture runtime/test/d3d12_texture_mip_drop_test.cpp: passed on D3D12 device (verifies reduced VRAM allocation footprint, SRV sampling, and dropped-mip readback).

GPUs tested: NVIDIA GeForce RTX 4050 Laptop GPU (Windows 11, driver 572.16), Apple M-series (macOS 15)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md (n/a - D3D12 runtime switch).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/471 **Author:** [@antikohza](https://github.com/antikohza) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feature/texture-mip-drop-6043` --- ### 📝 Commits (1) - [`87064bf`](https://github.com/ubiquitarianism/leonida/commit/87064bfe8e73155542006b81d01834a8687889a3) d3d12: implement LEONIDA_TEXTURE_MIP_DROP quality switch (#6043) ### 📊 Changes **8 files changed** (+1205 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `docs/boot.md` (+3 -0) 📝 `docs/d3d12_vulkan.md` (+4 -1) 📝 `runtime/CMakeLists.txt` (+7 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+119 -9) 📝 `runtime/src/vulkan_replay.h` (+98 -6) ➕ `runtime/test/d3d12_texture_mip_drop_test.cpp` (+374 -0) ➕ `tests/test_command_list_mip_skip.py` (+71 -0) ➕ `tests/test_texture_mip_drop.py` (+529 -0) </details> ### 📄 Description Fixes: #6043 (original tracking issue #6043 / low-VRAM memory pressure #2375) ### What and why Adds a configurable low-VRAM quality switch `LEONIDA_TEXTURE_MIP_DROP=N` (0..3, default 0) to drop top mip level(s) of pure sampled textures at creation time. - Pure sampled textures (textures without RenderTarget, DepthStencil, or UAV flags) have their top N mips dropped, reducing physical texture allocation size by ~75% (drop 1) or ~93.75% (drop 2). - Dimensions are dynamically shifted (`Width >> drop`, `Height >> drop`, `Depth >> drop`) with a minimum clamp of 1. - Mip count is reduced to `MipLevels - drop` in the underlying `VkImageCreateInfo` and allocation query. - Replaces function-local static initialization guards with a constant-initialized atomic (`std::atomic<int> s_texture_mip_drop{-1}`) to avoid thread-safety init guards on guest threads (`RT-488`). - Subresource remapping: - `Map()` / `Unmap()` cleanly rebinds subresources to the reduced mip structure and validates bounds against original descriptor counts. - `cpu_copy()` ignores CPU writes to dropped mips (returns `S_OK`) and zeroes destination buffers on read; validates box offsets and format blocks. - Shader Resource Views (SRVs): - Automatically rebases `MostDetailedMip` down by dropped mips and adjusts `ResourceMinLODClamp`. - Command Lists & Replay (`vulkan_replay.h`): - Copies to/from dropped mips (`prepare_texture_copy`, `prepare_resource_copy`) are skipped (`p.skip = true`). - Retained mip subresources are remapped to match the reduced image. - Resource barriers (`TransitionBarrier`, `TextureBarrier`) skip dropped mips and rebase subresource ranges. ### Tested - Python semantic test suite `tests/test_texture_mip_drop.py`: 22/22 tests passed (validates dimension scaling, SRV clamp remapping, CPU copy skipping/zeroing, and sentinel handling). - Python command list test suite `tests/test_command_list_mip_skip.py`: 2/2 tests passed (validates command list dropped mip copy skipping). - D3D12 device fixture `runtime/test/d3d12_texture_mip_drop_test.cpp`: passed on D3D12 device (verifies reduced VRAM allocation footprint, SRV sampling, and dropped-mip readback). GPUs tested: NVIDIA GeForce RTX 4050 Laptop GPU (Windows 11, driver 572.16), Apple M-series (macOS 15) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md` (n/a - D3D12 runtime switch). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#522
No description provided.