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