2 * Copyright © 2011 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 #include "brw_context.h"
26 #include "brw_state.h"
27 #include "brw_defines.h"
30 #include "program/program.h"
31 #include "program/prog_parameter.h"
32 #include "program/prog_statevars.h"
33 #include "main/framebuffer.h"
34 #include "intel_batchbuffer.h"
37 upload_wm_state(struct brw_context
*brw
)
39 struct gl_context
*ctx
= &brw
->ctx
;
40 /* BRW_NEW_FS_PROG_DATA */
41 const struct brw_wm_prog_data
*prog_data
= brw
->wm
.prog_data
;
42 bool writes_depth
= prog_data
->computed_depth_mode
!= BRW_PSCDEPTH_OFF
;
46 const bool multisampled_fbo
= _mesa_geometric_samples(ctx
->DrawBuffer
) > 1;
49 dw1
|= GEN7_WM_STATISTICS_ENABLE
;
50 dw1
|= GEN7_WM_LINE_AA_WIDTH_1_0
;
51 dw1
|= GEN7_WM_LINE_END_CAP_AA_WIDTH_0_5
;
54 if (ctx
->Line
.StippleFlag
)
55 dw1
|= GEN7_WM_LINE_STIPPLE_ENABLE
;
58 if (ctx
->Polygon
.StippleFlag
)
59 dw1
|= GEN7_WM_POLYGON_STIPPLE_ENABLE
;
61 if (prog_data
->uses_src_depth
)
62 dw1
|= GEN7_WM_USES_SOURCE_DEPTH
;
64 if (prog_data
->uses_src_w
)
65 dw1
|= GEN7_WM_USES_SOURCE_W
;
67 dw1
|= prog_data
->computed_depth_mode
<< GEN7_WM_COMPUTED_DEPTH_MODE_SHIFT
;
68 dw1
|= prog_data
->barycentric_interp_modes
<<
69 GEN7_WM_BARYCENTRIC_INTERPOLATION_MODE_SHIFT
;
71 /* _NEW_COLOR, _NEW_MULTISAMPLE */
72 /* Enable if the pixel shader kernel generates and outputs oMask.
74 if (prog_data
->uses_kill
|| ctx
->Color
.AlphaEnabled
||
75 ctx
->Multisample
.SampleAlphaToCoverage
||
76 prog_data
->uses_omask
) {
77 dw1
|= GEN7_WM_KILL_ENABLE
;
80 /* _NEW_BUFFERS | _NEW_COLOR */
81 if (brw_color_buffer_write_enabled(brw
) || writes_depth
||
82 prog_data
->has_side_effects
|| dw1
& GEN7_WM_KILL_ENABLE
) {
83 dw1
|= GEN7_WM_DISPATCH_ENABLE
;
85 if (multisampled_fbo
) {
86 /* _NEW_MULTISAMPLE */
87 if (ctx
->Multisample
.Enabled
)
88 dw1
|= GEN7_WM_MSRAST_ON_PATTERN
;
90 dw1
|= GEN7_WM_MSRAST_OFF_PIXEL
;
92 if (prog_data
->persample_dispatch
)
93 dw2
|= GEN7_WM_MSDISPMODE_PERSAMPLE
;
95 dw2
|= GEN7_WM_MSDISPMODE_PERPIXEL
;
97 dw1
|= GEN7_WM_MSRAST_OFF_PIXEL
;
98 dw2
|= GEN7_WM_MSDISPMODE_PERSAMPLE
;
101 if (prog_data
->uses_sample_mask
) {
102 dw1
|= GEN7_WM_USES_INPUT_COVERAGE_MASK
;
105 /* BRW_NEW_FS_PROG_DATA */
106 if (prog_data
->early_fragment_tests
)
107 dw1
|= GEN7_WM_EARLY_DS_CONTROL_PREPS
;
108 else if (prog_data
->has_side_effects
)
109 dw1
|= GEN7_WM_EARLY_DS_CONTROL_PSEXEC
;
111 /* The "UAV access enable" bits are unnecessary on HSW because they only
112 * seem to have an effect on the HW-assisted coherency mechanism which we
113 * don't need, and the rasterization-related UAV_ONLY flag and the
114 * DISPATCH_ENABLE bit can be set independently from it.
115 * C.f. gen8_upload_ps_extra().
117 * BRW_NEW_FRAGMENT_PROGRAM | BRW_NEW_FS_PROG_DATA | _NEW_BUFFERS | _NEW_COLOR
119 if (brw
->is_haswell
&&
120 !(brw_color_buffer_write_enabled(brw
) || writes_depth
) &&
121 prog_data
->has_side_effects
)
122 dw2
|= HSW_WM_UAV_ONLY
;
125 OUT_BATCH(_3DSTATE_WM
<< 16 | (3 - 2));
131 const struct brw_tracked_state gen7_wm_state
= {
133 .mesa
= _NEW_BUFFERS
|
138 .brw
= BRW_NEW_BATCH
|
140 BRW_NEW_FS_PROG_DATA
,
142 .emit
= upload_wm_state
,
146 gen7_upload_ps_state(struct brw_context
*brw
,
147 const struct brw_stage_state
*stage_state
,
148 const struct brw_wm_prog_data
*prog_data
,
149 bool enable_dual_src_blend
, unsigned sample_mask
,
150 unsigned fast_clear_op
)
152 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
153 uint32_t dw2
, dw4
, dw5
, ksp0
, ksp2
;
154 const int max_threads_shift
= brw
->is_haswell
?
155 HSW_PS_MAX_THREADS_SHIFT
: IVB_PS_MAX_THREADS_SHIFT
;
157 dw2
= dw4
= dw5
= ksp2
= 0;
159 const unsigned sampler_count
=
160 DIV_ROUND_UP(CLAMP(stage_state
->sampler_count
, 0, 16), 4);
161 dw2
|= SET_FIELD(sampler_count
, GEN7_PS_SAMPLER_COUNT
);
163 dw2
|= ((prog_data
->base
.binding_table
.size_bytes
/ 4) <<
164 GEN7_PS_BINDING_TABLE_ENTRY_COUNT_SHIFT
);
166 if (prog_data
->base
.use_alt_mode
)
167 dw2
|= GEN7_PS_FLOATING_POINT_MODE_ALT
;
169 /* Haswell requires the sample mask to be set in this packet as well as
170 * in 3DSTATE_SAMPLE_MASK; the values should match. */
171 /* _NEW_BUFFERS, _NEW_MULTISAMPLE */
173 dw4
|= SET_FIELD(sample_mask
, HSW_PS_SAMPLE_MASK
);
175 dw4
|= (devinfo
->max_wm_threads
- 1) << max_threads_shift
;
177 if (prog_data
->base
.nr_params
> 0)
178 dw4
|= GEN7_PS_PUSH_CONSTANT_ENABLE
;
180 /* From the IVB PRM, volume 2 part 1, page 287:
181 * "This bit is inserted in the PS payload header and made available to
182 * the DataPort (either via the message header or via header bypass) to
183 * indicate that oMask data (one or two phases) is included in Render
184 * Target Write messages. If present, the oMask data is used to mask off
187 if (prog_data
->uses_omask
)
188 dw4
|= GEN7_PS_OMASK_TO_RENDER_TARGET
;
190 /* From the IVB PRM, volume 2 part 1, page 287:
191 * "If the PS kernel does not need the Position XY Offsets to
192 * compute a Position Value, then this field should be programmed
193 * to POSOFFSET_NONE."
194 * "SW Recommendation: If the PS kernel needs the Position Offsets
195 * to compute a Position XY value, this field should match Position
196 * ZW Interpolation Mode to ensure a consistent position.xyzw
198 * We only require XY sample offsets. So, this recommendation doesn't
199 * look useful at the moment. We might need this in future.
201 if (prog_data
->uses_pos_offset
)
202 dw4
|= GEN7_PS_POSOFFSET_SAMPLE
;
204 dw4
|= GEN7_PS_POSOFFSET_NONE
;
206 /* The hardware wedges if you have this bit set but don't turn on any dual
207 * source blend factors.
209 if (enable_dual_src_blend
)
210 dw4
|= GEN7_PS_DUAL_SOURCE_BLEND_ENABLE
;
212 /* BRW_NEW_FS_PROG_DATA */
213 if (prog_data
->num_varying_inputs
!= 0)
214 dw4
|= GEN7_PS_ATTRIBUTE_ENABLE
;
216 dw4
|= fast_clear_op
;
218 if (prog_data
->dispatch_16
)
219 dw4
|= GEN7_PS_16_DISPATCH_ENABLE
;
221 if (prog_data
->dispatch_8
)
222 dw4
|= GEN7_PS_8_DISPATCH_ENABLE
;
224 dw5
|= prog_data
->base
.dispatch_grf_start_reg
<<
225 GEN7_PS_DISPATCH_START_GRF_SHIFT_0
;
226 dw5
|= prog_data
->dispatch_grf_start_reg_2
<<
227 GEN7_PS_DISPATCH_START_GRF_SHIFT_2
;
229 ksp0
= stage_state
->prog_offset
;
230 ksp2
= stage_state
->prog_offset
+ prog_data
->prog_offset_2
;
233 OUT_BATCH(_3DSTATE_PS
<< 16 | (8 - 2));
236 if (prog_data
->base
.total_scratch
) {
237 OUT_RELOC(brw
->wm
.base
.scratch_bo
,
238 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
239 ffs(stage_state
->per_thread_scratch
) - 11);
245 OUT_BATCH(0); /* kernel 1 pointer */
251 upload_ps_state(struct brw_context
*brw
)
253 /* BRW_NEW_FS_PROG_DATA */
254 const struct brw_wm_prog_data
*prog_data
= brw
->wm
.prog_data
;
255 const struct gl_context
*ctx
= &brw
->ctx
;
256 /* BRW_NEW_FS_PROG_DATA | _NEW_COLOR */
257 const bool enable_dual_src_blend
= prog_data
->dual_src_blend
&&
258 (ctx
->Color
.BlendEnabled
& 1) &&
259 ctx
->Color
.Blend
[0]._UsesDualSrc
;
260 /* _NEW_BUFFERS, _NEW_MULTISAMPLE */
261 const unsigned sample_mask
=
262 brw
->is_haswell
? gen6_determine_sample_mask(brw
) : 0;
264 gen7_upload_ps_state(brw
, &brw
->wm
.base
, prog_data
,
265 enable_dual_src_blend
, sample_mask
,
266 brw
->wm
.fast_clear_op
);
269 const struct brw_tracked_state gen7_ps_state
= {
271 .mesa
= _NEW_BUFFERS
|
274 .brw
= BRW_NEW_BATCH
|
276 BRW_NEW_FS_PROG_DATA
,
278 .emit
= upload_ps_state
,