1 /*
2 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Rob Clark <robclark@freedesktop.org>
25 */
26
27
28 #include "pipe/p_state.h"
29 #include "util/u_string.h"
30 #include "util/u_memory.h"
31
32 #include "fd2_zsa.h"
33 #include "fd2_context.h"
34 #include "fd2_util.h"
35
36 void *
fd2_zsa_state_create(struct pipe_context * pctx,const struct pipe_depth_stencil_alpha_state * cso)37 fd2_zsa_state_create(struct pipe_context *pctx,
38 const struct pipe_depth_stencil_alpha_state *cso)
39 {
40 struct fd2_zsa_stateobj *so;
41
42 so = CALLOC_STRUCT(fd2_zsa_stateobj);
43 if (!so)
44 return NULL;
45
46 so->base = *cso;
47
48 so->rb_depthcontrol |=
49 A2XX_RB_DEPTHCONTROL_ZFUNC(cso->depth.func); /* maps 1:1 */
50
51 if (cso->depth.enabled)
52 so->rb_depthcontrol |= A2XX_RB_DEPTHCONTROL_Z_ENABLE |
53 COND(!cso->alpha.enabled, A2XX_RB_DEPTHCONTROL_EARLY_Z_ENABLE);
54 if (cso->depth.writemask)
55 so->rb_depthcontrol |= A2XX_RB_DEPTHCONTROL_Z_WRITE_ENABLE;
56
57 if (cso->stencil[0].enabled) {
58 const struct pipe_stencil_state *s = &cso->stencil[0];
59
60 so->rb_depthcontrol |=
61 A2XX_RB_DEPTHCONTROL_STENCIL_ENABLE |
62 A2XX_RB_DEPTHCONTROL_STENCILFUNC(s->func) | /* maps 1:1 */
63 A2XX_RB_DEPTHCONTROL_STENCILFAIL(fd_stencil_op(s->fail_op)) |
64 A2XX_RB_DEPTHCONTROL_STENCILZPASS(fd_stencil_op(s->zpass_op)) |
65 A2XX_RB_DEPTHCONTROL_STENCILZFAIL(fd_stencil_op(s->zfail_op));
66 so->rb_stencilrefmask |=
67 0xff000000 | /* ??? */
68 A2XX_RB_STENCILREFMASK_STENCILWRITEMASK(s->writemask) |
69 A2XX_RB_STENCILREFMASK_STENCILMASK(s->valuemask);
70
71 if (cso->stencil[1].enabled) {
72 const struct pipe_stencil_state *bs = &cso->stencil[1];
73
74 so->rb_depthcontrol |=
75 A2XX_RB_DEPTHCONTROL_BACKFACE_ENABLE |
76 A2XX_RB_DEPTHCONTROL_STENCILFUNC_BF(bs->func) | /* maps 1:1 */
77 A2XX_RB_DEPTHCONTROL_STENCILFAIL_BF(fd_stencil_op(bs->fail_op)) |
78 A2XX_RB_DEPTHCONTROL_STENCILZPASS_BF(fd_stencil_op(bs->zpass_op)) |
79 A2XX_RB_DEPTHCONTROL_STENCILZFAIL_BF(fd_stencil_op(bs->zfail_op));
80 so->rb_stencilrefmask_bf |=
81 0xff000000 | /* ??? */
82 A2XX_RB_STENCILREFMASK_STENCILWRITEMASK(bs->writemask) |
83 A2XX_RB_STENCILREFMASK_STENCILMASK(bs->valuemask);
84 }
85 }
86
87 if (cso->alpha.enabled) {
88 so->rb_colorcontrol =
89 A2XX_RB_COLORCONTROL_ALPHA_FUNC(cso->alpha.func) |
90 A2XX_RB_COLORCONTROL_ALPHA_TEST_ENABLE;
91 so->rb_alpha_ref = fui(cso->alpha.ref_value);
92 }
93
94 return so;
95 }
96