From 12f18ce6f1ef6719dd7c95998bf8d971aa1a0e64 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Thu, 25 Oct 2001 02:22:46 +0000 Subject: [PATCH] adding support for runtime selection of tmap funcs --- texmap/Makefile.am | 6 +-- texmap/ntmap.c | 25 +++++------- texmap/scanline.c | 99 ++++++++++++++++++++++++++++++++++++++++------ texmap/scanline.h | 19 ++++++++- texmap/texmapl.h | 9 ++++- texmap/tmappent.S | 8 ++-- texmap/tmapppro.S | 8 ++-- 7 files changed, 131 insertions(+), 43 deletions(-) diff --git a/texmap/Makefile.am b/texmap/Makefile.am index 7897e2b3..00efedbd 100644 --- a/texmap/Makefile.am +++ b/texmap/Makefile.am @@ -2,9 +2,9 @@ noinst_LIBRARIES = libtexmap.a INCLUDES = -I $(top_srcdir)/includes -DFL1_WITH_FLAT if USE_ASM -libtexmap_a_SOURCES = ntmap.c tmapflat.c +libtexmap_a_SOURCES = ntmap.c scanline.c tmapflat.c tmappent.S tmapppro.S else -libtexmap_a_SOURCES = ntmap.c tmapflat.c scanline.c +libtexmap_a_SOURCES = ntmap.c scanline.c tmapflat.c endif SUFFIXES = .asm @@ -12,7 +12,7 @@ SUFFIXES = .asm $(NASM) $(NASMFLAGS) $< -o $@ if USE_ASM -libtexmap_a_LIBADD = tmapppro.o tmap_ll.o tmap_flt.o tmap_lin.o tmapfade.o +libtexmap_a_LIBADD = tmap_flt.o tmap_lin.o tmap_ll.o tmap_per.o tmapfade.o endif EXTRA_DIST = \ diff --git a/texmap/ntmap.c b/texmap/ntmap.c index 2792a464..a934ee26 100644 --- a/texmap/ntmap.c +++ b/texmap/ntmap.c @@ -12,13 +12,16 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ /* * $Source: /cvs/cvsroot/d2x/texmap/ntmap.c,v $ - * $Revision: 1.3 $ + * $Revision: 1.4 $ * $Author: bradleyb $ - * $Date: 2001-01-31 15:18:04 $ + * $Date: 2001-10-25 02:22:46 $ * * Start of conversion to new texture mapper. * * $Log: not supported by cvs2svn $ + * Revision 1.3 2001/01/31 15:18:04 bradleyb + * Makefile and conf.h fixes + * * Revision 1.2 2001/01/31 14:04:46 bradleyb * Fix compiler warnings * @@ -144,7 +147,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: ntmap.c,v 1.3 2001-01-31 15:18:04 bradleyb Exp $"; +static char rcsid[] = "$Id: ntmap.c,v 1.4 2001-10-25 02:22:46 bradleyb Exp $"; #endif #define VESA 0 @@ -161,13 +164,11 @@ static char rcsid[] = "$Id: ntmap.c,v 1.3 2001-01-31 15:18:04 bradleyb Exp $"; #include "gr.h" #include "3d.h" #include "error.h" -#include "rle.h" #include "texmap.h" #include "texmapl.h" -#ifdef NO_ASM +#include "rle.h" #include "scanline.h" -#endif //#include "../main/textures.h" @@ -521,11 +522,7 @@ void ntmap_scanline_lighted(grs_bitmap *srcb, int y, fix xleft, fix xright, fix if (fx_xright > Window_clip_right) fx_xright = Window_clip_right; - #if (defined(NO_ASM) && !defined(ASM_PER)) || defined(FP_TMAP) - c_tmap_scanline_per_nolight(); - #else - asm_tmap_scanline_per(); - #endif + cur_tmap_scanline_per(); break; case 1: { fix mul_thing; @@ -552,11 +549,7 @@ void ntmap_scanline_lighted(grs_bitmap *srcb, int y, fix xleft, fix xright, fix if (fx_xright > Window_clip_right) fx_xright = Window_clip_right; - #if (defined(NO_ASM) && !defined(ASM_PER)) || defined(FP_TMAP) - c_tmap_scanline_per(); - #else - asm_tmap_scanline_per(); - #endif + cur_tmap_scanline_per(); break; } case 2: diff --git a/texmap/scanline.c b/texmap/scanline.c index 3aa399be..f7564a7d 100644 --- a/texmap/scanline.c +++ b/texmap/scanline.c @@ -12,13 +12,16 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ /* * $Source: /cvs/cvsroot/d2x/texmap/scanline.c,v $ - * $Revision: 1.2 $ + * $Revision: 1.3 $ * $Author: bradleyb $ - * $Date: 2001-01-31 15:18:04 $ + * $Date: 2001-10-25 02:22:46 $ * * Routines to draw the texture mapped scanlines. * * $Log: not supported by cvs2svn $ + * Revision 1.2 2001/01/31 15:18:04 bradleyb + * Makefile and conf.h fixes + * * Revision 1.1.1.1 2001/01/19 03:30:16 bradleyb * Import of d2x-0.0.8 * @@ -48,7 +51,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: scanline.c,v 1.2 2001-01-31 15:18:04 bradleyb Exp $"; +static char rcsid[] = "$Id: scanline.c,v 1.3 2001-10-25 02:22:46 bradleyb Exp $"; #endif #include @@ -81,14 +84,15 @@ void c_tmap_scanline_flat() void c_tmap_scanline_shaded() { int fade; - ubyte *dest; + ubyte *dest, tmp; int x; dest = (ubyte *)(write_buffer + fx_xleft + (bytes_per_row * fx_y) ); fade = tmap_flat_shade_value<<8; for (x= fx_xright-fx_xleft+1 ; x > 0; --x ) { - *dest++ = gr_fade_table[ fade |(*dest)]; + tmp = *dest; + *dest++ = gr_fade_table[ fade |(tmp)]; } } @@ -269,8 +273,8 @@ void c_tmap_scanline_lin() } #endif -#ifdef FP_TMAP -void c_tmap_scanline_per_nolight() +// Used for energy centers. See comments for c_tmap_scanline_per(). +void c_fp_tmap_scanline_per_nolight() { ubyte *dest; uint c; @@ -507,7 +511,7 @@ void c_tmap_scanline_per_nolight() } } } -#else + void c_tmap_scanline_per_nolight() { ubyte *dest; @@ -543,10 +547,17 @@ void c_tmap_scanline_per_nolight() } } } -#endif -#ifdef FP_TMAP -void c_tmap_scanline_per() +// This texture mapper uses floating point extensively and writes 8 pixels at once, so it likely works +// best on 64 bit RISC processors. +// WARNING: it is not endian clean. For big endian, reverse the shift counts in the unrolled loops. I +// have no means to test that, so I didn't try it. Please tell me if you get this to work on a big +// endian machine. +// If you're using an Alpha, use the Compaq compiler for this file for quite some fps more. +// Unfortunately, it won't compile the whole source, so simply compile everything, change the +// compiler to ccc, remove scanline.o and compile again. +// Please send comments/suggestions to falk.hueffner@student.uni-tuebingen.de. +void c_fp_tmap_scanline_per() { ubyte *dest; uint c; @@ -803,7 +814,7 @@ void c_tmap_scanline_per() } } -#elif 1 +#if 1 // note the unrolling loop is broken. It is never called, and uses big endian. -- FH void c_tmap_scanline_per() { @@ -961,5 +972,69 @@ void c_tmap_scanline_per() } } +#endif +void (*cur_tmap_scanline_per)(void); +void (*cur_tmap_scanline_per_nolight)(void); +void (*cur_tmap_scanline_lin)(void); +void (*cur_tmap_scanline_lin_nolight)(void); +void (*cur_tmap_scanline_flat)(void); +void (*cur_tmap_scanline_shaded)(void); + +//runtime selection of optimized tmappers. 12/07/99 Matthew Mueller +//the reason I did it this way rather than having a *tmap_funcs that then points to a c_tmap or fp_tmap struct thats already filled in, is to avoid a second pointer dereference. +void select_tmap(char *type){ + if (!type){ +#ifndef NO_ASM + select_tmap("i386"); +#else + select_tmap("c"); #endif + return; + } +#ifndef NO_ASM + if (stricmp(type,"i386")==0){ + cur_tmap_scanline_per=asm_tmap_scanline_per; + cur_tmap_scanline_per_nolight=asm_tmap_scanline_per; + cur_tmap_scanline_lin=asm_tmap_scanline_lin_lighted; + cur_tmap_scanline_lin_nolight=asm_tmap_scanline_lin; + cur_tmap_scanline_flat=asm_tmap_scanline_flat; + cur_tmap_scanline_shaded=asm_tmap_scanline_shaded; + } + else if (stricmp(type,"pent")==0){ + cur_tmap_scanline_per=asm_pent_tmap_scanline_per; + cur_tmap_scanline_per_nolight=asm_pent_tmap_scanline_per; + cur_tmap_scanline_lin=asm_tmap_scanline_lin_lighted; + cur_tmap_scanline_lin_nolight=asm_tmap_scanline_lin; + cur_tmap_scanline_flat=asm_tmap_scanline_flat; + cur_tmap_scanline_shaded=asm_tmap_scanline_shaded; + } + else if (stricmp(type,"ppro")==0){ + cur_tmap_scanline_per=asm_ppro_tmap_scanline_per; + cur_tmap_scanline_per_nolight=asm_ppro_tmap_scanline_per; + cur_tmap_scanline_lin=asm_tmap_scanline_lin_lighted; + cur_tmap_scanline_lin_nolight=asm_tmap_scanline_lin; + cur_tmap_scanline_flat=asm_tmap_scanline_flat; + cur_tmap_scanline_shaded=asm_tmap_scanline_shaded; + } + else +#endif + if (stricmp(type,"fp")==0){ + cur_tmap_scanline_per=c_fp_tmap_scanline_per; + cur_tmap_scanline_per_nolight=c_fp_tmap_scanline_per_nolight; + cur_tmap_scanline_lin=c_tmap_scanline_lin; + cur_tmap_scanline_lin_nolight=c_tmap_scanline_lin_nolight; + cur_tmap_scanline_flat=c_tmap_scanline_flat; + cur_tmap_scanline_shaded=c_tmap_scanline_shaded; + } + else { + if (stricmp(type,"c")!=0) + printf("unknown tmap requested, using c tmap\n"); + cur_tmap_scanline_per=c_tmap_scanline_per; + cur_tmap_scanline_per_nolight=c_tmap_scanline_per_nolight; + cur_tmap_scanline_lin=c_tmap_scanline_lin; + cur_tmap_scanline_lin_nolight=c_tmap_scanline_lin_nolight; + cur_tmap_scanline_flat=c_tmap_scanline_flat; + cur_tmap_scanline_shaded=c_tmap_scanline_shaded; + } +} diff --git a/texmap/scanline.h b/texmap/scanline.h index 5920575a..006b9c45 100644 --- a/texmap/scanline.h +++ b/texmap/scanline.h @@ -12,13 +12,16 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ /* * $Source: /cvs/cvsroot/d2x/texmap/scanline.h,v $ - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * $Author: bradleyb $ - * $Date: 2001-01-19 03:30:16 $ + * $Date: 2001-10-25 02:22:46 $ * * Prototypes for C versions of texture mapped scanlines. * * $Log: not supported by cvs2svn $ + * Revision 1.1.1.1 2001/01/19 03:30:16 bradleyb + * Import of d2x-0.0.8 + * * Revision 1.1.1.1 1999/06/14 22:14:10 donut * Import of d1x 1.37 source. * @@ -43,5 +46,17 @@ extern void c_tmap_scanline_lin_nolight(); extern void c_tmap_scanline_flat(); extern void c_tmap_scanline_shaded(); +//typedef struct _tmap_scanline_funcs { +extern void (*cur_tmap_scanline_per)(void); +extern void (*cur_tmap_scanline_per_nolight)(void); +extern void (*cur_tmap_scanline_lin)(void); +extern void (*cur_tmap_scanline_lin_nolight)(void); +extern void (*cur_tmap_scanline_flat)(void); +extern void (*cur_tmap_scanline_shaded)(void); +//} tmap_scanline_funcs; + +//extern tmap_scanline_funcs tmap_funcs; +void select_tmap(char *type); + #endif diff --git a/texmap/texmapl.h b/texmap/texmapl.h index 88108085..f3f000b9 100644 --- a/texmap/texmapl.h +++ b/texmap/texmapl.h @@ -12,13 +12,16 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ /* * $Source: /cvs/cvsroot/d2x/texmap/texmapl.h,v $ - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * $Author: bradleyb $ - * $Date: 2001-01-19 03:30:16 $ + * $Date: 2001-10-25 02:22:46 $ * * Local include file for texture mapper library -- NOT to be included by users. * * $Log: not supported by cvs2svn $ + * Revision 1.1.1.1 2001/01/19 03:30:16 bradleyb + * Import of d2x-0.0.8 + * * Revision 1.1.1.1 1999/06/14 22:14:11 donut * Import of d1x 1.37 source. * @@ -85,6 +88,8 @@ extern unsigned char *pixptr; // texture mapper scanline renderers extern void asm_tmap_scanline_per(void); +extern void asm_pent_tmap_scanline_per(void); +extern void asm_ppro_tmap_scanline_per(void); //extern void asm_tmap_scanline_per_doubled(void); extern void asm_tmap_scanline_lin(void); //extern void asm_tmap_scanline_lin_16(void); diff --git a/texmap/tmappent.S b/texmap/tmappent.S index 26fb144a..9c5ac6b7 100644 --- a/texmap/tmappent.S +++ b/texmap/tmappent.S @@ -170,9 +170,9 @@ .equ _fx_dl_dx, fx_dl_dx .equ _Transparency_on, Transparency_on -.globl asm_tmap_scanline_per +.globl asm_pent_tmap_scanline_per #else -.globl _asm_tmap_scanline_per +.globl _asm_pent_tmap_scanline_per #endif .extern _pixptr, _gr_fade_table, _write_buffer @@ -217,9 +217,9 @@ ctlwd: .word 0 // the pre-tweaked FPU control word // #ifdef __linux__ -asm_tmap_scanline_per: +asm_pent_tmap_scanline_per: #else -_asm_tmap_scanline_per: +_asm_pent_tmap_scanline_per: #endif // Save registers the compiler might be using. diff --git a/texmap/tmapppro.S b/texmap/tmapppro.S index 87c771d4..f7b865b7 100644 --- a/texmap/tmapppro.S +++ b/texmap/tmapppro.S @@ -160,9 +160,9 @@ .equ _fx_dl_dx, fx_dl_dx .equ _Transparency_on, Transparency_on -.globl asm_tmap_scanline_per +.globl asm_ppro_tmap_scanline_per #else -.globl _asm_tmap_scanline_per +.globl _asm_ppro_tmap_scanline_per #endif .extern _pixptr, _gr_fade_table, _write_buffer @@ -203,9 +203,9 @@ ctlwd: .long 0 // the pre-tweaked FPU control word // #ifdef __linux__ -asm_tmap_scanline_per: +asm_ppro_tmap_scanline_per: #else -_asm_tmap_scanline_per: +_asm_ppro_tmap_scanline_per: #endif // Save registers the compiler might be using. -- 2.39.2