i965: Delete vestiges of resource streamer code.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_binding_tables.c
1 /*
2 * Copyright © 2013 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 /**
25 * \file brw_binding_tables.c
26 *
27 * State atoms which upload the "binding table" for each shader stage.
28 *
29 * Binding tables map a numeric "surface index" to the SURFACE_STATE structure
30 * for a currently bound surface. This allows SEND messages (such as sampler
31 * or data port messages) to refer to a particular surface by number, rather
32 * than by pointer.
33 *
34 * The binding table is stored as a (sparse) array of SURFACE_STATE entries;
35 * surface indexes are simply indexes into the array. The ordering of the
36 * entries is entirely left up to software; see the SURF_INDEX_* macros in
37 * brw_context.h to see our current layout.
38 */
39
40 #include "main/mtypes.h"
41
42 #include "brw_context.h"
43 #include "brw_defines.h"
44 #include "brw_state.h"
45 #include "intel_batchbuffer.h"
46
47 /**
48 * Upload a shader stage's binding table as indirect state.
49 *
50 * This copies brw_stage_state::surf_offset[] into the indirect state section
51 * of the batchbuffer (allocated by brw_state_batch()).
52 */
53 void
54 brw_upload_binding_table(struct brw_context *brw,
55 uint32_t packet_name,
56 const struct brw_stage_prog_data *prog_data,
57 struct brw_stage_state *stage_state)
58 {
59 if (prog_data->binding_table.size_bytes == 0) {
60 /* There are no surfaces; skip making the binding table altogether. */
61 if (stage_state->bind_bo_offset == 0 && brw->gen < 9)
62 return;
63
64 stage_state->bind_bo_offset = 0;
65 } else {
66 /* Upload a new binding table. */
67 if (INTEL_DEBUG & DEBUG_SHADER_TIME) {
68 brw_emit_buffer_surface_state(
69 brw, &stage_state->surf_offset[
70 prog_data->binding_table.shader_time_start],
71 brw->shader_time.bo, 0, ISL_FORMAT_RAW,
72 brw->shader_time.bo->size, 1, true);
73 }
74 uint32_t *bind = brw_state_batch(brw, AUB_TRACE_BINDING_TABLE,
75 prog_data->binding_table.size_bytes,
76 32,
77 &stage_state->bind_bo_offset);
78
79 /* BRW_NEW_SURFACES and BRW_NEW_*_CONSTBUF */
80 memcpy(bind, stage_state->surf_offset,
81 prog_data->binding_table.size_bytes);
82 }
83
84 brw->ctx.NewDriverState |= BRW_NEW_BINDING_TABLE_POINTERS;
85
86 if (brw->gen >= 7) {
87 BEGIN_BATCH(2);
88 OUT_BATCH(packet_name << 16 | (2 - 2));
89 /* Align SurfaceStateOffset[16:6] format to [15:5] PS Binding Table field
90 * when hw-generated binding table is enabled.
91 */
92 OUT_BATCH(stage_state->bind_bo_offset);
93 ADVANCE_BATCH();
94 }
95 }
96
97 /**
98 * State atoms which upload the binding table for a particular shader stage.
99 * @{
100 */
101
102 /** Upload the VS binding table. */
103 static void
104 brw_vs_upload_binding_table(struct brw_context *brw)
105 {
106 /* BRW_NEW_VS_PROG_DATA */
107 const struct brw_stage_prog_data *prog_data = brw->vs.base.prog_data;
108 brw_upload_binding_table(brw,
109 _3DSTATE_BINDING_TABLE_POINTERS_VS,
110 prog_data,
111 &brw->vs.base);
112 }
113
114 const struct brw_tracked_state brw_vs_binding_table = {
115 .dirty = {
116 .mesa = 0,
117 .brw = BRW_NEW_BATCH |
118 BRW_NEW_BLORP |
119 BRW_NEW_VS_CONSTBUF |
120 BRW_NEW_VS_PROG_DATA |
121 BRW_NEW_SURFACES,
122 },
123 .emit = brw_vs_upload_binding_table,
124 };
125
126
127 /** Upload the PS binding table. */
128 static void
129 brw_upload_wm_binding_table(struct brw_context *brw)
130 {
131 /* BRW_NEW_FS_PROG_DATA */
132 const struct brw_stage_prog_data *prog_data = brw->wm.base.prog_data;
133 brw_upload_binding_table(brw,
134 _3DSTATE_BINDING_TABLE_POINTERS_PS,
135 prog_data,
136 &brw->wm.base);
137 }
138
139 const struct brw_tracked_state brw_wm_binding_table = {
140 .dirty = {
141 .mesa = 0,
142 .brw = BRW_NEW_BATCH |
143 BRW_NEW_BLORP |
144 BRW_NEW_FS_PROG_DATA |
145 BRW_NEW_SURFACES,
146 },
147 .emit = brw_upload_wm_binding_table,
148 };
149
150 /** Upload the TCS binding table (if tessellation stages are active). */
151 static void
152 brw_tcs_upload_binding_table(struct brw_context *brw)
153 {
154 /* Skip if the tessellation stages are disabled. */
155 if (brw->tess_eval_program == NULL)
156 return;
157
158 /* BRW_NEW_TCS_PROG_DATA */
159 const struct brw_stage_prog_data *prog_data = brw->tcs.base.prog_data;
160 brw_upload_binding_table(brw,
161 _3DSTATE_BINDING_TABLE_POINTERS_HS,
162 prog_data,
163 &brw->tcs.base);
164 }
165
166 const struct brw_tracked_state brw_tcs_binding_table = {
167 .dirty = {
168 .mesa = 0,
169 .brw = BRW_NEW_BATCH |
170 BRW_NEW_BLORP |
171 BRW_NEW_DEFAULT_TESS_LEVELS |
172 BRW_NEW_SURFACES |
173 BRW_NEW_TCS_CONSTBUF |
174 BRW_NEW_TCS_PROG_DATA,
175 },
176 .emit = brw_tcs_upload_binding_table,
177 };
178
179 /** Upload the TES binding table (if TES is active). */
180 static void
181 brw_tes_upload_binding_table(struct brw_context *brw)
182 {
183 /* If there's no TES, skip changing anything. */
184 if (brw->tess_eval_program == NULL)
185 return;
186
187 /* BRW_NEW_TES_PROG_DATA */
188 const struct brw_stage_prog_data *prog_data = brw->tes.base.prog_data;
189 brw_upload_binding_table(brw,
190 _3DSTATE_BINDING_TABLE_POINTERS_DS,
191 prog_data,
192 &brw->tes.base);
193 }
194
195 const struct brw_tracked_state brw_tes_binding_table = {
196 .dirty = {
197 .mesa = 0,
198 .brw = BRW_NEW_BATCH |
199 BRW_NEW_BLORP |
200 BRW_NEW_SURFACES |
201 BRW_NEW_TES_CONSTBUF |
202 BRW_NEW_TES_PROG_DATA,
203 },
204 .emit = brw_tes_upload_binding_table,
205 };
206
207 /** Upload the GS binding table (if GS is active). */
208 static void
209 brw_gs_upload_binding_table(struct brw_context *brw)
210 {
211 /* If there's no GS, skip changing anything. */
212 if (brw->geometry_program == NULL)
213 return;
214
215 /* BRW_NEW_GS_PROG_DATA */
216 const struct brw_stage_prog_data *prog_data = brw->gs.base.prog_data;
217 brw_upload_binding_table(brw,
218 _3DSTATE_BINDING_TABLE_POINTERS_GS,
219 prog_data,
220 &brw->gs.base);
221 }
222
223 const struct brw_tracked_state brw_gs_binding_table = {
224 .dirty = {
225 .mesa = 0,
226 .brw = BRW_NEW_BATCH |
227 BRW_NEW_BLORP |
228 BRW_NEW_GS_CONSTBUF |
229 BRW_NEW_GS_PROG_DATA |
230 BRW_NEW_SURFACES,
231 },
232 .emit = brw_gs_upload_binding_table,
233 };
234 /** @} */
235
236 /**
237 * State atoms which emit 3DSTATE packets to update the binding table pointers.
238 * @{
239 */
240
241 /**
242 * (Gen4-5) Upload the binding table pointers for all shader stages.
243 *
244 * The binding table pointers are relative to the surface state base address,
245 * which points at the batchbuffer containing the streamed batch state.
246 */
247 static void
248 gen4_upload_binding_table_pointers(struct brw_context *brw)
249 {
250 BEGIN_BATCH(6);
251 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS << 16 | (6 - 2));
252 OUT_BATCH(brw->vs.base.bind_bo_offset);
253 OUT_BATCH(0); /* gs */
254 OUT_BATCH(0); /* clip */
255 OUT_BATCH(0); /* sf */
256 OUT_BATCH(brw->wm.base.bind_bo_offset);
257 ADVANCE_BATCH();
258 }
259
260 const struct brw_tracked_state brw_binding_table_pointers = {
261 .dirty = {
262 .mesa = 0,
263 .brw = BRW_NEW_BATCH |
264 BRW_NEW_BLORP |
265 BRW_NEW_BINDING_TABLE_POINTERS |
266 BRW_NEW_STATE_BASE_ADDRESS,
267 },
268 .emit = gen4_upload_binding_table_pointers,
269 };
270
271 /**
272 * (Sandybridge Only) Upload the binding table pointers for all shader stages.
273 *
274 * The binding table pointers are relative to the surface state base address,
275 * which points at the batchbuffer containing the streamed batch state.
276 */
277 static void
278 gen6_upload_binding_table_pointers(struct brw_context *brw)
279 {
280 BEGIN_BATCH(4);
281 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS << 16 |
282 GEN6_BINDING_TABLE_MODIFY_VS |
283 GEN6_BINDING_TABLE_MODIFY_GS |
284 GEN6_BINDING_TABLE_MODIFY_PS |
285 (4 - 2));
286 OUT_BATCH(brw->vs.base.bind_bo_offset); /* vs */
287 if (brw->ff_gs.prog_active)
288 OUT_BATCH(brw->ff_gs.bind_bo_offset); /* gs */
289 else
290 OUT_BATCH(brw->gs.base.bind_bo_offset); /* gs */
291 OUT_BATCH(brw->wm.base.bind_bo_offset); /* wm/ps */
292 ADVANCE_BATCH();
293 }
294
295 const struct brw_tracked_state gen6_binding_table_pointers = {
296 .dirty = {
297 .mesa = 0,
298 .brw = BRW_NEW_BATCH |
299 BRW_NEW_BLORP |
300 BRW_NEW_BINDING_TABLE_POINTERS |
301 BRW_NEW_STATE_BASE_ADDRESS,
302 },
303 .emit = gen6_upload_binding_table_pointers,
304 };
305
306 /** @} */