i965: Use intel_upload_space() for pull constant uploads.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vs_surface_state.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a 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, sublicense, 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
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keithw@vmware.com>
30 */
31
32 #include "main/mtypes.h"
33 #include "program/prog_parameter.h"
34
35 #include "brw_context.h"
36 #include "brw_state.h"
37 #include "intel_buffer_objects.h"
38
39 void
40 brw_upload_vec4_pull_constants(struct brw_context *brw,
41 GLbitfield brw_new_constbuf,
42 const struct gl_program *prog,
43 struct brw_stage_state *stage_state,
44 const struct brw_vec4_prog_data *prog_data)
45 {
46 int i;
47 uint32_t surf_index = prog_data->base.binding_table.pull_constants_start;
48
49 /* Updates the ParamaterValues[i] pointers for all parameters of the
50 * basic type of PROGRAM_STATE_VAR.
51 */
52 _mesa_load_state_parameters(&brw->ctx, prog->Parameters);
53
54 if (!prog_data->base.nr_pull_params) {
55 if (stage_state->surf_offset[surf_index]) {
56 stage_state->surf_offset[surf_index] = 0;
57 brw->state.dirty.brw |= brw_new_constbuf;
58 }
59 return;
60 }
61
62 /* _NEW_PROGRAM_CONSTANTS */
63 uint32_t size = prog_data->base.nr_pull_params * 4;
64 drm_intel_bo *const_bo = NULL;
65 uint32_t const_offset;
66 float *constants = intel_upload_space(brw, size, 64,
67 &const_bo, &const_offset);
68
69 for (i = 0; i < prog_data->base.nr_pull_params; i++) {
70 constants[i] = *prog_data->base.pull_param[i];
71 }
72
73 if (0) {
74 for (i = 0; i < ALIGN(prog_data->base.nr_pull_params, 4) / 4; i++) {
75 float *row = &constants[i * 4];
76 fprintf(stderr, "const surface %3d: %4.3f %4.3f %4.3f %4.3f\n",
77 i, row[0], row[1], row[2], row[3]);
78 }
79 }
80
81 brw_create_constant_surface(brw, const_bo, const_offset, size,
82 &stage_state->surf_offset[surf_index],
83 false);
84 drm_intel_bo_unreference(const_bo);
85
86 brw->state.dirty.brw |= brw_new_constbuf;
87 }
88
89
90 /* Creates a new VS constant buffer reflecting the current VS program's
91 * constants, if needed by the VS program.
92 *
93 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
94 * state atom.
95 */
96 static void
97 brw_upload_vs_pull_constants(struct brw_context *brw)
98 {
99 struct brw_stage_state *stage_state = &brw->vs.base;
100
101 /* BRW_NEW_VERTEX_PROGRAM */
102 struct brw_vertex_program *vp =
103 (struct brw_vertex_program *) brw->vertex_program;
104
105 /* CACHE_NEW_VS_PROG */
106 const struct brw_vec4_prog_data *prog_data = &brw->vs.prog_data->base;
107
108 /* _NEW_PROGRAM_CONSTANTS */
109 brw_upload_vec4_pull_constants(brw, BRW_NEW_VS_CONSTBUF, &vp->program.Base,
110 stage_state, prog_data);
111 }
112
113 const struct brw_tracked_state brw_vs_pull_constants = {
114 .dirty = {
115 .mesa = (_NEW_PROGRAM_CONSTANTS),
116 .brw = (BRW_NEW_BATCH | BRW_NEW_VERTEX_PROGRAM),
117 .cache = CACHE_NEW_VS_PROG,
118 },
119 .emit = brw_upload_vs_pull_constants,
120 };
121
122 static void
123 brw_upload_vs_ubo_surfaces(struct brw_context *brw)
124 {
125 struct gl_context *ctx = &brw->ctx;
126 /* _NEW_PROGRAM */
127 struct gl_shader_program *prog =
128 ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
129
130 if (!prog)
131 return;
132
133 /* CACHE_NEW_VS_PROG */
134 brw_upload_ubo_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_VERTEX],
135 &brw->vs.base, &brw->vs.prog_data->base.base);
136 }
137
138 const struct brw_tracked_state brw_vs_ubo_surfaces = {
139 .dirty = {
140 .mesa = _NEW_PROGRAM,
141 .brw = BRW_NEW_BATCH | BRW_NEW_UNIFORM_BUFFER,
142 .cache = CACHE_NEW_VS_PROG,
143 },
144 .emit = brw_upload_vs_ubo_surfaces,
145 };
146
147 static void
148 brw_upload_vs_abo_surfaces(struct brw_context *brw)
149 {
150 struct gl_context *ctx = &brw->ctx;
151 /* _NEW_PROGRAM */
152 struct gl_shader_program *prog =
153 ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
154
155 if (prog) {
156 /* CACHE_NEW_VS_PROG */
157 brw_upload_abo_surfaces(brw, prog, &brw->vs.base,
158 &brw->vs.prog_data->base.base);
159 }
160 }
161
162 const struct brw_tracked_state brw_vs_abo_surfaces = {
163 .dirty = {
164 .mesa = _NEW_PROGRAM,
165 .brw = BRW_NEW_BATCH | BRW_NEW_ATOMIC_BUFFER,
166 .cache = CACHE_NEW_VS_PROG,
167 },
168 .emit = brw_upload_vs_abo_surfaces,
169 };