• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2 
3 /*
4  * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  *
25  * Authors:
26  *    Rob Clark <robclark@freedesktop.org>
27  */
28 
29 
30 #include "pipe/p_state.h"
31 #include "util/u_string.h"
32 #include "util/u_memory.h"
33 
34 #include "fd4_rasterizer.h"
35 #include "fd4_context.h"
36 #include "fd4_format.h"
37 
38 void *
fd4_rasterizer_state_create(struct pipe_context * pctx,const struct pipe_rasterizer_state * cso)39 fd4_rasterizer_state_create(struct pipe_context *pctx,
40 		const struct pipe_rasterizer_state *cso)
41 {
42 	struct fd4_rasterizer_stateobj *so;
43 	float psize_min, psize_max;
44 
45 	so = CALLOC_STRUCT(fd4_rasterizer_stateobj);
46 	if (!so)
47 		return NULL;
48 
49 	so->base = *cso;
50 
51 	if (cso->point_size_per_vertex) {
52 		psize_min = util_get_min_point_size(cso);
53 		psize_max = 4092;
54 	} else {
55 		/* Force the point size to be as if the vertex output was disabled. */
56 		psize_min = cso->point_size;
57 		psize_max = cso->point_size;
58 	}
59 
60 /*
61 	if (cso->line_stipple_enable) {
62 		??? TODO line stipple
63 	}
64 	TODO cso->half_pixel_center
65 	if (cso->multisample)
66 		TODO
67 */
68 	so->gras_cl_clip_cntl = 0x80000; /* ??? */
69 	so->gras_su_point_minmax =
70 			A4XX_GRAS_SU_POINT_MINMAX_MIN(psize_min) |
71 			A4XX_GRAS_SU_POINT_MINMAX_MAX(psize_max);
72 	so->gras_su_point_size   = A4XX_GRAS_SU_POINT_SIZE(cso->point_size);
73 	so->gras_su_poly_offset_scale =
74 			A4XX_GRAS_SU_POLY_OFFSET_SCALE(cso->offset_scale);
75 	so->gras_su_poly_offset_offset =
76 			A4XX_GRAS_SU_POLY_OFFSET_OFFSET(cso->offset_units);
77 
78 	so->gras_su_mode_control =
79 			A4XX_GRAS_SU_MODE_CONTROL_LINEHALFWIDTH(cso->line_width/2.0);
80 	so->pc_prim_vtx_cntl2 =
81 		A4XX_PC_PRIM_VTX_CNTL2_POLYMODE_FRONT_PTYPE(fd_polygon_mode(cso->fill_front)) |
82 		A4XX_PC_PRIM_VTX_CNTL2_POLYMODE_BACK_PTYPE(fd_polygon_mode(cso->fill_back));
83 
84 	if (cso->fill_front != PIPE_POLYGON_MODE_FILL ||
85 		cso->fill_back != PIPE_POLYGON_MODE_FILL)
86 		so->pc_prim_vtx_cntl2 |= A4XX_PC_PRIM_VTX_CNTL2_POLYMODE_ENABLE;
87 
88 	if (cso->cull_face & PIPE_FACE_FRONT)
89 		so->gras_su_mode_control |= A4XX_GRAS_SU_MODE_CONTROL_CULL_FRONT;
90 	if (cso->cull_face & PIPE_FACE_BACK)
91 		so->gras_su_mode_control |= A4XX_GRAS_SU_MODE_CONTROL_CULL_BACK;
92 	if (!cso->front_ccw)
93 		so->gras_su_mode_control |= A4XX_GRAS_SU_MODE_CONTROL_FRONT_CW;
94 	if (!cso->flatshade_first)
95 		so->pc_prim_vtx_cntl |= A4XX_PC_PRIM_VTX_CNTL_PROVOKING_VTX_LAST;
96 
97 	if (cso->offset_tri)
98 		so->gras_su_mode_control |= A4XX_GRAS_SU_MODE_CONTROL_POLY_OFFSET;
99 
100 	if (!cso->depth_clip)
101 		so->gras_cl_clip_cntl |= A4XX_GRAS_CL_CLIP_CNTL_ZNEAR_CLIP_DISABLE |
102 			A4XX_GRAS_CL_CLIP_CNTL_ZFAR_CLIP_DISABLE;
103 	if (cso->clip_halfz)
104 		so->gras_cl_clip_cntl |= A4XX_GRAS_CL_CLIP_CNTL_ZERO_GB_SCALE_Z;
105 
106 	return so;
107 }
108