gallivm: work around slow code generated for interleaving 128bit vectors
[mesa.git] / src / gallium / drivers / freedreno / freedreno_rasterizer.c
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2
3 /*
4 * Copyright (C) 2012 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 "freedreno_rasterizer.h"
35 #include "freedreno_context.h"
36 #include "freedreno_util.h"
37
38
39 static enum adreno_pa_su_sc_draw
40 polygon_mode(unsigned mode)
41 {
42 switch (mode) {
43 case PIPE_POLYGON_MODE_POINT:
44 return PC_DRAW_POINTS;
45 case PIPE_POLYGON_MODE_LINE:
46 return PC_DRAW_LINES;
47 case PIPE_POLYGON_MODE_FILL:
48 return PC_DRAW_TRIANGLES;
49 default:
50 DBG("invalid polygon mode: %u", mode);
51 return 0;
52 }
53 }
54
55 static void *
56 fd_rasterizer_state_create(struct pipe_context *pctx,
57 const struct pipe_rasterizer_state *cso)
58 {
59 struct fd_rasterizer_stateobj *so;
60 float psize_min, psize_max;
61
62 so = CALLOC_STRUCT(fd_rasterizer_stateobj);
63 if (!so)
64 return NULL;
65
66 if (cso->point_size_per_vertex) {
67 psize_min = util_get_min_point_size(cso);
68 psize_max = 8192;
69 } else {
70 /* Force the point size to be as if the vertex output was disabled. */
71 psize_min = cso->point_size;
72 psize_max = cso->point_size;
73 }
74
75 so->base = *cso;
76
77 so->pa_sc_line_stipple = cso->line_stipple_enable ?
78 A2XX_PA_SC_LINE_STIPPLE_LINE_PATTERN(cso->line_stipple_pattern) |
79 A2XX_PA_SC_LINE_STIPPLE_REPEAT_COUNT(cso->line_stipple_factor) : 0;
80
81 so->pa_cl_clip_cntl = 0; // TODO
82
83 so->pa_su_vtx_cntl =
84 A2XX_PA_SU_VTX_CNTL_PIX_CENTER(cso->half_pixel_center ? PIXCENTER_OGL : PIXCENTER_D3D) |
85 A2XX_PA_SU_VTX_CNTL_QUANT_MODE(ONE_SIXTEENTH);
86
87 so->pa_su_point_size =
88 A2XX_PA_SU_POINT_SIZE_HEIGHT(cso->point_size/2) |
89 A2XX_PA_SU_POINT_SIZE_WIDTH(cso->point_size/2);
90
91 so->pa_su_point_minmax =
92 A2XX_PA_SU_POINT_MINMAX_MIN(psize_min/2) |
93 A2XX_PA_SU_POINT_MINMAX_MAX(psize_max/2);
94
95 so->pa_su_line_cntl =
96 A2XX_PA_SU_LINE_CNTL_WIDTH(cso->line_width/2);
97
98 so->pa_su_sc_mode_cntl =
99 A2XX_PA_SU_SC_MODE_CNTL_VTX_WINDOW_OFFSET_ENABLE |
100 A2XX_PA_SU_SC_MODE_CNTL_FRONT_PTYPE(polygon_mode(cso->fill_front)) |
101 A2XX_PA_SU_SC_MODE_CNTL_BACK_PTYPE(polygon_mode(cso->fill_back));
102
103 if (cso->cull_face & PIPE_FACE_FRONT)
104 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_CULL_FRONT;
105 if (cso->cull_face & PIPE_FACE_BACK)
106 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_CULL_BACK;
107 if (!cso->flatshade_first)
108 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_PROVOKING_VTX_LAST;
109 if (!cso->front_ccw)
110 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_FACE;
111 if (cso->line_stipple_enable)
112 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_LINE_STIPPLE_ENABLE;
113 if (cso->multisample)
114 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_MSAA_ENABLE;
115
116 if (cso->fill_front != PIPE_POLYGON_MODE_FILL ||
117 cso->fill_back != PIPE_POLYGON_MODE_FILL)
118 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_POLYMODE(POLY_DUALMODE);
119 else
120 so->pa_su_sc_mode_cntl |= A2XX_PA_SU_SC_MODE_CNTL_POLYMODE(POLY_DISABLED);
121
122 if (cso->offset_tri)
123 so->pa_su_sc_mode_cntl |=
124 A2XX_PA_SU_SC_MODE_CNTL_POLY_OFFSET_FRONT_ENABLE |
125 A2XX_PA_SU_SC_MODE_CNTL_POLY_OFFSET_BACK_ENABLE |
126 A2XX_PA_SU_SC_MODE_CNTL_POLY_OFFSET_PARA_ENABLE;
127
128 return so;
129 }
130
131 static void
132 fd_rasterizer_state_bind(struct pipe_context *pctx, void *hwcso)
133 {
134 struct fd_context *ctx = fd_context(pctx);
135 ctx->rasterizer = hwcso;
136 ctx->dirty |= FD_DIRTY_RASTERIZER;
137 }
138
139 static void
140 fd_rasterizer_state_delete(struct pipe_context *pctx, void *hwcso)
141 {
142 FREE(hwcso);
143 }
144
145 void
146 fd_rasterizer_init(struct pipe_context *pctx)
147 {
148 pctx->create_rasterizer_state = fd_rasterizer_state_create;
149 pctx->bind_rasterizer_state = fd_rasterizer_state_bind;
150 pctx->delete_rasterizer_state = fd_rasterizer_state_delete;
151 }