VSE: Remove cost calculation from cache

This value was meant to be used for keeping images that are slowest to
render in cache. Method of measurement was flawed, because it doesn't
take UI overhead into consideration.

Cache panel is to be removed because users should not have to tweak
settings like this. It is not useful for development either, therefore
it is removed completely.
This commit is contained in:
Richard Antalik 2020-12-20 03:58:38 +01:00
parent c4ff91aab7
commit 38b77ef8b2
Notes: blender-bot 2024-03-25 12:30:38 +01:00
Referenced by commit acba8f617b, Cleanup: Remove unused define
11 changed files with 51 additions and 126 deletions

View File

@ -1891,8 +1891,6 @@ class SEQUENCER_PT_cache_settings(SequencerButtonsPanel, Panel):
col.prop(ed, "use_cache_preprocessed", text="Pre-Processed")
col.prop(ed, "use_cache_composite", text="Composite")
col.prop(ed, "use_cache_final", text="Final")
col.separator()
col.prop(ed, "recycle_max_cost")
class SEQUENCER_PT_proxy_settings(SequencerButtonsPanel, Panel):

View File

@ -2111,8 +2111,10 @@ static bool draw_cache_view_init_fn(void *userdata, size_t item_count)
}
/* Called as a callback */
static bool draw_cache_view_iter_fn(
void *userdata, struct Sequence *seq, int timeline_frame, int cache_type, float UNUSED(cost))
static bool draw_cache_view_iter_fn(void *userdata,
struct Sequence *seq,
int timeline_frame,
int cache_type)
{
CacheDrawData *drawdata = userdata;
struct View2D *v2d = drawdata->v2d;

View File

@ -278,7 +278,7 @@ typedef struct Editing {
struct SeqCache *cache;
/* Cache control */
float recycle_max_cost;
float recycle_max_cost; /* UNUSED only for versioning. */
int cache_flag;
struct PrefetchJob *prefetch_job;

View File

@ -2101,13 +2101,6 @@ static void rna_def_editor(BlenderRNA *brna)
"Prefetch Frames",
"Render frames ahead of current frame in the background for faster playback");
RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, NULL);
prop = RNA_def_property(srna, "recycle_max_cost", PROP_FLOAT, PROP_NONE);
RNA_def_property_range(prop, 0.0f, SEQ_CACHE_COST_MAX);
RNA_def_property_ui_range(prop, 0.0f, SEQ_CACHE_COST_MAX, 0.1f, 1);
RNA_def_property_float_sdna(prop, NULL, "recycle_max_cost");
RNA_def_property_ui_text(
prop, "Recycle Up to Cost", "Only frames with cost lower than this value will be recycled");
}
static void rna_def_filter_video(StructRNA *srna)

View File

@ -60,14 +60,11 @@ void SEQ_relations_check_uuids_unique_and_report(const struct Scene *scene);
void SEQ_relations_session_uuid_generate(struct Sequence *sequence);
void SEQ_cache_cleanup(struct Scene *scene);
void SEQ_cache_iterate(struct Scene *scene,
void *userdata,
bool callback_init(void *userdata, size_t item_count),
bool callback_iter(void *userdata,
struct Sequence *seq,
int timeline_frame,
int cache_type,
float cost));
void SEQ_cache_iterate(
struct Scene *scene,
void *userdata,
bool callback_init(void *userdata, size_t item_count),
bool callback_iter(void *userdata, struct Sequence *seq, int timeline_frame, int cache_type));
#ifdef __cplusplus
}
#endif

View File

