1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2
3 /*
4 * Copyright (C) 2012-2013 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 "fd2_rasterizer.h"
35 #include "fd2_context.h"
36 #include "fd2_util.h"
37
38
39 void *
fd2_rasterizer_state_create(struct pipe_context * pctx,const struct pipe_rasterizer_state * cso)40 fd2_rasterizer_state_create(struct pipe_context *pctx,
41 const struct pipe_rasterizer_state *cso)
42 {
43 struct fd2_rasterizer_stateobj *so;
44 float psize_min, psize_max;
45
46 so = CALLOC_STRUCT(fd2_rasterizer_stateobj);
47 if (!so)
48 return NULL;
49
50 if (cso->point_size_per_vertex) {
51 psize_min = util_get_min_point_size(cso);
52 psize_max = 8192;
53 } else {
54 /* Force the point size to be as if the vertex output was disabled. */
55 psize_min = cso->point_size;
56 psize_max = cso->point_size;
57 }
58
59 so->base = *cso;
60
61 so->pa_sc_line_stipple = cso->line_stipple_enable ?
62 A2XX_PA_SC_LINE_STIPPLE_LINE_PATTERN(cso->line_stipple_pattern) |
63 A2XX_PA_SC_LINE_STIPPLE_REPEAT_COUNT(cso->line_stipple_factor) : 0;
64
65 so->pa_cl_clip_cntl = 0; // TODO
66
67 so->pa_su_vtx_cntl =
68 A2XX_PA_SU_VTX_CNTL_PIX_CENTER(cso->half_pixel_center ? PIXCENTER_OGL : PIXCENTER_D3D) |
69 A2XX_PA_SU_VTX_CNTL_QUANT_MODE(ONE_SIXTEENTH);
70
71 so->pa_su_point_size =
72 A2XX_PA_SU_POINT_SIZE_HEIGHT(cso->point_size/2) |
73 A2XX_PA_SU_POINT_SIZE_WIDTH(cso->point_size/2);
74
75 so->pa_su_point_minmax =
76 A2XX_PA_SU_POINT_MINMAX_MIN(psize_min/2) |
77 A2XX_PA_SU_POINT_MINMAX_MAX(psize_max/2);
78
79 so->pa_su_line_cntl =
80 A2XX_PA_SU_LINE_CNTL_WIDTH(cso->line_width/2);
81
82 so->pa_su_sc_mode_cntl =
83 A2XX_PA_SU_SC_MODE_CNTL_VTX_WINDOW_OFFSET_ENABLE |
84 A2XX_PA_SU_SC_MODE_CNTL_FRONT_PTYPE(fd_polygon_mode(cso->fill_front)) |
85 A2XX_PA_SU_SC_MODE_CNTL_BACK_PTYPE(fd_polygon_mode(cso->fill_back));
86
87 if (cso->cull_face & PIPE_FACE_FRONT)
88 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_CULL_FRONT;
89 if (cso->cull_face & PIPE_FACE_BACK)
90 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_CULL_BACK;
91 if (!cso->flatshade_first)
92 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_PROVOKING_VTX_LAST;
93 if (!cso->front_ccw)
94 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_FACE;
95 if (cso->line_stipple_enable)
96 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_LINE_STIPPLE_ENABLE;
97 if (cso->multisample)
98 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_MSAA_ENABLE;
99
100 if (cso->fill_front != PIPE_POLYGON_MODE_FILL ||
101 cso->fill_back != PIPE_POLYGON_MODE_FILL)
102 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_POLYMODE(POLY_DUALMODE);
103 else
104 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_POLYMODE(POLY_DISABLED);
105
106 if (cso->offset_tri)
107 so->pa_su_sc_mode_cntl |=
108 A2XX_PA_SU_SC_MODE_CNTL_POLY_OFFSET_FRONT_ENABLE |
109 A2XX_PA_SU_SC_MODE_CNTL_POLY_OFFSET_BACK_ENABLE |
110 A2XX_PA_SU_SC_MODE_CNTL_POLY_OFFSET_PARA_ENABLE;
111
112 return so;
113 }
114