gallium: check if surface has defined status in check_clear_depth_with_quad()
[mesa.git] / src / mesa / state_tracker / st_atom_constbuf.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 * Brian Paul
31 */
32
33 #include "main/imports.h"
34 #include "shader/prog_parameter.h"
35 #include "shader/prog_print.h"
36
37 #include "pipe/p_context.h"
38 #include "pipe/p_defines.h"
39 #include "pipe/p_winsys.h"
40 #include "pipe/p_inlines.h"
41
42 #include "st_context.h"
43 #include "st_atom.h"
44 #include "st_atom_constbuf.h"
45 #include "st_program.h"
46
47
48 /**
49 * Pass the given program parameters to the graphics pipe as a
50 * constant buffer.
51 * \param id either PIPE_SHADER_VERTEX or PIPE_SHADER_FRAGMENT
52 */
53 void st_upload_constants( struct st_context *st,
54 struct gl_program_parameter_list *params,
55 unsigned id)
56 {
57 struct pipe_winsys *ws = st->pipe->winsys;
58 struct pipe_constant_buffer *cbuf = &st->state.constants[id];
59
60 assert(id == PIPE_SHADER_VERTEX || id == PIPE_SHADER_FRAGMENT);
61
62 /* update constants */
63 if (params && params->NumParameters) {
64 const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4;
65
66 /* Update our own dependency flags. This works because this
67 * function will also be called whenever the program changes.
68 */
69 st->constants.tracked_state[id].dirty.mesa = params->StateFlags;
70
71 _mesa_load_state_parameters(st->ctx, params);
72
73 if (cbuf->buffer && cbuf->size != paramBytes)
74 pipe_buffer_reference( ws, &cbuf->buffer, NULL );
75
76 if (!cbuf->buffer) {
77 cbuf->buffer = ws->buffer_create(ws, 1, PIPE_BUFFER_USAGE_CONSTANT,
78 paramBytes);
79 }
80
81 if (0)
82 {
83 printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n",
84 __FUNCTION__, id, params->NumParameters, params->StateFlags);
85 _mesa_print_parameter_list(params);
86 }
87
88 /* load Mesa constants into the constant buffer */
89 if (cbuf->buffer) {
90 memcpy(ws->buffer_map(ws, cbuf->buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
91 params->ParameterValues, paramBytes);
92 ws->buffer_unmap(ws, cbuf->buffer);
93 }
94
95 cbuf->size = paramBytes;
96
97 st->pipe->set_constant_buffer(st->pipe, id, 0, cbuf);
98 }
99 else {
100 st->constants.tracked_state[id].dirty.mesa = 0;
101 // st->pipe->set_constant_buffer(st->pipe, id, 0, NULL);
102 }
103 }
104
105 /* Vertex shader:
106 */
107 static void update_vs_constants(struct st_context *st )
108 {
109 struct st_vertex_program *vp = st->vp;
110 struct gl_program_parameter_list *params = vp->Base.Base.Parameters;
111
112 st_upload_constants( st, params, PIPE_SHADER_VERTEX );
113 }
114
115 const struct st_tracked_state st_update_vs_constants = {
116 .name = "st_update_vs_constants",
117 .dirty = {
118 .mesa = 0,
119 .st = ST_NEW_VERTEX_PROGRAM,
120 },
121 .update = update_vs_constants
122 };
123
124 /* Fragment shader:
125 */
126 static void update_fs_constants(struct st_context *st )
127 {
128 struct st_fragment_program *fp = st->fp;
129 struct gl_program_parameter_list *params = fp->Base.Base.Parameters;
130
131 st_upload_constants( st, params, PIPE_SHADER_FRAGMENT );
132 }
133
134 const struct st_tracked_state st_update_fs_constants = {
135 .name = "st_update_fs_constants",
136 .dirty = {
137 .mesa = 0,
138 .st = ST_NEW_FRAGMENT_PROGRAM,
139 },
140 .update = update_fs_constants
141 };
142