Path: blob/21.2-virgl/src/gallium/drivers/svga/svga_draw_private.h
4570 views
/**********************************************************1* Copyright 2008-2009 VMware, Inc. All rights reserved.2*3* Permission is hereby granted, free of charge, to any person4* obtaining a copy of this software and associated documentation5* files (the "Software"), to deal in the Software without6* restriction, including without limitation the rights to use, copy,7* modify, merge, publish, distribute, sublicense, and/or sell copies8* of the Software, and to permit persons to whom the Software is9* furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23**********************************************************/2425#ifndef SVGA_DRAW_H_26#define SVGA_DRAW_H_2728#include "pipe/p_compiler.h"29#include "pipe/p_defines.h"30#include "indices/u_indices.h"31#include "util/u_prim.h"32#include "svga_context.h"33#include "svga_hw_reg.h"34#include "svga3d_shaderdefs.h"3536struct svga_context;37struct u_upload_mgr;3839/**40* Mask indicating which types of gallium primitives are actually41* handled by the svga device. Other types will be converted to42* these types by the index/translation code.43*/44static const unsigned svga_hw_prims =45((1 << PIPE_PRIM_POINTS) |46(1 << PIPE_PRIM_LINES) |47(1 << PIPE_PRIM_LINE_STRIP) |48(1 << PIPE_PRIM_TRIANGLES) |49(1 << PIPE_PRIM_TRIANGLE_STRIP) |50(1 << PIPE_PRIM_TRIANGLE_FAN) |51(1 << PIPE_PRIM_LINES_ADJACENCY) |52(1 << PIPE_PRIM_LINE_STRIP_ADJACENCY) |53(1 << PIPE_PRIM_TRIANGLES_ADJACENCY) |54(1 << PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY) |55(1 << PIPE_PRIM_PATCHES));565758/**59* Translate a gallium PIPE_PRIM_x value to an SVGA3D_PRIMITIVE_x value.60* Also, compute the number of primitives that'll be drawn given a61* vertex count.62* Note that this function doesn't have to handle PIPE_PRIM_LINE_LOOP,63* PIPE_PRIM_QUADS, PIPE_PRIM_QUAD_STRIP or PIPE_PRIM_POLYGON. We convert64* those to other types of primitives with index/translation code.65*/66static inline SVGA3dPrimitiveType67svga_translate_prim(unsigned mode, unsigned vcount, unsigned *prim_count,68ubyte vertices_per_patch)69{70switch (mode) {71case PIPE_PRIM_POINTS:72*prim_count = vcount;73return SVGA3D_PRIMITIVE_POINTLIST;7475case PIPE_PRIM_LINES:76*prim_count = vcount / 2;77return SVGA3D_PRIMITIVE_LINELIST;7879case PIPE_PRIM_LINE_STRIP:80*prim_count = vcount - 1;81return SVGA3D_PRIMITIVE_LINESTRIP;8283case PIPE_PRIM_TRIANGLES:84*prim_count = vcount / 3;85return SVGA3D_PRIMITIVE_TRIANGLELIST;8687case PIPE_PRIM_TRIANGLE_STRIP:88*prim_count = vcount - 2;89return SVGA3D_PRIMITIVE_TRIANGLESTRIP;9091case PIPE_PRIM_TRIANGLE_FAN:92*prim_count = vcount - 2;93return SVGA3D_PRIMITIVE_TRIANGLEFAN;9495case PIPE_PRIM_LINES_ADJACENCY:96*prim_count = vcount / 4;97return SVGA3D_PRIMITIVE_LINELIST_ADJ;9899case PIPE_PRIM_LINE_STRIP_ADJACENCY:100*prim_count = vcount - 3;101return SVGA3D_PRIMITIVE_LINESTRIP_ADJ;102103case PIPE_PRIM_TRIANGLES_ADJACENCY:104*prim_count = vcount / 6;105return SVGA3D_PRIMITIVE_TRIANGLELIST_ADJ;106107case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:108*prim_count = vcount / 2 - 2 ;109return SVGA3D_PRIMITIVE_TRIANGLESTRIP_ADJ;110111case PIPE_PRIM_PATCHES:112*prim_count = vcount / vertices_per_patch ;113assert(vertices_per_patch >= 1);114assert(vertices_per_patch <= 32);115return (SVGA3D_PRIMITIVE_1_CONTROL_POINT_PATCH - 1)116+ vertices_per_patch;117118default:119assert(0);120*prim_count = 0;121return 0;122}123}124125126struct index_cache {127u_generate_func generate;128unsigned gen_nr;129130/* If non-null, this buffer is filled by calling generate(nr, map(buffer))131*/132struct pipe_resource *buffer;133};134135136/** Max number of primitives per draw call */137#define QSZ SVGA3D_MAX_DRAW_PRIMITIVE_RANGES138139struct draw_cmd {140struct svga_winsys_context *swc;141142/* vertex layout info */143SVGA3dVertexDecl vdecl[SVGA3D_INPUTREG_MAX];144unsigned vdecl_count;145SVGA3dElementLayoutId vdecl_layout_id;146unsigned vdecl_buffer_index[SVGA3D_INPUTREG_MAX];147148/* vertex buffer info */149struct pipe_vertex_buffer vbufs[SVGA3D_INPUTREG_MAX];150unsigned vbuf_count;151152SVGA3dPrimitiveRange prim[QSZ];153struct pipe_resource *prim_ib[QSZ];154unsigned prim_count; /**< number of primitives for this draw */155unsigned min_index[QSZ];156unsigned max_index[QSZ];157};158159#define IDX_CACHE_MAX 8160161struct svga_hwtnl {162struct svga_context *svga;163struct u_upload_mgr *upload_ib;164165/* Additional negative index bias due to partial buffer uploads166* This is compensated for in the offset associated with all167* vertex buffers.168*/169int index_bias;170171/* Provoking vertex information (for flat shading). */172unsigned api_pv; /**< app-requested PV mode (PV_FIRST or PV_LAST) */173unsigned hw_pv; /**< device-supported PV mode (PV_FIRST or PV_LAST) */174175/* The triangle fillmode for the device (one of PIPE_POLYGON_MODE_{FILL,176* LINE,POINT}). If the polygon front mode matches the back mode,177* api_fillmode will be that mode. Otherwise, api_fillmode will be178* PIPE_POLYGON_MODE_FILL.179*/180unsigned api_fillmode;181182/* Cache the results of running a particular generate func on each183* primitive type.184*/185struct index_cache index_cache[PIPE_PRIM_MAX][IDX_CACHE_MAX];186187/* Try to build the maximal draw command packet before emitting:188*/189struct draw_cmd cmd;190};191192193194/**195* Do we need to use the gallium 'indices' helper to render unfilled196* triangles?197*/198static inline boolean199svga_need_unfilled_fallback(const struct svga_hwtnl *hwtnl,200enum pipe_prim_type prim)201{202if (u_reduced_prim(prim) != PIPE_PRIM_TRIANGLES) {203/* if we're drawing points or lines, no fallback needed */204return FALSE;205}206207if ((prim == PIPE_PRIM_QUADS ||208prim == PIPE_PRIM_QUAD_STRIP ||209prim == PIPE_PRIM_POLYGON) &&210hwtnl->api_fillmode == PIPE_POLYGON_MODE_LINE) {211/* We can't directly render quads or polygons. They're212* converted to triangles. If we let the device draw the triangle213* outlines we'll get an extra, stray lines in the interiors.214* So, to draw unfilled quads correctly, we need the fallback.215*/216return true;217}218return false;219}220221222enum pipe_error223svga_hwtnl_prim(struct svga_hwtnl *hwtnl,224const SVGA3dPrimitiveRange *range,225unsigned vcount,226unsigned min_index,227unsigned max_index,228struct pipe_resource *ib,229unsigned start_instance, unsigned instance_count,230const struct pipe_draw_indirect_info *indirect,231const struct pipe_stream_output_target *so_vertex_count);232233enum pipe_error234svga_hwtnl_simple_draw_range_elements(struct svga_hwtnl *hwtnl,235struct pipe_resource *indexBuffer,236unsigned index_size,237int index_bias,238unsigned min_index,239unsigned max_index,240enum pipe_prim_type prim,241unsigned start,242unsigned count,243unsigned start_instance,244unsigned instance_count,245ubyte vertices_per_patch);246247#endif248249250