Only do so if there is a shader writing gl_ViewportIndex.
This removes a lot of CPU overhead for the most common case.
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
struct gl_program *new_gp = ctx->GeometryProgram._Current;
struct gl_program *new_fp = ctx->FragmentProgram._Current;
uint64_t dirty = 0;
+ unsigned num_viewports = 1;
/* Flag states used by both new and old shaders to unbind shader resources
* properly when transitioning to shaders that don't use them.
dirty |= st_fragment_program(new_fp)->affected_states;
}
+ /* Find out the number of viewports. This determines how many scissors
+ * and viewport states we need to update.
+ */
+ struct gl_program *last_prim_shader = new_gp ? new_gp :
+ new_tep ? new_tep : new_vp;
+ if (last_prim_shader &&
+ last_prim_shader->info.outputs_written & VARYING_BIT_VIEWPORT)
+ num_viewports = ctx->Const.MaxViewports;
+
+ if (st->state.num_viewports != num_viewports) {
+ st->state.num_viewports = num_viewports;
+ dirty |= ST_NEW_VIEWPORT;
+
+ if (ctx->Scissor.EnableFlags & u_bit_consecutive(0, num_viewports))
+ dirty |= ST_NEW_SCISSOR;
+ }
+
st->dirty |= dirty;
}
unsigned i;
bool changed = false;
- for (i = 0 ; i < ctx->Const.MaxViewports; i++) {
+ for (i = 0 ; i < st->state.num_viewports; i++) {
scissor[i].minx = 0;
scissor[i].miny = 0;
scissor[i].maxx = fb_width;
changed = true;
}
}
- if (changed)
- st->pipe->set_scissor_states(st->pipe, 0, ctx->Const.MaxViewports, scissor); /* activate */
+
+ if (changed) {
+ struct pipe_context *pipe = st->pipe;
+
+ pipe->set_scissor_states(pipe, 0, st->state.num_viewports, scissor);
+ }
}
void
/* _NEW_VIEWPORT
*/
- for (i = 0; i < ctx->Const.MaxViewports; i++) {
+ for (i = 0; i < st->state.num_viewports; i++) {
float *scale = st->state.viewport[i].scale;
float *translate = st->state.viewport[i].translate;
}
cso_set_viewport(st->cso_context, &st->state.viewport[0]);
- if (ctx->Const.MaxViewports > 1)
- st->pipe->set_viewport_states(st->pipe, 1, ctx->Const.MaxViewports - 1, &st->state.viewport[1]);
+
+ if (st->state.num_viewports > 1) {
+ struct pipe_context *pipe = st->pipe;
+
+ pipe->set_viewport_states(pipe, 1, st->state.num_viewports - 1,
+ &st->state.viewport[1]);
+ }
}
unsigned fb_height;
unsigned fb_num_samples;
unsigned fb_num_layers;
+ unsigned num_viewports;
struct pipe_scissor_state scissor[PIPE_MAX_VIEWPORTS];
struct pipe_viewport_state viewport[PIPE_MAX_VIEWPORTS];
struct {