From a01122fe2669e042188b4ee38a506afec9c37cf9 Mon Sep 17 00:00:00 2001 From: Ramin Azarmehr Date: Tue, 12 Jun 2018 13:35:17 -0400 Subject: [PATCH] shader: get maximum number of render targets dynamically [airlied: pushed the get up a bit higher to make it cleaner] Reviewed-by: Jakob Bornecrantz Reviewed-by: Dave Airlie --- src/vrend_renderer.c | 7 +++++-- src/vrend_shader.c | 4 ++-- src/vrend_shader.h | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 465e194..8f8eb74 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -122,6 +122,7 @@ struct global_renderer_state { /* these appeared broken on at least one driver */ bool use_explicit_locations; uint32_t max_uniform_blocks; + uint32_t max_draw_buffers; struct list_head active_ctx_list; /* threaded sync */ @@ -4378,6 +4379,8 @@ int vrend_renderer_init(struct vrend_if_cbs *cbs, uint32_t flags) fprintf(stderr, "gl_version %d - compat profile\n", gl_ver); } + glGetIntegerv(GL_MAX_DRAW_BUFFERS, (GLint *) &vrend_state.max_draw_buffers); + if (epoxy_has_gl_extension("GL_ARB_robustness")) { vrend_state.have_arb_robustness = true; } else if (gles && epoxy_has_gl_extension("GL_KHR_robustness")) { @@ -4634,6 +4637,7 @@ struct vrend_context *vrend_create_context(int id, uint32_t nlen, const char *de grctx->shader_cfg.use_gles = vrend_state.use_gles; grctx->shader_cfg.use_core_profile = vrend_state.use_core_profile; grctx->shader_cfg.use_explicit_locations = vrend_state.use_explicit_locations; + grctx->shader_cfg.max_draw_buffers = vrend_state.max_draw_buffers; vrend_renderer_create_sub_ctx(grctx, 0); vrend_renderer_set_sub_ctx(grctx, 0); @@ -7012,8 +7016,7 @@ static bool vrend_renderer_fill_caps_common(uint32_t set, UNUSED uint32_t versio /* Common limits for all backends. */ - glGetIntegerv(GL_MAX_DRAW_BUFFERS, &max); - caps->v1.max_render_targets = max; + caps->v1.max_render_targets = vrend_state.max_draw_buffers; glGetIntegerv(GL_MAX_SAMPLES, &max); caps->v1.max_samples = max; diff --git a/src/vrend_shader.c b/src/vrend_shader.c index 99da6e2..3b17c5b 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -1208,7 +1208,7 @@ static int emit_cbuf_writes(struct dump_ctx *ctx) int i; char *sret; - for (i = ctx->num_outputs; i < 8; i++) { + for (i = ctx->num_outputs; i < ctx->cfg->max_draw_buffers; i++) { snprintf(buf, 255, "fsout_c%d = fsout_c0;\n", i); sret = add_str_to_glsl_main(ctx, buf); if (!sret) @@ -3494,7 +3494,7 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr) } if (ctx->write_all_cbufs) { - for (i = 0; i < 8; i++) { + for (i = 0; i < ctx->cfg->max_draw_buffers; i++) { if (ctx->cfg->use_gles) snprintf(buf, 255, "layout (location=%d) out vec4 fsout_c%d;\n", i, i); else diff --git a/src/vrend_shader.h b/src/vrend_shader.h index b7e7981..a20d1be 100644 --- a/src/vrend_shader.h +++ b/src/vrend_shader.h @@ -102,6 +102,7 @@ struct vrend_shader_key { struct vrend_shader_cfg { int glsl_version; + int max_draw_buffers; bool use_gles; bool use_core_profile; bool use_explicit_locations;