OSDN Git Service

5d6479777551fc5b8c97e63cd2e3b53806379ad0
[android-x86/external-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                           VC4_DIRTY_RASTERIZER)) {
34                 float *vpscale = vc4->viewport.scale;
35                 float *vptranslate = vc4->viewport.translate;
36                 float vp_minx = -fabsf(vpscale[0]) + vptranslate[0];
37                 float vp_maxx = fabsf(vpscale[0]) + vptranslate[0];
38                 float vp_miny = -fabsf(vpscale[1]) + vptranslate[1];
39                 float vp_maxy = fabsf(vpscale[1]) + vptranslate[1];
40
41                 /* Clip to the scissor if it's enabled, but still clip to the
42                  * drawable regardless since that controls where the binner
43                  * tries to put things.
44                  *
45                  * Additionally, always clip the rendering to the viewport,
46                  * since the hardware does guardband clipping, meaning
47                  * primitives would rasterize outside of the view volume.
48                  */
49                 uint32_t minx, miny, maxx, maxy;
50                 if (!vc4->rasterizer->base.scissor) {
51                         minx = MAX2(vp_minx, 0);
52                         miny = MAX2(vp_miny, 0);
53                         maxx = MIN2(vp_maxx, vc4->draw_width);
54                         maxy = MIN2(vp_maxy, vc4->draw_height);
55                 } else {
56                         minx = MAX2(vp_minx, vc4->scissor.minx);
57                         miny = MAX2(vp_miny, vc4->scissor.miny);
58                         maxx = MIN2(vp_maxx, vc4->scissor.maxx);
59                         maxy = MIN2(vp_maxy, vc4->scissor.maxy);
60                 }
61
62                 cl_u8(&bcl, VC4_PACKET_CLIP_WINDOW);
63                 cl_u16(&bcl, minx);
64                 cl_u16(&bcl, miny);
65                 cl_u16(&bcl, maxx - minx);
66                 cl_u16(&bcl, maxy - miny);
67
68                 vc4->draw_min_x = MIN2(vc4->draw_min_x, minx);
69                 vc4->draw_min_y = MIN2(vc4->draw_min_y, miny);
70                 vc4->draw_max_x = MAX2(vc4->draw_max_x, maxx);
71                 vc4->draw_max_y = MAX2(vc4->draw_max_y, maxy);
72         }
73
74         if (vc4->dirty & (VC4_DIRTY_RASTERIZER | VC4_DIRTY_ZSA)) {
75                 uint8_t ez_enable_mask_out = ~0;
76
77                 /* HW-2905: If the RCL ends up doing a full-res load when
78                  * multisampling, then early Z tracking may end up with values
79                  * from the previous tile due to a HW bug.  Disable it to
80                  * avoid that.
81                  *
82                  * We should be able to skip this when the Z is cleared, but I
83                  * was seeing bad rendering on glxgears -samples 4 even in
84                  * that case.
85                  */
86                 if (vc4->msaa)
87                         ez_enable_mask_out &= ~VC4_CONFIG_BITS_EARLY_Z;
88
89                 cl_u8(&bcl, VC4_PACKET_CONFIGURATION_BITS);
90                 cl_u8(&bcl,
91                       vc4->rasterizer->config_bits[0] |
92                       vc4->zsa->config_bits[0]);
93                 cl_u8(&bcl,
94                       vc4->rasterizer->config_bits[1] |
95                       vc4->zsa->config_bits[1]);
96                 cl_u8(&bcl,
97                       (vc4->rasterizer->config_bits[2] |
98                        vc4->zsa->config_bits[2]) & ez_enable_mask_out);
99         }
100
101         if (vc4->dirty & VC4_DIRTY_RASTERIZER) {
102                 cl_u8(&bcl, VC4_PACKET_DEPTH_OFFSET);
103                 cl_u16(&bcl, vc4->rasterizer->offset_factor);
104                 cl_u16(&bcl, vc4->rasterizer->offset_units);
105
106                 cl_u8(&bcl, VC4_PACKET_POINT_SIZE);
107                 cl_f(&bcl, vc4->rasterizer->point_size);
108
109                 cl_u8(&bcl, VC4_PACKET_LINE_WIDTH);
110                 cl_f(&bcl, vc4->rasterizer->base.line_width);
111         }
112
113         if (vc4->dirty & VC4_DIRTY_VIEWPORT) {
114                 cl_u8(&bcl, VC4_PACKET_CLIPPER_XY_SCALING);
115                 cl_f(&bcl, vc4->viewport.scale[0] * 16.0f);
116                 cl_f(&bcl, vc4->viewport.scale[1] * 16.0f);
117
118                 cl_u8(&bcl, VC4_PACKET_CLIPPER_Z_SCALING);
119                 cl_f(&bcl, vc4->viewport.translate[2]);
120                 cl_f(&bcl, vc4->viewport.scale[2]);
121
122                 cl_u8(&bcl, VC4_PACKET_VIEWPORT_OFFSET);
123                 cl_u16(&bcl, 16 * vc4->viewport.translate[0]);
124                 cl_u16(&bcl, 16 * vc4->viewport.translate[1]);
125         }
126
127         if (vc4->dirty & VC4_DIRTY_FLAT_SHADE_FLAGS) {
128                 cl_u8(&bcl, VC4_PACKET_FLAT_SHADE_FLAGS);
129                 cl_u32(&bcl, vc4->rasterizer->base.flatshade ?
130                        vc4->prog.fs->color_inputs : 0);
131         }
132
133         cl_end(&vc4->bcl, bcl);
134 }