Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 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_context.h" |
||
31 | #include "st_atom.h" |
||
32 | |||
33 | #include "cso_cache/cso_context.h" |
||
34 | |||
35 | |||
36 | /* Second state atom for user clip planes: |
||
37 | */ |
||
38 | static void update_sample_mask( struct st_context *st ) |
||
39 | { |
||
40 | unsigned sample_mask = 0xffffffff; |
||
41 | unsigned sample_count = 1; |
||
42 | struct pipe_framebuffer_state *framebuffer = &st->state.framebuffer; |
||
43 | |||
44 | /* dependency here on bound surface (or rather, sample count) is worrying */ |
||
45 | if (framebuffer->zsbuf) |
||
46 | sample_count = framebuffer->zsbuf->texture->nr_samples; |
||
47 | else if (framebuffer->cbufs[0]) |
||
48 | sample_count = framebuffer->cbufs[0]->texture->nr_samples; |
||
49 | |||
50 | if (st->ctx->Multisample.Enabled && sample_count > 1) { |
||
51 | /* unlike in gallium/d3d10 the mask is only active if msaa is enabled */ |
||
52 | if (st->ctx->Multisample.SampleCoverage) { |
||
53 | unsigned nr_bits; |
||
54 | nr_bits = (unsigned) |
||
55 | (st->ctx->Multisample.SampleCoverageValue * (float)sample_count); |
||
56 | /* there's lot of ways how to do this. We just use first few bits, |
||
57 | since we have no knowledge of sample positions here. When |
||
58 | app-supplied mask though is used too might need to be smarter. |
||
59 | Also, there's a interface restriction here in theory it is |
||
60 | encouraged this mask not be the same at each pixel. */ |
||
61 | sample_mask = (1 << nr_bits) - 1; |
||
62 | if (st->ctx->Multisample.SampleCoverageInvert) |
||
63 | sample_mask = ~sample_mask; |
||
64 | } |
||
65 | if (st->ctx->Multisample.SampleMask) |
||
66 | sample_mask &= st->ctx->Multisample.SampleMaskValue; |
||
67 | } |
||
68 | |||
69 | /* mask off unused bits or don't care? */ |
||
70 | |||
71 | if (sample_mask != st->state.sample_mask) { |
||
72 | st->state.sample_mask = sample_mask; |
||
73 | cso_set_sample_mask(st->cso_context, sample_mask); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | |||
78 | const struct st_tracked_state st_update_msaa = { |
||
79 | "st_update_msaa", /* name */ |
||
80 | { /* dirty */ |
||
81 | (_NEW_MULTISAMPLE | _NEW_BUFFERS), /* mesa */ |
||
82 | ST_NEW_FRAMEBUFFER, /* st */ |
||
83 | }, |
||
84 | update_sample_mask /* update */ |
||
85 | };><> |