Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_info/info_stats.c
| Show First 20 Lines • Show All 541 Lines • ▼ Show 20 Lines | *ofs += BLI_snprintf(info + *ofs, | ||||
| stats_fmt->totface, | stats_fmt->totface, | ||||
| stats_fmt->tottri); | stats_fmt->tottri); | ||||
| } | } | ||||
| *ofs += BLI_snprintf( | *ofs += BLI_snprintf( | ||||
| info + *ofs, len - *ofs, TIP_(" | Objects:%s/%s"), stats_fmt->totobjsel, stats_fmt->totobj); | info + *ofs, len - *ofs, TIP_(" | Objects:%s/%s"), stats_fmt->totobjsel, stats_fmt->totobj); | ||||
| } | } | ||||
| const char *ED_info_statusbar_string(Main *bmain, bScreen *screen, bContext *C) | static const char *info_statusbar_string( | ||||
| Main *bmain, bScreen *screen, Scene *scene, ViewLayer *view_layer, char statusbar_flag) | |||||
| { | { | ||||
| char formatted_mem[15]; | char formatted_mem[15]; | ||||
| size_t ofs = 0; | size_t ofs = 0; | ||||
| char *info = screen->statusbar_info; | char *info = screen->statusbar_info; | ||||
| int len = sizeof(screen->statusbar_info); | int len = sizeof(screen->statusbar_info); | ||||
Severin: I'm not entirely sure how BPY handles strings as return values of RNA functions.
Should it just… | |||||
Done Inline ActionsIn practice I haven't found this to be an issue. The buffer is reused but I guess it's just filled properly right after. Adding the buffer back to view layers would be sort of unfortunate in my opinion. This is really a terrible interface for getting these statistics. Even though we're restoring it now, I think we should remove it and provide a better alternative in the future. HooglyBoogly: In practice I haven't found this to be an issue. The buffer is reused but I guess it's just… | |||||
Not Done Inline ActionsI checked the BPY/RNA code, and it seems we always copy the buffer into the Python string. In that case we don't need to store a buffer in DNA at all and just have a static one instead. So we can avoid the 256 bytes for every screen. Severin: I checked the BPY/RNA code, and it seems we always copy the buffer into the Python string. In… | |||||
| info[0] = '\0'; | info[0] = '\0'; | ||||
| /* Scene statistics. */ | /* Scene statistics. */ | ||||
| if (U.statusbar_flag & STATUSBAR_SHOW_STATS) { | if (statusbar_flag & STATUSBAR_SHOW_STATS) { | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | |||||
| Scene *scene = CTX_data_scene(C); | |||||
| SceneStatsFmt stats_fmt; | SceneStatsFmt stats_fmt; | ||||
| if (format_stats(bmain, scene, view_layer, &stats_fmt)) { | if (format_stats(bmain, scene, view_layer, &stats_fmt)) { | ||||
| get_stats_string(info + ofs, len, &ofs, view_layer, &stats_fmt); | get_stats_string(info + ofs, len, &ofs, view_layer, &stats_fmt); | ||||
| } | } | ||||
| } | } | ||||
| /* Memory status. */ | /* Memory status. */ | ||||
| if (U.statusbar_flag & STATUSBAR_SHOW_MEMORY) { | if (statusbar_flag & STATUSBAR_SHOW_MEMORY) { | ||||
| if (info[0]) { | if (info[0]) { | ||||
| ofs += BLI_snprintf(info + ofs, len - ofs, " | "); | ofs += BLI_snprintf(info + ofs, len - ofs, " | "); | ||||
| } | } | ||||
| uintptr_t mem_in_use = MEM_get_memory_in_use(); | uintptr_t mem_in_use = MEM_get_memory_in_use(); | ||||
| BLI_str_format_byte_unit(formatted_mem, mem_in_use, false); | BLI_str_format_byte_unit(formatted_mem, mem_in_use, false); | ||||
| ofs += BLI_snprintf(info + ofs, len, TIP_("Memory: %s"), formatted_mem); | ofs += BLI_snprintf(info + ofs, len, TIP_("Memory: %s"), formatted_mem); | ||||
| } | } | ||||
| /* GPU VRAM status. */ | /* GPU VRAM status. */ | ||||
| if ((U.statusbar_flag & STATUSBAR_SHOW_VRAM) && (GPU_mem_stats_supported())) { | if ((statusbar_flag & STATUSBAR_SHOW_VRAM) && (GPU_mem_stats_supported())) { | ||||
| int gpu_free_mem_kb, gpu_tot_mem_kb; | int gpu_free_mem_kb, gpu_tot_mem_kb; | ||||
| GPU_mem_stats_get(&gpu_tot_mem_kb, &gpu_free_mem_kb); | GPU_mem_stats_get(&gpu_tot_mem_kb, &gpu_free_mem_kb); | ||||
| float gpu_total_gb = gpu_tot_mem_kb / 1048576.0f; | float gpu_total_gb = gpu_tot_mem_kb / 1048576.0f; | ||||
| float gpu_free_gb = gpu_free_mem_kb / 1048576.0f; | float gpu_free_gb = gpu_free_mem_kb / 1048576.0f; | ||||
| if (info[0]) { | if (info[0]) { | ||||
| ofs += BLI_snprintf(info + ofs, len - ofs, " | "); | ofs += BLI_snprintf(info + ofs, len - ofs, " | "); | ||||
| } | } | ||||
| if (gpu_free_mem_kb && gpu_tot_mem_kb) { | if (gpu_free_mem_kb && gpu_tot_mem_kb) { | ||||
| ofs += BLI_snprintf(info + ofs, | ofs += BLI_snprintf(info + ofs, | ||||
| len - ofs, | len - ofs, | ||||
| TIP_("VRAM: %.1f/%.1f GiB"), | TIP_("VRAM: %.1f/%.1f GiB"), | ||||
| gpu_total_gb - gpu_free_gb, | gpu_total_gb - gpu_free_gb, | ||||
| gpu_total_gb); | gpu_total_gb); | ||||
| } | } | ||||
| else { | else { | ||||
| /* Can only show amount of GPU VRAM available. */ | /* Can only show amount of GPU VRAM available. */ | ||||
| ofs += BLI_snprintf(info + ofs, len - ofs, TIP_("VRAM: %.1f GiB Free"), gpu_free_gb); | ofs += BLI_snprintf(info + ofs, len - ofs, TIP_("VRAM: %.1f GiB Free"), gpu_free_gb); | ||||
| } | } | ||||
| } | } | ||||
| /* Blender version. */ | /* Blender version. */ | ||||
| if (U.statusbar_flag & STATUSBAR_SHOW_VERSION) { | if (statusbar_flag & STATUSBAR_SHOW_VERSION) { | ||||
| if (info[0]) { | if (info[0]) { | ||||
| ofs += BLI_snprintf(info + ofs, len - ofs, " | "); | ofs += BLI_snprintf(info + ofs, len - ofs, " | "); | ||||
| } | } | ||||
| ofs += BLI_snprintf(info + ofs, len - ofs, TIP_("%s"), BKE_blender_version_string()); | ofs += BLI_snprintf(info + ofs, len - ofs, TIP_("%s"), BKE_blender_version_string()); | ||||
| } | } | ||||
| return info; | return info; | ||||
| } | } | ||||
| const char *ED_info_statusbar_string(Main *bmain, bScreen *screen, bContext *C) | |||||
| { | |||||
| return info_statusbar_string( | |||||
| bmain, screen, CTX_data_scene(C), CTX_data_view_layer(C), U.statusbar_flag); | |||||
| } | |||||
| const char *ED_info_statistics_string( | |||||
| Main *bmain, bScreen *screen, Scene *scene, ViewLayer *view_layer, char statusbar_flag) | |||||
| { | |||||
| return info_statusbar_string(bmain, screen, scene, view_layer, statusbar_flag); | |||||
| } | |||||
| static void stats_row(int col1, | static void stats_row(int col1, | ||||
| const char *key, | const char *key, | ||||
| int col2, | int col2, | ||||
| const char *value1, | const char *value1, | ||||
| const char *value2, | const char *value2, | ||||
| int *y, | int *y, | ||||
| int height) | int height) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 106 Lines • Show Last 20 Lines | |||||
I'm not entirely sure how BPY handles strings as return values of RNA functions.
Should it just wrap the char * and not create a copy, the way this is done here is problematic.
E.g. calling the screen level function with U.statusbar_flag = 0 and then calling it on the scene level would cause the result of the former to change, because both share the same buffer.
Maybe the buffer gets copied and it's not an issue. If it is, we should add a buffer back to the view layer.