Merge remote-tracking branch 'mesa-public/master' into vulkan
[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 struct vc4_cl_out *bcl = cl_start(&vc4->bcl);
32 if (vc4->dirty & (VC4_DIRTY_SCISSOR | VC4_DIRTY_VIEWPORT)) {
33 float *vpscale = vc4->viewport.scale;
34 float *vptranslate = vc4->viewport.translate;
35 float vp_minx = -fabsf(vpscale[0]) + vptranslate[0];
36 float vp_maxx = fabsf(vpscale[0]) + vptranslate[0];
37 float vp_miny = -fabsf(vpscale[1]) + vptranslate[1];
38 float vp_maxy = fabsf(vpscale[1]) + vptranslate[1];
39 uint32_t minx = MAX2(vc4->scissor.minx, vp_minx);
40 uint32_t miny = MAX2(vc4->scissor.miny, vp_miny);
41 uint32_t maxx = MIN2(vc4->scissor.maxx, vp_maxx);
42 uint32_t maxy = MIN2(vc4->scissor.maxy, vp_maxy);
43
44 cl_u8(&bcl, VC4_PACKET_CLIP_WINDOW);
45 cl_u16(&bcl, minx);
46 cl_u16(&bcl, miny);
47 cl_u16(&bcl, maxx - minx);
48 cl_u16(&bcl, maxy - miny);
49
50 vc4->draw_min_x = MIN2(vc4->draw_min_x, minx);
51 vc4->draw_min_y = MIN2(vc4->draw_min_y, miny);
52 vc4->draw_max_x = MAX2(vc4->draw_max_x, maxx);
53 vc4->draw_max_y = MAX2(vc4->draw_max_y, maxy);
54 }
55
56 if (vc4->dirty & (VC4_DIRTY_RASTERIZER | VC4_DIRTY_ZSA)) {
57 cl_u8(&bcl, VC4_PACKET_CONFIGURATION_BITS);
58 cl_u8(&bcl,
59 vc4->rasterizer->config_bits[0] |
60 vc4->zsa->config_bits[0]);
61 cl_u8(&bcl,
62 vc4->rasterizer->config_bits[1] |
63 vc4->zsa->config_bits[1]);
64 cl_u8(&bcl,
65 vc4->rasterizer->config_bits[2] |
66 vc4->zsa->config_bits[2]);
67 }
68
69 if (vc4->dirty & VC4_DIRTY_RASTERIZER) {
70 cl_u8(&bcl, VC4_PACKET_DEPTH_OFFSET);
71 cl_u16(&bcl, vc4->rasterizer->offset_factor);
72 cl_u16(&bcl, vc4->rasterizer->offset_units);
73
74 cl_u8(&bcl, VC4_PACKET_POINT_SIZE);
75 cl_f(&bcl, vc4->rasterizer->point_size);
76
77 cl_u8(&bcl, VC4_PACKET_LINE_WIDTH);
78 cl_f(&bcl, vc4->rasterizer->base.line_width);
79 }
80
81 if (vc4->dirty & VC4_DIRTY_VIEWPORT) {
82 cl_u8(&bcl, VC4_PACKET_CLIPPER_XY_SCALING);
83 cl_f(&bcl, vc4->viewport.scale[0] * 16.0f);
84 cl_f(&bcl, vc4->viewport.scale[1] * 16.0f);
85
86 cl_u8(&bcl, VC4_PACKET_CLIPPER_Z_SCALING);
87 cl_f(&bcl, vc4->viewport.translate[2]);
88 cl_f(&bcl, vc4->viewport.scale[2]);
89
90 cl_u8(&bcl, VC4_PACKET_VIEWPORT_OFFSET);
91 cl_u16(&bcl, 16 * vc4->viewport.translate[0]);
92 cl_u16(&bcl, 16 * vc4->viewport.translate[1]);
93 }
94
95 if (vc4->dirty & VC4_DIRTY_FLAT_SHADE_FLAGS) {
96 cl_u8(&bcl, VC4_PACKET_FLAT_SHADE_FLAGS);
97 cl_u32(&bcl, vc4->rasterizer->base.flatshade ?
98 vc4->prog.fs->color_inputs : 0);
99 }
100
101 cl_end(&vc4->bcl, bcl);
102 }