1 /*
2 * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
3 * Copyright © 2018 Google, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 * Authors:
25 * Rob Clark <robclark@freedesktop.org>
26 */
27
28
29 #include "pipe/p_state.h"
30 #include "util/u_string.h"
31 #include "util/u_memory.h"
32
33 #include "fd6_rasterizer.h"
34 #include "fd6_context.h"
35 #include "fd6_format.h"
36 #include "fd6_pack.h"
37
38 struct fd_ringbuffer *
__fd6_setup_rasterizer_stateobj(struct fd_context * ctx,const struct pipe_rasterizer_state * cso,bool primitive_restart)39 __fd6_setup_rasterizer_stateobj(struct fd_context *ctx,
40 const struct pipe_rasterizer_state *cso, bool primitive_restart)
41 {
42 struct fd_ringbuffer *ring = fd_ringbuffer_new_object(ctx->pipe, 18 * 4);
43 float psize_min, psize_max;
44
45 if (cso->point_size_per_vertex) {
46 psize_min = util_get_min_point_size(cso);
47 psize_max = 4092;
48 } else {
49 /* Force the point size to be as if the vertex output was disabled. */
50 psize_min = cso->point_size;
51 psize_max = cso->point_size;
52 }
53
54 OUT_REG(ring,
55 A6XX_GRAS_CL_CNTL(
56 .znear_clip_disable = !cso->depth_clip_near,
57 .zfar_clip_disable = !cso->depth_clip_far,
58 .unk5 = !cso->depth_clip_near || !cso->depth_clip_far,
59 .vp_clip_code_ignore = 1,
60 .zero_gb_scale_z = cso->clip_halfz
61 ));
62
63 OUT_REG(ring,
64 A6XX_GRAS_SU_CNTL(
65 .linehalfwidth = cso->line_width / 2.0,
66 .poly_offset = cso->offset_tri,
67 .msaa_enable = cso->multisample,
68 .cull_front = cso->cull_face & PIPE_FACE_FRONT,
69 .cull_back = cso->cull_face & PIPE_FACE_BACK,
70 .front_cw = !cso->front_ccw,
71 ));
72
73 OUT_REG(ring,
74 A6XX_GRAS_SU_POINT_MINMAX(
75 .min = psize_min,
76 .max = psize_max,
77 ),
78 A6XX_GRAS_SU_POINT_SIZE(
79 cso->point_size
80 ));
81
82 OUT_REG(ring,
83 A6XX_GRAS_SU_POLY_OFFSET_SCALE(
84 cso->offset_scale
85 ),
86 A6XX_GRAS_SU_POLY_OFFSET_OFFSET(
87 cso->offset_units
88 ),
89 A6XX_GRAS_SU_POLY_OFFSET_OFFSET_CLAMP(
90 cso->offset_clamp
91 ));
92
93 OUT_REG(ring,
94 A6XX_PC_PRIMITIVE_CNTL_0(
95 .provoking_vtx_last = !cso->flatshade_first,
96 .primitive_restart = primitive_restart,
97 ));
98
99 enum a6xx_polygon_mode mode = POLYMODE6_TRIANGLES;
100 switch (cso->fill_front) {
101 case PIPE_POLYGON_MODE_POINT:
102 mode = POLYMODE6_POINTS;
103 break;
104 case PIPE_POLYGON_MODE_LINE:
105 mode = POLYMODE6_LINES;
106 break;
107 default:
108 assert(cso->fill_front == PIPE_POLYGON_MODE_FILL);
109 break;
110 }
111
112 OUT_REG(ring, A6XX_VPC_POLYGON_MODE(mode));
113 OUT_REG(ring, A6XX_PC_POLYGON_MODE(mode));
114
115 return ring;
116 }
117
118 void *
fd6_rasterizer_state_create(struct pipe_context * pctx,const struct pipe_rasterizer_state * cso)119 fd6_rasterizer_state_create(struct pipe_context *pctx,
120 const struct pipe_rasterizer_state *cso)
121 {
122 struct fd6_rasterizer_stateobj *so;
123
124 so = CALLOC_STRUCT(fd6_rasterizer_stateobj);
125 if (!so)
126 return NULL;
127
128 so->base = *cso;
129
130 return so;
131 }
132
133 void
fd6_rasterizer_state_delete(struct pipe_context * pctx,void * hwcso)134 fd6_rasterizer_state_delete(struct pipe_context *pctx, void *hwcso)
135 {
136 struct fd6_rasterizer_stateobj *so = hwcso;
137
138 for (unsigned i = 0; i < ARRAY_SIZE(so->stateobjs); i++)
139 if (so->stateobjs[i])
140 fd_ringbuffer_del(so->stateobjs[i]);
141
142 FREE(hwcso);
143 }
144
145