1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (C) 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 "fd3_context.h"
32bf215546Sopenharmony_ci#include "fd3_format.h"
33bf215546Sopenharmony_ci#include "fd3_rasterizer.h"
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_civoid *
36bf215546Sopenharmony_cifd3_rasterizer_state_create(struct pipe_context *pctx,
37bf215546Sopenharmony_ci                            const struct pipe_rasterizer_state *cso)
38bf215546Sopenharmony_ci{
39bf215546Sopenharmony_ci   struct fd3_rasterizer_stateobj *so;
40bf215546Sopenharmony_ci   float psize_min, psize_max;
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci   so = CALLOC_STRUCT(fd3_rasterizer_stateobj);
43bf215546Sopenharmony_ci   if (!so)
44bf215546Sopenharmony_ci      return NULL;
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci   so->base = *cso;
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci   if (cso->point_size_per_vertex) {
49bf215546Sopenharmony_ci      psize_min = util_get_min_point_size(cso);
50bf215546Sopenharmony_ci      psize_max = 4092;
51bf215546Sopenharmony_ci   } else {
52bf215546Sopenharmony_ci      /* Force the point size to be as if the vertex output was disabled. */
53bf215546Sopenharmony_ci      psize_min = cso->point_size;
54bf215546Sopenharmony_ci      psize_max = cso->point_size;
55bf215546Sopenharmony_ci   }
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci   /*
58bf215546Sopenharmony_ci           if (cso->line_stipple_enable) {
59bf215546Sopenharmony_ci                   ??? TODO line stipple
60bf215546Sopenharmony_ci           }
61bf215546Sopenharmony_ci           TODO cso->half_pixel_center
62bf215546Sopenharmony_ci           if (cso->multisample)
63bf215546Sopenharmony_ci                   TODO
64bf215546Sopenharmony_ci   */
65bf215546Sopenharmony_ci   so->gras_cl_clip_cntl =
66bf215546Sopenharmony_ci      COND(cso->clip_halfz, A3XX_GRAS_CL_CLIP_CNTL_ZERO_GB_SCALE_Z);
67bf215546Sopenharmony_ci   so->gras_su_point_minmax = A3XX_GRAS_SU_POINT_MINMAX_MIN(psize_min) |
68bf215546Sopenharmony_ci                              A3XX_GRAS_SU_POINT_MINMAX_MAX(psize_max);
69bf215546Sopenharmony_ci   so->gras_su_point_size = A3XX_GRAS_SU_POINT_SIZE(cso->point_size);
70bf215546Sopenharmony_ci   so->gras_su_poly_offset_scale =
71bf215546Sopenharmony_ci      A3XX_GRAS_SU_POLY_OFFSET_SCALE_VAL(cso->offset_scale);
72bf215546Sopenharmony_ci   so->gras_su_poly_offset_offset =
73bf215546Sopenharmony_ci      A3XX_GRAS_SU_POLY_OFFSET_OFFSET(cso->offset_units * 2.0f);
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   so->gras_su_mode_control =
76bf215546Sopenharmony_ci      A3XX_GRAS_SU_MODE_CONTROL_LINEHALFWIDTH(cso->line_width / 2.0f);
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci   so->pc_prim_vtx_cntl = A3XX_PC_PRIM_VTX_CNTL_POLYMODE_FRONT_PTYPE(
79bf215546Sopenharmony_ci                             fd_polygon_mode(cso->fill_front)) |
80bf215546Sopenharmony_ci                          A3XX_PC_PRIM_VTX_CNTL_POLYMODE_BACK_PTYPE(
81bf215546Sopenharmony_ci                             fd_polygon_mode(cso->fill_back));
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci   if (cso->fill_front != PIPE_POLYGON_MODE_FILL ||
84bf215546Sopenharmony_ci       cso->fill_back != PIPE_POLYGON_MODE_FILL)
85bf215546Sopenharmony_ci      so->pc_prim_vtx_cntl |= A3XX_PC_PRIM_VTX_CNTL_POLYMODE_ENABLE;
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci   if (cso->cull_face & PIPE_FACE_FRONT)
88bf215546Sopenharmony_ci      so->gras_su_mode_control |= A3XX_GRAS_SU_MODE_CONTROL_CULL_FRONT;
89bf215546Sopenharmony_ci   if (cso->cull_face & PIPE_FACE_BACK)
90bf215546Sopenharmony_ci      so->gras_su_mode_control |= A3XX_GRAS_SU_MODE_CONTROL_CULL_BACK;
91bf215546Sopenharmony_ci   if (!cso->front_ccw)
92bf215546Sopenharmony_ci      so->gras_su_mode_control |= A3XX_GRAS_SU_MODE_CONTROL_FRONT_CW;
93bf215546Sopenharmony_ci   if (!cso->flatshade_first)
94bf215546Sopenharmony_ci      so->pc_prim_vtx_cntl |= A3XX_PC_PRIM_VTX_CNTL_PROVOKING_VTX_LAST;
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci   if (cso->offset_tri)
97bf215546Sopenharmony_ci      so->gras_su_mode_control |= A3XX_GRAS_SU_MODE_CONTROL_POLY_OFFSET;
98bf215546Sopenharmony_ci   if (!cso->depth_clip_near)
99bf215546Sopenharmony_ci      so->gras_cl_clip_cntl |= A3XX_GRAS_CL_CLIP_CNTL_CLIP_DISABLE;
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci   return so;
102bf215546Sopenharmony_ci}
103