diff options
author | Niklas Haas <git@haasn.xyz> | 2017-09-17 10:55:43 +0200 |
---|---|---|
committer | Niklas Haas <git@haasn.xyz> | 2017-09-26 17:25:35 +0200 |
commit | 47af509e1fad3e9ce30e3e339d8cd705fcd44ef2 (patch) | |
tree | 0f0ac7f905efe2a3efdfe4e0b38cae15d0be8eda /video/out/gpu/shader_cache.c | |
parent | ca85a153b4a201c7f6d600f861639ef68c1edfa3 (diff) | |
download | mpv-47af509e1fad3e9ce30e3e339d8cd705fcd44ef2.tar.bz2 mpv-47af509e1fad3e9ce30e3e339d8cd705fcd44ef2.tar.xz |
vo_gpu: attempt to avoid UBOs for dynamic variables
This makes the radeon driver shut up about frequently updating
STATIC_DRAW UBOs (--opengl-debug), and also reduces the amount of
synchronization necessary for vulkan uniform buffers.
Also add some extra debugging/tracing code paths. I went with a
flags-based approach in case we ever want to extend this.
Diffstat (limited to 'video/out/gpu/shader_cache.c')
-rw-r--r-- | video/out/gpu/shader_cache.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/video/out/gpu/shader_cache.c b/video/out/gpu/shader_cache.c index ff386546d3..4e9acc9e3e 100644 --- a/video/out/gpu/shader_cache.c +++ b/video/out/gpu/shader_cache.c @@ -76,6 +76,7 @@ struct gl_shader_cache { // Next binding point (texture unit, image unit, buffer binding, etc.) // In OpenGL these are separate for each input type int next_binding[RA_VARTYPE_COUNT]; + bool next_uniform_dynamic; struct ra_renderpass_params params; @@ -135,6 +136,7 @@ void gl_sc_reset(struct gl_shader_cache *sc) sc->pushc_size = 0; for (int i = 0; i < RA_VARTYPE_COUNT; i++) sc->next_binding[i] = 0; + sc->next_uniform_dynamic = false; sc->current_shader = NULL; sc->params = (struct ra_renderpass_params){0}; sc->needs_reset = false; @@ -259,14 +261,22 @@ static int gl_sc_next_binding(struct gl_shader_cache *sc, enum ra_vartype type) } } +void gl_sc_uniform_dynamic(struct gl_shader_cache *sc) +{ + sc->next_uniform_dynamic = true; +} + // Updates the metadata for the given sc_uniform. Assumes sc_uniform->input // and glsl_type/buffer_format are already set. static void update_uniform_params(struct gl_shader_cache *sc, struct sc_uniform *u) { + bool dynamic = sc->next_uniform_dynamic; + sc->next_uniform_dynamic = false; + // Try not using push constants for "large" values like matrices, since // this is likely to both exceed the VGPR budget as well as the pushc size // budget - bool try_pushc = u->input.dim_m == 1; + bool try_pushc = u->input.dim_m == 1 || dynamic; // Attempt using push constants first if (try_pushc && sc->ra->glsl_vulkan && sc->ra->max_pushc_size) { @@ -287,7 +297,10 @@ static void update_uniform_params(struct gl_shader_cache *sc, struct sc_uniform // to explicit offsets on UBO entries. In theory we could leave away // the offsets and support UBOs for older GL as well, but this is a nice // safety net for driver bugs (and also rules out potentially buggy drivers) - if (sc->ra->glsl_version >= 440 && (sc->ra->caps & RA_CAP_BUF_RO)) { + // Also avoid UBOs for highly dynamic stuff since that requires synchronizing + // the UBO writes every frame + bool try_ubo = !(sc->ra->caps & RA_CAP_GLOBAL_UNIFORM) || !dynamic; + if (try_ubo && sc->ra->glsl_version >= 440 && (sc->ra->caps & RA_CAP_BUF_RO)) { u->type = SC_UNIFORM_TYPE_UBO; u->layout = sc->ra->fns->uniform_layout(&u->input); u->offset = MP_ALIGN_UP(sc->ubo_size, u->layout.align); @@ -514,6 +527,13 @@ static void update_uniform(struct gl_shader_cache *sc, struct sc_entry *e, un->v = u->v; un->set = true; + static const char *desc[] = { + [SC_UNIFORM_TYPE_UBO] = "UBO", + [SC_UNIFORM_TYPE_PUSHC] = "PC", + [SC_UNIFORM_TYPE_GLOBAL] = "global", + }; + MP_TRACE(sc, "Updating %s uniform '%s'\n", desc[u->type], u->input.name); + switch (u->type) { case SC_UNIFORM_TYPE_GLOBAL: { struct ra_renderpass_input_val value = { |