Skip to content

unify(ww3d2): Merge dx8wrapper, dx8caps, shdlib#2499

Open
stephanmeesters wants to merge 12 commits intoTheSuperHackers:mainfrom
stephanmeesters:unify/dx8wrapper
Open

unify(ww3d2): Merge dx8wrapper, dx8caps, shdlib#2499
stephanmeesters wants to merge 12 commits intoTheSuperHackers:mainfrom
stephanmeesters:unify/dx8wrapper

Conversation

@stephanmeesters
Copy link
Copy Markdown

@stephanmeesters stephanmeesters commented Mar 29, 2026

Merged by hand using WinMerge.

I didn't make any decision about dead code and merged that along too, noted in commit messages

@stephanmeesters stephanmeesters changed the title unify(dx8wrapper): Merge dxwrapper.cpp/h unify(dx8wrapper): Merge dxwrapper Mar 29, 2026
@stephanmeesters stephanmeesters changed the title unify(dx8wrapper): Merge dxwrapper unify(dx8wrapper): Merge dx8wrapper, dx8caps, shdlib Mar 29, 2026
@stephanmeesters stephanmeesters marked this pull request as ready for review March 29, 2026 12:26
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 29, 2026

Greptile Summary

This PR merges three historically separate DX8 wrapper source units (dx8wrapper, dx8caps, shdlib) into a unified set, bringing the codebase up to what appears to be a later internal revision (~2002 EA/Westwood). It is a substantial port of missing functionality rather than new community code.

Key changes included:

  • Multi-stream vertex buffersRenderStateStruct::vertex_buffer is replaced by vertex_buffers[MAX_VERTEX_STREAMS], with consistent updates across dx8wrapper.cpp, dx8wrapper.h, and sortingrenderer.cpp.
  • Unified capshwVPCaps/swVPCaps collapsed into a single DX8Caps::Caps member; new overload constructor accepts pre-queried caps.
  • Extensive vendor-specific hacksCheck_Driver_Version_Status() and expanded Vendor_Specific_Hacks() cover NVidia, ATI, Matrox, 3DFX, PowerVR, S3, and VMware with per-device capability overrides and driver build-version blacklists.
  • ZBias support — new Set_DX8_ZBias() / Set_Projection_Transform_With_Z_Bias() functions with hardware fallback via projection matrix manipulation.
  • shdlib.h — new stub header providing no-op macros when USE_WWSHADE is disabled, added to CMakeLists.txt and wired into init/shutdown lifecycle.
  • Robustness improvementsD3DERR_OUTOFVIDEOMEMORY recovery (texture/mesh-cache invalidation + retry), dynamic depth-stencil format detection in Clear(), and fallback resolution stepping in Registry_Load_Render_Device.
  • Device enumeration — devices with zero valid resolutions are now filtered out; Is_Valid_Display_Format() enforces per-card resolution caps.

The only findings are P2 style issues: wrong game title and stale copyright year in shdlib.h's prologue, if/for bodies on the same line as conditions in several new code blocks, and a pair of swapped comments in Set_Any_Render_Device() left over from the logic inversion (fullscreen now tried before windowed).

Confidence Score: 5/5

Safe to merge — all findings are P2 style/convention issues that do not affect runtime correctness.

No P0 or P1 issues found. The structural change from single to multi-stream vertex buffers is applied consistently across all call sites. The caps unification is logically sound. All remaining comments are minor style concerns (header text, comment wording, single-line if bodies) that can be addressed in a follow-up.

shdlib.h (wrong product name + stale year in prologue); dx8wrapper.cpp (swapped comments in Set_Any_Render_Device).

Important Files Changed

Filename Overview
Generals/Code/Libraries/Source/WWVegas/WW3D2/CMakeLists.txt Adds shdlib.h to the WW3D2 source list; trivial one-line change with no issues.
Generals/Code/Libraries/Source/WWVegas/WW3D2/shdlib.h New header providing no-op macros when USE_WWSHADE is not defined; has wrong product name ("Zero Hour" instead of "Generals") and a stale copyright year (2025 instead of 2026) in its prologue.
Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8caps.h Adds new constructor overload, several capability accessors (ZBias, cubemap, multi-pass, fog), driver version status accessor, and log getters; collapses hwVPCaps/swVPCaps into a single Caps member.
Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8caps.cpp Major expansion: adds DXLOG/COMPACTLOG macros for diagnostic logging, a full Check_Driver_Version_Status() function with per-vendor/per-build blacklists, Is_Valid_Display_Format(), and extensive vendor-specific hacks (NVidia, ATI, 3DFX, PowerVR, S3, Matrox, VMware).
Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h Expands RenderStateStruct from single vertex_buffer to vertex_buffers[MAX_VERTEX_STREAMS], adds Set_DX8_ZBias/Set_Projection_Transform_With_Z_Bias inline implementations, and introduces the flimby hash function (dead code, call site is commented out). Minor style violations: for-loop bodies on the same line as conditions.
Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp Large merge: multi-stream vertex buffer support, SHD_INIT/SHUTDOWN lifecycle hooks, smarter D3DERR_OUTOFVIDEOMEMORY recovery with asset invalidation, dynamic depth-stencil detection in Clear(), device enumeration improvements (filter zero-resolution devices), and fallback resolution logic in Registry_Load_Render_Device. Misleading swapped comments in Set_Any_Render_Device and minor if-body-on-same-line style violations.
Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cpp Minor: adds commented-out ZBias calls between render passes and a blank line; no functional change.
Generals/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp Updates vertex_buffer to vertex_buffers[0] accesses to match new multi-stream struct, adds WWPROFILE instrumentation in Flush(), includes wwprofile.h and algorithm, and removes dead commented-out Apply() calls.

Sequence Diagram

sequenceDiagram
    participant App
    participant DX8Wrapper
    participant DX8Caps
    participant D3D as Direct3D8

    App->>DX8Wrapper: Enumerate_Devices()
    DX8Wrapper->>D3D: GetDeviceCaps(adapter, caps)
    DX8Wrapper->>D3D: GetAdapterIdentifier(adapter, id)
    DX8Wrapper->>DX8Caps: DX8Caps(d3d, caps, format, id)
    DX8Caps->>DX8Caps: Compute_Caps()
    DX8Caps->>DX8Caps: Check_Driver_Version_Status()
    DX8Caps->>DX8Caps: Vendor_Specific_Hacks()
    DX8Wrapper->>DX8Caps: Is_Valid_Display_Format(w, h, fmt)
    DX8Caps-->>DX8Wrapper: valid?
    DX8Wrapper-->>App: filtered RenderDeviceDescriptionTable

    App->>DX8Wrapper: Set_Render_Device(dev, w, h, bits, windowed)
    DX8Wrapper->>D3D: CreateDevice(...)
    alt 16/32-bit depth mismatch
        DX8Wrapper->>D3D: retry with D3DFMT_D16
    end
    DX8Wrapper->>DX8Wrapper: SHD_INIT

    App->>DX8Wrapper: Set_Vertex_Buffer(vb, stream)
    DX8Wrapper->>DX8Wrapper: update vertex_buffers[stream]

    App->>DX8Wrapper: Clear(color, z, ...)
    DX8Wrapper->>D3D: GetDepthStencilSurface()
    D3D-->>DX8Wrapper: depthbuffer
    DX8Wrapper->>DX8Wrapper: detect stencil from desc.Format
    DX8Wrapper->>D3D: Clear(flags)
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: Generals/Code/Libraries/Source/WWVegas/WW3D2/shdlib.h
Line: 2

Comment:
**Wrong product name for Generals/ directory**

This file is located in `Generals/Code/...`, but the GPL header uses `"Command & Conquer Generals Zero Hour(tm)"`. Per project convention, files in `Generals/` must use `"Command & Conquer Generals(tm)"`, while `"Generals Zero Hour(tm)"` is reserved for files under `GeneralsMD/`.

```suggestion
**	Command & Conquer Generals(tm)
```

**Rule Used:** Files in the Generals/ directory should use "Comma... ([source](https://app.greptile.com/review/custom-context?memory=c6b666fd-7852-40bc-a9fe-5fe48cd58769))

**Learnt From**
[TheSuperHackers/GeneralsGameCode#2153](https://github.com/TheSuperHackers/GeneralsGameCode/pull/2153#discussion_r2714608924)

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: Generals/Code/Libraries/Source/WWVegas/WW3D2/shdlib.h
Line: 3

Comment:
**Copyright year 2025 is prior to current year (2026)**

The comment references year `2025`, which is behind the current year. Please update to `2026`.

```suggestion
**	Copyright 2026 Electronic Arts Inc.
```

**Rule Used:** What: Flag newly created code comments that refere... ([source](https://app.greptile.com/review/custom-context?memory=fd72a556-4fd8-4db4-8b08-8e51516a64ad))

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h
Line: 1396-1397

Comment:
**Loop bodies should be on separate lines from conditions**

Both `for` loop bodies are on the same line as their conditions. Per the project style rule, loop/condition bodies must be on the next line to allow precise debugger breakpoint placement. The same pattern also appears in the new code at:
- `dx8wrapper.cpp:499``if (render_state.vertex_buffers[i]) render_state.vertex_buffers[i]->Release_Engine_Ref();`
- `dx8wrapper.cpp:722` — same pattern, inside `Release_Device()`
- `dx8caps.cpp:559``if (DriverDLL[0]=='3') VendorId=VENDOR_3DFX;`

```suggestion
	for (i=0;i<MAX_VERTEX_STREAMS;++i) {
		vertex_buffers[i]=0;
	}
	for (i=0;i<MAX_TEXTURE_STAGES;++i) {
		Textures[i]=0;
	}
```

**Rule Used:** Always place if/else/for/while statement bodies on... ([source](https://app.greptile.com/review/custom-context?memory=16b9b669-b823-49be-ba5b-2bd30ff3ba6d))

**Learnt From**
[TheSuperHackers/GeneralsGameCode#2067](https://github.com/TheSuperHackers/GeneralsGameCode/pull/2067#discussion_r2706274626)

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
Line: 836-849

Comment:
**Comments are reversed relative to actual loop order**

The PR swapped the loop bodies (fullscreen now first, windowed second) but the comments came from the old code and were placed on the wrong loops:

- Line 836: `// Then fullscreen` — but this is the **first** loop tried (windowed=`0` → fullscreen). "Then" implies it's secondary.
- Line 844: `// Try windowed first` — but this is the **second** loop tried (windowed=`1` → windowed). "first" is now misleading.

The comments should reflect the new intent:

```suggestion
	// Try fullscreen first
	int dev_number = 0;
	for (; dev_number < _RenderDeviceNameTable.Count(); dev_number++) {
		if (Set_Render_Device(dev_number,-1,-1,-1,0,false)) {
			return true;
		}
	}

	// Then windowed as fallback
	for (dev_number = 0; dev_number < _RenderDeviceNameTable.Count(); dev_number++) {
		if (Set_Render_Device(dev_number,-1,-1,-1,1,false)) {
			return true;
		}
	}
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (2): Last reviewed commit: "unify(dx8wrapper): Merge unnecessary for..." | Re-trigger Greptile

@Mauller
Copy link
Copy Markdown

Mauller commented Mar 29, 2026

This could probably do with a prior chore PR to cleanup the dead code, commented out stuff and remove dead defines that are unused like the xbox related stuff.

@stephanmeesters
Copy link
Copy Markdown
Author

This could probably do with a prior chore PR to cleanup the dead code, commented out stuff and remove dead defines that are unused like the xbox related stuff.

Sounds like a good idea, I’ll do that soon

@stephanmeesters stephanmeesters changed the title unify(dx8wrapper): Merge dx8wrapper, dx8caps, shdlib unify(dd3d2): Merge dx8wrapper, dx8caps, shdlib Mar 30, 2026
@stephanmeesters stephanmeesters changed the title unify(dd3d2): Merge dx8wrapper, dx8caps, shdlib unify(ww3d2): Merge dx8wrapper, dx8caps, shdlib Mar 30, 2026
@xezon xezon added Gen Relates to Generals Unify Unifies code between Generals and Zero Hour labels Mar 30, 2026
@xezon xezon added this to the Code foundation build up milestone Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gen Relates to Generals Unify Unifies code between Generals and Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants