1 /*
2 * Copyright (c) 2012-2015 Etnaviv Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "etnaviv_rasterizer.h"
25 #include "etnaviv_context.h"
26 #include "etnaviv_screen.h"
27
28 #include "hw/common.xml.h"
29
30 #include "etnaviv_translate.h"
31 #include "util/u_math.h"
32 #include "util/u_memory.h"
33
34 void *
etna_rasterizer_state_create(struct pipe_context * pctx,const struct pipe_rasterizer_state * so)35 etna_rasterizer_state_create(struct pipe_context *pctx,
36 const struct pipe_rasterizer_state *so)
37 {
38 struct etna_rasterizer_state *cs;
39 struct etna_context *ctx = etna_context(pctx);
40
41 if (so->fill_front != so->fill_back)
42 DBG("Different front and back fill mode not supported");
43
44 cs = CALLOC_STRUCT(etna_rasterizer_state);
45 if (!cs)
46 return NULL;
47
48 cs->base = *so;
49
50 cs->PA_CONFIG = (so->flatshade ? VIVS_PA_CONFIG_SHADE_MODEL_FLAT : VIVS_PA_CONFIG_SHADE_MODEL_SMOOTH) |
51 translate_cull_face(so->cull_face, so->front_ccw) |
52 translate_polygon_mode(so->fill_front) |
53 COND(so->point_quad_rasterization, VIVS_PA_CONFIG_POINT_SPRITE_ENABLE) |
54 COND(so->point_size_per_vertex, VIVS_PA_CONFIG_POINT_SIZE_ENABLE) |
55 COND(VIV_FEATURE(ctx->screen, chipMinorFeatures1, WIDE_LINE), VIVS_PA_CONFIG_WIDE_LINE);
56 cs->PA_LINE_WIDTH = fui(so->line_width / 2.0f);
57 cs->PA_POINT_SIZE = fui(so->point_size / 2.0f);
58 cs->SE_DEPTH_SCALE = fui(so->offset_scale);
59 cs->SE_DEPTH_BIAS = fui((so->offset_units / 65535.0f) * 2.0f);
60 cs->SE_CONFIG = COND(so->line_last_pixel, VIVS_SE_CONFIG_LAST_PIXEL_ENABLE);
61 /* XXX anything else? */
62 /* XXX bottom_edge_rule */
63 cs->PA_SYSTEM_MODE =
64 COND(!so->flatshade_first, VIVS_PA_SYSTEM_MODE_PROVOKING_VERTEX_LAST) |
65 COND(so->half_pixel_center, VIVS_PA_SYSTEM_MODE_HALF_PIXEL_CENTER);
66
67 /* so->scissor overrides the scissor, defaulting to the whole framebuffer,
68 * with the scissor state */
69 cs->scissor = so->scissor;
70
71 /* point size per vertex adds a vertex shader output */
72 cs->point_size_per_vertex = so->point_size_per_vertex;
73
74 assert(!so->clip_halfz); /* could be supported with shader magic, actually
75 D3D z is default on older gc */
76
77 return cs;
78 }
79