summaryrefslogtreecommitdiff
path: root/src/mesa/state_tracker
diff options
context:
space:
mode:
authorBrian <brian.paul@tungstengraphics.com>2007-08-22 12:24:51 -0600
committerBrian <brian.paul@tungstengraphics.com>2007-08-22 12:26:46 -0600
commitc0bb4ba9e665e40a325d82aa2ee48d7b8abd603b (patch)
tree48338074f07042599856e95b4529e0ffbca4be63 /src/mesa/state_tracker
parentd1fbf621dc48a488c0f860c5851332d269e6d637 (diff)
Rework of shader constant buffers.
They're now totally independent of the actual shaders. Also, implemented in terms of pipe_buffer_handles/objects.
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r--src/mesa/state_tracker/st_atom_fs.c38
-rw-r--r--src/mesa/state_tracker/st_atom_vs.c49
-rw-r--r--src/mesa/state_tracker/st_cb_clear.c2
-rw-r--r--src/mesa/state_tracker/st_cb_drawpixels.c2
-rw-r--r--src/mesa/state_tracker/st_context.h7
-rw-r--r--src/mesa/state_tracker/st_program.h4
6 files changed, 66 insertions, 36 deletions
diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c
index 9aba9aaa56..019b6457e0 100644
--- a/src/mesa/state_tracker/st_atom_fs.c
+++ b/src/mesa/state_tracker/st_atom_fs.c
@@ -32,6 +32,8 @@
#include "shader/prog_parameter.h"
#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_winsys.h"
#include "pipe/tgsi/mesa/mesa_to_tgsi.h"
#include "pipe/tgsi/core/tgsi_dump.h"
@@ -53,12 +55,36 @@ static void compile_fs( struct st_context *st,
}
+static void
+update_fs_constants(struct st_context *st,
+ struct gl_program_parameter_list *params)
+
+{
+ const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4;
+ struct pipe_winsys *ws = st->pipe->winsys;
+ struct pipe_constant_buffer *cbuf
+ = &st->state.constants[PIPE_SHADER_FRAGMENT];
+
+ if (!cbuf->buffer)
+ cbuf->buffer = ws->buffer_create(ws, 1);
+
+ /* load Mesa constants into the constant buffer */
+ if (paramBytes)
+ ws->buffer_data(ws, cbuf->buffer, paramBytes, params->ParameterValues);
+
+ cbuf->size = paramBytes;
+
+ st->pipe->set_constant_buffer(st->pipe, PIPE_SHADER_FRAGMENT, 0, cbuf);
+}
+
+
static void update_fs( struct st_context *st )
{
struct pipe_shader_state fs;
struct st_fragment_program *fp = NULL;
struct gl_program_parameter_list *params = NULL;
+ /* find active shader and params */
if (st->ctx->Shader.CurrentProgram &&
st->ctx->Shader.CurrentProgram->LinkStatus &&
st->ctx->Shader.CurrentProgram->FragmentProgram) {
@@ -72,25 +98,21 @@ static void update_fs( struct st_context *st )
params = st->ctx->FragmentProgram._Current->Base.Parameters;
}
+ /* update constants */
if (fp && params) {
- /* load program's constants array */
-
_mesa_load_state_parameters(st->ctx, params);
-
- fp->constants.nr_constants = params->NumParameters;
- memcpy(fp->constants.constant,
- params->ParameterValues,
- params->NumParameters * sizeof(GLfloat) * 4);
+ update_fs_constants(st, params);
}
+ /* translate shader to TGSI format */
if (fp->dirty)
compile_fs( st, fp );
+ /* update pipe state */
memset( &fs, 0, sizeof(fs) );
fs.inputs_read = fp->Base.Base.InputsRead;
fs.outputs_written = fp->Base.Base.OutputsWritten;
fs.tokens = &fp->tokens[0];
- fs.constants = &fp->constants;
if (memcmp(&fs, &st->state.fs, sizeof(fs)) != 0 ||
fp->dirty)
diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c
index c8bd805e02..8a38020afd 100644
--- a/src/mesa/state_tracker/st_atom_vs.c
+++ b/src/mesa/state_tracker/st_atom_vs.c
@@ -34,6 +34,8 @@
#include "tnl/t_vp_build.h"
#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_winsys.h"
#include "pipe/tgsi/mesa/mesa_to_tgsi.h"
#include "pipe/tgsi/core/tgsi_dump.h"
@@ -56,17 +58,36 @@ static void compile_vs( struct st_context *st,
}
+static void
+update_vs_constants(struct st_context *st,
+ struct gl_program_parameter_list *params)
+
+{
+ const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4;
+ struct pipe_winsys *ws = st->pipe->winsys;
+ struct pipe_constant_buffer *cbuf
+ = &st->state.constants[PIPE_SHADER_VERTEX];
+
+ if (!cbuf->buffer)
+ cbuf->buffer = ws->buffer_create(ws, 1);
+
+ /* load Mesa constants into the constant buffer */
+ if (paramBytes)
+ ws->buffer_data(ws, cbuf->buffer, paramBytes, params->ParameterValues);
+
+ cbuf->size = paramBytes;
+
+ st->pipe->set_constant_buffer(st->pipe, PIPE_SHADER_VERTEX, 0, cbuf);
+}
+
+
static void update_vs( struct st_context *st )
{
struct pipe_shader_state vs;
struct st_vertex_program *vp = NULL;
struct gl_program_parameter_list *params = NULL;
-#if 0
- if (st->ctx->VertexProgram._MaintainTnlProgram)
- _tnl_UpdateFixedFunctionProgram( st->ctx );
-#endif
-
+ /* find active shader and params */
if (st->ctx->Shader.CurrentProgram &&
st->ctx->Shader.CurrentProgram->LinkStatus &&
st->ctx->Shader.CurrentProgram->VertexProgram) {
@@ -80,31 +101,21 @@ static void update_vs( struct st_context *st )
params = st->ctx->VertexProgram._Current->Base.Parameters;
}
- /* XXXX temp */
-#if 1
- if (!vp)
- return;
-#endif
+ /* update constants */
if (vp && params) {
- /* load program's constants array */
-
- /* XXX this should probably be done elsewhere/separately */
_mesa_load_state_parameters(st->ctx, params);
-
- vp->constants.nr_constants = params->NumParameters;
- memcpy(vp->constants.constant,
- params->ParameterValues,
- params->NumParameters * sizeof(GLfloat) * 4);
+ update_vs_constants(st, params);
}
+ /* translate shader to TGSI format */
if (vp->dirty)
compile_vs( st, vp );
+ /* update pipe state */
memset( &vs, 0, sizeof(vs) );
vs.outputs_written = vp->Base.Base.OutputsWritten;
vs.inputs_read = vp->Base.Base.InputsRead;
vs.tokens = &vp->tokens[0];
- vs.constants = &vp->constants;
if (memcmp(&vs, &st->state.vs, sizeof(vs)) != 0 ||
vp->dirty)
diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index 2f2d11c014..e3690deb5a 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -350,7 +350,6 @@ clear_with_quad(GLcontext *ctx,
memset(&fs, 0, sizeof(fs));
fs.inputs_read = stfp->Base.Base.InputsRead;
fs.tokens = &stfp->tokens[0];
- fs.constants = NULL;
pipe->set_fs_state(pipe, &fs);
}
@@ -365,7 +364,6 @@ clear_with_quad(GLcontext *ctx,
vs.inputs_read = stvp->Base.Base.InputsRead;
vs.outputs_written = stvp->Base.Base.OutputsWritten;
vs.tokens = &stvp->tokens[0];
- vs.constants = NULL;
pipe->set_vs_state(pipe, &vs);
}
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index d3f060e691..a45700e1db 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -332,7 +332,6 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
memset(&fs, 0, sizeof(fs));
fs.inputs_read = stfp->Base.Base.InputsRead;
fs.tokens = &stfp->tokens[0];
- fs.constants = NULL;
pipe->set_fs_state(pipe, &fs);
}
@@ -347,7 +346,6 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
vs.inputs_read = stvp->Base.Base.InputsRead;
vs.outputs_written = stvp->Base.Base.OutputsWritten;
vs.tokens = &stvp->tokens[0];
- vs.constants = NULL;
pipe->set_vs_state(pipe, &vs);
}
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 35774a790e..38d6a3ed86 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -71,16 +71,17 @@ struct st_context
struct pipe_blend_color blend_color;
struct pipe_clear_color_state clear_color;
struct pipe_clip_state clip;
+ struct pipe_constant_buffer constants[2];
struct pipe_depth_state depth;
struct pipe_framebuffer_state framebuffer;
- struct pipe_shader_state fs;
- struct pipe_shader_state vs;
+ struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS];
struct pipe_poly_stipple poly_stipple;
struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS];
struct pipe_scissor_state scissor;
struct pipe_setup_state setup;
+ struct pipe_shader_state fs;
+ struct pipe_shader_state vs;
struct pipe_stencil_state stencil;
- struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS];
struct pipe_viewport_state viewport;
} state;
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index b077fdf069..3ff4f4e9c7 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -53,8 +53,6 @@ struct st_fragment_program
struct tgsi_token tokens[ST_FP_MAX_TOKENS];
GLboolean dirty;
- struct pipe_constant_buffer constants;
-
#if 0
GLfloat (*cbuffer)[4];
GLuint nr_constants;
@@ -85,7 +83,9 @@ struct st_vertex_program
struct tgsi_token tokens[ST_FP_MAX_TOKENS];
GLboolean dirty;
+#if 0
struct pipe_constant_buffer constants;
+#endif
GLuint param_state;
};