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 GLbitfield brw_new_binding_table
,
57 const struct brw_stage_prog_data
*prog_data
,
58 struct brw_stage_state
*stage_state
)
60 if (prog_data
->binding_table
.size_bytes
== 0) {
61 /* There are no surfaces; skip making the binding table altogether. */
62 if (stage_state
->bind_bo_offset
== 0 && brw
->gen
< 9)
65 stage_state
->bind_bo_offset
= 0;
67 /* Upload a new binding table. */
68 if (INTEL_DEBUG
& DEBUG_SHADER_TIME
) {
69 brw
->vtbl
.emit_buffer_surface_state(
70 brw
, &stage_state
->surf_offset
[
71 prog_data
->binding_table
.shader_time_start
],
72 brw
->shader_time
.bo
, 0, BRW_SURFACEFORMAT_RAW
,
73 brw
->shader_time
.bo
->size
, 1, true);
76 uint32_t *bind
= brw_state_batch(brw
, AUB_TRACE_BINDING_TABLE
,
77 prog_data
->binding_table
.size_bytes
, 32,
78 &stage_state
->bind_bo_offset
);
80 /* BRW_NEW_SURFACES and BRW_NEW_*_CONSTBUF */
81 memcpy(bind
, stage_state
->surf_offset
,
82 prog_data
->binding_table
.size_bytes
);
85 brw
->ctx
.NewDriverState
|= brw_new_binding_table
;
89 OUT_BATCH(packet_name
<< 16 | (2 - 2));
90 OUT_BATCH(stage_state
->bind_bo_offset
);
96 * State atoms which upload the binding table for a particular shader stage.
100 /** Upload the VS binding table. */
102 brw_vs_upload_binding_table(struct brw_context
*brw
)
104 /* BRW_NEW_VS_PROG_DATA */
105 const struct brw_stage_prog_data
*prog_data
= brw
->vs
.base
.prog_data
;
106 brw_upload_binding_table(brw
,
107 _3DSTATE_BINDING_TABLE_POINTERS_VS
,
108 BRW_NEW_VS_BINDING_TABLE
, prog_data
,
112 const struct brw_tracked_state brw_vs_binding_table
= {
115 .brw
= BRW_NEW_BATCH
|
116 BRW_NEW_VS_CONSTBUF
|
117 BRW_NEW_VS_PROG_DATA
|
120 .emit
= brw_vs_upload_binding_table
,
124 /** Upload the PS binding table. */
126 brw_upload_wm_binding_table(struct brw_context
*brw
)
128 /* BRW_NEW_FS_PROG_DATA */
129 const struct brw_stage_prog_data
*prog_data
= brw
->wm
.base
.prog_data
;
130 brw_upload_binding_table(brw
,
131 _3DSTATE_BINDING_TABLE_POINTERS_PS
,
132 BRW_NEW_PS_BINDING_TABLE
, prog_data
,
136 const struct brw_tracked_state brw_wm_binding_table
= {
139 .brw
= BRW_NEW_BATCH
|
140 BRW_NEW_FS_PROG_DATA
|
143 .emit
= brw_upload_wm_binding_table
,
146 /** Upload the GS binding table (if GS is active). */
148 brw_gs_upload_binding_table(struct brw_context
*brw
)
150 /* If there's no GS, skip changing anything. */
151 if (brw
->geometry_program
== NULL
)
154 /* BRW_NEW_GS_PROG_DATA */
155 const struct brw_stage_prog_data
*prog_data
= brw
->gs
.base
.prog_data
;
156 brw_upload_binding_table(brw
,
157 _3DSTATE_BINDING_TABLE_POINTERS_GS
,
158 BRW_NEW_GS_BINDING_TABLE
, prog_data
,
162 const struct brw_tracked_state brw_gs_binding_table
= {
165 .brw
= BRW_NEW_BATCH
|
166 BRW_NEW_GS_CONSTBUF
|
167 BRW_NEW_GS_PROG_DATA
|
170 .emit
= brw_gs_upload_binding_table
,
176 * State atoms which emit 3DSTATE packets to update the binding table pointers.
181 * (Gen4-5) Upload the binding table pointers for all shader stages.
183 * The binding table pointers are relative to the surface state base address,
184 * which points at the batchbuffer containing the streamed batch state.
187 gen4_upload_binding_table_pointers(struct brw_context
*brw
)
190 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS
<< 16 | (6 - 2));
191 OUT_BATCH(brw
->vs
.base
.bind_bo_offset
);
192 OUT_BATCH(0); /* gs */
193 OUT_BATCH(0); /* clip */
194 OUT_BATCH(0); /* sf */
195 OUT_BATCH(brw
->wm
.base
.bind_bo_offset
);
199 const struct brw_tracked_state brw_binding_table_pointers
= {
202 .brw
= BRW_NEW_BATCH
|
203 BRW_NEW_GS_BINDING_TABLE
|
204 BRW_NEW_PS_BINDING_TABLE
|
205 BRW_NEW_STATE_BASE_ADDRESS
|
206 BRW_NEW_VS_BINDING_TABLE
,
208 .emit
= gen4_upload_binding_table_pointers
,
212 * (Sandybridge Only) Upload the binding table pointers for all shader stages.
214 * The binding table pointers are relative to the surface state base address,
215 * which points at the batchbuffer containing the streamed batch state.
218 gen6_upload_binding_table_pointers(struct brw_context
*brw
)
221 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS
<< 16 |
222 GEN6_BINDING_TABLE_MODIFY_VS
|
223 GEN6_BINDING_TABLE_MODIFY_GS
|
224 GEN6_BINDING_TABLE_MODIFY_PS
|
226 OUT_BATCH(brw
->vs
.base
.bind_bo_offset
); /* vs */
227 if (brw
->ff_gs
.prog_active
)
228 OUT_BATCH(brw
->ff_gs
.bind_bo_offset
); /* gs */
230 OUT_BATCH(brw
->gs
.base
.bind_bo_offset
); /* gs */
231 OUT_BATCH(brw
->wm
.base
.bind_bo_offset
); /* wm/ps */
235 const struct brw_tracked_state gen6_binding_table_pointers
= {
238 .brw
= BRW_NEW_BATCH
|
239 BRW_NEW_GS_BINDING_TABLE
|
240 BRW_NEW_PS_BINDING_TABLE
|
241 BRW_NEW_STATE_BASE_ADDRESS
|
242 BRW_NEW_VS_BINDING_TABLE
,
244 .emit
= gen6_upload_binding_table_pointers
,