@ -938,7 +938,6 @@ static SeqCacheKey *seq_cache_get_item_for_removal(Scene *scene)
GHashIterator gh_iter;
BLI_ghashIterator_init(&gh_iter, cache->hash);
int total_count = 0;
int cheap_count = 0;
while (!BLI_ghashIterator_done(&gh_iter)) {
key = BLI_ghashIterator_getKey(&gh_iter);
@ -959,25 +958,22 @@ static SeqCacheKey *seq_cache_get_item_for_removal(Scene *scene)
total_count++;
if (key->cost <= scene->ed->recycle_max_cost) {
cheap_count++;
if (lkey) {
if (key->timeline_frame < lkey->timeline_frame) {
lkey = key;
}
}
else {
if (lkey) {
if (key->timeline_frame < lkey->timeline_frame) {
lkey = key;
}
if (rkey) {
if (key->timeline_frame > rkey->timeline_frame) {
rkey = key;
}
}
else {
}
else {
lkey = key;
}
if (rkey) {
if (key->timeline_frame > rkey->timeline_frame) {
rkey = key;
}
}
else {
rkey = key;
}
}
finalkey = seq_cache_choose_key(scene, lkey, rkey);
@ -1281,10 +1277,10 @@ struct ImBuf *seq_cache_get(const SeqRenderData *context,
BLI_mutex_unlock(&cache->disk_cache->read_write_mutex);
if (ibuf) {
if (key.type == SEQ_CACHE_STORE_FINAL_OUT) {
seq_cache_put_if_possible(context, seq, timeline_frame, type, ibuf, 0.0f, true);
seq_cache_put_if_possible(context, seq, timeline_frame, type, ibuf, true);
}
else {
seq_cache_put(context, seq, timeline_frame, type, ibuf, 0.0f, true);
seq_cache_put(context, seq, timeline_frame, type, ibuf, true);
}
}
}
@ -1297,7 +1293,6 @@ bool seq_cache_put_if_possible(const SeqRenderData *context,
float timeline_frame,
int type,
ImBuf *ibuf,
float cost,
bool skip_disk_cache)
{
Scene *scene = context->scene;
@ -1313,7 +1308,7 @@ bool seq_cache_put_if_possible(const SeqRenderData *context,
}
if (seq_cache_recycle_item(scene)) {
seq_cache_put(context, seq, timeline_frame, type, ibuf, cost, skip_disk_cache);
seq_cache_put(context, seq, timeline_frame, type, ibuf, skip_disk_cache);
return true;
}
@ -1327,7 +1322,6 @@ void seq_cache_put(const SeqRenderData *context,
float timeline_frame,
int type,
ImBuf *i,
float cost,
bool skip_disk_cache)
{
if (i == NULL || context->skip_cache || context->is_proxy_render || !seq) {
@ -1370,10 +1364,6 @@ void seq_cache_put(const SeqRenderData *context,
flag = scene->ed->cache_flag;
}
if (cost > SEQ_CACHE_COST_MAX) {
cost = SEQ_CACHE_COST_MAX;
}
SeqCacheKey *key;
key = BLI_mempool_alloc(cache->keys_pool);
key->cache_owner = cache;
@ -1382,7 +1372,6 @@ void seq_cache_put(const SeqRenderData *context,
key->frame_index = seq_cache_timeline_frame_to_frame_index(seq, timeline_frame, type);
key->timeline_frame = timeline_frame;
key->type = type;
key->cost = cost;
key->link_prev = NULL;
key->link_next = NULL;
key->is_temp_cache = true;
@ -1430,14 +1419,11 @@ void seq_cache_put(const SeqRenderData *context,
}
}
void SEQ_cache_iterate(struct Scene *scene,
void *userdata,
bool callback_init(void *userdata, size_t item_count),
bool callback_iter(void *userdata,
struct Sequence *seq,
int timeline_frame,
int cache_type,
float cost))
void SEQ_cache_iterate(
struct Scene *scene,
void *userdata,
bool callback_init(void *userdata, size_t item_count),
bool callback_iter(void *userdata, struct Sequence *seq, int timeline_frame, int cache_type))
{
SeqCache *cache = seq_cache_get_from_scene(scene);
if (!cache) {
@ -1454,7 +1440,7 @@ void SEQ_cache_iterate(struct Scene *scene,
SeqCacheKey *key = BLI_ghashIterator_getKey(&gh_iter);
BLI_ghashIterator_step(&gh_iter);
interrupt = callback_iter(userdata, key->seq, key->timeline_frame, key->type, key->cost);
interrupt = callback_iter(userdata, key->seq, key->timeline_frame, key->type);
}
cache->last_key = NULL;

View File

@ -47,14 +47,12 @@ void seq_cache_put(const struct SeqRenderData *context,
float timeline_frame,
int type,
struct ImBuf *i,
float cost,
bool skip_disk_cache);
bool seq_cache_put_if_possible(const struct SeqRenderData *context,
struct Sequence *seq,
float timeline_frame,
int type,
struct ImBuf *nval,
float cost,
bool skip_disk_cache);
bool seq_cache_recycle_item(struct Scene *scene);
void seq_cache_free_temp_cache(struct Scene *scene, short id, int timeline_frame);

View File

@ -178,7 +178,7 @@ static bool seq_prefetch_is_cache_full(Scene *scene)
{
PrefetchJob *pfjob = seq_prefetch_job_get(scene);
if (!seq_cache_is_full(pfjob->scene)) {
if (!seq_cache_is_full()) {
return false;
}
@ -528,7 +528,7 @@ static PrefetchJob *seq_prefetch_start_ex(const SeqRenderData *context, float cf
}
/* Start or resume prefetching*/
void seq_prefetch_start(const SeqRenderData *context, float timeline_frame, float cost)
void seq_prefetch_start(const SeqRenderData *context, float timeline_frame)
{
Scene *scene = context->scene;
Editing *ed = scene->ed;
@ -540,13 +540,12 @@ void seq_prefetch_start(const SeqRenderData *context, float timeline_frame, floa
bool running = seq_prefetch_job_is_running(scene);
seq_prefetch_resume(scene);
/* conditions to start:
* prefetch enabled, prefetch not running, not scrubbing,
* not playing and rendering-expensive footage, cache storage enabled, has strips to render,
* not rendering, not doing modal transform - important, see D7820.
* prefetch enabled, prefetch not running, not scrubbing, not playing,
* cache storage enabled, has strips to render, not rendering, not doing modal transform -
* important, see D7820.
*/
if ((ed->cache_flag & SEQ_CACHE_PREFETCH_ENABLE) && !running && !scrubbing &&
!(playing && cost > 0.9) && ed->cache_flag & SEQ_CACHE_ALL_TYPES && has_strips &&
!G.is_rendering && !G.moving) {
if ((ed->cache_flag & SEQ_CACHE_PREFETCH_ENABLE) && !running && !scrubbing && !playing &&
ed->cache_flag & SEQ_CACHE_ALL_TYPES && has_strips && !G.is_rendering && !G.moving) {
seq_prefetch_start_ex(context, timeline_frame);
}

View File

@ -35,7 +35,7 @@ struct Sequence;
}
#endif
void seq_prefetch_start(const struct SeqRenderData *context, float timeline_frame, float cost);
void seq_prefetch_start(const struct SeqRenderData *context, float timeline_frame);
void seq_prefetch_free(struct Scene *scene);
bool seq_prefetch_job_is_running(struct Scene *scene);
void seq_prefetch_get_time_range(struct Scene *scene, int *start, int *end);

View File

@ -403,24 +403,6 @@ int seq_get_shown_sequences(ListBase *seqbasep,
return cnt;
}
/* Estimate time spent by the program rendering the strip */
static clock_t seq_estimate_render_cost_begin(void)
{
return clock();
}
static float seq_estimate_render_cost_end(Scene *scene, clock_t begin)
{
clock_t end = clock();
float time_spent = (float)(end - begin);
float time_max = (1.0f / scene->r.frs_sec) * CLOCKS_PER_SEC;
if (time_max != 0) {
return time_spent / time_max;
}
return 1;
}
/** \} */
/* -------------------------------------------------------------------- */
@ -738,7 +720,6 @@ static ImBuf *seq_render_preprocess_ibuf(const SeqRenderData *context,
Sequence *seq,
ImBuf *ibuf,
float timeline_frame,
clock_t begin,
bool use_preprocess,
const bool is_proxy_image)
{
@ -748,20 +729,15 @@ static ImBuf *seq_render_preprocess_ibuf(const SeqRenderData *context,
}
if (use_preprocess) {
float cost = seq_estimate_render_cost_end(context->scene, begin);
/* Proxies are not stored in cache. */
if (!is_proxy_image) {
seq_cache_put(context, seq, timeline_frame, SEQ_CACHE_STORE_RAW, ibuf, cost, false);
seq_cache_put(context, seq, timeline_frame, SEQ_CACHE_STORE_RAW, ibuf, false);
}
/* Reset timer so we can get partial render time. */
begin = seq_estimate_render_cost_begin();
ibuf = input_preprocess(context, seq, timeline_frame, ibuf);
}
float cost = seq_estimate_render_cost_end(context->scene, begin);
seq_cache_put(context, seq, timeline_frame, SEQ_CACHE_STORE_PREPROCESSED, ibuf, cost, false);
seq_cache_put(context, seq, timeline_frame, SEQ_CACHE_STORE_PREPROCESSED, ibuf, false);
return ibuf;
}
@ -1073,7 +1049,7 @@ static ImBuf *seq_render_image_strip(const SeqRenderData *context,
if (view_id != context->view_id) {
ibufs_arr[view_id] = seq_render_preprocess_ibuf(
&localcontext, seq, ibufs_arr[view_id], timeline_frame, clock(), true, false);
&localcontext, seq, ibufs_arr[view_id], timeline_frame, true, false);
}
}
@ -1223,7 +1199,7 @@ static ImBuf *seq_render_movie_strip(const SeqRenderData *context,
if (view_id != context->view_id) {
ibuf_arr[view_id] = seq_render_preprocess_ibuf(
&localcontext, seq, ibuf_arr[view_id], timeline_frame, clock(), true, false);
&localcontext, seq, ibuf_arr[view_id], timeline_frame, true, false);
}
}
@ -1630,7 +1606,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context,
if (view_id != context->view_id) {
seq_cache_put(
&localcontext, seq, timeline_frame, SEQ_CACHE_STORE_RAW, ibufs_arr[view_id], 0, false);
&localcontext, seq, timeline_frame, SEQ_CACHE_STORE_RAW, ibufs_arr[view_id], false);
}
RE_ReleaseResultImage(re);
@ -1805,8 +1781,6 @@ ImBuf *seq_render_strip(const SeqRenderData *context,
bool use_preprocess = false;
bool is_proxy_image = false;
clock_t begin = seq_estimate_render_cost_begin();
ibuf = seq_cache_get(context, seq, timeline_frame, SEQ_CACHE_STORE_PREPROCESSED, false);
if (ibuf != NULL) {
return ibuf;
@ -1824,7 +1798,7 @@ ImBuf *seq_render_strip(const SeqRenderData *context,
if (ibuf) {
use_preprocess = seq_input_have_to_preprocess(context, seq, timeline_frame);
ibuf = seq_render_preprocess_ibuf(
context, seq, ibuf, timeline_frame, begin, use_preprocess, is_proxy_image);
context, seq, ibuf, timeline_frame, use_preprocess, is_proxy_image);
}
if (ibuf == NULL) {
@ -1910,7 +1884,6 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context,
int count;
int i;
ImBuf *out = NULL;
clock_t begin;
count = seq_get_shown_sequences(seqbasep, timeline_frame, chanshown, (Sequence **)&seq_arr);
@ -1946,16 +1919,13 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context,
break;
case EARLY_DO_EFFECT:
if (i == 0) {
begin = seq_estimate_render_cost_begin();
ImBuf *ibuf1 = IMB_allocImBuf(context->rectx, context->recty, 32, IB_rect);
ImBuf *ibuf2 = seq_render_strip(context, state, seq, timeline_frame);
out = seq_render_strip_stack_apply_effect(context, seq, timeline_frame, ibuf1, ibuf2);
float cost = seq_estimate_render_cost_end(context->scene, begin);
seq_cache_put(
context, seq_arr[i], timeline_frame, SEQ_CACHE_STORE_COMPOSITE, out, cost, false);
context, seq_arr[i], timeline_frame, SEQ_CACHE_STORE_COMPOSITE, out, false);
IMB_freeImBuf(ibuf1);
IMB_freeImBuf(ibuf2);
@ -1969,7 +1939,6 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context,
i++;
for (; i < count; i++) {
begin = seq_estimate_render_cost_begin();
Sequence *seq = seq_arr[i];
if (seq_get_early_out_for_blend_mode(seq) == EARLY_DO_EFFECT) {
@ -1982,9 +1951,7 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context,
IMB_freeImBuf(ibuf2);
}
float cost = seq_estimate_render_cost_end(context->scene, begin);
seq_cache_put(
context, seq_arr[i], timeline_frame, SEQ_CACHE_STORE_COMPOSITE, out, cost, false);
seq_cache_put(context, seq_arr[i], timeline_frame, SEQ_CACHE_STORE_COMPOSITE, out, false);
}
return out;
@ -2029,36 +1996,22 @@ ImBuf *SEQ_render_give_ibuf(const SeqRenderData *context, float timeline_frame,
seq_cache_free_temp_cache(context->scene, context->task_id, timeline_frame);
clock_t begin = seq_estimate_render_cost_begin();
float cost = 0;
if (count && !out) {
BLI_mutex_lock(&seq_render_mutex);
out = seq_render_strip_stack(context, &state, seqbasep, timeline_frame, chanshown);
cost = seq_estimate_render_cost_end(context->scene, begin);
if (context->is_prefetch_render) {
seq_cache_put(context,
seq_arr[count - 1],
timeline_frame,
SEQ_CACHE_STORE_FINAL_OUT,
out,
cost,
false);
seq_cache_put(
context, seq_arr[count - 1], timeline_frame, SEQ_CACHE_STORE_FINAL_OUT, out, false);
}
else {
seq_cache_put_if_possible(context,
seq_arr[count - 1],
timeline_frame,
SEQ_CACHE_STORE_FINAL_OUT,
out,
cost,
false);
seq_cache_put_if_possible(
context, seq_arr[count - 1], timeline_frame, SEQ_CACHE_STORE_FINAL_OUT, out, false);
}
BLI_mutex_unlock(&seq_render_mutex);
}
seq_prefetch_start(context, timeline_frame, cost);
seq_prefetch_start(context, timeline_frame);
return out;
}

View File

@ -249,7 +249,6 @@ Editing *SEQ_editing_ensure(Scene *scene)
ed->cache_flag = SEQ_CACHE_STORE_FINAL_OUT;
ed->cache_flag |= SEQ_CACHE_VIEW_FINAL_OUT;
ed->cache_flag |= SEQ_CACHE_VIEW_ENABLE;
ed->recycle_max_cost = 10.0f;
}
return scene->ed;