1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org> 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors: 24bf215546Sopenharmony_ci * Rob Clark <robclark@freedesktop.org> 25bf215546Sopenharmony_ci */ 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "pipe/p_state.h" 28bf215546Sopenharmony_ci#include "util/u_memory.h" 29bf215546Sopenharmony_ci#include "util/u_string.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci#include "fd5_context.h" 32bf215546Sopenharmony_ci#include "fd5_format.h" 33bf215546Sopenharmony_ci#include "fd5_rasterizer.h" 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_civoid * 36bf215546Sopenharmony_cifd5_rasterizer_state_create(struct pipe_context *pctx, 37bf215546Sopenharmony_ci const struct pipe_rasterizer_state *cso) 38bf215546Sopenharmony_ci{ 39bf215546Sopenharmony_ci struct fd5_rasterizer_stateobj *so; 40bf215546Sopenharmony_ci float psize_min, psize_max; 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci so = CALLOC_STRUCT(fd5_rasterizer_stateobj); 43bf215546Sopenharmony_ci if (!so) 44bf215546Sopenharmony_ci return NULL; 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_ci so->base = *cso; 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci if (cso->point_size_per_vertex) { 49bf215546Sopenharmony_ci psize_min = util_get_min_point_size(cso); 50bf215546Sopenharmony_ci psize_max = 4092; 51bf215546Sopenharmony_ci } else { 52bf215546Sopenharmony_ci /* Force the point size to be as if the vertex output was disabled. */ 53bf215546Sopenharmony_ci psize_min = cso->point_size; 54bf215546Sopenharmony_ci psize_max = cso->point_size; 55bf215546Sopenharmony_ci } 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci so->gras_su_point_minmax = A5XX_GRAS_SU_POINT_MINMAX_MIN(psize_min) | 58bf215546Sopenharmony_ci A5XX_GRAS_SU_POINT_MINMAX_MAX(psize_max); 59bf215546Sopenharmony_ci so->gras_su_point_size = A5XX_GRAS_SU_POINT_SIZE(cso->point_size); 60bf215546Sopenharmony_ci so->gras_su_poly_offset_scale = 61bf215546Sopenharmony_ci A5XX_GRAS_SU_POLY_OFFSET_SCALE(cso->offset_scale); 62bf215546Sopenharmony_ci so->gras_su_poly_offset_offset = 63bf215546Sopenharmony_ci A5XX_GRAS_SU_POLY_OFFSET_OFFSET(cso->offset_units); 64bf215546Sopenharmony_ci so->gras_su_poly_offset_clamp = 65bf215546Sopenharmony_ci A5XX_GRAS_SU_POLY_OFFSET_OFFSET_CLAMP(cso->offset_clamp); 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci so->gras_su_cntl = A5XX_GRAS_SU_CNTL_LINEHALFWIDTH(cso->line_width / 2.0f); 68bf215546Sopenharmony_ci so->pc_raster_cntl = 69bf215546Sopenharmony_ci A5XX_PC_RASTER_CNTL_POLYMODE_FRONT_PTYPE( 70bf215546Sopenharmony_ci fd_polygon_mode(cso->fill_front)) | 71bf215546Sopenharmony_ci A5XX_PC_RASTER_CNTL_POLYMODE_BACK_PTYPE(fd_polygon_mode(cso->fill_back)); 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_ci if (cso->fill_front != PIPE_POLYGON_MODE_FILL || 74bf215546Sopenharmony_ci cso->fill_back != PIPE_POLYGON_MODE_FILL) 75bf215546Sopenharmony_ci so->pc_raster_cntl |= A5XX_PC_RASTER_CNTL_POLYMODE_ENABLE; 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci if (cso->cull_face & PIPE_FACE_FRONT) 78bf215546Sopenharmony_ci so->gras_su_cntl |= A5XX_GRAS_SU_CNTL_CULL_FRONT; 79bf215546Sopenharmony_ci if (cso->cull_face & PIPE_FACE_BACK) 80bf215546Sopenharmony_ci so->gras_su_cntl |= A5XX_GRAS_SU_CNTL_CULL_BACK; 81bf215546Sopenharmony_ci if (!cso->front_ccw) 82bf215546Sopenharmony_ci so->gras_su_cntl |= A5XX_GRAS_SU_CNTL_FRONT_CW; 83bf215546Sopenharmony_ci if (cso->offset_tri) 84bf215546Sopenharmony_ci so->gras_su_cntl |= A5XX_GRAS_SU_CNTL_POLY_OFFSET; 85bf215546Sopenharmony_ci 86bf215546Sopenharmony_ci if (!cso->flatshade_first) 87bf215546Sopenharmony_ci so->pc_primitive_cntl |= A5XX_PC_PRIMITIVE_CNTL_PROVOKING_VTX_LAST; 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_ci// if (!cso->depth_clip) 90bf215546Sopenharmony_ci// so->gras_cl_clip_cntl |= 91bf215546Sopenharmony_ci// A5XX_GRAS_CL_CLIP_CNTL_ZNEAR_CLIP_DISABLE | 92bf215546Sopenharmony_ci// A5XX_GRAS_CL_CLIP_CNTL_ZFAR_CLIP_DISABLE; 93bf215546Sopenharmony_ci if (cso->clip_halfz) 94bf215546Sopenharmony_ci so->gras_cl_clip_cntl |= A5XX_GRAS_CL_CNTL_ZERO_GB_SCALE_Z; 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci return so; 97bf215546Sopenharmony_ci} 98