renderer: split out draw time sampler/ubo setup to separate functions

Trying to clean up the draw vbo functions a little.

The commit looks wierd, the final code looks better
macos/master
Dave Airlie 10 years ago
parent c76148ec17
commit 0a55b3264c
  1. 180
      src/vrend_renderer.c

@ -2390,84 +2390,11 @@ static void vrend_draw_bind_vertex_binding(struct vrend_context *ctx,
}
}
void vrend_draw_vbo(struct vrend_context *ctx,
const struct pipe_draw_info *info,
uint32_t cso)
static void vrend_draw_bind_samplers(struct vrend_context *ctx)
{
int i;
int sampler_id;
int ubo_id;
bool new_program = FALSE;
uint32_t shader_type;
if (ctx->in_error)
return;
if (ctx->ctx_switch_pending)
vrend_finish_context_switch(ctx);
vrend_update_frontface_state(ctx);
if (ctx->sub->stencil_state_dirty)
vrend_update_stencil_state(ctx);
if (ctx->sub->scissor_state_dirty)
vrend_update_scissor_state(ctx);
if (ctx->sub->viewport_state_dirty)
vrend_update_viewport_state(ctx);
vrend_patch_blend_func(ctx);
if (ctx->sub->shader_dirty) {
struct vrend_linked_shader_program *prog;
boolean fs_dirty, vs_dirty, gs_dirty;
boolean dual_src = util_blend_state_is_dual(&ctx->sub->blend_state, 0);
if (!ctx->sub->vs || !ctx->sub->fs) {
fprintf(stderr,"dropping rendering due to missing shaders: %s\n", ctx->debug_name);
return;
}
vrend_shader_select(ctx, ctx->sub->fs, &fs_dirty);
vrend_shader_select(ctx, ctx->sub->vs, &vs_dirty);
if (ctx->sub->gs)
vrend_shader_select(ctx, ctx->sub->gs, &gs_dirty);
if (!ctx->sub->vs->current || !ctx->sub->fs->current || (ctx->sub->gs && !ctx->sub->gs->current)) {
fprintf(stderr, "failure to compile shader variants: %s\n", ctx->debug_name);
return;
}
prog = lookup_shader_program(ctx, ctx->sub->vs->current->id, ctx->sub->fs->current->id, ctx->sub->gs ? ctx->sub->gs->current->id : 0, dual_src);
if (!prog) {
prog = add_shader_program(ctx, ctx->sub->vs->current, ctx->sub->fs->current, ctx->sub->gs ? ctx->sub->gs->current : NULL);
if (!prog)
return;
}
if (ctx->sub->prog != prog) {
new_program = TRUE;
ctx->sub->prog = prog;
}
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->sub->fb_id);
vrend_use_program(ctx, ctx->sub->prog->id);
for (shader_type = PIPE_SHADER_VERTEX; shader_type <= (ctx->sub->gs ? PIPE_SHADER_GEOMETRY : PIPE_SHADER_FRAGMENT); shader_type++) {
if (ctx->sub->prog->const_locs[shader_type] && (ctx->sub->const_dirty[shader_type] || new_program)) {
int nc;
if (shader_type == PIPE_SHADER_VERTEX) {
nc = ctx->sub->vs->sinfo.num_consts;
} else if (shader_type == PIPE_SHADER_GEOMETRY) {
nc = ctx->sub->gs->sinfo.num_consts;
} else if (shader_type == PIPE_SHADER_FRAGMENT) {
nc = ctx->sub->fs->sinfo.num_consts;
}
for (i = 0; i < nc; i++) {
if (ctx->sub->prog->const_locs[shader_type][i] != -1 && ctx->sub->consts[shader_type].consts)
glUniform4uiv(ctx->sub->prog->const_locs[shader_type][i], 1, &ctx->sub->consts[shader_type].consts[i * 4]);
}
ctx->sub->const_dirty[shader_type] = FALSE;
}
}
int i;
int shader_type;
sampler_id = 0;
for (shader_type = PIPE_SHADER_VERTEX; shader_type <= (ctx->sub->gs ? PIPE_SHADER_GEOMETRY : PIPE_SHADER_FRAGMENT); shader_type++) {
@ -2527,6 +2454,20 @@ void vrend_draw_vbo(struct vrend_context *ctx,
}
}
if (use_core_profile && ctx->sub->prog->fs_stipple_loc != -1) {
glActiveTexture(GL_TEXTURE0 + sampler_id);
glBindTexture(GL_TEXTURE_2D, ctx->pstipple_tex_id);
glUniform1i(ctx->sub->prog->fs_stipple_loc, sampler_id);
}
ctx->sub->sampler_state_dirty = FALSE;
}
static void vrend_draw_bind_ubo(struct vrend_context *ctx)
{
int i;
int ubo_id;
int shader_type;
ubo_id = 0;
for (shader_type = PIPE_SHADER_VERTEX; shader_type <= (ctx->sub->gs ? PIPE_SHADER_GEOMETRY : PIPE_SHADER_FRAGMENT); shader_type++) {
uint32_t mask;
@ -2552,8 +2493,88 @@ void vrend_draw_vbo(struct vrend_context *ctx,
ubo_id++;
}
}
}
ctx->sub->sampler_state_dirty = FALSE;
void vrend_draw_vbo(struct vrend_context *ctx,
const struct pipe_draw_info *info,
uint32_t cso)
{
int i;
bool new_program = FALSE;
uint32_t shader_type;
if (ctx->in_error)
return;
if (ctx->ctx_switch_pending)
vrend_finish_context_switch(ctx);
vrend_update_frontface_state(ctx);
if (ctx->sub->stencil_state_dirty)
vrend_update_stencil_state(ctx);
if (ctx->sub->scissor_state_dirty)
vrend_update_scissor_state(ctx);
if (ctx->sub->viewport_state_dirty)
vrend_update_viewport_state(ctx);
vrend_patch_blend_func(ctx);
if (ctx->sub->shader_dirty) {
struct vrend_linked_shader_program *prog;
boolean fs_dirty, vs_dirty, gs_dirty;
boolean dual_src = util_blend_state_is_dual(&ctx->sub->blend_state, 0);
if (!ctx->sub->vs || !ctx->sub->fs) {
fprintf(stderr,"dropping rendering due to missing shaders: %s\n", ctx->debug_name);
return;
}
vrend_shader_select(ctx, ctx->sub->fs, &fs_dirty);
vrend_shader_select(ctx, ctx->sub->vs, &vs_dirty);
if (ctx->sub->gs)
vrend_shader_select(ctx, ctx->sub->gs, &gs_dirty);
if (!ctx->sub->vs->current || !ctx->sub->fs->current || (ctx->sub->gs && !ctx->sub->gs->current)) {
fprintf(stderr, "failure to compile shader variants: %s\n", ctx->debug_name);
return;
}
prog = lookup_shader_program(ctx, ctx->sub->vs->current->id, ctx->sub->fs->current->id, ctx->sub->gs ? ctx->sub->gs->current->id : 0, dual_src);
if (!prog) {
prog = add_shader_program(ctx, ctx->sub->vs->current, ctx->sub->fs->current, ctx->sub->gs ? ctx->sub->gs->current : NULL);
if (!prog)
return;
}
if (ctx->sub->prog != prog) {
new_program = TRUE;
ctx->sub->prog = prog;
}
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->sub->fb_id);
vrend_use_program(ctx, ctx->sub->prog->id);
for (shader_type = PIPE_SHADER_VERTEX; shader_type <= (ctx->sub->gs ? PIPE_SHADER_GEOMETRY : PIPE_SHADER_FRAGMENT); shader_type++) {
if (ctx->sub->prog->const_locs[shader_type] && (ctx->sub->const_dirty[shader_type] || new_program)) {
int nc;
if (shader_type == PIPE_SHADER_VERTEX) {
nc = ctx->sub->vs->sinfo.num_consts;
} else if (shader_type == PIPE_SHADER_GEOMETRY) {
nc = ctx->sub->gs->sinfo.num_consts;
} else if (shader_type == PIPE_SHADER_FRAGMENT) {
nc = ctx->sub->fs->sinfo.num_consts;
}
for (i = 0; i < nc; i++) {
if (ctx->sub->prog->const_locs[shader_type][i] != -1 && ctx->sub->consts[shader_type].consts)
glUniform4uiv(ctx->sub->prog->const_locs[shader_type][i], 1, &ctx->sub->consts[shader_type].consts[i * 4]);
}
ctx->sub->const_dirty[shader_type] = FALSE;
}
}
vrend_draw_bind_samplers(ctx);
vrend_draw_bind_ubo(ctx);
if (!ctx->sub->ve) {
fprintf(stderr,"illegal VE setup - skipping renderering\n");
@ -2561,11 +2582,6 @@ void vrend_draw_vbo(struct vrend_context *ctx,
}
glUniform4f(ctx->sub->prog->vs_ws_adjust_loc, 0.0, ctx->sub->viewport_is_negative ? -1.0 : 1.0, ctx->sub->depth_scale, ctx->sub->depth_transform);
if (use_core_profile && ctx->sub->prog->fs_stipple_loc != -1) {
glActiveTexture(GL_TEXTURE0 + sampler_id);
glBindTexture(GL_TEXTURE_2D, ctx->pstipple_tex_id);
glUniform1i(ctx->sub->prog->fs_stipple_loc, sampler_id);
}
if (ctx->sub->rs_state.clip_plane_enable) {
for (i = 0 ; i < 8; i++) {

Loading…
Cancel
Save