broadcom/vc5: Fix CLIF dumping of lists that aren't capped by a HALT.
[mesa.git] / src / mesa / state_tracker / st_atom_msaa.c
1 /**************************************************************************
2 *
3 * Copyright 2010 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "st_context.h"
30 #include "pipe/p_screen.h"
31 #include "pipe/p_context.h"
32 #include "st_atom.h"
33 #include "st_program.h"
34
35 #include "cso_cache/cso_context.h"
36 #include "main/framebuffer.h"
37
38
39 /* Update the sample mask for MSAA.
40 */
41 void
42 st_update_sample_mask(struct st_context *st)
43 {
44 unsigned sample_mask = 0xffffffff;
45 unsigned sample_count = st->state.fb_num_samples;
46
47 if (_mesa_is_multisample_enabled(st->ctx) && sample_count > 1) {
48 /* unlike in gallium/d3d10 the mask is only active if msaa is enabled */
49 if (st->ctx->Multisample.SampleCoverage) {
50 unsigned nr_bits = (unsigned)
51 (st->ctx->Multisample.SampleCoverageValue * (float) sample_count);
52 /* there's lot of ways how to do this. We just use first few bits,
53 * since we have no knowledge of sample positions here. When
54 * app-supplied mask though is used too might need to be smarter.
55 * Also, there's an interface restriction here in theory it is
56 * encouraged this mask not be the same at each pixel.
57 */
58 sample_mask = (1 << nr_bits) - 1;
59 if (st->ctx->Multisample.SampleCoverageInvert)
60 sample_mask = ~sample_mask;
61 }
62 if (st->ctx->Multisample.SampleMask)
63 sample_mask &= st->ctx->Multisample.SampleMaskValue;
64 }
65
66 cso_set_sample_mask(st->cso_context, sample_mask);
67 }
68
69
70 void
71 st_update_sample_shading(struct st_context *st)
72 {
73 if (!st->fp)
74 return;
75
76 if (!st->ctx->Extensions.ARB_sample_shading)
77 return;
78
79 cso_set_min_samples(st->cso_context,
80 _mesa_get_min_invocations_per_fragment(st->ctx, &st->fp->Base, false));
81 }