Skip to content

fix(textureloader): Simplify and fix faulty implementations of texture reduction (2)#2814

Open
xezon wants to merge 1 commit into
TheSuperHackers:mainfrom
xezon:xezon/fix-mipmaps
Open

fix(textureloader): Simplify and fix faulty implementations of texture reduction (2)#2814
xezon wants to merge 1 commit into
TheSuperHackers:mainfrom
xezon:xezon/fix-mipmaps

Conversation

@xezon

@xezon xezon commented Jun 20, 2026

Copy link
Copy Markdown

This change further simplifies and fixes the implementations of texture reduction.

I tested retail vs patched game with different texture reduction levels and it looked identical.

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Refactor Edits the code with insignificant behavior changes, is never user facing Fix Is fixing something, but is not user facing labels Jun 20, 2026
@greptile-apps

greptile-apps Bot commented Jun 20, 2026

Copy link
Copy Markdown

Greptile Summary

This PR simplifies the texture reduction pipeline by making Width, Height, and Depth hold the post-reduction dimensions directly inside Begin_Compressed_Load rather than using separate reduced_* locals. The redundant Validate_Texture_Size calls are removed because Apply_Dim_Reduction already performs that validation internally, and Load_Compressed_Mipmap drops its manual width >>= Reduction pre-shift since Get_Width() / Get_Height() now return already-reduced values.

  • Named constants MinTextureDim and MinTextureDepth replace magic literals 4u and 1u throughout the reduction logic.
  • The MipLevelCount field is initialized to MIP_LEVELS_ALL (instead of raw 0) and Apply_Mip_Reduction uses WWASSERT to make the preconditions established by Validate_Reduction explicit, replacing the old silent underflow recovery.
  • VolumeTextureLoadTaskClass::Load_Compressed_Mipmap now clamps depth correctly on each shift with max(depth >> 1, MinTextureDepth) rather than relying on the clamp at the start of the next iteration.

Confidence Score: 4/5

Safe to merge; the refactored paths are logically equivalent to the originals for all valid inputs, and the author has manually verified retail vs. patched behaviour at multiple reduction levels.

The core logic change — writing reduced dimensions directly into Width/Height instead of local variables, then relying on those values in Load_Compressed_Mipmap — is correct because Apply_Dim_Reduction already validates through Validate_Texture_Size internally. The replacement of silent mip-count underflow recovery with WWASSERT is safe because Validate_Reduction guarantees the asserted invariants before Apply_Mip_Reduction is called. One conservative pre-existing quirk remains: the max_mip_level_count loop uses an AND condition across width and height, which can under-count valid mip levels for heavily non-square textures (e.g. 4x64), but this is unchanged from before and does not affect correctness for the game's typical square DXT textures.

No files require special attention; the single changed file is self-contained and all touched call sites (2D, cube, volume texture paths) received consistent treatment.

Important Files Changed

Filename Overview
Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp Simplifies Begin_Compressed_Load (2D, cube, volume) to write reduced dimensions directly into Width/Height/Depth, removes redundant Validate_Texture_Size calls, drops manual pre-loop reduction shifts in Load_Compressed_Mipmap, and replaces silent mip-count underflow recovery with WWASSERT. Logic is correct given Validate_Reduction guarantees the asserted preconditions; minor conservative behaviour in max_mip_level_count for non-square textures is pre-existing.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Begin_Compressed_Load] --> B[Get_Texture_Information]
    B --> C[Get_Valid_Texture_Format]
    C --> D[Validate_Reduction]
    D --> E[Apply_Dim_Reduction
Width/Height = reduced dims]
    E --> F[Apply_Mip_Reduction
MipLevelCount capped by max_mip_level_count]
    F --> G[_Create_DX8_Texture
Width, Height, MipLevelCount]
    G --> H[Load_Compressed_Mipmap]
    H --> I[DDSFileClass opened with Get_Reduction]
    I --> J{for level 0..MipLevelCount-1}
    J --> K[WWASSERT width >= MinTextureDim]
    K --> L[Copy_Level_To_Surface]
    L --> M[width >>= 1 / height >>= 1]
    M --> J
    J --> N[return true]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Begin_Compressed_Load] --> B[Get_Texture_Information]
    B --> C[Get_Valid_Texture_Format]
    C --> D[Validate_Reduction]
    D --> E[Apply_Dim_Reduction
Width/Height = reduced dims]
    E --> F[Apply_Mip_Reduction
MipLevelCount capped by max_mip_level_count]
    F --> G[_Create_DX8_Texture
Width, Height, MipLevelCount]
    G --> H[Load_Compressed_Mipmap]
    H --> I[DDSFileClass opened with Get_Reduction]
    I --> J{for level 0..MipLevelCount-1}
    J --> K[WWASSERT width >= MinTextureDim]
    K --> L[Copy_Level_To_Surface]
    L --> M[width >>= 1 / height >>= 1]
    M --> J
    J --> N[return true]
Loading

Reviews (1): Last reviewed commit: "fix(textureloader): Simplify and fix fau..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Is fixing something, but is not user facing Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant