Skip to content

Conversation

@JohnsterID
Copy link

@JohnsterID JohnsterID commented Jan 24, 2026

Summary

Eliminates d3dx8d.dll dependency for MinGW-w64 (i686) builds by implementing a D3DX8 compatibility layer using existing WWMath libraries and Direct3D 8 native APIs.

Build Strategy: Merge with Rebase (preserves commit history)

What This Achieves

Removed d3dx8d dependency from MinGW build targets g_generals and z_generals

  • generalsv.exe: 12M, no d3dx8.dll dependency
  • generalszh.exe: 13M, no d3dx8.dll dependency
  • Verified via objdump - both executables built and tested successfully

Provides strategic foundation for DX9 migration

  • Proven D3DX elimination pattern reusable after VC6 dropped
  • WWMath integration validated
  • Game code decoupled from D3DX dependency

Zero runtime overhead

  • Math functions: Inline WWMath wrappers
  • Texture operations: Direct D3D8 API (hardware accelerated)
  • Shaders: Precompiled bytecode (~450 bytes for 3 water shaders)

Function Replacement (D3DXCompat.h)

  • 20 D3DX functions implemented
  • Include guard coordination prevents min-dx8-sdk conflicts
  • Implementations:
    • Math: WWMath wrappers
    • Textures: Direct D3D8 API calls (CreateTexture, CopyRects)
    • Shaders: Precompiled bytecode lookup (3 water shaders)

Link-Time (cmake/dx8.cmake)

  • Removes d3dx8d from d3d8lib link libraries
  • All functions inline, no library needed

Implementation Highlights

D3DX Function Coverage (19 used by game)

Fully Implemented (16):

  • Matrix operations: Inverse, Multiply, Scaling, Translation, Transpose, Identity, RotationZ
  • Vector operations: Vec4Transform, Vec4Dot, Vec3Transform
  • Textures: CreateTexture, LoadSurfaceFromSurface
  • Shaders: AssembleShader (precompiled bytecode)
  • Utilities: GetFVFVertexSize, GetErrorStringA

Acceptable Stubs (3):

  • D3DXFilterTexture → No-op (game uses existing mipmaps)
  • D3DXCreateFont → WorldBuilder only (tools disabled in MinGW)
  • D3DXCreateTextureFromFileExA → Dead code (zero callers)

Shader Precompilation

