Depsgraph: Add utility to stringify recalc flags

Allows to log human-readable list of recalc bits that are set.

The usage is pretty simple:

```
printf("%s: %s %s\n", __func__, id->name, DEG_stringify_recalc_flags(id->recalc).c_str());
```

Pull Request: https://projects.blender.org/blender/blender/pulls/137715
This commit is contained in:
Sergey Sharybin
2025-04-18 16:31:30 +02:00
committed by Sergey Sharybin
parent 8b3f49381a
commit e599a7525b
3 changed files with 47 additions and 27 deletions

View File

@@ -11,6 +11,7 @@
#pragma once
#include <cstdio>
#include <string>
#include "BLI_string_ref.hh"
@@ -65,3 +66,13 @@ bool DEG_debug_graph_relations_validate(Depsgraph *graph,
/** Perform consistency check on the graph. */
bool DEG_debug_consistency_check(Depsgraph *graph);
/** Convert bitflag representation of recalculation flags to string that consists of human-readable
* names of recalculation bits that are set in the given mask.
*
* If flags == 0 the result is "NONE".
*
* Example:
* DEG_stringify_recalc_flags(ID_RECALC_GEOMETRY | ID_RECALC_SHADING) -> "GEOMETRY, SHADING".
*/
std::string DEG_stringify_recalc_flags(unsigned int flags);

View File

@@ -24,6 +24,8 @@
#include "intern/node/deg_node_id.hh"
#include "intern/node/deg_node_time.hh"
#include "BLI_math_bits.h"
namespace deg = blender::deg;
void DEG_debug_flags_set(Depsgraph *depsgraph, int flags)
@@ -357,3 +359,36 @@ void DEG_debug_print_eval_time(Depsgraph *depsgraph,
time);
fflush(stdout);
}
static std::string stringify_append_bit(const std::string &str, IDRecalcFlag tag)
{
const char *tag_name = DEG_update_tag_as_string(tag);
if (tag_name == nullptr) {
return str;
}
std::string result = str;
if (!result.empty()) {
result += ", ";
}
result += tag_name;
return result;
}
std::string DEG_stringify_recalc_flags(uint flags)
{
if (flags == 0) {
return "NONE";
}
std::string result;
uint current_flag = flags;
/* Special cases to avoid ALL flags from being split into individual bits. */
if ((current_flag & ID_RECALC_PSYS_ALL) == ID_RECALC_PSYS_ALL) {
result = stringify_append_bit(result, ID_RECALC_PSYS_ALL);
}
/* Handle all the rest of the flags. */
while (current_flag != 0) {
IDRecalcFlag tag = (IDRecalcFlag)(1 << bitscan_forward_clear_uint(&current_flag));
result = stringify_append_bit(result, tag);
}
return result;
}

View File

@@ -401,38 +401,12 @@ void graph_id_tag_update_single_flag(Main *bmain,
deg_graph_id_tag_legacy_compat(bmain, graph, id, tag, update_source);
}
std::string stringify_append_bit(const std::string &str, IDRecalcFlag tag)
{
const char *tag_name = DEG_update_tag_as_string(tag);
if (tag_name == nullptr) {
return str;
}
std::string result = str;
if (!result.empty()) {
result += ", ";
}
result += tag_name;
return result;
}
std::string stringify_update_bitfield(uint flags)
{
if (flags == 0) {
return "LEGACY_0";
}
std::string result;
uint current_flag = flags;
/* Special cases to avoid ALL flags form being split into
* individual bits. */
if ((current_flag & ID_RECALC_PSYS_ALL) == ID_RECALC_PSYS_ALL) {
result = stringify_append_bit(result, ID_RECALC_PSYS_ALL);
}
/* Handle all the rest of the flags. */
while (current_flag != 0) {
IDRecalcFlag tag = (IDRecalcFlag)(1 << bitscan_forward_clear_uint(&current_flag));
result = stringify_append_bit(result, tag);
}
return result;
return DEG_stringify_recalc_flags(flags);
}
const char *update_source_as_string(eUpdateSource source)