From dd4225f27e6b43e85694096d96adb211efa7aedd Mon Sep 17 00:00:00 2001 From: Misaki Kasumi Date: Fri, 17 May 2024 14:46:53 +0800 Subject: [PATCH] dispatch: add option "no_compute" --- src/dispatch.c | 2 +- src/include/libplacebo/dispatch.h | 3 +++ src/include/libplacebo/renderer.h | 2 +- src/renderer.c | 11 +++++++++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/dispatch.c b/src/dispatch.c index ce4e667d..ee76ddf2 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -1208,7 +1208,7 @@ bool pl_dispatch_finish(pl_dispatch dp, const struct pl_dispatch_params *params) } const struct pl_gpu_limits *limits = &dp->gpu->limits; - bool can_compute = tpars->storable; + bool can_compute = tpars->storable && !params->no_compute; if (can_compute && params->blend_params) can_compute = tpars->format->caps & PL_FMT_CAP_READWRITE; diff --git a/src/include/libplacebo/dispatch.h b/src/include/libplacebo/dispatch.h index 141055c2..f41fea9a 100644 --- a/src/include/libplacebo/dispatch.h +++ b/src/include/libplacebo/dispatch.h @@ -115,6 +115,9 @@ struct pl_dispatch_params { // execution time of the shader, which means `pl_dispatch_info.samples` may // be empty as a result. pl_timer timer; + + // Disable the use of compute shaders. + bool no_compute; }; #define pl_dispatch_params(...) (&(struct pl_dispatch_params) { __VA_ARGS__ }) diff --git a/src/include/libplacebo/renderer.h b/src/include/libplacebo/renderer.h index f52a0ea6..eca034e2 100644 --- a/src/include/libplacebo/renderer.h +++ b/src/include/libplacebo/renderer.h @@ -679,7 +679,7 @@ static inline void pl_frame_clear(pl_gpu gpu, const struct pl_frame *frame, // Helper function to clear a frame to a fully tiled background. PL_API void pl_frame_clear_tiles(pl_gpu gpu, const struct pl_frame *frame, - const float tile_colors[2][3], int tile_size); + const float tile_colors[2][3], int tile_size, bool no_compute); // Helper functions to return the fixed/inferred pl_frame parameters used // for rendering internally. Mutates `image` and `target` in-place to hold diff --git a/src/renderer.c b/src/renderer.c index 7f518f6c..c3eb675a 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -518,6 +518,7 @@ static pl_tex _img_tex(struct pass_state *pass, struct img *img, pl_debug_tag ta bool ok = pl_dispatch_finish(rr->dp, pl_dispatch_params( .shader = &img->sh, .target = tex, + .no_compute = pass->params->no_compute, )); const char *err_msg = img->err_msg; @@ -2064,6 +2065,7 @@ static pl_tex get_feature_map(struct pass_state *pass) bool ok = pl_dispatch_finish(rr->dp, pl_dispatch_params( .shader = &sh, .target = inter_tex, + .no_compute = pass->params->no_compute, )); if (!ok) goto error; @@ -2082,6 +2084,7 @@ static pl_tex get_feature_map(struct pass_state *pass) ok = pl_dispatch_finish(rr->dp, pl_dispatch_params( .shader = &sh, .target = out_tex, + .no_compute = pass->params->no_compute, )); if (!ok) goto error; @@ -2263,6 +2266,7 @@ static bool pass_error_diffusion(struct pass_state *pass, pl_shader *sh, bool ok = pl_dispatch_finish(rr->dp, pl_dispatch_params( .shader = sh, .target = edpars.input_tex, + .no_compute = pass->params->no_compute, )); if (ok) { @@ -2303,7 +2307,7 @@ static void clear_target(pl_renderer rr, const struct pl_frame *target, pl_frame_clear_rgba(rr->gpu, target, CLEAR_COL(params)); break; case PL_CLEAR_TILES: - pl_frame_clear_tiles(rr->gpu, target, params->tile_colors, params->tile_size); + pl_frame_clear_tiles(rr->gpu, target, params->tile_colors, params->tile_size, params->no_compute); break; case PL_CLEAR_SKIP: break; case PL_CLEAR_MODE_COUNT: pl_unreachable(); @@ -2622,6 +2626,7 @@ static bool pass_output_target(struct pass_state *pass) .target = plane->texture, .blend_params = params->blend_params, .rect = plane_rect, + .no_compute = pass->params->no_compute, )); if (!ok) @@ -3540,6 +3545,7 @@ bool pl_render_image_mix(pl_renderer rr, const struct pl_frame_mix *images, ok = pl_dispatch_finish(rr->dp, pl_dispatch_params( .shader = &inter_pass.img.sh, .target = f->tex, + .no_compute = params->no_compute, )); if (!ok) goto inter_pass_error; @@ -3785,7 +3791,7 @@ bool pl_frame_is_cropped(const struct pl_frame *frame) } void pl_frame_clear_tiles(pl_gpu gpu, const struct pl_frame *frame, - const float tile_colors[2][3], int tile_size) + const float tile_colors[2][3], int tile_size, bool no_compute) { struct pl_color_repr repr = frame->repr; pl_transform3x3 tr = pl_color_repr_decode(&repr, NULL); @@ -3832,6 +3838,7 @@ void pl_frame_clear_tiles(pl_gpu gpu, const struct pl_frame *frame, pl_dispatch_finish(dp, pl_dispatch_params( .shader = &sh, .target = plane->texture, + .no_compute = no_compute, )); } }