Skip to content

Commit

Permalink
dispatch: add option "no_compute"
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihe774 committed May 17, 2024
1 parent 07b5be6 commit dd4225f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions src/include/libplacebo/dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ })
Expand Down
2 changes: 1 addition & 1 deletion src/include/libplacebo/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions src/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
));
}
}
Expand Down

0 comments on commit dd4225f

Please sign in to comment.