Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a4xx/fd4_zsa.c
4574 views
1
/*
2
* Copyright (C) 2014 Rob Clark <[email protected]>
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 <[email protected]>
25
*/
26
27
#include "pipe/p_state.h"
28
#include "util/u_memory.h"
29
#include "util/u_string.h"
30
31
#include "fd4_context.h"
32
#include "fd4_format.h"
33
#include "fd4_zsa.h"
34
35
void *
36
fd4_zsa_state_create(struct pipe_context *pctx,
37
const struct pipe_depth_stencil_alpha_state *cso)
38
{
39
struct fd4_zsa_stateobj *so;
40
41
so = CALLOC_STRUCT(fd4_zsa_stateobj);
42
if (!so)
43
return NULL;
44
45
so->base = *cso;
46
47
so->rb_depth_control |=
48
A4XX_RB_DEPTH_CONTROL_ZFUNC(cso->depth_func); /* maps 1:1 */
49
50
if (cso->depth_enabled)
51
so->rb_depth_control |=
52
A4XX_RB_DEPTH_CONTROL_Z_ENABLE | A4XX_RB_DEPTH_CONTROL_Z_TEST_ENABLE;
53
54
if (cso->depth_writemask)
55
so->rb_depth_control |= A4XX_RB_DEPTH_CONTROL_Z_WRITE_ENABLE;
56
57
if (cso->stencil[0].enabled) {
58
const struct pipe_stencil_state *s = &cso->stencil[0];
59
60
so->rb_stencil_control |=
61
A4XX_RB_STENCIL_CONTROL_STENCIL_READ |
62
A4XX_RB_STENCIL_CONTROL_STENCIL_ENABLE |
63
A4XX_RB_STENCIL_CONTROL_FUNC(s->func) | /* maps 1:1 */
64
A4XX_RB_STENCIL_CONTROL_FAIL(fd_stencil_op(s->fail_op)) |
65
A4XX_RB_STENCIL_CONTROL_ZPASS(fd_stencil_op(s->zpass_op)) |
66
A4XX_RB_STENCIL_CONTROL_ZFAIL(fd_stencil_op(s->zfail_op));
67
so->rb_stencil_control2 |= A4XX_RB_STENCIL_CONTROL2_STENCIL_BUFFER;
68
so->rb_stencilrefmask |=
69
0xff000000 | /* ??? */
70
A4XX_RB_STENCILREFMASK_STENCILWRITEMASK(s->writemask) |
71
A4XX_RB_STENCILREFMASK_STENCILMASK(s->valuemask);
72
73
if (cso->stencil[1].enabled) {
74
const struct pipe_stencil_state *bs = &cso->stencil[1];
75
76
so->rb_stencil_control |=
77
A4XX_RB_STENCIL_CONTROL_STENCIL_ENABLE_BF |
78
A4XX_RB_STENCIL_CONTROL_FUNC_BF(bs->func) | /* maps 1:1 */
79
A4XX_RB_STENCIL_CONTROL_FAIL_BF(fd_stencil_op(bs->fail_op)) |
80
A4XX_RB_STENCIL_CONTROL_ZPASS_BF(fd_stencil_op(bs->zpass_op)) |
81
A4XX_RB_STENCIL_CONTROL_ZFAIL_BF(fd_stencil_op(bs->zfail_op));
82
so->rb_stencilrefmask_bf |=
83
0xff000000 | /* ??? */
84
A4XX_RB_STENCILREFMASK_BF_STENCILWRITEMASK(bs->writemask) |
85
A4XX_RB_STENCILREFMASK_BF_STENCILMASK(bs->valuemask);
86
}
87
}
88
89
if (cso->alpha_enabled) {
90
uint32_t ref = cso->alpha_ref_value * 255.0;
91
so->gras_alpha_control = A4XX_GRAS_ALPHA_CONTROL_ALPHA_TEST_ENABLE;
92
so->rb_alpha_control =
93
A4XX_RB_ALPHA_CONTROL_ALPHA_TEST |
94
A4XX_RB_ALPHA_CONTROL_ALPHA_REF(ref) |
95
A4XX_RB_ALPHA_CONTROL_ALPHA_TEST_FUNC(cso->alpha_func);
96
so->rb_depth_control |= A4XX_RB_DEPTH_CONTROL_EARLY_Z_DISABLE;
97
}
98
99
return so;
100
}
101
102