2 * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
3 * Copyright © 2018 Google, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Rob Clark <robclark@freedesktop.org>
29 #include "pipe/p_state.h"
30 #include "util/u_string.h"
31 #include "util/u_memory.h"
34 #include "fd6_context.h"
35 #include "fd6_format.h"
38 fd6_zsa_state_create(struct pipe_context
*pctx
,
39 const struct pipe_depth_stencil_alpha_state
*cso
)
41 struct fd6_zsa_stateobj
*so
;
43 so
= CALLOC_STRUCT(fd6_zsa_stateobj
);
49 switch (cso
->depth
.func
) {
51 case PIPE_FUNC_LEQUAL
:
52 so
->gras_lrz_cntl
= A6XX_GRAS_LRZ_CNTL_ENABLE
;
55 case PIPE_FUNC_GREATER
:
56 case PIPE_FUNC_GEQUAL
:
57 so
->gras_lrz_cntl
= A6XX_GRAS_LRZ_CNTL_ENABLE
| A6XX_GRAS_LRZ_CNTL_GREATER
;
62 so
->gras_lrz_cntl
= 0;
66 if (!(cso
->stencil
->enabled
|| cso
->alpha
.enabled
|| !cso
->depth
.writemask
))
70 A6XX_RB_DEPTH_CNTL_ZFUNC(cso
->depth
.func
); /* maps 1:1 */
72 if (cso
->depth
.enabled
)
74 A6XX_RB_DEPTH_CNTL_Z_ENABLE
|
75 A6XX_RB_DEPTH_CNTL_Z_TEST_ENABLE
;
77 if (cso
->depth
.writemask
)
78 so
->rb_depth_cntl
|= A6XX_RB_DEPTH_CNTL_Z_WRITE_ENABLE
;
80 if (cso
->stencil
[0].enabled
) {
81 const struct pipe_stencil_state
*s
= &cso
->stencil
[0];
83 so
->rb_stencil_control
|=
84 A6XX_RB_STENCIL_CONTROL_STENCIL_READ
|
85 A6XX_RB_STENCIL_CONTROL_STENCIL_ENABLE
|
86 A6XX_RB_STENCIL_CONTROL_FUNC(s
->func
) | /* maps 1:1 */
87 A6XX_RB_STENCIL_CONTROL_FAIL(fd_stencil_op(s
->fail_op
)) |
88 A6XX_RB_STENCIL_CONTROL_ZPASS(fd_stencil_op(s
->zpass_op
)) |
89 A6XX_RB_STENCIL_CONTROL_ZFAIL(fd_stencil_op(s
->zfail_op
));
91 so
->rb_stencilmask
= A6XX_RB_STENCILMASK_MASK(s
->valuemask
);
92 so
->rb_stencilwrmask
= A6XX_RB_STENCILWRMASK_WRMASK(s
->writemask
);
94 if (cso
->stencil
[1].enabled
) {
95 const struct pipe_stencil_state
*bs
= &cso
->stencil
[1];
97 so
->rb_stencil_control
|=
98 A6XX_RB_STENCIL_CONTROL_STENCIL_ENABLE_BF
|
99 A6XX_RB_STENCIL_CONTROL_FUNC_BF(bs
->func
) | /* maps 1:1 */
100 A6XX_RB_STENCIL_CONTROL_FAIL_BF(fd_stencil_op(bs
->fail_op
)) |
101 A6XX_RB_STENCIL_CONTROL_ZPASS_BF(fd_stencil_op(bs
->zpass_op
)) |
102 A6XX_RB_STENCIL_CONTROL_ZFAIL_BF(fd_stencil_op(bs
->zfail_op
));
104 so
->rb_stencilmask
|= A6XX_RB_STENCILMASK_BFMASK(bs
->valuemask
);
105 so
->rb_stencilwrmask
|= A6XX_RB_STENCILWRMASK_BFWRMASK(bs
->writemask
);
109 if (cso
->alpha
.enabled
) {
110 uint32_t ref
= cso
->alpha
.ref_value
* 255.0;
111 so
->rb_alpha_control
=
112 A6XX_RB_ALPHA_CONTROL_ALPHA_TEST
|
113 A6XX_RB_ALPHA_CONTROL_ALPHA_REF(ref
) |
114 A6XX_RB_ALPHA_CONTROL_ALPHA_TEST_FUNC(cso
->alpha
.func
);
115 // so->rb_depth_control |=
116 // A6XX_RB_DEPTH_CONTROL_EARLY_Z_DISABLE;