i965: Remove never used RSR and RSL opcodes.
[mesa.git] / src / mesa / drivers / dri / i965 / gen7_wm_state.c
1 /*
2 * Copyright © 2011 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 #include <stdbool.h>
25 #include "brw_context.h"
26 #include "brw_state.h"
27 #include "brw_defines.h"
28 #include "brw_util.h"
29 #include "brw_wm.h"
30 #include "program/prog_parameter.h"
31 #include "program/prog_statevars.h"
32 #include "intel_batchbuffer.h"
33
34 static void
35 upload_wm_state(struct brw_context *brw)
36 {
37 struct gl_context *ctx = &brw->ctx;
38 const struct brw_fragment_program *fp =
39 brw_fragment_program_const(brw->fragment_program);
40 bool writes_depth = false;
41 uint32_t dw1, dw2;
42
43 /* _NEW_BUFFERS */
44 bool multisampled_fbo = ctx->DrawBuffer->Visual.samples > 1;
45
46 dw1 = dw2 = 0;
47 dw1 |= GEN7_WM_STATISTICS_ENABLE;
48 dw1 |= GEN7_WM_LINE_AA_WIDTH_1_0;
49 dw1 |= GEN7_WM_LINE_END_CAP_AA_WIDTH_0_5;
50
51 /* _NEW_LINE */
52 if (ctx->Line.StippleFlag)
53 dw1 |= GEN7_WM_LINE_STIPPLE_ENABLE;
54
55 /* _NEW_POLYGON */
56 if (ctx->Polygon.StippleFlag)
57 dw1 |= GEN7_WM_POLYGON_STIPPLE_ENABLE;
58
59 /* BRW_NEW_FRAGMENT_PROGRAM */
60 if (fp->program.Base.InputsRead & VARYING_BIT_POS)
61 dw1 |= GEN7_WM_USES_SOURCE_DEPTH | GEN7_WM_USES_SOURCE_W;
62 if (fp->program.Base.OutputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
63 writes_depth = true;
64 dw1 |= GEN7_WM_PSCDEPTH_ON;
65 }
66 /* CACHE_NEW_WM_PROG */
67 dw1 |= brw->wm.prog_data->barycentric_interp_modes <<
68 GEN7_WM_BARYCENTRIC_INTERPOLATION_MODE_SHIFT;
69
70 /* _NEW_COLOR, _NEW_MULTISAMPLE */
71 if (fp->program.UsesKill || ctx->Color.AlphaEnabled ||
72 ctx->Multisample.SampleAlphaToCoverage)
73 dw1 |= GEN7_WM_KILL_ENABLE;
74
75 /* _NEW_BUFFERS */
76 if (brw_color_buffer_write_enabled(brw) || writes_depth ||
77 dw1 & GEN7_WM_KILL_ENABLE) {
78 dw1 |= GEN7_WM_DISPATCH_ENABLE;
79 }
80 if (multisampled_fbo) {
81 /* _NEW_MULTISAMPLE */
82 if (ctx->Multisample.Enabled)
83 dw1 |= GEN7_WM_MSRAST_ON_PATTERN;
84 else
85 dw1 |= GEN7_WM_MSRAST_OFF_PIXEL;
86 dw2 |= GEN7_WM_MSDISPMODE_PERPIXEL;
87 } else {
88 dw1 |= GEN7_WM_MSRAST_OFF_PIXEL;
89 dw2 |= GEN7_WM_MSDISPMODE_PERSAMPLE;
90 }
91
92 BEGIN_BATCH(3);
93 OUT_BATCH(_3DSTATE_WM << 16 | (3 - 2));
94 OUT_BATCH(dw1);
95 OUT_BATCH(dw2);
96 ADVANCE_BATCH();
97 }
98
99 const struct brw_tracked_state gen7_wm_state = {
100 .dirty = {
101 .mesa = (_NEW_LINE | _NEW_POLYGON |
102 _NEW_COLOR | _NEW_BUFFERS |
103 _NEW_MULTISAMPLE),
104 .brw = (BRW_NEW_FRAGMENT_PROGRAM |
105 BRW_NEW_BATCH),
106 .cache = CACHE_NEW_WM_PROG,
107 },
108 .emit = upload_wm_state,
109 };
110
111 static void
112 upload_ps_state(struct brw_context *brw)
113 {
114 struct gl_context *ctx = &brw->ctx;
115 uint32_t dw2, dw4, dw5;
116 const int max_threads_shift = brw->is_haswell ?
117 HSW_PS_MAX_THREADS_SHIFT : IVB_PS_MAX_THREADS_SHIFT;
118
119 /* BRW_NEW_PS_BINDING_TABLE */
120 BEGIN_BATCH(2);
121 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS_PS << 16 | (2 - 2));
122 OUT_BATCH(brw->wm.bind_bo_offset);
123 ADVANCE_BATCH();
124
125 /* CACHE_NEW_SAMPLER */
126 BEGIN_BATCH(2);
127 OUT_BATCH(_3DSTATE_SAMPLER_STATE_POINTERS_PS << 16 | (2 - 2));
128 OUT_BATCH(brw->wm.sampler_offset);
129 ADVANCE_BATCH();
130
131 /* CACHE_NEW_WM_PROG */
132 if (brw->wm.prog_data->nr_params == 0) {
133 /* Disable the push constant buffers. */
134 BEGIN_BATCH(7);
135 OUT_BATCH(_3DSTATE_CONSTANT_PS << 16 | (7 - 2));
136 OUT_BATCH(0);
137 OUT_BATCH(0);
138 OUT_BATCH(0);
139 OUT_BATCH(0);
140 OUT_BATCH(0);
141 OUT_BATCH(0);
142 ADVANCE_BATCH();
143 } else {
144 BEGIN_BATCH(7);
145 OUT_BATCH(_3DSTATE_CONSTANT_PS << 16 | (7 - 2));
146
147 OUT_BATCH(ALIGN(brw->wm.prog_data->nr_params,
148 brw->wm.prog_data->dispatch_width) / 8);
149 OUT_BATCH(0);
150 /* Pointer to the WM constant buffer. Covered by the set of
151 * state flags from gen6_upload_wm_push_constants.
152 */
153 OUT_BATCH(brw->wm.push_const_offset | GEN7_MOCS_L3);
154 OUT_BATCH(0);
155 OUT_BATCH(0);
156 OUT_BATCH(0);
157 ADVANCE_BATCH();
158 }
159
160 dw2 = dw4 = dw5 = 0;
161
162 /* CACHE_NEW_SAMPLER */
163 dw2 |= (ALIGN(brw->wm.sampler_count, 4) / 4) << GEN7_PS_SAMPLER_COUNT_SHIFT;
164
165 /* Use ALT floating point mode for ARB fragment programs, because they
166 * require 0^0 == 1. Even though _CurrentFragmentProgram is used for
167 * rendering, CurrentFragmentProgram is used for this check to
168 * differentiate between the GLSL and non-GLSL cases.
169 */
170 if (ctx->Shader.CurrentFragmentProgram == NULL)
171 dw2 |= GEN7_PS_FLOATING_POINT_MODE_ALT;
172
173 if (brw->is_haswell)
174 dw4 |= SET_FIELD(1, HSW_PS_SAMPLE_MASK); /* 1 sample for now */
175
176 dw4 |= (brw->max_wm_threads - 1) << max_threads_shift;
177
178 /* CACHE_NEW_WM_PROG */
179 if (brw->wm.prog_data->nr_params > 0)
180 dw4 |= GEN7_PS_PUSH_CONSTANT_ENABLE;
181
182 /* CACHE_NEW_WM_PROG | _NEW_COLOR
183 *
184 * The hardware wedges if you have this bit set but don't turn on any dual
185 * source blend factors.
186 */
187 if (brw->wm.prog_data->dual_src_blend &&
188 (ctx->Color.BlendEnabled & 1) &&
189 ctx->Color.Blend[0]._UsesDualSrc) {
190 dw4 |= GEN7_PS_DUAL_SOURCE_BLEND_ENABLE;
191 }
192
193 /* BRW_NEW_FRAGMENT_PROGRAM */
194 if (brw->fragment_program->Base.InputsRead != 0)
195 dw4 |= GEN7_PS_ATTRIBUTE_ENABLE;
196
197 dw4 |= GEN7_PS_8_DISPATCH_ENABLE;
198 if (brw->wm.prog_data->prog_offset_16)
199 dw4 |= GEN7_PS_16_DISPATCH_ENABLE;
200
201 dw5 |= (brw->wm.prog_data->first_curbe_grf <<
202 GEN7_PS_DISPATCH_START_GRF_SHIFT_0);
203 dw5 |= (brw->wm.prog_data->first_curbe_grf_16 <<
204 GEN7_PS_DISPATCH_START_GRF_SHIFT_2);
205
206 BEGIN_BATCH(8);
207 OUT_BATCH(_3DSTATE_PS << 16 | (8 - 2));
208 OUT_BATCH(brw->wm.prog_offset);
209 OUT_BATCH(dw2);
210 if (brw->wm.prog_data->total_scratch) {
211 OUT_RELOC(brw->wm.scratch_bo,
212 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
213 ffs(brw->wm.prog_data->total_scratch) - 11);
214 } else {
215 OUT_BATCH(0);
216 }
217 OUT_BATCH(dw4);
218 OUT_BATCH(dw5);
219 OUT_BATCH(0); /* kernel 1 pointer */
220 OUT_BATCH(brw->wm.prog_offset + brw->wm.prog_data->prog_offset_16);
221 ADVANCE_BATCH();
222 }
223
224 const struct brw_tracked_state gen7_ps_state = {
225 .dirty = {
226 .mesa = (_NEW_PROGRAM_CONSTANTS |
227 _NEW_COLOR),
228 .brw = (BRW_NEW_FRAGMENT_PROGRAM |
229 BRW_NEW_PS_BINDING_TABLE |
230 BRW_NEW_BATCH |
231 BRW_NEW_PUSH_CONSTANT_ALLOCATION),
232 .cache = (CACHE_NEW_SAMPLER |
233 CACHE_NEW_WM_PROG)
234 },
235 .emit = upload_ps_state,
236 };