i965: Add new SIMD8 VS prog data flag
[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 /**
40 * Creates a temporary BO containing the pull constant data for the shader
41 * stage, and the SURFACE_STATE struct that points at it.
42 *
43 * Pull constants are GLSL uniforms (and other constant data) beyond what we
44 * could fit as push constants, or that have variable-index array access
45 * (which is easiest to support using pull constants, and avoids filling
46 * register space with mostly-unused data).
47 *
48 * Compare this path to brw_curbe.c for gen4/5 push constants, and
49 * gen6_vs_state.c for gen6+ push constants.
50 */
51 void
52 brw_upload_pull_constants(struct brw_context *brw,
53 GLbitfield brw_new_constbuf,
54 const struct gl_program *prog,
55 struct brw_stage_state *stage_state,
56 const struct brw_stage_prog_data *prog_data,
57 bool dword_pitch)
58 {
59 int i;
60 uint32_t surf_index = prog_data->binding_table.pull_constants_start;
61
62 if (!prog_data->nr_pull_params) {
63 if (stage_state->surf_offset[surf_index]) {
64 stage_state->surf_offset[surf_index] = 0;
65 brw->state.dirty.brw |= brw_new_constbuf;
66 }
67 return;
68 }
69
70 /* Updates the ParamaterValues[i] pointers for all parameters of the
71 * basic type of PROGRAM_STATE_VAR.
72 */
73 _mesa_load_state_parameters(&brw->ctx, prog->Parameters);
74
75 /* BRW_NEW_*_PROG_DATA | _NEW_PROGRAM_CONSTANTS */
76 uint32_t size = prog_data->nr_pull_params * 4;
77 drm_intel_bo *const_bo = NULL;
78 uint32_t const_offset;
79 gl_constant_value *constants = intel_upload_space(brw, size, 64,
80 &const_bo, &const_offset);
81
82 STATIC_ASSERT(sizeof(gl_constant_value) == sizeof(float));
83
84 for (i = 0; i < prog_data->nr_pull_params; i++) {
85 constants[i] = *prog_data->pull_param[i];
86 }
87
88 if (0) {
89 for (i = 0; i < ALIGN(prog_data->nr_pull_params, 4) / 4; i++) {
90 const gl_constant_value *row = &constants[i * 4];
91 fprintf(stderr, "const surface %3d: %4.3f %4.3f %4.3f %4.3f\n",
92 i, row[0].f, row[1].f, row[2].f, row[3].f);
93 }
94 }
95
96 brw_create_constant_surface(brw, const_bo, const_offset, size,
97 &stage_state->surf_offset[surf_index],
98 dword_pitch);
99 drm_intel_bo_unreference(const_bo);
100
101 brw->state.dirty.brw |= brw_new_constbuf;
102 }
103
104
105 /* Creates a new VS constant buffer reflecting the current VS program's
106 * constants, if needed by the VS program.
107 *
108 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
109 * state atom.
110 */
111 static void
112 brw_upload_vs_pull_constants(struct brw_context *brw)
113 {
114 struct brw_stage_state *stage_state = &brw->vs.base;
115 bool dword_pitch;
116
117 /* BRW_NEW_VERTEX_PROGRAM */
118 struct brw_vertex_program *vp =
119 (struct brw_vertex_program *) brw->vertex_program;
120
121 /* BRW_NEW_VS_PROG_DATA */
122 const struct brw_stage_prog_data *prog_data = &brw->vs.prog_data->base.base;
123
124 dword_pitch = brw->vs.prog_data->base.simd8;
125
126 /* _NEW_PROGRAM_CONSTANTS */
127 brw_upload_pull_constants(brw, BRW_NEW_VS_CONSTBUF, &vp->program.Base,
128 stage_state, prog_data, dword_pitch);
129 }
130
131 const struct brw_tracked_state brw_vs_pull_constants = {
132 .dirty = {
133 .mesa = _NEW_PROGRAM_CONSTANTS,
134 .brw = BRW_NEW_BATCH |
135 BRW_NEW_VERTEX_PROGRAM |
136 BRW_NEW_VS_PROG_DATA,
137 },
138 .emit = brw_upload_vs_pull_constants,
139 };
140
141 static void
142 brw_upload_vs_ubo_surfaces(struct brw_context *brw)
143 {
144 struct gl_context *ctx = &brw->ctx;
145 /* _NEW_PROGRAM */
146 struct gl_shader_program *prog =
147 ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
148 bool dword_pitch;
149
150 if (!prog)
151 return;
152
153 /* BRW_NEW_VS_PROG_DATA */
154 dword_pitch = brw->vs.prog_data->base.simd8;
155 brw_upload_ubo_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_VERTEX],
156 &brw->vs.base, &brw->vs.prog_data->base.base,
157 dword_pitch);
158 }
159
160 const struct brw_tracked_state brw_vs_ubo_surfaces = {
161 .dirty = {
162 .mesa = _NEW_PROGRAM,
163 .brw = BRW_NEW_BATCH |
164 BRW_NEW_UNIFORM_BUFFER |
165 BRW_NEW_VS_PROG_DATA,
166 },
167 .emit = brw_upload_vs_ubo_surfaces,
168 };
169
170 static void
171 brw_upload_vs_abo_surfaces(struct brw_context *brw)
172 {
173 struct gl_context *ctx = &brw->ctx;
174 /* _NEW_PROGRAM */
175 struct gl_shader_program *prog =
176 ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
177
178 if (prog) {
179 /* BRW_NEW_VS_PROG_DATA */
180 brw_upload_abo_surfaces(brw, prog, &brw->vs.base,
181 &brw->vs.prog_data->base.base);
182 }
183 }
184
185 const struct brw_tracked_state brw_vs_abo_surfaces = {
186 .dirty = {
187 .mesa = _NEW_PROGRAM,
188 .brw = BRW_NEW_ATOMIC_BUFFER |
189 BRW_NEW_BATCH |
190 BRW_NEW_VS_PROG_DATA,
191 },
192 .emit = brw_upload_vs_abo_surfaces,
193 };