2 * Copyright © 2019 Intel Corporation
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:
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
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
23 #ifndef GEN_GUARDBAND_H
24 #define GEN_GUARDBAND_H
27 gen_calculate_guardband_size(uint32_t fb_width
, uint32_t fb_height
,
28 float m00
, float m11
, float m30
, float m31
,
29 float *xmin
, float *xmax
,
30 float *ymin
, float *ymax
)
32 /* According to the "Vertex X,Y Clamping and Quantization" section of the
33 * Strips and Fans documentation:
35 * "The vertex X and Y screen-space coordinates are also /clamped/ to the
36 * fixed-point "guardband" range supported by the rasterization hardware"
40 * "In almost all circumstances, if an object’s vertices are actually
41 * modified by this clamping (i.e., had X or Y coordinates outside of
42 * the guardband extent the rendered object will not match the intended
43 * result. Therefore software should take steps to ensure that this does
44 * not happen - e.g., by clipping objects such that they do not exceed
45 * these limits after the Drawing Rectangle is applied."
47 * I believe the fundamental restriction is that the rasterizer (in
48 * the SF/WM stages) have a limit on the number of pixels that can be
49 * rasterized. We need to ensure any coordinates beyond the rasterizer
50 * limit are handled by the clipper. So effectively that limit becomes
51 * the clipper's guardband size.
55 * "In addition, in order to be correctly rendered, objects must have a
56 * screenspace bounding box not exceeding 8K in the X or Y direction.
57 * This additional restriction must also be comprehended by software,
58 * i.e., enforced by use of clipping."
60 * This makes no sense. Gen7+ hardware supports 16K render targets,
61 * and you definitely need to be able to draw polygons that fill the
62 * surface. Our assumption is that the rasterizer was limited to 8K
63 * on Sandybridge, which only supports 8K surfaces, and it was actually
64 * increased to 16K on Ivybridge and later.
66 * So, limit the guardband to 16K on Gen7+ and 8K on Sandybridge.
68 const float gb_size
= GEN_GEN
>= 7 ? 16384.0f
: 8192.0f
;
70 /* Workaround: prevent gpu hangs on SandyBridge
71 * by disabling guardband clipping for odd dimensions.
73 if (GEN_GEN
== 6 && (fb_width
& 1 || fb_height
& 1)) {
81 if (m00
!= 0 && m11
!= 0) {
82 /* First, we compute the screen-space render area */
83 const float ss_ra_xmin
= MIN3( 0, m30
+ m00
, m30
- m00
);
84 const float ss_ra_xmax
= MAX3( fb_width
, m30
+ m00
, m30
- m00
);
85 const float ss_ra_ymin
= MIN3( 0, m31
+ m11
, m31
- m11
);
86 const float ss_ra_ymax
= MAX3(fb_height
, m31
+ m11
, m31
- m11
);
88 /* We want the guardband to be centered on that */
89 const float ss_gb_xmin
= (ss_ra_xmin
+ ss_ra_xmax
) / 2 - gb_size
;
90 const float ss_gb_xmax
= (ss_ra_xmin
+ ss_ra_xmax
) / 2 + gb_size
;
91 const float ss_gb_ymin
= (ss_ra_ymin
+ ss_ra_ymax
) / 2 - gb_size
;
92 const float ss_gb_ymax
= (ss_ra_ymin
+ ss_ra_ymax
) / 2 + gb_size
;
94 /* Now we need it in native device coordinates */
95 const float ndc_gb_xmin
= (ss_gb_xmin
- m30
) / m00
;
96 const float ndc_gb_xmax
= (ss_gb_xmax
- m30
) / m00
;
97 const float ndc_gb_ymin
= (ss_gb_ymin
- m31
) / m11
;
98 const float ndc_gb_ymax
= (ss_gb_ymax
- m31
) / m11
;
100 /* Thanks to Y-flipping and ORIGIN_UPPER_LEFT, the Y coordinates may be
101 * flipped upside-down. X should be fine though.
103 assert(ndc_gb_xmin
<= ndc_gb_xmax
);
106 *ymin
= MIN2(ndc_gb_ymin
, ndc_gb_ymax
);
107 *ymax
= MAX2(ndc_gb_ymin
, ndc_gb_ymax
);
109 /* The viewport scales to 0, so nothing will be rendered. */
117 #endif /* GEN_GUARDBAND_H */