st_atom_constbuf.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027  /*
00028   * Authors:
00029   *   Keith Whitwell <keith@tungstengraphics.com>
00030   *   Brian Paul
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    /* 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 }
00104 
00105 /* Vertex shader:
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",                            /* name */
00117    {                                                    /* dirty */
00118       0,  /* set dynamically above */                   /* mesa */
00119       ST_NEW_VERTEX_PROGRAM,                            /* st */
00120    },
00121    update_vs_constants                                  /* update */
00122 };
00123 
00124 /* Fragment shader:
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",                            /* name */
00136    {                                                    /* dirty */
00137       0,  /* set dynamically above */                   /* mesa */
00138       ST_NEW_FRAGMENT_PROGRAM,                          /* st */
00139    },
00140    update_fs_constants                                  /* update */
00141 };
00142 

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