2 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Rob Clark <robclark@freedesktop.org>
28 #include "pipe/p_state.h"
29 #include "util/u_string.h"
30 #include "util/u_memory.h"
33 #include "fd2_context.h"
37 fd2_zsa_state_create(struct pipe_context
*pctx
,
38 const struct pipe_depth_stencil_alpha_state
*cso
)
40 struct fd2_zsa_stateobj
*so
;
42 so
= CALLOC_STRUCT(fd2_zsa_stateobj
);
48 so
->rb_depthcontrol
|=
49 A2XX_RB_DEPTHCONTROL_ZFUNC(cso
->depth
.func
); /* maps 1:1 */
51 if (cso
->depth
.enabled
)
52 so
->rb_depthcontrol
|= A2XX_RB_DEPTHCONTROL_Z_ENABLE
;
53 if (cso
->depth
.writemask
)
54 so
->rb_depthcontrol
|= A2XX_RB_DEPTHCONTROL_Z_WRITE_ENABLE
;
56 if (cso
->stencil
[0].enabled
) {
57 const struct pipe_stencil_state
*s
= &cso
->stencil
[0];
59 so
->rb_depthcontrol
|=
60 A2XX_RB_DEPTHCONTROL_STENCIL_ENABLE
|
61 A2XX_RB_DEPTHCONTROL_STENCILFUNC(s
->func
) | /* maps 1:1 */
62 A2XX_RB_DEPTHCONTROL_STENCILFAIL(fd_stencil_op(s
->fail_op
)) |
63 A2XX_RB_DEPTHCONTROL_STENCILZPASS(fd_stencil_op(s
->zpass_op
)) |
64 A2XX_RB_DEPTHCONTROL_STENCILZFAIL(fd_stencil_op(s
->zfail_op
));
65 so
->rb_stencilrefmask
|=
66 0xff000000 | /* ??? */
67 A2XX_RB_STENCILREFMASK_STENCILWRITEMASK(s
->writemask
) |
68 A2XX_RB_STENCILREFMASK_STENCILMASK(s
->valuemask
);
70 if (cso
->stencil
[1].enabled
) {
71 const struct pipe_stencil_state
*bs
= &cso
->stencil
[1];
73 so
->rb_depthcontrol
|=
74 A2XX_RB_DEPTHCONTROL_BACKFACE_ENABLE
|
75 A2XX_RB_DEPTHCONTROL_STENCILFUNC_BF(bs
->func
) | /* maps 1:1 */
76 A2XX_RB_DEPTHCONTROL_STENCILFAIL_BF(fd_stencil_op(bs
->fail_op
)) |
77 A2XX_RB_DEPTHCONTROL_STENCILZPASS_BF(fd_stencil_op(bs
->zpass_op
)) |
78 A2XX_RB_DEPTHCONTROL_STENCILZFAIL_BF(fd_stencil_op(bs
->zfail_op
));
79 so
->rb_stencilrefmask_bf
|=
80 0xff000000 | /* ??? */
81 A2XX_RB_STENCILREFMASK_STENCILWRITEMASK(bs
->writemask
) |
82 A2XX_RB_STENCILREFMASK_STENCILMASK(bs
->valuemask
);
86 if (cso
->alpha
.enabled
) {
88 A2XX_RB_COLORCONTROL_ALPHA_FUNC(cso
->alpha
.func
) |
89 A2XX_RB_COLORCONTROL_ALPHA_TEST_ENABLE
;
90 so
->rb_alpha_ref
= fui(cso
->alpha
.ref_value
);