Path: blob/21.2-virgl/src/intel/common/intel_guardband.h
4547 views
/*1* Copyright © 2019 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/22#ifndef INTEL_GUARDBAND_H23#define INTEL_GUARDBAND_H2425static inline void26intel_calculate_guardband_size(uint32_t fb_width, uint32_t fb_height,27float m00, float m11, float m30, float m31,28float *xmin, float *xmax,29float *ymin, float *ymax)30{31/* According to the "Vertex X,Y Clamping and Quantization" section of the32* Strips and Fans documentation:33*34* "The vertex X and Y screen-space coordinates are also /clamped/ to the35* fixed-point "guardband" range supported by the rasterization hardware"36*37* and38*39* "In almost all circumstances, if an object’s vertices are actually40* modified by this clamping (i.e., had X or Y coordinates outside of41* the guardband extent the rendered object will not match the intended42* result. Therefore software should take steps to ensure that this does43* not happen - e.g., by clipping objects such that they do not exceed44* these limits after the Drawing Rectangle is applied."45*46* I believe the fundamental restriction is that the rasterizer (in47* the SF/WM stages) have a limit on the number of pixels that can be48* rasterized. We need to ensure any coordinates beyond the rasterizer49* limit are handled by the clipper. So effectively that limit becomes50* the clipper's guardband size.51*52* It goes on to say:53*54* "In addition, in order to be correctly rendered, objects must have a55* screenspace bounding box not exceeding 8K in the X or Y direction.56* This additional restriction must also be comprehended by software,57* i.e., enforced by use of clipping."58*59* This makes no sense. Gfx7+ hardware supports 16K render targets,60* and you definitely need to be able to draw polygons that fill the61* surface. Our assumption is that the rasterizer was limited to 8K62* on Sandybridge, which only supports 8K surfaces, and it was actually63* increased to 16K on Ivybridge and later.64*65* So, limit the guardband to 16K on Gfx7+ and 8K on Sandybridge.66*/67const float gb_size = GFX_VER >= 7 ? 16384.0f : 8192.0f;6869/* Workaround: prevent gpu hangs on SandyBridge70* by disabling guardband clipping for odd dimensions.71*/72if (GFX_VER == 6 && (fb_width & 1 || fb_height & 1)) {73*xmin = -1.0f;74*xmax = 1.0f;75*ymin = -1.0f;76*ymax = 1.0f;77return;78}7980if (m00 != 0 && m11 != 0) {81/* First, we compute the screen-space render area */82const float ss_ra_xmin = MIN3( 0, m30 + m00, m30 - m00);83const float ss_ra_xmax = MAX3( fb_width, m30 + m00, m30 - m00);84const float ss_ra_ymin = MIN3( 0, m31 + m11, m31 - m11);85const float ss_ra_ymax = MAX3(fb_height, m31 + m11, m31 - m11);8687/* We want the guardband to be centered on that */88const float ss_gb_xmin = (ss_ra_xmin + ss_ra_xmax) / 2 - gb_size;89const float ss_gb_xmax = (ss_ra_xmin + ss_ra_xmax) / 2 + gb_size;90const float ss_gb_ymin = (ss_ra_ymin + ss_ra_ymax) / 2 - gb_size;91const float ss_gb_ymax = (ss_ra_ymin + ss_ra_ymax) / 2 + gb_size;9293/* Now we need it in native device coordinates */94const float ndc_gb_xmin = (ss_gb_xmin - m30) / m00;95const float ndc_gb_xmax = (ss_gb_xmax - m30) / m00;96const float ndc_gb_ymin = (ss_gb_ymin - m31) / m11;97const float ndc_gb_ymax = (ss_gb_ymax - m31) / m11;9899/* Thanks to Y-flipping and ORIGIN_UPPER_LEFT, the Y coordinates may be100* flipped upside-down. X should be fine though.101*/102assert(ndc_gb_xmin <= ndc_gb_xmax);103*xmin = ndc_gb_xmin;104*xmax = ndc_gb_xmax;105*ymin = MIN2(ndc_gb_ymin, ndc_gb_ymax);106*ymax = MAX2(ndc_gb_ymin, ndc_gb_ymax);107} else {108/* The viewport scales to 0, so nothing will be rendered. */109*xmin = 0.0f;110*xmax = 0.0f;111*ymin = 0.0f;112*ymax = 0.0f;113}114}115116#endif /* INTEL_GUARDBAND_H */117118119