2 * Copyright © 2013 Intel Corporation
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:
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
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
25 * \file brw_binding_tables.c
27 * State atoms which upload the "binding table" for each shader stage.
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
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.
40 #include "main/mtypes.h"
42 #include "brw_context.h"
43 #include "brw_defines.h"
44 #include "brw_state.h"
45 #include "intel_batchbuffer.h"
48 * Upload a shader stage's binding table as indirect state.
50 * This copies brw_stage_state::surf_offset[] into the indirect state section
51 * of the batchbuffer (allocated by brw_state_batch()).
54 brw_upload_binding_table(struct brw_context
*brw
,
56 const struct brw_stage_prog_data
*prog_data
,
57 struct brw_stage_state
*stage_state
)
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)
64 stage_state
->bind_bo_offset
= 0;
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);
75 brw_state_batch(brw
, prog_data
->binding_table
.size_bytes
,
76 32, &stage_state
->bind_bo_offset
);
78 /* BRW_NEW_SURFACES and BRW_NEW_*_CONSTBUF */
79 memcpy(bind
, stage_state
->surf_offset
,
80 prog_data
->binding_table
.size_bytes
);
83 brw
->ctx
.NewDriverState
|= BRW_NEW_BINDING_TABLE_POINTERS
;
87 OUT_BATCH(packet_name
<< 16 | (2 - 2));
88 /* Align SurfaceStateOffset[16:6] format to [15:5] PS Binding Table field
89 * when hw-generated binding table is enabled.
91 OUT_BATCH(stage_state
->bind_bo_offset
);
97 * State atoms which upload the binding table for a particular shader stage.
101 /** Upload the VS binding table. */
103 brw_vs_upload_binding_table(struct brw_context
*brw
)
105 /* BRW_NEW_VS_PROG_DATA */
106 const struct brw_stage_prog_data
*prog_data
= brw
->vs
.base
.prog_data
;
107 brw_upload_binding_table(brw
,
108 _3DSTATE_BINDING_TABLE_POINTERS_VS
,
113 const struct brw_tracked_state brw_vs_binding_table
= {
116 .brw
= BRW_NEW_BATCH
|
118 BRW_NEW_VS_CONSTBUF
|
119 BRW_NEW_VS_PROG_DATA
|
122 .emit
= brw_vs_upload_binding_table
,
126 /** Upload the PS binding table. */
128 brw_upload_wm_binding_table(struct brw_context
*brw
)
130 /* BRW_NEW_FS_PROG_DATA */
131 const struct brw_stage_prog_data
*prog_data
= brw
->wm
.base
.prog_data
;
132 brw_upload_binding_table(brw
,
133 _3DSTATE_BINDING_TABLE_POINTERS_PS
,
138 const struct brw_tracked_state brw_wm_binding_table
= {
141 .brw
= BRW_NEW_BATCH
|
143 BRW_NEW_FS_PROG_DATA
|
146 .emit
= brw_upload_wm_binding_table
,
149 /** Upload the TCS binding table (if tessellation stages are active). */
151 brw_tcs_upload_binding_table(struct brw_context
*brw
)
153 /* Skip if the tessellation stages are disabled. */
154 if (brw
->tess_eval_program
== NULL
)
157 /* BRW_NEW_TCS_PROG_DATA */
158 const struct brw_stage_prog_data
*prog_data
= brw
->tcs
.base
.prog_data
;
159 brw_upload_binding_table(brw
,
160 _3DSTATE_BINDING_TABLE_POINTERS_HS
,
165 const struct brw_tracked_state brw_tcs_binding_table
= {
168 .brw
= BRW_NEW_BATCH
|
170 BRW_NEW_DEFAULT_TESS_LEVELS
|
172 BRW_NEW_TCS_CONSTBUF
|
173 BRW_NEW_TCS_PROG_DATA
,
175 .emit
= brw_tcs_upload_binding_table
,
178 /** Upload the TES binding table (if TES is active). */
180 brw_tes_upload_binding_table(struct brw_context
*brw
)
182 /* If there's no TES, skip changing anything. */
183 if (brw
->tess_eval_program
== NULL
)
186 /* BRW_NEW_TES_PROG_DATA */
187 const struct brw_stage_prog_data
*prog_data
= brw
->tes
.base
.prog_data
;
188 brw_upload_binding_table(brw
,
189 _3DSTATE_BINDING_TABLE_POINTERS_DS
,
194 const struct brw_tracked_state brw_tes_binding_table
= {
197 .brw
= BRW_NEW_BATCH
|
200 BRW_NEW_TES_CONSTBUF
|
201 BRW_NEW_TES_PROG_DATA
,
203 .emit
= brw_tes_upload_binding_table
,
206 /** Upload the GS binding table (if GS is active). */
208 brw_gs_upload_binding_table(struct brw_context
*brw
)
210 /* If there's no GS, skip changing anything. */
211 if (brw
->geometry_program
== NULL
)
214 /* BRW_NEW_GS_PROG_DATA */
215 const struct brw_stage_prog_data
*prog_data
= brw
->gs
.base
.prog_data
;
216 brw_upload_binding_table(brw
,
217 _3DSTATE_BINDING_TABLE_POINTERS_GS
,
222 const struct brw_tracked_state brw_gs_binding_table
= {
225 .brw
= BRW_NEW_BATCH
|
227 BRW_NEW_GS_CONSTBUF
|
228 BRW_NEW_GS_PROG_DATA
|
231 .emit
= brw_gs_upload_binding_table
,
236 * State atoms which emit 3DSTATE packets to update the binding table pointers.
241 * (Gen4-5) Upload the binding table pointers for all shader stages.
243 * The binding table pointers are relative to the surface state base address,
244 * which points at the batchbuffer containing the streamed batch state.
247 gen4_upload_binding_table_pointers(struct brw_context
*brw
)
250 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS
<< 16 | (6 - 2));
251 OUT_BATCH(brw
->vs
.base
.bind_bo_offset
);
252 OUT_BATCH(0); /* gs */
253 OUT_BATCH(0); /* clip */
254 OUT_BATCH(0); /* sf */
255 OUT_BATCH(brw
->wm
.base
.bind_bo_offset
);
259 const struct brw_tracked_state brw_binding_table_pointers
= {
262 .brw
= BRW_NEW_BATCH
|
264 BRW_NEW_BINDING_TABLE_POINTERS
|
265 BRW_NEW_STATE_BASE_ADDRESS
,
267 .emit
= gen4_upload_binding_table_pointers
,
271 * (Sandybridge Only) Upload the binding table pointers for all shader stages.
273 * The binding table pointers are relative to the surface state base address,
274 * which points at the batchbuffer containing the streamed batch state.
277 gen6_upload_binding_table_pointers(struct brw_context
*brw
)
280 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS
<< 16 |
281 GEN6_BINDING_TABLE_MODIFY_VS
|
282 GEN6_BINDING_TABLE_MODIFY_GS
|
283 GEN6_BINDING_TABLE_MODIFY_PS
|
285 OUT_BATCH(brw
->vs
.base
.bind_bo_offset
); /* vs */
286 if (brw
->ff_gs
.prog_active
)
287 OUT_BATCH(brw
->ff_gs
.bind_bo_offset
); /* gs */
289 OUT_BATCH(brw
->gs
.base
.bind_bo_offset
); /* gs */
290 OUT_BATCH(brw
->wm
.base
.bind_bo_offset
); /* wm/ps */
294 const struct brw_tracked_state gen6_binding_table_pointers
= {
297 .brw
= BRW_NEW_BATCH
|
299 BRW_NEW_BINDING_TABLE_POINTERS
|
300 BRW_NEW_STATE_BASE_ADDRESS
,
302 .emit
= gen6_upload_binding_table_pointers
,