1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
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:
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
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
26 * Rob Clark <robclark@freedesktop.org>
30 #include "pipe/p_state.h"
31 #include "util/u_string.h"
32 #include "util/u_memory.h"
34 #include "freedreno_rasterizer.h"
35 #include "freedreno_context.h"
36 #include "freedreno_util.h"
39 static enum adreno_pa_su_sc_draw
40 polygon_mode(unsigned mode
)
43 case PIPE_POLYGON_MODE_POINT
:
44 return PC_DRAW_POINTS
;
45 case PIPE_POLYGON_MODE_LINE
:
47 case PIPE_POLYGON_MODE_FILL
:
48 return PC_DRAW_TRIANGLES
;
50 DBG("invalid polygon mode: %u", mode
);
56 fd_rasterizer_state_create(struct pipe_context
*pctx
,
57 const struct pipe_rasterizer_state
*cso
)
59 struct fd_rasterizer_stateobj
*so
;
60 float psize_min
, psize_max
;
62 so
= CALLOC_STRUCT(fd_rasterizer_stateobj
);
66 if (cso
->point_size_per_vertex
) {
67 psize_min
= util_get_min_point_size(cso
);
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
;
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;
81 so
->pa_cl_clip_cntl
= 0; // TODO
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
);
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);
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);
96 A2XX_PA_SU_LINE_CNTL_WIDTH(cso
->line_width
/2);
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
));
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
;
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
;
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
);
120 so
->pa_su_sc_mode_cntl
|= A2XX_PA_SU_SC_MODE_CNTL_POLYMODE(POLY_DISABLED
);
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
;
132 fd_rasterizer_state_bind(struct pipe_context
*pctx
, void *hwcso
)
134 struct fd_context
*ctx
= fd_context(pctx
);
135 ctx
->rasterizer
= hwcso
;
136 ctx
->dirty
|= FD_DIRTY_RASTERIZER
;
140 fd_rasterizer_state_delete(struct pipe_context
*pctx
, void *hwcso
)
146 fd_rasterizer_init(struct pipe_context
*pctx
)
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
;