perf(d3d): enable PUREDEVICE and remove unused mixed vertex processing#2438
perf(d3d): enable PUREDEVICE and remove unused mixed vertex processing#2438githubawn wants to merge 1 commit intoTheSuperHackers:mainfrom
Conversation
|
| Filename | Overview |
|---|---|
| GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp | Core PUREDEVICE enablement: switches vertex processing from MIXED to HARDWARE, enables D3DCREATE_PUREDEVICE when caps allow, and seeds the render state cache with correct D3D defaults for D3DRS_COLORWRITEENABLE and D3DRS_CULLMODE. Minor ternary continuation indentation inconsistency. |
| Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp | Same PUREDEVICE enablement as the GeneralsMD counterpart, with the same ternary continuation indentation issue. |
| Core/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp | Migrates D3DRS_CULLMODE save/restore to the cached wrapper API, but leaves numerous direct _Get_D3D_Device8()->SetPixelShader() and SetTexture() calls unchanged. These bypass the DX8Wrapper cache and create state-coherency hazards now that PUREDEVICE is active and GetPixelShader/GetTexture can no longer be used to resync. |
| Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp | Comprehensive replacement of all direct _Get_D3D_Device8()->SetTexture() and SetPixelShader() calls with their DX8Wrapper cached equivalents. Also removes an unused hr variable. Changes are mechanical and correct. |
| Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp | Replaces direct GetRenderState(D3DRS_COLORWRITEENABLE) call with Get_DX8_Render_State(), correctly using the seeded cache value instead of querying the pure device. |
| GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp | Same D3DRS_COLORWRITEENABLE save fix as Generals counterpart. |
| Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp | Replaces direct GetRenderState(D3DRS_COLORWRITEENABLE) with the cached wrapper, consistent with PUREDEVICE requirements. |
| GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp | Same D3DRS_COLORWRITEENABLE fix as Generals counterpart. |
Sequence Diagram
sequenceDiagram
participant App
participant DX8Wrapper
participant D3DDevice
Note over DX8Wrapper: Invalidate_Cached_Render_States()<br/>Seeds COLORWRITEENABLE=0xF<br/>Seeds CULLMODE=D3DCULL_CCW
App->>DX8Wrapper: Create_Device()
DX8Wrapper->>D3DDevice: CreateDevice(HARDWARE_VP | PUREDEVICE)
D3DDevice-->>DX8Wrapper: IDirect3DDevice8*
Note over App,D3DDevice: Rendering – PUREDEVICE path
App->>DX8Wrapper: Get_DX8_Render_State(CULLMODE)
DX8Wrapper-->>App: returns RenderStates[CULLMODE] (cache only)
App->>DX8Wrapper: Set_DX8_Render_State(CULLMODE, NONE)
DX8Wrapper->>D3DDevice: SetRenderState(CULLMODE, NONE)
App->>DX8Wrapper: Set_DX8_Texture(stage, tex)
DX8Wrapper->>D3DDevice: SetTexture(stage, tex)
App->>DX8Wrapper: Set_Pixel_Shader(shader)
DX8Wrapper->>D3DDevice: SetPixelShader(shader)
App->>DX8Wrapper: Set_DX8_Render_State(CULLMODE, saved)
DX8Wrapper->>D3DDevice: SetRenderState(CULLMODE, saved)
Note over App,D3DDevice: ⚠️ W3DWater.cpp bypasses wrapper
App->>D3DDevice: _Get_D3D_Device8()->SetPixelShader(0)
Note over DX8Wrapper: Pixel_Shader cache now stale!
Comments Outside Diff (1)
-
Core/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp, line 2892 (link)Direct SetPixelShader calls stale the wrapper cache
With
D3DCREATE_PUREDEVICEnow enabled by this PR, theDX8Wrapper's internalPixel_Shadercache is the sole authoritative source for the current pixel shader state (sinceGetPixelShaderon a pure device is prohibited and returns garbage). However, this line (and others below at lines 2904 and 3300, and thedrawTrapezoidWaterpath at lines 265, 2431, 3022) callSetPixelShaderdirectly on the device, bypassing theDX8Wrapper::Set_Pixel_Shaderwrapper and its cache.This creates a concrete cache-coherency hazard:
- The wrapper has previously called
Set_Pixel_Shader(X), soPixel_Shader == X. - This line directly sets the device to
m_riverWaterPixelShader, then line 2904 sets it to0— both without updating the cache. - At some later point,
Set_Pixel_Shader(X)is called again; because the cache already recordsX, the wrapper elides theSetPixelShader(X)call to the device — but the device is actually at0. The wrong shader remains active.
The original code comment (
// enable this when all 'get' dx calls are removed KJM) specifically gated the pure-device path on eliminating all state-read calls. Now that PUREDEVICE is live, these stale-write calls inW3DWater.cppshould be migrated toDX8Wrapper::Set_Pixel_ShaderandDX8Wrapper::Set_DX8_Textureto keep the cache consistent. - The wrapper has previously called
Last reviewed commit: 1fbb3c0
5d1f618 to
b75c140
Compare
b75c140 to
1fbb3c0
Compare
|
|
bigger and more changes than i expected, closing draft for now |
|
It might be easier to look at enabling Hardware vertex shading before trying a pure device mode, you have to be more careful when using a pure device in how you handle the hardware. |
This PR optimizes the D3D8 renderer by enabling Pure Device and switching from Mixed Vertex Processing to a hardware-only path. These changes reduce CPU overhead and improve frame stability, particularly in translation layers.