Path: blob/21.2-virgl/src/gallium/drivers/llvmpipe/lp_rast.h
4570 views
/**************************************************************************1*2* Copyright 2009 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627/**28* The rast code is concerned with rasterization of command bins.29* Each screen tile has a bin associated with it. To render the30* scene we iterate over the tile bins and execute the commands31* in each bin.32* We'll do that with multiple threads...33*/343536#ifndef LP_RAST_H37#define LP_RAST_H3839#include "pipe/p_compiler.h"40#include "util/u_pack_color.h"41#include "lp_jit.h"424344struct lp_rasterizer;45struct lp_scene;46struct lp_fence;47struct cmd_bin;4849#define FIXED_TYPE_WIDTH 6450/** For sub-pixel positioning */51#define FIXED_ORDER 852#define FIXED_ONE (1<<FIXED_ORDER)53#define FIXED_SHIFT (FIXED_TYPE_WIDTH - 1)54/** Maximum length of an edge in a primitive in pixels.55* If the framebuffer is large we have to think about fixed-point56* integer overflow. Coordinates need ((FIXED_TYPE_WIDTH/2) - 1) bits57* to be able to fit product of two such coordinates inside58* FIXED_TYPE_WIDTH, any larger and we could overflow a59* FIXED_TYPE_WIDTH_-bit int.60*/61#define MAX_FIXED_LENGTH (1 << (((FIXED_TYPE_WIDTH/2) - 1) - FIXED_ORDER))6263#define MAX_FIXED_LENGTH32 (1 << (((32/2) - 1) - FIXED_ORDER))6465/* Rasterizer output size going to jit fs, width/height */66#define LP_RASTER_BLOCK_SIZE 46768#define LP_MAX_ACTIVE_BINNED_QUERIES 646970#define IMUL64(a, b) (((int64_t)(a)) * ((int64_t)(b)))7172struct lp_rasterizer_task;7374extern const float lp_sample_pos_4x[4][2];7576/**77* Rasterization state.78* Objects of this type are put into the shared data bin and pointed79* to by commands in the per-tile bins.80*/81struct lp_rast_state {82/* State for the shader. This also contains state which feeds into83* the fragment shader, such as blend color and alpha ref value.84*/85struct lp_jit_context jit_context;8687/* The shader itself. Probably we also need to pass a pointer to88* the tile color/z/stencil data somehow89*/90struct lp_fragment_shader_variant *variant;91};929394/**95* Coefficients necessary to run the shader at a given location.96* First coefficient is position.97* These pointers point into the bin data buffer.98*/99struct lp_rast_shader_inputs {100unsigned frontfacing:1; /** True for front-facing */101unsigned disable:1; /** Partially binned, disable this command */102unsigned opaque:1; /** Is opaque */103unsigned pad0:13; /* wasted space */104unsigned view_index:16;105unsigned stride; /* how much to advance data between a0, dadx, dady */106unsigned layer; /* the layer to render to (from gs, already clamped) */107unsigned viewport_index; /* the active viewport index (from gs, already clamped) */108109/* followed by a0, dadx, dady and planes[] */110};111112struct lp_rast_plane {113/* edge function values at minx,miny ?? */114int64_t c;115116int32_t dcdx;117int32_t dcdy;118119/* one-pixel sized trivial reject offsets for each plane */120uint32_t eo;121/*122* We rely on this struct being 64bit aligned (ideally it would be 128bit123* but that's quite the waste) and therefore on 32bit we need padding124* since otherwise (even with the 64bit number in there) it wouldn't be.125*/126uint32_t pad;127};128129/**130* Rasterization information for a triangle known to be in this bin,131* plus inputs to run the shader:132* These fields are tile- and bin-independent.133* Objects of this type are put into the lp_setup_context::data buffer.134*/135struct lp_rast_triangle {136#ifdef DEBUG137float v[3][2];138float pad0;139float pad1;140#endif141142/* inputs for the shader */143struct lp_rast_shader_inputs inputs;144/* planes are also allocated here */145};146147148struct lp_rast_clear_rb {149union util_color color_val;150unsigned cbuf;151};152153154#define GET_A0(inputs) ((float (*)[4])((inputs)+1))155#define GET_DADX(inputs) ((float (*)[4])((char *)((inputs) + 1) + (inputs)->stride))156#define GET_DADY(inputs) ((float (*)[4])((char *)((inputs) + 1) + 2 * (inputs)->stride))157#define GET_PLANES(tri) ((struct lp_rast_plane *)((char *)(&(tri)->inputs + 1) + 3 * (tri)->inputs.stride))158159160161struct lp_rasterizer *162lp_rast_create( unsigned num_threads );163164void165lp_rast_destroy( struct lp_rasterizer * );166167void168lp_rast_queue_scene( struct lp_rasterizer *rast,169struct lp_scene *scene );170171void172lp_rast_finish( struct lp_rasterizer *rast );173174175union lp_rast_cmd_arg {176const struct lp_rast_shader_inputs *shade_tile;177struct {178const struct lp_rast_triangle *tri;179unsigned plane_mask;180} triangle;181const struct lp_rast_state *set_state;182const struct lp_rast_clear_rb *clear_rb;183struct {184uint64_t value;185uint64_t mask;186} clear_zstencil;187const struct lp_rast_state *state;188struct lp_fence *fence;189struct llvmpipe_query *query_obj;190};191192193/* Cast wrappers. Hopefully these compile to noops!194*/195static inline union lp_rast_cmd_arg196lp_rast_arg_inputs( const struct lp_rast_shader_inputs *shade_tile )197{198union lp_rast_cmd_arg arg;199arg.shade_tile = shade_tile;200return arg;201}202203static inline union lp_rast_cmd_arg204lp_rast_arg_triangle( const struct lp_rast_triangle *triangle,205unsigned plane_mask)206{207union lp_rast_cmd_arg arg;208arg.triangle.tri = triangle;209arg.triangle.plane_mask = plane_mask;210return arg;211}212213/**214* Build argument for a contained triangle.215*216* All planes are enabled, so instead of the plane mask we pass the upper217* left coordinates of the a block that fully encloses the triangle.218*/219static inline union lp_rast_cmd_arg220lp_rast_arg_triangle_contained( const struct lp_rast_triangle *triangle,221unsigned x, unsigned y)222{223union lp_rast_cmd_arg arg;224arg.triangle.tri = triangle;225arg.triangle.plane_mask = x | (y << 8);226return arg;227}228229static inline union lp_rast_cmd_arg230lp_rast_arg_state( const struct lp_rast_state *state )231{232union lp_rast_cmd_arg arg;233arg.set_state = state;234return arg;235}236237static inline union lp_rast_cmd_arg238lp_rast_arg_fence( struct lp_fence *fence )239{240union lp_rast_cmd_arg arg;241arg.fence = fence;242return arg;243}244245246static inline union lp_rast_cmd_arg247lp_rast_arg_clearzs( uint64_t value, uint64_t mask )248{249union lp_rast_cmd_arg arg;250arg.clear_zstencil.value = value;251arg.clear_zstencil.mask = mask;252return arg;253}254255256static inline union lp_rast_cmd_arg257lp_rast_arg_query( struct llvmpipe_query *pq )258{259union lp_rast_cmd_arg arg;260arg.query_obj = pq;261return arg;262}263264static inline union lp_rast_cmd_arg265lp_rast_arg_null( void )266{267union lp_rast_cmd_arg arg;268arg.set_state = NULL;269return arg;270}271272273/**274* Binnable Commands.275* These get put into bins by the setup code and are called when276* the bins are executed.277*/278#define LP_RAST_OP_CLEAR_COLOR 0x0279#define LP_RAST_OP_CLEAR_ZSTENCIL 0x1280#define LP_RAST_OP_TRIANGLE_1 0x2281#define LP_RAST_OP_TRIANGLE_2 0x3282#define LP_RAST_OP_TRIANGLE_3 0x4283#define LP_RAST_OP_TRIANGLE_4 0x5284#define LP_RAST_OP_TRIANGLE_5 0x6285#define LP_RAST_OP_TRIANGLE_6 0x7286#define LP_RAST_OP_TRIANGLE_7 0x8287#define LP_RAST_OP_TRIANGLE_8 0x9288#define LP_RAST_OP_TRIANGLE_3_4 0xa289#define LP_RAST_OP_TRIANGLE_3_16 0xb290#define LP_RAST_OP_TRIANGLE_4_16 0xc291#define LP_RAST_OP_SHADE_TILE 0xd292#define LP_RAST_OP_SHADE_TILE_OPAQUE 0xe293#define LP_RAST_OP_BEGIN_QUERY 0xf294#define LP_RAST_OP_END_QUERY 0x10295#define LP_RAST_OP_SET_STATE 0x11296#define LP_RAST_OP_TRIANGLE_32_1 0x12297#define LP_RAST_OP_TRIANGLE_32_2 0x13298#define LP_RAST_OP_TRIANGLE_32_3 0x14299#define LP_RAST_OP_TRIANGLE_32_4 0x15300#define LP_RAST_OP_TRIANGLE_32_5 0x16301#define LP_RAST_OP_TRIANGLE_32_6 0x17302#define LP_RAST_OP_TRIANGLE_32_7 0x18303#define LP_RAST_OP_TRIANGLE_32_8 0x19304#define LP_RAST_OP_TRIANGLE_32_3_4 0x1a305#define LP_RAST_OP_TRIANGLE_32_3_16 0x1b306#define LP_RAST_OP_TRIANGLE_32_4_16 0x1c307308#define LP_RAST_OP_MS_TRIANGLE_1 0x1d309#define LP_RAST_OP_MS_TRIANGLE_2 0x1e310#define LP_RAST_OP_MS_TRIANGLE_3 0x1f311#define LP_RAST_OP_MS_TRIANGLE_4 0x20312#define LP_RAST_OP_MS_TRIANGLE_5 0x21313#define LP_RAST_OP_MS_TRIANGLE_6 0x22314#define LP_RAST_OP_MS_TRIANGLE_7 0x23315#define LP_RAST_OP_MS_TRIANGLE_8 0x24316#define LP_RAST_OP_MS_TRIANGLE_3_4 0x25317#define LP_RAST_OP_MS_TRIANGLE_3_16 0x26318#define LP_RAST_OP_MS_TRIANGLE_4_16 0x27319#define LP_RAST_OP_MAX 0x28320#define LP_RAST_OP_MASK 0xff321322void323lp_debug_bins( struct lp_scene *scene );324void325lp_debug_draw_bins_by_cmd_length( struct lp_scene *scene );326void327lp_debug_draw_bins_by_coverage( struct lp_scene *scene );328329330#endif331332333