Path: blob/21.2-virgl/src/gallium/drivers/vc4/vc4_emit.c
4570 views
/*1* Copyright © 2014 Broadcom2*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*/2223#include "vc4_context.h"2425void26vc4_emit_state(struct pipe_context *pctx)27{28struct vc4_context *vc4 = vc4_context(pctx);29struct vc4_job *job = vc4->job;3031if (vc4->dirty & (VC4_DIRTY_SCISSOR | VC4_DIRTY_VIEWPORT |32VC4_DIRTY_RASTERIZER)) {33float *vpscale = vc4->viewport.scale;34float *vptranslate = vc4->viewport.translate;35float vp_minx = -fabsf(vpscale[0]) + vptranslate[0];36float vp_maxx = fabsf(vpscale[0]) + vptranslate[0];37float vp_miny = -fabsf(vpscale[1]) + vptranslate[1];38float vp_maxy = fabsf(vpscale[1]) + vptranslate[1];3940/* Clip to the scissor if it's enabled, but still clip to the41* drawable regardless since that controls where the binner42* tries to put things.43*44* Additionally, always clip the rendering to the viewport,45* since the hardware does guardband clipping, meaning46* primitives would rasterize outside of the view volume.47*/48uint32_t minx, miny, maxx, maxy;49if (!vc4->rasterizer->base.scissor) {50minx = MAX2(vp_minx, 0);51miny = MAX2(vp_miny, 0);52maxx = MAX2(MIN2(vp_maxx, job->draw_width), minx);53maxy = MAX2(MIN2(vp_maxy, job->draw_height), miny);54} else {55minx = MAX2(vp_minx, vc4->scissor.minx);56miny = MAX2(vp_miny, vc4->scissor.miny);57maxx = MAX2(MIN2(vp_maxx, vc4->scissor.maxx), minx);58maxy = MAX2(MIN2(vp_maxy, vc4->scissor.maxy), miny);59}6061cl_emit(&job->bcl, CLIP_WINDOW, clip) {62clip.clip_window_left_pixel_coordinate = minx;63clip.clip_window_bottom_pixel_coordinate = miny;64clip.clip_window_height_in_pixels = maxy - miny;65clip.clip_window_width_in_pixels = maxx - minx;66}6768job->draw_min_x = MIN2(job->draw_min_x, minx);69job->draw_min_y = MIN2(job->draw_min_y, miny);70job->draw_max_x = MAX2(job->draw_max_x, maxx);71job->draw_max_y = MAX2(job->draw_max_y, maxy);72}7374if (vc4->dirty & (VC4_DIRTY_RASTERIZER |75VC4_DIRTY_ZSA |76VC4_DIRTY_COMPILED_FS)) {77uint8_t ez_enable_mask_out = ~0;78uint8_t rasosm_mask_out = ~0;7980struct vc4_cl_out *bcl = cl_start(&job->bcl);81/* HW-2905: If the RCL ends up doing a full-res load when82* multisampling, then early Z tracking may end up with values83* from the previous tile due to a HW bug. Disable it to84* avoid that.85*86* We should be able to skip this when the Z is cleared, but I87* was seeing bad rendering on glxgears -samples 4 even in88* that case.89*/90if (job->msaa || vc4->prog.fs->disable_early_z)91ez_enable_mask_out &= ~VC4_CONFIG_BITS_EARLY_Z;9293/* Don't set the rasterizer to oversample if we're doing our94* binning and load/stores in single-sample mode. This is for95* the samples == 1 case, where vc4 doesn't do any96* multisampling behavior.97*/98if (!job->msaa) {99rasosm_mask_out &=100~VC4_CONFIG_BITS_RASTERIZER_OVERSAMPLE_4X;101}102103cl_u8(&bcl, VC4_PACKET_CONFIGURATION_BITS);104cl_u8(&bcl,105(vc4->rasterizer->config_bits[0] |106vc4->zsa->config_bits[0]) & rasosm_mask_out);107cl_u8(&bcl,108vc4->rasterizer->config_bits[1] |109vc4->zsa->config_bits[1]);110cl_u8(&bcl,111(vc4->rasterizer->config_bits[2] |112vc4->zsa->config_bits[2]) & ez_enable_mask_out);113cl_end(&job->bcl, bcl);114}115116if (vc4->dirty & VC4_DIRTY_RASTERIZER) {117cl_emit_prepacked(&job->bcl, &vc4->rasterizer->packed);118}119120if (vc4->dirty & VC4_DIRTY_VIEWPORT) {121cl_emit(&job->bcl, CLIPPER_XY_SCALING, clip) {122clip.viewport_half_width_in_1_16th_of_pixel =123vc4->viewport.scale[0] * 16.0f;124clip.viewport_half_height_in_1_16th_of_pixel =125vc4->viewport.scale[1] * 16.0f;126}127128cl_emit(&job->bcl, CLIPPER_Z_SCALE_AND_OFFSET, clip) {129clip.viewport_z_offset_zc_to_zs =130vc4->viewport.translate[2];131clip.viewport_z_scale_zc_to_zs =132vc4->viewport.scale[2];133}134135cl_emit(&job->bcl, VIEWPORT_OFFSET, vp) {136vp.viewport_centre_x_coordinate =137vc4->viewport.translate[0];138vp.viewport_centre_y_coordinate =139vc4->viewport.translate[1];140}141}142143if (vc4->dirty & VC4_DIRTY_FLAT_SHADE_FLAGS) {144cl_emit(&job->bcl, FLAT_SHADE_FLAGS, flags) {145if (vc4->rasterizer->base.flatshade)146flags.flat_shading_flags =147vc4->prog.fs->color_inputs;148}149}150}151152153