2 * Copyright © 2012 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 #include "intel_batchbuffer.h"
26 #include "brw_context.h"
27 #include "brw_defines.h"
37 sample_positions_4x
[] = { 0xae2ae662 };
38 /* Sample positions are based on a solution to the "8 queens" puzzle.
39 * Rationale: in a solution to the 8 queens puzzle, no two queens share
40 * a row, column, or diagonal. This is a desirable property for samples
41 * in a multisampling pattern, because it ensures that the samples are
42 * relatively uniformly distributed through the pixel.
44 * There are several solutions to the 8 queens puzzle (see
45 * http://en.wikipedia.org/wiki/Eight_queens_puzzle). This solution was
46 * chosen because it has a queen close to the center; this should
47 * improve the accuracy of centroid interpolation, since the hardware
48 * implements centroid interpolation by choosing the centermost sample
49 * that overlaps with the primitive being drawn.
51 * Note: from the Ivy Bridge PRM, Vol2 Part1 p304 (3DSTATE_MULTISAMPLE:
54 * "When programming the sample offsets (for NUMSAMPLES_4 or _8 and
55 * MSRASTMODE_xxx_PATTERN), the order of the samples 0 to 3 (or 7
56 * for 8X) must have monotonically increasing distance from the
57 * pixel center. This is required to get the correct centroid
58 * computation in the device."
72 sample_positions_8x
[] = { 0xdbb39d79, 0x3ff55117 };
76 gen6_get_sample_position(struct gl_context
*ctx
,
77 struct gl_framebuffer
*fb
,
78 GLuint index
, GLfloat
*result
)
80 switch (fb
->Visual
.samples
) {
82 result
[0] = result
[1] = 0.5f
;
85 uint8_t val
= (uint8_t)(sample_positions_4x
[0] >> (8*index
));
86 result
[0] = ((val
>> 4) & 0xf) / 16.0f
;
87 result
[1] = (val
& 0xf) / 16.0f
;
91 uint8_t val
= (uint8_t)(sample_positions_8x
[index
>>2] >> (8*(index
& 3)));
92 result
[0] = ((val
>> 4) & 0xf) / 16.0f
;
93 result
[1] = (val
& 0xf) / 16.0f
;
97 assert(!"Not implemented");
102 * 3DSTATE_MULTISAMPLE
105 gen6_emit_3dstate_multisample(struct brw_context
*brw
,
106 unsigned num_samples
)
108 struct intel_context
*intel
= &brw
->intel
;
110 uint32_t number_of_multisamples
= 0;
111 uint32_t sample_positions_3210
= 0;
112 uint32_t sample_positions_7654
= 0;
114 switch (num_samples
) {
117 number_of_multisamples
= MS_NUMSAMPLES_1
;
120 number_of_multisamples
= MS_NUMSAMPLES_4
;
121 sample_positions_3210
= sample_positions_4x
[0];
124 number_of_multisamples
= MS_NUMSAMPLES_8
;
125 sample_positions_3210
= sample_positions_8x
[0];
126 sample_positions_7654
= sample_positions_8x
[1];
129 assert(!"Unrecognized num_samples in gen6_emit_3dstate_multisample");
133 int len
= intel
->gen
>= 7 ? 4 : 3;
135 OUT_BATCH(_3DSTATE_MULTISAMPLE
<< 16 | (len
- 2));
136 OUT_BATCH(MS_PIXEL_LOCATION_CENTER
| number_of_multisamples
);
137 OUT_BATCH(sample_positions_3210
);
139 OUT_BATCH(sample_positions_7654
);
145 * 3DSTATE_SAMPLE_MASK
148 gen6_emit_3dstate_sample_mask(struct brw_context
*brw
,
149 unsigned num_samples
, float coverage
,
150 bool coverage_invert
, unsigned sample_mask
)
152 struct intel_context
*intel
= &brw
->intel
;
155 OUT_BATCH(_3DSTATE_SAMPLE_MASK
<< 16 | (2 - 2));
156 if (num_samples
> 1) {
157 int coverage_int
= (int) (num_samples
* coverage
+ 0.5);
158 uint32_t coverage_bits
= (1 << coverage_int
) - 1;
160 coverage_bits
^= (1 << num_samples
) - 1;
161 OUT_BATCH(coverage_bits
& sample_mask
);
169 static void upload_multisample_state(struct brw_context
*brw
)
171 struct intel_context
*intel
= &brw
->intel
;
172 struct gl_context
*ctx
= &intel
->ctx
;
173 float coverage
= 1.0;
174 float coverage_invert
= false;
175 unsigned sample_mask
= ~0u;
178 unsigned num_samples
= ctx
->DrawBuffer
->Visual
.samples
;
180 /* _NEW_MULTISAMPLE */
181 if (ctx
->Multisample
._Enabled
) {
182 if (ctx
->Multisample
.SampleCoverage
) {
183 coverage
= ctx
->Multisample
.SampleCoverageValue
;
184 coverage_invert
= ctx
->Multisample
.SampleCoverageInvert
;
186 if (ctx
->Multisample
.SampleMask
) {
187 sample_mask
= ctx
->Multisample
.SampleMaskValue
;
191 /* 3DSTATE_MULTISAMPLE is nonpipelined. */
192 intel_emit_post_sync_nonzero_flush(intel
);
194 gen6_emit_3dstate_multisample(brw
, num_samples
);
195 gen6_emit_3dstate_sample_mask(brw
, num_samples
, coverage
,
196 coverage_invert
, sample_mask
);
200 const struct brw_tracked_state gen6_multisample_state
= {
202 .mesa
= _NEW_BUFFERS
|
204 .brw
= BRW_NEW_CONTEXT
,
207 .emit
= upload_multisample_state