Path: blob/21.2-virgl/src/gallium/auxiliary/draw/draw_pt_post_vs.c
4565 views
/**************************************************************************1*2* Copyright 2008 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#include "util/u_memory.h"28#include "util/u_math.h"29#include "util/u_prim.h"30#include "pipe/p_context.h"31#include "draw/draw_context.h"32#include "draw/draw_private.h"33#include "draw/draw_pt.h"34#include "draw/draw_vs.h"3536#define DO_CLIP_XY 0x137#define DO_CLIP_FULL_Z 0x238#define DO_CLIP_HALF_Z 0x439#define DO_CLIP_USER 0x840#define DO_VIEWPORT 0x1041#define DO_EDGEFLAG 0x2042#define DO_CLIP_XY_GUARD_BAND 0x40434445struct pt_post_vs {46struct draw_context *draw;4748unsigned flags;4950boolean (*run)( struct pt_post_vs *pvs,51struct draw_vertex_info *info,52const struct draw_prim_info *prim_info );53};5455static inline void56initialize_vertex_header(struct vertex_header *header)57{58header->clipmask = 0;59header->edgeflag = 1;60header->pad = 0;61header->vertex_id = UNDEFINED_VERTEX_ID;62}6364static inline float65dot4(const float *a, const float *b)66{67return (a[0]*b[0] +68a[1]*b[1] +69a[2]*b[2] +70a[3]*b[3]);71}7273#define FLAGS (0)74#define TAG(x) x##_none75#include "draw_cliptest_tmp.h"7677#define FLAGS (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_VIEWPORT)78#define TAG(x) x##_xy_fullz_viewport79#include "draw_cliptest_tmp.h"8081#define FLAGS (DO_CLIP_XY | DO_CLIP_HALF_Z | DO_VIEWPORT)82#define TAG(x) x##_xy_halfz_viewport83#include "draw_cliptest_tmp.h"8485#define FLAGS (DO_CLIP_XY_GUARD_BAND | DO_CLIP_HALF_Z | DO_VIEWPORT)86#define TAG(x) x##_xy_gb_halfz_viewport87#include "draw_cliptest_tmp.h"8889#define FLAGS (DO_CLIP_FULL_Z | DO_VIEWPORT)90#define TAG(x) x##_fullz_viewport91#include "draw_cliptest_tmp.h"9293#define FLAGS (DO_CLIP_HALF_Z | DO_VIEWPORT)94#define TAG(x) x##_halfz_viewport95#include "draw_cliptest_tmp.h"9697#define FLAGS (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_USER | DO_VIEWPORT)98#define TAG(x) x##_xy_fullz_user_viewport99#include "draw_cliptest_tmp.h"100101#define FLAGS (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_USER | DO_VIEWPORT | DO_EDGEFLAG)102#define TAG(x) x##_xy_fullz_user_viewport_edgeflag103#include "draw_cliptest_tmp.h"104105106107/* Don't want to create 64 versions of this function, so catch the108* less common ones here. This is looking like something which should109* be code-generated, perhaps appended to the end of the vertex110* shader.111*/112#define FLAGS (pvs->flags)113#define TAG(x) x##_generic114#include "draw_cliptest_tmp.h"115116117118boolean draw_pt_post_vs_run( struct pt_post_vs *pvs,119struct draw_vertex_info *info,120const struct draw_prim_info *prim_info )121{122return pvs->run( pvs, info, prim_info );123}124125126void draw_pt_post_vs_prepare( struct pt_post_vs *pvs,127boolean clip_xy,128boolean clip_z,129boolean clip_user,130boolean guard_band,131boolean bypass_viewport,132boolean clip_halfz,133boolean need_edgeflags )134{135pvs->flags = 0;136137/* This combination not currently tested/in use:138*/139if (!clip_halfz)140guard_band = FALSE;141142if (clip_xy && !guard_band) {143pvs->flags |= DO_CLIP_XY;144ASSIGN_4V( pvs->draw->plane[0], -1, 0, 0, 1 );145ASSIGN_4V( pvs->draw->plane[1], 1, 0, 0, 1 );146ASSIGN_4V( pvs->draw->plane[2], 0, -1, 0, 1 );147ASSIGN_4V( pvs->draw->plane[3], 0, 1, 0, 1 );148}149else if (clip_xy && guard_band) {150pvs->flags |= DO_CLIP_XY_GUARD_BAND;151ASSIGN_4V( pvs->draw->plane[0], -0.5, 0, 0, 1 );152ASSIGN_4V( pvs->draw->plane[1], 0.5, 0, 0, 1 );153ASSIGN_4V( pvs->draw->plane[2], 0, -0.5, 0, 1 );154ASSIGN_4V( pvs->draw->plane[3], 0, 0.5, 0, 1 );155}156157if (clip_z) {158if (clip_halfz) {159pvs->flags |= DO_CLIP_HALF_Z;160ASSIGN_4V( pvs->draw->plane[4], 0, 0, 1, 0 );161} else {162pvs->flags |= DO_CLIP_FULL_Z;163ASSIGN_4V( pvs->draw->plane[4], 0, 0, 1, 1 );164}165}166167if (clip_user)168pvs->flags |= DO_CLIP_USER;169170if (!bypass_viewport)171pvs->flags |= DO_VIEWPORT;172173if (need_edgeflags)174pvs->flags |= DO_EDGEFLAG;175176/* Now select the relevant function:177*/178switch (pvs->flags) {179case 0:180pvs->run = do_cliptest_none;181break;182183case DO_CLIP_XY | DO_CLIP_FULL_Z | DO_VIEWPORT:184pvs->run = do_cliptest_xy_fullz_viewport;185break;186187case DO_CLIP_XY | DO_CLIP_HALF_Z | DO_VIEWPORT:188pvs->run = do_cliptest_xy_halfz_viewport;189break;190191case DO_CLIP_XY_GUARD_BAND | DO_CLIP_HALF_Z | DO_VIEWPORT:192pvs->run = do_cliptest_xy_gb_halfz_viewport;193break;194195case DO_CLIP_FULL_Z | DO_VIEWPORT:196pvs->run = do_cliptest_fullz_viewport;197break;198199case DO_CLIP_HALF_Z | DO_VIEWPORT:200pvs->run = do_cliptest_halfz_viewport;201break;202203case DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_USER | DO_VIEWPORT:204pvs->run = do_cliptest_xy_fullz_user_viewport;205break;206207case (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_USER |208DO_VIEWPORT | DO_EDGEFLAG):209pvs->run = do_cliptest_xy_fullz_user_viewport_edgeflag;210break;211212default:213pvs->run = do_cliptest_generic;214break;215}216}217218219struct pt_post_vs *draw_pt_post_vs_create( struct draw_context *draw )220{221struct pt_post_vs *pvs = CALLOC_STRUCT( pt_post_vs );222if (!pvs)223return NULL;224225pvs->draw = draw;226227return pvs;228}229230void draw_pt_post_vs_destroy( struct pt_post_vs *pvs )231{232FREE(pvs);233}234235236