4990fd180257c4093758d206cdf55d7959a0f89f
[mesa.git] / src / gallium / drivers / etnaviv / etnaviv_rasterizer.c
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 *
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 /* Disregard flatshading on GC880+, as a HW bug there seem to disable all
42 * varying interpolation if it's enabled */
43 bool flatshade = ctx->screen->model < 880 ? so->flatshade : false;
44
45 if (so->fill_front != so->fill_back)
46 DBG("Different front and back fill mode not supported");
47
48 cs = CALLOC_STRUCT(etna_rasterizer_state);
49 if (!cs)
50 return NULL;
51
52 cs->base = *so;
53
54 cs->PA_CONFIG = (flatshade ? VIVS_PA_CONFIG_SHADE_MODEL_FLAT : VIVS_PA_CONFIG_SHADE_MODEL_SMOOTH) |
55 translate_cull_face(so->cull_face, so->front_ccw) |
56 translate_polygon_mode(so->fill_front) |
57 COND(so->point_quad_rasterization, VIVS_PA_CONFIG_POINT_SPRITE_ENABLE) |
58 COND(so->point_size_per_vertex, VIVS_PA_CONFIG_POINT_SIZE_ENABLE) |
59 COND(VIV_FEATURE(ctx->screen, chipMinorFeatures1, WIDE_LINE), VIVS_PA_CONFIG_WIDE_LINE);
60 cs->PA_LINE_WIDTH = fui(so->line_width / 2.0f);
61 cs->PA_POINT_SIZE = fui(so->point_size / 2.0f);
62 cs->SE_DEPTH_SCALE = fui(so->offset_scale);
63 cs->SE_DEPTH_BIAS = fui(so->offset_units) / 65535.0f;
64 cs->SE_CONFIG = COND(so->line_last_pixel, VIVS_SE_CONFIG_LAST_PIXEL_ENABLE);
65 /* XXX anything else? */
66 /* XXX bottom_edge_rule */
67 cs->PA_SYSTEM_MODE =
68 COND(so->half_pixel_center, VIVS_PA_SYSTEM_MODE_UNK0 | VIVS_PA_SYSTEM_MODE_UNK4);
69
70 /* so->scissor overrides the scissor, defaulting to the whole framebuffer,
71 * with the scissor state */
72 cs->scissor = so->scissor;
73
74 /* point size per vertex adds a vertex shader output */
75 cs->point_size_per_vertex = so->point_size_per_vertex;
76
77 assert(!so->clip_halfz); /* could be supported with shader magic, actually
78 D3D z is default on older gc */
79
80 return cs;
81 }