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/prog_parameter.h"
31 #include "program/prog_statevars.h"
32 #include "intel_batchbuffer.h"
35 gen7_prepare_wm_constants(struct brw_context
*brw
)
37 struct intel_context
*intel
= &brw
->intel
;
38 struct gl_context
*ctx
= &intel
->ctx
;
39 const struct brw_fragment_program
*fp
=
40 brw_fragment_program_const(brw
->fragment_program
);
42 /* Updates the ParameterValues[i] pointers for all parameters of the
43 * basic type of PROGRAM_STATE_VAR.
45 /* XXX: Should this happen somewhere before to get our state flag set? */
46 _mesa_load_state_parameters(ctx
, fp
->program
.Base
.Parameters
);
48 /* BRW_NEW_FRAGMENT_PROGRAM */
49 if (brw
->wm
.prog_data
->nr_params
!= 0) {
53 constants
= brw_state_batch(brw
,
54 brw
->wm
.prog_data
->nr_params
*
56 32, &brw
->wm
.push_const_offset
);
58 for (i
= 0; i
< brw
->wm
.prog_data
->nr_params
; i
++) {
59 constants
[i
] = convert_param(brw
->wm
.prog_data
->param_convert
[i
],
60 *brw
->wm
.prog_data
->param
[i
]);
64 printf("WM constants:\n");
65 for (i
= 0; i
< brw
->wm
.prog_data
->nr_params
; i
++) {
67 printf("g%d: ", brw
->wm
.prog_data
->first_curbe_grf
+ i
/ 8);
68 printf("%8f ", constants
[i
]);
79 const struct brw_tracked_state gen7_wm_constants
= {
81 .mesa
= _NEW_PROGRAM_CONSTANTS
,
82 .brw
= (BRW_NEW_BATCH
| BRW_NEW_FRAGMENT_PROGRAM
),
85 .prepare
= gen7_prepare_wm_constants
,
89 upload_wm_state(struct brw_context
*brw
)
91 struct intel_context
*intel
= &brw
->intel
;
92 struct gl_context
*ctx
= &intel
->ctx
;
93 const struct brw_fragment_program
*fp
=
94 brw_fragment_program_const(brw
->fragment_program
);
95 bool writes_depth
= false;
99 dw1
|= GEN7_WM_STATISTICS_ENABLE
;
100 dw1
|= GEN7_WM_LINE_AA_WIDTH_1_0
;
101 dw1
|= GEN7_WM_LINE_END_CAP_AA_WIDTH_0_5
;
104 if (ctx
->Line
.StippleFlag
)
105 dw1
|= GEN7_WM_LINE_STIPPLE_ENABLE
;
107 /* _NEW_POLYGONSTIPPLE */
108 if (ctx
->Polygon
.StippleFlag
)
109 dw1
|= GEN7_WM_POLYGON_STIPPLE_ENABLE
;
111 /* BRW_NEW_FRAGMENT_PROGRAM */
112 if (fp
->program
.Base
.InputsRead
& (1 << FRAG_ATTRIB_WPOS
))
113 dw1
|= GEN7_WM_USES_SOURCE_DEPTH
| GEN7_WM_USES_SOURCE_W
;
114 if (fp
->program
.Base
.OutputsWritten
& BITFIELD64_BIT(FRAG_RESULT_DEPTH
)) {
116 dw1
|= GEN7_WM_PSCDEPTH_ON
;
120 if (fp
->program
.UsesKill
|| ctx
->Color
.AlphaEnabled
)
121 dw1
|= GEN7_WM_KILL_ENABLE
;
124 if (brw_color_buffer_write_enabled(brw
) || writes_depth
||
125 dw1
& GEN7_WM_KILL_ENABLE
) {
126 dw1
|= GEN7_WM_DISPATCH_ENABLE
;
129 dw1
|= GEN7_WM_PERSPECTIVE_PIXEL_BARYCENTRIC
;
132 OUT_BATCH(_3DSTATE_WM
<< 16 | (3 - 2));
138 const struct brw_tracked_state gen7_wm_state
= {
140 .mesa
= (_NEW_LINE
| _NEW_POLYGON
| _NEW_POLYGONSTIPPLE
|
141 _NEW_COLOR
| _NEW_BUFFERS
),
142 .brw
= (BRW_NEW_CURBE_OFFSETS
|
143 BRW_NEW_FRAGMENT_PROGRAM
|
144 BRW_NEW_NR_WM_SURFACES
|
149 .emit
= upload_wm_state
,
153 upload_ps_state(struct brw_context
*brw
)
155 struct intel_context
*intel
= &brw
->intel
;
156 uint32_t dw2
, dw4
, dw5
;
159 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS_PS
<< 16 | (2 - 2));
160 OUT_BATCH(brw
->wm
.bind_bo_offset
);
163 /* CACHE_NEW_SAMPLER */
165 OUT_BATCH(_3DSTATE_SAMPLER_STATE_POINTERS_PS
<< 16 | (2 - 2));
166 OUT_BATCH(brw
->wm
.sampler_offset
);
169 /* CACHE_NEW_WM_PROG */
170 if (brw
->wm
.prog_data
->nr_params
== 0) {
171 /* Disable the push constant buffers. */
173 OUT_BATCH(_3DSTATE_CONSTANT_PS
<< 16 | (7 - 2));
183 OUT_BATCH(_3DSTATE_CONSTANT_PS
<< 16 | (7 - 2));
185 OUT_BATCH(ALIGN(brw
->wm
.prog_data
->nr_params
,
186 brw
->wm
.prog_data
->dispatch_width
) / 8);
188 /* Pointer to the WM constant buffer. Covered by the set of
189 * state flags from gen7_prepare_wm_constants
191 OUT_BATCH(brw
->wm
.push_const_offset
);
200 dw2
|= (ALIGN(brw
->wm
.sampler_count
, 4) / 4) << GEN7_PS_SAMPLER_COUNT_SHIFT
;
202 /* BRW_NEW_NR_WM_SURFACES */
203 dw2
|= brw
->wm
.nr_surfaces
<< GEN7_PS_BINDING_TABLE_ENTRY_COUNT_SHIFT
;
205 /* OpenGL non-ieee floating point mode */
206 dw2
|= GEN7_PS_FLOATING_POINT_MODE_ALT
;
208 /* CACHE_NEW_SAMPLER */
209 dw4
|= (brw
->wm_max_threads
- 1) << GEN7_PS_MAX_THREADS_SHIFT
;
211 /* CACHE_NEW_WM_PROG */
212 if (brw
->wm
.prog_data
->nr_params
> 0)
213 dw4
|= GEN7_PS_PUSH_CONSTANT_ENABLE
;
215 /* BRW_NEW_FRAGMENT_PROGRAM */
216 if (brw
->fragment_program
->Base
.InputsRead
!= 0)
217 dw4
|= GEN7_PS_ATTRIBUTE_ENABLE
;
219 if (brw
->wm
.prog_data
->dispatch_width
== 8)
220 dw4
|= GEN7_PS_8_DISPATCH_ENABLE
;
222 dw4
|= GEN7_PS_16_DISPATCH_ENABLE
;
224 /* BRW_NEW_CURBE_OFFSETS */
225 dw5
|= (brw
->wm
.prog_data
->first_curbe_grf
<<
226 GEN7_PS_DISPATCH_START_GRF_SHIFT_0
);
229 OUT_BATCH(_3DSTATE_PS
<< 16 | (8 - 2));
230 OUT_BATCH(brw
->wm
.prog_offset
);
232 OUT_BATCH(0); /* scratch space base offset */
235 OUT_BATCH(0); /* kernel 1 pointer */
236 OUT_BATCH(brw
->wm
.prog_offset
+ brw
->wm
.prog_data
->prog_offset_16
);
240 const struct brw_tracked_state gen7_ps_state
= {
242 .mesa
= (_NEW_LINE
| _NEW_POLYGON
| _NEW_POLYGONSTIPPLE
|
243 _NEW_PROGRAM_CONSTANTS
),
244 .brw
= (BRW_NEW_CURBE_OFFSETS
|
245 BRW_NEW_FRAGMENT_PROGRAM
|
246 BRW_NEW_NR_WM_SURFACES
|
247 BRW_NEW_PS_BINDING_TABLE
|
250 .cache
= (CACHE_NEW_SAMPLER
|
253 .emit
= upload_ps_state
,