From ac22178eb049126003db40b0a77a111498a12ab7 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 22 Apr 2009 11:52:16 -0600 Subject: i965: enable VS constant buffers In the VS constants can now be handled in two different ways: 1. If there's room in the GRF, put constants there. They're preloaded from the CURBE prior to VS execution. This is the historical approach. The problem is the GRF may not have room for all the shader's constants and temps and misc registers. Hence... 2. Use a separate constant buffer which is read from using a READ message. This allows a very large number of constants and frees up GRF regs for shader temporaries. This is the new approach. May be a little slower than 1. 1 vs. 2 is chosen according to how many constants and temps the shader needs. --- src/mesa/drivers/dri/i965/brw_vs_emit.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/mesa/drivers/dri/i965/brw_vs_emit.c') diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c b/src/mesa/drivers/dri/i965/brw_vs_emit.c index 524f1211ce..1da5a3f502 100644 --- a/src/mesa/drivers/dri/i965/brw_vs_emit.c +++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c @@ -69,13 +69,17 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c ) { GLuint i, reg = 0, mrf; -#if 0 - if (c->vp->program.Base.Parameters->NumParameters >= 6) - c->use_const_buffer = 1; + /* Determine whether to use a real constant buffer or use a block + * of GRF registers for constants. The later is faster but only + * works if everything fits in the GRF. + * XXX this heuristic/check may need some fine tuning... + */ + if (c->vp->program.Base.Parameters->NumParameters + + c->vp->program.Base.NumTemporaries + 20 > BRW_MAX_GRF) + c->use_const_buffer = GL_TRUE; else -#endif c->use_const_buffer = GL_FALSE; - /*printf("use_const_buffer = %d\n", c->use_const_buffer);*/ + printf("use_const_buffer = %d\n", c->use_const_buffer); /* r0 -- reserved as usual */ -- cgit v1.2.3 From ebfbd8c4fef78e3cd9604660e5bb96e3c6df07e5 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 22 Apr 2009 13:46:58 -0600 Subject: i965: disable debug printf --- src/mesa/drivers/dri/i965/brw_vs_emit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/drivers/dri/i965/brw_vs_emit.c') diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c b/src/mesa/drivers/dri/i965/brw_vs_emit.c index 1da5a3f502..c2b3702798 100644 --- a/src/mesa/drivers/dri/i965/brw_vs_emit.c +++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c @@ -79,7 +79,7 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c ) c->use_const_buffer = GL_TRUE; else c->use_const_buffer = GL_FALSE; - printf("use_const_buffer = %d\n", c->use_const_buffer); + /*printf("use_const_buffer = %d\n", c->use_const_buffer);*/ /* r0 -- reserved as usual */ -- cgit v1.2.3 From 777b9ff43e88e456d686208c83712f26aba2dd95 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 27 Apr 2009 10:45:41 -0600 Subject: i965: only upload constant buffer data when we actually need the const buffer Make the use_const_buffer field per-program and only call the code which updates the constant buffer's data if the flag is set. This should undo the perf regression from 20f3497e4b6756e330f7b3f54e8acaa1d6c92052 (cherry picked from master, commit dc9705d12d162ba6d087eb762e315de9f97bc456) --- src/mesa/drivers/dri/i965/brw_context.h | 2 ++ src/mesa/drivers/dri/i965/brw_curbe.c | 6 ++++-- src/mesa/drivers/dri/i965/brw_vs.h | 2 -- src/mesa/drivers/dri/i965/brw_vs_emit.c | 11 ++++++----- src/mesa/drivers/dri/i965/brw_wm.h | 2 -- src/mesa/drivers/dri/i965/brw_wm_glsl.c | 16 ++++++++++------ 6 files changed, 22 insertions(+), 17 deletions(-) (limited to 'src/mesa/drivers/dri/i965/brw_vs_emit.c') diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h index f0d4993e11..838e718d0d 100644 --- a/src/mesa/drivers/dri/i965/brw_context.h +++ b/src/mesa/drivers/dri/i965/brw_context.h @@ -161,6 +161,7 @@ struct brw_vertex_program { struct gl_vertex_program program; GLuint id; dri_bo *const_buffer; /** Program constant buffer/surface */ + GLboolean use_const_buffer; }; @@ -171,6 +172,7 @@ struct brw_fragment_program { GLboolean isGLSL; /**< really, any IF/LOOP/CONT/BREAK instructions */ dri_bo *const_buffer; /** Program constant buffer/surface */ + GLboolean use_const_buffer; }; diff --git a/src/mesa/drivers/dri/i965/brw_curbe.c b/src/mesa/drivers/dri/i965/brw_curbe.c index da746e4aa0..e6e26cdc40 100644 --- a/src/mesa/drivers/dri/i965/brw_curbe.c +++ b/src/mesa/drivers/dri/i965/brw_curbe.c @@ -368,7 +368,8 @@ update_vertex_constant_buffer(struct brw_context *brw) printf("update VS constants in buffer %p vp = %p\n", vp->const_buffer, vp); printf("program %u\n", vp->program.Base.Id); } - update_constant_buffer(brw, vp->program.Base.Parameters, vp->const_buffer); + if (vp->use_const_buffer) + update_constant_buffer(brw, vp->program.Base.Parameters, vp->const_buffer); } @@ -382,7 +383,8 @@ update_fragment_constant_buffer(struct brw_context *brw) printf("update WM constants in buffer %p\n", fp->const_buffer); printf("program %u\n", fp->program.Base.Id); } - update_constant_buffer(brw, fp->program.Base.Parameters, fp->const_buffer); + if (fp->use_const_buffer) + update_constant_buffer(brw, fp->program.Base.Parameters, fp->const_buffer); } diff --git a/src/mesa/drivers/dri/i965/brw_vs.h b/src/mesa/drivers/dri/i965/brw_vs.h index d20cf78b8a..1e4f66091e 100644 --- a/src/mesa/drivers/dri/i965/brw_vs.h +++ b/src/mesa/drivers/dri/i965/brw_vs.h @@ -75,8 +75,6 @@ struct brw_vs_compile { struct brw_reg userplane[6]; - /** using a real constant buffer? */ - GLboolean use_const_buffer; /** we may need up to 3 constants per instruction (if use_const_buffer) */ struct { GLint index; diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c b/src/mesa/drivers/dri/i965/brw_vs_emit.c index c2b3702798..b9a338b1cd 100644 --- a/src/mesa/drivers/dri/i965/brw_vs_emit.c +++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c @@ -76,9 +76,10 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c ) */ if (c->vp->program.Base.Parameters->NumParameters + c->vp->program.Base.NumTemporaries + 20 > BRW_MAX_GRF) - c->use_const_buffer = GL_TRUE; + c->vp->use_const_buffer = GL_TRUE; else - c->use_const_buffer = GL_FALSE; + c->vp->use_const_buffer = GL_FALSE; + /*printf("use_const_buffer = %d\n", c->use_const_buffer);*/ /* r0 -- reserved as usual @@ -100,7 +101,7 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c ) /* Vertex program parameters from curbe: */ - if (c->use_const_buffer) { + if (c->vp->use_const_buffer) { /* get constants from a real constant buffer */ c->prog_data.curb_read_length = 0; c->prog_data.nr_params = 4; /* XXX 0 causes a bug elsewhere... */ @@ -176,7 +177,7 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c ) reg++; } - if (c->use_const_buffer) { + if (c->vp->use_const_buffer) { for (i = 0; i < 3; i++) { c->current_const[i].index = -1; c->current_const[i].reg = brw_vec8_grf(reg, 0); @@ -873,7 +874,7 @@ get_src_reg( struct brw_vs_compile *c, case PROGRAM_STATE_VAR: case PROGRAM_CONSTANT: case PROGRAM_UNIFORM: - if (c->use_const_buffer) { + if (c->vp->use_const_buffer) { return get_constant(c, inst, argIndex); } else if (relAddr) { diff --git a/src/mesa/drivers/dri/i965/brw_wm.h b/src/mesa/drivers/dri/i965/brw_wm.h index 75205fddb7..2f80a60c12 100644 --- a/src/mesa/drivers/dri/i965/brw_wm.h +++ b/src/mesa/drivers/dri/i965/brw_wm.h @@ -257,8 +257,6 @@ struct brw_wm_compile { GLuint tmp_max; GLuint subroutines[BRW_WM_MAX_SUBROUTINE]; - /** using a real constant buffer? */ - GLboolean use_const_buffer; /** we may need up to 3 constants per instruction (if use_const_buffer) */ struct { GLint index; diff --git a/src/mesa/drivers/dri/i965/brw_wm_glsl.c b/src/mesa/drivers/dri/i965/brw_wm_glsl.c index 3471c1946e..eca4ca2c82 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_glsl.c +++ b/src/mesa/drivers/dri/i965/brw_wm_glsl.c @@ -311,12 +311,12 @@ static void prealloc_reg(struct brw_wm_compile *c) /* use a real constant buffer, or just use a section of the GRF? */ /* XXX this heuristic may need adjustment... */ if ((nr_params + nr_temps) * 4 + reg_index > 80) - c->use_const_buffer = GL_TRUE; + c->fp->use_const_buffer = GL_TRUE; else - c->use_const_buffer = GL_FALSE; + c->fp->use_const_buffer = GL_FALSE; /*printf("WM use_const_buffer = %d\n", c->use_const_buffer);*/ - if (c->use_const_buffer) { + if (c->fp->use_const_buffer) { /* We'll use a real constant buffer and fetch constants from * it with a dataport read message. */ @@ -377,12 +377,16 @@ static void prealloc_reg(struct brw_wm_compile *c) * They'll be found in these registers. * XXX alloc these on demand! */ - if (c->use_const_buffer) { + if (c->fp->use_const_buffer) { for (i = 0; i < 3; i++) { c->current_const[i].index = -1; c->current_const[i].reg = brw_vec8_grf(alloc_grf(c), 0); } } +#if 0 + printf("USE CONST BUFFER? %d\n", c->fp->use_const_buffer); + printf("AFTER PRE_ALLOC, reg_index = %d\n", c->reg_index); +#endif } @@ -488,7 +492,7 @@ static struct brw_reg get_src_reg(struct brw_wm_compile *c, const GLuint nr = 1; const GLuint component = GET_SWZ(src->Swizzle, channel); - if (c->use_const_buffer && + if (c->fp->use_const_buffer && (src->File == PROGRAM_STATE_VAR || src->File == PROGRAM_CONSTANT || src->File == PROGRAM_UNIFORM)) { @@ -2730,7 +2734,7 @@ static void brw_wm_emit_glsl(struct brw_context *brw, struct brw_wm_compile *c) #endif /* fetch any constants that this instruction needs */ - if (c->use_const_buffer) + if (c->fp->use_const_buffer) fetch_constants(c, inst); if (inst->CondUpdate) -- cgit v1.2.3