00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "main/imports.h"
00034 #include "shader/prog_parameter.h"
00035 #include "shader/prog_print.h"
00036
00037 #include "pipe/p_context.h"
00038 #include "pipe/p_defines.h"
00039 #include "pipe/p_inlines.h"
00040
00041 #include "st_context.h"
00042 #include "st_atom.h"
00043 #include "st_atom_constbuf.h"
00044 #include "st_program.h"
00045
00046
00052 void st_upload_constants( struct st_context *st,
00053 struct gl_program_parameter_list *params,
00054 unsigned id)
00055 {
00056 struct pipe_context *pipe = st->pipe;
00057 struct pipe_constant_buffer *cbuf = &st->state.constants[id];
00058
00059 assert(id == PIPE_SHADER_VERTEX || id == PIPE_SHADER_FRAGMENT);
00060
00061
00062 if (params && params->NumParameters) {
00063 const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4;
00064
00065
00066
00067
00068 st->constants.tracked_state[id].dirty.mesa =
00069 (params->StateFlags | _NEW_PROGRAM);
00070
00071 _mesa_load_state_parameters(st->ctx, params);
00072
00073
00074
00075
00076 pipe_buffer_reference(pipe->screen, &cbuf->buffer, NULL );
00077 cbuf->buffer = pipe_buffer_create(pipe->screen, 16, PIPE_BUFFER_USAGE_CONSTANT,
00078 paramBytes );
00079
00080 if (0)
00081 {
00082 printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n",
00083 __FUNCTION__, id, params->NumParameters, params->StateFlags);
00084 _mesa_print_parameter_list(params);
00085 }
00086
00087
00088 if (cbuf->buffer) {
00089 void *map = pipe_buffer_map(pipe->screen, cbuf->buffer,
00090 PIPE_BUFFER_USAGE_CPU_WRITE);
00091 memcpy(map, params->ParameterValues, paramBytes);
00092 pipe_buffer_unmap(pipe->screen, cbuf->buffer);
00093 }
00094
00095 cbuf->size = paramBytes;
00096
00097 st->pipe->set_constant_buffer(st->pipe, id, 0, cbuf);
00098 }
00099 else {
00100 st->constants.tracked_state[id].dirty.mesa = 0;
00101
00102 }
00103 }
00104
00105
00106
00107 static void update_vs_constants(struct st_context *st )
00108 {
00109 struct st_vertex_program *vp = st->vp;
00110 struct gl_program_parameter_list *params = vp->Base.Base.Parameters;
00111
00112 st_upload_constants( st, params, PIPE_SHADER_VERTEX );
00113 }
00114
00115 const struct st_tracked_state st_update_vs_constants = {
00116 "st_update_vs_constants",
00117 {
00118 0,
00119 ST_NEW_VERTEX_PROGRAM,
00120 },
00121 update_vs_constants
00122 };
00123
00124
00125
00126 static void update_fs_constants(struct st_context *st )
00127 {
00128 struct st_fragment_program *fp = st->fp;
00129 struct gl_program_parameter_list *params = fp->Base.Base.Parameters;
00130
00131 st_upload_constants( st, params, PIPE_SHADER_FRAGMENT );
00132 }
00133
00134 const struct st_tracked_state st_update_fs_constants = {
00135 "st_update_fs_constants",
00136 {
00137 0,
00138 ST_NEW_FRAGMENT_PROGRAM,
00139 },
00140 update_fs_constants
00141 };
00142