NFSU.cc / RE Atlas / Rendering & Shaders

Render: D3D9 layer, effects, queue, views, EAGL and the static D3DX (Speed.exe PC)

Rendering & Shaders 156 verified Speed.exe addresses Speed.exe (2003, x86)

Marks: V = read in code and a second tool agrees (Hopper H, Ghidra G, capstone C), I = inferred, U = open. Names: census/names_render.tsv (84 rows; same-address rows in other names_*.tsv were skipped). Blur, camera, TPK/assets and CRT are in blur.md, camera.md, assets.md, runtime.md and are only referenced here. Method note: I swept all of .text with capstone for calls through a register loaded from [0x73636c] (the device) and compared that fingerprint with the H and G pseudocode (table "Re-derived" below).

Answer

Of those, 997 sit in a statically linked D3DX9 (0x5ab730..0x61e000: HLSL/effect compiler, preprocessor, ps_1_x/vs_x assembler, math), 297 in EAGL (EA's graphics runtime, 0x61e000..0x640000) and 65 in SEH funclets (0x684b..0x696e). Only about 350 are the game's own render code, and only 65 of those (0x401e50..0x411f00) touch Direct3D.

Everything else (cars, world, particles, flares, HUD) queues work or calls these. There is no SetVertexShader/SetPixelShader in game code: shaders come from ID3DXEffect objects compiled at run time by the linked D3DX (503 of 997 D3DX functions ran in the coverage union, so the .efx text is compiled on this machine at startup; U which functions exactly).

recover a lost device, then recycle per-frame memory (flow below).

RenderQueue_Flush 0x40ed70, which selects the effect, binds VB/IB only when they change, and issues DrawIndexedPrimitive. Seven effect slots (stride 0xe0) at 0x71abb8.

Address map (V unless marked)

RangeWhatEvidence
0x401520..0x401e50modal frame loops (disc check, simple 2D frame)G+H+C
0x401e50dynamic quad VB/IB pool (30 VBs, 300-quad index buffer)G+H+C
0x407db0..0x408220texture D3D creation (named earlier), vertex declarationsG
0x408830D3D init: Direct3DCreate9(0x1f), pools, window class "GameFrame", CreateDeviceG
0x408b20state reset; 0x408f00..0x409b70 per-view render pieces; 0x409580 RenderFrameMainH+G
0x40a4e0..0x40b4e0device lost/reset, scene RT, RT table, reflection cubeG+H+C
0x40cb80..0x40d6e0blur chain (blur.md)
0x40e180..0x40e900effect creation, ramp texture, per-effect parametersG
0x40ed50..0x4102f0effect select, queue flush, buckets, lights, bonesH+C
0x410400..0x410ed0caps, resolutions, quality levels, option block 0x700e70..G+C
0x403a60, 0x404110particle systems (update, draw)H, G
0x4ae650..0x4ae830emitters/flaresH
0x5443f0..0x544f30flare quads and lamp flares (docs/flare_re.md)
0x56d8d0..0x571870car draw and car listsH
0x5ab730..0x61e000D3DX9 static: math thunks 0x5ac449..0x5ac8e5, PSGP init 0x5b065b, effect compiler (strings "ID3DXEffectCompiler: ...") 0x5b2d7a.., HLSL parser/typechecker 0x5ba0ab..0x5c7bd2, preprocessor 0x5c5700.., asm assembler 0x5e4ca2..0x5e8cd0, ps_1_x backend 0x604024..0x60f23a, vs backend 0x60fcaa..0x61808bG strings
0x61e000..0x640000EAGL: dynamic loader (.symtab/.strtab), symbol pool, RenderContext, PC caps/window, VertexBuffer/IndexBuffer wrappers, EAGLAnimG strings

Flow of one frame (V: H+G, addresses in order)

  1. Render_InitSubsystem 0x53e020 (once, from 0x4471b0): 0x408830 creates IDirect3D9 [0x736368], the window [0x736380] and the device

[0x73636c] with present parameters [0x71a96c] (filled by 0x4086b0), then 0x40a7f0, 0x40ac80, 0x40c600, EAGL 0x61f020/30, 0x627b90 and the pools DynamicFrameMemory, eLightFlare, ePointSprite3D, ePoly. 0x410e50 reads caps; 0x40e180 creates the 7 effects.

  1. RenderFrame 0x40a580, every frame:

a. 0x408410 (view/Z mode), set the two zero flags [0x734608]/[0x73460c] from option [0x700eb4]; 0x5707b0 updates views (0x40ad60 builds matrices). b. Loop i = 0..15 over gViews (0x740460, stride 0x60): active views get 0x40dd00 (camera.md); view 8 first runs 0x40a140. c. If TestCooperativeLevel (+0xc) is OK: BeginScene (+0xa4), 0x409cd0(1) (HUD pass in, hud docs), 0x409580, and when [0x73645c]==1 0x40d6e0 composites the scene RT into the back buffer, 0x409cd0(0), EndScene (+0xa8). d. Present (+0x44). On D3DERR_DEVICELOST (0x88760868) and then NOTRESET (0x88760869): Device_HandleLost 0x40a4e0 -> Device_ResetAndRecreate 0x40a510. e. 0x403a60(0x78e980, 1/60) particle update, 0x545ea0 texture animation, Clear (+0xac, flags 7, z=1.0), 0x53e210 ping-pong the scratch arena, 0x53e330 recycle per-frame lists, frame counter [0x7364dc]++, then input/audio ticks (0x405860, 0x4058d0, 0x4057c0, 0x419ea0, 0x4130d0, 0x41e670).

  1. RenderFrameMain 0x409580 (H, order verified against blur.md): reflection views first (6 slots 0x740820..0x740a00, 0x571870, 0x40ed50, 0x446730, 0x4ae650, flares),

then for the player view: 0x4090a0, scene RT select 0x40abd0, 0x446730 (queue world sections), 0x58a240, RenderWorldModels 0x592100, motion blur 0x40cd40, 0x408b20, cars 0x571050/0x570950, emitters 0x4ae650, particle systems 0x404110 x2 (if [0x700ea8]), then flares (0x544f30, 0x4ae7d0, 0x570d00/0x570c70) or the light-streak path 0x409b70; after the view the rear-view mirror: 0x409180(RVM) and 0x409180(RVM_MASK) (textures from 0x408610).

  1. Every 0x40ed50 call increments [0x71b1dc] and runs RenderQueue_Flush 0x40ed70.

RenderQueue_Flush 0x40ed70 (V: H body, C device-call fingerprint)

For each effect slot k (0..6) at 0x71abd0 + k*0xe0 with bucket list heads at 0x78a4e8..0x78a868 (stride 8 per kind): select effect (0x40e6d0 logic inline: End old, init callback, SetVertexDeclaration(slot+4), Begin = effect vtbl +0x100), then for each queued item (node: +0 next, +4 prev, +0x10 item, +0x18 sub-list): 0x40f3d0 sets blend/cull, 0x410400 loads matrices, 0x4100a0 per-object params, 0x40f7c0 lights (SetLight +0xcc, LightEnable +0xd4), 0x40fae0 material, then per pass Pass (+0x104) and DrawIndexedPrimitive (+0x148) after SetStreamSource (+0x190) / SetIndices (+0x1a0) only if the buffer differs from [0x7363e8] / [0x7363ec]. Items with no index data use DrawPrimitiveUP strip (+0x14c, stride 0x18). Counters: 0x71b1d8 items, 0x71b1e8 VB changes, 0x71b1ec IB changes, 0x71b204 effect switches (I for what each one counts).

Structures (offsets V from H+G unless noted)

+0x84/+0x88/+0x8c/+0x38 parameter handles used by 0x40e7b0/0x4100a0 (I). Created by 0x40e180 from the descriptor table 0x7010c0 (stride 0x80, vertex element indices).

D3D9 calls the game makes (V, capstone sweep; counts of call sites)

SetRenderState 59, SetSamplerState 24, SetRenderTarget 12, SetVertexDeclaration 9, SetTextureStageState 9, CreateTexture 8, Clear 7, DrawPrimitiveUP 7, SetDepthStencilSurface 4, SetViewport 4, SetTransform 4, BeginScene/EndScene/Present 3 each, CreateVertexDeclaration 3, SetTexture 3, CreateDepthStencilSurface 3, GetDepthStencilSurface 3, CreateVertex/IndexBuffer 2, Reset 2, LightEnable 2, SetStreamSource/SetIndices/DrawIndexedPrimitive 1 each, SetLight 1, SetMaterial 1, CreateCubeTexture 1, SetFVF 1. Not called by game code: SetVertexShader, SetPixelShader, SetShaderConstant, DrawPrimitive. The host (host/d3d9.c) therefore sees shaders only through the D3DX-created effects.

Re-derived with a second tool (12)

Method: first the capstone fingerprint (which device calls a function makes and with what immediate arguments), written down as a guess, then H and G pseudocode.

AddrFingerprint (C)H / G readingResult
0x401e50CreateVertexBuffer, CreateIndexBufferG: 30 VBs, 0xe10 INDEX16 filled with quad patternmatch
0x40e560CreateTexture(0x40,1,0,0,0x15,1,0x71abb4)G: 64x1 A8R8G8B8 ramp fillmatch
0x40b340CreateCubeTexture, CreateDepthStencilSurfaceG: cube + 6 faces + 6 depth surfacesmatch
0x40a510Reset x2H: calls 0x401e50, 0x40a890, 0x40aa20, 0x40b340, 0x40cb80 after Reset; G merges it with 0x40a4e0match (G boundary differs)
0x410e50GetDeviceCaps, LightEnableG: caps, adapter id, disable all lightsmatch
0x408220CreateVertexDeclaration x2G: two element arraysmatch, element meaning open
0x40ed70SetDecl, SetStreamSource, SetIndices, DrawIndexedPrimitive, DrawPrimitiveUPH: bucket flushmatch (G merges with 0x40ed50)
0x40e6d0SetVertexDeclarationH: effect switchmatch
0x4091808x SamplerState ADDRESS=3, SetTexture, DrawPrimitiveUP(6,2,?,0x18)G: textured quadmatch
0x410ed0stores to 0x736334, 0x700e74G: level 0..3 option tablematch
0x40aa20GetDepthStencilSurface x2G: 7-entry target tablepartial (field meaning I)
0x40a580TestCooperativeLevel, BeginScene, Clear, EndScene, PresentH and G same ordermatch

Score: 10 match, 1 match with boundary difference, 1 partial; the fingerprint was not blind for 0x40a580 (frame order already in blur.md).

Open

HANDOFF: names_render.tsv has 84 rows; next: decode the 7 effect descriptors (0x7010c0) and the .efx loader 0x594c60, then name the car draw 0x56dc30 sub-passes and the D3DX create-effect entry points.