1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (C) 2012-2013 Rob Clark <robclark@freedesktop.org>
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci * Authors:
24bf215546Sopenharmony_ci *    Rob Clark <robclark@freedesktop.org>
25bf215546Sopenharmony_ci */
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include "pipe/p_state.h"
28bf215546Sopenharmony_ci#include "util/u_memory.h"
29bf215546Sopenharmony_ci#include "util/u_string.h"
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include "fd2_context.h"
32bf215546Sopenharmony_ci#include "fd2_rasterizer.h"
33bf215546Sopenharmony_ci#include "fd2_util.h"
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_civoid *
36bf215546Sopenharmony_cifd2_rasterizer_state_create(struct pipe_context *pctx,
37bf215546Sopenharmony_ci                            const struct pipe_rasterizer_state *cso)
38bf215546Sopenharmony_ci{
39bf215546Sopenharmony_ci   struct fd2_rasterizer_stateobj *so;
40bf215546Sopenharmony_ci   float psize_min, psize_max;
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci   so = CALLOC_STRUCT(fd2_rasterizer_stateobj);
43bf215546Sopenharmony_ci   if (!so)
44bf215546Sopenharmony_ci      return NULL;
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci   if (cso->point_size_per_vertex) {
47bf215546Sopenharmony_ci      psize_min = util_get_min_point_size(cso);
48bf215546Sopenharmony_ci      psize_max = 8192.0f - 0.0625f;
49bf215546Sopenharmony_ci   } else {
50bf215546Sopenharmony_ci      /* Force the point size to be as if the vertex output was disabled. */
51bf215546Sopenharmony_ci      psize_min = cso->point_size;
52bf215546Sopenharmony_ci      psize_max = cso->point_size;
53bf215546Sopenharmony_ci   }
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci   so->base = *cso;
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci   so->pa_sc_line_stipple =
58bf215546Sopenharmony_ci      cso->line_stipple_enable
59bf215546Sopenharmony_ci         ? A2XX_PA_SC_LINE_STIPPLE_LINE_PATTERN(cso->line_stipple_pattern) |
60bf215546Sopenharmony_ci              A2XX_PA_SC_LINE_STIPPLE_REPEAT_COUNT(cso->line_stipple_factor)
61bf215546Sopenharmony_ci         : 0;
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci   so->pa_cl_clip_cntl = 0; // TODO
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci   so->pa_su_vtx_cntl =
66bf215546Sopenharmony_ci      A2XX_PA_SU_VTX_CNTL_PIX_CENTER(cso->half_pixel_center ? PIXCENTER_OGL
67bf215546Sopenharmony_ci                                                            : PIXCENTER_D3D) |
68bf215546Sopenharmony_ci      A2XX_PA_SU_VTX_CNTL_QUANT_MODE(ONE_SIXTEENTH);
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci   so->pa_su_point_size = A2XX_PA_SU_POINT_SIZE_HEIGHT(cso->point_size / 2) |
71bf215546Sopenharmony_ci                          A2XX_PA_SU_POINT_SIZE_WIDTH(cso->point_size / 2);
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci   so->pa_su_point_minmax = A2XX_PA_SU_POINT_MINMAX_MIN(psize_min / 2) |
74bf215546Sopenharmony_ci                            A2XX_PA_SU_POINT_MINMAX_MAX(psize_max / 2);
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci   so->pa_su_line_cntl = A2XX_PA_SU_LINE_CNTL_WIDTH(cso->line_width / 2);
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci   so->pa_su_sc_mode_cntl =
79bf215546Sopenharmony_ci      A2XX_PA_SU_SC_MODE_CNTL_VTX_WINDOW_OFFSET_ENABLE |
80bf215546Sopenharmony_ci      A2XX_PA_SU_SC_MODE_CNTL_FRONT_PTYPE(fd_polygon_mode(cso->fill_front)) |
81bf215546Sopenharmony_ci      A2XX_PA_SU_SC_MODE_CNTL_BACK_PTYPE(fd_polygon_mode(cso->fill_back));
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci   if (cso->cull_face & PIPE_FACE_FRONT)
84bf215546Sopenharmony_ci      so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_CULL_FRONT;
85bf215546Sopenharmony_ci   if (cso->cull_face & PIPE_FACE_BACK)
86bf215546Sopenharmony_ci      so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_CULL_BACK;
87bf215546Sopenharmony_ci   if (!cso->flatshade_first)
88bf215546Sopenharmony_ci      so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_PROVOKING_VTX_LAST;
89bf215546Sopenharmony_ci   if (!cso->front_ccw)
90bf215546Sopenharmony_ci      so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_FACE;
91bf215546Sopenharmony_ci   if (cso->line_stipple_enable)
92bf215546Sopenharmony_ci      so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_LINE_STIPPLE_ENABLE;
93bf215546Sopenharmony_ci   if (cso->multisample)
94bf215546Sopenharmony_ci      so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_MSAA_ENABLE;
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci   if (cso->fill_front != PIPE_POLYGON_MODE_FILL ||
97bf215546Sopenharmony_ci       cso->fill_back != PIPE_POLYGON_MODE_FILL)
98bf215546Sopenharmony_ci      so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_POLYMODE(POLY_DUALMODE);
99bf215546Sopenharmony_ci   else
100bf215546Sopenharmony_ci      so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_POLYMODE(POLY_DISABLED);
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_ci   if (cso->offset_tri)
103bf215546Sopenharmony_ci      so->pa_su_sc_mode_cntl |=
104bf215546Sopenharmony_ci         A2XX_PA_SU_SC_MODE_CNTL_POLY_OFFSET_FRONT_ENABLE |
105bf215546Sopenharmony_ci         A2XX_PA_SU_SC_MODE_CNTL_POLY_OFFSET_BACK_ENABLE |
106bf215546Sopenharmony_ci         A2XX_PA_SU_SC_MODE_CNTL_POLY_OFFSET_PARA_ENABLE;
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_ci   return so;
109bf215546Sopenharmony_ci}
110