Commit 27835a8b authored by Niklas Haas's avatar Niklas Haas

shaders: allow overriding shader GLSL version explicitly

This can be useful for API users that don't want to go through the
bother of setting up a dummy `pl_gpu` just to create some shaders.
parent 729e4aee
Pipeline #4983 passed with stages
in 2 minutes and 53 seconds
......@@ -2,7 +2,7 @@ project('libplacebo', ['c', 'cpp'],
license: 'LGPL2.1+',
default_options: ['c_std=c99'],
meson_version: '>=0.47',
version: '1.20.0',
version: '1.21.0',
)
# Version number
......
......@@ -50,6 +50,11 @@ struct pl_shader_params {
// determinstic rendering, this may safely be left as 0. Otherwise, it
// should be incremented by 1 on successive frames.
uint8_t index;
// If `glsl.version` is nonzero, then this structure will be used to
// determine the effective GLSL mode and capabilities. If `gpu` is also
// set, then this overrides `gpu->glsl`.
struct pl_glsl_desc glsl;
};
// Creates a new, blank, mutable pl_shader object.
......
......@@ -909,5 +909,5 @@ const char *sh_bvec(const struct pl_shader *sh, int dims)
};
pl_assert(dims > 0 && dims < PL_ARRAY_SIZE(bvecs));
return sh_glsl_ver(sh) >= 130 ? bvecs[dims] : vecs[dims];
return sh_glsl(sh).version >= 130 ? bvecs[dims] : vecs[dims];
}
......@@ -193,8 +193,14 @@ const char *sh_bvec(const struct pl_shader *sh, int dims);
#define SH_PARAMS(sh) ((sh)->res.params)
#define SH_GPU(sh) (SH_PARAMS(sh).gpu)
// Returns the GLSL version, defaulting to 130 if no information is known
static inline int sh_glsl_ver(const struct pl_shader *sh)
// Returns the GLSL description, defaulting to desktop 130.
static inline struct pl_glsl_desc sh_glsl(const struct pl_shader *sh)
{
return SH_GPU(sh) ? SH_GPU(sh)->glsl.version : 130;
if (SH_PARAMS(sh).glsl.version)
return SH_PARAMS(sh).glsl;
if (SH_GPU(sh))
return SH_GPU(sh)->glsl;
return (struct pl_glsl_desc) { .version = 130 };
}
......@@ -1019,7 +1019,7 @@ void pl_shader_dither(struct pl_shader *sh, int new_depth,
}
enum pl_dither_method method = params->method;
bool can_fixed = sh_glsl_ver(sh) >= 130;
bool can_fixed = sh_glsl(sh).version >= 130;
ident_t lut = NULL;
int lut_size = 0;
......
......@@ -446,7 +446,7 @@ bool pl_shader_sample_polar(struct pl_shader *sh,
bool use_gather = sqrt(x*x + y*y) < obj->filter->radius_cutoff;
// Make sure all required features are supported
use_gather &= sh_glsl_ver(sh) >= 400;
use_gather &= sh_glsl(sh).version >= 400;
use_gather &= gpu->limits.max_gather_offset != 0;
use_gather &= PL_MAX(x, y) <= gpu->limits.max_gather_offset;
use_gather &= PL_MIN(x, y) >= gpu->limits.min_gather_offset;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment