1 /* 2 * Copyright © 2012 Rob Clark <[email protected]> 3 * SPDX-License-Identifier: MIT 4 * 5 * Authors: 6 * Rob Clark <[email protected]> 7 */ 8 9 #include "pipe/p_state.h" 10 #include "util/u_memory.h" 11 #include "util/u_string.h" 12 13 #include "fd2_context.h" 14 #include "fd2_util.h" 15 #include "fd2_zsa.h" 16 17 void * fd2_zsa_state_create(struct pipe_context * pctx,const struct pipe_depth_stencil_alpha_state * cso)18fd2_zsa_state_create(struct pipe_context *pctx, 19 const struct pipe_depth_stencil_alpha_state *cso) 20 { 21 struct fd2_zsa_stateobj *so; 22 23 so = CALLOC_STRUCT(fd2_zsa_stateobj); 24 if (!so) 25 return NULL; 26 27 so->base = *cso; 28 29 so->rb_depthcontrol |= 30 A2XX_RB_DEPTHCONTROL_ZFUNC(cso->depth_func); /* maps 1:1 */ 31 32 if (cso->depth_enabled) 33 so->rb_depthcontrol |= 34 A2XX_RB_DEPTHCONTROL_Z_ENABLE | 35 COND(!cso->alpha_enabled, A2XX_RB_DEPTHCONTROL_EARLY_Z_ENABLE); 36 if (cso->depth_writemask) 37 so->rb_depthcontrol |= A2XX_RB_DEPTHCONTROL_Z_WRITE_ENABLE; 38 39 if (cso->stencil[0].enabled) { 40 const struct pipe_stencil_state *s = &cso->stencil[0]; 41 42 so->rb_depthcontrol |= 43 A2XX_RB_DEPTHCONTROL_STENCIL_ENABLE | 44 A2XX_RB_DEPTHCONTROL_STENCILFUNC(s->func) | /* maps 1:1 */ 45 A2XX_RB_DEPTHCONTROL_STENCILFAIL(fd_stencil_op(s->fail_op)) | 46 A2XX_RB_DEPTHCONTROL_STENCILZPASS(fd_stencil_op(s->zpass_op)) | 47 A2XX_RB_DEPTHCONTROL_STENCILZFAIL(fd_stencil_op(s->zfail_op)); 48 so->rb_stencilrefmask |= 49 0xff000000 | /* ??? */ 50 A2XX_RB_STENCILREFMASK_STENCILWRITEMASK(s->writemask) | 51 A2XX_RB_STENCILREFMASK_STENCILMASK(s->valuemask); 52 53 if (cso->stencil[1].enabled) { 54 const struct pipe_stencil_state *bs = &cso->stencil[1]; 55 56 so->rb_depthcontrol |= 57 A2XX_RB_DEPTHCONTROL_BACKFACE_ENABLE | 58 A2XX_RB_DEPTHCONTROL_STENCILFUNC_BF(bs->func) | /* maps 1:1 */ 59 A2XX_RB_DEPTHCONTROL_STENCILFAIL_BF(fd_stencil_op(bs->fail_op)) | 60 A2XX_RB_DEPTHCONTROL_STENCILZPASS_BF(fd_stencil_op(bs->zpass_op)) | 61 A2XX_RB_DEPTHCONTROL_STENCILZFAIL_BF(fd_stencil_op(bs->zfail_op)); 62 so->rb_stencilrefmask_bf |= 63 0xff000000 | /* ??? */ 64 A2XX_RB_STENCILREFMASK_STENCILWRITEMASK(bs->writemask) | 65 A2XX_RB_STENCILREFMASK_STENCILMASK(bs->valuemask); 66 } 67 } 68 69 if (cso->alpha_enabled) { 70 so->rb_colorcontrol = A2XX_RB_COLORCONTROL_ALPHA_FUNC(cso->alpha_func) | 71 A2XX_RB_COLORCONTROL_ALPHA_TEST_ENABLE; 72 so->rb_alpha_ref = fui(cso->alpha_ref_value); 73 } 74 75 return so; 76 } 77