2017-08-04 17:09:46 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <libavutil/sha.h>
|
|
|
|
#include <libavutil/mem.h>
|
|
|
|
|
|
|
|
#include "osdep/io.h"
|
|
|
|
|
|
|
|
#include "common/common.h"
|
|
|
|
#include "options/path.h"
|
|
|
|
#include "stream/stream.h"
|
|
|
|
#include "shader_cache.h"
|
2017-08-05 16:20:45 +00:00
|
|
|
#include "utils.h"
|
2017-08-04 17:09:46 +00:00
|
|
|
|
|
|
|
// Force cache flush if more than this number of shaders is created.
|
|
|
|
#define SC_MAX_ENTRIES 48
|
|
|
|
|
|
|
|
union uniform_val {
|
2017-08-05 12:20:14 +00:00
|
|
|
float f[9]; // RA_VARTYPE_FLOAT
|
2017-08-05 20:29:48 +00:00
|
|
|
int i[4]; // RA_VARTYPE_INT
|
2017-08-05 12:20:14 +00:00
|
|
|
struct ra_tex *tex; // RA_VARTYPE_TEX, RA_VARTYPE_IMG_*
|
2017-08-05 20:29:48 +00:00
|
|
|
struct ra_buf *buf; // RA_VARTYPE_BUF_*
|
2017-08-04 17:09:46 +00:00
|
|
|
};
|
|
|
|
|
2017-09-08 02:27:53 +00:00
|
|
|
enum sc_uniform_type {
|
|
|
|
SC_UNIFORM_TYPE_GLOBAL = 0, // global uniform (RA_CAP_GLOBAL_UNIFORM)
|
|
|
|
SC_UNIFORM_TYPE_UBO = 1, // uniform buffer (RA_CAP_BUF_RO)
|
2017-09-08 04:13:55 +00:00
|
|
|
SC_UNIFORM_TYPE_PUSHC = 2, // push constant (ra.max_pushc_size)
|
2017-09-08 02:27:53 +00:00
|
|
|
};
|
|
|
|
|
2017-08-04 17:09:46 +00:00
|
|
|
struct sc_uniform {
|
2017-09-08 02:27:53 +00:00
|
|
|
enum sc_uniform_type type;
|
2017-08-05 12:20:14 +00:00
|
|
|
struct ra_renderpass_input input;
|
2017-08-04 17:09:46 +00:00
|
|
|
const char *glsl_type;
|
|
|
|
union uniform_val v;
|
2017-08-05 20:29:48 +00:00
|
|
|
char *buffer_format;
|
2017-09-08 04:13:55 +00:00
|
|
|
// for SC_UNIFORM_TYPE_UBO/PUSHC:
|
2017-09-08 02:27:53 +00:00
|
|
|
struct ra_layout layout;
|
|
|
|
size_t offset; // byte offset within the buffer
|
2017-08-04 17:09:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sc_cached_uniform {
|
|
|
|
union uniform_val v;
|
2017-08-26 03:58:50 +00:00
|
|
|
int index; // for ra_renderpass_input_val
|
2017-09-12 01:00:47 +00:00
|
|
|
bool set; // whether the uniform has ever been set
|
2017-08-04 17:09:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sc_entry {
|
2017-08-05 12:20:14 +00:00
|
|
|
struct ra_renderpass *pass;
|
|
|
|
struct sc_cached_uniform *cached_uniforms;
|
|
|
|
int num_cached_uniforms;
|
|
|
|
bstr total;
|
2017-08-05 16:20:45 +00:00
|
|
|
struct timer_pool *timer;
|
2017-08-26 03:58:50 +00:00
|
|
|
struct ra_buf *ubo;
|
|
|
|
int ubo_index; // for ra_renderpass_input_val.index
|
2017-09-08 04:13:55 +00:00
|
|
|
void *pushc;
|
2017-08-04 17:09:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct gl_shader_cache {
|
2017-08-05 12:20:14 +00:00
|
|
|
struct ra *ra;
|
2017-08-04 17:09:46 +00:00
|
|
|
struct mp_log *log;
|
|
|
|
|
|
|
|
// permanent
|
|
|
|
char **exts;
|
|
|
|
int num_exts;
|
|
|
|
|
|
|
|
// this is modified during use (gl_sc_add() etc.) and reset for each shader
|
|
|
|
bstr prelude_text;
|
|
|
|
bstr header_text;
|
|
|
|
bstr text;
|
2017-08-26 03:39:53 +00:00
|
|
|
|
|
|
|
// 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];
|
2017-09-17 08:55:43 +00:00
|
|
|
bool next_uniform_dynamic;
|
2017-08-04 17:09:46 +00:00
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
struct ra_renderpass_params params;
|
|
|
|
|
|
|
|
struct sc_entry **entries;
|
2017-08-04 17:09:46 +00:00
|
|
|
int num_entries;
|
|
|
|
|
|
|
|
struct sc_entry *current_shader; // set by gl_sc_generate()
|
|
|
|
|
|
|
|
struct sc_uniform *uniforms;
|
|
|
|
int num_uniforms;
|
|
|
|
|
2017-08-26 03:58:50 +00:00
|
|
|
int ubo_binding;
|
|
|
|
size_t ubo_size;
|
2017-09-08 04:13:55 +00:00
|
|
|
size_t pushc_size;
|
2017-08-26 03:58:50 +00:00
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
struct ra_renderpass_input_val *values;
|
|
|
|
int num_values;
|
2017-08-04 17:09:46 +00:00
|
|
|
|
|
|
|
// For checking that the user is calling gl_sc_reset() properly.
|
|
|
|
bool needs_reset;
|
|
|
|
|
|
|
|
bool error_state; // true if an error occurred
|
|
|
|
|
|
|
|
// temporary buffers (avoids frequent reallocations)
|
2017-08-05 12:20:14 +00:00
|
|
|
bstr tmp[6];
|
2017-08-04 17:09:46 +00:00
|
|
|
|
|
|
|
// For the disk-cache.
|
|
|
|
char *cache_dir;
|
|
|
|
struct mpv_global *global; // can be NULL
|
|
|
|
};
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
struct gl_shader_cache *gl_sc_create(struct ra *ra, struct mpv_global *global,
|
|
|
|
struct mp_log *log)
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
|
|
|
struct gl_shader_cache *sc = talloc_ptrtype(NULL, sc);
|
|
|
|
*sc = (struct gl_shader_cache){
|
2017-08-05 12:20:14 +00:00
|
|
|
.ra = ra,
|
|
|
|
.global = global,
|
2017-08-04 17:09:46 +00:00
|
|
|
.log = log,
|
|
|
|
};
|
|
|
|
gl_sc_reset(sc);
|
|
|
|
return sc;
|
|
|
|
}
|
|
|
|
|
2017-08-05 17:38:43 +00:00
|
|
|
// Reset the previous pass. This must be called after gl_sc_generate and before
|
2017-09-23 07:54:42 +00:00
|
|
|
// starting a new shader. It may also be called on errors.
|
|
|
|
void gl_sc_reset(struct gl_shader_cache *sc)
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
|
|
|
sc->prelude_text.len = 0;
|
|
|
|
sc->header_text.len = 0;
|
|
|
|
sc->text.len = 0;
|
|
|
|
for (int n = 0; n < sc->num_uniforms; n++)
|
2017-08-05 12:20:14 +00:00
|
|
|
talloc_free((void *)sc->uniforms[n].input.name);
|
2017-08-04 17:09:46 +00:00
|
|
|
sc->num_uniforms = 0;
|
2017-08-26 03:58:50 +00:00
|
|
|
sc->ubo_binding = 0;
|
|
|
|
sc->ubo_size = 0;
|
2017-09-08 04:13:55 +00:00
|
|
|
sc->pushc_size = 0;
|
2017-08-26 03:39:53 +00:00
|
|
|
for (int i = 0; i < RA_VARTYPE_COUNT; i++)
|
|
|
|
sc->next_binding[i] = 0;
|
2017-09-17 08:55:43 +00:00
|
|
|
sc->next_uniform_dynamic = false;
|
2017-08-04 17:09:46 +00:00
|
|
|
sc->current_shader = NULL;
|
2017-08-05 12:20:14 +00:00
|
|
|
sc->params = (struct ra_renderpass_params){0};
|
2017-08-04 17:09:46 +00:00
|
|
|
sc->needs_reset = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sc_flush_cache(struct gl_shader_cache *sc)
|
|
|
|
{
|
2017-09-28 09:53:57 +00:00
|
|
|
MP_DBG(sc, "flushing shader cache\n");
|
2017-08-04 17:09:46 +00:00
|
|
|
|
|
|
|
for (int n = 0; n < sc->num_entries; n++) {
|
2017-08-05 12:20:14 +00:00
|
|
|
struct sc_entry *e = sc->entries[n];
|
2017-08-26 03:58:50 +00:00
|
|
|
ra_buf_free(sc->ra, &e->ubo);
|
2017-08-05 12:20:14 +00:00
|
|
|
if (e->pass)
|
|
|
|
sc->ra->fns->renderpass_destroy(sc->ra, e->pass);
|
2017-08-05 16:20:45 +00:00
|
|
|
timer_pool_destroy(e->timer);
|
2017-08-05 12:20:14 +00:00
|
|
|
talloc_free(e);
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
|
|
|
sc->num_entries = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_sc_destroy(struct gl_shader_cache *sc)
|
|
|
|
{
|
|
|
|
if (!sc)
|
|
|
|
return;
|
|
|
|
gl_sc_reset(sc);
|
|
|
|
sc_flush_cache(sc);
|
|
|
|
talloc_free(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gl_sc_error_state(struct gl_shader_cache *sc)
|
|
|
|
{
|
|
|
|
return sc->error_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_sc_reset_error(struct gl_shader_cache *sc)
|
|
|
|
{
|
|
|
|
sc->error_state = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_sc_enable_extension(struct gl_shader_cache *sc, char *name)
|
|
|
|
{
|
|
|
|
for (int n = 0; n < sc->num_exts; n++) {
|
|
|
|
if (strcmp(sc->exts[n], name) == 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MP_TARRAY_APPEND(sc, sc->exts, sc->num_exts, talloc_strdup(sc, name));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define bstr_xappend0(sc, b, s) bstr_xappend(sc, b, bstr0(s))
|
|
|
|
|
|
|
|
void gl_sc_add(struct gl_shader_cache *sc, const char *text)
|
|
|
|
{
|
|
|
|
bstr_xappend0(sc, &sc->text, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_sc_addf(struct gl_shader_cache *sc, const char *textf, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, textf);
|
|
|
|
bstr_xappend_vasprintf(sc, &sc->text, textf, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_sc_hadd(struct gl_shader_cache *sc, const char *text)
|
|
|
|
{
|
|
|
|
bstr_xappend0(sc, &sc->header_text, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_sc_haddf(struct gl_shader_cache *sc, const char *textf, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, textf);
|
|
|
|
bstr_xappend_vasprintf(sc, &sc->header_text, textf, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_sc_hadd_bstr(struct gl_shader_cache *sc, struct bstr text)
|
|
|
|
{
|
|
|
|
bstr_xappend(sc, &sc->header_text, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_sc_paddf(struct gl_shader_cache *sc, const char *textf, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, textf);
|
|
|
|
bstr_xappend_vasprintf(sc, &sc->prelude_text, textf, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sc_uniform *find_uniform(struct gl_shader_cache *sc,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct sc_uniform new = {
|
2017-08-05 12:20:14 +00:00
|
|
|
.input = {
|
|
|
|
.dim_v = 1,
|
|
|
|
.dim_m = 1,
|
|
|
|
},
|
2017-08-04 17:09:46 +00:00
|
|
|
};
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
for (int n = 0; n < sc->num_uniforms; n++) {
|
|
|
|
struct sc_uniform *u = &sc->uniforms[n];
|
|
|
|
if (strcmp(u->input.name, name) == 0) {
|
|
|
|
const char *allocname = u->input.name;
|
|
|
|
*u = new;
|
|
|
|
u->input.name = allocname;
|
|
|
|
return u;
|
|
|
|
}
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
// not found -> add it
|
|
|
|
new.input.name = talloc_strdup(NULL, name);
|
|
|
|
MP_TARRAY_APPEND(sc, sc->uniforms, sc->num_uniforms, new);
|
|
|
|
return &sc->uniforms[sc->num_uniforms - 1];
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-08-26 03:39:53 +00:00
|
|
|
static int gl_sc_next_binding(struct gl_shader_cache *sc, enum ra_vartype type)
|
|
|
|
{
|
2018-11-10 10:27:03 +00:00
|
|
|
return sc->next_binding[sc->ra->fns->desc_namespace(sc->ra, type)]++;
|
2017-08-26 03:39:53 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 08:55:43 +00:00
|
|
|
void gl_sc_uniform_dynamic(struct gl_shader_cache *sc)
|
|
|
|
{
|
|
|
|
sc->next_uniform_dynamic = true;
|
|
|
|
}
|
|
|
|
|
2017-09-08 04:13:55 +00:00
|
|
|
// 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)
|
|
|
|
{
|
2017-09-17 08:55:43 +00:00
|
|
|
bool dynamic = sc->next_uniform_dynamic;
|
|
|
|
sc->next_uniform_dynamic = false;
|
|
|
|
|
2017-09-08 04:13:55 +00:00
|
|
|
// 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
|
2017-09-17 08:55:43 +00:00
|
|
|
bool try_pushc = u->input.dim_m == 1 || dynamic;
|
2017-09-08 04:13:55 +00:00
|
|
|
|
|
|
|
// Attempt using push constants first
|
|
|
|
if (try_pushc && sc->ra->glsl_vulkan && sc->ra->max_pushc_size) {
|
|
|
|
struct ra_layout layout = sc->ra->fns->push_constant_layout(&u->input);
|
|
|
|
size_t offset = MP_ALIGN_UP(sc->pushc_size, layout.align);
|
|
|
|
// Push constants have limited size, so make sure we don't exceed this
|
|
|
|
size_t new_size = offset + layout.size;
|
|
|
|
if (new_size <= sc->ra->max_pushc_size) {
|
|
|
|
u->type = SC_UNIFORM_TYPE_PUSHC;
|
|
|
|
u->layout = layout;
|
|
|
|
u->offset = offset;
|
|
|
|
sc->pushc_size = new_size;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-08-26 03:58:50 +00:00
|
|
|
|
2017-09-08 04:13:55 +00:00
|
|
|
// Attempt using uniform buffer next. The GLSL version 440 check is due
|
|
|
|
// 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)
|
2017-09-17 08:55:43 +00:00
|
|
|
// 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)) {
|
2017-09-08 04:13:55 +00:00
|
|
|
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);
|
|
|
|
sc->ubo_size = u->offset + u->layout.size;
|
2017-08-26 03:58:50 +00:00
|
|
|
return;
|
2017-09-08 04:13:55 +00:00
|
|
|
}
|
2017-08-26 03:58:50 +00:00
|
|
|
|
2017-09-08 04:13:55 +00:00
|
|
|
// If all else fails, use global uniforms
|
|
|
|
assert(sc->ra->caps & RA_CAP_GLOBAL_UNIFORM);
|
|
|
|
u->type = SC_UNIFORM_TYPE_GLOBAL;
|
2017-08-26 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-04 17:09:46 +00:00
|
|
|
void gl_sc_uniform_texture(struct gl_shader_cache *sc, char *name,
|
|
|
|
struct ra_tex *tex)
|
|
|
|
{
|
2017-08-05 12:20:14 +00:00
|
|
|
const char *glsl_type = "sampler2D";
|
|
|
|
if (tex->params.dimensions == 1) {
|
|
|
|
glsl_type = "sampler1D";
|
|
|
|
} else if (tex->params.dimensions == 3) {
|
|
|
|
glsl_type = "sampler3D";
|
|
|
|
} else if (tex->params.non_normalized) {
|
|
|
|
glsl_type = "sampler2DRect";
|
|
|
|
} else if (tex->params.external_oes) {
|
|
|
|
glsl_type = "samplerExternalOES";
|
|
|
|
} else if (tex->params.format->ctype == RA_CTYPE_UINT) {
|
|
|
|
glsl_type = sc->ra->glsl_es ? "highp usampler2D" : "usampler2D";
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
struct sc_uniform *u = find_uniform(sc, name);
|
|
|
|
u->input.type = RA_VARTYPE_TEX;
|
|
|
|
u->glsl_type = glsl_type;
|
2017-08-26 03:39:53 +00:00
|
|
|
u->input.binding = gl_sc_next_binding(sc, u->input.type);
|
2017-08-05 12:20:14 +00:00
|
|
|
u->v.tex = tex;
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
void gl_sc_uniform_image2D_wo(struct gl_shader_cache *sc, const char *name,
|
|
|
|
struct ra_tex *tex)
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
|
|
|
gl_sc_enable_extension(sc, "GL_ARB_shader_image_load_store");
|
|
|
|
|
|
|
|
struct sc_uniform *u = find_uniform(sc, name);
|
2017-08-05 12:20:14 +00:00
|
|
|
u->input.type = RA_VARTYPE_IMG_W;
|
|
|
|
u->glsl_type = "writeonly image2D";
|
2017-08-26 03:39:53 +00:00
|
|
|
u->input.binding = gl_sc_next_binding(sc, u->input.type);
|
2017-08-05 12:20:14 +00:00
|
|
|
u->v.tex = tex;
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 20:29:48 +00:00
|
|
|
void gl_sc_ssbo(struct gl_shader_cache *sc, char *name, struct ra_buf *buf,
|
2017-08-04 17:09:46 +00:00
|
|
|
char *format, ...)
|
|
|
|
{
|
2017-08-26 03:48:12 +00:00
|
|
|
assert(sc->ra->caps & RA_CAP_BUF_RW);
|
2017-08-04 17:09:46 +00:00
|
|
|
gl_sc_enable_extension(sc, "GL_ARB_shader_storage_buffer_object");
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
struct sc_uniform *u = find_uniform(sc, name);
|
2017-08-05 20:29:48 +00:00
|
|
|
u->input.type = RA_VARTYPE_BUF_RW;
|
2017-08-05 12:20:14 +00:00
|
|
|
u->glsl_type = "";
|
2017-08-26 03:39:53 +00:00
|
|
|
u->input.binding = gl_sc_next_binding(sc, u->input.type);
|
2017-08-05 20:29:48 +00:00
|
|
|
u->v.buf = buf;
|
2017-08-04 17:09:46 +00:00
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
2017-08-05 20:29:48 +00:00
|
|
|
u->buffer_format = ta_vasprintf(sc, format, ap);
|
2017-08-04 17:09:46 +00:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
void gl_sc_uniform_f(struct gl_shader_cache *sc, char *name, float f)
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
|
|
|
struct sc_uniform *u = find_uniform(sc, name);
|
2017-08-05 12:20:14 +00:00
|
|
|
u->input.type = RA_VARTYPE_FLOAT;
|
2017-08-04 17:09:46 +00:00
|
|
|
u->glsl_type = "float";
|
2017-09-08 04:13:55 +00:00
|
|
|
update_uniform_params(sc, u);
|
2017-08-04 17:09:46 +00:00
|
|
|
u->v.f[0] = f;
|
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
void gl_sc_uniform_i(struct gl_shader_cache *sc, char *name, int i)
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
|
|
|
struct sc_uniform *u = find_uniform(sc, name);
|
2017-08-05 12:20:14 +00:00
|
|
|
u->input.type = RA_VARTYPE_INT;
|
2017-08-04 17:09:46 +00:00
|
|
|
u->glsl_type = "int";
|
2017-09-08 04:13:55 +00:00
|
|
|
update_uniform_params(sc, u);
|
2017-08-04 17:09:46 +00:00
|
|
|
u->v.i[0] = i;
|
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
void gl_sc_uniform_vec2(struct gl_shader_cache *sc, char *name, float f[2])
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
|
|
|
struct sc_uniform *u = find_uniform(sc, name);
|
2017-08-05 12:20:14 +00:00
|
|
|
u->input.type = RA_VARTYPE_FLOAT;
|
|
|
|
u->input.dim_v = 2;
|
2017-08-04 17:09:46 +00:00
|
|
|
u->glsl_type = "vec2";
|
2017-09-08 04:13:55 +00:00
|
|
|
update_uniform_params(sc, u);
|
2017-08-04 17:09:46 +00:00
|
|
|
u->v.f[0] = f[0];
|
|
|
|
u->v.f[1] = f[1];
|
|
|
|
}
|
|
|
|
|
vo_opengl: refactor into vo_gpu
This is done in several steps:
1. refactor MPGLContext -> struct ra_ctx
2. move GL-specific stuff in vo_opengl into opengl/context.c
3. generalize context creation to support other APIs, and add --gpu-api
4. rename all of the --opengl- options that are no longer opengl-specific
5. move all of the stuff from opengl/* that isn't GL-specific into gpu/
(note: opengl/gl_utils.h became opengl/utils.h)
6. rename vo_opengl to vo_gpu
7. to handle window screenshots, the short-term approach was to just add
it to ra_swchain_fns. Long term (and for vulkan) this has to be moved to
ra itself (and vo_gpu altered to compensate), but this was a stop-gap
measure to prevent this commit from getting too big
8. move ra->fns->flush to ra_gl_ctx instead
9. some other minor changes that I've probably already forgotten
Note: This is one half of a major refactor, the other half of which is
provided by rossy's following commit. This commit enables support for
all linux platforms, while his version enables support for all non-linux
platforms.
Note 2: vo_opengl_cb.c also re-uses ra_gl_ctx so it benefits from the
--opengl- options like --opengl-early-flush, --opengl-finish etc. Should
be a strict superset of the old functionality.
Disclaimer: Since I have no way of compiling mpv on all platforms, some
of these ports were done blindly. Specifically, the blind ports included
context_mali_fbdev.c and context_rpi.c. Since they're both based on
egl_helpers, the port should have gone smoothly without any major
changes required. But if somebody complains about a compile error on
those platforms (assuming anybody actually uses them), you know where to
complain.
2017-09-14 06:04:55 +00:00
|
|
|
void gl_sc_uniform_vec3(struct gl_shader_cache *sc, char *name, float f[3])
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
|
|
|
struct sc_uniform *u = find_uniform(sc, name);
|
2017-08-05 12:20:14 +00:00
|
|
|
u->input.type = RA_VARTYPE_FLOAT;
|
|
|
|
u->input.dim_v = 3;
|
2017-08-04 17:09:46 +00:00
|
|
|
u->glsl_type = "vec3";
|
2017-09-08 04:13:55 +00:00
|
|
|
update_uniform_params(sc, u);
|
2017-08-04 17:09:46 +00:00
|
|
|
u->v.f[0] = f[0];
|
|
|
|
u->v.f[1] = f[1];
|
|
|
|
u->v.f[2] = f[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void transpose2x2(float r[2 * 2])
|
|
|
|
{
|
|
|
|
MPSWAP(float, r[0+2*1], r[1+2*0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_sc_uniform_mat2(struct gl_shader_cache *sc, char *name,
|
vo_opengl: refactor into vo_gpu
This is done in several steps:
1. refactor MPGLContext -> struct ra_ctx
2. move GL-specific stuff in vo_opengl into opengl/context.c
3. generalize context creation to support other APIs, and add --gpu-api
4. rename all of the --opengl- options that are no longer opengl-specific
5. move all of the stuff from opengl/* that isn't GL-specific into gpu/
(note: opengl/gl_utils.h became opengl/utils.h)
6. rename vo_opengl to vo_gpu
7. to handle window screenshots, the short-term approach was to just add
it to ra_swchain_fns. Long term (and for vulkan) this has to be moved to
ra itself (and vo_gpu altered to compensate), but this was a stop-gap
measure to prevent this commit from getting too big
8. move ra->fns->flush to ra_gl_ctx instead
9. some other minor changes that I've probably already forgotten
Note: This is one half of a major refactor, the other half of which is
provided by rossy's following commit. This commit enables support for
all linux platforms, while his version enables support for all non-linux
platforms.
Note 2: vo_opengl_cb.c also re-uses ra_gl_ctx so it benefits from the
--opengl- options like --opengl-early-flush, --opengl-finish etc. Should
be a strict superset of the old functionality.
Disclaimer: Since I have no way of compiling mpv on all platforms, some
of these ports were done blindly. Specifically, the blind ports included
context_mali_fbdev.c and context_rpi.c. Since they're both based on
egl_helpers, the port should have gone smoothly without any major
changes required. But if somebody complains about a compile error on
those platforms (assuming anybody actually uses them), you know where to
complain.
2017-09-14 06:04:55 +00:00
|
|
|
bool transpose, float *v)
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
|
|
|
struct sc_uniform *u = find_uniform(sc, name);
|
2017-08-05 12:20:14 +00:00
|
|
|
u->input.type = RA_VARTYPE_FLOAT;
|
|
|
|
u->input.dim_v = 2;
|
|
|
|
u->input.dim_m = 2;
|
2017-08-04 17:09:46 +00:00
|
|
|
u->glsl_type = "mat2";
|
2017-09-08 04:13:55 +00:00
|
|
|
update_uniform_params(sc, u);
|
2017-08-04 17:09:46 +00:00
|
|
|
for (int n = 0; n < 4; n++)
|
|
|
|
u->v.f[n] = v[n];
|
|
|
|
if (transpose)
|
|
|
|
transpose2x2(&u->v.f[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void transpose3x3(float r[3 * 3])
|
|
|
|
{
|
|
|
|
MPSWAP(float, r[0+3*1], r[1+3*0]);
|
|
|
|
MPSWAP(float, r[0+3*2], r[2+3*0]);
|
|
|
|
MPSWAP(float, r[1+3*2], r[2+3*1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_sc_uniform_mat3(struct gl_shader_cache *sc, char *name,
|
vo_opengl: refactor into vo_gpu
This is done in several steps:
1. refactor MPGLContext -> struct ra_ctx
2. move GL-specific stuff in vo_opengl into opengl/context.c
3. generalize context creation to support other APIs, and add --gpu-api
4. rename all of the --opengl- options that are no longer opengl-specific
5. move all of the stuff from opengl/* that isn't GL-specific into gpu/
(note: opengl/gl_utils.h became opengl/utils.h)
6. rename vo_opengl to vo_gpu
7. to handle window screenshots, the short-term approach was to just add
it to ra_swchain_fns. Long term (and for vulkan) this has to be moved to
ra itself (and vo_gpu altered to compensate), but this was a stop-gap
measure to prevent this commit from getting too big
8. move ra->fns->flush to ra_gl_ctx instead
9. some other minor changes that I've probably already forgotten
Note: This is one half of a major refactor, the other half of which is
provided by rossy's following commit. This commit enables support for
all linux platforms, while his version enables support for all non-linux
platforms.
Note 2: vo_opengl_cb.c also re-uses ra_gl_ctx so it benefits from the
--opengl- options like --opengl-early-flush, --opengl-finish etc. Should
be a strict superset of the old functionality.
Disclaimer: Since I have no way of compiling mpv on all platforms, some
of these ports were done blindly. Specifically, the blind ports included
context_mali_fbdev.c and context_rpi.c. Since they're both based on
egl_helpers, the port should have gone smoothly without any major
changes required. But if somebody complains about a compile error on
those platforms (assuming anybody actually uses them), you know where to
complain.
2017-09-14 06:04:55 +00:00
|
|
|
bool transpose, float *v)
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
|
|
|
struct sc_uniform *u = find_uniform(sc, name);
|
2017-08-05 12:20:14 +00:00
|
|
|
u->input.type = RA_VARTYPE_FLOAT;
|
|
|
|
u->input.dim_v = 3;
|
|
|
|
u->input.dim_m = 3;
|
2017-08-04 17:09:46 +00:00
|
|
|
u->glsl_type = "mat3";
|
2017-09-08 04:13:55 +00:00
|
|
|
update_uniform_params(sc, u);
|
2017-08-04 17:09:46 +00:00
|
|
|
for (int n = 0; n < 9; n++)
|
|
|
|
u->v.f[n] = v[n];
|
|
|
|
if (transpose)
|
|
|
|
transpose3x3(&u->v.f[0]);
|
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
void gl_sc_blend(struct gl_shader_cache *sc,
|
|
|
|
enum ra_blend blend_src_rgb,
|
|
|
|
enum ra_blend blend_dst_rgb,
|
|
|
|
enum ra_blend blend_src_alpha,
|
|
|
|
enum ra_blend blend_dst_alpha)
|
|
|
|
{
|
|
|
|
sc->params.enable_blend = true;
|
|
|
|
sc->params.blend_src_rgb = blend_src_rgb;
|
|
|
|
sc->params.blend_dst_rgb = blend_dst_rgb;
|
|
|
|
sc->params.blend_src_alpha = blend_src_alpha;
|
|
|
|
sc->params.blend_dst_alpha = blend_dst_alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *vao_glsl_type(const struct ra_renderpass_input *e)
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
|
|
|
// pretty dumb... too dumb, but works for us
|
2017-08-05 12:20:14 +00:00
|
|
|
switch (e->dim_v) {
|
2017-08-04 17:09:46 +00:00
|
|
|
case 1: return "float";
|
|
|
|
case 2: return "vec2";
|
|
|
|
case 3: return "vec3";
|
|
|
|
case 4: return "vec4";
|
|
|
|
default: abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-26 03:58:50 +00:00
|
|
|
static void update_ubo(struct ra *ra, struct ra_buf *ubo, struct sc_uniform *u)
|
|
|
|
{
|
|
|
|
uintptr_t src = (uintptr_t) &u->v;
|
2017-09-08 02:27:53 +00:00
|
|
|
size_t dst = u->offset;
|
|
|
|
struct ra_layout src_layout = ra_renderpass_input_layout(&u->input);
|
|
|
|
struct ra_layout dst_layout = u->layout;
|
|
|
|
|
|
|
|
for (int i = 0; i < u->input.dim_m; i++) {
|
|
|
|
ra->fns->buf_update(ra, ubo, dst, (void *)src, src_layout.stride);
|
|
|
|
src += src_layout.stride;
|
|
|
|
dst += dst_layout.stride;
|
2017-08-26 03:58:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 04:13:55 +00:00
|
|
|
static void update_pushc(struct ra *ra, void *pushc, struct sc_uniform *u)
|
|
|
|
{
|
|
|
|
uintptr_t src = (uintptr_t) &u->v;
|
|
|
|
uintptr_t dst = (uintptr_t) pushc + (ptrdiff_t) u->offset;
|
|
|
|
struct ra_layout src_layout = ra_renderpass_input_layout(&u->input);
|
|
|
|
struct ra_layout dst_layout = u->layout;
|
|
|
|
|
|
|
|
for (int i = 0; i < u->input.dim_m; i++) {
|
|
|
|
memcpy((void *)dst, (void *)src, src_layout.stride);
|
|
|
|
src += src_layout.stride;
|
|
|
|
dst += dst_layout.stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
static void update_uniform(struct gl_shader_cache *sc, struct sc_entry *e,
|
|
|
|
struct sc_uniform *u, int n)
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
2017-08-05 12:20:14 +00:00
|
|
|
struct sc_cached_uniform *un = &e->cached_uniforms[n];
|
2017-09-08 02:27:53 +00:00
|
|
|
struct ra_layout layout = ra_renderpass_input_layout(&u->input);
|
2017-09-12 01:00:47 +00:00
|
|
|
if (layout.size > 0 && un->set && memcmp(&un->v, &u->v, layout.size) == 0)
|
2017-09-08 02:27:53 +00:00
|
|
|
return;
|
2017-08-05 12:20:14 +00:00
|
|
|
|
2017-09-08 02:27:53 +00:00
|
|
|
un->v = u->v;
|
2017-09-12 01:00:47 +00:00
|
|
|
un->set = true;
|
2017-08-26 03:58:50 +00:00
|
|
|
|
2017-09-17 08:55:43 +00:00
|
|
|
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);
|
|
|
|
|
2017-09-08 02:27:53 +00:00
|
|
|
switch (u->type) {
|
|
|
|
case SC_UNIFORM_TYPE_GLOBAL: {
|
|
|
|
struct ra_renderpass_input_val value = {
|
|
|
|
.index = un->index,
|
|
|
|
.data = &un->v,
|
|
|
|
};
|
|
|
|
MP_TARRAY_APPEND(sc, sc->values, sc->num_values, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SC_UNIFORM_TYPE_UBO:
|
|
|
|
assert(e->ubo);
|
|
|
|
update_ubo(sc->ra, e->ubo, u);
|
|
|
|
break;
|
2017-09-08 04:13:55 +00:00
|
|
|
case SC_UNIFORM_TYPE_PUSHC:
|
|
|
|
assert(e->pushc);
|
|
|
|
update_pushc(sc->ra, e->pushc, u);
|
|
|
|
break;
|
2017-09-08 02:27:53 +00:00
|
|
|
default: abort();
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
void gl_sc_set_cache_dir(struct gl_shader_cache *sc, const char *dir)
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
|
|
|
talloc_free(sc->cache_dir);
|
|
|
|
sc->cache_dir = talloc_strdup(sc, dir);
|
|
|
|
}
|
|
|
|
|
2017-08-26 03:58:50 +00:00
|
|
|
static bool create_pass(struct gl_shader_cache *sc, struct sc_entry *entry)
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
2017-08-26 03:58:50 +00:00
|
|
|
bool ret = false;
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
void *tmp = talloc_new(NULL);
|
|
|
|
struct ra_renderpass_params params = sc->params;
|
2017-08-04 17:09:46 +00:00
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
const char *cache_header = "mpv shader cache v1\n";
|
|
|
|
char *cache_filename = NULL;
|
|
|
|
char *cache_dir = NULL;
|
|
|
|
|
|
|
|
if (sc->cache_dir && sc->cache_dir[0]) {
|
|
|
|
// Try to load it from a disk cache.
|
|
|
|
cache_dir = mp_get_user_path(tmp, sc->global, sc->cache_dir);
|
|
|
|
|
|
|
|
struct AVSHA *sha = av_sha_alloc();
|
|
|
|
if (!sha)
|
|
|
|
abort();
|
|
|
|
av_sha_init(sha, 256);
|
|
|
|
av_sha_update(sha, entry->total.start, entry->total.len);
|
|
|
|
|
|
|
|
uint8_t hash[256 / 8];
|
|
|
|
av_sha_final(sha, hash);
|
|
|
|
av_free(sha);
|
|
|
|
|
|
|
|
char hashstr[256 / 8 * 2 + 1];
|
|
|
|
for (int n = 0; n < 256 / 8; n++)
|
|
|
|
snprintf(hashstr + n * 2, sizeof(hashstr) - n * 2, "%02X", hash[n]);
|
|
|
|
|
|
|
|
cache_filename = mp_path_join(tmp, cache_dir, hashstr);
|
|
|
|
if (stat(cache_filename, &(struct stat){0}) == 0) {
|
2017-09-28 09:53:57 +00:00
|
|
|
MP_DBG(sc, "Trying to load shader from disk...\n");
|
2017-08-05 12:20:14 +00:00
|
|
|
struct bstr cachedata =
|
|
|
|
stream_read_file(cache_filename, tmp, sc->global, 1000000000);
|
|
|
|
if (bstr_eatstart0(&cachedata, cache_header))
|
|
|
|
params.cached_program = cachedata;
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-26 03:58:50 +00:00
|
|
|
// If using a UBO, also make sure to add it as an input value so the RA
|
|
|
|
// can see it
|
|
|
|
if (sc->ubo_size) {
|
|
|
|
entry->ubo_index = sc->params.num_inputs;
|
|
|
|
struct ra_renderpass_input ubo_input = {
|
|
|
|
.name = "UBO",
|
|
|
|
.type = RA_VARTYPE_BUF_RO,
|
|
|
|
.dim_v = 1,
|
|
|
|
.dim_m = 1,
|
|
|
|
.binding = sc->ubo_binding,
|
|
|
|
};
|
|
|
|
MP_TARRAY_APPEND(sc, params.inputs, params.num_inputs, ubo_input);
|
|
|
|
}
|
2017-08-04 17:09:46 +00:00
|
|
|
|
2017-09-08 04:13:55 +00:00
|
|
|
if (sc->pushc_size) {
|
|
|
|
params.push_constants_size = MP_ALIGN_UP(sc->pushc_size, 4);
|
|
|
|
entry->pushc = talloc_zero_size(entry, params.push_constants_size);
|
|
|
|
}
|
|
|
|
|
2017-08-26 03:58:50 +00:00
|
|
|
if (sc->ubo_size) {
|
|
|
|
struct ra_buf_params ubo_params = {
|
|
|
|
.type = RA_BUF_TYPE_UNIFORM,
|
|
|
|
.size = sc->ubo_size,
|
|
|
|
.host_mutable = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
entry->ubo = ra_buf_create(sc->ra, &ubo_params);
|
|
|
|
if (!entry->ubo) {
|
|
|
|
MP_ERR(sc, "Failed creating uniform buffer!\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
2017-08-04 17:09:46 +00:00
|
|
|
|
2017-09-23 13:15:51 +00:00
|
|
|
entry->pass = sc->ra->fns->renderpass_create(sc->ra, ¶ms);
|
|
|
|
if (!entry->pass)
|
|
|
|
goto error;
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
if (entry->pass && cache_filename) {
|
|
|
|
bstr nc = entry->pass->params.cached_program;
|
|
|
|
if (nc.len && !bstr_equals(params.cached_program, nc)) {
|
|
|
|
mp_mkdirp(cache_dir);
|
2017-08-04 17:09:46 +00:00
|
|
|
|
2017-09-28 09:53:57 +00:00
|
|
|
MP_DBG(sc, "Writing shader cache file: %s\n", cache_filename);
|
2017-08-05 12:20:14 +00:00
|
|
|
FILE *out = fopen(cache_filename, "wb");
|
2017-08-04 17:09:46 +00:00
|
|
|
if (out) {
|
2017-08-05 12:20:14 +00:00
|
|
|
fwrite(cache_header, strlen(cache_header), 1, out);
|
|
|
|
fwrite(nc.start, nc.len, 1, out);
|
2017-08-04 17:09:46 +00:00
|
|
|
fclose(out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-26 03:58:50 +00:00
|
|
|
ret = true;
|
|
|
|
|
|
|
|
error:
|
2017-08-04 17:09:46 +00:00
|
|
|
talloc_free(tmp);
|
2017-08-26 03:58:50 +00:00
|
|
|
return ret;
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ADD(x, ...) bstr_xappend_asprintf(sc, (x), __VA_ARGS__)
|
|
|
|
#define ADD_BSTR(x, s) bstr_xappend(sc, (x), (s))
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
static void add_uniforms(struct gl_shader_cache *sc, bstr *dst)
|
|
|
|
{
|
2017-08-26 03:58:50 +00:00
|
|
|
// Add all of the UBO entries separately as members of their own buffer
|
|
|
|
if (sc->ubo_size > 0) {
|
|
|
|
ADD(dst, "layout(std140, binding=%d) uniform UBO {\n", sc->ubo_binding);
|
|
|
|
for (int n = 0; n < sc->num_uniforms; n++) {
|
|
|
|
struct sc_uniform *u = &sc->uniforms[n];
|
2017-09-08 02:27:53 +00:00
|
|
|
if (u->type != SC_UNIFORM_TYPE_UBO)
|
2017-08-26 03:58:50 +00:00
|
|
|
continue;
|
2017-09-08 04:13:55 +00:00
|
|
|
ADD(dst, "layout(offset=%zu) %s %s;\n", u->offset, u->glsl_type,
|
|
|
|
u->input.name);
|
|
|
|
}
|
|
|
|
ADD(dst, "};\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ditto for push constants
|
|
|
|
if (sc->pushc_size > 0) {
|
2017-09-28 22:41:50 +00:00
|
|
|
ADD(dst, "layout(std430, push_constant) uniform PushC {\n");
|
2017-09-08 04:13:55 +00:00
|
|
|
for (int n = 0; n < sc->num_uniforms; n++) {
|
|
|
|
struct sc_uniform *u = &sc->uniforms[n];
|
|
|
|
if (u->type != SC_UNIFORM_TYPE_PUSHC)
|
|
|
|
continue;
|
2018-09-29 00:17:44 +00:00
|
|
|
ADD(dst, "layout(offset=%zu) %s %s;\n", u->offset, u->glsl_type,
|
2017-09-08 04:13:55 +00:00
|
|
|
u->input.name);
|
2017-08-26 03:58:50 +00:00
|
|
|
}
|
|
|
|
ADD(dst, "};\n");
|
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
for (int n = 0; n < sc->num_uniforms; n++) {
|
|
|
|
struct sc_uniform *u = &sc->uniforms[n];
|
2017-09-08 02:27:53 +00:00
|
|
|
if (u->type != SC_UNIFORM_TYPE_GLOBAL)
|
2017-08-26 03:58:50 +00:00
|
|
|
continue;
|
2017-08-05 12:20:14 +00:00
|
|
|
switch (u->input.type) {
|
|
|
|
case RA_VARTYPE_INT:
|
|
|
|
case RA_VARTYPE_FLOAT:
|
2017-08-26 03:58:50 +00:00
|
|
|
assert(sc->ra->caps & RA_CAP_GLOBAL_UNIFORM);
|
|
|
|
// fall through
|
2017-08-05 12:20:14 +00:00
|
|
|
case RA_VARTYPE_TEX:
|
2017-08-20 02:27:42 +00:00
|
|
|
// Vulkan requires explicitly assigning the bindings in the shader
|
|
|
|
// source. For OpenGL it's optional, but requires higher GL version
|
|
|
|
// so we don't do it (and instead have ra_gl update the bindings
|
|
|
|
// after program creation).
|
|
|
|
if (sc->ra->glsl_vulkan)
|
|
|
|
ADD(dst, "layout(binding=%d) ", u->input.binding);
|
2017-08-05 12:20:14 +00:00
|
|
|
ADD(dst, "uniform %s %s;\n", u->glsl_type, u->input.name);
|
|
|
|
break;
|
2017-08-26 03:48:12 +00:00
|
|
|
case RA_VARTYPE_BUF_RO:
|
|
|
|
ADD(dst, "layout(std140, binding=%d) uniform %s { %s };\n",
|
|
|
|
u->input.binding, u->input.name, u->buffer_format);
|
|
|
|
break;
|
2017-08-05 20:29:48 +00:00
|
|
|
case RA_VARTYPE_BUF_RW:
|
2017-08-05 12:20:14 +00:00
|
|
|
ADD(dst, "layout(std430, binding=%d) buffer %s { %s };\n",
|
2017-08-05 20:29:48 +00:00
|
|
|
u->input.binding, u->input.name, u->buffer_format);
|
2017-08-05 12:20:14 +00:00
|
|
|
break;
|
2017-09-24 14:09:24 +00:00
|
|
|
case RA_VARTYPE_IMG_W: {
|
|
|
|
// For better compatibility, we have to explicitly label the
|
vo_gpu: export the GLSL format qualifier for ra_format
Backported from @haasn's change to libplacebo, except in the current RA,
there's nothing to indicate an ra_format can be bound as a storage
image, so there's no way to force all of these formats to have a
glsl_format. Instead, the layout qualifier will be removed if
glsl_format is NULL.
This is needed for the upcoming ra_d3d11 backend. In Direct3D 11, while
loading float values from unorm images often works as expected, it's
technically undefined behaviour, and in Windows 10, it will cause the
debug layer to spam the log with error messages. Also, apparently in
GLSL, the format name must match the image's format exactly (but in
Direct3D, it just has to have the same component type.)
2017-10-21 14:18:31 +00:00
|
|
|
// type of data we will be reading/writing to this image.
|
|
|
|
const char *fmt = u->v.tex->params.format->glsl_format;
|
2017-09-24 14:09:24 +00:00
|
|
|
|
|
|
|
if (sc->ra->glsl_vulkan) {
|
vo_gpu: export the GLSL format qualifier for ra_format
Backported from @haasn's change to libplacebo, except in the current RA,
there's nothing to indicate an ra_format can be bound as a storage
image, so there's no way to force all of these formats to have a
glsl_format. Instead, the layout qualifier will be removed if
glsl_format is NULL.
This is needed for the upcoming ra_d3d11 backend. In Direct3D 11, while
loading float values from unorm images often works as expected, it's
technically undefined behaviour, and in Windows 10, it will cause the
debug layer to spam the log with error messages. Also, apparently in
GLSL, the format name must match the image's format exactly (but in
Direct3D, it just has to have the same component type.)
2017-10-21 14:18:31 +00:00
|
|
|
if (fmt) {
|
|
|
|
ADD(dst, "layout(binding=%d, %s) ", u->input.binding, fmt);
|
|
|
|
} else {
|
|
|
|
ADD(dst, "layout(binding=%d) ", u->input.binding);
|
|
|
|
}
|
|
|
|
} else if (fmt) {
|
2017-09-24 14:09:24 +00:00
|
|
|
ADD(dst, "layout(%s) ", fmt);
|
|
|
|
}
|
|
|
|
ADD(dst, "uniform %s %s;\n", u->glsl_type, u->input.name);
|
|
|
|
}
|
2017-08-05 12:20:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 17:09:46 +00:00
|
|
|
// 1. Generate vertex and fragment shaders from the fragment shader text added
|
|
|
|
// with gl_sc_add(). The generated shader program is cached (based on the
|
|
|
|
// text), so actual compilation happens only the first time.
|
|
|
|
// 2. Update the uniforms and textures set with gl_sc_uniform_*.
|
|
|
|
// 3. Make the new shader program current (glUseProgram()).
|
|
|
|
// After that, you render, and then you call gc_sc_reset(), which does:
|
|
|
|
// 1. Unbind the program and all textures.
|
|
|
|
// 2. Reset the sc state and prepare for a new shader program. (All uniforms
|
|
|
|
// and fragment operations needed for the next program have to be re-added.)
|
2017-08-21 05:00:25 +00:00
|
|
|
static void gl_sc_generate(struct gl_shader_cache *sc,
|
|
|
|
enum ra_renderpass_type type,
|
2017-09-27 22:07:42 +00:00
|
|
|
const struct ra_format *target_format,
|
|
|
|
const struct ra_renderpass_input *vao,
|
|
|
|
int vao_len, size_t vertex_stride)
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
2017-08-05 12:20:14 +00:00
|
|
|
int glsl_version = sc->ra->glsl_version;
|
|
|
|
int glsl_es = sc->ra->glsl_es ? glsl_version : 0;
|
|
|
|
|
|
|
|
sc->params.type = type;
|
2017-08-04 17:09:46 +00:00
|
|
|
|
|
|
|
// gl_sc_reset() must be called after ending the previous render process,
|
|
|
|
// and before starting a new one.
|
|
|
|
assert(!sc->needs_reset);
|
2017-08-05 12:20:14 +00:00
|
|
|
sc->needs_reset = true;
|
2017-08-04 17:09:46 +00:00
|
|
|
|
2017-08-26 03:58:50 +00:00
|
|
|
// If using a UBO, pick a binding (needed for shader generation)
|
|
|
|
if (sc->ubo_size)
|
|
|
|
sc->ubo_binding = gl_sc_next_binding(sc, RA_VARTYPE_BUF_RO);
|
|
|
|
|
2017-08-04 17:09:46 +00:00
|
|
|
for (int n = 0; n < MP_ARRAY_SIZE(sc->tmp); n++)
|
|
|
|
sc->tmp[n].len = 0;
|
|
|
|
|
|
|
|
// set up shader text (header + uniforms + body)
|
|
|
|
bstr *header = &sc->tmp[0];
|
2017-08-05 12:20:14 +00:00
|
|
|
ADD(header, "#version %d%s\n", glsl_version, glsl_es >= 300 ? " es" : "");
|
|
|
|
if (type == RA_RENDERPASS_TYPE_COMPUTE) {
|
2017-08-04 17:09:46 +00:00
|
|
|
// This extension cannot be enabled in fragment shader. Enable it as
|
|
|
|
// an exception for compute shader.
|
|
|
|
ADD(header, "#extension GL_ARB_compute_shader : enable\n");
|
|
|
|
}
|
|
|
|
for (int n = 0; n < sc->num_exts; n++)
|
|
|
|
ADD(header, "#extension %s : enable\n", sc->exts[n]);
|
2017-08-05 12:20:14 +00:00
|
|
|
if (glsl_es) {
|
2017-08-04 17:09:46 +00:00
|
|
|
ADD(header, "precision mediump float;\n");
|
|
|
|
ADD(header, "precision mediump sampler2D;\n");
|
2017-08-05 12:20:14 +00:00
|
|
|
if (sc->ra->caps & RA_CAP_TEX_3D)
|
2017-08-04 17:09:46 +00:00
|
|
|
ADD(header, "precision mediump sampler3D;\n");
|
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
if (glsl_version >= 130) {
|
2017-08-20 02:27:42 +00:00
|
|
|
ADD(header, "#define tex1D texture\n");
|
|
|
|
ADD(header, "#define tex3D texture\n");
|
2017-08-04 17:09:46 +00:00
|
|
|
} else {
|
2017-08-20 02:27:42 +00:00
|
|
|
ADD(header, "#define tex1D texture1D\n");
|
|
|
|
ADD(header, "#define tex3D texture3D\n");
|
2017-08-04 17:09:46 +00:00
|
|
|
ADD(header, "#define texture texture2D\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Additional helpers.
|
|
|
|
ADD(header, "#define LUT_POS(x, lut_size)"
|
|
|
|
" mix(0.5 / (lut_size), 1.0 - 0.5 / (lut_size), (x))\n");
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
char *vert_in = glsl_version >= 130 ? "in" : "attribute";
|
|
|
|
char *vert_out = glsl_version >= 130 ? "out" : "varying";
|
|
|
|
char *frag_in = glsl_version >= 130 ? "in" : "varying";
|
2017-08-04 17:09:46 +00:00
|
|
|
|
|
|
|
struct bstr *vert = NULL, *frag = NULL, *comp = NULL;
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
if (type == RA_RENDERPASS_TYPE_RASTER) {
|
2017-08-04 17:09:46 +00:00
|
|
|
// vertex shader: we don't use the vertex shader, so just setup a
|
|
|
|
// dummy, which passes through the vertex array attributes.
|
|
|
|
bstr *vert_head = &sc->tmp[1];
|
|
|
|
ADD_BSTR(vert_head, *header);
|
|
|
|
bstr *vert_body = &sc->tmp[2];
|
|
|
|
ADD(vert_body, "void main() {\n");
|
|
|
|
bstr *frag_vaos = &sc->tmp[3];
|
2017-09-27 22:07:42 +00:00
|
|
|
for (int n = 0; n < vao_len; n++) {
|
|
|
|
const struct ra_renderpass_input *e = &vao[n];
|
2017-08-04 17:09:46 +00:00
|
|
|
const char *glsl_type = vao_glsl_type(e);
|
2017-08-20 02:27:42 +00:00
|
|
|
char loc[32] = {0};
|
|
|
|
if (sc->ra->glsl_vulkan)
|
|
|
|
snprintf(loc, sizeof(loc), "layout(location=%d) ", n);
|
2017-08-04 17:09:46 +00:00
|
|
|
if (strcmp(e->name, "position") == 0) {
|
|
|
|
// setting raster pos. requires setting gl_Position magic variable
|
2017-08-05 12:20:14 +00:00
|
|
|
assert(e->dim_v == 2 && e->type == RA_VARTYPE_FLOAT);
|
2017-08-20 02:27:42 +00:00
|
|
|
ADD(vert_head, "%s%s vec2 vertex_position;\n", loc, vert_in);
|
2017-08-04 17:09:46 +00:00
|
|
|
ADD(vert_body, "gl_Position = vec4(vertex_position, 1.0, 1.0);\n");
|
|
|
|
} else {
|
2017-08-20 02:27:42 +00:00
|
|
|
ADD(vert_head, "%s%s %s vertex_%s;\n", loc, vert_in, glsl_type, e->name);
|
|
|
|
ADD(vert_head, "%s%s %s %s;\n", loc, vert_out, glsl_type, e->name);
|
2017-08-04 17:09:46 +00:00
|
|
|
ADD(vert_body, "%s = vertex_%s;\n", e->name, e->name);
|
2017-08-20 02:27:42 +00:00
|
|
|
ADD(frag_vaos, "%s%s %s %s;\n", loc, frag_in, glsl_type, e->name);
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ADD(vert_body, "}\n");
|
|
|
|
vert = vert_head;
|
|
|
|
ADD_BSTR(vert, *vert_body);
|
|
|
|
|
|
|
|
// fragment shader; still requires adding used uniforms and VAO elements
|
|
|
|
frag = &sc->tmp[4];
|
|
|
|
ADD_BSTR(frag, *header);
|
2017-08-20 02:27:42 +00:00
|
|
|
if (glsl_version >= 130) {
|
|
|
|
ADD(frag, "%sout vec4 out_color;\n",
|
|
|
|
sc->ra->glsl_vulkan ? "layout(location=0) " : "");
|
|
|
|
}
|
2017-08-04 17:09:46 +00:00
|
|
|
ADD_BSTR(frag, *frag_vaos);
|
2017-08-05 12:20:14 +00:00
|
|
|
add_uniforms(sc, frag);
|
2017-08-04 17:09:46 +00:00
|
|
|
|
|
|
|
ADD_BSTR(frag, sc->prelude_text);
|
|
|
|
ADD_BSTR(frag, sc->header_text);
|
|
|
|
|
|
|
|
ADD(frag, "void main() {\n");
|
|
|
|
// we require _all_ frag shaders to write to a "vec4 color"
|
|
|
|
ADD(frag, "vec4 color = vec4(0.0, 0.0, 0.0, 1.0);\n");
|
|
|
|
ADD_BSTR(frag, sc->text);
|
2017-08-05 12:20:14 +00:00
|
|
|
if (glsl_version >= 130) {
|
2017-08-04 17:09:46 +00:00
|
|
|
ADD(frag, "out_color = color;\n");
|
|
|
|
} else {
|
|
|
|
ADD(frag, "gl_FragColor = color;\n");
|
|
|
|
}
|
|
|
|
ADD(frag, "}\n");
|
2017-08-21 05:00:25 +00:00
|
|
|
|
|
|
|
// We need to fix the format of the render dst at renderpass creation
|
|
|
|
// time
|
|
|
|
assert(target_format);
|
|
|
|
sc->params.target_format = target_format;
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
if (type == RA_RENDERPASS_TYPE_COMPUTE) {
|
2017-08-04 17:09:46 +00:00
|
|
|
comp = &sc->tmp[4];
|
|
|
|
ADD_BSTR(comp, *header);
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
add_uniforms(sc, comp);
|
2017-08-04 17:09:46 +00:00
|
|
|
|
|
|
|
ADD_BSTR(comp, sc->prelude_text);
|
|
|
|
ADD_BSTR(comp, sc->header_text);
|
|
|
|
|
|
|
|
ADD(comp, "void main() {\n");
|
|
|
|
ADD(comp, "vec4 color = vec4(0.0, 0.0, 0.0, 1.0);\n"); // convenience
|
|
|
|
ADD_BSTR(comp, sc->text);
|
|
|
|
ADD(comp, "}\n");
|
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
bstr *hash_total = &sc->tmp[5];
|
|
|
|
|
|
|
|
ADD(hash_total, "type %d\n", sc->params.type);
|
|
|
|
|
|
|
|
if (frag) {
|
|
|
|
ADD_BSTR(hash_total, *frag);
|
|
|
|
sc->params.frag_shader = frag->start;
|
|
|
|
}
|
|
|
|
ADD(hash_total, "\n");
|
|
|
|
if (vert) {
|
|
|
|
ADD_BSTR(hash_total, *vert);
|
|
|
|
sc->params.vertex_shader = vert->start;
|
|
|
|
}
|
|
|
|
ADD(hash_total, "\n");
|
|
|
|
if (comp) {
|
|
|
|
ADD_BSTR(hash_total, *comp);
|
|
|
|
sc->params.compute_shader = comp->start;
|
|
|
|
}
|
|
|
|
ADD(hash_total, "\n");
|
|
|
|
|
|
|
|
if (sc->params.enable_blend) {
|
|
|
|
ADD(hash_total, "blend %d %d %d %d\n",
|
|
|
|
sc->params.blend_src_rgb, sc->params.blend_dst_rgb,
|
|
|
|
sc->params.blend_src_alpha, sc->params.blend_dst_alpha);
|
|
|
|
}
|
|
|
|
|
2017-08-21 05:00:25 +00:00
|
|
|
if (sc->params.target_format)
|
|
|
|
ADD(hash_total, "format %s\n", sc->params.target_format->name);
|
|
|
|
|
2017-08-04 17:09:46 +00:00
|
|
|
struct sc_entry *entry = NULL;
|
|
|
|
for (int n = 0; n < sc->num_entries; n++) {
|
2017-08-05 12:20:14 +00:00
|
|
|
struct sc_entry *cur = sc->entries[n];
|
|
|
|
if (bstr_equals(cur->total, *hash_total)) {
|
|
|
|
entry = cur;
|
|
|
|
break;
|
|
|
|
}
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
|
|
|
if (!entry) {
|
|
|
|
if (sc->num_entries == SC_MAX_ENTRIES)
|
|
|
|
sc_flush_cache(sc);
|
2017-08-05 12:20:14 +00:00
|
|
|
entry = talloc_ptrtype(NULL, entry);
|
2017-08-04 17:09:46 +00:00
|
|
|
*entry = (struct sc_entry){
|
2017-08-05 12:20:14 +00:00
|
|
|
.total = bstrdup(entry, *hash_total),
|
2017-08-05 16:20:45 +00:00
|
|
|
.timer = timer_pool_create(sc->ra),
|
2017-08-04 17:09:46 +00:00
|
|
|
};
|
2017-09-27 22:07:42 +00:00
|
|
|
|
|
|
|
// The vertex shader uses mangled names for the vertex attributes, so
|
|
|
|
// that the fragment shader can use the "real" names. But the shader is
|
|
|
|
// expecting the vertex attribute names (at least with older GLSL
|
|
|
|
// targets for GL).
|
|
|
|
sc->params.vertex_stride = vertex_stride;
|
|
|
|
for (int n = 0; n < vao_len; n++) {
|
|
|
|
struct ra_renderpass_input attrib = vao[n];
|
|
|
|
attrib.name = talloc_asprintf(entry, "vertex_%s", attrib.name);
|
|
|
|
MP_TARRAY_APPEND(sc, sc->params.vertex_attribs,
|
|
|
|
sc->params.num_vertex_attribs, attrib);
|
|
|
|
}
|
|
|
|
|
2017-08-04 17:09:46 +00:00
|
|
|
for (int n = 0; n < sc->num_uniforms; n++) {
|
2017-08-05 12:20:14 +00:00
|
|
|
struct sc_cached_uniform u = {0};
|
2017-09-08 02:27:53 +00:00
|
|
|
if (sc->uniforms[n].type == SC_UNIFORM_TYPE_GLOBAL) {
|
|
|
|
// global uniforms need to be made visible to the ra_renderpass
|
2017-08-26 03:58:50 +00:00
|
|
|
u.index = sc->params.num_inputs;
|
|
|
|
MP_TARRAY_APPEND(sc, sc->params.inputs, sc->params.num_inputs,
|
|
|
|
sc->uniforms[n].input);
|
|
|
|
}
|
2017-08-05 12:20:14 +00:00
|
|
|
MP_TARRAY_APPEND(entry, entry->cached_uniforms,
|
|
|
|
entry->num_cached_uniforms, u);
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
2017-08-26 03:58:50 +00:00
|
|
|
if (!create_pass(sc, entry))
|
|
|
|
sc->error_state = true;
|
2017-08-05 12:20:14 +00:00
|
|
|
MP_TARRAY_APPEND(sc, sc->entries, sc->num_entries, entry);
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|
2017-09-23 13:15:51 +00:00
|
|
|
|
|
|
|
if (!entry->pass) {
|
2017-09-18 03:42:54 +00:00
|
|
|
sc->current_shader = NULL;
|
2017-08-05 16:20:45 +00:00
|
|
|
return;
|
2017-09-18 03:42:54 +00:00
|
|
|
}
|
2017-08-04 17:09:46 +00:00
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
assert(sc->num_uniforms == entry->num_cached_uniforms);
|
2017-08-04 17:09:46 +00:00
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
sc->num_values = 0;
|
2017-08-04 17:09:46 +00:00
|
|
|
for (int n = 0; n < sc->num_uniforms; n++)
|
2017-08-05 12:20:14 +00:00
|
|
|
update_uniform(sc, entry, &sc->uniforms[n], n);
|
2017-08-04 17:09:46 +00:00
|
|
|
|
2017-08-26 03:58:50 +00:00
|
|
|
// If we're using a UBO, make sure to bind it as well
|
|
|
|
if (sc->ubo_size) {
|
|
|
|
struct ra_renderpass_input_val ubo_val = {
|
|
|
|
.index = entry->ubo_index,
|
|
|
|
.data = &entry->ubo,
|
|
|
|
};
|
|
|
|
MP_TARRAY_APPEND(sc, sc->values, sc->num_values, ubo_val);
|
|
|
|
}
|
|
|
|
|
2017-08-04 17:09:46 +00:00
|
|
|
sc->current_shader = entry;
|
|
|
|
}
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
struct mp_pass_perf gl_sc_dispatch_draw(struct gl_shader_cache *sc,
|
2017-08-18 00:31:58 +00:00
|
|
|
struct ra_tex *target, bool discard,
|
2017-09-27 22:07:42 +00:00
|
|
|
const struct ra_renderpass_input *vao,
|
|
|
|
int vao_len, size_t vertex_stride,
|
|
|
|
void *vertices, size_t num_vertices)
|
2017-08-04 17:09:46 +00:00
|
|
|
{
|
2017-08-05 16:20:45 +00:00
|
|
|
struct timer_pool *timer = NULL;
|
|
|
|
|
2017-08-18 00:31:58 +00:00
|
|
|
sc->params.invalidate_target = discard;
|
2017-09-27 22:07:42 +00:00
|
|
|
gl_sc_generate(sc, RA_RENDERPASS_TYPE_RASTER, target->params.format,
|
|
|
|
vao, vao_len, vertex_stride);
|
2017-08-05 12:20:14 +00:00
|
|
|
if (!sc->current_shader)
|
|
|
|
goto error;
|
|
|
|
|
2017-08-05 16:20:45 +00:00
|
|
|
timer = sc->current_shader->timer;
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
struct mp_rect full_rc = {0, 0, target->params.w, target->params.h};
|
2017-08-04 17:09:46 +00:00
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
struct ra_renderpass_run_params run = {
|
|
|
|
.pass = sc->current_shader->pass,
|
|
|
|
.values = sc->values,
|
|
|
|
.num_values = sc->num_values,
|
2017-09-08 04:13:55 +00:00
|
|
|
.push_constants = sc->current_shader->pushc,
|
2017-08-05 12:20:14 +00:00
|
|
|
.target = target,
|
2017-09-27 22:07:42 +00:00
|
|
|
.vertex_data = vertices,
|
|
|
|
.vertex_count = num_vertices,
|
2017-08-05 12:20:14 +00:00
|
|
|
.viewport = full_rc,
|
|
|
|
.scissors = full_rc,
|
|
|
|
};
|
|
|
|
|
2017-08-05 16:20:45 +00:00
|
|
|
timer_pool_start(timer);
|
2017-08-05 12:20:14 +00:00
|
|
|
sc->ra->fns->renderpass_run(sc->ra, &run);
|
2017-08-05 16:20:45 +00:00
|
|
|
timer_pool_stop(timer);
|
2017-08-05 12:20:14 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
gl_sc_reset(sc);
|
2017-08-05 16:20:45 +00:00
|
|
|
return timer_pool_measure(timer);
|
2017-08-05 12:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct mp_pass_perf gl_sc_dispatch_compute(struct gl_shader_cache *sc,
|
|
|
|
int w, int h, int d)
|
|
|
|
{
|
2017-08-05 16:20:45 +00:00
|
|
|
struct timer_pool *timer = NULL;
|
|
|
|
|
2017-09-27 22:07:42 +00:00
|
|
|
gl_sc_generate(sc, RA_RENDERPASS_TYPE_COMPUTE, NULL, NULL, 0, 0);
|
2017-08-05 12:20:14 +00:00
|
|
|
if (!sc->current_shader)
|
|
|
|
goto error;
|
|
|
|
|
2017-08-05 16:20:45 +00:00
|
|
|
timer = sc->current_shader->timer;
|
|
|
|
|
2017-08-05 12:20:14 +00:00
|
|
|
struct ra_renderpass_run_params run = {
|
|
|
|
.pass = sc->current_shader->pass,
|
|
|
|
.values = sc->values,
|
|
|
|
.num_values = sc->num_values,
|
2017-09-08 04:13:55 +00:00
|
|
|
.push_constants = sc->current_shader->pushc,
|
2017-08-05 12:20:14 +00:00
|
|
|
.compute_groups = {w, h, d},
|
|
|
|
};
|
|
|
|
|
2017-08-05 16:20:45 +00:00
|
|
|
timer_pool_start(timer);
|
2017-08-05 12:20:14 +00:00
|
|
|
sc->ra->fns->renderpass_run(sc->ra, &run);
|
2017-08-05 16:20:45 +00:00
|
|
|
timer_pool_stop(timer);
|
2017-08-05 12:20:14 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
gl_sc_reset(sc);
|
2017-08-05 16:20:45 +00:00
|
|
|
return timer_pool_measure(timer);
|
2017-08-04 17:09:46 +00:00
|
|
|
}
|