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 "etnaviv_translate.h"
29 #include "util/u_math.h"
30 #include "util/u_memory.h"
31
32 void *
etna_rasterizer_state_create(struct pipe_context * pctx,const struct pipe_rasterizer_state * so)33 etna_rasterizer_state_create(struct pipe_context *pctx,
34 const struct pipe_rasterizer_state *so)
35 {
36 struct etna_rasterizer_state *cs;
37 struct etna_context *ctx = etna_context(pctx);
38
39 if (so->fill_front != so->fill_back)
40 DBG("Different front and back fill mode not supported");
41
42 cs = CALLOC_STRUCT(etna_rasterizer_state);
43 if (!cs)
44 return NULL;
45
46 cs->base = *so;
47
48 cs->PA_CONFIG = (so->flatshade ? VIVS_PA_CONFIG_SHADE_MODEL_FLAT : VIVS_PA_CONFIG_SHADE_MODEL_SMOOTH) |
49 translate_cull_face(so->cull_face, so->front_ccw) |
50 translate_polygon_mode(so->fill_front) |
51 COND(so->point_quad_rasterization, VIVS_PA_CONFIG_POINT_SPRITE_ENABLE) |
52 COND(so->point_size_per_vertex, VIVS_PA_CONFIG_POINT_SIZE_ENABLE) |
53 COND(VIV_FEATURE(ctx->screen, ETNA_FEATURE_WIDE_LINE), VIVS_PA_CONFIG_WIDE_LINE);
54 cs->PA_LINE_WIDTH = fui(so->line_width / 2.0f);
55 cs->PA_POINT_SIZE = fui(so->point_size / 2.0f);
56 cs->SE_DEPTH_SCALE = fui(so->offset_scale);
57 cs->SE_DEPTH_BIAS = fui((so->offset_units / 65535.0f) * 2.0f);
58 cs->SE_CONFIG = COND(so->line_last_pixel, VIVS_SE_CONFIG_LAST_PIXEL_ENABLE);
59 /* XXX anything else? */
60 /* XXX bottom_edge_rule */
61 cs->PA_SYSTEM_MODE =
62 COND(!so->flatshade_first, VIVS_PA_SYSTEM_MODE_PROVOKING_VERTEX_LAST) |
63 COND(so->half_pixel_center, VIVS_PA_SYSTEM_MODE_HALF_PIXEL_CENTER);
64
65 /* so->scissor overrides the scissor, defaulting to the whole framebuffer,
66 * with the scissor state */
67 cs->scissor = so->scissor;
68
69 /* point size per vertex adds a vertex shader output */
70 cs->point_size_per_vertex = so->point_size_per_vertex;
71
72 assert(!so->clip_halfz); /* could be supported with shader magic, actually
73 D3D z is default on older gc */
74
75 return cs;
76 }
77