[virglrenderer-devel] shader: get maximum number of render targets dynamically
Ramin Azarmehr
ramin.azarmehr at gmail.com
Mon Jun 11 14:46:40 UTC 2018
Thank you Gurchetan. The problem is that the context 0 (master) is created
in vrend_renderer_init(), before caps parameters are populated in
vrend_renderer_fill_caps_common(). So, we'll get "illegal shader" errors at
initialization stage if vrend_state.max_draw_buffers is set in fill_caps
(tested that).
In the following patch I added max_draw_buffers to vrend_state, but set it
at vrend_renderer_init() before context 0 is created. Let me know if this
is fine.
---
diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index 8fd113b..c7f41a4 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -123,6 +123,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 */
@@ -4297,6 +4298,7 @@ int vrend_renderer_init(struct vrend_if_cbs *cbs,
uint32_t flags)
if (vrend_state.have_debug_cb) {
glDisable(GL_DEBUG_OUTPUT);
}
+ glGetIntegerv(GL_MAX_DRAW_BUFFERS, (GLint *)
&vrend_state.max_draw_buffers);
vrend_clicbs->destroy_gl_context(gl_context);
list_inithead(&vrend_state.fence_list);
@@ -4463,6 +4465,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);
@@ -6734,8 +6737,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 8cc695a..d477d67 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -994,7 +994,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)
@@ -2963,7 +2963,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 149f389..bcfa78e 100644
--- a/src/vrend_shader.h
+++ b/src/vrend_shader.h
@@ -90,6 +90,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;
On Fri, Jun 8, 2018 at 6:21 PM, Gurchetan Singh <gurchetansingh at chromium.org
> wrote:
> On Fri, Jun 8, 2018 at 2:39 PM Ramin Azarmehr <ramin.azarmehr at gmail.com>
> wrote:
> >
> > Not all platforms have 8 render targets. So, get the maximum draw
> buffers at runtime, and pass to shader.
> > e.g., on i.MX8 QuadMax platform (dual GPU), there are only 4 draw
> buffers per GPU, causing shader compile failures with current virgl code.
> >
> > P.S.: I'm new to this mailing list system; please advise if there's any
> problem with my posting style so I can correct before posting my other
> patches. Thanks.
>
> Posting style is definitely fine, please do send more patches :-)
>
> > ---
> > diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
> > index 8fd113b..f43c944 100644
> > --- a/src/vrend_renderer.c
> > +++ b/src/vrend_renderer.c
> > @@ -4466,6 +4466,7 @@ struct vrend_context *vrend_create_context(int id,
> uint32_t nlen, const char *de
> > vrend_renderer_create_sub_ctx(grctx, 0);
> > vrend_renderer_set_sub_ctx(grctx, 0);
> >
> > + glGetIntegerv(GL_MAX_DRAW_BUFFERS, &grctx->shader_cfg.max_draw_
> buffers);
>
> nit: typically this code derives the shader_cfg from the vrend_state.
> Since we already query for GL_MAX_DRAW_BUFFERS in
> vrend_renderer_fill_caps_common, can you just add a field vrend_state
> (like max_uniform_blocks) and copy it in vrend_create_context?
>
> > vrender_get_glsl_version(&grctx->shader_cfg.glsl_version);
> >
> > list_addtail(&grctx->ctx_entry, &vrend_state.active_ctx_list);diff
> --git a/src/vrend_shader.c b/src/vrend_shader.c
> > index 8cc695a..d477d67 100644
> > --- a/src/vrend_shader.c
> > +++ b/src/vrend_shader.c
> > @@ -994,7 +994,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)
> > @@ -2963,7 +2963,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);
> > elsediff --git a/src/vrend_shader.h b/src/vrend_shader.h
> > index 149f389..bcfa78e 100644
> > --- a/src/vrend_shader.h
> > +++ b/src/vrend_shader.h
> > @@ -90,6 +90,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;
> > _______________________________________________
> > virglrenderer-devel mailing list
> > virglrenderer-devel at lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/virglrenderer-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/virglrenderer-devel/attachments/20180611/16d5ba38/attachment.html>
More information about the virglrenderer-devel
mailing list