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.

fix(w3ddevice): size shadow buffer slots to the 16-bit buffer limit

Olcay Seyganeea04c1d0cb1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f29363646..08893f3b4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -49,6 +49,7 @@ found and fixed, EA's own, not port damage.**
- The Performance / Quality slider stopped short of this version's own looks: you had to find each box by hand. Now it reaches all nine. One stop past High brings tone mapping, the sky and ground light, ambient occlusion and water splashes, the next adds battle marks and weather, and Ultra adds firelight, atmosphere and collapsing buildings. All nine together cost 1.4 ms of graphics card time a frame on an RTX 2060 in our chaos fight, 9.36 against 7.99. High is the picture it always was, and under Classic Graphics the slider leaves every one of them off at any stop. Firelight, atmosphere and collapsing buildings carry known faults, a stall, a black smear at a flat camera and a hitch, which is why they wait for Ultra.
- The launcher's Options page has the same slider, with every new box beside it. Move it there or in the game and each opens on what the other saved.
- A detail preset now means EA's detail settings. Before this, a preset in your settings file switched on team glow, water foam and 4x multisampling behind any box you could see, and not on the very first start, so the first start and the second drew different pictures. Now a Reforged setting comes on from its own line, which the menu writes when you accept.
+- The Classic stencil shadows no longer crash the game under a model with a very large shadow outline. The room the game kept for a shadow's outline ran out at about 680 edges, and a building past that took the match down. That room is sixteen times larger now.
- Smooth Motion, the blending that made units glide on a fast monitor, had no switch at all. It is a box in Options, Display, off until ticked, and a 60 Hz screen shows no difference either way.
- Already playing? Nothing in your settings file gets rewritten and every line in it still wins. A setting you never touched has no line, so it takes the new default, which for most of you means Classic on your next start. Untick Classic Graphics once and you are back. The settings can differ between players in one match: none of them reaches the game's logic.
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DBufferManager.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DBufferManager.h
index e31e357eb..79374f602 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DBufferManager.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DBufferManager.h
@@ -37,14 +37,18 @@
#include "dx8vertexbuffer.h"
#include "dx8indexbuffer.h"
-#define MAX_VB_SIZES 128 //number of different sized VB slots allowed.
+// One size class per MIN_SLOT_SIZE step, up to 65504: DX8VertexBufferClass and DX8IndexBufferClass
+// take their counts as unsigned short, so a buffer, and the slot inside it, holds no more. At 128
+// classes (4096 vertices, 4096 indices) a building whose shadow silhouette passed about 680 edges
+// indexed past both tables in getSlot.
+#define MAX_VB_SIZES ((65536 >> MIN_SLOT_SIZE_SHIFT) - 1) //number of different sized VB slots allowed.
#define MIN_SLOT_SIZE 32 //minimum number of vertices allocated per slot (power of 2). See also MIN_SLOT_SIZE_SHIFT.
#define MIN_SLOT_SIZE_SHIFT 5 //used for division by MIN_SLOT_SIZE
#define MAX_VERTEX_BUFFERS_CREATED 32 //maximum number of D3D vertex buffers allowed to create per vertex type.
#define DEFAULT_VERTEX_BUFFER_SIZE 8192 //this size ends up generating VB's of about 256Kbytes
#define MAX_NUMBER_SLOTS 4096 //maximum number of slots that can be allocated.
-#define MAX_IB_SIZES 128 //number of different sized IB slots allowed (goes all the way up to 65536)
+#define MAX_IB_SIZES MAX_VB_SIZES //number of different sized IB slots allowed, the same unsigned short ceiling
#define MAX_INDEX_BUFFERS_CREATED 32
#define DEFAULT_INDEX_BUFFER_SIZE 32768
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DBufferManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DBufferManager.cpp
index d3f79a56b..6ac6aef4b 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DBufferManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DBufferManager.cpp
@@ -243,7 +243,14 @@ W3DBufferManager::W3DVertexBufferSlot *W3DBufferManager::getSlot(VBM_FVF_TYPES f
size = (size + (MIN_SLOT_SIZE-1)) & (~(MIN_SLOT_SIZE-1));
Int sizeIndex = (size >> MIN_SLOT_SIZE_SHIFT)-1;
- DEBUG_ASSERTCRASH(sizeIndex < MAX_VB_SIZES && size, ("Allocating too large vertex buffer slot"));
+ DEBUG_ASSERTCRASH(size, ("Allocating empty vertex buffer slot"));
+
+ // Past the table a slot has no size class to come back to, and no buffer could hold it.
+ if (sizeIndex >= MAX_VB_SIZES)
+ {
+ logShadowBudgetOnce("vertex buffer slot sizes", MAX_VB_SIZES << MIN_SLOT_SIZE_SHIFT);
+ return NULL;
+ }
if ((vbSlot=m_W3DVertexBufferSlots[fvfType][sizeIndex]) != 0)
{ //found a previously allocated slot matching required size
@@ -367,7 +374,13 @@ W3DBufferManager::W3DIndexBufferSlot *W3DBufferManager::getSlot(Int size)
size = (size + (MIN_SLOT_SIZE-1)) & (~(MIN_SLOT_SIZE-1));
Int sizeIndex = (size >> MIN_SLOT_SIZE_SHIFT)-1;
- DEBUG_ASSERTCRASH(sizeIndex < MAX_IB_SIZES && size, ("Allocating too large index buffer slot"));
+ DEBUG_ASSERTCRASH(size, ("Allocating empty index buffer slot"));
+
+ if (sizeIndex >= MAX_IB_SIZES)
+ {
+ logShadowBudgetOnce("index buffer slot sizes", MAX_IB_SIZES << MIN_SLOT_SIZE_SHIFT);
+ return NULL;
+ }
if ((ibSlot=m_W3DIndexBufferSlots[sizeIndex]) != 0)
{ //found a previously allocated slot matching required size