2 * Copyright © 2009 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
24 * Eric Anholt <eric@anholt.net>
28 #include "brw_context.h"
29 #include "brw_state.h"
30 #include "brw_defines.h"
32 #include "program/prog_parameter.h"
33 #include "program/prog_statevars.h"
34 #include "main/shaderapi.h"
35 #include "intel_batchbuffer.h"
38 gen6_upload_vs_push_constants(struct brw_context
*brw
)
40 struct brw_stage_state
*stage_state
= &brw
->vs
.base
;
42 /* _BRW_NEW_VERTEX_PROGRAM */
43 const struct brw_program
*vp
= brw_program_const(brw
->vertex_program
);
44 /* BRW_NEW_VS_PROG_DATA */
45 const struct brw_stage_prog_data
*prog_data
= brw
->vs
.base
.prog_data
;
47 _mesa_shader_write_subroutine_indices(&brw
->ctx
, MESA_SHADER_VERTEX
);
48 gen6_upload_push_constants(brw
, &vp
->program
, prog_data
, stage_state
,
49 AUB_TRACE_VS_CONSTANTS
);
52 if (brw
->gen
== 7 && !brw
->is_haswell
&& !brw
->is_baytrail
)
53 gen7_emit_vs_workaround_flush(brw
);
55 gen7_upload_constant_state(brw
, stage_state
, true /* active */,
56 _3DSTATE_CONSTANT_VS
);
60 const struct brw_tracked_state gen6_vs_push_constants
= {
62 .mesa
= _NEW_PROGRAM_CONSTANTS
|
64 .brw
= BRW_NEW_BATCH
|
66 BRW_NEW_PUSH_CONSTANT_ALLOCATION
|
67 BRW_NEW_VERTEX_PROGRAM
|
70 .emit
= gen6_upload_vs_push_constants
,
74 upload_vs_state(struct brw_context
*brw
)
76 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
77 const struct brw_stage_state
*stage_state
= &brw
->vs
.base
;
78 const struct brw_stage_prog_data
*prog_data
= stage_state
->prog_data
;
79 const struct brw_vue_prog_data
*vue_prog_data
=
80 brw_vue_prog_data(stage_state
->prog_data
);
81 uint32_t floating_point_mode
= 0;
83 /* From the BSpec, 3D Pipeline > Geometry > Vertex Shader > State,
84 * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
86 * [DevSNB] A pipeline flush must be programmed prior to a 3DSTATE_VS
87 * command that causes the VS Function Enable to toggle. Pipeline
88 * flush can be executed by sending a PIPE_CONTROL command with CS
89 * stall bit set and a post sync operation.
91 * We've already done such a flush at the start of state upload, so we
92 * don't need to do another one here.
95 if (stage_state
->push_const_size
== 0) {
96 /* Disable the push constant buffers. */
98 OUT_BATCH(_3DSTATE_CONSTANT_VS
<< 16 | (5 - 2));
106 OUT_BATCH(_3DSTATE_CONSTANT_VS
<< 16 |
107 GEN6_CONSTANT_BUFFER_0_ENABLE
|
109 /* Pointer to the VS constant buffer. Covered by the set of
110 * state flags from gen6_upload_vs_constants
112 OUT_BATCH(stage_state
->push_const_offset
+
113 stage_state
->push_const_size
- 1);
120 if (prog_data
->use_alt_mode
)
121 floating_point_mode
= GEN6_VS_FLOATING_POINT_MODE_ALT
;
124 OUT_BATCH(_3DSTATE_VS
<< 16 | (6 - 2));
125 OUT_BATCH(stage_state
->prog_offset
);
126 OUT_BATCH(floating_point_mode
|
127 ((ALIGN(stage_state
->sampler_count
, 4)/4) << GEN6_VS_SAMPLER_COUNT_SHIFT
) |
128 ((prog_data
->binding_table
.size_bytes
/ 4) <<
129 GEN6_VS_BINDING_TABLE_ENTRY_COUNT_SHIFT
));
131 if (prog_data
->total_scratch
) {
132 OUT_RELOC(stage_state
->scratch_bo
,
133 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
134 ffs(stage_state
->per_thread_scratch
) - 11);
139 OUT_BATCH((prog_data
->dispatch_grf_start_reg
<<
140 GEN6_VS_DISPATCH_START_GRF_SHIFT
) |
141 (vue_prog_data
->urb_read_length
<< GEN6_VS_URB_READ_LENGTH_SHIFT
) |
142 (0 << GEN6_VS_URB_ENTRY_READ_OFFSET_SHIFT
));
144 OUT_BATCH(((devinfo
->max_vs_threads
- 1) << GEN6_VS_MAX_THREADS_SHIFT
) |
145 GEN6_VS_STATISTICS_ENABLE
|
149 /* Based on my reading of the simulator, the VS constants don't get
150 * pulled into the VS FF unit until an appropriate pipeline flush
151 * happens, and instead the 3DSTATE_CONSTANT_VS packet just adds
152 * references to them into a little FIFO. The flushes are common,
153 * but don't reliably happen between this and a 3DPRIMITIVE, causing
154 * the primitive to use the wrong constants. Then the FIFO
155 * containing the constant setup gets added to again on the next
156 * constants change, and eventually when a flush does happen the
157 * unit is overwhelmed by constant changes and dies.
159 * To avoid this, send a PIPE_CONTROL down the line that will
160 * update the unit immediately loading the constants. The flush
161 * type bits here were those set by the STATE_BASE_ADDRESS whose
162 * move in a82a43e8d99e1715dd11c9c091b5ab734079b6a6 triggered the
163 * bug reports that led to this workaround, and may be more than
164 * what is strictly required to avoid the issue.
166 brw_emit_pipe_control_flush(brw
,
167 PIPE_CONTROL_DEPTH_STALL
|
168 PIPE_CONTROL_INSTRUCTION_INVALIDATE
|
169 PIPE_CONTROL_STATE_CACHE_INVALIDATE
);
172 const struct brw_tracked_state gen6_vs_state
= {
174 .mesa
= _NEW_PROGRAM_CONSTANTS
|
176 .brw
= BRW_NEW_BATCH
|
179 BRW_NEW_PUSH_CONSTANT_ALLOCATION
|
180 BRW_NEW_VERTEX_PROGRAM
|
181 BRW_NEW_VS_PROG_DATA
,
183 .emit
= upload_vs_state
,