Skip to content

Commit

Permalink
renderer: add pl_renderer_get_errors
Browse files Browse the repository at this point in the history
This provides feedback about renderer state.
  • Loading branch information
kasper93 authored and haasn committed Feb 19, 2023
1 parent 8c00fd1 commit 0115d7c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 15 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ project('libplacebo', ['c', 'cpp'],
5,
# API version
{
'249': 'add `pl_render_error`, `pl_render_errors` and `pl_renderer_get_errors`',
'248': 'add pl_hook.signature',
'247': 'add pl_color_map_params.visualize_lut',
'246': 'add `pl_tone_map_st2094_10` and `pl_tone_map_st2094_40`',
Expand Down
35 changes: 35 additions & 0 deletions src/include/libplacebo/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ PL_API_BEGIN
// Thread-safety: Unsafe
typedef struct pl_renderer_t *pl_renderer;

// Enum values used in pl_renderer_errors_t as a bit positions for error flags
enum pl_render_error {
PL_RENDER_ERR_NONE = 0,
PL_RENDER_ERR_FBO = 1 << 0,
PL_RENDER_ERR_SAMPLING = 1 << 1,
PL_RENDER_ERR_DEBANDING = 1 << 2,
PL_RENDER_ERR_BLENDING = 1 << 3,
PL_RENDER_ERR_OVERLAY = 1 << 4,
PL_RENDER_ERR_PEAK_DETECT = 1 << 5,
PL_RENDER_ERR_FILM_GRAIN = 1 << 6,
PL_RENDER_ERR_FRAME_MIXING = 1 << 7,
PL_RENDER_ERR_DEINTERLACING = 1 << 8,
PL_RENDER_ERR_ERROR_DIFFUSION = 1 << 9,
PL_RENDER_ERR_HOOKS = 1 << 10,
};

// Struct describing current renderer state, including internal processing errors,
// as well as list of signatures of disabled hooks.
struct pl_render_errors {
enum pl_render_error errors;
// List containing signatures of disabled hooks
const uint64_t *disabled_hooks;
int num_disabled_hooks;
};

// Creates a new renderer object, which is backed by a GPU context. This is a
// high-level object that takes care of the rendering chain as a whole, from
// the source textures to the finished frame.
Expand All @@ -54,6 +79,16 @@ size_t pl_renderer_save(pl_renderer rr, uint8_t *out_cache);
// Note: See the security warnings on `pl_pass_params.cached_program`.
void pl_renderer_load(pl_renderer rr, const uint8_t *cache);

// Returns current renderer state, see pl_render_errors.
struct pl_render_errors pl_renderer_get_errors(pl_renderer rr);

// Clears errors state of renderer. If `errors` is NULL, all render errors will
// be cleared. Otherwise only selected errors/hooks will be cleared.
// If `PL_RENDER_ERR_HOOKS` is set and `num_disabled_hooks` is 0, clear all hooks.
// Otherwise only selected hooks will be cleard based on `disabled_hooks` array.
void pl_renderer_reset_errors(pl_renderer rr,
const struct pl_render_errors *errors);

enum pl_lut_type {
PL_LUT_UNKNOWN = 0,
PL_LUT_NATIVE, // applied to raw image contents (after fixing bit depth)
Expand Down
69 changes: 54 additions & 15 deletions src/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,6 @@ struct icc_state {
bool error;
};

enum pl_render_error {
PL_RENDER_ERR_NONE = 0,
PL_RENDER_ERR_FBO = 1 << 0,
PL_RENDER_ERR_SAMPLING = 1 << 1,
PL_RENDER_ERR_DEBANDING = 1 << 2,
PL_RENDER_ERR_BLENDING = 1 << 3,
PL_RENDER_ERR_OVERLAY = 1 << 4,
PL_RENDER_ERR_PEAK_DETECT = 1 << 5,
PL_RENDER_ERR_FILM_GRAIN = 1 << 6,
PL_RENDER_ERR_FRAME_MIXING = 1 << 7,
PL_RENDER_ERR_DEINTERLACING = 1 << 8,
PL_RENDER_ERR_ERROR_DIFFUSION = 1 << 9,
PL_RENDER_ERR_HOOKS = 1 << 10,
};

struct pl_renderer_t {
pl_gpu gpu;
pl_dispatch dp;
Expand Down Expand Up @@ -3443,3 +3428,57 @@ void pl_frame_clear_rgba(pl_gpu gpu, const struct pl_frame *frame,
pl_tex_clear(gpu, plane->texture, clear);
}
}

struct pl_render_errors pl_renderer_get_errors(pl_renderer rr)
{
return (struct pl_render_errors) {
.errors = rr->errors,
.disabled_hooks = rr->disabled_hooks.elem,
.num_disabled_hooks = rr->disabled_hooks.num,
};
}

void pl_renderer_reset_errors(pl_renderer rr,
const struct pl_render_errors *errors)
{
if (!errors) {
// Reset everything
rr->errors = PL_RENDER_ERR_NONE;
rr->disabled_hooks.num = 0;
return;
}

// Reset only requested errors
rr->errors &= ~errors->errors;

// Not clearing hooks
if (!(errors->errors & PL_RENDER_ERR_HOOKS))
goto done;

// Remove all hook signatures
if (!errors->num_disabled_hooks) {
rr->disabled_hooks.num = 0;
goto done;
}

// At this point we require valid array of hooks
if (!errors->disabled_hooks) {
assert(errors->disabled_hooks);
goto done;
}

for (int i = 0; i < errors->num_disabled_hooks; i++) {
for (int j = 0; j < rr->disabled_hooks.num; j++) {
// Remove only requested hook signatures
if (rr->disabled_hooks.elem[j] == errors->disabled_hooks[i]) {
PL_ARRAY_REMOVE_AT(rr->disabled_hooks, j);
break;
}
}
}

done:
if (rr->disabled_hooks.num)
rr->errors |= PL_RENDER_ERR_HOOKS;
return;
}

0 comments on commit 0115d7c

Please sign in to comment.