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"
34 gen6_emit_3dstate_multisample(struct brw_context
*brw
,
37 struct intel_context
*intel
= &brw
->intel
;
39 uint32_t number_of_multisamples
= 0;
40 uint32_t sample_positions_3210
= 0;
41 uint32_t sample_positions_7654
= 0;
43 switch (num_samples
) {
45 number_of_multisamples
= MS_NUMSAMPLES_1
;
48 number_of_multisamples
= MS_NUMSAMPLES_4
;
56 sample_positions_3210
= 0xae2ae662;
59 number_of_multisamples
= MS_NUMSAMPLES_8
;
60 /* Sample positions are based on a solution to the "8 queens" puzzle.
61 * Rationale: in a solution to the 8 queens puzzle, no two queens share
62 * a row, column, or diagonal. This is a desirable property for samples
63 * in a multisampling pattern, because it ensures that the samples are
64 * relatively uniformly distributed through the pixel.
66 * There are several solutions to the 8 queens puzzle (see
67 * http://en.wikipedia.org/wiki/Eight_queens_puzzle). This solution was
68 * chosen because it has a queen close to the center; this should
69 * improve the accuracy of centroid interpolation, since the hardware
70 * implements centroid interpolation by choosing the centermost sample
71 * that overlaps with the primitive being drawn.
73 * Note: from the Ivy Bridge PRM, Vol2 Part1 p304 (3DSTATE_MULTISAMPLE:
76 * "When programming the sample offsets (for NUMSAMPLES_4 or _8 and
77 * MSRASTMODE_xxx_PATTERN), the order of the samples 0 to 3 (or 7
78 * for 8X) must have monotonically increasing distance from the
79 * pixel center. This is required to get the correct centroid
80 * computation in the device."
93 sample_positions_3210
= 0xdbb39d79;
94 sample_positions_7654
= 0x3ff55117;
97 assert(!"Unrecognized num_samples in gen6_emit_3dstate_multisample");
101 int len
= intel
->gen
>= 7 ? 4 : 3;
103 OUT_BATCH(_3DSTATE_MULTISAMPLE
<< 16 | (len
- 2));
104 OUT_BATCH(MS_PIXEL_LOCATION_CENTER
| number_of_multisamples
);
105 OUT_BATCH(sample_positions_3210
);
107 OUT_BATCH(sample_positions_7654
);
113 * 3DSTATE_SAMPLE_MASK
116 gen6_emit_3dstate_sample_mask(struct brw_context
*brw
,
117 unsigned num_samples
, float coverage
,
118 bool coverage_invert
)
120 struct intel_context
*intel
= &brw
->intel
;
122 /* TODO: 8x MSAA not implemented */
123 assert(num_samples
<= 4);
126 OUT_BATCH(_3DSTATE_SAMPLE_MASK
<< 16 | (2 - 2));
127 if (num_samples
> 0) {
128 int coverage_int
= (int) (num_samples
* coverage
+ 0.5);
129 uint32_t coverage_bits
= (1 << coverage_int
) - 1;
131 coverage_bits
^= (1 << num_samples
) - 1;
132 OUT_BATCH(coverage_bits
);
140 static void upload_multisample_state(struct brw_context
*brw
)
142 struct intel_context
*intel
= &brw
->intel
;
143 struct gl_context
*ctx
= &intel
->ctx
;
144 float coverage
= 1.0;
145 float coverage_invert
= false;
148 unsigned num_samples
= ctx
->DrawBuffer
->Visual
.samples
;
150 /* _NEW_MULTISAMPLE */
151 if (ctx
->Multisample
._Enabled
&& ctx
->Multisample
.SampleCoverage
) {
152 coverage
= ctx
->Multisample
.SampleCoverageValue
;
153 coverage_invert
= ctx
->Multisample
.SampleCoverageInvert
;
156 /* 3DSTATE_MULTISAMPLE is nonpipelined. */
157 intel_emit_post_sync_nonzero_flush(intel
);
159 gen6_emit_3dstate_multisample(brw
, num_samples
);
160 gen6_emit_3dstate_sample_mask(brw
, num_samples
, coverage
, coverage_invert
);
164 const struct brw_tracked_state gen6_multisample_state
= {
166 .mesa
= _NEW_BUFFERS
|
168 .brw
= BRW_NEW_CONTEXT
,
171 .emit
= upload_multisample_state