1 /* 2 * Copyright © 2013 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 "fd3_context.h" 14 #include "fd3_format.h" 15 #include "fd3_rasterizer.h" 16 17 void * fd3_rasterizer_state_create(struct pipe_context * pctx,const struct pipe_rasterizer_state * cso)18fd3_rasterizer_state_create(struct pipe_context *pctx, 19 const struct pipe_rasterizer_state *cso) 20 { 21 struct fd3_rasterizer_stateobj *so; 22 float psize_min, psize_max; 23 24 so = CALLOC_STRUCT(fd3_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 /* 40 if (cso->line_stipple_enable) { 41 ??? TODO line stipple 42 } 43 TODO cso->half_pixel_center 44 if (cso->multisample) 45 TODO 46 */ 47 so->gras_cl_clip_cntl = 48 COND(cso->clip_halfz, A3XX_GRAS_CL_CLIP_CNTL_ZERO_GB_SCALE_Z); 49 so->gras_su_point_minmax = A3XX_GRAS_SU_POINT_MINMAX_MIN(psize_min) | 50 A3XX_GRAS_SU_POINT_MINMAX_MAX(psize_max); 51 so->gras_su_point_size = A3XX_GRAS_SU_POINT_SIZE(cso->point_size); 52 so->gras_su_poly_offset_scale = 53 A3XX_GRAS_SU_POLY_OFFSET_SCALE_VAL(cso->offset_scale); 54 so->gras_su_poly_offset_offset = 55 A3XX_GRAS_SU_POLY_OFFSET_OFFSET(cso->offset_units * 2.0f); 56 57 so->gras_su_mode_control = 58 A3XX_GRAS_SU_MODE_CONTROL_LINEHALFWIDTH(cso->line_width / 2.0f); 59 60 so->pc_prim_vtx_cntl = A3XX_PC_PRIM_VTX_CNTL_POLYMODE_FRONT_PTYPE( 61 fd_polygon_mode(cso->fill_front)) | 62 A3XX_PC_PRIM_VTX_CNTL_POLYMODE_BACK_PTYPE( 63 fd_polygon_mode(cso->fill_back)); 64 65 if (cso->fill_front != PIPE_POLYGON_MODE_FILL || 66 cso->fill_back != PIPE_POLYGON_MODE_FILL) 67 so->pc_prim_vtx_cntl |= A3XX_PC_PRIM_VTX_CNTL_POLYMODE_ENABLE; 68 69 if (cso->cull_face & PIPE_FACE_FRONT) 70 so->gras_su_mode_control |= A3XX_GRAS_SU_MODE_CONTROL_CULL_FRONT; 71 if (cso->cull_face & PIPE_FACE_BACK) 72 so->gras_su_mode_control |= A3XX_GRAS_SU_MODE_CONTROL_CULL_BACK; 73 if (!cso->front_ccw) 74 so->gras_su_mode_control |= A3XX_GRAS_SU_MODE_CONTROL_FRONT_CW; 75 if (!cso->flatshade_first) 76 so->pc_prim_vtx_cntl |= A3XX_PC_PRIM_VTX_CNTL_PROVOKING_VTX_LAST; 77 78 if (cso->offset_tri) 79 so->gras_su_mode_control |= A3XX_GRAS_SU_MODE_CONTROL_POLY_OFFSET; 80 if (!cso->depth_clip_near) 81 so->gras_cl_clip_cntl |= A3XX_GRAS_CL_CLIP_CNTL_CLIP_DISABLE; 82 83 return so; 84 } 85