Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a2xx/fd2_zsa.c
4574 views
1
/*
2
* Copyright (C) 2012 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 "fd2_context.h"
32
#include "fd2_util.h"
33
#include "fd2_zsa.h"
34
35
void *
36
fd2_zsa_state_create(struct pipe_context *pctx,
37
const struct pipe_depth_stencil_alpha_state *cso)
38
{
39
struct fd2_zsa_stateobj *so;
40
41
so = CALLOC_STRUCT(fd2_zsa_stateobj);
42
if (!so)
43
return NULL;
44
45
so->base = *cso;
46
47
so->rb_depthcontrol |=
48
A2XX_RB_DEPTHCONTROL_ZFUNC(cso->depth_func); /* maps 1:1 */
49
50
if (cso->depth_enabled)
51
so->rb_depthcontrol |=
52
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 = 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);
91
}
92
93
return so;
94
}
95
96