Commit 782358f
committed
Convert engineLoadTXD textures to D3DPOOL_DEFAULT (#4062)
GTA SA's RenderWare loader (D3DResourceSystem::CreateTexture @ 0x730510)
hardcodes D3DPOOL_MANAGED for every texture in a TXD. MANAGED textures
are mirrored 1:1 in system memory so D3D9 can auto-restore them on a
device reset, which is exactly what makes a 10 MB DXT TXD count as
~20 MB of working set in MTA's process.
After RW finishes decoding a script-loaded TXD in CRenderWareSA::ReadTXD
we now walk every raster, allocate a fresh IDirect3DTexture9 in
D3DPOOL_DEFAULT, copy each mip through a transient SYSTEMMEM scratch +
UpdateTexture, release the original MANAGED texture, and swap the
pointer in rasterExt->texture. The release deliberately bypasses
D3DResourceSystem::DestroyTexture so the gD3DTextureBuffer cache
(MANAGED-only, keyed by w/h/format) never sees DEFAULT-pool entries;
the destroy intercept in CRenderWareSA::DestroyTexture NULLs
rasterExt->texture before RwTextureDestroy so _rwD3D9RasterDestroy
hits its existing early-out.
Conversion happens before ScriptAddedTxd so the shader-matching map
(m_D3DDataTexInfoMap) is keyed against the new IDirect3DTexture9
pointer the renderer will see.
Cube maps, palettised rasters, and unrecognised D3DFORMATs are skipped
and stay MANAGED; per-texture failures (out of vram, lock failure)
silently leave the original MANAGED texture in place.
Because DEFAULT-pool resources are auto-destroyed on a D3D9 cooperative
loss, CRenderWareSA gains OnDeviceLost / OnDeviceReset hooks called
from CGraphics around the existing CRenderItemManager handling.
CClientTXD implements a new CRwReplacementOwner interface and re-decodes
on Reset: file-path TXDs re-read from disk, raw-data TXDs use the
m_FileData buffer that LoadFromBuffer already keeps for the clothes
system.
Memory impact for a 10 MB TXD:
- file path (the common case for vehicle/skin packs):
~10 MB sysmem dropped, VRAM usage unchanged. ~50% total saving.
- raw-data path (rare; engineLoadTXD with a buffer):
m_FileData was already kept by master for clothes compatibility, so
the MANAGED shadow is replaced by that buffer at no net memory cost.1 parent 7f23f61 commit 782358f
8 files changed
Lines changed: 595 additions & 7 deletions
File tree
- Client
- core/Graphics
- game_sa
- mods/deathmatch/logic
- sdk/game
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
1727 | 1729 | | |
1728 | 1730 | | |
1729 | 1731 | | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
1730 | 1739 | | |
1731 | 1740 | | |
1732 | 1741 | | |
| |||
1757 | 1766 | | |
1758 | 1767 | | |
1759 | 1768 | | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
1760 | 1776 | | |
1761 | 1777 | | |
1762 | 1778 | | |
| |||
0 commit comments