Skip to content

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.

perf(ww3d2): cut the direct3d 11 frame to 7.6ms in the inferno test

Olcay Seyganb0a6379a21f1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b95e209c6..65ee05bdb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,7 @@ found and fixed — EA's own, not port damage.**
- Explosions no longer catch the picture. The first time each kind of fire, smoke or blast reached the screen, the game stopped for 25 to 60ms to prepare it, and the opening volley of a fight cost 300ms at once. That work is kept on disk and ships with the game, so it happens while the map loads, in about 3ms, and the worst frame of the same battle went from 141ms to 38ms.
- The price, build time and power figures on the command bar buttons stopped costing you frames. All the buttons shared one piece of text, so every figure on the bar was lettered from scratch every frame, about 33 of them. Each now keeps its own: a battle that averaged 14ms a frame averages 11.7ms, frames slower than 60 a second went from one in six to one in a hundred, and the old renderer gets about 0.8ms back too. The money readout was lettered again every frame as well, for a number that had not changed; it is lettered when the number moves. Over a whole battle the game now letters 163 pieces of text where it lettered 68,227.
- A screen full of fire and smoke is cheaper to draw. Thirty Inferno Cannons shelling twenty Crusaders used to send the graphics card 459 separate batches of see-through effects a frame, mostly the same texture again and again, and the game looked up the same seven card settings from scratch for every one of them. Matching effects go out together now, and settings that have not changed are not looked up again: 177 batches, and the same battle went from 11.6ms a frame to 8.6ms. It is at 6.7ms now, since the game stopped preparing everything it draws a second time for a copy of the picture nobody sees. Nothing on screen changes, the effects are drawn in exactly the order they were.
+- The same battle with the particle limit turned up costs 7.6ms a frame where it cost 9.1ms, and the old renderer went from 9.3ms to 6.3ms. Both were keeping a count of every kind of draw the game makes, and both did it by writing out and reading back a description of each one, on every draw, for a report no player ever opens. They glance at one draw in sixteen now. The new renderer also stopped re-sending the graphics card settings it had just sent.
- Raise the particle limit as far as you like and every puff gets drawn. Past about sixteen thousand smoke and fire sprites on screen the game quietly stopped drawing the rest: a test with 68,000 of them showed barely a fifth. A test with 101,000 now draws all of them at 8.3ms a frame, and in 1,200 frames not one fell below 60 a second. The first version that drew them all took 22.4ms; the rest came from sorting and copying them far less and from sharing the work across every core of the processor.
- Every animation runs on a clock instead of counting frames.
- A scroll that starts after the camera has stood still no longer lurches. The first frame of the move was timed from the last time the camera moved, so after a few seconds of looking at one spot it was worth three frames of scrolling at once. The clock runs while the camera is still now, and the first frame moves one frame's worth.
@@ -1304,5 +1305,5 @@ 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.
+- A frame through Direct3D 11 still costs a little more than it does through the old renderer: 7.6ms against 6.3ms in a screen full of inferno cannon fire. `-d3d9` on the command line puts the old renderer back on its own.
- You need to own the game; no game data ships here.
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp
index 797118929..7aaa4c626 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp
@@ -253,6 +253,7 @@ DX11BackendClass::~DX11BackendClass()
bool DX11BackendClass::Initialise(DX11DeviceClass * device)
{
Device = device;
+ Forget_Bindings();
// New buffers hold nothing the copies below know about.
VertexConstantsHeld = false;
@@ -679,6 +680,7 @@ void DX11BackendClass::Begin_Scene()
}
Device->Get_Context()->OMSetRenderTargets(1, &target, Device->Get_Depth_Stencil_View());
+ Forget_Bindings();
Set_Viewport(0, 0, Device->Get_Width(), Device->Get_Height());
}
@@ -756,6 +758,7 @@ void DX11BackendClass::Set_Render_Target(ID3D11RenderTargetView * target)
if (back_buffer != NULL) {
Device->Get_Context()->OMSetRenderTargets(1, &back_buffer,
Device->Get_Depth_Stencil_View());
+ Forget_Bindings();
Set_Viewport(0, 0, Device->Get_Width(), Device->Get_Height());
}
return;
@@ -789,6 +792,7 @@ void DX11BackendClass::Set_Render_Target(ID3D11RenderTargetView * target)
CurrentTargetResource = resource;
CurrentDepth = Depth_For(width, height);
Device->Get_Context()->OMSetRenderTargets(1, &CurrentTarget, CurrentDepth);
+ Forget_Bindings();
Set_Viewport(0, 0, width, height);
}
@@ -1233,6 +1237,8 @@ void DX11BackendClass::Forget_Last_State_Objects()
LastDepthStencilState = NULL;
LastRasterizerState = NULL;
memset(LastSamplerStates, 0, sizeof(LastSamplerStates));
+ // A released state object's address can come back as a new one, so what is bound goes too.
+ Forget_Bindings();
}
ID3D11BlendState * DX11BackendClass::Blend_State()
@@ -1357,36 +1363,121 @@ ID3D11Buffer * DX11BackendClass::Vertex_Constants() const
return (VertexProgram != ENGINE_SHADER_NONE) ? EngineConstantBuffer : VertexConstantBuffer;
}
+void DX11BackendClass::Forget_Bindings()
+{
+ memset(&Bound, 0, sizeof(Bound));
+ memset(TargetCheckedViews, 0, sizeof(TargetCheckedViews));
+ memset(TargetCheckedIsTarget, 0, sizeof(TargetCheckedIsTarget));
+}
+
void DX11BackendClass::Bind_State_Objects()
{
ID3D11DeviceContext * context = Device->Get_Context();
+ const bool known = Bound.Known;
- context->OMSetBlendState(Blend_State(), NULL, 0xffffffff);
- context->OMSetDepthStencilState(Depth_Stencil_State(), RenderStates.Get_Stencil_Reference());
- context->RSSetState(Rasterizer_State());
+ ID3D11BlendState * blend = Blend_State();
+ if (!known || blend != Bound.Blend) {
+ context->OMSetBlendState(blend, NULL, 0xffffffff);
+ Bound.Blend = blend;
+ }
+ ID3D11DepthStencilState * depth_stencil = Depth_Stencil_State();
+ const UINT stencil_reference = RenderStates.Get_Stencil_Reference();
+ if (!known || depth_stencil != Bound.DepthStencil || stencil_reference != Bound.StencilReference) {
+ context->OMSetDepthStencilState(depth_stencil, stencil_reference);
+ Bound.DepthStencil = depth_stencil;
+ Bound.StencilReference = stencil_reference;
+ }
+ ID3D11RasterizerState * rasterizer = Rasterizer_State();
+ if (!known || rasterizer != Bound.Rasterizer) {
+ context->RSSetState(rasterizer);
+ Bound.Rasterizer = rasterizer;
+ }
ID3D11SamplerState * samplers[DX11_BACKEND_TEXTURE_STAGES];
ID3D11ShaderResourceView * textures[DX11_BACKEND_TEXTURE_STAGES];
for (unsigned sampler = 0; sampler < DX11_BACKEND_TEXTURE_STAGES; ++sampler) {
samplers[sampler] = Sampler_State(sampler);
- textures[sampler] = Readable_Texture(Textures[sampler]);
+ textures[sampler] = Readable_Texture(sampler, Textures[sampler]);
+ }
+ if (!known || memcmp(samplers, Bound.Samplers, sizeof(samplers)) != 0) {
+ context->PSSetSamplers(0, DX11_BACKEND_TEXTURE_STAGES, samplers);
+ memcpy(Bound.Samplers, samplers, sizeof(samplers));
+ }
+ if (!known || memcmp(textures, Bound.Textures, sizeof(textures)) != 0) {
+ context->PSSetShaderResources(0, DX11_BACKEND_TEXTURE_STAGES, textures);
+ memcpy(Bound.Textures, textures, sizeof(textures));
}
- context->PSSetSamplers(0, DX11_BACKEND_TEXTURE_STAGES, samplers);
- context->PSSetShaderResources(0, DX11_BACKEND_TEXTURE_STAGES, textures);
}
-ID3D11ShaderResourceView * DX11BackendClass::Readable_Texture(ID3D11ShaderResourceView * texture)
+void DX11BackendClass::Bind_Pipeline(const Pipeline & pipeline, ID3D11Buffer * vertices, UINT stride,
+ UINT offset, ID3D11Buffer * indices, DXGI_FORMAT index_format, D3D11_PRIMITIVE_TOPOLOGY topology)
+{
+ ID3D11DeviceContext * context = Device->Get_Context();
+ const bool known = Bound.Known;
+
+ if (!known || pipeline.Layout != Bound.Layout) {
+ context->IASetInputLayout(pipeline.Layout);
+ Bound.Layout = pipeline.Layout;
+ }
+ if (!known || vertices != Bound.VertexBuffer || stride != Bound.VertexStride
+ || offset != Bound.VertexOffset) {
+ context->IASetVertexBuffers(0, 1, &vertices, &stride, &offset);
+ Bound.VertexBuffer = vertices;
+ Bound.VertexStride = stride;
+ Bound.VertexOffset = offset;
+ }
+ // A draw with no index buffer leaves the last one bound, as it always did.
+ if (indices != NULL && (!known || indices != Bound.IndexBuffer || index_format != Bound.IndexFormat)) {
+ context->IASetIndexBuffer(indices, index_format, 0);
+ Bound.IndexBuffer = indices;
+ Bound.IndexFormat = index_format;
+ }
+ if (!known || topology != Bound.Topology) {
+ context->IASetPrimitiveTopology(topology);
+ Bound.Topology = topology;
+ }
+ if (!known || pipeline.VertexShader != Bound.VertexShader) {
+ context->VSSetShader(pipeline.VertexShader, NULL, 0);
+ Bound.VertexShader = pipeline.VertexShader;
+ }
+ ID3D11Buffer * vertex_constants = Vertex_Constants();
+ if (!known || vertex_constants != Bound.VertexConstants) {
+ context->VSSetConstantBuffers(0, 1, &vertex_constants);
+ Bound.VertexConstants = vertex_constants;
+ }
+ if (!known || pipeline.PixelShader != Bound.PixelShader) {
+ context->PSSetShader(pipeline.PixelShader, NULL, 0);
+ Bound.PixelShader = pipeline.PixelShader;
+ }
+ if (!known || PixelConstantBuffer != Bound.PixelConstants) {
+ context->PSSetConstantBuffers(0, 1, &PixelConstantBuffer);
+ Bound.PixelConstants = PixelConstantBuffer;
+ }
+ Bound.Known = true;
+}
+
+ID3D11ShaderResourceView * DX11BackendClass::Readable_Texture(unsigned stage,
+ ID3D11ShaderResourceView * texture)
{
if (texture == NULL || CurrentTarget == NULL) {
return texture;
}
- ID3D11Resource * resource = NULL;
- texture->GetResource(&resource);
- resource->Release();
- if (resource != CurrentTargetResource) {
+ // The whole scene is drawn into a target when the screen filters are on, and asking every
+ // texture of every draw which resource it views went through the runtime twice a stage: 4% of
+ // the fireball frame. The answer only changes with the view or the target, and a new target
+ // calls Forget_Bindings, which clears these.
+ if (texture != TargetCheckedViews[stage]) {
+ ID3D11Resource * resource = NULL;
+ texture->GetResource(&resource);
+ resource->Release();
+ TargetCheckedViews[stage] = texture;
+ TargetCheckedIsTarget[stage] = resource == CurrentTargetResource;
+ }
+ if (!TargetCheckedIsTarget[stage]) {
return texture;
}
+ ID3D11Resource * resource = CurrentTargetResource;
// Set_Render_Target keeps only a target that is a two dimensional texture.
D3D11_TEXTURE2D_DESC description;
@@ -1466,17 +1557,7 @@ bool DX11BackendClass::Draw_Indexed(unsigned index_count, unsigned start_index,
Upload_Constants();
Bind_State_Objects();
- const UINT stride = StreamStride;
- const UINT offset = StreamOffset;
- context->IASetInputLayout(pipeline.Layout);
- context->IASetVertexBuffers(0, 1, &StreamBuffer, &stride, &offset);
- context->IASetIndexBuffer(IndexBuffer, IndexFormat, 0);
- context->IASetPrimitiveTopology(topology);
- context->VSSetShader(pipeline.VertexShader, NULL, 0);
- ID3D11Buffer * vertex_constants = Vertex_Constants();
- context->VSSetConstantBuffers(0, 1, &vertex_constants);
- context->PSSetShader(pipeline.PixelShader, NULL, 0);
- context->PSSetConstantBuffers(0, 1, &PixelConstantBuffer);
+ Bind_Pipeline(pipeline, StreamBuffer, StreamStride, StreamOffset, IndexBuffer, IndexFormat, topology);
context->DrawIndexed(index_count, start_index, base_vertex);
++DrawsMade;
@@ -1515,16 +1596,8 @@ bool DX11BackendClass::Draw_Triangles(unsigned vertex_count, unsigned start_vert
Upload_Constants();
Bind_State_Objects();
- const UINT stride = StreamStride;
- const UINT offset = StreamOffset;
- context->IASetInputLayout(pipeline.Layout);
- context->IASetVertexBuffers(0, 1, &StreamBuffer, &stride, &offset);
- context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- context->VSSetShader(pipeline.VertexShader, NULL, 0);
- ID3D11Buffer * vertex_constants = Vertex_Constants();
- context->VSSetConstantBuffers(0, 1, &vertex_constants);
- context->PSSetShader(pipeline.PixelShader, NULL, 0);
- context->PSSetConstantBuffers(0, 1, &PixelConstantBuffer);
+ Bind_Pipeline(pipeline, StreamBuffer, StreamStride, StreamOffset, NULL, DXGI_FORMAT_UNKNOWN,
+ D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
context->Draw(vertex_count, start_vertex);
++DrawsMade;
@@ -1685,16 +1758,8 @@ bool DX11BackendClass::Draw_User_Strip(const void * vertices, unsigned primitive
Upload_Constants();
Bind_State_Objects();
- const UINT vertex_stride = stride;
- const UINT offset = 0;
- context->IASetInputLayout(pipeline.Layout);
- context->IASetVertexBuffers(0, 1, &UserBuffer, &vertex_stride, &offset);
- context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- context->VSSetShader(pipeline.VertexShader, NULL, 0);
- ID3D11Buffer * vertex_constants = Vertex_Constants();
- context->VSSetConstantBuffers(0, 1, &vertex_constants);
- context->PSSetShader(pipeline.PixelShader, NULL, 0);
- context->PSSetConstantBuffers(0, 1, &PixelConstantBuffer);
+ Bind_Pipeline(pipeline, UserBuffer, stride, 0, NULL, DXGI_FORMAT_UNKNOWN,
+ D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
context->Draw(list_vertex_count, 0);
++DrawsMade;
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h
index 338c87684..5590e3963 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h
@@ -71,6 +71,9 @@ public:
bool Initialise(DX11DeviceClass * device);
void Shutdown();
+ // For whoever binds on the context behind the draws: the next draw binds everything again.
+ void Forget_Bindings();
+
// The setters, named for the D3D9 calls the engine makes. None of them touches the device;
// they write into the shadow state that Draw resolves.
void Set_Render_State(D3DRENDERSTATETYPE state, DWORD value);
@@ -276,8 +279,7 @@ private:
float World[16];
float View[16];
- float Projection[16];
- // The per-stage texture transforms. Two of them, because ffvertex writes two and the game sets
+ float Projection[16]; // The per-stage texture transforms. Two of them, because ffvertex writes two and the game sets
// no more than two stages in any state the probe counted. These are what turn a camera space
// position into the cloud shadow's coordinates, and with an identity in their place the whole
// terrain samples one texel of it.
@@ -425,7 +427,10 @@ private:
ID3D11Resource * CurrentTargetResource;
ID3D11Texture2D * TargetCopy;
ID3D11ShaderResourceView * TargetCopyView;
- ID3D11ShaderResourceView * Readable_Texture(ID3D11ShaderResourceView * texture);
+ ID3D11ShaderResourceView * Readable_Texture(unsigned stage, ID3D11ShaderResourceView * texture);
+ // Per stage, the last view asked about and whether it views the current target.
+ ID3D11ShaderResourceView * TargetCheckedViews[DX11_BACKEND_TEXTURE_STAGES];
+ bool TargetCheckedIsTarget[DX11_BACKEND_TEXTURE_STAGES];
std::map<std::string, ID3D11BlendState *> BlendStates;
std::map<std::string, ID3D11DepthStencilState *> DepthStencilStates;
@@ -449,6 +454,37 @@ private:
ID3D11SamplerState * LastSamplerStates[DX11_BACKEND_TEXTURE_STAGES];
void Forget_Last_State_Objects();
+ // What the last draw left bound on the context, so the next one only makes the calls that change
+ // something. Every draw used to make fifteen binding calls, and in the fireball scene the runtime
+ // behind them was the largest single thing on the main thread. Only the draws below bind through
+ // this; whatever else binds on the context calls Forget_Bindings, and so does anything that
+ // changes the render target, since the runtime unbinds any view of a texture that becomes one.
+ struct ContextBindings
+ {
+ bool Known;
+ ID3D11BlendState * Blend;
+ ID3D11DepthStencilState * DepthStencil;
+ UINT StencilReference;
+ ID3D11RasterizerState * Rasterizer;
+ ID3D11SamplerState * Samplers[DX11_BACKEND_TEXTURE_STAGES];
+ ID3D11ShaderResourceView * Textures[DX11_BACKEND_TEXTURE_STAGES];
+ ID3D11InputLayout * Layout;
+ ID3D11Buffer * VertexBuffer;
+ UINT VertexStride;
+ UINT VertexOffset;
+ ID3D11Buffer * IndexBuffer;
+ DXGI_FORMAT IndexFormat;
+ D3D11_PRIMITIVE_TOPOLOGY Topology;
+ ID3D11VertexShader * VertexShader;
+ ID3D11Buffer * VertexConstants;
+ ID3D11PixelShader * PixelShader;
+ ID3D11Buffer * PixelConstants;
+ };
+ ContextBindings Bound;
+ void Bind_Pipeline(const Pipeline & pipeline, ID3D11Buffer * vertices, UINT stride,
+ UINT offset, ID3D11Buffer * indices, DXGI_FORMAT index_format,
+ D3D11_PRIMITIVE_TOPOLOGY topology);
+
unsigned PipelinesBuilt;
unsigned long long DrawsMade;
unsigned long long DrawsRefused;
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
index 27cad5eab..8bf5fd7e3 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
@@ -339,11 +339,13 @@ static void take_the_frame_to_the_screen()
Backend.Begin_Scene();
}
+// The chain binds its own shaders, states and views on the context the backend's draws use.
void Direct3D11_Finish_Scene()
{
if (Active && Post.Run_Chain()) {
take_the_frame_to_the_screen();
}
+ Backend.Forget_Bindings();
}
void Direct3D11_Finish_Frame()
@@ -351,6 +353,7 @@ void Direct3D11_Finish_Frame()
if (Active && Post.Copy_Through()) {
take_the_frame_to_the_screen();
}
+ Backend.Forget_Bindings();
}
void Direct3D11_Begin_Scene()
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffprobe.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffprobe.cpp
index f13f2204f..5412d3a62 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffprobe.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffprobe.cpp
@@ -62,6 +62,13 @@ static bool _CombinerShadersEnabled = false;
static std::map<Combination, unsigned> _Counts;
static std::map<IDirect3DPixelShader9 *, unsigned> _PixelShaderIds;
static unsigned long long _DrawsSeen = 0;
+static unsigned long long _DrawsSampled = 0;
+
+// Reading forty-odd states back off the device on every draw was 0.8ms of an 8ms frame in the
+// fireball scene, on either renderer, for a report nobody playing reads. One draw in this many is
+// read instead. The stride is a count, not a clock, so the same draws are sampled every run, and a
+// combination drawn even once a frame still turns up within the first second.
+static const unsigned SAMPLE_STRIDE = 16;
void FixedFunctionProbe_Enable(bool enabled)
{
@@ -88,10 +95,14 @@ void FixedFunctionProbe_Record(IDirect3DDevice9 * device)
if (!_Enabled || device == NULL) {
return;
}
- ++_DrawsSeen;
+ if (_DrawsSeen++ % SAMPLE_STRIDE != 0) {
+ return;
+ }
+ ++_DrawsSampled;
- Combination combination;
- combination.reserve(PIXEL_RENDER_STATE_COUNT + MAXIMUM_STAGES*STAGE_STATE_COUNT + 2);
+ // Kept between draws so a draw does not allocate one; clear() keeps the capacity.
+ static Combination combination;
+ combination.clear();
for (size_t index = 0; index < PIXEL_RENDER_STATE_COUNT; ++index) {
DWORD value = 0;
@@ -223,10 +234,10 @@ void FixedFunctionProbe_Dump(const char * path)
}
}
- fprintf(file, "%u distinct combinations over %llu draw calls\n",
- (unsigned)_Counts.size(), _DrawsSeen);
- fprintf(file, "%u of them fixed function (%llu draws), %u driven by a pixel shader (%u draws)\n",
- (unsigned)_Counts.size() - shader_combinations, _DrawsSeen - shader_draws,
+ fprintf(file, "%u distinct combinations over %llu draw calls, one in %u read (%llu)\n",
+ (unsigned)_Counts.size(), _DrawsSeen, SAMPLE_STRIDE, _DrawsSampled);
+ fprintf(file, "%u of them fixed function (%llu draws read), %u driven by a pixel shader (%u draws read)\n",
+ (unsigned)_Counts.size() - shader_combinations, _DrawsSampled - shader_draws,
shader_combinations, shader_draws);
fprintf(file, "%u distinct pixel shaders seen\n\n", (unsigned)_PixelShaderIds.size());
@@ -234,8 +245,8 @@ void FixedFunctionProbe_Dump(const char * path)
for (std::multimap<unsigned, const Combination *>::const_reverse_iterator entry = by_use.rbegin();
entry != by_use.rend(); ++entry) {
const Combination & combination = *entry->second;
- fprintf(file, "#%u %u draws (%.2f%%)\n", ++rank, entry->first,
- 100.0 * entry->first / (double)(_DrawsSeen ? _DrawsSeen : 1));
+ fprintf(file, "#%u %u draws read (%.2f%%)\n", ++rank, entry->first,
+ 100.0 * entry->first / (double)(_DrawsSampled ? _DrawsSampled : 1));
size_t position = 0;
for (size_t index = 0; index < PIXEL_RENDER_STATE_COUNT; ++index, ++position) {
@@ -261,4 +272,5 @@ void FixedFunctionProbe_Dump(const char * path)
_Counts.clear();
_PixelShaderIds.clear();
_DrawsSeen = 0;
+ _DrawsSampled = 0;
}
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshadercache.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshadercache.cpp
index 2d876cbcd..2fe04dd1a 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshadercache.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshadercache.cpp
@@ -84,7 +84,10 @@ void CombinerShaderCache_Read_Device(IDirect3DDevice9 * device, CombinerDescript
IDirect3DPixelShader9 * CombinerShaderCache_Get(IDirect3DDevice9 * device,
const CombinerDescription & description)
{
- const std::string key = CombinerShader_Key(description);
+ // The description's own bytes, not CombinerShader_Key's text: formatting that text on every draw
+ // was 15% of a Direct3D 9 frame in the fireball scene, all of it inside the C runtime's printf.
+ // CombinerShaderCache_Read_Device zeroes the whole struct first, so equal draws are equal bytes.
+ const std::string key((const char *)&description, sizeof(description));
const std::map<std::string, IDirect3DPixelShader9 *>::const_iterator known = _Shaders.find(key);
if (known != _Shaders.end()) {
if (known->second != NULL) {