Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(ww3d2): run bloom, fxaa and sharpen on the Direct3D 11 frame by default
Olcay Seyganc3f80d57f82c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5bf876c9e..e63344d2b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -3,7 +3,7 @@EA opened the source of Generals and Zero Hour, the game that is still on sale and still runs onSteam. This build is that source with the bugs the game shipped with fixed and everything below added.-**123 changes. ~580 engine source files ported. 14 automated test suites. Around 60 original bugs+**124 changes. ~580 engine source files ported. 14 automated test suites. Around 60 original bugsfound and fixed — EA's own, not port damage.**---@@ -204,6 +204,7 @@ found and fixed — EA's own, not port damage.**## Sharper textures, for free- The game draws its picture through Direct3D 11 now, and falls back to the old renderer on a machine that cannot make a Direct3D 11 device. Eight views over five maps come out within one step of one colour channel of the old picture, which is the smallest difference a screen can show.+- The Direct3D 11 picture comes with its finishing passes on, no switch needed. Explosions glow past their own edges, because the battlefield is kept brighter than white until the glow is worked out; jagged edges are smoothed; and a light sharpening brings the 2003 textures back up after the smoothing. All three run over the battlefield only, before the health bars and the command bar go on top, so the lettering is untouched. In a screen of thirty inferno cannons firing the frame averaged 11.89ms with them against 11.82ms without. The antialiasing setting on the display page is for the old renderer; `-dx11post off` on the command line gives you the plain picture, and `-dx11post fxaa` picks effects one by one. The old renderer's rolling-wave sea never went missing in a real match either: both of the game's settings files turn it off, so no map ever drew it.- 481 base-game textures at four times the resolution now beat Zero Hour's downscaled copies.- A long thin texture loads at the size it was drawn at. Anything wider than eight to one used to be stretched onto a bigger, blurrier one, because that was the limit of a 2002 graphics card; the card is asked now, and modern ones have no such limit.- Anything standing still keeps its shadow in the fog. A town you have already walked through used@@ -1128,5 +1129,4 @@ found and fixed — EA's own, not port damage.**## Not there yet- Online and LAN play are untested.- A frame through Direct3D 11 still costs more than it did through the old renderer: 13.6ms against 8.6ms in a screen full of inferno cannon fire, down from 16.9ms once the old renderer stopped drawing a second copy of every frame that nobody saw. `-d3d9` on the command line puts the old renderer back on its own.-- Antialiasing from the display page does not reach the Direct3D 11 picture yet, and the rolling-wave sea is drawn only by the old renderer, so it is missing from the new one.- You need to own the game; no game data ships here.diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex 838c5e5ba..f75c1d15b 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -1504,9 +1504,9 @@ Int parseDirect3D11Dump(char *args[], int num)* amount by which something beat white, and the frame comes back to eight bits through a tone* curve whose knee leaves everything ordinary exactly where it was.*- * Everything else in the backend exists to draw the frame Direct3D 9 draws and this exists to- * draw a different one, so it is off unless it is asked for and dx11-check.ps1 is run without- * it. */+ * Without the switch the chain is "bloom,fxaa,sharpen", set in GlobalData, since v1.0.0. The+ * rest of the backend exists to draw the frame Direct3D 9 draws and this exists to draw a+ * different one, so dx11-check.ps1 and tree-check.ps1 pass "-dx11post off". */Int parseDirect3D11Post(char *args[], int num){if (TheWritableGlobalData)diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex 0faf5f103..cac69c20a 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -649,7 +649,9 @@ GlobalData::GlobalData()m_vsync = FALSE;m_direct3D11 = TRUE;m_direct3D11DumpPath.clear();- m_direct3D11PostChain.clear();+ // The Direct3D 11 frame gets every effect the backend has unless -dx11post names a chain of its+ // own; "-dx11post off" is the faithful 2003 picture that dx11-check.ps1 compares against.+ m_direct3D11PostChain = "bloom,fxaa,sharpen";m_xResolution = 800;m_yResolution = 600;m_maxShellScreens = 0;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cppindex 12b2f8210..b012ab709 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp@@ -775,6 +775,20 @@ static void sizeWindowToClient( Int mode, Int width, Int height )x, y, outerW, outerH, SWP_NOACTIVATE );}+//=============================================================================+// GlobalData carries the whole chain by default and -dx11post replaces it, "off" included. FXAA is+// always in the default: the Direct3D 11 swap chain takes one sample, and a multisampled scene+// target would break the screen filters, which redirect the scene into a texture of the same size+// and share the back buffer's depth with it.+static void pushDirect3D11PostChain( void )+{+ const AsciiString & requested = TheGlobalData->m_direct3D11PostChain;+ if( !Direct3D11_Post_Chain( requested.str() ) && !requested.isEmpty() )+ {+ DEBUG_LOG(( "-dx11post: '%s' names no effect this build has, so no chain runs\n", requested.str() ));+ }+}+/** Set resolution of display *///=============================================================================Bool W3DDisplay::setDisplayMode( UnsignedInt xres, UnsignedInt yres, UnsignedInt bitdepth, Bool windowed )@@ -787,6 +801,7 @@ Bool W3DDisplay::setDisplayMode( UnsignedInt xres, UnsignedInt yres, UnsignedInt{DX8Wrapper::Set_Requested_VSync( TheGlobalData->m_vsync != FALSE );Direct3D11_Set_VSync( TheGlobalData->m_vsync != FALSE );+ pushDirect3D11PostChain();}//@@ -1042,8 +1057,11 @@ void W3DDisplay::init( void )// Multisampling has to be known before the device exists, and WW3D2 cannot read GlobalData, so// the sample count is handed to it here. msaaSamplesForLevel turns the stored index into 0, 2,- // 4, 8 or 16; the device degrades an unsupported one on its own.- DX8Wrapper::Set_Requested_MultiSample_Level( msaaSamplesForLevel( TheGlobalData->m_msaaLevel ) );+ // 4, 8 or 16; the device degrades an unsupported one on its own. While Direct3D 11 presents,+ // the Direct3D 9 frame is never shown, so its samples would be memory spent on nothing; the+ // Direct3D 11 frame is smoothed by the FXAA in its default chain instead.+ DX8Wrapper::Set_Requested_MultiSample_Level( TheGlobalData->m_direct3D11+ ? 0 : msaaSamplesForLevel( TheGlobalData->m_msaaLevel ) );DX8Wrapper::Set_Requested_VSync( TheGlobalData->m_vsync != FALSE );Direct3D11_Set_VSync( TheGlobalData->m_vsync != FALSE );@@ -1054,12 +1072,7 @@ void W3DDisplay::init( void )Direct3D11_Enable( TheGlobalData->m_direct3D11 != FALSE );Direct3D11_Present_Enable( TheGlobalData->m_direct3D11 != FALSE );Direct3D11_Dump_Programs_To( TheGlobalData->m_direct3D11DumpPath.str() );- if( !Direct3D11_Post_Chain( TheGlobalData->m_direct3D11PostChain.str() )- && !TheGlobalData->m_direct3D11PostChain.isEmpty() )- {- DEBUG_LOG(( "-dx11post: '%s' names no effect this build has, so no chain runs\n",- TheGlobalData->m_direct3D11PostChain.str() ));- }+ pushDirect3D11PostChain();// Same problem, same answer: the filter table is built the moment the device exists and WW3D2// cannot see GlobalData, so the player's texture filtering goes in here. Nothing in the gamediff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.hindex e39d78e02..26d639be1 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h@@ -26,10 +26,10 @@** backend binds Get_Scene_View() where it used to bind the back buffer view and the change ends** there.**-** The chain is off by default and the exit measurement for the backend is taken with it off. An-** effect that improves the picture makes the frame differ from Direct3D 9's on purpose, which is-** the one thing dx11-check.ps1 is built to refuse, so the two cannot both be the default and this-** is the one that gives way.+** The game asks for bloom, fxaa and sharpen unless -dx11post says otherwise. An effect that+** improves the picture makes the frame differ from Direct3D 9's on purpose, which is the one thing+** dx11-check.ps1 is built to refuse, so that script passes "-dx11post off" and measures the+** backend without it.**** Where it runs matters as much as what it does. W3DView::draw calls for the chain at the moment** the world is finished and before the health bars, the unit names and the command bar go over it.diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.hindex e9dfd17e5..60e1189e5 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h@@ -124,8 +124,9 @@ void Direct3D11_Set_VSync(bool enabled);// always has. Returns false for a name it does not know and turns the chain off, so a misspelt// switch is a plain frame and a report line rather than a different picture.//-// This is the first thing in the backend that draws a frame Direct3D 9 does not draw, so it is off-// unless it is asked for and dx11-check.ps1's exit measurement is taken without it.+// This is the first thing in the backend that draws a frame Direct3D 9 does not draw. The game+// hands it "bloom,fxaa,sharpen" unless -dx11post names another chain; dx11-check.ps1's exit+// measurement passes "-dx11post off".bool Direct3D11_Post_Chain(const char * chain);// The chain and the size it runs at, for the shutdown report, or why there is no chain.diff --git a/dx11-check.ps1 b/dx11-check.ps1index adbb781ea..4497d27bc 100644--- a/dx11-check.ps1+++ b/dx11-check.ps1@@ -46,9 +46,10 @@# -MeanMargin is the pass threshold in levels a channel, and 1.0 is the frame buffer's own step: two# frames that agree to within the smallest value the buffer can hold are the same frame.#-# -dx11post is the one switch that must never be added here. It runs an effect over the finished-# frame on purpose, so a run with it on disagrees with Direct3D 9 by design and this script would be-# measuring the effect rather than the backend. Its own before and after is a pair of pictures.+# -dx11post off is on every launch and must stay there. The post chain runs by default since+# v1.0.0, and it changes the finished frame on purpose, so a run with it on disagrees with Direct3D 9+# by design and this script would be measuring the effect rather than the backend. Its own before+# and after is a pair of pictures.param([double]$Margin = 1.0, [double]$MeanMargin = 1.0, [string]$Map = '',[switch]$BackendNoise, [switch]$CountRule, [string[]]$Extra = @())@@ -75,7 +76,7 @@ $cases = @(function Shoot($c, $tag, $extra) {Get-ChildItem "$shots\sshot*.bmp" -ErrorAction SilentlyContinue | Remove-Item -Force$arguments = @('-win','-xres','1280','-yres','720','-quickstart','-noshellmap','-multiInstance',- '-msaa','0','-map',"`"Maps\$($c.map)\$($c.map).map`"",'-autoskirmish','4','-aidiff','easy',+ '-msaa','0','-dx11post','off','-map',"`"Maps\$($c.map)\$($c.map).map`"",'-autoskirmish','4','-aidiff','easy','-seed','5','-maxframes',($c.f+80),'-screenshot',$c.f,'-camera',$c.x,$c.y,'-logPrefix',"dx11chk_$tag`_") + $extra + $Extratry {diff --git a/tree-check.ps1 b/tree-check.ps1index aa605ab49..2356b8c61 100644--- a/tree-check.ps1+++ b/tree-check.ps1@@ -39,9 +39,12 @@ $cases = @(# .bmp in it afterwards, and a run that writes none - the reference build needs more than the wait# below to reach frame 2400 - would otherwise hand back the previous case's picture and compare two# different frames. Empty, that is a stated failure instead of a number.+#+# -dx11post off for the same kind of reason: the post chain runs by default since v1.0.0, and a+# reference build from before that draws without it, so the bloom would be the difference counted.function Shoot($exe, $c, $tag) {Get-ChildItem "$shots\sshot*.bmp" -ErrorAction SilentlyContinue | Remove-Item -Force- $args = @('-win','-xres','1280','-yres','720','-quickstart','-noshellmap','-multiInstance','-msaa','0',+ $args = @('-win','-xres','1280','-yres','720','-quickstart','-noshellmap','-multiInstance','-msaa','0','-dx11post','off','-map',"`"Maps\$($c.map)\$($c.map).map`"",'-autoskirmish','4','-aidiff','easy','-seed','5','-maxframes',($c.f+80),'-screenshot',$c.f,'-camera',$c.x,$c.y,'-logPrefix',"chk_$tag`_")try {