Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a6xx/fd6_rasterizer.c
4574 views
/*1* Copyright (C) 2016 Rob Clark <[email protected]>2* Copyright © 2018 Google, Inc.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* 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 THE21* SOFTWARE.22*23* Authors:24* Rob Clark <[email protected]>25*/2627#include "pipe/p_state.h"28#include "util/u_memory.h"29#include "util/u_string.h"3031#include "fd6_context.h"32#include "fd6_format.h"33#include "fd6_pack.h"34#include "fd6_rasterizer.h"3536struct fd_ringbuffer *37__fd6_setup_rasterizer_stateobj(struct fd_context *ctx,38const struct pipe_rasterizer_state *cso,39bool primitive_restart)40{41struct fd_ringbuffer *ring = fd_ringbuffer_new_object(ctx->pipe, 18 * 4);42float psize_min, psize_max;4344if (cso->point_size_per_vertex) {45psize_min = util_get_min_point_size(cso);46psize_max = 4092;47} else {48/* Force the point size to be as if the vertex output was disabled. */49psize_min = cso->point_size;50psize_max = cso->point_size;51}5253OUT_REG(ring, A6XX_GRAS_CL_CNTL(.znear_clip_disable = !cso->depth_clip_near,54.zfar_clip_disable = !cso->depth_clip_far,55.unk5 = !cso->depth_clip_near ||56!cso->depth_clip_far,57.vp_clip_code_ignore = 1,58.zero_gb_scale_z = cso->clip_halfz));5960OUT_REG(ring,61A6XX_GRAS_SU_CNTL(.linehalfwidth = cso->line_width / 2.0,62.poly_offset = cso->offset_tri,63.msaa_enable = cso->multisample,64.cull_front = cso->cull_face & PIPE_FACE_FRONT,65.cull_back = cso->cull_face & PIPE_FACE_BACK,66.front_cw = !cso->front_ccw, ));6768OUT_REG(ring,69A6XX_GRAS_SU_POINT_MINMAX(.min = psize_min, .max = psize_max, ),70A6XX_GRAS_SU_POINT_SIZE(cso->point_size));7172OUT_REG(ring, A6XX_GRAS_SU_POLY_OFFSET_SCALE(cso->offset_scale),73A6XX_GRAS_SU_POLY_OFFSET_OFFSET(cso->offset_units),74A6XX_GRAS_SU_POLY_OFFSET_OFFSET_CLAMP(cso->offset_clamp));7576OUT_REG(ring,77A6XX_PC_PRIMITIVE_CNTL_0(.provoking_vtx_last = !cso->flatshade_first,78.primitive_restart = primitive_restart, ));7980enum a6xx_polygon_mode mode = POLYMODE6_TRIANGLES;81switch (cso->fill_front) {82case PIPE_POLYGON_MODE_POINT:83mode = POLYMODE6_POINTS;84break;85case PIPE_POLYGON_MODE_LINE:86mode = POLYMODE6_LINES;87break;88default:89assert(cso->fill_front == PIPE_POLYGON_MODE_FILL);90break;91}9293OUT_REG(ring, A6XX_VPC_POLYGON_MODE(mode));94OUT_REG(ring, A6XX_PC_POLYGON_MODE(mode));9596return ring;97}9899void *100fd6_rasterizer_state_create(struct pipe_context *pctx,101const struct pipe_rasterizer_state *cso)102{103struct fd6_rasterizer_stateobj *so;104105so = CALLOC_STRUCT(fd6_rasterizer_stateobj);106if (!so)107return NULL;108109so->base = *cso;110111return so;112}113114void115fd6_rasterizer_state_delete(struct pipe_context *pctx, void *hwcso)116{117struct fd6_rasterizer_stateobj *so = hwcso;118119for (unsigned i = 0; i < ARRAY_SIZE(so->stateobjs); i++)120if (so->stateobjs[i])121fd_ringbuffer_del(so->stateobjs[i]);122123FREE(hwcso);124}125126127