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 #define FD_BO_NO_HARDPIN 1
29
30 #include "pipe/p_state.h"
31 #include "util/u_memory.h"
32 #include "util/u_string.h"
33
34 #include "fd6_context.h"
35 #include "fd6_pack.h"
36 #include "fd6_rasterizer.h"
37
38 template <chip CHIP>
39 struct fd_ringbuffer *
__fd6_setup_rasterizer_stateobj(struct fd_context * ctx,const struct pipe_rasterizer_state * cso,bool primitive_restart)40 __fd6_setup_rasterizer_stateobj(struct fd_context *ctx,
41 const struct pipe_rasterizer_state *cso,
42 bool primitive_restart)
43 {
44 struct fd_ringbuffer *ring = fd_ringbuffer_new_object(ctx->pipe, 26 * 4);
45 float psize_min, psize_max;
46
47 if (cso->point_size_per_vertex) {
48 psize_min = util_get_min_point_size(cso);
49 psize_max = 4092;
50 } else {
51 /* Force the point size to be as if the vertex output was disabled. */
52 psize_min = cso->point_size;
53 psize_max = cso->point_size;
54 }
55
56 OUT_REG(ring,
57 A6XX_GRAS_CL_CNTL(
58 .znear_clip_disable = !cso->depth_clip_near,
59 .zfar_clip_disable = !cso->depth_clip_far,
60 .z_clamp_enable = cso->depth_clamp,
61 .zero_gb_scale_z = cso->clip_halfz,
62 .vp_clip_code_ignore = 1,
63 ),
64 );
65
66 OUT_REG(ring,
67 A6XX_GRAS_SU_CNTL(
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 .linehalfwidth = cso->line_width / 2.0f,
72 .poly_offset = cso->offset_tri,
73 .line_mode = cso->multisample ? RECTANGULAR : BRESENHAM,
74 ),
75 );
76
77 OUT_REG(ring,
78 A6XX_GRAS_SU_POINT_MINMAX(.min = psize_min, .max = psize_max, ),
79 A6XX_GRAS_SU_POINT_SIZE(cso->point_size));
80
81 OUT_REG(ring, A6XX_GRAS_SU_POLY_OFFSET_SCALE(cso->offset_scale),
82 A6XX_GRAS_SU_POLY_OFFSET_OFFSET(cso->offset_units),
83 A6XX_GRAS_SU_POLY_OFFSET_OFFSET_CLAMP(cso->offset_clamp));
84
85 OUT_REG(ring,
86 A6XX_PC_PRIMITIVE_CNTL_0(
87 .primitive_restart = primitive_restart,
88 .provoking_vtx_last = !cso->flatshade_first,
89 ),
90 );
91
92 enum a6xx_polygon_mode mode = POLYMODE6_TRIANGLES;
93 switch (cso->fill_front) {
94 case PIPE_POLYGON_MODE_POINT:
95 mode = POLYMODE6_POINTS;
96 break;
97 case PIPE_POLYGON_MODE_LINE:
98 mode = POLYMODE6_LINES;
99 break;
100 default:
101 assert(cso->fill_front == PIPE_POLYGON_MODE_FILL);
102 break;
103 }
104
105 OUT_REG(ring, A6XX_VPC_POLYGON_MODE(mode));
106 OUT_REG(ring, PC_POLYGON_MODE(CHIP, mode));
107
108 if (ctx->screen->info->a6xx.has_shading_rate) {
109 OUT_REG(ring, A6XX_RB_UNKNOWN_8A00());
110 OUT_REG(ring, A6XX_RB_UNKNOWN_8A10());
111 OUT_REG(ring, A6XX_RB_UNKNOWN_8A20());
112 OUT_REG(ring, A6XX_RB_UNKNOWN_8A30());
113 }
114
115 return ring;
116 }
117
118 template struct fd_ringbuffer *__fd6_setup_rasterizer_stateobj<A6XX>(struct fd_context *ctx, const struct pipe_rasterizer_state *cso, bool primitive_restart);
119 template struct fd_ringbuffer *__fd6_setup_rasterizer_stateobj<A7XX>(struct fd_context *ctx, const struct pipe_rasterizer_state *cso, bool primitive_restart);
120
121 void *
fd6_rasterizer_state_create(struct pipe_context * pctx,const struct pipe_rasterizer_state * cso)122 fd6_rasterizer_state_create(struct pipe_context *pctx,
123 const struct pipe_rasterizer_state *cso)
124 {
125 struct fd6_rasterizer_stateobj *so;
126
127 so = CALLOC_STRUCT(fd6_rasterizer_stateobj);
128 if (!so)
129 return NULL;
130
131 so->base = *cso;
132
133 return so;
134 }
135
136 void
fd6_rasterizer_state_delete(struct pipe_context * pctx,void * hwcso)137 fd6_rasterizer_state_delete(struct pipe_context *pctx, void *hwcso)
138 {
139 struct fd6_rasterizer_stateobj *so = (struct fd6_rasterizer_stateobj *)hwcso;
140
141 for (unsigned i = 0; i < ARRAY_SIZE(so->stateobjs); i++)
142 if (so->stateobjs[i])
143 fd_ringbuffer_del(so->stateobjs[i]);
144
145 FREE(hwcso);
146 }
147