26bb567f65ce0dc37b7582e1fe7b019533aa4170
[mesa.git] / src / gallium / drivers / freedreno / a6xx / fd6_rasterizer.c
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
37 void *
38 fd6_rasterizer_state_create(struct pipe_context *pctx,
39 const struct pipe_rasterizer_state *cso)
40 {
41 struct fd_context *ctx = fd_context(pctx);
42 struct fd6_rasterizer_stateobj *so;
43 float psize_min, psize_max;
44
45 so = CALLOC_STRUCT(fd6_rasterizer_stateobj);
46 if (!so)
47 return NULL;
48
49 so->base = *cso;
50
51 if (cso->point_size_per_vertex) {
52 psize_min = util_get_min_point_size(cso);
53 psize_max = 4092;
54 } else {
55 /* Force the point size to be as if the vertex output was disabled. */
56 psize_min = cso->point_size;
57 psize_max = cso->point_size;
58 }
59
60 so->gras_su_point_minmax =
61 A6XX_GRAS_SU_POINT_MINMAX_MIN(psize_min) |
62 A6XX_GRAS_SU_POINT_MINMAX_MAX(psize_max);
63 so->gras_su_point_size = A6XX_GRAS_SU_POINT_SIZE(cso->point_size);
64 so->gras_su_poly_offset_scale =
65 A6XX_GRAS_SU_POLY_OFFSET_SCALE(cso->offset_scale);
66 so->gras_su_poly_offset_offset =
67 A6XX_GRAS_SU_POLY_OFFSET_OFFSET(cso->offset_units);
68 so->gras_su_poly_offset_clamp =
69 A6XX_GRAS_SU_POLY_OFFSET_OFFSET_CLAMP(cso->offset_clamp);
70
71 so->gras_su_cntl =
72 A6XX_GRAS_SU_CNTL_LINEHALFWIDTH(cso->line_width/2.0);
73 #if 0
74 so->pc_raster_cntl =
75 A6XX_PC_RASTER_CNTL_POLYMODE_FRONT_PTYPE(fd_polygon_mode(cso->fill_front)) |
76 A6XX_PC_RASTER_CNTL_POLYMODE_BACK_PTYPE(fd_polygon_mode(cso->fill_back));
77 #endif
78
79 #if 0
80 if (cso->fill_front != PIPE_POLYGON_MODE_FILL ||
81 cso->fill_back != PIPE_POLYGON_MODE_FILL)
82 so->pc_raster_cntl |= A6XX_PC_RASTER_CNTL_POLYMODE_ENABLE;
83 #endif
84
85 if (cso->cull_face & PIPE_FACE_FRONT)
86 so->gras_su_cntl |= A6XX_GRAS_SU_CNTL_CULL_FRONT;
87 if (cso->cull_face & PIPE_FACE_BACK)
88 so->gras_su_cntl |= A6XX_GRAS_SU_CNTL_CULL_BACK;
89 if (!cso->front_ccw)
90 so->gras_su_cntl |= A6XX_GRAS_SU_CNTL_FRONT_CW;
91 if (cso->offset_tri)
92 so->gras_su_cntl |= A6XX_GRAS_SU_CNTL_POLY_OFFSET;
93
94 if (!cso->flatshade_first)
95 so->pc_primitive_cntl |= A6XX_PC_PRIMITIVE_CNTL_0_PROVOKING_VTX_LAST;
96
97 // if (!cso->depth_clip)
98 // so->gras_cl_clip_cntl |= A6XX_GRAS_CL_CLIP_CNTL_ZNEAR_CLIP_DISABLE |
99 // A6XX_GRAS_CL_CLIP_CNTL_ZFAR_CLIP_DISABLE;
100 #if 0
101 if (cso->clip_halfz)
102 so->gras_cl_clip_cntl |= A6XX_GRAS_CL_CNTL_ZERO_GB_SCALE_Z;
103 #endif
104
105 so->stateobj = fd_ringbuffer_new_object(ctx->pipe, 15 * 4);
106 struct fd_ringbuffer *ring = so->stateobj;
107
108 OUT_PKT4(ring, REG_A6XX_GRAS_UNKNOWN_8000, 1);
109 OUT_RING(ring, 0x80);
110 OUT_PKT4(ring, REG_A6XX_GRAS_UNKNOWN_8001, 1);
111 OUT_RING(ring, 0x0);
112 OUT_PKT4(ring, REG_A6XX_GRAS_UNKNOWN_8004, 1);
113 OUT_RING(ring, 0x0);
114
115 OUT_PKT4(ring, REG_A6XX_GRAS_SU_CNTL, 1);
116 OUT_RING(ring, so->gras_su_cntl);
117
118 OUT_PKT4(ring, REG_A6XX_GRAS_SU_POINT_MINMAX, 2);
119 OUT_RING(ring, so->gras_su_point_minmax);
120 OUT_RING(ring, so->gras_su_point_size);
121
122 OUT_PKT4(ring, REG_A6XX_GRAS_SU_POLY_OFFSET_SCALE, 3);
123 OUT_RING(ring, so->gras_su_poly_offset_scale);
124 OUT_RING(ring, so->gras_su_poly_offset_offset);
125 OUT_RING(ring, so->gras_su_poly_offset_clamp);
126
127 #if 0
128 OUT_PKT4(ring, REG_A6XX_PC_RASTER_CNTL, 1);
129 OUT_RING(ring, so->pc_raster_cntl);
130
131 OUT_PKT4(ring, REG_A6XX_GRAS_CL_CNTL, 1);
132 OUT_RING(ring, so->gras_cl_clip_cntl);
133 #endif
134
135 return so;
136 }
137
138 void
139 fd6_rasterizer_state_delete(struct pipe_context *pctx, void *hwcso)
140 {
141 struct fd6_rasterizer_stateobj *so = hwcso;
142
143 fd_ringbuffer_del(so->stateobj);
144 FREE(hwcso);
145 }
146