xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/freedreno/a5xx/fd5_rasterizer.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2016 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 "fd5_context.h"
14 #include "fd5_format.h"
15 #include "fd5_rasterizer.h"
16 
17 void *
fd5_rasterizer_state_create(struct pipe_context * pctx,const struct pipe_rasterizer_state * cso)18 fd5_rasterizer_state_create(struct pipe_context *pctx,
19                             const struct pipe_rasterizer_state *cso)
20 {
21    struct fd5_rasterizer_stateobj *so;
22    float psize_min, psize_max;
23 
24    so = CALLOC_STRUCT(fd5_rasterizer_stateobj);
25    if (!so)
26       return NULL;
27 
28    so->base = *cso;
29 
30    if (cso->point_size_per_vertex) {
31       psize_min = util_get_min_point_size(cso);
32       psize_max = 4092;
33    } else {
34       /* Force the point size to be as if the vertex output was disabled. */
35       psize_min = cso->point_size;
36       psize_max = cso->point_size;
37    }
38 
39    so->gras_su_point_minmax = A5XX_GRAS_SU_POINT_MINMAX_MIN(psize_min) |
40                               A5XX_GRAS_SU_POINT_MINMAX_MAX(psize_max);
41    so->gras_su_point_size = A5XX_GRAS_SU_POINT_SIZE(cso->point_size);
42    so->gras_su_poly_offset_scale =
43       A5XX_GRAS_SU_POLY_OFFSET_SCALE(cso->offset_scale);
44    so->gras_su_poly_offset_offset =
45       A5XX_GRAS_SU_POLY_OFFSET_OFFSET(cso->offset_units);
46    so->gras_su_poly_offset_clamp =
47       A5XX_GRAS_SU_POLY_OFFSET_OFFSET_CLAMP(cso->offset_clamp);
48 
49    so->gras_su_cntl = A5XX_GRAS_SU_CNTL_LINEHALFWIDTH(cso->line_width / 2.0f);
50    so->pc_raster_cntl =
51       A5XX_PC_RASTER_CNTL_POLYMODE_FRONT_PTYPE(
52          fd_polygon_mode(cso->fill_front)) |
53       A5XX_PC_RASTER_CNTL_POLYMODE_BACK_PTYPE(fd_polygon_mode(cso->fill_back));
54 
55    if (cso->fill_front != PIPE_POLYGON_MODE_FILL ||
56        cso->fill_back != PIPE_POLYGON_MODE_FILL)
57       so->pc_raster_cntl |= A5XX_PC_RASTER_CNTL_POLYMODE_ENABLE;
58 
59    if (cso->cull_face & PIPE_FACE_FRONT)
60       so->gras_su_cntl |= A5XX_GRAS_SU_CNTL_CULL_FRONT;
61    if (cso->cull_face & PIPE_FACE_BACK)
62       so->gras_su_cntl |= A5XX_GRAS_SU_CNTL_CULL_BACK;
63    if (!cso->front_ccw)
64       so->gras_su_cntl |= A5XX_GRAS_SU_CNTL_FRONT_CW;
65    if (cso->offset_tri)
66       so->gras_su_cntl |= A5XX_GRAS_SU_CNTL_POLY_OFFSET;
67 
68    if (!cso->flatshade_first)
69       so->pc_primitive_cntl |= A5XX_PC_PRIMITIVE_CNTL_PROVOKING_VTX_LAST;
70 
71 //   if (!cso->depth_clip)
72 //      so->gras_cl_clip_cntl |=
73 //            A5XX_GRAS_CL_CLIP_CNTL_ZNEAR_CLIP_DISABLE |
74 //            A5XX_GRAS_CL_CLIP_CNTL_ZFAR_CLIP_DISABLE;
75    if (cso->clip_halfz)
76       so->gras_cl_clip_cntl |= A5XX_GRAS_CL_CNTL_ZERO_GB_SCALE_Z;
77 
78    return so;
79 }
80