-
Notifications
You must be signed in to change notification settings - Fork 151
perf(radar): Reduce cost of W3DRadar::renderObjectList (by 80%), W3DRadar::buildTerrainTexture (by 25%) and W3DRadar::clearShroud #2138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(radar): Reduce cost of W3DRadar::renderObjectList (by 80%), W3DRadar::buildTerrainTexture (by 25%) and W3DRadar::clearShroud #2138
Conversation
…adar::buildTerrainTexture (by 25%), W3DRadar::clearShroud by locking radar surface only once
|
| Filename | Overview |
|---|---|
| Core/Libraries/Source/WWVegas/WW3D2/surfaceclass.h | Added Get_Bytes_Per_Pixel() helper and updated Draw_Pixel, Draw_H_Line, Get_Pixel to accept pre-locked surface parameters for performance optimization |
| Core/Libraries/Source/WWVegas/WW3D2/surfaceclass.cpp | Refactored Draw_Pixel, Draw_H_Line, and Get_Pixel to use memcpy and accept locked surface pointers, eliminating repeated lock/unlock cycles |
| Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp | Optimized radar rendering by locking surfaces once per function (renderObjectList, buildTerrainTexture, clearShroud, refreshObjects, setShroudLevel) instead of per-pixel, achieving 80% and 25% performance improvements |
Sequence Diagram
sequenceDiagram
participant Radar as W3DRadar
participant Surface as SurfaceClass
participant D3D as Direct3D Surface
Note over Radar,D3D: Before Optimization (per-pixel locking)
Radar->>Surface: DrawPixel(x1, y1, color1)
Surface->>D3D: Lock()
D3D-->>Surface: pBits
Surface->>D3D: Write pixel
Surface->>D3D: Unlock()
Radar->>Surface: DrawPixel(x2, y2, color2)
Surface->>D3D: Lock()
D3D-->>Surface: pBits
Surface->>D3D: Write pixel
Surface->>D3D: Unlock()
Note over Radar,D3D: Repeated for each pixel (expensive)
Note over Radar,D3D: After Optimization (single lock per batch)
Radar->>Surface: Lock(&pitch)
Surface->>D3D: Lock()
D3D-->>Surface: pBits, pitch
Surface-->>Radar: pBits, pitch
Radar->>Surface: Get_Bytes_Per_Pixel()
Surface-->>Radar: bytesPerPixel
loop For each pixel
Radar->>Surface: Draw_Pixel(x, y, color, bytesPerPixel, pBits, pitch)
Surface->>Surface: memcpy to locked memory (no lock/unlock)
end
Radar->>Surface: Unlock()
Surface->>D3D: Unlock()
Note over Radar,D3D: 80% faster for renderObjectList
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5 files reviewed, 2 comments
|
Code LGTM, good find! I left some nits about commented out code, but looks good to go |
bobtista
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| * 1/10/2025 TheSuperHackers : Added bits and pitch to argument list for better performance * | ||
| *=============================================================================================*/ | ||
| void SurfaceClass::DrawPixel(const unsigned int x,const unsigned int y, unsigned int color) | ||
| void SurfaceClass::Draw_Pixel(const unsigned int x, const unsigned int y, unsigned int color, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to add a comment to these that the surface needs to be externally locked and unlocked before using this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm ok I can add it in the header file. I thought it was kind of implied by the new argument requirement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of comment, I added a typedef LockedSurfacePtr for the void pointer, which acts as a means to document the related types in this class.
This change reduces the cost of
W3DRadar::renderObjectListby around 80%, from 0.5 ms to 0.1 ms (tested with many radar objects)W3DRadar::buildTerrainTextureby around 25%, from 0.0127 ms to 0.0164 msW3DRadar::clearShroud- not measured because not importantThis is achieved by locking the radar surface only once instead of many times in loops.
W3DRadar::renderObjectListis called every 6 logic frames, and the jump from 0.5 ms to 0.1 ms is nice to improve overall performance (measured on modern machine).Functions
SurfaceClass::DrawPixelandSurfaceClass::DrawHLinewere renamed to better fit the WWVegas style.The
NULL's in W3DRadar were changed tonullptr, which was added by #2072.