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"
33 #include "program/program.h"
34 #include "program/prog_parameter.h"
35 #include "program/prog_statevars.h"
36 #include "main/framebuffer.h"
37 #include "intel_batchbuffer.h"
40 gen6_upload_wm_push_constants(struct brw_context
*brw
)
42 struct brw_stage_state
*stage_state
= &brw
->wm
.base
;
43 /* BRW_NEW_FRAGMENT_PROGRAM */
44 const struct brw_fragment_program
*fp
=
45 brw_fragment_program_const(brw
->fragment_program
);
46 /* BRW_NEW_FS_PROG_DATA */
47 const struct brw_wm_prog_data
*prog_data
= brw
->wm
.prog_data
;
49 gen6_upload_push_constants(brw
, &fp
->program
.Base
, &prog_data
->base
,
50 stage_state
, AUB_TRACE_WM_CONSTANTS
);
53 gen7_upload_constant_state(brw
, &brw
->wm
.base
, true,
54 _3DSTATE_CONSTANT_PS
);
58 const struct brw_tracked_state gen6_wm_push_constants
= {
60 .mesa
= _NEW_PROGRAM_CONSTANTS
,
61 .brw
= BRW_NEW_BATCH
|
63 BRW_NEW_FRAGMENT_PROGRAM
|
64 BRW_NEW_FS_PROG_DATA
|
65 BRW_NEW_PUSH_CONSTANT_ALLOCATION
,
67 .emit
= gen6_upload_wm_push_constants
,
71 gen6_upload_wm_state(struct brw_context
*brw
,
72 const struct brw_wm_prog_data
*prog_data
,
73 const struct brw_stage_state
*stage_state
,
74 bool multisampled_fbo
,
75 bool dual_source_blend_enable
, bool kill_enable
,
76 bool color_buffer_write_enable
, bool msaa_enabled
,
77 bool line_stipple_enable
, bool polygon_stipple_enable
,
78 bool statistic_enable
)
80 uint32_t dw2
, dw4
, dw5
, dw6
, ksp0
, ksp2
;
82 /* We can't fold this into gen6_upload_wm_push_constants(), because
83 * according to the SNB PRM, vol 2 part 1 section 7.2.2
84 * (3DSTATE_CONSTANT_PS [DevSNB]):
86 * "[DevSNB]: This packet must be followed by WM_STATE."
88 if (prog_data
->base
.nr_params
== 0) {
89 /* Disable the push constant buffers. */
91 OUT_BATCH(_3DSTATE_CONSTANT_PS
<< 16 | (5 - 2));
99 OUT_BATCH(_3DSTATE_CONSTANT_PS
<< 16 |
100 GEN6_CONSTANT_BUFFER_0_ENABLE
|
102 /* Pointer to the WM constant buffer. Covered by the set of
103 * state flags from gen6_upload_wm_push_constants.
105 OUT_BATCH(stage_state
->push_const_offset
+
106 stage_state
->push_const_size
- 1);
113 dw2
= dw4
= dw5
= dw6
= ksp2
= 0;
115 if (statistic_enable
)
116 dw4
|= GEN6_WM_STATISTICS_ENABLE
;
118 dw5
|= GEN6_WM_LINE_AA_WIDTH_1_0
;
119 dw5
|= GEN6_WM_LINE_END_CAP_AA_WIDTH_0_5
;
121 if (prog_data
->base
.use_alt_mode
)
122 dw2
|= GEN6_WM_FLOATING_POINT_MODE_ALT
;
124 dw2
|= (ALIGN(stage_state
->sampler_count
, 4) / 4) <<
125 GEN6_WM_SAMPLER_COUNT_SHIFT
;
127 dw2
|= ((prog_data
->base
.binding_table
.size_bytes
/ 4) <<
128 GEN6_WM_BINDING_TABLE_ENTRY_COUNT_SHIFT
);
130 dw5
|= (brw
->max_wm_threads
- 1) << GEN6_WM_MAX_THREADS_SHIFT
;
132 if (prog_data
->prog_offset_16
|| prog_data
->no_8
) {
133 dw5
|= GEN6_WM_16_DISPATCH_ENABLE
;
135 if (!prog_data
->no_8
&& !prog_data
->persample_dispatch
) {
136 dw5
|= GEN6_WM_8_DISPATCH_ENABLE
;
137 dw4
|= (prog_data
->base
.dispatch_grf_start_reg
<<
138 GEN6_WM_DISPATCH_START_GRF_SHIFT_0
);
139 dw4
|= (prog_data
->dispatch_grf_start_reg_16
<<
140 GEN6_WM_DISPATCH_START_GRF_SHIFT_2
);
141 ksp0
= stage_state
->prog_offset
;
142 ksp2
= stage_state
->prog_offset
+ prog_data
->prog_offset_16
;
144 dw4
|= (prog_data
->dispatch_grf_start_reg_16
<<
145 GEN6_WM_DISPATCH_START_GRF_SHIFT_0
);
146 ksp0
= stage_state
->prog_offset
+ prog_data
->prog_offset_16
;
150 dw5
|= GEN6_WM_8_DISPATCH_ENABLE
;
151 dw4
|= (prog_data
->base
.dispatch_grf_start_reg
<<
152 GEN6_WM_DISPATCH_START_GRF_SHIFT_0
);
153 ksp0
= stage_state
->prog_offset
;
156 if (dual_source_blend_enable
)
157 dw5
|= GEN6_WM_DUAL_SOURCE_BLEND_ENABLE
;
159 if (line_stipple_enable
)
160 dw5
|= GEN6_WM_LINE_STIPPLE_ENABLE
;
162 if (polygon_stipple_enable
)
163 dw5
|= GEN6_WM_POLYGON_STIPPLE_ENABLE
;
165 if (prog_data
->uses_src_depth
)
166 dw5
|= GEN6_WM_USES_SOURCE_DEPTH
;
167 if (prog_data
->uses_src_w
)
168 dw5
|= GEN6_WM_USES_SOURCE_W
;
169 if (prog_data
->computed_depth_mode
!= BRW_PSCDEPTH_OFF
)
170 dw5
|= GEN6_WM_COMPUTED_DEPTH
;
171 dw6
|= prog_data
->barycentric_interp_modes
<<
172 GEN6_WM_BARYCENTRIC_INTERPOLATION_MODE_SHIFT
;
175 dw5
|= GEN6_WM_KILL_ENABLE
;
177 if (color_buffer_write_enable
||
178 dw5
& (GEN6_WM_KILL_ENABLE
| GEN6_WM_COMPUTED_DEPTH
))
179 dw5
|= GEN6_WM_DISPATCH_ENABLE
;
181 /* From the SNB PRM, volume 2 part 1, page 278:
182 * "This bit is inserted in the PS payload header and made available to
183 * the DataPort (either via the message header or via header bypass) to
184 * indicate that oMask data (one or two phases) is included in Render
185 * Target Write messages. If present, the oMask data is used to mask off
188 if (prog_data
->uses_omask
)
189 dw5
|= GEN6_WM_OMASK_TO_RENDER_TARGET
;
191 dw6
|= prog_data
->num_varying_inputs
<<
192 GEN6_WM_NUM_SF_OUTPUTS_SHIFT
;
193 if (multisampled_fbo
) {
195 dw6
|= GEN6_WM_MSRAST_ON_PATTERN
;
197 dw6
|= GEN6_WM_MSRAST_OFF_PIXEL
;
199 if (prog_data
->persample_dispatch
)
200 dw6
|= GEN6_WM_MSDISPMODE_PERSAMPLE
;
202 dw6
|= GEN6_WM_MSDISPMODE_PERPIXEL
;
204 /* From the Sandy Bridge PRM, Vol 2 part 1, 7.7.1 ("Pixel Grouping
205 * (Dispatch Size) Control"), p.334:
207 * Note: in the table below, the Valid column indicates which
208 * products that combination is supported on. Combinations of
209 * dispatch enables not listed in the table are not available on
212 * A: Valid on all products
214 * B: Not valid on [DevSNB] if 4x PERPIXEL mode with pixel shader
217 * D: Valid on all products, except when in non-1x PERSAMPLE mode
218 * (applies to [DevSNB+] only). Not valid on [DevSNB] if 4x
219 * PERPIXEL mode with pixel shader computed depth.
221 * E: Not valid on [DevSNB] if 4x PERPIXEL mode with pixel shader
224 * F: Valid on all products, except not valid on [DevSNB] if 4x
225 * PERPIXEL mode with pixel shader computed depth.
227 * In the table that follows, the only entry with "A" in the Valid
228 * column is the entry where only 8 pixel dispatch is enabled.
229 * Therefore, when we are in PERPIXEL mode with pixel shader computed
230 * depth, we need to disable SIMD16 dispatch.
232 if (dw5
& GEN6_WM_COMPUTED_DEPTH
)
233 dw5
&= ~GEN6_WM_16_DISPATCH_ENABLE
;
236 dw6
|= GEN6_WM_MSRAST_OFF_PIXEL
;
237 dw6
|= GEN6_WM_MSDISPMODE_PERSAMPLE
;
240 /* From the SNB PRM, volume 2 part 1, page 281:
241 * "If the PS kernel does not need the Position XY Offsets
242 * to compute a Position XY value, then this field should be
243 * programmed to POSOFFSET_NONE."
245 * "SW Recommendation: If the PS kernel needs the Position Offsets
246 * to compute a Position XY value, this field should match Position
247 * ZW Interpolation Mode to ensure a consistent position.xyzw
249 * We only require XY sample offsets. So, this recommendation doesn't
250 * look useful at the moment. We might need this in future.
252 if (prog_data
->uses_pos_offset
)
253 dw6
|= GEN6_WM_POSOFFSET_SAMPLE
;
255 dw6
|= GEN6_WM_POSOFFSET_NONE
;
258 OUT_BATCH(_3DSTATE_WM
<< 16 | (9 - 2));
261 if (prog_data
->base
.total_scratch
) {
262 OUT_RELOC(stage_state
->scratch_bo
,
263 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
264 ffs(prog_data
->base
.total_scratch
) - 11);
271 OUT_BATCH(0); /* kernel 1 pointer */
277 upload_wm_state(struct brw_context
*brw
)
279 struct gl_context
*ctx
= &brw
->ctx
;
280 /* BRW_NEW_FS_PROG_DATA */
281 const struct brw_wm_prog_data
*prog_data
= brw
->wm
.prog_data
;
284 const bool multisampled_fbo
= _mesa_geometric_samples(ctx
->DrawBuffer
) > 1;
286 /* BRW_NEW_FS_PROG_DATA | _NEW_COLOR */
287 const bool dual_src_blend_enable
= prog_data
->dual_src_blend
&&
288 (ctx
->Color
.BlendEnabled
& 1) &&
289 ctx
->Color
.Blend
[0]._UsesDualSrc
;
291 /* _NEW_COLOR, _NEW_MULTISAMPLE */
292 const bool kill_enable
= prog_data
->uses_kill
|| ctx
->Color
.AlphaEnabled
||
293 ctx
->Multisample
.SampleAlphaToCoverage
||
294 prog_data
->uses_omask
;
296 /* Rendering against the gl-context is always taken into account. */
297 const bool statistic_enable
= true;
299 /* _NEW_LINE | _NEW_POLYGON | _NEW_BUFFERS | _NEW_COLOR |
302 gen6_upload_wm_state(brw
, prog_data
, &brw
->wm
.base
,
304 dual_src_blend_enable
, kill_enable
,
305 brw_color_buffer_write_enabled(brw
),
306 ctx
->Multisample
.Enabled
,
307 ctx
->Line
.StippleFlag
, ctx
->Polygon
.StippleFlag
,
311 const struct brw_tracked_state gen6_wm_state
= {
313 .mesa
= _NEW_BUFFERS
|
318 _NEW_PROGRAM_CONSTANTS
,
319 .brw
= BRW_NEW_BATCH
|
321 BRW_NEW_FS_PROG_DATA
|
322 BRW_NEW_PUSH_CONSTANT_ALLOCATION
,
324 .emit
= upload_wm_state
,