Generated by scripts/compile_shaders.py from scripts/shaders/*.psh:

  • water_shader1.psh: River water (co-issued instructions)
  • water_shader2.psh: Environment mapping (texbem)
  • water_shader3.psh: Trapezoid water (mad)

D3DXAssembleShader identifies shaders by signature strings and returns precompiled bytecode.

Build Verification

Environment:

  • OS: Debian Trixie
  • Compiler: MinGW-w64 GCC 14-win32 (i686-w64-mingw32)
  • CMake: 3.31.6

Commands:

cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/mingw-w64-i686.cmake
cmake --build . --target g_generals -j$(nproc)
cmake --build . --target z_generals -j$(nproc)

DLL Dependencies:

i686-w64-mingw32-objdump -p generalsv.exe | grep "DLL Name:"
# Result: NO d3dx8.dll or d3dx8d.dll
# Only: KERNEL32, USER32, GDI32, ole32, binkw32, mss32, etc.

Known Limitations

1. WorldBuilder Not Supported

  • Current status: D3DXCreateFont is stubbed (4 call sites in wbview3d.cpp)
  • Scope: WorldBuilder is not built with MinGW (RTS_BUILD_GENERALS_TOOLS disabled)
  • Impact: No impact on game executables (g_generals, z_generals)
  • Future work: When WorldBuilder is unified (merging the Generals and GeneralsMD versions into a shared tool, consistent with other tool unification work) and the MFC dependency is replaced for MinGW compatibility, implement a D3DXCreateFont alternative.

### 2. Temporary Forked Dependencies (BLOCKER)
- bink-sdk-stub: JohnsterID/bink-sdk-stub@fix-mingw-export-aliases
- miles-sdk-stub: JohnsterID/miles-sdk-stub@fix-mingw-export-aliases
- TODO: Remove commit before merge, only used for runtime testing

JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 24, 2026
…rs#2176)

Create D3DXCompat.h with WWMath-based D3DX replacements (550 lines).
Implement vector/matrix math functions using existing WWMath library.
Add D3DXWrapper.h for conditional D3DX inclusion (45 lines).

Functions implemented:
- Math: D3DXVec4Dot, D3DXVec4Transform, D3DXVec3Transform,
  D3DXMatrixTranspose, D3DXMatrixMultiply, D3DXMatrixRotationZ (21 uses)
- Utilities: D3DXGetErrorStringA, D3DXGetFVFVertexSize (6 uses)
- Textures: D3DXCreateTexture, D3DXCreateCubeTexture,
  D3DXCreateVolumeTexture (6 uses)

Functions stubbed for future implementation:
- D3DXMatrixInverse: Awaiting Matrix4x4::Inverse() implementation
- D3DXLoadSurfaceFromSurface, D3DXFilterTexture: Return errors to
  trigger fallback to existing game code

This provides implementations for most D3DX8 functions used by the game.
JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 24, 2026
…rs#2176)

- Add no_d3dx_verify.cmake for post-build DLL import checking
- Add MINGW_NO_D3DX option to cmake/mingw.cmake (default: OFF)
- Conditional d3dx8d linking in main executables
- Update CMake targets for selective D3DXWrapper inclusion
- Add verification targets to g_generals and z_generals

Build system changes:
- cmake/mingw.cmake: NO_D3DX option, selective forced includes
- cmake/dx8.cmake: Conditional d3dx8d removal from d3d8lib
- cmake/no_d3dx_verify.cmake: Post-build objdump DLL verification
- CMakeLists.txt: Include verification system
- Target CMakeLists: Add conditional linking and forced includes

Currently disabled (MINGW_NO_D3DX=OFF) to use d3dx8.dll until header
conflicts are resolved. When enabled (ON), will verify no d3dx8 imports
in built executables.

Prepares build system for D3DX-free binaries in future releases.

Files modified:
- 11 CMakeLists.txt files across build system
- 1 new cmake verification module (no_d3dx_verify.cmake)
JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 24, 2026
…structure (TheSuperHackers#2176)

Complete D3DX8 elimination for Zero Hour targets and enable the feature
for both Generals and Zero Hour. This turns on the D3DX-free build by
default, eliminating the d3dx8.dll dependency.

Changes:
- Add D3DXWrapper.h forced include to generalszh, worldbuilder_zh
- Enable MINGW_NO_D3DX option by default (header conflicts resolved)
- Add shader stub infrastructure (scripts/shaders/water_shader2.psh, water_shader3.psh)
- Expand D3DXCompat.h with shader function stubs

Build status:
- generalsv.exe: 12M, NO d3dx8.dll dependency
- generalszh.exe: 13M, NO d3dx8.dll dependency

D3DX8 elimination complete for MinGW builds.

D3DXAssembleShader implementation completed in next commit.
JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 24, 2026
…eSuperHackers#2176)

Replace D3DXAssembleShader with precompiled bytecode lookup for water
shaders. This eliminates the shader compilation dependency.

Implementation approach:
- Extract 3 shader bytecodes from d3dx8.dll using Wine debugging
- Match shader source strings to identify which shader to return
- Create ID3DXBuffer wrapper class for bytecode storage

Shaders implemented:
1. River water shader (scripts/shaders/water_shader1.psh - co-issued instructions, +mul opcode)
2. Environment mapping water (scripts/shaders/water_shader2.psh - texbem bump environment mapping)
3. Trapezoid water (scripts/shaders/water_shader3.psh - mad multiply-add)

Total shader bytecode: ~450 bytes for all 3 shaders combined.

This completes D3DX8 elimination for MinGW builds. All D3DX functions
used by the game now have replacements or acceptable stubs.
JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 24, 2026
TheSuperHackers#2176)

Implement surface copying using D3D8's native IDirect3DDevice8::CopyRects
instead of Wine/d3dx8.dll. This provides hardware-accelerated surface copying
using Direct3D 8 API directly.

Implementation:
- Call pSrcSurface->GetDevice() to obtain D3D8 device
- Use device->CopyRects() for hardware-accelerated copy
- Same API as DX8Wrapper::_Copy_DX8_Rects (14 uses in codebase)
- No Wine code needed - pure D3D8 API

Why Direct D3D8 instead of Wine:
- CopyRects is native D3D8 functionality (no d3dx8.dll required)
- Avoids complex Wine texture locking/filtering code
- Game already uses this API extensively via DX8Wrapper
- Hardware-accelerated, same performance as existing code

Function now fully implemented with working surface copy.
JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 24, 2026
…Hackers#2176)

Implement D3DXMatrixIdentity using WWMath and stub D3DXCreateFont for
disabled Generals Tools build.

1. D3DXMatrixIdentity - Full Implementation
   - Maps to Matrix4x4::Make_Identity() from WWMath
   - Used in 8+ locations, including water rendering (W3DWater.cpp)
   - Critical for clipping matrix initialization

2. D3DXCreateFont - Stub for Disabled Tools
   - Only used in disabled Generals Tools (apt, w3dviewer)
   - Build preset RTS_BUILD_GENERALS_TOOLS=OFF by default
   - Returns D3DERR_NOTAVAILABLE to indicate unavailable functionality
   - Acceptable stub for out-of-scope build targets

Alternative approaches evaluated:
- Matrix4x4::Make_Identity() found in WWMath (used for implementation)
- No existing game font system suitable for D3DXCreateFont
- GDI CreateFont possible but unnecessary for disabled build

D3DXMatrixIdentity completes matrix math coverage alongside existing
D3DXMatrixMultiply, D3DXMatrixRotationZ, D3DXMatrixTranspose.
JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 24, 2026
…ibility (TheSuperHackers#2176)

Point to JohnsterID fork branches with MinGW export alias fixes.
These are temporary workarounds until upstream repositories accept the fixes.

Changes:
- bink-sdk-stub: TheSuperHackers → JohnsterID/fix-mingw-export-aliases
- miles-sdk-stub: TheSuperHackers → JohnsterID/fix-mingw-export-aliases

Issue: MinGW-w64 requires proper __declspec(dllexport) for stub libraries.
Upstream PRs pending to merge these fixes back to TheSuperHackers repos.
JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 24, 2026
TheSuperHackers#2176)

Implement surface copying using D3D8's native IDirect3DDevice8::CopyRects
instead of Wine/d3dx8.dll. This provides hardware-accelerated surface copying
using Direct3D 8 API directly.

Implementation:
- Call pSrcSurface->GetDevice() to obtain D3D8 device
- Use device->CopyRects() for hardware-accelerated copy
- Same API as DX8Wrapper::_Copy_DX8_Rects (14 uses in codebase)
- No Wine code needed - pure D3D8 API

Why Direct D3D8 instead of Wine:
- CopyRects is native D3D8 functionality (no d3dx8.dll required)
- Avoids complex Wine texture locking/filtering code
- Game already uses this API extensively via DX8Wrapper
- Hardware-accelerated, same performance as existing code

Function now fully implemented with working surface copy.
JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 24, 2026
…Hackers#2176)

Implement D3DXMatrixIdentity using WWMath and stub D3DXCreateFont for
disabled Generals Tools build.

1. D3DXMatrixIdentity - Full Implementation
   - Maps to Matrix4x4::Make_Identity() from WWMath
   - Used in 8+ locations, including water rendering (W3DWater.cpp)
   - Critical for clipping matrix initialization

2. D3DXCreateFont - Stub for Disabled Tools
   - Only used in disabled Generals Tools (apt, w3dviewer)
   - Build preset RTS_BUILD_GENERALS_TOOLS=OFF by default
   - Returns D3DERR_NOTAVAILABLE to indicate unavailable functionality
   - Acceptable stub for out-of-scope build targets

Alternative approaches evaluated:
- Matrix4x4::Make_Identity() found in WWMath (used for implementation)
- No existing game font system suitable for D3DXCreateFont
- GDI CreateFont possible but unnecessary for disabled build

D3DXMatrixIdentity completes matrix math coverage alongside existing
D3DXMatrixMultiply, D3DXMatrixRotationZ, D3DXMatrixTranspose.
@xezon
Copy link

xezon commented Jan 25, 2026

I assume this is AI generated code?

Drafts are typically not looked at.

@JohnsterID
Copy link
Author

JohnsterID commented Jan 25, 2026

Yes with refactoring and runtime testing. I was going to switch to ready soon as I can't see anything else staring at it. It will help in the future anyway separate to Mingw-w64 with any eventual move to DX9 after VC6. I need to delete the temp commit as I had to use it for runtime testing.

@JohnsterID JohnsterID marked this pull request as ready for review January 25, 2026 10:15
@xezon xezon requested a review from OmniBlade January 25, 2026 10:38
@xezon
Copy link

xezon commented Jan 26, 2026

@greptileai

@greptile-apps
Copy link

greptile-apps bot commented Jan 26, 2026

Greptile Overview

Greptile Summary

Successfully eliminates d3dx8d.dll dependency from MinGW-w64 builds by implementing a comprehensive D3DX8 compatibility layer.

Key Changes:

  • D3DXCompat.h (1000 lines): Complete D3DX8 replacement layer implementing 20 functions using WWMath library for matrix/vector operations, Direct3D 8 native API for texture operations, and precompiled bytecode for shader assembly
  • D3DXWrapper.h: Conditional include wrapper that routes to compatibility layer when NO_D3DX is defined
  • Shader Infrastructure: Python assembler (compile_shaders.py) generates precompiled PS 1.1 bytecode for 3 water shaders, embedded directly in D3DXCompat.h (~450 bytes total)
  • Build System: CMake changes enable MINGW_NO_D3DX option (default ON), remove d3dx8d linkage, apply forced includes to relevant targets, and add post-build verification via objdump

Implementation Quality:

  • Math functions use proven WWMath library (existing Westwood codebase)
  • Texture operations call Direct3D 8 API directly (hardware accelerated)
  • Shader identification uses unique instruction signatures (+mul r0.a, texbem, mad)
  • Include guard coordination prevents conflicts with min-dx8-sdk headers
  • Zero runtime overhead (all math functions inline, textures use native D3D8)

Build Verification:

  • Confirmed via objdump: generalsv.exe (12M) and generalszh.exe (13M) have no d3dx8.dll dependency
  • Automated post-build verification added to fail builds if d3dx8*.dll imports detected

Strategic Value:

  • Provides reusable pattern for DX9 migration after VC6 dropped
  • Decouples game code from D3DX dependency
  • WorldBuilder stubs acceptable (tools not built with MinGW)

Confidence Score: 5/5

  • Safe to merge - well-architected dependency elimination with comprehensive testing and verification
  • All D3DX function implementations verified correct against usage patterns in codebase, WWMath integration proven, Direct3D 8 API usage follows existing patterns, shader bytecode matches source assembly, build verification ensures no DLL dependency leakage, zero impact on non-MinGW builds
  • No files require special attention

Important Files Changed

Filename Overview
Core/Libraries/Include/Lib/D3DXCompat.h Comprehensive D3DX8 compatibility layer with WWMath integration, Direct3D 8 wrappers, and precompiled shader bytecode - all implementations verified correct
Core/Libraries/Include/Lib/D3DXWrapper.h Clean conditional include wrapper that routes to D3DXCompat.h when NO_D3DX is defined, otherwise uses standard d3dx8.h
scripts/compile_shaders.py Pixel Shader 1.1 assembler for water shaders - generates precompiled bytecode arrays embedded in D3DXCompat.h
cmake/dx8.cmake Removes d3dx8d from d3d8lib link libraries when MINGW_NO_D3DX is enabled
cmake/mingw.cmake Added MINGW_NO_D3DX option (default ON) that defines NO_D3DX and sets up D3DXWrapper.h for selective inclusion
cmake/no_d3dx_verify.cmake Post-build verification using objdump to ensure executables have no d3dx8*.dll imports when NO_D3DX is enabled
Generals/Code/Main/CMakeLists.txt Conditionally links d3dx8 only when NO_D3DX is disabled, adds verification for g_generals target
GeneralsMD/Code/Main/CMakeLists.txt Conditionally links d3dx8 only when NO_D3DX is disabled, adds verification for z_generals target

Sequence Diagram

sequenceDiagram
    participant Game as Game Code
    participant Wrapper as D3DXWrapper.h
    participant Compat as D3DXCompat.h
    participant WWMath as WWMath Library
    participant D3D8 as Direct3D 8 API
    participant Shader as Precompiled Shaders

    Note over Game,Shader: MinGW Build with NO_D3DX enabled

    Game->>Wrapper: #include D3DXWrapper.h
    Wrapper->>Compat: #include D3DXCompat.h (when NO_D3DX)
    Note over Compat: Defines include guards to block<br/>min-dx8-sdk D3DX headers

    rect rgb(240, 248, 255)
        Note over Game,WWMath: Math Operations (WWMath-based)
        Game->>Compat: D3DXMatrixInverse()
        Compat->>WWMath: Matrix4x4::Inverse()
        WWMath-->>Compat: Inverse matrix
        Compat-->>Game: D3DXMATRIX result

        Game->>Compat: D3DXMatrixMultiply()
        Compat->>WWMath: Matrix4x4::operator*
        WWMath-->>Compat: Product matrix
        Compat-->>Game: D3DXMATRIX result

        Game->>Compat: D3DXVec4Transform()
        Compat->>WWMath: Matrix4x4::Transform_Vector()
        WWMath-->>Compat: Transformed vector
        Compat-->>Game: D3DXVECTOR4 result
    end

    rect rgb(240, 255, 240)
        Note over Game,D3D8: Texture Operations (Direct D3D8)
        Game->>Compat: D3DXCreateTexture()
        Compat->>D3D8: IDirect3DDevice8::CreateTexture()
        D3D8-->>Compat: IDirect3DTexture8*
        Compat-->>Game: Texture created

        Game->>Compat: D3DXLoadSurfaceFromSurface()
        Compat->>D3D8: GetDevice() + CopyRects()
        D3D8-->>Compat: Hardware-accelerated copy
        Compat-->>Game: Surface copied
    end

    rect rgb(255, 248, 240)
        Note over Game,Shader: Shader Assembly (Precompiled)
        Game->>Compat: D3DXAssembleShader(water_shader1)
        Compat->>Shader: Identify by "+mul r0.a" signature
        Shader-->>Compat: shader1_bytecode[]
        Compat->>Compat: new D3DXShaderBuffer(bytecode)
        Compat-->>Game: ID3DXBuffer* with bytecode

        Game->>D3D8: CreatePixelShader(bytecode)
        D3D8-->>Game: Pixel shader created
    end

    Note over Game,Shader: Result: No d3dx8.dll dependency<br/>All functions inline or direct D3D8 calls
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 27, 2026
TheSuperHackers#2176)

Implement surface copying using D3D8's native IDirect3DDevice8::CopyRects
instead of Wine/d3dx8.dll. This provides hardware-accelerated surface copying
using Direct3D 8 API directly.

Implementation:
- Call pSrcSurface->GetDevice() to obtain D3D8 device
- Use device->CopyRects() for hardware-accelerated copy
- Same API as DX8Wrapper::_Copy_DX8_Rects (14 uses in codebase)
- No Wine code needed - pure D3D8 API

Why Direct D3D8 instead of Wine:
- CopyRects is native D3D8 functionality (no d3dx8.dll required)
- Avoids complex Wine texture locking/filtering code
- Game already uses this API extensively via DX8Wrapper
- Hardware-accelerated, same performance as existing code

Function now fully implemented with working surface copy.
JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 27, 2026
…Hackers#2176)

Implement D3DXMatrixIdentity using WWMath and stub D3DXCreateFont for
disabled Generals Tools build.

1. D3DXMatrixIdentity - Full Implementation
   - Maps to Matrix4x4::Make_Identity() from WWMath
   - Used in 8+ locations, including water rendering (W3DWater.cpp)
   - Critical for clipping matrix initialization

2. D3DXCreateFont - Stub for Disabled Tools
   - Only used in disabled Generals Tools (apt, w3dviewer)
   - Build preset RTS_BUILD_GENERALS_TOOLS=OFF by default
   - Returns D3DERR_NOTAVAILABLE to indicate unavailable functionality
   - Acceptable stub for out-of-scope build targets

Alternative approaches evaluated:
- Matrix4x4::Make_Identity() found in WWMath (used for implementation)
- No existing game font system suitable for D3DXCreateFont
- GDI CreateFont possible but unnecessary for disabled build

D3DXMatrixIdentity completes matrix math coverage alongside existing
D3DXMatrixMultiply, D3DXMatrixRotationZ, D3DXMatrixTranspose.
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +19 to +25
/**
* D3DXCompat.h - D3DX8 compatibility layer using WWMath
*
* This header provides replacements for D3DX8 math functions using the existing
* WWMath library (Westwood Math). This eliminates the need for d3dx8.dll at runtime.
*
* Usage: Define NO_D3DX before including D3DX8 headers
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing @file directive in Doxygen block

Suggested change
/**
* D3DXCompat.h - D3DX8 compatibility layer using WWMath
*
* This header provides replacements for D3DX8 math functions using the existing
* WWMath library (Westwood Math). This eliminates the need for d3dx8.dll at runtime.
*
* Usage: Define NO_D3DX before including D3DX8 headers
/**
* @file D3DXCompat.h
* @brief D3DX8 compatibility layer using WWMath
*
* This header provides replacements for D3DX8 math functions using the existing
* WWMath library (Westwood Math). This eliminates the need for d3dx8.dll at runtime.
*
* Usage: Define NO_D3DX before including D3DX8 headers
*/

Context Used: Rule from dashboard - All source files (.h, .cpp, .inl) must have a standardized prologue consisting of: 1) GPL-3.0 licens... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: Core/Libraries/Include/Lib/D3DXCompat.h
Line: 19:25

Comment:
Missing `@file` directive in Doxygen block

```suggestion
/**
 * @file D3DXCompat.h
 * @brief D3DX8 compatibility layer using WWMath
 * 
 * This header provides replacements for D3DX8 math functions using the existing
 * WWMath library (Westwood Math). This eliminates the need for d3dx8.dll at runtime.
 * 
 * Usage: Define NO_D3DX before including D3DX8 headers
 */
```

**Context Used:** Rule from `dashboard` - All source files (.h, .cpp, .inl) must have a standardized prologue consisting of: 1) GPL-3.0 licens... ([source](https://app.greptile.com/review/custom-context?memory=c1850c23-ecc8-49a8-a6e9-ffb44120e6b3))

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

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

Comment on lines +19 to +28
/**
* D3DXWrapper.h - Conditional D3DX8 include
*
* Include this file instead of <d3dx8.h> directly.
* When NO_D3DX is defined, uses compatibility layer.
* Otherwise, uses standard D3DX8 headers.
*
* NOTE: This header is safe to force-include globally.
* For C files, it does nothing when NO_D3DX is defined.
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing @file directive in Doxygen block

Suggested change
/**
* D3DXWrapper.h - Conditional D3DX8 include
*
* Include this file instead of <d3dx8.h> directly.
* When NO_D3DX is defined, uses compatibility layer.
* Otherwise, uses standard D3DX8 headers.
*
* NOTE: This header is safe to force-include globally.
* For C files, it does nothing when NO_D3DX is defined.
*/
/**
* @file D3DXWrapper.h
* @brief Conditional D3DX8 include
*
* Include this file instead of <d3dx8.h> directly.
* When NO_D3DX is defined, uses compatibility layer.
* Otherwise, uses standard D3DX8 headers.
*
* NOTE: This header is safe to force-include globally.
* For C files, it does nothing when NO_D3DX is defined.
*/

Context Used: Rule from dashboard - All source files (.h, .cpp, .inl) must have a standardized prologue consisting of: 1) GPL-3.0 licens... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: Core/Libraries/Include/Lib/D3DXWrapper.h
Line: 19:28

Comment:
Missing `@file` directive in Doxygen block

```suggestion
/**
 * @file D3DXWrapper.h
 * @brief Conditional D3DX8 include
 * 
 * Include this file instead of <d3dx8.h> directly.
 * When NO_D3DX is defined, uses compatibility layer.
 * Otherwise, uses standard D3DX8 headers.
 * 
 * NOTE: This header is safe to force-include globally.
 * For C files, it does nothing when NO_D3DX is defined.
 */
```

**Context Used:** Rule from `dashboard` - All source files (.h, .cpp, .inl) must have a standardized prologue consisting of: 1) GPL-3.0 licens... ([source](https://app.greptile.com/review/custom-context?memory=c1850c23-ecc8-49a8-a6e9-ffb44120e6b3))

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

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

…rs#2176)

Create D3DXCompat.h with WWMath-based D3DX replacements (550 lines).
Implement vector/matrix math functions using existing WWMath library.
Add D3DXWrapper.h for conditional D3DX inclusion (45 lines).

Functions implemented:
- Math: D3DXVec4Dot, D3DXVec4Transform, D3DXVec3Transform,
  D3DXMatrixTranspose, D3DXMatrixMultiply, D3DXMatrixRotationZ (21 uses)
- Utilities: D3DXGetErrorStringA, D3DXGetFVFVertexSize (6 uses)
- Textures: D3DXCreateTexture, D3DXCreateCubeTexture,
  D3DXCreateVolumeTexture (6 uses)

Functions stubbed for future implementation:
- D3DXMatrixInverse: Awaiting Matrix4x4::Inverse() implementation
- D3DXLoadSurfaceFromSurface, D3DXFilterTexture: Return errors to
  trigger fallback to existing game code

This provides implementations for most D3DX8 functions used by the game.
…rs#2176)

- Add no_d3dx_verify.cmake for post-build DLL import checking
- Add MINGW_NO_D3DX option to cmake/mingw.cmake (default: OFF)
- Conditional d3dx8d linking in main executables
- Update CMake targets for selective D3DXWrapper inclusion
- Add verification targets to g_generals and z_generals

Build system changes:
- cmake/mingw.cmake: NO_D3DX option, selective forced includes
- cmake/dx8.cmake: Conditional d3dx8d removal from d3d8lib
- cmake/no_d3dx_verify.cmake: Post-build objdump DLL verification
- CMakeLists.txt: Include verification system
- Target CMakeLists: Add conditional linking and forced includes

Currently disabled (MINGW_NO_D3DX=OFF) to use d3dx8.dll until header
conflicts are resolved. When enabled (ON), will verify no d3dx8 imports
in built executables.

Prepares build system for D3DX-free binaries in future releases.

Files modified:
- 11 CMakeLists.txt files across build system
- 1 new cmake verification module (no_d3dx_verify.cmake)
JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 27, 2026
…structure (TheSuperHackers#2176)

Complete D3DX8 elimination for Zero Hour targets and enable the feature
for both Generals and Zero Hour. This turns on the D3DX-free build by
default, eliminating the d3dx8.dll dependency.

Changes:
- Add D3DXWrapper.h forced include to generalszh, worldbuilder_zh
- Enable MINGW_NO_D3DX option by default (header conflicts resolved)
- Add shader stub infrastructure (scripts/shaders/water_shader2.psh, water_shader3.psh)
- Expand D3DXCompat.h with shader function stubs

Build status:
- generalsv.exe: 12M, NO d3dx8.dll dependency
- generalszh.exe: 13M, NO d3dx8.dll dependency

D3DX8 elimination complete for MinGW builds.

D3DXAssembleShader implementation completed in next commit.
JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 27, 2026
…eSuperHackers#2176)

Replace D3DXAssembleShader with precompiled bytecode lookup for water
shaders. This eliminates the shader compilation dependency.

Implementation approach:
- Extract 3 shader bytecodes from d3dx8.dll using Wine debugging
- Match shader source strings to identify which shader to return
- Create ID3DXBuffer wrapper class for bytecode storage

Shaders implemented:
1. River water shader (scripts/shaders/water_shader1.psh - co-issued instructions, +mul opcode)
2. Environment mapping water (scripts/shaders/water_shader2.psh - texbem bump environment mapping)
3. Trapezoid water (scripts/shaders/water_shader3.psh - mad multiply-add)

Total shader bytecode: ~450 bytes for all 3 shaders combined.

This completes D3DX8 elimination for MinGW builds. All D3DX functions
used by the game now have replacements or acceptable stubs.
JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 27, 2026
TheSuperHackers#2176)

Implement surface copying using D3D8's native IDirect3DDevice8::CopyRects
instead of Wine/d3dx8.dll. This provides hardware-accelerated surface copying
using Direct3D 8 API directly.

Implementation:
- Call pSrcSurface->GetDevice() to obtain D3D8 device
- Use device->CopyRects() for hardware-accelerated copy
- Same API as DX8Wrapper::_Copy_DX8_Rects (14 uses in codebase)
- No Wine code needed - pure D3D8 API

Why Direct D3D8 instead of Wine:
- CopyRects is native D3D8 functionality (no d3dx8.dll required)
- Avoids complex Wine texture locking/filtering code
- Game already uses this API extensively via DX8Wrapper
- Hardware-accelerated, same performance as existing code

Function now fully implemented with working surface copy.
JohnsterID added a commit to JohnsterID/GeneralsGameCode that referenced this pull request Jan 27, 2026
…Hackers#2176)

Implement D3DXMatrixIdentity using WWMath and stub D3DXCreateFont for
disabled Generals Tools build.

1. D3DXMatrixIdentity - Full Implementation
   - Maps to Matrix4x4::Make_Identity() from WWMath
   - Used in 8+ locations, including water rendering (W3DWater.cpp)
   - Critical for clipping matrix initialization

2. D3DXCreateFont - Stub for Disabled Tools
   - Only used in disabled Generals Tools (apt, w3dviewer)
   - Build preset RTS_BUILD_GENERALS_TOOLS=OFF by default
   - Returns D3DERR_NOTAVAILABLE to indicate unavailable functionality
   - Acceptable stub for out-of-scope build targets

Alternative approaches evaluated:
- Matrix4x4::Make_Identity() found in WWMath (used for implementation)
- No existing game font system suitable for D3DXCreateFont
- GDI CreateFont possible but unnecessary for disabled build

D3DXMatrixIdentity completes matrix math coverage alongside existing
D3DXMatrixMultiply, D3DXMatrixRotationZ, D3DXMatrixTranspose.
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

…structure (TheSuperHackers#2176)

Complete D3DX8 elimination for Zero Hour targets and enable the feature
for both Generals and Zero Hour. This turns on the D3DX-free build by
default, eliminating the d3dx8.dll dependency.

Changes:
- Add D3DXWrapper.h forced include to generalszh, worldbuilder_zh
- Enable MINGW_NO_D3DX option by default (header conflicts resolved)
- Add shader stub infrastructure (scripts/shaders/water_shader2.psh, water_shader3.psh)
- Expand D3DXCompat.h with shader function stubs

Build status:
- generalsv.exe: 12M, NO d3dx8.dll dependency
- generalszh.exe: 13M, NO d3dx8.dll dependency

D3DX8 elimination complete for MinGW builds.

D3DXAssembleShader implementation completed in next commit.
…eSuperHackers#2176)

Replace D3DXAssembleShader with precompiled bytecode lookup for water
shaders. This eliminates the shader compilation dependency.

Implementation approach:
- Extract 3 shader bytecodes from d3dx8.dll using Wine debugging
- Match shader source strings to identify which shader to return
- Create ID3DXBuffer wrapper class for bytecode storage

Shaders implemented:
1. River water shader (scripts/shaders/water_shader1.psh - co-issued instructions, +mul opcode)
2. Environment mapping water (scripts/shaders/water_shader2.psh - texbem bump environment mapping)
3. Trapezoid water (scripts/shaders/water_shader3.psh - mad multiply-add)

Total shader bytecode: ~450 bytes for all 3 shaders combined.

This completes D3DX8 elimination for MinGW builds. All D3DX functions
used by the game now have replacements or acceptable stubs.
TheSuperHackers#2176)

Implement surface copying using D3D8's native IDirect3DDevice8::CopyRects
instead of Wine/d3dx8.dll. This provides hardware-accelerated surface copying
using Direct3D 8 API directly.

Implementation:
- Call pSrcSurface->GetDevice() to obtain D3D8 device
- Use device->CopyRects() for hardware-accelerated copy
- Same API as DX8Wrapper::_Copy_DX8_Rects (14 uses in codebase)
- No Wine code needed - pure D3D8 API

Why Direct D3D8 instead of Wine:
- CopyRects is native D3D8 functionality (no d3dx8.dll required)
- Avoids complex Wine texture locking/filtering code
- Game already uses this API extensively via DX8Wrapper
- Hardware-accelerated, same performance as existing code

Function now fully implemented with working surface copy.
…Hackers#2176)

Implement D3DXMatrixIdentity using WWMath and stub D3DXCreateFont for
disabled Generals Tools build.

1. D3DXMatrixIdentity - Full Implementation
   - Maps to Matrix4x4::Make_Identity() from WWMath
   - Used in 8+ locations, including water rendering (W3DWater.cpp)
   - Critical for clipping matrix initialization

2. D3DXCreateFont - Stub for Disabled Tools
   - Only used in disabled Generals Tools (apt, w3dviewer)
   - Build preset RTS_BUILD_GENERALS_TOOLS=OFF by default
   - Returns D3DERR_NOTAVAILABLE to indicate unavailable functionality
   - Acceptable stub for out-of-scope build targets

Alternative approaches evaluated:
- Matrix4x4::Make_Identity() found in WWMath (used for implementation)
- No existing game font system suitable for D3DXCreateFont
- GDI CreateFont possible but unnecessary for disabled build

D3DXMatrixIdentity completes matrix math coverage alongside existing
D3DXMatrixMultiply, D3DXMatrixRotationZ, D3DXMatrixTranspose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants