vo_gpu: add namespace query mechanism

Backported from @haasn's change to libplacebo. More flexible than the
previous "shared || non-shared" distinction. The extra flexibility is
needed for Direct3D 11, but it also doesn't hurt code-wise.
This commit is contained in:
James Ross-Gowan 2017-10-22 00:10:09 +11:00
parent 793b43020c
commit 41dff03f8d
4 changed files with 21 additions and 10 deletions

View File

@ -50,8 +50,7 @@ enum {
RA_CAP_BUF_RO = 1 << 5, // supports RA_VARTYPE_BUF_RO
RA_CAP_BUF_RW = 1 << 6, // supports RA_VARTYPE_BUF_RW
RA_CAP_NESTED_ARRAY = 1 << 7, // supports nested arrays
RA_CAP_SHARED_BINDING = 1 << 8, // sampler/image/buffer namespaces are disjoint
RA_CAP_GLOBAL_UNIFORM = 1 << 9, // supports using "naked" uniforms (not UBO)
RA_CAP_GLOBAL_UNIFORM = 1 << 8, // supports using "naked" uniforms (not UBO)
};
enum ra_ctype {
@ -206,8 +205,8 @@ struct ra_renderpass_input {
// RA_VARTYPE_IMG_W: image unit
// RA_VARTYPE_BUF_* buffer binding point
// Other uniforms: unused
// If RA_CAP_SHARED_BINDING is set, these may only be unique per input type.
// Otherwise, these must be unique for all input values.
// Bindings must be unique within each namespace, as specified by
// desc_namespace()
int binding;
};
@ -396,6 +395,11 @@ struct ra_fns {
// but must be implemented if ra.max_pushc_size > 0.
struct ra_layout (*push_constant_layout)(struct ra_renderpass_input *inp);
// Returns an abstract namespace index for a given renderpass input type.
// This will always be a value >= 0 and < RA_VARTYPE_COUNT. This is used to
// figure out which inputs may share the same value of `binding`.
int (*desc_namespace)(enum ra_vartype type);
// Clear the dst with the given color (rgba) and within the given scissor.
// dst must have dst->params.render_dst==true. Content outside of the
// scissor is preserved.

View File

@ -254,11 +254,7 @@ static struct sc_uniform *find_uniform(struct gl_shader_cache *sc,
static int gl_sc_next_binding(struct gl_shader_cache *sc, enum ra_vartype type)
{
if (sc->ra->caps & RA_CAP_SHARED_BINDING) {
return sc->next_binding[type]++;
} else {
return sc->next_binding[0]++;
}
return sc->next_binding[sc->ra->fns->desc_namespace(type)]++;
}
void gl_sc_uniform_dynamic(struct gl_shader_cache *sc)

View File

@ -96,7 +96,6 @@ static int ra_init_gl(struct ra *ra, GL *gl)
static const int caps_map[][2] = {
{RA_CAP_DIRECT_UPLOAD, 0},
{RA_CAP_SHARED_BINDING, 0},
{RA_CAP_GLOBAL_UNIFORM, 0},
{RA_CAP_TEX_1D, MPGL_CAP_1D_TEX},
{RA_CAP_TEX_3D, MPGL_CAP_3D_TEX},
@ -653,6 +652,11 @@ static void gl_blit(struct ra *ra, struct ra_tex *dst, struct ra_tex *src,
gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}
static int gl_desc_namespace(enum ra_vartype type)
{
return type;
}
static void gl_renderpass_destroy(struct ra *ra, struct ra_renderpass *pass)
{
GL *gl = ra_gl_get(ra);
@ -1122,6 +1126,7 @@ static struct ra_fns ra_fns_gl = {
.clear = gl_clear,
.blit = gl_blit,
.uniform_layout = std140_layout,
.desc_namespace = gl_desc_namespace,
.renderpass_create = gl_renderpass_create,
.renderpass_destroy = gl_renderpass_destroy,
.renderpass_run = gl_renderpass_run,

View File

@ -1585,6 +1585,11 @@ static void vk_clear(struct ra *ra, struct ra_tex *tex, float color[4],
}
}
static int vk_desc_namespace(enum ra_vartype type)
{
return 0;
}
#define VK_QUERY_POOL_SIZE (MPVK_MAX_STREAMING_DEPTH * 4)
struct vk_timer {
@ -1688,6 +1693,7 @@ static struct ra_fns ra_fns_vk = {
.blit = vk_blit,
.uniform_layout = std140_layout,
.push_constant_layout = std430_layout,
.desc_namespace = vk_desc_namespace,
.renderpass_create = vk_renderpass_create,
.renderpass_destroy = vk_renderpass_destroy_lazy,
.renderpass_run = vk_renderpass_run,