Skip to content

Commit 1e5b86a

Browse files
committed
Eliminated one frame memory copy and one clear frame operation in rendering chain, 20-70% higher framerate
1 parent 5a406b3 commit 1e5b86a

File tree

8 files changed

+30
-19
lines changed

8 files changed

+30
-19
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ The fastest and most memory efficient lattice Boltzmann CFD software, running on
137137
- fixed compiler warnings on Android
138138
- fixed `make.sh` failing on some systems due to nonstandard interpreter path
139139
- fixed that `make` would not compile with multiple cores on some systems
140+
- [v2.15](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.15) (09.04.2024) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.14...v2.15) (framerate boost)
141+
- eliminated one frame memory copy and one clear frame operation in rendering chain, for 20-70% higher framerate on both Windows and Linux
142+
- enabled `g++` compiler optimizations for faster startup and higher rendering framerate
143+
- fixed bug in multithreaded sanity checks
144+
- fixed wrong unit conversion for thermal expansion coefficient
145+
- fixed density to pressure conversion in LBM units
146+
- fixed bug that raytracing kernel could lock up simulation
147+
- fixed minor visual artifacts with raytracing
148+
- fixed that console sometimes was not cleared before `INTERACTIVE_GRAPHICS_ASCII` rendering starts
140149

141150
</details>
142151

src/graphics.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ void draw_line_label(const int x0, const int y0, const int x1, const int y1, con
335335
}
336336
}
337337
}
338-
void draw_bitmap(const int* bitmap) {
339-
std::copy(bitmap, bitmap+(int)camera.width*(int)camera.height, camera.bitmap);
338+
void draw_bitmap(int* bitmap) {
339+
std::swap(camera.bitmap, bitmap); // swap pointers instead of memory copy
340340
}
341341

342342
void draw_pixel(const float3& p, const int color) {
@@ -471,7 +471,7 @@ void update_frame(const double frametime) {
471471
main_label(frametime);
472472
SetBitmapBits(frameDC, 4*(int)camera.width*(int)camera.height, camera.bitmap);
473473
BitBlt(displayDC, 0, 0, (int)camera.width, (int)camera.height, memDC, 0, 0, SRCCOPY); // copy back buffer to front buffer
474-
camera.clear_frame(); // clear frame
474+
//camera.clear_frame(); // clear frame
475475
}
476476
LRESULT CALLBACK WndProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam) {
477477
if(message==WM_DESTROY) {
@@ -618,10 +618,11 @@ int key_linux(const int keycode) {
618618
}
619619
void update_frame(const double frametime) {
620620
main_label(frametime);
621+
x11_image->data = (char*)camera.bitmap; // camera.bitmap pointer might have been changed, so update x11_image->data pointer here
621622
updating_frame = true;
622623
XPutImage(x11_display, x11_window, x11_gc, x11_image, 0, 0, 0, 0, camera.width, camera.height);
623624
updating_frame = false;
624-
camera.clear_frame(); // clear frame
625+
//camera.clear_frame(); // clear frame
625626
if(!camera.lockmouse) XWarpPointer(x11_display, x11_window, x11_window, 0, 0, camera.width, camera.height, camera.width/2, camera.height/2); // center cursor
626627
}
627628
void hide_cursor() {
@@ -766,7 +767,7 @@ void update_frame(const double frametime) {
766767
print_video_dither(&image, textwidth, textheight);
767768
print(alignr(textwidth, to_string(textwidth)+"x"+to_string(textheight)+" "+alignr(4, to_int(1.0/frametime))+"fps"));
768769
show_console_cursor(true);
769-
camera.clear_frame(); // clear frame
770+
//camera.clear_frame(); // clear frame
770771
}
771772
void input_detection() {
772773
while(running) {

src/graphics.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,8 @@ class Camera {
157157
if(!lockmouse) update_rotation(mouse_x, mouse_y);
158158
}
159159
void clear_frame() {
160-
for(uint i=0u; i<width*height; i++) {
161-
bitmap[i] = GRAPHICS_BACKGROUND_COLOR;
162-
zbuffer[i] = min_int;
163-
}
160+
std::fill(bitmap, bitmap+width*height, GRAPHICS_BACKGROUND_COLOR); // faster than "for(uint i=0u; i<width*height; i++) bitmap[i] = GRAPHICS_BACKGROUND_COLOR;"
161+
std::fill(zbuffer, zbuffer+width*height, min_int); // faster than "for(uint i=0u; i<width*height; i++) zbuffer[i] = min_int;"
164162
}
165163
float data(const uint i) const { // returns all camera data required for rendering
166164
switch(i) {
@@ -332,7 +330,7 @@ extern bool key_1, key_2, key_3, key_4, key_5, key_6, key_7, key_8, key_9, key_0
332330

333331
void set_light(const uint i, const float3& p);
334332

335-
void draw_bitmap(const int* bitmap);
333+
void draw_bitmap(int* bitmap);
336334
void draw_label(const int x, const int y, const string& s, const int color);
337335
void draw_line_label(const int x0, const int y0, const int x1, const int y1, const int color);
338336

src/info.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void Info::print_logo() const {
5555
print("| "); print("\\ \\ / /", c); print(" |\n");
5656
print("| "); print("\\ ' /", c); print(" |\n");
5757
print("| "); print("\\ /", c); print(" |\n");
58-
print("| "); print("\\ /", c); print(" FluidX3D Version 2.14 |\n");
58+
print("| "); print("\\ /", c); print(" FluidX3D Version 2.15 |\n");
5959
print("| "); print( "'", c); print(" Copyright (c) Dr. Moritz Lehmann |\n");
6060
print("|-----------------------------------------------------------------------------|\n");
6161
}
@@ -86,6 +86,7 @@ void Info::print_initialize() {
8686
println("| MLUPs | Bandwidth | Steps/s | Current Step | "+string(steps==max_ulong?"Elapsed Time ":"Time Remaining")+" |");
8787
#else // INTERACTIVE_GRAPHICS_ASCII
8888
println("'-----------------'-----------------------------------------------------------'");
89+
clear_console();
8990
#endif // INTERACTIVE_GRAPHICS_ASCII
9091
clock.start();
9192
allow_rendering = true;

src/info.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class LBM;
66
struct Info { // contains redundant information for console printing
77
LBM* lbm = nullptr;
88
bool allow_rendering = false; // allows interactive redering if true
9+
bool allow_labeling = true; // allows drawing label if true
910
double runtime_lbm=0.0, runtime_total=0.0f; // lbm (compute) and total (compute + rendering + data evaluation) runtime
1011
double runtime_lbm_timestep_last=1.0, runtime_lbm_timestep_smooth=1.0, runtime_lbm_last=0.0; // for printing simulation info
1112
Clock clock; // for measuring total runtime

src/lbm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ int* LBM::Graphics::draw_frame() {
11381138
#endif // GRAPHICS_TRANSPARENCY
11391139
}
11401140
}
1141+
info.allow_labeling = new_frame;
11411142
return bitmap;
11421143
}
11431144

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void draw_scale(const int field_mode, const int color) {
5656
draw_label(ox+min(0, w+7+label_length_max*(FONT_WIDTH)-(int)length(title)*(FONT_WIDTH)), oy-(FONT_HEIGHT)*3/2-6, title, color); // colorbar title
5757
}
5858
void main_label(const double frametime) {
59-
if(info.allow_rendering) {
59+
if(info.allow_rendering&&info.allow_labeling) {
6060
info.print_update();
6161
const int c = invert(GRAPHICS_BACKGROUND_COLOR);
6262
{
@@ -77,7 +77,7 @@ void main_label(const double frametime) {
7777
draw_label(ox, oy+i, "Steps " +alignr(31u, /************************************/ alignr(10u, info.lbm->get_t())+" ("+alignr(5, to_uint(1.0/info.runtime_lbm_timestep_smooth))+" Steps/s)"), c); i+=FONT_HEIGHT;
7878
draw_label(ox, oy+i, "FPS " +alignr(33u, /************************************************************/ alignr(4u, to_uint(1.0/frametime))+" ("+alignr(5u, camera.fps_limit)+" fps max)"), c);
7979
}
80-
draw_label(2, camera.height-1*(FONT_HEIGHT)-1, "FluidX3D v2.14 Copyright (c) Dr. Moritz Lehmann", c);
80+
draw_label(2, camera.height-1*(FONT_HEIGHT)-1, "FluidX3D v2.15 Copyright (c) Dr. Moritz Lehmann", c);
8181
if(!key_H) {
8282
draw_label(camera.width-16*(FONT_WIDTH)-1, 2, "Press H for Help", c);
8383
} else {

src/resource.rc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#include "winres.h"
33
#undef APSTUDIO_READONLY_SYMBOLS
44

5-
MAINICON ICON "src/icon.ico"
5+
MAINICON ICON "icon.ico"
66

77
VS_VERSION_INFO VERSIONINFO
8-
FILEVERSION 1,0,0,0
9-
PRODUCTVERSION 1,0,0,0
8+
FILEVERSION 0,0,0,0
9+
PRODUCTVERSION 0,0,0,0
1010
FILEFLAGSMASK 0x3FL
1111
FILEFLAGS 0x0L
1212
FILEOS 0x4L
@@ -19,12 +19,12 @@ BEGIN
1919
BEGIN
2020
VALUE "CompanyName", "ProjectPhysX"
2121
VALUE "FileDescription", "FluidX3D"
22-
VALUE "FileVersion", "1.0.0.0"
22+
VALUE "FileVersion", "0.0.0.0"
2323
VALUE "InternalName", "FluidX3D"
24-
VALUE "LegalCopyright", "(c) Moritz Lehmann"
24+
VALUE "LegalCopyright", "(c) Dr. Moritz Lehmann"
2525
VALUE "OriginalFilename", "FluidX3D.exe"
2626
VALUE "ProductName", "FluidX3D"
27-
VALUE "ProductVersion", "1.0"
27+
VALUE "ProductVersion", "v2.15"
2828
END
2929
END
3030
BLOCK "VarFileInfo"

0 commit comments

Comments
 (0)