Skip to content

Reimplement 2 UI::Rendering TextureRenderCore asm functions from gynt's drafts (100%) - #389

Merged
gynt merged 5 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round9b-100
Nov 10, 2026
Merged

gynt merged 5 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round9b-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

Two more TextureRenderCore functions at 100%, the last two of the round whose other five are in #386. Both were written from gynt's drafts (92.8% and 93.2% on his reimpl/TextureRenderCore). Each commit cites the draft it builds on and credits him as co-author. Part of the rest of UI that gynt OK'd on 2026-11-09.

Function Address gynt's draft
TextureRenderCore::renderGmWithPreparedAlphaMask 0x0044F170 93.2% (3ea4438)
TextureRenderCore::renderInterfaceOrBuildingOccupationArea 0x0044E630 92.8% (ac42b30)

Measured on main d5d965d. The branch is rebased onto 847c77b, which leaves the two functions' files and InitBlendFilterArraysUnk.cpp as they were.

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), resolvers enabled locally (not committed), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie.
  • reccmp: a full build reads both at 100.0% raw and normalized. The callee's other two callers, ApplyBlending and renderBlendedBlackBox, stay at 100.0%.
  • Last two commits: they change comments and how the asm spells its numbers. quick_diff output is identical for both files.
  • Checks: openshc-pr-check gives no errors, and status_regression.py finds no score below a known one.
  • Not run in game.

Why /GL (cmake commit 0c8b764)

Both functions load the height into edi once and still use it after the InitBlendFilterArraysUnk call: lea edx, [ecx + edi] at 0x0044F205, lea ecx, [eax + edi] at 0x0044E6CC. So the original compiler knew that call leaves edi alone.

  • Without /GL, MSVC reads the height from memory again after the call. By quick_diff, that is the only difference in the C++ part.
  • With /GL on both files and on InitBlendFilterArraysUnk.cpp, the compiler sees the callee across files, as for the other caller and callee pairs in cmake/compiler-flags-gl.txt. The three lines sit next to the other UI/Rendering entries.
  • InitBlendFilterArraysUnk reads 97.9% raw in every full build, with /GL or without. Its instructions match. The only difference is how reccmp prints two loop-end compares against an address just past the end of the blend filter array, which our DLL lays out differently. Reimplement 32 rendering and UI rendering functions at 100% #311 records that, and main keeps it at 100%. /GL doesn't change it.

How much is assembly

The drawing loops are handwritten assembly in the original, and they stay as inline asm here, transcribed from the binary:

  • renderGmWithPreparedAlphaMask: one loop per colour mode (2 blocks, about 380 instructions).
  • renderInterfaceOrBuildingOccupationArea: RGB555 and RGB565, each for the normal and the zoomed-out surface (4 blocks, about 710 instructions).

Everything around them is C++: the zoom test, the blend filter rows (short* const, declared at first use), the InitBlendFilterArraysUnk call, and the pointers and counts the loops start from.

  • The asm compares its stream tokens with the TgxToken names, as renderTgxWithColorUnk and main's other TGX asm blocks do.
  • Its labels say what each loop does.
  • Its numbers follow main's asm: colour masks as lowercase hex (0xffe0, 0x3ff, …), shift counts and plain values in decimal (shr bx, 10, mov eax, 32, cmp edx, 31).

The style-lint bot will flag the 50 masks above 0xff (126 hex masks in all). Every one is a mask in an and, written as main's TGX asm writes them; gynt's rule on #311 allows hex there.

lineJump, lineBytes, heightStart and heightEnd are declared without a value before the zoom and surface tests, because every arm assigns them, as in renderTgxWithColorUnk.

Kept as it is, measured with quick_diff

Function Kept The other form
renderInterfaceOrBuildingOccupationArea columnOffset declared in the zoomed-out branch only at function scope: 1.0000 → 0.9702 (two stack slots swap; measured with the callee in the same file)
both the map arm first (!= RT_SCREEN_MENU) == with the arms swapped: 0.8258 → 0.8077 and 0.8270 → 0.8228
renderGmWithPreparedAlphaMask maskPtr read before the height test after it: 0.8258 → 0.8235
renderGmWithPreparedAlphaMask two filter pointers at the table's base one for both: 0.8258 → 0.8231

The plain quick_diff figures are below 1.0000 because, without /GL, the height is read again after the callee (see above). Each comment gives its number in main's one-line form.

Other PRs

🤖 Generated with Claude Code

kotijekriv and others added 5 commits November 10, 2026 07:36
…ngOccupationArea and InitBlendFilterArraysUnk


Both functions (0x0044F170, 0x0044E630) load height into edi once and still use it after the
InitBlendFilterArraysUnk call (lea edx, [ecx + edi] at 0x0044F205; lea ecx, [eax + edi] at 0x0044E6CC), so the
original compiler knew that call leaves height alone. Here height is named in the functions' asm blocks, so
without that knowledge MSVC reads it from memory again after the call; by quick_diff that is the only difference
in the C++ part. With InitBlendFilterArraysUnk's definition compiled into the same file (a local test that
includes it) both match instruction for instruction; /GL on all three files gives the compiler that view across
files, as for the other caller and callee pairs in this list. The lines sit next to the other UI/Rendering entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
renderGmWithPreparedAlphaMask draws a TGX image through the alpha surface prepared earlier: per pixel, the mask's
blue channel less blendStrength leaves the destination alone at or below zero, copies the source at 31 and blends
the two through DAT_BlendFilterArrays in between, in one handwritten asm loop per colour mode. From gynt's draft
(3ea4438 on reimpl/TextureRenderCore, 93.2% there; his later 3d17527 on this file is an arm swap
on the earlier decompiled version, not on this one). Needs the cmake commit that puts this file and
InitBlendFilterArraysUnk.cpp under /GL: the original keeps
height in edi across that call, which MSVC only does when it can see the callee.

Also: the asm reads the render surface from the global, main's parameter names, lineJump / lineBytes /
heightStart / heightEnd as in renderTgxWithColorUnk, 4056 for the map surface's width, maskPtr as the alpha
surface's own ushort*, the token compares with the TgxToken names and descriptive labels as in the other TGX asm
blocks on main. With InitBlendFilterArraysUnk compiled into the same file and the ebp-frame slots resolved,
quick_diff is 1.0000 (442 instructions each side).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
renderInterfaceOrBuildingOccupationArea blends a TGX image over the destination through the pair of
DAT_BlendFilterArrays rows that blendStrengthUnk picks, in four handwritten asm loops (RGB555 and RGB565, each for
the normal and the zoomed-out surface, which keeps only every second row and column). From gynt's draft
(ac42b30 on reimpl/TextureRenderCore, 92.8% there, "two stack slots swapped"; his newer 3d17527 on this file
is an arm swap on the earlier decompiled version, not on this one). Needs the cmake commit that puts this file and
InitBlendFilterArraysUnk.cpp under /GL: the original keeps height in edi across that call.

Also: the asm reads the render surface from the global, the destination filter row computed before the source
row (the other order swaps ecx and edx), main's parameter names, lineJump / lineBytes / heightStart / heightEnd as
in renderTgxWithColorUnk (gynt's draft kept the line jump and the line bytes in width and blendStrengthUnk; as
locals MSVC gives them those parameters' slots, so the code is the same), the token compares with the TgxToken
names and descriptive labels as in the other TGX asm blocks on main. The two swapped slots: columnOffset is used
only by the zoomed-out loops and is declared in that branch, now an else; declared at function scope it takes
[ebp - 4] and pushes heightStart to [ebp - 8], the other way round from the original (declaration order, names
and extra references did not move them). With InitBlendFilterArraysUnk compiled into the same file and the
ebp-frame slots resolved, quick_diff goes 0.9702 -> 1.0000 (805 instructions each side).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The comment above each InitBlendFilterArraysUnk call in renderGmWithPreparedAlphaMask
and renderInterfaceOrBuildingOccupationArea also said that the original keeps height in
edi across the call, which needs /GL on these files and the callee. That is a finding
about the build, not about the code, so it moves to the PR description; the line on why
the call is there stays.

quick_diff output is identical for both files, plain and with the callee in the same TU
(1.0000 there). The full /GL build of the commit before reads both at 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ked for


The asm writes masks as lowercase 0x numbers, and shift counts and plain values (32, 31) in decimal, as main's
TGX asm blocks do; none of them uses the MASM h suffix. Each body gets a one-line summary, and the shapes the
review asked about get main's measured comment:
- the map arm first (with the arms swapped: 0.8258 -> 0.8077 and 0.8270 -> 0.8228);
- maskPtr read before the height test (after it: 0.8235);
- two filter pointers in renderGmWithPreparedAlphaMask (one for both: 0.8231).
The zoomed-out arm says why its lineJump is a whole row, and columnOffset says that only the asm writes it.

quick_diff output is identical for both files, with -s.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Style guide reading (advisory, posted once)

50 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 2 of the 2 reimplemented .cpp file(s) in this PR.

The match comes first. Where the ugly form is what matched, it stays -- that is the guide's own overriding rule, and rule 21 asks for a one-line comment saying what was measured so the next reader does not retry it. This report is posted once, when the PR opens, and is not repeated on later pushes.

rule what it asks hits
11 No magic addresses 2
18 Use the name, not the number 48
Where

Rule 11 — No magic addresses

  • src/OpenSHC/UI/Rendering/TextureRenderCore/renderInterfaceOrBuildingOccupationArea.cpp:432 — literal address 0xFFFFFFFE
  • src/OpenSHC/UI/Rendering/TextureRenderCore/renderInterfaceOrBuildingOccupationArea.cpp:657 — literal address 0xFFFFFFFE

Rule 18 — Use the name, not the number

  • src/OpenSHC/UI/Rendering/TextureRenderCore/renderGmWithPreparedAlphaMask.cpp:169 — hex constant 0xFFE0; use a name, or decimal
  • src/OpenSHC/UI/Rendering/TextureRenderCore/renderGmWithPreparedAlphaMask.cpp:175 — hex constant 0xFC1F; use a name, or decimal
  • src/OpenSHC/UI/Rendering/TextureRenderCore/renderGmWithPreparedAlphaMask.cpp:181 — hex constant 0x3FF; use a name, or decimal
  • src/OpenSHC/UI/Rendering/TextureRenderCore/renderGmWithPreparedAlphaMask.cpp:193 — hex constant 0xFFE0; use a name, or decimal
  • src/OpenSHC/UI/Rendering/TextureRenderCore/renderGmWithPreparedAlphaMask.cpp:199 — hex constant 0xFC1F; use a name, or decimal
  • src/OpenSHC/UI/Rendering/TextureRenderCore/renderGmWithPreparedAlphaMask.cpp:205 — hex constant 0x83FF; use a name, or decimal
  • src/OpenSHC/UI/Rendering/TextureRenderCore/renderGmWithPreparedAlphaMask.cpp:242 — hex constant 0xFFE0; use a name, or decimal
  • src/OpenSHC/UI/Rendering/TextureRenderCore/renderGmWithPreparedAlphaMask.cpp:248 — hex constant 0xFC1F; use a name, or decimal
  • src/OpenSHC/UI/Rendering/TextureRenderCore/renderGmWithPreparedAlphaMask.cpp:254 — hex constant 0x3FF; use a name, or decimal
  • src/OpenSHC/UI/Rendering/TextureRenderCore/renderGmWithPreparedAlphaMask.cpp:267 — hex constant 0xFFE0; use a name, or decimal
  • ... and 38 more

@gynt
gynt added this pull request to the merge queue Nov 10, 2026
Merged via the queue into sourcehold:main with commit 276a2a3 Nov 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants