Repository navigation
Direct3D 9 performance: uploads keep the render pass, pipelines made ahead, less work per draw; PE2_PROF profiler - #13
Open
marcocebrian wants to merge 12 commits into
Open
marcocebrian wants to merge 12 commits into
marcocebrian wants to merge 12 commits into
Conversation
Fixes found bringing up C&C 3: Tiberium Wars (EA SAGE, Direct3D 9) from "closes at once" to playable skirmishes, each written against Windows behaviour so other games of the era benefit. docs/32bit-game-fixes.md describes every change. Conversion - Launchers: convert the program a launcher runs (SkuDef set-exe, a name the launcher holds, or its own name with another extension), from a sub-folder, with the launcher's arguments (%GAMEDIR% expanded at start). - System libraries a game expects Windows to provide (msvcr80/90, d3dx9_24-43), fetched from Microsoft's redistributables (tools/fetch_sys32.sh) and rewritten with the game; msvcrt.dll served by whichever C runtime is built in. Rewriter - Programs linked without relocations: find code through pointer-looking values (never written back), switch tables bounded by their compare, overlapping starts; progress on stderr. - ud0/ud1, enter's unsigned size, notrack, jcxz, far jecxz/loop targets. Runtime and window layer - 55 missing Windows functions (runtime/win_extra32.c); tools/missing32.py lists what a game still lacks; crash reports show the game's call chain. - Exclusive fullscreen at the mode's size with mouse mapping; native display resolutions; DirectInput fed in the full window layer; a clipped visible cursor keeps moving; text into 24/16-bit bitmaps; .cur/.ani cursors. Direct3D 9 - Lost devices on deactivation, freeing released textures and buffers, UpdateSurface rectangles, indexed draws without an index buffer, indexed pixel shader inputs, a GeForce 8800 GTX adapter identity.
…n game on its Space StretchRect between rectangles of different sizes now draws the source into the destination (point or linear); it copied the top-left part, so distortion effects that shrink the frame smeared a magnified corner across the view. GetAdapterDisplayMode reports a fullscreen device's mode, otherwise the display's pixels (not points): native resolution survives applying options. Arriving on the Space of a fullscreen window activates its program, so a lost device is reset instead of staying lost. Notes in docs/32bit-game-fixes.md.
With D3DRS_POINTSPRITEENABLE, texture coordinate set 0 is the position across the sprite and the size is the one the vertex shader writes (oPts or a PSIZE output). Sprites sampled a single texel and drew flat squares: C&C 3's Tiberium gas and smoke were hard-edged rectangles. Notes updated.
…D3DX - Texture uploads: UnlockRect uploads only the locked rectangle, staged in the frame ring and batched in one blit pass (was a new Metal buffer, a command stream break and the whole level per unlock). - Low heap: freed memory is zeroed keeping 16 KB hardware pages whole, so Metal can wrap Direct3D buffers placed there (newBufferWithBytesNoCopy returned nil under Rosetta's 4 KB pages and draws were dropped); buffer memory is 16 KB aligned. - Accelerated exports: a native registered under a library family name (d3dx9.dll) serves that export of every d3dx9_NN.dll, falling back to the library's own code. First: D3DXLoadSurfaceFromMemory for 32-bit surfaces, whose per-pixel x87 conversion froze C&C 3 for ten seconds after each Reset. - Window layer: WM_ACTIVATEAPP/WM_ACTIVATE follow the application's own activation for a fullscreen window. - Diagnostics: PE2_TRACE_BURST logs calls and messages after each Reset; the frame-rate line reports uploads. - docs/32bit-game-fixes.md: the above, and what is still open.
…app beside its files)
…ut focus - Shaders: c[a0 + n] reads the shader's own def value for a register it defines, the program's constant otherwise, and 0 outside the register file (was clamped into the program's constants). C&C 3's particle quad corners live in def c21..c24 read through c[a0.w + 16]: a refinery's smoke became beams and a screen-wide haze (the white flash). - Window layer: an exclusive-fullscreen window is minimised while its program is in the background (IsIconic, WM_SIZE SIZE_MINIMIZED, WM_ACTIVATE minimised flag) and restored on return. - DirectInput: DISCL_FOREGROUND devices are unacquired on deactivation (DIERR_INPUTLOST, then DIERR_OTHERAPPHASPRIO until active again). - Diagnostics: PE2_DRAWLOG_TRIGGER (log draws and save frames for a moment on demand), PE2_SKIP_SHADER (drop an effect's draws), W64_MSGLOG. - docs/32bit-game-fixes.md: the above; the flash is solved, the pause menu on return is still open with what was found.
…twork access
- gethostbyname of the machine's own name lists loopback only when there is
no other address, as Windows does. C&C 3 sorted the list, took 127.0.0.1
and then announced its LAN games on loopback only.
- Converted apps declare NSLocalNetworkUsageDescription: macOS refuses LAN
broadcasts ("no route to host") until the user allows it.
- PE2_TRACE_SOCK logs failed sendto calls.
- A standalone surface's hidden texture no longer holds its own reference, so releasing the surface frees both. None were ever freed: C&C 3's LAN lobby creates hundreds of offscreen surfaces a second and ran the low memory out in two minutes (crash in res_new on a null allocation). - The five-second frame-rate line reports the low memory in use.
…); read 16 bytes per instruction
…ions as Windows reports them (32-bit)
…nged state per draw; 16x anisotropic filtering; stall counters
…profiler; input log; missing-function messages once; notes on method
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #12. The commits new in this PR are
f56f588and8cff743. Measured on Kane's Wrath at 3456x2234, everything at its highest.Uploads between draws keep the render pass. Each texture upload ended the open render pass, so the next draw reloaded the whole colour and depth targets (tile-based GPU). C&C 3 updates thousands of small textures between draws in some scenes, and froze at 4.7 fps with the sound breaking up. A texture the open command buffer has not used yet is now filled in its own command buffer, committed just before; a texture already used this frame is updated in order inside it, as before. The 4.7 fps scenes now run at 30 fps with 0 pass breaks.
Pipelines made ahead. New effects (a building blowing up) made dozens of pipelines in one frame, a hitch of up to 400 ms. Every pipeline made is recorded in
learn/d3d9/pipelines.binby what Metal needs to make it: function names, vertex layout, attachments, blending. At device creation the recorded ones are made on background threads. The pipeline key also leaves out fields the pipeline isn't made from (blend factors with blending off, strides of unread streams).PE2_NO_WARM=1turns it off.Less work per draw. Everything runs translated under Rosetta, Metal included, so:
16x anisotropic filtering on mipmapped, linearly filtered textures, like a driver control-panel override.
PE2_ANISO=<n>sets it; 0 means only what the game asks for.Measuring.
PE2_PROF=1is a sampling CPU profiler in the runtime (runtime/prof.c).sampleand Instruments show???under Rosetta; this names rewritten code by its original address and has a main-thread table and yield attribution.PE2_TRACE=1adds a 5 s line with render passes, upload breaks, GPU waits, pipeline costs, and upload and draw CPU time.PE2_INPUTLOG=1logs keys on their way to the game.GetProcAddressis reported only the first 3 times. C&C 3 asks forDebugSetMutea dozen times a second, and each one was written to stderr even untraced.Result: a 14-minute skirmish with buildings destroyed averaged 29.7 fps against the game's 30 limit, with no stall.