st_atom_constbuf.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void st_upload_constants (struct st_context *st, struct gl_program_parameter_list *params, unsigned id)
 Pass the given program parameters to the graphics pipe as a constant buffer.


Function Documentation

void st_upload_constants ( struct st_context st,
struct gl_program_parameter_list *  params,
unsigned  id 
)

Pass the given program parameters to the graphics pipe as a constant buffer.

Parameters:
id either PIPE_SHADER_VERTEX or PIPE_SHADER_FRAGMENT

Definition at line 52 of file st_atom_constbuf.c.

References assert, pipe_constant_buffer::buffer, st_context::constants, st_context::ctx, st_context::pipe, pipe_buffer_create(), pipe_buffer_map(), pipe_buffer_reference(), pipe_buffer_unmap(), PIPE_BUFFER_USAGE_CONSTANT, PIPE_BUFFER_USAGE_CPU_WRITE, PIPE_SHADER_FRAGMENT, PIPE_SHADER_VERTEX, pipe_context::screen, pipe_context::set_constant_buffer, pipe_constant_buffer::size, and st_context::state.

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    /* update constants */
00062    if (params && params->NumParameters) {
00063       const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4;
00064 
00065       /* Update our own dependency flags.  This works because this
00066        * function will also be called whenever the program changes.
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       /* We always need to get a new buffer, to keep the drivers simple and
00074        * avoid gratuitous rendering synchronization.
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       /* load Mesa constants into the constant buffer */
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       //  st->pipe->set_constant_buffer(st->pipe, id, 0, NULL);
00102    }
00103 }


Generated on Tue Sep 29 06:25:51 2009 for Gallium3D by  doxygen 1.5.4