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/shaderapi.h"
37 #include "main/framebuffer.h"
38 #include "intel_batchbuffer.h"
41 gen6_upload_wm_push_constants(struct brw_context
*brw
)
43 struct brw_stage_state
*stage_state
= &brw
->wm
.base
;
44 /* BRW_NEW_FRAGMENT_PROGRAM */
45 const struct brw_fragment_program
*fp
=
46 brw_fragment_program_const(brw
->fragment_program
);
47 /* BRW_NEW_FS_PROG_DATA */
48 const struct brw_stage_prog_data
*prog_data
= brw
->wm
.base
.prog_data
;
50 _mesa_shader_write_subroutine_indices(&brw
->ctx
, MESA_SHADER_FRAGMENT
);
52 gen6_upload_push_constants(brw
, &fp
->program
.Base
, prog_data
,
53 stage_state
, AUB_TRACE_WM_CONSTANTS
);
56 gen7_upload_constant_state(brw
, &brw
->wm
.base
, true,
57 _3DSTATE_CONSTANT_PS
);
61 const struct brw_tracked_state gen6_wm_push_constants
= {
63 .mesa
= _NEW_PROGRAM_CONSTANTS
,
64 .brw
= BRW_NEW_BATCH
|
66 BRW_NEW_FRAGMENT_PROGRAM
|
67 BRW_NEW_FS_PROG_DATA
|
68 BRW_NEW_PUSH_CONSTANT_ALLOCATION
,
70 .emit
= gen6_upload_wm_push_constants
,
74 gen6_upload_wm_state(struct brw_context
*brw
,
75 const struct brw_wm_prog_data
*prog_data
,
76 const struct brw_stage_state
*stage_state
,
77 bool multisampled_fbo
,
78 bool dual_source_blend_enable
, bool kill_enable
,
79 bool color_buffer_write_enable
, bool msaa_enabled
,
80 bool line_stipple_enable
, bool polygon_stipple_enable
,
81 bool statistic_enable
)
83 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
84 uint32_t dw2
, dw4
, dw5
, dw6
, ksp0
, ksp2
;
86 /* We can't fold this into gen6_upload_wm_push_constants(), because
87 * according to the SNB PRM, vol 2 part 1 section 7.2.2
88 * (3DSTATE_CONSTANT_PS [DevSNB]):
90 * "[DevSNB]: This packet must be followed by WM_STATE."
92 if (prog_data
->base
.nr_params
== 0) {
93 /* Disable the push constant buffers. */
95 OUT_BATCH(_3DSTATE_CONSTANT_PS
<< 16 | (5 - 2));
103 OUT_BATCH(_3DSTATE_CONSTANT_PS
<< 16 |
104 GEN6_CONSTANT_BUFFER_0_ENABLE
|
106 /* Pointer to the WM constant buffer. Covered by the set of
107 * state flags from gen6_upload_wm_push_constants.
109 OUT_BATCH(stage_state
->push_const_offset
+
110 stage_state
->push_const_size
- 1);
117 dw2
= dw4
= dw5
= dw6
= ksp2
= 0;
119 if (statistic_enable
)
120 dw4
|= GEN6_WM_STATISTICS_ENABLE
;
122 dw5
|= GEN6_WM_LINE_AA_WIDTH_1_0
;
123 dw5
|= GEN6_WM_LINE_END_CAP_AA_WIDTH_0_5
;
125 if (prog_data
->base
.use_alt_mode
)
126 dw2
|= GEN6_WM_FLOATING_POINT_MODE_ALT
;
128 dw2
|= (ALIGN(stage_state
->sampler_count
, 4) / 4) <<
129 GEN6_WM_SAMPLER_COUNT_SHIFT
;
131 dw2
|= ((prog_data
->base
.binding_table
.size_bytes
/ 4) <<
132 GEN6_WM_BINDING_TABLE_ENTRY_COUNT_SHIFT
);
134 dw5
|= (devinfo
->max_wm_threads
- 1) << GEN6_WM_MAX_THREADS_SHIFT
;
136 if (prog_data
->dispatch_8
)
137 dw5
|= GEN6_WM_8_DISPATCH_ENABLE
;
139 if (prog_data
->dispatch_16
)
140 dw5
|= GEN6_WM_16_DISPATCH_ENABLE
;
142 dw4
|= prog_data
->base
.dispatch_grf_start_reg
<<
143 GEN6_WM_DISPATCH_START_GRF_SHIFT_0
;
144 dw4
|= prog_data
->dispatch_grf_start_reg_2
<<
145 GEN6_WM_DISPATCH_START_GRF_SHIFT_2
;
147 ksp0
= stage_state
->prog_offset
;
148 ksp2
= stage_state
->prog_offset
+ prog_data
->prog_offset_2
;
150 if (dual_source_blend_enable
)
151 dw5
|= GEN6_WM_DUAL_SOURCE_BLEND_ENABLE
;
153 if (line_stipple_enable
)
154 dw5
|= GEN6_WM_LINE_STIPPLE_ENABLE
;
156 if (polygon_stipple_enable
)
157 dw5
|= GEN6_WM_POLYGON_STIPPLE_ENABLE
;
159 if (prog_data
->uses_src_depth
)
160 dw5
|= GEN6_WM_USES_SOURCE_DEPTH
;
161 if (prog_data
->uses_src_w
)
162 dw5
|= GEN6_WM_USES_SOURCE_W
;
163 if (prog_data
->computed_depth_mode
!= BRW_PSCDEPTH_OFF
)
164 dw5
|= GEN6_WM_COMPUTED_DEPTH
;
165 dw6
|= prog_data
->barycentric_interp_modes
<<
166 GEN6_WM_BARYCENTRIC_INTERPOLATION_MODE_SHIFT
;
169 dw5
|= GEN6_WM_KILL_ENABLE
;
171 if (color_buffer_write_enable
||
172 dw5
& (GEN6_WM_KILL_ENABLE
| GEN6_WM_COMPUTED_DEPTH
))
173 dw5
|= GEN6_WM_DISPATCH_ENABLE
;
175 /* From the SNB PRM, volume 2 part 1, page 278:
176 * "This bit is inserted in the PS payload header and made available to
177 * the DataPort (either via the message header or via header bypass) to
178 * indicate that oMask data (one or two phases) is included in Render
179 * Target Write messages. If present, the oMask data is used to mask off
182 if (prog_data
->uses_omask
)
183 dw5
|= GEN6_WM_OMASK_TO_RENDER_TARGET
;
185 dw6
|= prog_data
->num_varying_inputs
<<
186 GEN6_WM_NUM_SF_OUTPUTS_SHIFT
;
187 if (multisampled_fbo
) {
189 dw6
|= GEN6_WM_MSRAST_ON_PATTERN
;
191 dw6
|= GEN6_WM_MSRAST_OFF_PIXEL
;
193 if (prog_data
->persample_dispatch
)
194 dw6
|= GEN6_WM_MSDISPMODE_PERSAMPLE
;
196 dw6
|= GEN6_WM_MSDISPMODE_PERPIXEL
;
199 dw6
|= GEN6_WM_MSRAST_OFF_PIXEL
;
200 dw6
|= GEN6_WM_MSDISPMODE_PERSAMPLE
;
203 /* From the SNB PRM, volume 2 part 1, page 281:
204 * "If the PS kernel does not need the Position XY Offsets
205 * to compute a Position XY value, then this field should be
206 * programmed to POSOFFSET_NONE."
208 * "SW Recommendation: If the PS kernel needs the Position Offsets
209 * to compute a Position XY value, this field should match Position
210 * ZW Interpolation Mode to ensure a consistent position.xyzw
212 * We only require XY sample offsets. So, this recommendation doesn't
213 * look useful at the moment. We might need this in future.
215 if (prog_data
->uses_pos_offset
)
216 dw6
|= GEN6_WM_POSOFFSET_SAMPLE
;
218 dw6
|= GEN6_WM_POSOFFSET_NONE
;
221 OUT_BATCH(_3DSTATE_WM
<< 16 | (9 - 2));
224 if (prog_data
->base
.total_scratch
) {
225 OUT_RELOC(stage_state
->scratch_bo
,
226 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
227 ffs(stage_state
->per_thread_scratch
) - 11);
234 OUT_BATCH(0); /* kernel 1 pointer */
240 upload_wm_state(struct brw_context
*brw
)
242 struct gl_context
*ctx
= &brw
->ctx
;
243 /* BRW_NEW_FS_PROG_DATA */
244 const struct brw_wm_prog_data
*prog_data
=
245 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
248 const bool multisampled_fbo
= _mesa_geometric_samples(ctx
->DrawBuffer
) > 1;
250 /* BRW_NEW_FS_PROG_DATA | _NEW_COLOR */
251 const bool dual_src_blend_enable
= prog_data
->dual_src_blend
&&
252 (ctx
->Color
.BlendEnabled
& 1) &&
253 ctx
->Color
.Blend
[0]._UsesDualSrc
;
255 /* _NEW_COLOR, _NEW_MULTISAMPLE */
256 const bool kill_enable
= prog_data
->uses_kill
|| ctx
->Color
.AlphaEnabled
||
257 ctx
->Multisample
.SampleAlphaToCoverage
||
258 prog_data
->uses_omask
;
260 /* Rendering against the gl-context is always taken into account. */
261 const bool statistic_enable
= true;
263 /* _NEW_LINE | _NEW_POLYGON | _NEW_BUFFERS | _NEW_COLOR |
266 gen6_upload_wm_state(brw
, prog_data
, &brw
->wm
.base
,
268 dual_src_blend_enable
, kill_enable
,
269 brw_color_buffer_write_enabled(brw
),
270 ctx
->Multisample
.Enabled
,
271 ctx
->Line
.StippleFlag
, ctx
->Polygon
.StippleFlag
,
275 const struct brw_tracked_state gen6_wm_state
= {
277 .mesa
= _NEW_BUFFERS
|
282 _NEW_PROGRAM_CONSTANTS
,
283 .brw
= BRW_NEW_BATCH
|
285 BRW_NEW_FS_PROG_DATA
|
286 BRW_NEW_PUSH_CONSTANT_ALLOCATION
,
288 .emit
= upload_wm_state
,