vc4: Fix triangle-guardband-viewport piglit test.
[mesa.git] / src / gallium / drivers / vc4 / vc4_emit.c
1 /*
2 * Copyright © 2014 Broadcom
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, sublicense,
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 next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * 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 NONINFRINGEMENT. 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 DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "vc4_context.h"
25
26 void
27 vc4_emit_state(struct pipe_context *pctx)
28 {
29 struct vc4_context *vc4 = vc4_context(pctx);
30
31 if (vc4->dirty & (VC4_DIRTY_SCISSOR | VC4_DIRTY_VIEWPORT)) {
32 float *vpscale = vc4->viewport.scale;
33 float *vptranslate = vc4->viewport.translate;
34 float vp_minx = -fabs(vpscale[0]) + vptranslate[0];
35 float vp_maxx = fabs(vpscale[0]) + vptranslate[0];
36 float vp_miny = -fabs(vpscale[1]) + vptranslate[1];
37 float vp_maxy = fabs(vpscale[1]) + vptranslate[1];
38 uint32_t minx = MAX2(vc4->scissor.minx, vp_minx);
39 uint32_t miny = MAX2(vc4->scissor.miny, vp_miny);
40
41 cl_u8(&vc4->bcl, VC4_PACKET_CLIP_WINDOW);
42 cl_u16(&vc4->bcl, minx);
43 cl_u16(&vc4->bcl, miny);
44 cl_u16(&vc4->bcl, MIN2(vc4->scissor.maxx, vp_maxx) - minx);
45 cl_u16(&vc4->bcl, MIN2(vc4->scissor.maxy, vp_maxy) - miny);
46 }
47
48 if (vc4->dirty & (VC4_DIRTY_RASTERIZER | VC4_DIRTY_ZSA)) {
49 cl_u8(&vc4->bcl, VC4_PACKET_CONFIGURATION_BITS);
50 cl_u8(&vc4->bcl,
51 vc4->rasterizer->config_bits[0] |
52 vc4->zsa->config_bits[0]);
53 cl_u8(&vc4->bcl,
54 vc4->rasterizer->config_bits[1] |
55 vc4->zsa->config_bits[1]);
56 cl_u8(&vc4->bcl,
57 vc4->rasterizer->config_bits[2] |
58 vc4->zsa->config_bits[2]);
59 }
60
61 if (vc4->dirty & VC4_DIRTY_RASTERIZER) {
62 cl_u8(&vc4->bcl, VC4_PACKET_DEPTH_OFFSET);
63 cl_u16(&vc4->bcl, vc4->rasterizer->offset_factor);
64 cl_u16(&vc4->bcl, vc4->rasterizer->offset_units);
65
66 cl_u8(&vc4->bcl, VC4_PACKET_POINT_SIZE);
67 cl_f(&vc4->bcl, vc4->rasterizer->point_size);
68
69 cl_u8(&vc4->bcl, VC4_PACKET_LINE_WIDTH);
70 cl_f(&vc4->bcl, vc4->rasterizer->base.line_width);
71 }
72
73 if (vc4->dirty & VC4_DIRTY_VIEWPORT) {
74 cl_u8(&vc4->bcl, VC4_PACKET_CLIPPER_XY_SCALING);
75 cl_f(&vc4->bcl, vc4->viewport.scale[0] * 16.0f);
76 cl_f(&vc4->bcl, vc4->viewport.scale[1] * 16.0f);
77
78 cl_u8(&vc4->bcl, VC4_PACKET_CLIPPER_Z_SCALING);
79 cl_f(&vc4->bcl, vc4->viewport.translate[2]);
80 cl_f(&vc4->bcl, vc4->viewport.scale[2]);
81
82 cl_u8(&vc4->bcl, VC4_PACKET_VIEWPORT_OFFSET);
83 cl_u16(&vc4->bcl, 16 * vc4->viewport.translate[0]);
84 cl_u16(&vc4->bcl, 16 * vc4->viewport.translate[1]);
85 }
86
87 if (vc4->dirty & VC4_DIRTY_FLAT_SHADE_FLAGS) {
88 cl_u8(&vc4->bcl, VC4_PACKET_FLAT_SHADE_FLAGS);
89 cl_u32(&vc4->bcl, vc4->rasterizer->base.flatshade ?
90 vc4->prog.fs->color_inputs : 0);
91 }
92 }