1 /*
2 * Copyright (C) 2014 Rob Clark <robclark@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@freedesktop.org>
25 */
26
27 #include "pipe/p_state.h"
28 #include "util/u_memory.h"
29 #include "util/u_string.h"
30
31 #include "fd4_context.h"
32 #include "fd4_format.h"
33 #include "fd4_rasterizer.h"
34
35 void *
fd4_rasterizer_state_create(struct pipe_context * pctx,const struct pipe_rasterizer_state * cso)36 fd4_rasterizer_state_create(struct pipe_context *pctx,
37 const struct pipe_rasterizer_state *cso)
38 {
39 struct fd4_rasterizer_stateobj *so;
40 float psize_min, psize_max;
41
42 so = CALLOC_STRUCT(fd4_rasterizer_stateobj);
43 if (!so)
44 return NULL;
45
46 so->base = *cso;
47
48 if (cso->point_size_per_vertex) {
49 psize_min = util_get_min_point_size(cso);
50 psize_max = 4092;
51 } else {
52 /* Force the point size to be as if the vertex output was disabled. */
53 psize_min = cso->point_size;
54 psize_max = cso->point_size;
55 }
56
57 /*
58 if (cso->line_stipple_enable) {
59 ??? TODO line stipple
60 }
61 TODO cso->half_pixel_center
62 if (cso->multisample)
63 TODO
64 */
65 so->gras_cl_clip_cntl = 0x80000; /* ??? */
66 so->gras_su_point_minmax = A4XX_GRAS_SU_POINT_MINMAX_MIN(psize_min) |
67 A4XX_GRAS_SU_POINT_MINMAX_MAX(psize_max);
68 so->gras_su_point_size = A4XX_GRAS_SU_POINT_SIZE(cso->point_size);
69 so->gras_su_poly_offset_scale =
70 A4XX_GRAS_SU_POLY_OFFSET_SCALE(cso->offset_scale);
71 so->gras_su_poly_offset_offset =
72 A4XX_GRAS_SU_POLY_OFFSET_OFFSET(cso->offset_units * 2.0f);
73 so->gras_su_poly_offset_clamp =
74 A4XX_GRAS_SU_POLY_OFFSET_CLAMP(cso->offset_clamp);
75
76 so->gras_su_mode_control =
77 A4XX_GRAS_SU_MODE_CONTROL_LINEHALFWIDTH(cso->line_width / 2.0);
78 so->pc_prim_vtx_cntl2 = A4XX_PC_PRIM_VTX_CNTL2_POLYMODE_FRONT_PTYPE(
79 fd_polygon_mode(cso->fill_front)) |
80 A4XX_PC_PRIM_VTX_CNTL2_POLYMODE_BACK_PTYPE(
81 fd_polygon_mode(cso->fill_back));
82
83 if (cso->fill_front != PIPE_POLYGON_MODE_FILL ||
84 cso->fill_back != PIPE_POLYGON_MODE_FILL)
85 so->pc_prim_vtx_cntl2 |= A4XX_PC_PRIM_VTX_CNTL2_POLYMODE_ENABLE;
86
87 if (cso->cull_face & PIPE_FACE_FRONT)
88 so->gras_su_mode_control |= A4XX_GRAS_SU_MODE_CONTROL_CULL_FRONT;
89 if (cso->cull_face & PIPE_FACE_BACK)
90 so->gras_su_mode_control |= A4XX_GRAS_SU_MODE_CONTROL_CULL_BACK;
91 if (!cso->front_ccw)
92 so->gras_su_mode_control |= A4XX_GRAS_SU_MODE_CONTROL_FRONT_CW;
93 if (!cso->flatshade_first)
94 so->pc_prim_vtx_cntl |= A4XX_PC_PRIM_VTX_CNTL_PROVOKING_VTX_LAST;
95
96 if (cso->offset_tri)
97 so->gras_su_mode_control |= A4XX_GRAS_SU_MODE_CONTROL_POLY_OFFSET;
98
99 if (!cso->depth_clip_near)
100 so->gras_cl_clip_cntl |= A4XX_GRAS_CL_CLIP_CNTL_ZNEAR_CLIP_DISABLE |
101 A4XX_GRAS_CL_CLIP_CNTL_ZFAR_CLIP_DISABLE;
102 if (cso->clip_halfz)
103 so->gras_cl_clip_cntl |= A4XX_GRAS_CL_CLIP_CNTL_ZERO_GB_SCALE_Z;
104
105 return so;
106 }
107