diff options
| author | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:31:46 -0800 |
|---|---|---|
| committer | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:46:31 -0800 |
| commit | f56bb35301836e56582a575a75864392a0177875 (patch) | |
| tree | de61ddd39de3e7df52759711950b4c288592f0dc /mp/src/devtools | |
| parent | Mark some more files as text. (diff) | |
| download | source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.tar.xz source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.zip | |
Fix line endings. WHAMMY.
Diffstat (limited to 'mp/src/devtools')
| -rw-r--r-- | mp/src/devtools/bin/buildshaderlist.pl | 42 | ||||
| -rw-r--r-- | mp/src/devtools/bin/checkshaderchecksums.pl | 232 | ||||
| -rw-r--r-- | mp/src/devtools/bin/copyshaderincfiles.pl | 150 | ||||
| -rw-r--r-- | mp/src/devtools/bin/copyshaders.pl | 344 | ||||
| -rw-r--r-- | mp/src/devtools/bin/fix_particle_operator_names.pl | 220 | ||||
| -rw-r--r-- | mp/src/devtools/bin/fxc_prep.pl | 1898 | ||||
| -rwxr-xr-x | mp/src/devtools/bin/osx32/xcode_ccache_wrapper | 6 | ||||
| -rw-r--r-- | mp/src/devtools/bin/psh_prep.pl | 666 | ||||
| -rw-r--r-- | mp/src/devtools/bin/shaderinfo.pl | 72 | ||||
| -rw-r--r-- | mp/src/devtools/bin/splitdiff3.pl | 108 | ||||
| -rw-r--r-- | mp/src/devtools/bin/uniqifylist.pl | 12 | ||||
| -rw-r--r-- | mp/src/devtools/bin/updateshaders.pl | 610 | ||||
| -rw-r--r-- | mp/src/devtools/bin/valve_perl_helpers.pl | 1116 | ||||
| -rw-r--r-- | mp/src/devtools/bin/vsh_prep.pl | 2212 |
14 files changed, 3844 insertions, 3844 deletions
diff --git a/mp/src/devtools/bin/buildshaderlist.pl b/mp/src/devtools/bin/buildshaderlist.pl index 57790ace..98a4051f 100644 --- a/mp/src/devtools/bin/buildshaderlist.pl +++ b/mp/src/devtools/bin/buildshaderlist.pl @@ -1,22 +1,22 @@ -use File::DosGlob;
-@ARGV = map {
- my @g = File::DosGlob::glob($_) if /[*?]/;
- @g ? @g : $_;
- } @ARGV;
-
-open FILE, ">__tmpshaderlist.txt";
-
-foreach $arg (@ARGV)
-{
- if( $arg =~ m/\.fxc$/i || $arg =~ m/\.vsh$/i || $arg =~ m/\.psh$/i )
- {
- print $arg . "\n";
- print FILE $arg . "\n";
- }
-}
-
-close FILE;
-
-system "buildshaders.bat __tmpshaderlist";
-
+use File::DosGlob; +@ARGV = map { + my @g = File::DosGlob::glob($_) if /[*?]/; + @g ? @g : $_; + } @ARGV; + +open FILE, ">__tmpshaderlist.txt"; + +foreach $arg (@ARGV) +{ + if( $arg =~ m/\.fxc$/i || $arg =~ m/\.vsh$/i || $arg =~ m/\.psh$/i ) + { + print $arg . "\n"; + print FILE $arg . "\n"; + } +} + +close FILE; + +system "buildshaders.bat __tmpshaderlist"; + unlink "__tmpshaderlist.txt";
\ No newline at end of file diff --git a/mp/src/devtools/bin/checkshaderchecksums.pl b/mp/src/devtools/bin/checkshaderchecksums.pl index e41509f2..26841cbe 100644 --- a/mp/src/devtools/bin/checkshaderchecksums.pl +++ b/mp/src/devtools/bin/checkshaderchecksums.pl @@ -1,116 +1,116 @@ -use String::CRC32;
-BEGIN {use File::Basename; push @INC, dirname($0); }
-require "valve_perl_helpers.pl";
-
-sub GetShaderType
-{
- my $shadername = shift;
- my $shadertype;
- if( $shadername =~ m/\.vsh/i )
- {
- $shadertype = "vsh";
- }
- elsif( $shadername =~ m/\.psh/i )
- {
- $shadertype = "psh";
- }
- elsif( $shadername =~ m/\.fxc/i )
- {
- $shadertype = "fxc";
- }
- else
- {
- die;
- }
- return $shadertype;
-}
-
-sub GetShaderSrc
-{
- my $shadername = shift;
- if ( $shadername =~ m/^(.*)-----/i )
- {
- return $1;
- }
- else
- {
- return $shadername;
- }
-}
-
-sub GetShaderType
-{
- my $shadername = shift;
- my $shadertype;
- if( $shadername =~ m/\.vsh/i )
- {
- $shadertype = "vsh";
- }
- elsif( $shadername =~ m/\.psh/i )
- {
- $shadertype = "psh";
- }
- elsif( $shadername =~ m/\.fxc/i )
- {
- $shadertype = "fxc";
- }
- else
- {
- die;
- }
- return $shadertype;
-}
-
-sub GetShaderBase
-{
- my $shadername = shift;
- if ( $shadername =~ m/-----(.*)$/i )
- {
- return $1;
- }
- else
- {
- my $shadertype = &GetShaderType( $shadername );
- $shadername =~ s/\.$shadertype//i;
- return $shadername;
- }
-}
-
-$g_x360 = 0;
-$g_vcsext = ".vcs";
-
-while( 1 )
-{
- $inputbase = shift;
-
- if( $inputbase =~ m/-x360/ )
- {
- $g_x360 = 1;
- $g_vcsext = ".360.vcs";
- }
- else
- {
- last;
- }
-}
-
-# rip the txt off the end if it's there.
-$inputbase =~ s/\.txt//i;
-
-my @srcfiles = &LoadShaderListFile( $inputbase );
-
-foreach $srcfile ( @srcfiles )
-{
- my $shadertype = &GetShaderType( $srcfile );
- my $shaderbase = &GetShaderBase( $srcfile );
- my $shadersrc = &GetShaderSrc( $srcfile );
- my $vcsFileName = "..\\..\\..\\game\\hl2\\shaders\\$shadertype\\$shaderbase" . $g_vcsext;
-# print "shadersrc: $shadersrc vcsFileName: $vcsFileName\n";
-
- if( $g_x360 && ( $shaderbase =~ m/_ps20$/i ) )
- {
- next; # skip _ps20 files for 360
- }
-
- &CheckCRCAgainstTarget( $shadersrc, $vcsFileName, 1 );
-}
+use String::CRC32; +BEGIN {use File::Basename; push @INC, dirname($0); } +require "valve_perl_helpers.pl"; + +sub GetShaderType +{ + my $shadername = shift; + my $shadertype; + if( $shadername =~ m/\.vsh/i ) + { + $shadertype = "vsh"; + } + elsif( $shadername =~ m/\.psh/i ) + { + $shadertype = "psh"; + } + elsif( $shadername =~ m/\.fxc/i ) + { + $shadertype = "fxc"; + } + else + { + die; + } + return $shadertype; +} + +sub GetShaderSrc +{ + my $shadername = shift; + if ( $shadername =~ m/^(.*)-----/i ) + { + return $1; + } + else + { + return $shadername; + } +} + +sub GetShaderType +{ + my $shadername = shift; + my $shadertype; + if( $shadername =~ m/\.vsh/i ) + { + $shadertype = "vsh"; + } + elsif( $shadername =~ m/\.psh/i ) + { + $shadertype = "psh"; + } + elsif( $shadername =~ m/\.fxc/i ) + { + $shadertype = "fxc"; + } + else + { + die; + } + return $shadertype; +} + +sub GetShaderBase +{ + my $shadername = shift; + if ( $shadername =~ m/-----(.*)$/i ) + { + return $1; + } + else + { + my $shadertype = &GetShaderType( $shadername ); + $shadername =~ s/\.$shadertype//i; + return $shadername; + } +} + +$g_x360 = 0; +$g_vcsext = ".vcs"; + +while( 1 ) +{ + $inputbase = shift; + + if( $inputbase =~ m/-x360/ ) + { + $g_x360 = 1; + $g_vcsext = ".360.vcs"; + } + else + { + last; + } +} + +# rip the txt off the end if it's there. +$inputbase =~ s/\.txt//i; + +my @srcfiles = &LoadShaderListFile( $inputbase ); + +foreach $srcfile ( @srcfiles ) +{ + my $shadertype = &GetShaderType( $srcfile ); + my $shaderbase = &GetShaderBase( $srcfile ); + my $shadersrc = &GetShaderSrc( $srcfile ); + my $vcsFileName = "..\\..\\..\\game\\hl2\\shaders\\$shadertype\\$shaderbase" . $g_vcsext; +# print "shadersrc: $shadersrc vcsFileName: $vcsFileName\n"; + + if( $g_x360 && ( $shaderbase =~ m/_ps20$/i ) ) + { + next; # skip _ps20 files for 360 + } + + &CheckCRCAgainstTarget( $shadersrc, $vcsFileName, 1 ); +} diff --git a/mp/src/devtools/bin/copyshaderincfiles.pl b/mp/src/devtools/bin/copyshaderincfiles.pl index 21702d8f..c3419e62 100644 --- a/mp/src/devtools/bin/copyshaderincfiles.pl +++ b/mp/src/devtools/bin/copyshaderincfiles.pl @@ -1,75 +1,75 @@ -BEGIN {use File::Basename; push @INC, dirname($0); }
-require "valve_perl_helpers.pl";
-use Cwd;
-use String::CRC32;
-
-my $txtfilename = shift;
-my $arg = shift;
-
-my $is360 = 0;
-my $platformextension = "";
-if( $arg =~ m/-x360/i )
-{
- $is360 = 1;
- $platformextension = ".360";
-}
-
-open TXTFILE, "<$txtfilename";
-
-my $src;
-my $dst;
-while( $src = <TXTFILE> )
-{
- # get rid of comments
- $src =~ s,//.*,,g;
-
- # skip blank lines
- if( $src =~ m/^\s*$/ )
- {
- next;
- }
-
- # Get rid of newlines.
- $src =~ s/\n//g;
-
- # Save off the shader source filename.
- my $dst = $src;
-
- $dst =~ s/_tmp//gi;
-
- # Does the dst exist?
- my $dstexists = -e $dst;
- my $srcexists = -e $src;
- # What are the time stamps for the src and dst?
- my $srcmodtime = ( stat $src )[9];
- my $dstmodtime = ( stat $dst )[9];
-
- # Open for edit or add if different than what is in perforce already.
- if( !$dstexists || ( $srcmodtime != $dstmodtime ) )
- {
- # Make the target writable if it exists
- if( $dstexists )
- {
- MakeFileWritable( $dst );
- }
-
- my $dir = $dst;
- $dir =~ s,([^/\\]*$),,; # rip the filename off the end
- my $filename = $1;
-
- # create the target directory if it doesn't exist
- if( !$dstexists )
- {
- &MakeDirHier( $dir, 0777 );
- }
-
- # copy the file to its targets. . . we want to see STDERR here if there is an error.
- my $cmd = "copy $src $dst > nul";
-# print STDERR "$cmd\n";
- system $cmd;
-
- MakeFileReadOnly( $dst );
- }
-}
-
-close TXTFILE;
+BEGIN {use File::Basename; push @INC, dirname($0); } +require "valve_perl_helpers.pl"; +use Cwd; +use String::CRC32; + +my $txtfilename = shift; +my $arg = shift; + +my $is360 = 0; +my $platformextension = ""; +if( $arg =~ m/-x360/i ) +{ + $is360 = 1; + $platformextension = ".360"; +} + +open TXTFILE, "<$txtfilename"; + +my $src; +my $dst; +while( $src = <TXTFILE> ) +{ + # get rid of comments + $src =~ s,//.*,,g; + + # skip blank lines + if( $src =~ m/^\s*$/ ) + { + next; + } + + # Get rid of newlines. + $src =~ s/\n//g; + + # Save off the shader source filename. + my $dst = $src; + + $dst =~ s/_tmp//gi; + + # Does the dst exist? + my $dstexists = -e $dst; + my $srcexists = -e $src; + # What are the time stamps for the src and dst? + my $srcmodtime = ( stat $src )[9]; + my $dstmodtime = ( stat $dst )[9]; + + # Open for edit or add if different than what is in perforce already. + if( !$dstexists || ( $srcmodtime != $dstmodtime ) ) + { + # Make the target writable if it exists + if( $dstexists ) + { + MakeFileWritable( $dst ); + } + + my $dir = $dst; + $dir =~ s,([^/\\]*$),,; # rip the filename off the end + my $filename = $1; + + # create the target directory if it doesn't exist + if( !$dstexists ) + { + &MakeDirHier( $dir, 0777 ); + } + + # copy the file to its targets. . . we want to see STDERR here if there is an error. + my $cmd = "copy $src $dst > nul"; +# print STDERR "$cmd\n"; + system $cmd; + + MakeFileReadOnly( $dst ); + } +} + +close TXTFILE; diff --git a/mp/src/devtools/bin/copyshaders.pl b/mp/src/devtools/bin/copyshaders.pl index 53839298..cb849a84 100644 --- a/mp/src/devtools/bin/copyshaders.pl +++ b/mp/src/devtools/bin/copyshaders.pl @@ -1,172 +1,172 @@ -BEGIN {use File::Basename; push @INC, dirname($0); }
-require "valve_perl_helpers.pl";
-use Cwd;
-use String::CRC32;
-
-sub ReadInputFileWithIncludes
-{
- local( $filename ) = shift;
-
- local( *INPUT );
- local( $output );
-
- open INPUT, "<$filename" || die;
-
- local( $line );
- local( $linenum ) = 1;
- while( $line = <INPUT> )
- {
- if( $line =~ m/\#include\s+\"(.*)\"/i )
- {
- $output.= ReadInputFileWithIncludes( $1 );
- }
- else
- {
- $output .= $line;
- }
- }
-
- close INPUT;
- return $output;
-}
-
-sub PatchCRC
-{
- my $filename = shift;
- my $crc = shift;
-# print STDERR "PatchCRC( $filename, $crc )\n";
- local( *FP );
- open FP, "+<$filename" || die;
- binmode( FP );
- seek FP, 6 * 4, 0;
- my $uInt = "I";
- if( $filename =~ m/360/ )
- {
- $uInt = "N";
- }
- print FP pack $uInt, $crc;
- close FP;
-}
-
-my $txtfilename = shift;
-my $arg = shift;
-
-my $is360 = 0;
-my $platformextension = "";
-if( $arg =~ m/-x360/i )
-{
- $is360 = 1;
- $platformextension = ".360";
-}
-
-# Get the changelist number for the Shader Auto Checkout changelist. Will create the changelist if it doesn't exist.
-my $changelistnumber = `valve_p4_create_changelist.cmd ..\\..\\..\\game\\hl2\\shaders \"Shader Auto Checkout VCS\"`;
-# Get rid of the newline
-$changelistnumber =~ s/\n//g;
-
-my $changelistarg = "";
-if( $changelistnumber != 0 )
-{
- $changelistarg = "-c $changelistnumber"
-}
-
-open TXTFILE, "<$txtfilename";
-
-my $src;
-my $dst;
-while( $src = <TXTFILE> )
-{
- # get rid of comments
- $src =~ s,//.*,,g;
-
- # skip blank lines
- if( $src =~ m/^\s*$/ )
- {
- next;
- }
-
- # Get rid of newlines.
- $src =~ s/\n//g;
-
- # Save off the shader source filename.
- my $shadersrcfilename = $src;
- $shadersrcfilename =~ s/-----.*$//;
- # use only target basename.
- $src =~ s/^.*-----//;
-
- # where the binary vcs file is
- my $spath = "";
-
- if ( $shadersrcfilename =~ m@\.fxc@i )
- {
- $spath = "shaders\\fxc\\";
- }
- if ( $shadersrcfilename =~ m@\.vsh@i )
- {
- $spath = "shaders\\vsh\\";
- }
- if ( $shadersrcfilename =~ m@\.psh@i )
- {
- $spath = "shaders\\psh\\";
- }
-
- # make the source have path and extension
- $src = $spath . $src . $platformextension . ".vcs";
-
- # build the dest filename.
- $dst = $src;
-
- $dst =~ s/shaders\\/..\\..\\..\\game\\hl2\\shaders\\/i;
-
- # Does the dst exist?
- my $dstexists = -e $dst;
- my $srcexists = -e $src;
- # What are the time stamps for the src and dst?
- my $srcmodtime = ( stat $src )[9];
- my $dstmodtime = ( stat $dst )[9];
-
- # Write $dst to a file so that we can do perforce stuff to it later.
- local( *VCSLIST );
- open VCSLIST, ">>vcslist.txt" || die;
- print VCSLIST $dst . "\n";
- close VCSLIST;
-
- # Open for edit or add if different than what is in perforce already.
- if( !$dstexists || ( $srcmodtime != $dstmodtime ) )
- {
- if ( $srcexists && $shadersrcfilename =~ m@\.fxc@i )
- {
- # Get the CRC for the source file.
- my $srccode = ReadInputFileWithIncludes( $shadersrcfilename );
- my $crc = crc32( $srccode );
-
- # Patch the source VCS file with the CRC32 of the source code used to build that file.
- PatchCRC( $src, $crc );
- }
-
- # Make the target vcs writable if it exists
- if( $dstexists )
- {
- MakeFileWritable( $dst );
- }
-
- my $dir = $dst;
- $dir =~ s,([^/\\]*$),,; # rip the filename off the end
- my $filename = $1;
-
- # create the target directory if it doesn't exist
- if( !$dstexists )
- {
- &MakeDirHier( $dir, 0777 );
- }
-
- # copy the file to its targets. . . we want to see STDERR here if there is an error.
- my $cmd = "copy $src $dst > nul";
-# print STDERR "$cmd\n";
- system $cmd;
-
- MakeFileReadOnly( $dst );
- }
-}
-
-close TXTFILE;
+BEGIN {use File::Basename; push @INC, dirname($0); } +require "valve_perl_helpers.pl"; +use Cwd; +use String::CRC32; + +sub ReadInputFileWithIncludes +{ + local( $filename ) = shift; + + local( *INPUT ); + local( $output ); + + open INPUT, "<$filename" || die; + + local( $line ); + local( $linenum ) = 1; + while( $line = <INPUT> ) + { + if( $line =~ m/\#include\s+\"(.*)\"/i ) + { + $output.= ReadInputFileWithIncludes( $1 ); + } + else + { + $output .= $line; + } + } + + close INPUT; + return $output; +} + +sub PatchCRC +{ + my $filename = shift; + my $crc = shift; +# print STDERR "PatchCRC( $filename, $crc )\n"; + local( *FP ); + open FP, "+<$filename" || die; + binmode( FP ); + seek FP, 6 * 4, 0; + my $uInt = "I"; + if( $filename =~ m/360/ ) + { + $uInt = "N"; + } + print FP pack $uInt, $crc; + close FP; +} + +my $txtfilename = shift; +my $arg = shift; + +my $is360 = 0; +my $platformextension = ""; +if( $arg =~ m/-x360/i ) +{ + $is360 = 1; + $platformextension = ".360"; +} + +# Get the changelist number for the Shader Auto Checkout changelist. Will create the changelist if it doesn't exist. +my $changelistnumber = `valve_p4_create_changelist.cmd ..\\..\\..\\game\\hl2\\shaders \"Shader Auto Checkout VCS\"`; +# Get rid of the newline +$changelistnumber =~ s/\n//g; + +my $changelistarg = ""; +if( $changelistnumber != 0 ) +{ + $changelistarg = "-c $changelistnumber" +} + +open TXTFILE, "<$txtfilename"; + +my $src; +my $dst; +while( $src = <TXTFILE> ) +{ + # get rid of comments + $src =~ s,//.*,,g; + + # skip blank lines + if( $src =~ m/^\s*$/ ) + { + next; + } + + # Get rid of newlines. + $src =~ s/\n//g; + + # Save off the shader source filename. + my $shadersrcfilename = $src; + $shadersrcfilename =~ s/-----.*$//; + # use only target basename. + $src =~ s/^.*-----//; + + # where the binary vcs file is + my $spath = ""; + + if ( $shadersrcfilename =~ m@\.fxc@i ) + { + $spath = "shaders\\fxc\\"; + } + if ( $shadersrcfilename =~ m@\.vsh@i ) + { + $spath = "shaders\\vsh\\"; + } + if ( $shadersrcfilename =~ m@\.psh@i ) + { + $spath = "shaders\\psh\\"; + } + + # make the source have path and extension + $src = $spath . $src . $platformextension . ".vcs"; + + # build the dest filename. + $dst = $src; + + $dst =~ s/shaders\\/..\\..\\..\\game\\hl2\\shaders\\/i; + + # Does the dst exist? + my $dstexists = -e $dst; + my $srcexists = -e $src; + # What are the time stamps for the src and dst? + my $srcmodtime = ( stat $src )[9]; + my $dstmodtime = ( stat $dst )[9]; + + # Write $dst to a file so that we can do perforce stuff to it later. + local( *VCSLIST ); + open VCSLIST, ">>vcslist.txt" || die; + print VCSLIST $dst . "\n"; + close VCSLIST; + + # Open for edit or add if different than what is in perforce already. + if( !$dstexists || ( $srcmodtime != $dstmodtime ) ) + { + if ( $srcexists && $shadersrcfilename =~ m@\.fxc@i ) + { + # Get the CRC for the source file. + my $srccode = ReadInputFileWithIncludes( $shadersrcfilename ); + my $crc = crc32( $srccode ); + + # Patch the source VCS file with the CRC32 of the source code used to build that file. + PatchCRC( $src, $crc ); + } + + # Make the target vcs writable if it exists + if( $dstexists ) + { + MakeFileWritable( $dst ); + } + + my $dir = $dst; + $dir =~ s,([^/\\]*$),,; # rip the filename off the end + my $filename = $1; + + # create the target directory if it doesn't exist + if( !$dstexists ) + { + &MakeDirHier( $dir, 0777 ); + } + + # copy the file to its targets. . . we want to see STDERR here if there is an error. + my $cmd = "copy $src $dst > nul"; +# print STDERR "$cmd\n"; + system $cmd; + + MakeFileReadOnly( $dst ); + } +} + +close TXTFILE; diff --git a/mp/src/devtools/bin/fix_particle_operator_names.pl b/mp/src/devtools/bin/fix_particle_operator_names.pl index 86fd0f0f..c0f5ee06 100644 --- a/mp/src/devtools/bin/fix_particle_operator_names.pl +++ b/mp/src/devtools/bin/fix_particle_operator_names.pl @@ -1,110 +1,110 @@ -#!perl
-use File::Find;
-
-&BuildRemapTable;
-
-find(\&convert, "." );
-
-
-sub convert
- {
- return unless (/\.pcf$/i);
- return if (/^tmp\.pcf$/i);
- return if (/^tmp2\.pcf$/i);
- return if (/360\.pcf$/i);
- print STDERR "process ", $File::Find::name," ($_) dir=",`cd`," \n";
- my $fname=$_;
- print `p4 edit $fname`;
- print `dmxconvert -i $_ -o tmp.pcf -oe keyvalues2`;
- open(TMP, "tmp.pcf" ) || return;
- open(OUT, ">tmp2.pcf" ) || die;
- while(<TMP>)
- {
- s/[\n\r]//g;
- if ( (/^(\s*\"functionName\"\s*\"string\"\s*\")(.*)\"(.*)$/) &&
- length($map{$2}) )
- {
- $_=$1.$map{$2}.'"'.$3;
- }
- if ( (/^(\s*\"name\"\s*\"string\"\s*\")(.*)\"(.*)$/) &&
- length($map{$2}) )
- {
- $_=$1.$map{$2}.'"'.$3;
- }
- print OUT "$_\n";
- }
- close OUT;
- close TMP;
- print `dmxconvert -i tmp2.pcf -o $fname -ie keyvalues2 -oe binary`;
- unlink "tmp.pcf";
- unlink "tmp2.pcf";
-}
-
-
-
-
-
-
-
-
-
-
-
-
-sub BuildRemapTable
-{
- $map{"alpha_fade"}= "Alpha Fade and Decay";
- $map{"alpha_fade_in_random"}= "Alpha Fade In Random";
- $map{"alpha_fade_out_random"}= "Alpha Fade Out Random";
- $map{"basic_movement"}= "Movement Basic";
- $map{"color_fade"}= "Color Fade";
- $map{"controlpoint_light"}= "Color Light From Control Point";
- $map{"Dampen Movement Relative to Control Point"}= "Movement Dampen Relative to Control Point";
- $map{"Distance Between Control Points Scale"}= "Remap Distance Between Two Control Points to Scalar";
- $map{"Distance to Control Points Scale"}= "Remap Distance to Control Point to Scalar";
- $map{"lifespan_decay"}= "Lifespan Decay";
- $map{"lock to bone"}= "Movement Lock to Bone";
- $map{"postion_lock_to_controlpoint"}= "Movement Lock to Control Point";
- $map{"maintain position along path"}= "Movement Maintain Position Along Path";
- $map{"Match Particle Velocities"}= "Movement Match Particle Velocities";
- $map{"Max Velocity"}= "Movement Max Velocity";
- $map{"noise"}= "Noise Scalar";
- $map{"vector noise"}= "Noise Vector";
- $map{"oscillate_scalar"}= "Oscillate Scalar";
- $map{"oscillate_vector"}= "Oscillate Vector";
- $map{"Orient Rotation to 2D Direction"}= "Rotation Orient to 2D Direction";
- $map{"radius_scale"}= "Radius Scale";
- $map{"Random Cull"}= "Cull Random";
- $map{"remap_scalar"}= "Remap Scalar";
- $map{"rotation_movement"}= "Rotation Basic";
- $map{"rotation_spin"}= "Rotation Spin Roll";
- $map{"rotation_spin yaw"}= "Rotation Spin Yaw";
- $map{"alpha_random"}= "Alpha Random";
- $map{"color_random"}= "Color Random";
- $map{"create from parent particles"}= "Position From Parent Particles";
- $map{"Create In Hierarchy"}= "Position In CP Hierarchy";
- $map{"random position along path"}= "Position Along Path Random";
- $map{"random position on model"}= "Position on Model Random";
- $map{"sequential position along path"}= "Position Along Path Sequential";
- $map{"position_offset_random"}= "Position Modify Offset Random";
- $map{"position_warp_random"}= "Position Modify Warp Random";
- $map{"position_within_box"}= "Position Within Box Random";
- $map{"position_within_sphere"}= "Position Within Sphere Random";
- $map{"Inherit Velocity"}= "Velocity Inherit from Control Point";
- $map{"Initial Repulsion Velocity"}= "Velocity Repulse from World";
- $map{"Initial Velocity Noise"}= "Velocity Noise";
- $map{"Initial Scalar Noise"}= "Remap Noise to Scalar";
- $map{"Lifespan from distance to world"}= "Lifetime from Time to Impact";
- $map{"Pre-Age Noise"}= "Lifetime Pre-Age Noise";
- $map{"lifetime_random"}= "Lifetime Random";
- $map{"radius_random"}= "Radius Random";
- $map{"random yaw"}= "Rotation Yaw Random";
- $map{"Randomly Flip Yaw"}= "Rotation Yaw Flip Random";
- $map{"rotation_random"}= "Rotation Random";
- $map{"rotation_speed_random"}= "Rotation Speed Random";
- $map{"sequence_random"}= "Sequence Random";
- $map{"second_sequence_random"}= "Sequence Two Random";
- $map{"trail_length_random"}= "Trail Length Random";
- $map{"velocity_random"}= "Velocity Random";
-}
-
+#!perl +use File::Find; + +&BuildRemapTable; + +find(\&convert, "." ); + + +sub convert + { + return unless (/\.pcf$/i); + return if (/^tmp\.pcf$/i); + return if (/^tmp2\.pcf$/i); + return if (/360\.pcf$/i); + print STDERR "process ", $File::Find::name," ($_) dir=",`cd`," \n"; + my $fname=$_; + print `p4 edit $fname`; + print `dmxconvert -i $_ -o tmp.pcf -oe keyvalues2`; + open(TMP, "tmp.pcf" ) || return; + open(OUT, ">tmp2.pcf" ) || die; + while(<TMP>) + { + s/[\n\r]//g; + if ( (/^(\s*\"functionName\"\s*\"string\"\s*\")(.*)\"(.*)$/) && + length($map{$2}) ) + { + $_=$1.$map{$2}.'"'.$3; + } + if ( (/^(\s*\"name\"\s*\"string\"\s*\")(.*)\"(.*)$/) && + length($map{$2}) ) + { + $_=$1.$map{$2}.'"'.$3; + } + print OUT "$_\n"; + } + close OUT; + close TMP; + print `dmxconvert -i tmp2.pcf -o $fname -ie keyvalues2 -oe binary`; + unlink "tmp.pcf"; + unlink "tmp2.pcf"; +} + + + + + + + + + + + + +sub BuildRemapTable +{ + $map{"alpha_fade"}= "Alpha Fade and Decay"; + $map{"alpha_fade_in_random"}= "Alpha Fade In Random"; + $map{"alpha_fade_out_random"}= "Alpha Fade Out Random"; + $map{"basic_movement"}= "Movement Basic"; + $map{"color_fade"}= "Color Fade"; + $map{"controlpoint_light"}= "Color Light From Control Point"; + $map{"Dampen Movement Relative to Control Point"}= "Movement Dampen Relative to Control Point"; + $map{"Distance Between Control Points Scale"}= "Remap Distance Between Two Control Points to Scalar"; + $map{"Distance to Control Points Scale"}= "Remap Distance to Control Point to Scalar"; + $map{"lifespan_decay"}= "Lifespan Decay"; + $map{"lock to bone"}= "Movement Lock to Bone"; + $map{"postion_lock_to_controlpoint"}= "Movement Lock to Control Point"; + $map{"maintain position along path"}= "Movement Maintain Position Along Path"; + $map{"Match Particle Velocities"}= "Movement Match Particle Velocities"; + $map{"Max Velocity"}= "Movement Max Velocity"; + $map{"noise"}= "Noise Scalar"; + $map{"vector noise"}= "Noise Vector"; + $map{"oscillate_scalar"}= "Oscillate Scalar"; + $map{"oscillate_vector"}= "Oscillate Vector"; + $map{"Orient Rotation to 2D Direction"}= "Rotation Orient to 2D Direction"; + $map{"radius_scale"}= "Radius Scale"; + $map{"Random Cull"}= "Cull Random"; + $map{"remap_scalar"}= "Remap Scalar"; + $map{"rotation_movement"}= "Rotation Basic"; + $map{"rotation_spin"}= "Rotation Spin Roll"; + $map{"rotation_spin yaw"}= "Rotation Spin Yaw"; + $map{"alpha_random"}= "Alpha Random"; + $map{"color_random"}= "Color Random"; + $map{"create from parent particles"}= "Position From Parent Particles"; + $map{"Create In Hierarchy"}= "Position In CP Hierarchy"; + $map{"random position along path"}= "Position Along Path Random"; + $map{"random position on model"}= "Position on Model Random"; + $map{"sequential position along path"}= "Position Along Path Sequential"; + $map{"position_offset_random"}= "Position Modify Offset Random"; + $map{"position_warp_random"}= "Position Modify Warp Random"; + $map{"position_within_box"}= "Position Within Box Random"; + $map{"position_within_sphere"}= "Position Within Sphere Random"; + $map{"Inherit Velocity"}= "Velocity Inherit from Control Point"; + $map{"Initial Repulsion Velocity"}= "Velocity Repulse from World"; + $map{"Initial Velocity Noise"}= "Velocity Noise"; + $map{"Initial Scalar Noise"}= "Remap Noise to Scalar"; + $map{"Lifespan from distance to world"}= "Lifetime from Time to Impact"; + $map{"Pre-Age Noise"}= "Lifetime Pre-Age Noise"; + $map{"lifetime_random"}= "Lifetime Random"; + $map{"radius_random"}= "Radius Random"; + $map{"random yaw"}= "Rotation Yaw Random"; + $map{"Randomly Flip Yaw"}= "Rotation Yaw Flip Random"; + $map{"rotation_random"}= "Rotation Random"; + $map{"rotation_speed_random"}= "Rotation Speed Random"; + $map{"sequence_random"}= "Sequence Random"; + $map{"second_sequence_random"}= "Sequence Two Random"; + $map{"trail_length_random"}= "Trail Length Random"; + $map{"velocity_random"}= "Velocity Random"; +} + diff --git a/mp/src/devtools/bin/fxc_prep.pl b/mp/src/devtools/bin/fxc_prep.pl index adc51ad8..9f67ca50 100644 --- a/mp/src/devtools/bin/fxc_prep.pl +++ b/mp/src/devtools/bin/fxc_prep.pl @@ -1,949 +1,949 @@ -BEGIN {use File::Basename; push @INC, dirname($0); }
-require "valve_perl_helpers.pl";
-
-sub ReadInputFile
-{
- local( $filename ) = shift;
- local( *INPUT );
- local( @output );
- open INPUT, "<$filename" || die;
-
- local( $line );
- local( $linenum ) = 1;
- while( $line = <INPUT> )
- {
-# print "LINE: $line";
-# $line =~ s/\n//g;
-# local( $postfix ) = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
-# $postfix .= "; LINEINFO($filename)($linenum)\n";
- if( $line =~ m/\#include\s+\"(.*)\"/i )
- {
- push @output, &ReadInputFile( $1 );
- }
- else
- {
-# push @output, $line . $postfix;
- push @output, $line;
- }
- $linenum++;
- }
-
- close INPUT;
-# print "-----------------\n";
-# print @output;
-# print "-----------------\n";
- return @output;
-}
-
-$dynamic_compile = defined $ENV{"dynamic_shaders"} && $ENV{"dynamic_shaders"} != 0;
-$generateListingFile = 0;
-$spewCombos = 0;
-
-@startTimes = times;
-$startTime = time;
-
-$g_produceCppClasses = 1;
-$g_produceCompiledVcs = 1;
-
-while( 1 )
-{
- $fxc_filename = shift;
- if( $fxc_filename =~ m/-source/ )
- {
- shift;
- }
- elsif( $fxc_filename =~ m/-nv3x/i )
- {
- $nvidia = 1;
- }
- elsif( $fxc_filename =~ m/-ps20a/i )
- {
- $ps2a = 1;
- }
- elsif( $fxc_filename =~ m/-x360/i )
- {
- # enable x360
- $g_x360 = 1;
- }
- elsif( $fxc_filename =~ m/-novcs/i )
- {
- $g_produceCompiledVcs = 0;
- }
- elsif( $fxc_filename =~ m/-nocpp/i )
- {
- $g_produceCppClasses = 0;
- }
- else
- {
- last;
- }
-}
-
-$argstring = $fxc_filename;
-$fxc_basename = $fxc_filename;
-$fxc_basename =~ s/^.*-----//;
-$fxc_filename =~ s/-----.*$//;
-
-$debug = 0;
-$forcehalf = 0;
-
-sub ToUpper
-{
- local( $in ) = shift;
- $in =~ tr/a-z/A-Z/;
- return $in;
-}
-
-sub CreateCCodeToSpewDynamicCombo
-{
- local( $out ) = "";
-
- $out .= "\t\tOutputDebugString( \"src:$fxc_filename vcs:$fxc_basename dynamic index\" );\n";
- $out .= "\t\tchar tmp[128];\n";
- $out .= "\t\tint shaderID = ";
- local( $scale ) = 1;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- local( $name ) = @dynamicDefineNames[$i];
- local( $varname ) = "m_n" . $name;
- $out .= "( $scale * $varname ) + ";
- $scale *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
- }
- $out .= "0;\n";
- if( scalar( @dynamicDefineNames ) + scalar( @staticDefineNames ) > 0 )
- {
- $out .= "\t\tint nCombo = shaderID;\n";
- }
-
- my $type = GetShaderType( $fxc_filename );
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $out .= "\t\tint n$dynamicDefineNames[$i] = nCombo % ";
- $out .= ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) + $dynamicDefineMin[$i];
- $out .= ";\n";
-
- $out .= "\t\tsprintf( tmp, \"\%d\", n$dynamicDefineNames[$i] );\n";
- $out .= "\t\tOutputDebugString( \" $dynamicDefineNames[$i]";
- $out .= "=\" );\n";
- $out .= "\t\tOutputDebugString( tmp );\n";
-
- $out .= "\t\tnCombo = nCombo / " . ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) . ";\n";
- $out .= "\n";
- }
- $out .= "\t\tOutputDebugString( \"\\n\" );\n";
- return $out;
-}
-
-sub CreateCCodeToSpewStaticCombo
-{
- local( $out ) = "";
-
- $out .= "\t\tOutputDebugString( \"src:$fxc_filename vcs:$fxc_basename static index\" );\n";
- $out .= "\t\tchar tmp[128];\n";
- $out .= "\t\tint shaderID = ";
-
- local( $scale ) = 1;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $scale *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
- }
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- local( $name ) = @staticDefineNames[$i];
- local( $varname ) = "m_n" . $name;
- $out .= "( $scale * $varname ) + ";
- $scale *= $staticDefineMax[$i] - $staticDefineMin[$i] + 1;
- }
- $out .= "0;\n";
-
-# $out .= "\t\tsprintf( tmp, \"\%d\\n\", shaderID );\n";
-# $out .= "\t\tOutputDebugString( tmp );\n\n";
- if( scalar( @staticDefineNames ) + scalar( @staticDefineNames ) > 0 )
- {
- $out .= "\t\tint nCombo = shaderID;\n";
- }
-
- my $type = GetShaderType( $fxc_filename );
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $out .= "\t\tnCombo = nCombo / " . ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) . ";\n";
- }
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- $out .= "\t\tint n$staticDefineNames[$i] = nCombo % ";
- $out .= ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) + $staticDefineMin[$i];
- $out .= ";\n";
-
- $out .= "\t\tsprintf( tmp, \"\%d\", n$staticDefineNames[$i] );\n";
- $out .= "\t\tOutputDebugString( \" $staticDefineNames[$i]";
- $out .= "=\" );\n";
- $out .= "\t\tOutputDebugString( tmp );\n";
-
- $out .= "\t\tnCombo = nCombo / " . ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) . ";\n";
- $out .= "\n";
- }
- $out .= "\t\tOutputDebugString( \"\\n\" );\n";
- return $out;
-}
-
-sub WriteHelperVar
-{
- local( $name ) = shift;
- local( $min ) = shift;
- local( $max ) = shift;
- local( $varname ) = "m_n" . $name;
- local( $boolname ) = "m_b" . $name;
- push @outputHeader, "private:\n";
- push @outputHeader, "\tint $varname;\n";
- push @outputHeader, "#ifdef _DEBUG\n";
- push @outputHeader, "\tbool $boolname;\n";
- push @outputHeader, "#endif\n";
- push @outputHeader, "public:\n";
- # int version of set function
- push @outputHeader, "\tvoid Set" . $name . "( int i )\n";
- push @outputHeader, "\t{\n";
- push @outputHeader, "\t\tAssert( i >= $min && i <= $max );\n";
- push @outputHeader, "\t\t$varname = i;\n";
- push @outputHeader, "#ifdef _DEBUG\n";
- push @outputHeader, "\t\t$boolname = true;\n";
- push @outputHeader, "#endif\n";
- push @outputHeader, "\t}\n";
- # bool version of set function
- push @outputHeader, "\tvoid Set" . $name . "( bool i )\n";
- push @outputHeader, "\t{\n";
-# push @outputHeader, "\t\tAssert( i >= $min && i <= $max );\n";
- push @outputHeader, "\t\t$varname = i ? 1 : 0;\n";
- push @outputHeader, "#ifdef _DEBUG\n";
- push @outputHeader, "\t\t$boolname = true;\n";
- push @outputHeader, "#endif\n";
- push @outputHeader, "\t}\n";
-}
-
-sub WriteStaticBoolExpression
-{
- local( $prefix ) = shift;
- local( $operator ) = shift;
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- if( $i )
- {
- push @outputHeader, " $operator ";
- }
- local( $name ) = @staticDefineNames[$i];
- local( $boolname ) = "m_b" . $name;
- push @outputHeader, "$prefix$boolname";
- }
- push @outputHeader, ";\n";
-}
-
-sub WriteDynamicBoolExpression
-{
- local( $prefix ) = shift;
- local( $operator ) = shift;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- if( $i )
- {
- push @outputHeader, " $operator ";
- }
- local( $name ) = @dynamicDefineNames[$i];
- local( $boolname ) = "m_b" . $name;
- push @outputHeader, "$prefix$boolname";
- }
- push @outputHeader, ";\n";
-}
-
-sub WriteDynamicHelperClasses
-{
- local( $basename ) = $fxc_basename;
- $basename =~ tr/A-Z/a-z/;
- local( $classname ) = $basename . "_Dynamic_Index";
- push @outputHeader, "class $classname\n";
- push @outputHeader, "{\n";
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $name = $dynamicDefineNames[$i];
- $min = $dynamicDefineMin[$i];
- $max = $dynamicDefineMax[$i];
- &WriteHelperVar( $name, $min, $max );
- }
- push @outputHeader, "public:\n";
-# push @outputHeader, "void SetPixelShaderIndex( IShaderAPI *pShaderAPI ) { pShaderAPI->SetPixelShaderIndex( GetIndex() ); }\n";
- push @outputHeader, "\t$classname()\n";
- push @outputHeader, "\t{\n";
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- local( $name ) = @dynamicDefineNames[$i];
- local( $boolname ) = "m_b" . $name;
- local( $varname ) = "m_n" . $name;
- push @outputHeader, "#ifdef _DEBUG\n";
- push @outputHeader, "\t\t$boolname = false;\n";
- push @outputHeader, "#endif // _DEBUG\n";
- push @outputHeader, "\t\t$varname = 0;\n";
- }
- push @outputHeader, "\t}\n";
- push @outputHeader, "\tint GetIndex()\n";
- push @outputHeader, "\t{\n";
- push @outputHeader, "\t\t// Asserts to make sure that we aren't using any skipped combinations.\n";
- foreach $skip (@perlskipcodeindividual)
- {
- # can't do this static and dynamic can see each other.
-# $skip =~ s/\$/m_n/g;
-# $skip =~ s/defined//g;
-# push @outputHeader, "\t\tAssert( !( $skip ) );\n";
-# print "\t\tAssert( !( $skip ) );\n";
- }
- push @outputHeader, "\t\t// Asserts to make sure that we are setting all of the combination vars.\n";
-
- push @outputHeader, "#ifdef _DEBUG\n";
- if( scalar( @dynamicDefineNames ) > 0 )
- {
- push @outputHeader, "\t\tbool bAllDynamicVarsDefined = ";
- WriteDynamicBoolExpression( "", "&&" );
- }
- if( scalar( @dynamicDefineNames ) > 0 )
- {
- push @outputHeader, "\t\tAssert( bAllDynamicVarsDefined );\n";
- }
- push @outputHeader, "#endif // _DEBUG\n";
-
- if( $spewCombos && scalar( @dynamicDefineNames ) )
- {
- push @outputHeader, &CreateCCodeToSpewDynamicCombo();
- }
- push @outputHeader, "\t\treturn ";
- local( $scale ) = 1;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- local( $name ) = @dynamicDefineNames[$i];
- local( $varname ) = "m_n" . $name;
- push @outputHeader, "( $scale * $varname ) + ";
- $scale *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
- }
- push @outputHeader, "0;\n";
- push @outputHeader, "\t}\n";
- push @outputHeader, "};\n";
- push @outputHeader, "\#define shaderDynamicTest_" . $basename . " ";
- my $prefix;
- my $shaderType = &GetShaderType( $fxc_filename );
- if( $shaderType =~ m/^vs/i )
- {
- $prefix = "vsh_";
- }
- else
- {
- $prefix = "psh_";
- }
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- local( $name ) = @dynamicDefineNames[$i];
- push @outputHeader, $prefix . "forgot_to_set_dynamic_" . $name . " + ";
- }
- push @outputHeader, "0\n";
-}
-
-sub WriteStaticHelperClasses
-{
- local( $basename ) = $fxc_basename;
- $basename =~ tr/A-Z/a-z/;
- local( $classname ) = $basename . "_Static_Index";
- push @outputHeader, "#include \"shaderlib/cshader.h\"\n";
- push @outputHeader, "class $classname\n";
- push @outputHeader, "{\n";
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- $name = $staticDefineNames[$i];
- $min = $staticDefineMin[$i];
- $max = $staticDefineMax[$i];
- &WriteHelperVar( $name, $min, $max );
- }
- push @outputHeader, "public:\n";
-# push @outputHeader, "void SetShaderIndex( IShaderShadow *pShaderShadow ) { pShaderShadow->SetPixelShaderIndex( GetIndex() ); }\n";
- push @outputHeader, "\t$classname( )\n";
- push @outputHeader, "\t{\n";
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- local( $name ) = @staticDefineNames[$i];
- local( $boolname ) = "m_b" . $name;
- local( $varname ) = "m_n" . $name;
- if ( length( $staticDefineInit{$name} ) )
- {
- push @outputHeader, "#ifdef _DEBUG\n";
- push @outputHeader, "\t\t$boolname = true;\n";
- push @outputHeader, "#endif // _DEBUG\n";
- push @outputHeader, "\t\t$varname = $staticDefineInit{$name};\n";
- }
- else
- {
- push @outputHeader, "#ifdef _DEBUG\n";
- push @outputHeader, "\t\t$boolname = false;\n";
- push @outputHeader, "#endif // _DEBUG\n";
- push @outputHeader, "\t\t$varname = 0;\n";
- }
- }
- push @outputHeader, "\t}\n";
- push @outputHeader, "\tint GetIndex()\n";
- push @outputHeader, "\t{\n";
- push @outputHeader, "\t\t// Asserts to make sure that we aren't using any skipped combinations.\n";
- foreach $skip (@perlskipcodeindividual)
- {
- $skip =~ s/\$/m_n/g;
-# push @outputHeader, "\t\tAssert( !( $skip ) );\n";
- }
- push @outputHeader, "\t\t// Asserts to make sure that we are setting all of the combination vars.\n";
-
- push @outputHeader, "#ifdef _DEBUG\n";
- if( scalar( @staticDefineNames ) > 0 )
- {
- push @outputHeader, "\t\tbool bAllStaticVarsDefined = ";
- WriteStaticBoolExpression( "", "&&" );
-
- }
- if( scalar( @staticDefineNames ) > 0 )
- {
- push @outputHeader, "\t\tAssert( bAllStaticVarsDefined );\n";
- }
- push @outputHeader, "#endif // _DEBUG\n";
-
- if( $spewCombos && scalar( @staticDefineNames ) )
- {
- push @outputHeader, &CreateCCodeToSpewStaticCombo();
- }
- push @outputHeader, "\t\treturn ";
- local( $scale ) = 1;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $scale *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
- }
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- local( $name ) = @staticDefineNames[$i];
- local( $varname ) = "m_n" . $name;
- push @outputHeader, "( $scale * $varname ) + ";
- $scale *= $staticDefineMax[$i] - $staticDefineMin[$i] + 1;
- }
- push @outputHeader, "0;\n";
- push @outputHeader, "\t}\n";
- push @outputHeader, "};\n";
- push @outputHeader, "\#define shaderStaticTest_" . $basename . " ";
- my $prefix;
- my $shaderType = &GetShaderType( $fxc_filename );
- if( $shaderType =~ m/^vs/i )
- {
- $prefix = "vsh_";
- }
- else
- {
- $prefix = "psh_";
- }
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- local( $name ) = @staticDefineNames[$i];
- push @outputHeader, $prefix . "forgot_to_set_static_" . $name . " + " unless (length($staticDefineInit{$name} ));
- }
- push @outputHeader, "0\n";
-}
-
-sub GetNewMainName
-{
- local( $shadername ) = shift;
- local( $combo ) = shift;
- local( $i );
- $shadername =~ s/\./_/g;
- local( $name ) = $shadername;
- for( $i = 0; $i < scalar( @defineNames ); $i++ )
- {
- local( $val ) = ( $combo % ( $defineMax[$i] - $defineMin[$i] + 1 ) ) + $defineMin[$i];
- $name .= "_" . $defineNames[$i] . "_" . $val;
- $combo = $combo / ( $defineMax[$i] - $defineMin[$i] + 1 );
- }
-# return $name;
- return "main";
-}
-
-sub RenameMain
-{
- local( $shadername ) = shift;
- local( $combo ) = shift;
- local( $name ) = &GetNewMainName( $shadername, $combo );
- return "/Dmain=$name /E$name ";
-}
-
-sub GetShaderType
-{
- local( $shadername ) = shift; # hack - use global variables
- $shadername = $fxc_basename;
- if( $shadername =~ m/ps30/i )
- {
- if( $debug )
- {
- return "ps_3_sw";
- }
- else
- {
- return "ps_3_0";
- }
- }
- elsif( $shadername =~ m/ps20b/i )
- {
- return "ps_2_b";
- }
- elsif( $shadername =~ m/ps20/i )
- {
- if( $debug )
- {
- return "ps_2_sw";
- }
- else
- {
- if( $ps2a )
- {
- return "ps_2_a";
- }
- else
- {
- return "ps_2_0";
- }
- }
- }
- elsif( $shadername =~ m/ps14/i )
- {
- return "ps_1_4";
- }
- elsif( $shadername =~ m/ps11/i )
- {
- return "ps_1_1";
- }
- elsif( $shadername =~ m/vs30/i )
- {
- if( $debug )
- {
- return "vs_3_sw";
- }
- else
- {
- return "vs_3_0";
- }
- }
- elsif( $shadername =~ m/vs20/i )
- {
- if( $debug )
- {
- return "vs_2_sw";
- }
- else
- {
- return "vs_2_0";
- }
- }
- elsif( $shadername =~ m/vs14/i )
- {
- return "vs_1_1";
- }
- elsif( $shadername =~ m/vs11/i )
- {
- return "vs_1_1";
- }
- else
- {
- die "\n\nSHADERNAME = $shadername\n\n";
- }
-}
-
-sub CalcNumCombos
-{
- local( $i, $numCombos );
- $numCombos = 1;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
- }
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- $numCombos *= $staticDefineMax[$i] - $staticDefineMin[$i] + 1;
- }
- return $numCombos;
-}
-
-sub CalcNumDynamicCombos
-{
- local( $i, $numCombos );
- $numCombos = 1;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
- }
- return $numCombos;
-}
-
-sub CreateCFuncToCreateCompileCommandLine
-{
- local( $out ) = "";
-
- $out .= "\t\tOutputDebugString( \"compiling src:$fxc_filename vcs:$fxc_basename \" );\n";
- $out .= "\t\tchar tmp[128];\n";
- $out .= "\t\tsprintf( tmp, \"\%d\\n\", shaderID );\n";
- $out .= "\t\tOutputDebugString( tmp );\n";
- $out .= "\t\tstatic PrecompiledShaderByteCode_t byteCode;\n";
- if( scalar( @dynamicDefineNames ) + scalar( @staticDefineNames ) > 0 )
- {
- $out .= "\t\tint nCombo = shaderID;\n";
- }
-
-# $out .= "\tvoid BuildCompileCommandLine( int nCombo, char *pResult, int maxLength )\n";
-# $out .= "\t{\n";
- $out .= "\t\tD3DXMACRO ";
- $out .= "defineMacros";
- $out .= "[";
- $out .= scalar( @dynamicDefineNames ) + scalar( @staticDefineNames ) + 1; # add 1 for null termination
- $out .= "];\n";
- if( scalar( @dynamicDefineNames ) + scalar( @staticDefineNames ) > 0 )
- {
- $out .= "\t\tchar tmpStringBuf[1024];\n";
- $out .= "\t\tchar *pTmpString = tmpStringBuf;\n\n";
- }
-
- local( $i );
- my $type = GetShaderType( $fxc_filename );
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $out .= "\t\tsprintf( pTmpString, \"%d\", nCombo % ";
- $out .= ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) + $dynamicDefineMin[$i];
- $out .= " );\n";
- $out .= "\t\tdefineMacros";
- $out .= "[";
- $out .= $i;
- $out .= "]";
- $out .= "\.Name = ";
- $out .= "\"$dynamicDefineNames[$i]\";\n";
-
- $out .= "\t\tint n$dynamicDefineNames[$i] = nCombo % ";
- $out .= ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) + $dynamicDefineMin[$i];
- $out .= ";\n";
- $out .= "\t\tUNUSED( n$dynamicDefineNames[$i] );\n";
-
- $out .= "\t\tdefineMacros";
- $out .= "[";
- $out .= $i;
- $out .= "]";
- $out .= "\.Definition = ";
- $out .= "pTmpString;\n";
- $out .= "\t\tpTmpString += strlen( pTmpString ) + 1;\n";
-
- $out .= "\t\tsprintf( tmp, \"\%d\", n$dynamicDefineNames[$i] );\n";
- $out .= "\t\tOutputDebugString( \" $dynamicDefineNames[$i]";
- $out .= "=\" );\n";
- $out .= "\t\tOutputDebugString( tmp );\n";
-
- $out .= "\t\tnCombo = nCombo / " . ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) . ";\n";
- $out .= "\n";
- }
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- $out .= "\t\tsprintf( pTmpString, \"%d\", nCombo % ";
- $out .= ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) + $staticDefineMin[$i];
- $out .= " );\n";
- $out .= "\t\tdefineMacros";
- $out .= "[";
- $out .= $i + scalar( @dynamicDefineNames );
- $out .= "]";
- $out .= "\.Name = ";
- $out .= "\"$staticDefineNames[$i]\";\n";
-
- $out .= "\t\tint n$staticDefineNames[$i] = nCombo % ";
- $out .= ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) + $staticDefineMin[$i];
- $out .= ";\n";
- $out .= "\t\tUNUSED( n$staticDefineNames[$i] );\n";
-
- $out .= "\t\tdefineMacros";
- $out .= "[";
- $out .= $i + scalar( @dynamicDefineNames );
- $out .= "]";
- $out .= "\.Definition = ";
- $out .= "pTmpString;\n";
- $out .= "\t\tpTmpString += strlen( pTmpString ) + 1;\n";
-
- $out .= "\t\tsprintf( tmp, \"\%d\", n$staticDefineNames[$i] );\n";
- $out .= "\t\tOutputDebugString( \" $staticDefineNames[$i]";
- $out .= "=\" );\n";
- $out .= "\t\tOutputDebugString( tmp );\n";
-
- $out .= "\t\tnCombo = nCombo / " . ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) . ";\n";
- $out .= "\n";
- }
-
- $out .= "\t\tOutputDebugString( \"\\n\" );\n";
-
- $cskipcode = $perlskipcode;
- $cskipcode =~ s/\$/n/g;
- $out .= "\t\tif( $cskipcode )\n\t\t{\n";
- $out .= "\t\t\tstatic char blah[4] = { 0, 0, 0, 0 };\n";
- $out .= "\t\t\tbyteCode.m_pRawData = blah;\n";
- $out .= "\t\t\tbyteCode.m_nSizeInBytes = 4;\n";
- $out .= "\t\t\treturn byteCode;\n";
- $out .= "\t\t}\n";
-
-
-
- $out .= "\t\t// Must null terminate macros.\n";
- $out .= "\t\tdefineMacros[";
- $out .= scalar( @dynamicDefineNames ) + scalar( @staticDefineNames );
- $out .= "]";
- $out .= ".Name = NULL;\n";
- $out .= "\t\tdefineMacros[";
- $out .= scalar( @dynamicDefineNames ) + scalar( @staticDefineNames );
- $out .= "]";
- $out .= ".Definition = NULL;\n\n";
-
-
- $out .= "\t\tLPD3DXBUFFER pShader; // NOTE: THESE LEAK!!!\n";
- $out .= "\t\tLPD3DXBUFFER pErrorMessages; // NOTE: THESE LEAK!!!\n";
- $out .= "\t\tHRESULT hr = D3DXCompileShaderFromFile( \"u:\\\\hl2_e3_2004\\\\src_e3_2004\\\\materialsystem\\\\stdshaders\\\\$fxc_filename\",\n\t\t\tdefineMacros,\n\t\t\tNULL, // LPD3DXINCLUDE \n\t\t\t\"main\",\n\t\t\t\"$type\",\n\t\t\t0, // DWORD Flags\n\t\t\t&pShader,\n\t\t\t&pErrorMessages,\n\t\t\tNULL // LPD3DXCONSTANTTABLE *ppConstantTable\n\t\t\t );\n";
- $out .= "\t\tif( hr != D3D_OK )\n";
- $out .= "\t\t{\n";
- $out .= "\t\t\tconst char *pErrorMessageString = ( const char * )pErrorMessages->GetBufferPointer();\n";
- $out .= "\t\t\tOutputDebugString( pErrorMessageString );\n";
- $out .= "\t\t\tOutputDebugString( \"\\n\" );\n";
- $out .= "\t\t\tAssert( 0 );\n";
- $out .= "\t\t\tstatic char blah[4] = { 0, 0, 0, 0 };\n";
- $out .= "\t\t\tbyteCode.m_pRawData = blah;\n";
- $out .= "\t\t\tbyteCode.m_nSizeInBytes = 4;\n";
- $out .= "\t\t}\n";
- $out .= "\t\telse\n";
- $out .= "\t\t{\n";
- $out .= "\t\t\tbyteCode.m_pRawData = pShader->GetBufferPointer();\n";
- $out .= "\t\t\tbyteCode.m_nSizeInBytes = pShader->GetBufferSize();\n";
- $out .= "\t\t}\n";
- $out .= "\t\treturn byteCode;\n";
- return $out;
-}
-
-#print "--------\n";
-
-if ( $g_x360 )
-{
- $fxctmp = "fxctmp9_360_tmp";
-}
-else
-{
- $fxctmp = "fxctmp9_tmp";
-}
-
-if( !stat $fxctmp )
-{
- mkdir $fxctmp, 0777 || die $!;
-}
-
-# suck in an input file (using includes)
-#print "$fxc_filename...";
-@fxc = ReadInputFile( $fxc_filename );
-
-# READ THE TOP OF THE FILE TO FIND SHADER COMBOS
-foreach $line ( @fxc )
-{
- $line="" if ($g_x360 && ($line=~/\[PC\]/)); # line marked as [PC] when building for x360
- $line="" if (($g_x360 == 0) && ($line=~/\[XBOX\]/)); # line marked as [XBOX] when building for pc
-
- if ( $fxc_basename =~ m/_ps(\d+\w?)$/i )
- {
- my $psver = $1;
- $line="" if (($line =~/\[ps\d+\w?\]/i) && ($line!~/\[ps$psver\]/i)); # line marked for a version of compiler and not what we build
- }
- if ( $fxc_basename =~ m/_vs(\d+\w?)$/i )
- {
- my $vsver = $1;
- $line="" if (($line =~/\[vs\d+\w?\]/i) && ($line!~/\[vs$vsver\]/i)); # line marked for a version of compiler and not what we build
- }
-
- my $init_expr;
-
- $init_expr = $1 if ( $line=~/\[\=([^\]]+)\]/); # parse default init expression for combos
-
- $line=~s/\[[^\[\]]*\]//; # cut out all occurrences of
- # square brackets and whatever is
- # inside all these modifications
- # to the line are seen later when
- # processing skips and centroids
-
- next if( $line =~ m/^\s*$/ );
-
- if( $line =~ m/^\s*\/\/\s*STATIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ )
- {
- local( $name, $min, $max );
- $name = $1;
- $min = $2;
- $max = $3;
- # print STDERR "STATIC: \"$name\" \"$min..$max\"\n";
- push @staticDefineNames, $name;
- push @staticDefineMin, $min;
- push @staticDefineMax, $max;
- $staticDefineInit{$name}=$init_expr;
- }
- elsif( $line =~ m/^\s*\/\/\s*DYNAMIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ )
- {
- local( $name, $min, $max );
- $name = $1;
- $min = $2;
- $max = $3;
- # print STDERR "DYNAMIC: \"$name\" \"$min..$max\"\n";
- push @dynamicDefineNames, $name;
- push @dynamicDefineMin, $min;
- push @dynamicDefineMax, $max;
- }
-}
-# READ THE WHOLE FILE AND FIND SKIP STATEMENTS
-foreach $line ( @fxc )
-{
- if( $line =~ m/^\s*\/\/\s*SKIP\s*\s*\:\s*(.*)$/ )
- {
- # print $1 . "\n";
- $perlskipcode .= "(" . $1 . ")||";
- push @perlskipcodeindividual, $1;
- }
-}
-
-if( defined $perlskipcode )
-{
- $perlskipcode .= "0";
- $perlskipcode =~ s/\n//g;
-}
-else
-{
- $perlskipcode = "0";
-}
-
-# READ THE WHOLE FILE AND FIND CENTROID STATEMENTS
-foreach $line ( @fxc )
-{
- if( $line =~ m/^\s*\/\/\s*CENTROID\s*\:\s*TEXCOORD(\d+)\s*$/ )
- {
- $centroidEnable{$1} = 1;
-# print "CENTROID: $1\n";
- }
-}
-
-if( $spewCombos )
-{
- push @outputHeader, "#include \"windows.h\"\n";
-}
-
-#push @outputHeader, "\#include \"shaderlib\\baseshader.h\"\n";
-#push @outputHeader, "IShaderDynamicAPI *CBaseShader::s_pShaderAPI;\n";
-
-# Go ahead an compute the mask of samplers that need to be centroid sampled
-$centroidMask = 0;
-foreach $centroidRegNum ( keys( %centroidEnable ) )
-{
-# print "THING: $samplerName $centroidRegNum\n";
- $centroidMask += 1 << $centroidRegNum;
-}
-
-#printf "0x%x\n", $centroidMask;
-
-$numCombos = &CalcNumCombos();
-#print "$numCombos combos\n";
-
-
-if( $g_produceCompiledVcs && !$dynamic_compile )
-{
- open FOUT, ">>filelistgen.txt" || die "can't open filelistgen.txt";
-
- print FOUT "**** generated by fxc_prep.pl ****\n";
- print FOUT "#BEGIN " . $fxc_basename . "\n";
- print FOUT "$fxc_filename" . "\n";
- print FOUT "#DEFINES-D:\n";
- for( $i = 0; $i < scalar( @dynamicDefineNames ); \$i++ )
- {
- print FOUT "$dynamicDefineNames[$i]=";
- print FOUT $dynamicDefineMin[$i];
- print FOUT "..";
- print FOUT $dynamicDefineMax[$i];
- print FOUT "\n";
- }
- print FOUT "#DEFINES-S:\n";
- for( $i = 0; $i < scalar( @staticDefineNames ); \$i++ )
- {
- print FOUT "$staticDefineNames[$i]=";
- print FOUT $staticDefineMin[$i];
- print FOUT "..";
- print FOUT $staticDefineMax[$i];
- print FOUT "\n";
- }
- print FOUT "#SKIP:\n";
- print FOUT "$perlskipcode\n";
- print FOUT "#COMMAND:\n";
- # first line
- print FOUT "fxc.exe ";
- print FOUT "/DTOTALSHADERCOMBOS=$numCombos ";
- print FOUT "/DCENTROIDMASK=$centroidMask ";
- print FOUT "/DNUMDYNAMICCOMBOS=" . &CalcNumDynamicCombos() . " ";
- print FOUT "/DFLAGS=0x0 "; # Nothing here for now.
- print FOUT "\n";
-#defines go here
-# second line
- print FOUT &RenameMain( $fxc_filename, $i );
- print FOUT "/T" . &GetShaderType( $fxc_filename ) . " ";
- print FOUT "/DSHADER_MODEL_" . &ToUpper( &GetShaderType( $fxc_filename ) ) . "=1 ";
- if( $nvidia )
- {
- print FOUT "/DNV3X=1 "; # enable NV3X codepath
- }
- if ( $g_x360 )
- {
- print FOUT "/D_X360=1 "; # shaders can identify X360 centric code
- # print FOUT "/Xbe:2- "; # use the less-broken old back end
- }
- if( $debug )
- {
- print FOUT "/Od "; # disable optimizations
- print FOUT "/Zi "; # enable debug info
- }
-# print FOUT "/Zi "; # enable debug info
- print FOUT "/nologo ";
-# print FOUT "/Fhtmpshader.h ";
- print FOUT "/Foshader.o ";
- print FOUT "$fxc_filename";
- print FOUT ">output.txt 2>&1";
- print FOUT "\n";
- #end of command line
- print FOUT "#END\n";
- print FOUT "**** end ****\n";
-
- close FOUT;
-}
-
-if ( $g_produceCppClasses )
-{
- # Write out the C++ helper class for picking shader combos
- &WriteStaticHelperClasses();
- &WriteDynamicHelperClasses();
- my $incfilename = "$fxctmp\\$fxc_basename" . ".inc";
- &WriteFile( $incfilename, join( "", @outputHeader ) );
-}
-
-
-
-if( $generateListingFile )
-{
- my $listFileName = "$fxctmp/$fxc_basename" . ".lst";
- print "writing $listFileName\n";
- if( !open FILE, ">$listFileName" )
- {
- die;
- }
- print FILE @listingOutput;
- close FILE;
-}
-
-
-@endTimes = times;
-
-$endTime = time;
-
-#printf "Elapsed user time: %.2f seconds!\n", $endTimes[0] - $startTimes[0];
-#printf "Elapsed system time: %.2f seconds!\n", $endTimes[1] - $startTimes[1];
-#printf "Elapsed child user time: %.2f seconds!\n", $endTimes[2] - $startTimes[2];
-#printf "Elapsed child system time: %.2f seconds!\n", $endTimes[3] - $startTimes[3];
-
-#printf "Elapsed total time: %.2f seconds!\n", $endTime - $startTime;
-
+BEGIN {use File::Basename; push @INC, dirname($0); } +require "valve_perl_helpers.pl"; + +sub ReadInputFile +{ + local( $filename ) = shift; + local( *INPUT ); + local( @output ); + open INPUT, "<$filename" || die; + + local( $line ); + local( $linenum ) = 1; + while( $line = <INPUT> ) + { +# print "LINE: $line"; +# $line =~ s/\n//g; +# local( $postfix ) = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; +# $postfix .= "; LINEINFO($filename)($linenum)\n"; + if( $line =~ m/\#include\s+\"(.*)\"/i ) + { + push @output, &ReadInputFile( $1 ); + } + else + { +# push @output, $line . $postfix; + push @output, $line; + } + $linenum++; + } + + close INPUT; +# print "-----------------\n"; +# print @output; +# print "-----------------\n"; + return @output; +} + +$dynamic_compile = defined $ENV{"dynamic_shaders"} && $ENV{"dynamic_shaders"} != 0; +$generateListingFile = 0; +$spewCombos = 0; + +@startTimes = times; +$startTime = time; + +$g_produceCppClasses = 1; +$g_produceCompiledVcs = 1; + +while( 1 ) +{ + $fxc_filename = shift; + if( $fxc_filename =~ m/-source/ ) + { + shift; + } + elsif( $fxc_filename =~ m/-nv3x/i ) + { + $nvidia = 1; + } + elsif( $fxc_filename =~ m/-ps20a/i ) + { + $ps2a = 1; + } + elsif( $fxc_filename =~ m/-x360/i ) + { + # enable x360 + $g_x360 = 1; + } + elsif( $fxc_filename =~ m/-novcs/i ) + { + $g_produceCompiledVcs = 0; + } + elsif( $fxc_filename =~ m/-nocpp/i ) + { + $g_produceCppClasses = 0; + } + else + { + last; + } +} + +$argstring = $fxc_filename; +$fxc_basename = $fxc_filename; +$fxc_basename =~ s/^.*-----//; +$fxc_filename =~ s/-----.*$//; + +$debug = 0; +$forcehalf = 0; + +sub ToUpper +{ + local( $in ) = shift; + $in =~ tr/a-z/A-Z/; + return $in; +} + +sub CreateCCodeToSpewDynamicCombo +{ + local( $out ) = ""; + + $out .= "\t\tOutputDebugString( \"src:$fxc_filename vcs:$fxc_basename dynamic index\" );\n"; + $out .= "\t\tchar tmp[128];\n"; + $out .= "\t\tint shaderID = "; + local( $scale ) = 1; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + local( $name ) = @dynamicDefineNames[$i]; + local( $varname ) = "m_n" . $name; + $out .= "( $scale * $varname ) + "; + $scale *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1; + } + $out .= "0;\n"; + if( scalar( @dynamicDefineNames ) + scalar( @staticDefineNames ) > 0 ) + { + $out .= "\t\tint nCombo = shaderID;\n"; + } + + my $type = GetShaderType( $fxc_filename ); + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $out .= "\t\tint n$dynamicDefineNames[$i] = nCombo % "; + $out .= ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) + $dynamicDefineMin[$i]; + $out .= ";\n"; + + $out .= "\t\tsprintf( tmp, \"\%d\", n$dynamicDefineNames[$i] );\n"; + $out .= "\t\tOutputDebugString( \" $dynamicDefineNames[$i]"; + $out .= "=\" );\n"; + $out .= "\t\tOutputDebugString( tmp );\n"; + + $out .= "\t\tnCombo = nCombo / " . ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) . ";\n"; + $out .= "\n"; + } + $out .= "\t\tOutputDebugString( \"\\n\" );\n"; + return $out; +} + +sub CreateCCodeToSpewStaticCombo +{ + local( $out ) = ""; + + $out .= "\t\tOutputDebugString( \"src:$fxc_filename vcs:$fxc_basename static index\" );\n"; + $out .= "\t\tchar tmp[128];\n"; + $out .= "\t\tint shaderID = "; + + local( $scale ) = 1; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $scale *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1; + } + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + local( $name ) = @staticDefineNames[$i]; + local( $varname ) = "m_n" . $name; + $out .= "( $scale * $varname ) + "; + $scale *= $staticDefineMax[$i] - $staticDefineMin[$i] + 1; + } + $out .= "0;\n"; + +# $out .= "\t\tsprintf( tmp, \"\%d\\n\", shaderID );\n"; +# $out .= "\t\tOutputDebugString( tmp );\n\n"; + if( scalar( @staticDefineNames ) + scalar( @staticDefineNames ) > 0 ) + { + $out .= "\t\tint nCombo = shaderID;\n"; + } + + my $type = GetShaderType( $fxc_filename ); + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $out .= "\t\tnCombo = nCombo / " . ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) . ";\n"; + } + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + $out .= "\t\tint n$staticDefineNames[$i] = nCombo % "; + $out .= ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) + $staticDefineMin[$i]; + $out .= ";\n"; + + $out .= "\t\tsprintf( tmp, \"\%d\", n$staticDefineNames[$i] );\n"; + $out .= "\t\tOutputDebugString( \" $staticDefineNames[$i]"; + $out .= "=\" );\n"; + $out .= "\t\tOutputDebugString( tmp );\n"; + + $out .= "\t\tnCombo = nCombo / " . ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) . ";\n"; + $out .= "\n"; + } + $out .= "\t\tOutputDebugString( \"\\n\" );\n"; + return $out; +} + +sub WriteHelperVar +{ + local( $name ) = shift; + local( $min ) = shift; + local( $max ) = shift; + local( $varname ) = "m_n" . $name; + local( $boolname ) = "m_b" . $name; + push @outputHeader, "private:\n"; + push @outputHeader, "\tint $varname;\n"; + push @outputHeader, "#ifdef _DEBUG\n"; + push @outputHeader, "\tbool $boolname;\n"; + push @outputHeader, "#endif\n"; + push @outputHeader, "public:\n"; + # int version of set function + push @outputHeader, "\tvoid Set" . $name . "( int i )\n"; + push @outputHeader, "\t{\n"; + push @outputHeader, "\t\tAssert( i >= $min && i <= $max );\n"; + push @outputHeader, "\t\t$varname = i;\n"; + push @outputHeader, "#ifdef _DEBUG\n"; + push @outputHeader, "\t\t$boolname = true;\n"; + push @outputHeader, "#endif\n"; + push @outputHeader, "\t}\n"; + # bool version of set function + push @outputHeader, "\tvoid Set" . $name . "( bool i )\n"; + push @outputHeader, "\t{\n"; +# push @outputHeader, "\t\tAssert( i >= $min && i <= $max );\n"; + push @outputHeader, "\t\t$varname = i ? 1 : 0;\n"; + push @outputHeader, "#ifdef _DEBUG\n"; + push @outputHeader, "\t\t$boolname = true;\n"; + push @outputHeader, "#endif\n"; + push @outputHeader, "\t}\n"; +} + +sub WriteStaticBoolExpression +{ + local( $prefix ) = shift; + local( $operator ) = shift; + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + if( $i ) + { + push @outputHeader, " $operator "; + } + local( $name ) = @staticDefineNames[$i]; + local( $boolname ) = "m_b" . $name; + push @outputHeader, "$prefix$boolname"; + } + push @outputHeader, ";\n"; +} + +sub WriteDynamicBoolExpression +{ + local( $prefix ) = shift; + local( $operator ) = shift; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + if( $i ) + { + push @outputHeader, " $operator "; + } + local( $name ) = @dynamicDefineNames[$i]; + local( $boolname ) = "m_b" . $name; + push @outputHeader, "$prefix$boolname"; + } + push @outputHeader, ";\n"; +} + +sub WriteDynamicHelperClasses +{ + local( $basename ) = $fxc_basename; + $basename =~ tr/A-Z/a-z/; + local( $classname ) = $basename . "_Dynamic_Index"; + push @outputHeader, "class $classname\n"; + push @outputHeader, "{\n"; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $name = $dynamicDefineNames[$i]; + $min = $dynamicDefineMin[$i]; + $max = $dynamicDefineMax[$i]; + &WriteHelperVar( $name, $min, $max ); + } + push @outputHeader, "public:\n"; +# push @outputHeader, "void SetPixelShaderIndex( IShaderAPI *pShaderAPI ) { pShaderAPI->SetPixelShaderIndex( GetIndex() ); }\n"; + push @outputHeader, "\t$classname()\n"; + push @outputHeader, "\t{\n"; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + local( $name ) = @dynamicDefineNames[$i]; + local( $boolname ) = "m_b" . $name; + local( $varname ) = "m_n" . $name; + push @outputHeader, "#ifdef _DEBUG\n"; + push @outputHeader, "\t\t$boolname = false;\n"; + push @outputHeader, "#endif // _DEBUG\n"; + push @outputHeader, "\t\t$varname = 0;\n"; + } + push @outputHeader, "\t}\n"; + push @outputHeader, "\tint GetIndex()\n"; + push @outputHeader, "\t{\n"; + push @outputHeader, "\t\t// Asserts to make sure that we aren't using any skipped combinations.\n"; + foreach $skip (@perlskipcodeindividual) + { + # can't do this static and dynamic can see each other. +# $skip =~ s/\$/m_n/g; +# $skip =~ s/defined//g; +# push @outputHeader, "\t\tAssert( !( $skip ) );\n"; +# print "\t\tAssert( !( $skip ) );\n"; + } + push @outputHeader, "\t\t// Asserts to make sure that we are setting all of the combination vars.\n"; + + push @outputHeader, "#ifdef _DEBUG\n"; + if( scalar( @dynamicDefineNames ) > 0 ) + { + push @outputHeader, "\t\tbool bAllDynamicVarsDefined = "; + WriteDynamicBoolExpression( "", "&&" ); + } + if( scalar( @dynamicDefineNames ) > 0 ) + { + push @outputHeader, "\t\tAssert( bAllDynamicVarsDefined );\n"; + } + push @outputHeader, "#endif // _DEBUG\n"; + + if( $spewCombos && scalar( @dynamicDefineNames ) ) + { + push @outputHeader, &CreateCCodeToSpewDynamicCombo(); + } + push @outputHeader, "\t\treturn "; + local( $scale ) = 1; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + local( $name ) = @dynamicDefineNames[$i]; + local( $varname ) = "m_n" . $name; + push @outputHeader, "( $scale * $varname ) + "; + $scale *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1; + } + push @outputHeader, "0;\n"; + push @outputHeader, "\t}\n"; + push @outputHeader, "};\n"; + push @outputHeader, "\#define shaderDynamicTest_" . $basename . " "; + my $prefix; + my $shaderType = &GetShaderType( $fxc_filename ); + if( $shaderType =~ m/^vs/i ) + { + $prefix = "vsh_"; + } + else + { + $prefix = "psh_"; + } + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + local( $name ) = @dynamicDefineNames[$i]; + push @outputHeader, $prefix . "forgot_to_set_dynamic_" . $name . " + "; + } + push @outputHeader, "0\n"; +} + +sub WriteStaticHelperClasses +{ + local( $basename ) = $fxc_basename; + $basename =~ tr/A-Z/a-z/; + local( $classname ) = $basename . "_Static_Index"; + push @outputHeader, "#include \"shaderlib/cshader.h\"\n"; + push @outputHeader, "class $classname\n"; + push @outputHeader, "{\n"; + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + $name = $staticDefineNames[$i]; + $min = $staticDefineMin[$i]; + $max = $staticDefineMax[$i]; + &WriteHelperVar( $name, $min, $max ); + } + push @outputHeader, "public:\n"; +# push @outputHeader, "void SetShaderIndex( IShaderShadow *pShaderShadow ) { pShaderShadow->SetPixelShaderIndex( GetIndex() ); }\n"; + push @outputHeader, "\t$classname( )\n"; + push @outputHeader, "\t{\n"; + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + local( $name ) = @staticDefineNames[$i]; + local( $boolname ) = "m_b" . $name; + local( $varname ) = "m_n" . $name; + if ( length( $staticDefineInit{$name} ) ) + { + push @outputHeader, "#ifdef _DEBUG\n"; + push @outputHeader, "\t\t$boolname = true;\n"; + push @outputHeader, "#endif // _DEBUG\n"; + push @outputHeader, "\t\t$varname = $staticDefineInit{$name};\n"; + } + else + { + push @outputHeader, "#ifdef _DEBUG\n"; + push @outputHeader, "\t\t$boolname = false;\n"; + push @outputHeader, "#endif // _DEBUG\n"; + push @outputHeader, "\t\t$varname = 0;\n"; + } + } + push @outputHeader, "\t}\n"; + push @outputHeader, "\tint GetIndex()\n"; + push @outputHeader, "\t{\n"; + push @outputHeader, "\t\t// Asserts to make sure that we aren't using any skipped combinations.\n"; + foreach $skip (@perlskipcodeindividual) + { + $skip =~ s/\$/m_n/g; +# push @outputHeader, "\t\tAssert( !( $skip ) );\n"; + } + push @outputHeader, "\t\t// Asserts to make sure that we are setting all of the combination vars.\n"; + + push @outputHeader, "#ifdef _DEBUG\n"; + if( scalar( @staticDefineNames ) > 0 ) + { + push @outputHeader, "\t\tbool bAllStaticVarsDefined = "; + WriteStaticBoolExpression( "", "&&" ); + + } + if( scalar( @staticDefineNames ) > 0 ) + { + push @outputHeader, "\t\tAssert( bAllStaticVarsDefined );\n"; + } + push @outputHeader, "#endif // _DEBUG\n"; + + if( $spewCombos && scalar( @staticDefineNames ) ) + { + push @outputHeader, &CreateCCodeToSpewStaticCombo(); + } + push @outputHeader, "\t\treturn "; + local( $scale ) = 1; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $scale *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1; + } + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + local( $name ) = @staticDefineNames[$i]; + local( $varname ) = "m_n" . $name; + push @outputHeader, "( $scale * $varname ) + "; + $scale *= $staticDefineMax[$i] - $staticDefineMin[$i] + 1; + } + push @outputHeader, "0;\n"; + push @outputHeader, "\t}\n"; + push @outputHeader, "};\n"; + push @outputHeader, "\#define shaderStaticTest_" . $basename . " "; + my $prefix; + my $shaderType = &GetShaderType( $fxc_filename ); + if( $shaderType =~ m/^vs/i ) + { + $prefix = "vsh_"; + } + else + { + $prefix = "psh_"; + } + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + local( $name ) = @staticDefineNames[$i]; + push @outputHeader, $prefix . "forgot_to_set_static_" . $name . " + " unless (length($staticDefineInit{$name} )); + } + push @outputHeader, "0\n"; +} + +sub GetNewMainName +{ + local( $shadername ) = shift; + local( $combo ) = shift; + local( $i ); + $shadername =~ s/\./_/g; + local( $name ) = $shadername; + for( $i = 0; $i < scalar( @defineNames ); $i++ ) + { + local( $val ) = ( $combo % ( $defineMax[$i] - $defineMin[$i] + 1 ) ) + $defineMin[$i]; + $name .= "_" . $defineNames[$i] . "_" . $val; + $combo = $combo / ( $defineMax[$i] - $defineMin[$i] + 1 ); + } +# return $name; + return "main"; +} + +sub RenameMain +{ + local( $shadername ) = shift; + local( $combo ) = shift; + local( $name ) = &GetNewMainName( $shadername, $combo ); + return "/Dmain=$name /E$name "; +} + +sub GetShaderType +{ + local( $shadername ) = shift; # hack - use global variables + $shadername = $fxc_basename; + if( $shadername =~ m/ps30/i ) + { + if( $debug ) + { + return "ps_3_sw"; + } + else + { + return "ps_3_0"; + } + } + elsif( $shadername =~ m/ps20b/i ) + { + return "ps_2_b"; + } + elsif( $shadername =~ m/ps20/i ) + { + if( $debug ) + { + return "ps_2_sw"; + } + else + { + if( $ps2a ) + { + return "ps_2_a"; + } + else + { + return "ps_2_0"; + } + } + } + elsif( $shadername =~ m/ps14/i ) + { + return "ps_1_4"; + } + elsif( $shadername =~ m/ps11/i ) + { + return "ps_1_1"; + } + elsif( $shadername =~ m/vs30/i ) + { + if( $debug ) + { + return "vs_3_sw"; + } + else + { + return "vs_3_0"; + } + } + elsif( $shadername =~ m/vs20/i ) + { + if( $debug ) + { + return "vs_2_sw"; + } + else + { + return "vs_2_0"; + } + } + elsif( $shadername =~ m/vs14/i ) + { + return "vs_1_1"; + } + elsif( $shadername =~ m/vs11/i ) + { + return "vs_1_1"; + } + else + { + die "\n\nSHADERNAME = $shadername\n\n"; + } +} + +sub CalcNumCombos +{ + local( $i, $numCombos ); + $numCombos = 1; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1; + } + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + $numCombos *= $staticDefineMax[$i] - $staticDefineMin[$i] + 1; + } + return $numCombos; +} + +sub CalcNumDynamicCombos +{ + local( $i, $numCombos ); + $numCombos = 1; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1; + } + return $numCombos; +} + +sub CreateCFuncToCreateCompileCommandLine +{ + local( $out ) = ""; + + $out .= "\t\tOutputDebugString( \"compiling src:$fxc_filename vcs:$fxc_basename \" );\n"; + $out .= "\t\tchar tmp[128];\n"; + $out .= "\t\tsprintf( tmp, \"\%d\\n\", shaderID );\n"; + $out .= "\t\tOutputDebugString( tmp );\n"; + $out .= "\t\tstatic PrecompiledShaderByteCode_t byteCode;\n"; + if( scalar( @dynamicDefineNames ) + scalar( @staticDefineNames ) > 0 ) + { + $out .= "\t\tint nCombo = shaderID;\n"; + } + +# $out .= "\tvoid BuildCompileCommandLine( int nCombo, char *pResult, int maxLength )\n"; +# $out .= "\t{\n"; + $out .= "\t\tD3DXMACRO "; + $out .= "defineMacros"; + $out .= "["; + $out .= scalar( @dynamicDefineNames ) + scalar( @staticDefineNames ) + 1; # add 1 for null termination + $out .= "];\n"; + if( scalar( @dynamicDefineNames ) + scalar( @staticDefineNames ) > 0 ) + { + $out .= "\t\tchar tmpStringBuf[1024];\n"; + $out .= "\t\tchar *pTmpString = tmpStringBuf;\n\n"; + } + + local( $i ); + my $type = GetShaderType( $fxc_filename ); + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $out .= "\t\tsprintf( pTmpString, \"%d\", nCombo % "; + $out .= ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) + $dynamicDefineMin[$i]; + $out .= " );\n"; + $out .= "\t\tdefineMacros"; + $out .= "["; + $out .= $i; + $out .= "]"; + $out .= "\.Name = "; + $out .= "\"$dynamicDefineNames[$i]\";\n"; + + $out .= "\t\tint n$dynamicDefineNames[$i] = nCombo % "; + $out .= ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) + $dynamicDefineMin[$i]; + $out .= ";\n"; + $out .= "\t\tUNUSED( n$dynamicDefineNames[$i] );\n"; + + $out .= "\t\tdefineMacros"; + $out .= "["; + $out .= $i; + $out .= "]"; + $out .= "\.Definition = "; + $out .= "pTmpString;\n"; + $out .= "\t\tpTmpString += strlen( pTmpString ) + 1;\n"; + + $out .= "\t\tsprintf( tmp, \"\%d\", n$dynamicDefineNames[$i] );\n"; + $out .= "\t\tOutputDebugString( \" $dynamicDefineNames[$i]"; + $out .= "=\" );\n"; + $out .= "\t\tOutputDebugString( tmp );\n"; + + $out .= "\t\tnCombo = nCombo / " . ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) . ";\n"; + $out .= "\n"; + } + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + $out .= "\t\tsprintf( pTmpString, \"%d\", nCombo % "; + $out .= ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) + $staticDefineMin[$i]; + $out .= " );\n"; + $out .= "\t\tdefineMacros"; + $out .= "["; + $out .= $i + scalar( @dynamicDefineNames ); + $out .= "]"; + $out .= "\.Name = "; + $out .= "\"$staticDefineNames[$i]\";\n"; + + $out .= "\t\tint n$staticDefineNames[$i] = nCombo % "; + $out .= ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) + $staticDefineMin[$i]; + $out .= ";\n"; + $out .= "\t\tUNUSED( n$staticDefineNames[$i] );\n"; + + $out .= "\t\tdefineMacros"; + $out .= "["; + $out .= $i + scalar( @dynamicDefineNames ); + $out .= "]"; + $out .= "\.Definition = "; + $out .= "pTmpString;\n"; + $out .= "\t\tpTmpString += strlen( pTmpString ) + 1;\n"; + + $out .= "\t\tsprintf( tmp, \"\%d\", n$staticDefineNames[$i] );\n"; + $out .= "\t\tOutputDebugString( \" $staticDefineNames[$i]"; + $out .= "=\" );\n"; + $out .= "\t\tOutputDebugString( tmp );\n"; + + $out .= "\t\tnCombo = nCombo / " . ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) . ";\n"; + $out .= "\n"; + } + + $out .= "\t\tOutputDebugString( \"\\n\" );\n"; + + $cskipcode = $perlskipcode; + $cskipcode =~ s/\$/n/g; + $out .= "\t\tif( $cskipcode )\n\t\t{\n"; + $out .= "\t\t\tstatic char blah[4] = { 0, 0, 0, 0 };\n"; + $out .= "\t\t\tbyteCode.m_pRawData = blah;\n"; + $out .= "\t\t\tbyteCode.m_nSizeInBytes = 4;\n"; + $out .= "\t\t\treturn byteCode;\n"; + $out .= "\t\t}\n"; + + + + $out .= "\t\t// Must null terminate macros.\n"; + $out .= "\t\tdefineMacros["; + $out .= scalar( @dynamicDefineNames ) + scalar( @staticDefineNames ); + $out .= "]"; + $out .= ".Name = NULL;\n"; + $out .= "\t\tdefineMacros["; + $out .= scalar( @dynamicDefineNames ) + scalar( @staticDefineNames ); + $out .= "]"; + $out .= ".Definition = NULL;\n\n"; + + + $out .= "\t\tLPD3DXBUFFER pShader; // NOTE: THESE LEAK!!!\n"; + $out .= "\t\tLPD3DXBUFFER pErrorMessages; // NOTE: THESE LEAK!!!\n"; + $out .= "\t\tHRESULT hr = D3DXCompileShaderFromFile( \"u:\\\\hl2_e3_2004\\\\src_e3_2004\\\\materialsystem\\\\stdshaders\\\\$fxc_filename\",\n\t\t\tdefineMacros,\n\t\t\tNULL, // LPD3DXINCLUDE \n\t\t\t\"main\",\n\t\t\t\"$type\",\n\t\t\t0, // DWORD Flags\n\t\t\t&pShader,\n\t\t\t&pErrorMessages,\n\t\t\tNULL // LPD3DXCONSTANTTABLE *ppConstantTable\n\t\t\t );\n"; + $out .= "\t\tif( hr != D3D_OK )\n"; + $out .= "\t\t{\n"; + $out .= "\t\t\tconst char *pErrorMessageString = ( const char * )pErrorMessages->GetBufferPointer();\n"; + $out .= "\t\t\tOutputDebugString( pErrorMessageString );\n"; + $out .= "\t\t\tOutputDebugString( \"\\n\" );\n"; + $out .= "\t\t\tAssert( 0 );\n"; + $out .= "\t\t\tstatic char blah[4] = { 0, 0, 0, 0 };\n"; + $out .= "\t\t\tbyteCode.m_pRawData = blah;\n"; + $out .= "\t\t\tbyteCode.m_nSizeInBytes = 4;\n"; + $out .= "\t\t}\n"; + $out .= "\t\telse\n"; + $out .= "\t\t{\n"; + $out .= "\t\t\tbyteCode.m_pRawData = pShader->GetBufferPointer();\n"; + $out .= "\t\t\tbyteCode.m_nSizeInBytes = pShader->GetBufferSize();\n"; + $out .= "\t\t}\n"; + $out .= "\t\treturn byteCode;\n"; + return $out; +} + +#print "--------\n"; + +if ( $g_x360 ) +{ + $fxctmp = "fxctmp9_360_tmp"; +} +else +{ + $fxctmp = "fxctmp9_tmp"; +} + +if( !stat $fxctmp ) +{ + mkdir $fxctmp, 0777 || die $!; +} + +# suck in an input file (using includes) +#print "$fxc_filename..."; +@fxc = ReadInputFile( $fxc_filename ); + +# READ THE TOP OF THE FILE TO FIND SHADER COMBOS +foreach $line ( @fxc ) +{ + $line="" if ($g_x360 && ($line=~/\[PC\]/)); # line marked as [PC] when building for x360 + $line="" if (($g_x360 == 0) && ($line=~/\[XBOX\]/)); # line marked as [XBOX] when building for pc + + if ( $fxc_basename =~ m/_ps(\d+\w?)$/i ) + { + my $psver = $1; + $line="" if (($line =~/\[ps\d+\w?\]/i) && ($line!~/\[ps$psver\]/i)); # line marked for a version of compiler and not what we build + } + if ( $fxc_basename =~ m/_vs(\d+\w?)$/i ) + { + my $vsver = $1; + $line="" if (($line =~/\[vs\d+\w?\]/i) && ($line!~/\[vs$vsver\]/i)); # line marked for a version of compiler and not what we build + } + + my $init_expr; + + $init_expr = $1 if ( $line=~/\[\=([^\]]+)\]/); # parse default init expression for combos + + $line=~s/\[[^\[\]]*\]//; # cut out all occurrences of + # square brackets and whatever is + # inside all these modifications + # to the line are seen later when + # processing skips and centroids + + next if( $line =~ m/^\s*$/ ); + + if( $line =~ m/^\s*\/\/\s*STATIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ ) + { + local( $name, $min, $max ); + $name = $1; + $min = $2; + $max = $3; + # print STDERR "STATIC: \"$name\" \"$min..$max\"\n"; + push @staticDefineNames, $name; + push @staticDefineMin, $min; + push @staticDefineMax, $max; + $staticDefineInit{$name}=$init_expr; + } + elsif( $line =~ m/^\s*\/\/\s*DYNAMIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ ) + { + local( $name, $min, $max ); + $name = $1; + $min = $2; + $max = $3; + # print STDERR "DYNAMIC: \"$name\" \"$min..$max\"\n"; + push @dynamicDefineNames, $name; + push @dynamicDefineMin, $min; + push @dynamicDefineMax, $max; + } +} +# READ THE WHOLE FILE AND FIND SKIP STATEMENTS +foreach $line ( @fxc ) +{ + if( $line =~ m/^\s*\/\/\s*SKIP\s*\s*\:\s*(.*)$/ ) + { + # print $1 . "\n"; + $perlskipcode .= "(" . $1 . ")||"; + push @perlskipcodeindividual, $1; + } +} + +if( defined $perlskipcode ) +{ + $perlskipcode .= "0"; + $perlskipcode =~ s/\n//g; +} +else +{ + $perlskipcode = "0"; +} + +# READ THE WHOLE FILE AND FIND CENTROID STATEMENTS +foreach $line ( @fxc ) +{ + if( $line =~ m/^\s*\/\/\s*CENTROID\s*\:\s*TEXCOORD(\d+)\s*$/ ) + { + $centroidEnable{$1} = 1; +# print "CENTROID: $1\n"; + } +} + +if( $spewCombos ) +{ + push @outputHeader, "#include \"windows.h\"\n"; +} + +#push @outputHeader, "\#include \"shaderlib\\baseshader.h\"\n"; +#push @outputHeader, "IShaderDynamicAPI *CBaseShader::s_pShaderAPI;\n"; + +# Go ahead an compute the mask of samplers that need to be centroid sampled +$centroidMask = 0; +foreach $centroidRegNum ( keys( %centroidEnable ) ) +{ +# print "THING: $samplerName $centroidRegNum\n"; + $centroidMask += 1 << $centroidRegNum; +} + +#printf "0x%x\n", $centroidMask; + +$numCombos = &CalcNumCombos(); +#print "$numCombos combos\n"; + + +if( $g_produceCompiledVcs && !$dynamic_compile ) +{ + open FOUT, ">>filelistgen.txt" || die "can't open filelistgen.txt"; + + print FOUT "**** generated by fxc_prep.pl ****\n"; + print FOUT "#BEGIN " . $fxc_basename . "\n"; + print FOUT "$fxc_filename" . "\n"; + print FOUT "#DEFINES-D:\n"; + for( $i = 0; $i < scalar( @dynamicDefineNames ); \$i++ ) + { + print FOUT "$dynamicDefineNames[$i]="; + print FOUT $dynamicDefineMin[$i]; + print FOUT ".."; + print FOUT $dynamicDefineMax[$i]; + print FOUT "\n"; + } + print FOUT "#DEFINES-S:\n"; + for( $i = 0; $i < scalar( @staticDefineNames ); \$i++ ) + { + print FOUT "$staticDefineNames[$i]="; + print FOUT $staticDefineMin[$i]; + print FOUT ".."; + print FOUT $staticDefineMax[$i]; + print FOUT "\n"; + } + print FOUT "#SKIP:\n"; + print FOUT "$perlskipcode\n"; + print FOUT "#COMMAND:\n"; + # first line + print FOUT "fxc.exe "; + print FOUT "/DTOTALSHADERCOMBOS=$numCombos "; + print FOUT "/DCENTROIDMASK=$centroidMask "; + print FOUT "/DNUMDYNAMICCOMBOS=" . &CalcNumDynamicCombos() . " "; + print FOUT "/DFLAGS=0x0 "; # Nothing here for now. + print FOUT "\n"; +#defines go here +# second line + print FOUT &RenameMain( $fxc_filename, $i ); + print FOUT "/T" . &GetShaderType( $fxc_filename ) . " "; + print FOUT "/DSHADER_MODEL_" . &ToUpper( &GetShaderType( $fxc_filename ) ) . "=1 "; + if( $nvidia ) + { + print FOUT "/DNV3X=1 "; # enable NV3X codepath + } + if ( $g_x360 ) + { + print FOUT "/D_X360=1 "; # shaders can identify X360 centric code + # print FOUT "/Xbe:2- "; # use the less-broken old back end + } + if( $debug ) + { + print FOUT "/Od "; # disable optimizations + print FOUT "/Zi "; # enable debug info + } +# print FOUT "/Zi "; # enable debug info + print FOUT "/nologo "; +# print FOUT "/Fhtmpshader.h "; + print FOUT "/Foshader.o "; + print FOUT "$fxc_filename"; + print FOUT ">output.txt 2>&1"; + print FOUT "\n"; + #end of command line + print FOUT "#END\n"; + print FOUT "**** end ****\n"; + + close FOUT; +} + +if ( $g_produceCppClasses ) +{ + # Write out the C++ helper class for picking shader combos + &WriteStaticHelperClasses(); + &WriteDynamicHelperClasses(); + my $incfilename = "$fxctmp\\$fxc_basename" . ".inc"; + &WriteFile( $incfilename, join( "", @outputHeader ) ); +} + + + +if( $generateListingFile ) +{ + my $listFileName = "$fxctmp/$fxc_basename" . ".lst"; + print "writing $listFileName\n"; + if( !open FILE, ">$listFileName" ) + { + die; + } + print FILE @listingOutput; + close FILE; +} + + +@endTimes = times; + +$endTime = time; + +#printf "Elapsed user time: %.2f seconds!\n", $endTimes[0] - $startTimes[0]; +#printf "Elapsed system time: %.2f seconds!\n", $endTimes[1] - $startTimes[1]; +#printf "Elapsed child user time: %.2f seconds!\n", $endTimes[2] - $startTimes[2]; +#printf "Elapsed child system time: %.2f seconds!\n", $endTimes[3] - $startTimes[3]; + +#printf "Elapsed total time: %.2f seconds!\n", $endTime - $startTime; + diff --git a/mp/src/devtools/bin/osx32/xcode_ccache_wrapper b/mp/src/devtools/bin/osx32/xcode_ccache_wrapper index 4f038475..475f508f 100755 --- a/mp/src/devtools/bin/osx32/xcode_ccache_wrapper +++ b/mp/src/devtools/bin/osx32/xcode_ccache_wrapper @@ -1,3 +1,3 @@ -#!/bin/bash
-
-exec $(dirname $0)/ccache "${DT_TOOLCHAIN_DIR}"/usr/bin/clang -Qunused-arguments "$@"
+#!/bin/bash + +exec $(dirname $0)/ccache "${DT_TOOLCHAIN_DIR}"/usr/bin/clang -Qunused-arguments "$@" diff --git a/mp/src/devtools/bin/psh_prep.pl b/mp/src/devtools/bin/psh_prep.pl index 5aa49c11..1c44c41d 100644 --- a/mp/src/devtools/bin/psh_prep.pl +++ b/mp/src/devtools/bin/psh_prep.pl @@ -1,333 +1,333 @@ -use String::CRC32;
-BEGIN {use File::Basename; push @INC, dirname($0); }
-require "valve_perl_helpers.pl";
-
-sub BuildDefineOptions
-{
- local( $output );
- local( $combo ) = shift;
- local( $i );
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- local( $val ) = ( $combo % ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) ) + $dynamicDefineMin[$i];
- $output .= "/D$dynamicDefineNames[$i]=$val ";
- $combo = $combo / ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 );
- }
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- local( $val ) = ( $combo % ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) ) + $staticDefineMin[$i];
- $output .= "/D$staticDefineNames[$i]=$val ";
- $combo = $combo / ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 );
- }
- return $output;
-}
-
-sub CalcNumCombos
-{
- local( $i, $numCombos );
- $numCombos = 1;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
- }
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- $numCombos *= $staticDefineMax[$i] - $staticDefineMin[$i] + 1;
- }
- return $numCombos;
-}
-
-sub CalcNumDynamicCombos
-{
- local( $i, $numCombos );
- $numCombos = 1;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
- }
- return $numCombos;
-}
-
-$g_dx9 = 1;
-
-while( 1 )
-{
- $psh_filename = shift;
-
- if( $psh_filename =~ m/-source/ )
- {
- $g_SourceDir = shift;
- }
- elsif( $psh_filename =~ m/-x360/ )
- {
- $g_x360 = 1;
- }
- else
- {
- last;
- }
-}
-
-$psh_filename =~ s/-----.*$//;
-
-
-# Get the shader binary version number from a header file.
-open FILE, "<$g_SourceDir\\public\\materialsystem\\shader_vcs_version.h" || die;
-while( $line = <FILE> )
-{
- if( $line =~ m/^\#define\s+SHADER_VCS_VERSION_NUMBER\s+(\d+)\s*$/ )
- {
- $shaderVersion = $1;
- last;
- }
-}
-if( !defined $shaderVersion )
-{
- die "couldn't get shader version from shader_vcs_version.h";
-}
-close FILE;
-
-
-
-local( @staticDefineNames );
-local( @staticDefineMin );
-local( @staticDefineMax );
-local( @dynamicDefineNames );
-local( @dynamicDefineMin );
-local( @dynamicDefineMax );
-
-# Parse the combos.
-open PSH, "<$psh_filename";
-while( <PSH> )
-{
- last if( !m,^;, );
- s,^;\s*,,;
- if( m/\s*STATIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ )
- {
- local( $name, $min, $max );
- $name = $1;
- $min = $2;
- $max = $3;
-# print "\"STATIC: $name\" \"$min..$max\"\n";
- if (/\[(.*)\]/)
- {
- $platforms=$1;
- next if ( ($g_x360) && (!($platforms=~/XBOX/i)) );
- next if ( (!$g_x360) && (!($platforms=~/PC/i)) );
- }
- push @staticDefineNames, $name;
- push @staticDefineMin, $min;
- push @staticDefineMax, $max;
- }
- elsif( m/\s*DYNAMIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ )
- {
- local( $name, $min, $max );
- $name = $1;
- $min = $2;
- $max = $3;
-# print "\"DYNAMIC: $name\" \"$min..$max\"\n";
- if (/\[(.*)\]/)
- {
- $platforms=$1;
- next if ( ($g_x360) && (!($platforms=~/XBOX/i)) );
- next if ( (!$g_x360) && (!($platforms=~/PC/i)) );
- }
- push @dynamicDefineNames, $name;
- push @dynamicDefineMin, $min;
- push @dynamicDefineMax, $max;
- }
-}
-close PSH;
-
-$numCombos = &CalcNumCombos();
-$numDynamicCombos = &CalcNumDynamicCombos();
-print "$psh_filename\n";
-#print "$numCombos combos\n";
-#print "$numDynamicCombos dynamic combos\n";
-
-if( $g_x360 )
-{
- $pshtmp = "pshtmp9_360";
-}
-elsif( $g_dx9 )
-{
- $pshtmp = "pshtmp9";
-}
-else
-{
- $pshtmp = "pshtmp8";
-}
-$basename = $psh_filename;
-$basename =~ s/\.psh$//i;
-
-for( $shaderCombo = 0; $shaderCombo < $numCombos; $shaderCombo++ )
-{
- my $tempFilename = "shader$shaderCombo.o";
- unlink $tempFilename;
-
- if( $g_x360 )
- {
- $cmd = "$g_SourceDir\\x360xdk\\bin\\win32\\psa /D_X360=1 /Foshader$shaderCombo.o /nologo " . &BuildDefineOptions( $shaderCombo ) . "$psh_filename > NIL";
- }
- else
- {
- $cmd = "$g_SourceDir\\dx9sdk\\utilities\\psa /Foshader$shaderCombo.o /nologo " . &BuildDefineOptions( $shaderCombo ) . "$psh_filename > NIL";
- }
-
- if( !stat $pshtmp )
- {
- mkdir $pshtmp, 0777 || die $!;
- }
-
-# print $cmd . "\n";
- system $cmd || die $!;
-
- # Make sure a file got generated because sometimes the die above won't happen on compile errors.
- my $filesize = (stat $tempFilename)[7];
- if ( !$filesize )
- {
- die "Error compiling shader$shaderCombo.o";
- }
-
- push @outputHeader, @hdr;
-}
-
-$basename =~ s/\.fxc//gi;
-push @outputHeader, "static PrecompiledShaderByteCode_t " . $basename . "_pixel_shaders[" . $numCombos . "] = \n";
-push @outputHeader, "{\n";
-local( $j );
-for( $j = 0; $j < $numCombos; $j++ )
-{
- local( $thing ) = "pixelShader_" . $basename . "_" . $j;
- push @outputHeader, "\t{ " . "$thing, sizeof( $thing ) },\n";
-}
-push @outputHeader, "};\n";
-
-push @outputHeader, "struct $basename" . "PixelShader_t : public PrecompiledShader_t\n";
-push @outputHeader, "{\n";
-push @outputHeader, "\t$basename" . "PixelShader_t()\n";
-push @outputHeader, "\t{\n";
-push @outputHeader, "\t\tm_nFlags = 0;\n";
-push @outputHeader, "\t\tm_pByteCode = " . $basename . "_pixel_shaders;\n";
-push @outputHeader, "\t\tm_nShaderCount = $numCombos;\n";
-#push @outputHeader, "\t\tm_nDynamicCombos = m_nShaderCount;\n";
-push @outputHeader, "\t\t// NOTE!!! psh_prep.pl shaders are always static combos!\n";
-push @outputHeader, "\t\tm_nDynamicCombos = 1;\n";
-push @outputHeader, "\t\tm_pName = \"$basename\";\n";
-if( $basename =~ /vs\d\d/ ) # hack
-{
- push @outputHeader, "\t\tGetShaderDLL()->InsertPrecompiledShader( PRECOMPILED_VERTEX_SHADER, this );\n";
-}
-else
-{
- push @outputHeader, "\t\tGetShaderDLL()->InsertPrecompiledShader( PRECOMPILED_PIXEL_SHADER, this );\n";
-}
-push @outputHeader, "\t}\n";
-push @outputHeader, "\tvirtual const PrecompiledShaderByteCode_t &GetByteCode( int shaderID )\n";
-push @outputHeader, "\t{\n";
-push @outputHeader, "\t\treturn m_pByteCode[shaderID];\n";
-push @outputHeader, "\t}\n";
-push @outputHeader, "};\n";
-
-push @outputHeader, "static $basename" . "PixelShader_t $basename" . "_PixelShaderInstance;\n";
-
-
-&MakeDirHier( "shaders/psh" );
-
-my $vcsName = "";
-if( $g_x360 )
-{
- $vcsName = $basename . ".360.vcs";
-}
-else
-{
- $vcsName = $basename . ".vcs";
-}
-
-open COMPILEDSHADER, ">shaders/psh/$vcsName" || die;
-binmode( COMPILEDSHADER );
-
-#
-# Write out the part of the header that we know. . we'll write the rest after writing the object code.
-#
-
-#print $numCombos . "\n";
-
-# Pack arguments
-my $sInt = "i";
-my $uInt = "I";
-if ( $g_x360 )
-{
- # Change arguments to "big endian long"
- $sInt = "N";
- $uInt = "N";
-}
-
-open PSH, "<$psh_filename";
-my $crc = crc32( *PSH );
-close PSH;
-#print STDERR "crc for $psh_filename: $crc\n";
-
-# version
-print COMPILEDSHADER pack $sInt, 4;
-# totalCombos
-print COMPILEDSHADER pack $sInt, $numCombos;
-# dynamic combos
-print COMPILEDSHADER pack $sInt, $numDynamicCombos;
-# flags
-print COMPILEDSHADER pack $uInt, 0x0; # nothing here for now.
-# centroid mask
-print COMPILEDSHADER pack $uInt, 0;
-# reference size for diffs
-print COMPILEDSHADER pack $uInt, 0;
-# crc32 of the source code
-print COMPILEDSHADER pack $uInt, $crc;
-
-my $beginningOfDir = tell COMPILEDSHADER;
-
-# Write out a blank directionary. . we'll fill it in later.
-for( $i = 0; $i < $numCombos; $i++ )
-{
- # offset from beginning of file.
- print COMPILEDSHADER pack $sInt, 0;
- # size
- print COMPILEDSHADER pack $sInt, 0;
-}
-
-my $startByteCode = tell COMPILEDSHADER;
-my @byteCodeStart;
-my @byteCodeSize;
-
-# Write out the shader object code.
-for( $shaderCombo = 0; $shaderCombo < $numCombos; $shaderCombo++ )
-{
- my $filename = "shader$shaderCombo\.o";
- my $filesize = (stat $filename)[7];
-
- $byteCodeStart[$shaderCombo] = tell COMPILEDSHADER;
- $byteCodeSize[$shaderCombo] = $filesize;
- open SHADERBYTECODE, "<$filename";
- binmode SHADERBYTECODE;
-
- my $bin;
- my $numread = read SHADERBYTECODE, $bin, $filesize;
-# print "filename: $filename numread: $numread filesize: $filesize\n";
- close SHADERBYTECODE;
- unlink $filename;
-
- print COMPILEDSHADER $bin;
-}
-
-# Seek back to the directory and write it out.
-seek COMPILEDSHADER, $beginningOfDir, 0;
-for( $i = 0; $i < $numCombos; $i++ )
-{
- # offset from beginning of file.
- print COMPILEDSHADER pack $sInt, $byteCodeStart[$i];
- # size
- print COMPILEDSHADER pack $sInt, $byteCodeSize[$i];
-}
-
-close COMPILEDSHADER;
-
-
+use String::CRC32; +BEGIN {use File::Basename; push @INC, dirname($0); } +require "valve_perl_helpers.pl"; + +sub BuildDefineOptions +{ + local( $output ); + local( $combo ) = shift; + local( $i ); + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + local( $val ) = ( $combo % ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) ) + $dynamicDefineMin[$i]; + $output .= "/D$dynamicDefineNames[$i]=$val "; + $combo = $combo / ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ); + } + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + local( $val ) = ( $combo % ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) ) + $staticDefineMin[$i]; + $output .= "/D$staticDefineNames[$i]=$val "; + $combo = $combo / ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ); + } + return $output; +} + +sub CalcNumCombos +{ + local( $i, $numCombos ); + $numCombos = 1; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1; + } + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + $numCombos *= $staticDefineMax[$i] - $staticDefineMin[$i] + 1; + } + return $numCombos; +} + +sub CalcNumDynamicCombos +{ + local( $i, $numCombos ); + $numCombos = 1; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1; + } + return $numCombos; +} + +$g_dx9 = 1; + +while( 1 ) +{ + $psh_filename = shift; + + if( $psh_filename =~ m/-source/ ) + { + $g_SourceDir = shift; + } + elsif( $psh_filename =~ m/-x360/ ) + { + $g_x360 = 1; + } + else + { + last; + } +} + +$psh_filename =~ s/-----.*$//; + + +# Get the shader binary version number from a header file. +open FILE, "<$g_SourceDir\\public\\materialsystem\\shader_vcs_version.h" || die; +while( $line = <FILE> ) +{ + if( $line =~ m/^\#define\s+SHADER_VCS_VERSION_NUMBER\s+(\d+)\s*$/ ) + { + $shaderVersion = $1; + last; + } +} +if( !defined $shaderVersion ) +{ + die "couldn't get shader version from shader_vcs_version.h"; +} +close FILE; + + + +local( @staticDefineNames ); +local( @staticDefineMin ); +local( @staticDefineMax ); +local( @dynamicDefineNames ); +local( @dynamicDefineMin ); +local( @dynamicDefineMax ); + +# Parse the combos. +open PSH, "<$psh_filename"; +while( <PSH> ) +{ + last if( !m,^;, ); + s,^;\s*,,; + if( m/\s*STATIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ ) + { + local( $name, $min, $max ); + $name = $1; + $min = $2; + $max = $3; +# print "\"STATIC: $name\" \"$min..$max\"\n"; + if (/\[(.*)\]/) + { + $platforms=$1; + next if ( ($g_x360) && (!($platforms=~/XBOX/i)) ); + next if ( (!$g_x360) && (!($platforms=~/PC/i)) ); + } + push @staticDefineNames, $name; + push @staticDefineMin, $min; + push @staticDefineMax, $max; + } + elsif( m/\s*DYNAMIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ ) + { + local( $name, $min, $max ); + $name = $1; + $min = $2; + $max = $3; +# print "\"DYNAMIC: $name\" \"$min..$max\"\n"; + if (/\[(.*)\]/) + { + $platforms=$1; + next if ( ($g_x360) && (!($platforms=~/XBOX/i)) ); + next if ( (!$g_x360) && (!($platforms=~/PC/i)) ); + } + push @dynamicDefineNames, $name; + push @dynamicDefineMin, $min; + push @dynamicDefineMax, $max; + } +} +close PSH; + +$numCombos = &CalcNumCombos(); +$numDynamicCombos = &CalcNumDynamicCombos(); +print "$psh_filename\n"; +#print "$numCombos combos\n"; +#print "$numDynamicCombos dynamic combos\n"; + +if( $g_x360 ) +{ + $pshtmp = "pshtmp9_360"; +} +elsif( $g_dx9 ) +{ + $pshtmp = "pshtmp9"; +} +else +{ + $pshtmp = "pshtmp8"; +} +$basename = $psh_filename; +$basename =~ s/\.psh$//i; + +for( $shaderCombo = 0; $shaderCombo < $numCombos; $shaderCombo++ ) +{ + my $tempFilename = "shader$shaderCombo.o"; + unlink $tempFilename; + + if( $g_x360 ) + { + $cmd = "$g_SourceDir\\x360xdk\\bin\\win32\\psa /D_X360=1 /Foshader$shaderCombo.o /nologo " . &BuildDefineOptions( $shaderCombo ) . "$psh_filename > NIL"; + } + else + { + $cmd = "$g_SourceDir\\dx9sdk\\utilities\\psa /Foshader$shaderCombo.o /nologo " . &BuildDefineOptions( $shaderCombo ) . "$psh_filename > NIL"; + } + + if( !stat $pshtmp ) + { + mkdir $pshtmp, 0777 || die $!; + } + +# print $cmd . "\n"; + system $cmd || die $!; + + # Make sure a file got generated because sometimes the die above won't happen on compile errors. + my $filesize = (stat $tempFilename)[7]; + if ( !$filesize ) + { + die "Error compiling shader$shaderCombo.o"; + } + + push @outputHeader, @hdr; +} + +$basename =~ s/\.fxc//gi; +push @outputHeader, "static PrecompiledShaderByteCode_t " . $basename . "_pixel_shaders[" . $numCombos . "] = \n"; +push @outputHeader, "{\n"; +local( $j ); +for( $j = 0; $j < $numCombos; $j++ ) +{ + local( $thing ) = "pixelShader_" . $basename . "_" . $j; + push @outputHeader, "\t{ " . "$thing, sizeof( $thing ) },\n"; +} +push @outputHeader, "};\n"; + +push @outputHeader, "struct $basename" . "PixelShader_t : public PrecompiledShader_t\n"; +push @outputHeader, "{\n"; +push @outputHeader, "\t$basename" . "PixelShader_t()\n"; +push @outputHeader, "\t{\n"; +push @outputHeader, "\t\tm_nFlags = 0;\n"; +push @outputHeader, "\t\tm_pByteCode = " . $basename . "_pixel_shaders;\n"; +push @outputHeader, "\t\tm_nShaderCount = $numCombos;\n"; +#push @outputHeader, "\t\tm_nDynamicCombos = m_nShaderCount;\n"; +push @outputHeader, "\t\t// NOTE!!! psh_prep.pl shaders are always static combos!\n"; +push @outputHeader, "\t\tm_nDynamicCombos = 1;\n"; +push @outputHeader, "\t\tm_pName = \"$basename\";\n"; +if( $basename =~ /vs\d\d/ ) # hack +{ + push @outputHeader, "\t\tGetShaderDLL()->InsertPrecompiledShader( PRECOMPILED_VERTEX_SHADER, this );\n"; +} +else +{ + push @outputHeader, "\t\tGetShaderDLL()->InsertPrecompiledShader( PRECOMPILED_PIXEL_SHADER, this );\n"; +} +push @outputHeader, "\t}\n"; +push @outputHeader, "\tvirtual const PrecompiledShaderByteCode_t &GetByteCode( int shaderID )\n"; +push @outputHeader, "\t{\n"; +push @outputHeader, "\t\treturn m_pByteCode[shaderID];\n"; +push @outputHeader, "\t}\n"; +push @outputHeader, "};\n"; + +push @outputHeader, "static $basename" . "PixelShader_t $basename" . "_PixelShaderInstance;\n"; + + +&MakeDirHier( "shaders/psh" ); + +my $vcsName = ""; +if( $g_x360 ) +{ + $vcsName = $basename . ".360.vcs"; +} +else +{ + $vcsName = $basename . ".vcs"; +} + +open COMPILEDSHADER, ">shaders/psh/$vcsName" || die; +binmode( COMPILEDSHADER ); + +# +# Write out the part of the header that we know. . we'll write the rest after writing the object code. +# + +#print $numCombos . "\n"; + +# Pack arguments +my $sInt = "i"; +my $uInt = "I"; +if ( $g_x360 ) +{ + # Change arguments to "big endian long" + $sInt = "N"; + $uInt = "N"; +} + +open PSH, "<$psh_filename"; +my $crc = crc32( *PSH ); +close PSH; +#print STDERR "crc for $psh_filename: $crc\n"; + +# version +print COMPILEDSHADER pack $sInt, 4; +# totalCombos +print COMPILEDSHADER pack $sInt, $numCombos; +# dynamic combos +print COMPILEDSHADER pack $sInt, $numDynamicCombos; +# flags +print COMPILEDSHADER pack $uInt, 0x0; # nothing here for now. +# centroid mask +print COMPILEDSHADER pack $uInt, 0; +# reference size for diffs +print COMPILEDSHADER pack $uInt, 0; +# crc32 of the source code +print COMPILEDSHADER pack $uInt, $crc; + +my $beginningOfDir = tell COMPILEDSHADER; + +# Write out a blank directionary. . we'll fill it in later. +for( $i = 0; $i < $numCombos; $i++ ) +{ + # offset from beginning of file. + print COMPILEDSHADER pack $sInt, 0; + # size + print COMPILEDSHADER pack $sInt, 0; +} + +my $startByteCode = tell COMPILEDSHADER; +my @byteCodeStart; +my @byteCodeSize; + +# Write out the shader object code. +for( $shaderCombo = 0; $shaderCombo < $numCombos; $shaderCombo++ ) +{ + my $filename = "shader$shaderCombo\.o"; + my $filesize = (stat $filename)[7]; + + $byteCodeStart[$shaderCombo] = tell COMPILEDSHADER; + $byteCodeSize[$shaderCombo] = $filesize; + open SHADERBYTECODE, "<$filename"; + binmode SHADERBYTECODE; + + my $bin; + my $numread = read SHADERBYTECODE, $bin, $filesize; +# print "filename: $filename numread: $numread filesize: $filesize\n"; + close SHADERBYTECODE; + unlink $filename; + + print COMPILEDSHADER $bin; +} + +# Seek back to the directory and write it out. +seek COMPILEDSHADER, $beginningOfDir, 0; +for( $i = 0; $i < $numCombos; $i++ ) +{ + # offset from beginning of file. + print COMPILEDSHADER pack $sInt, $byteCodeStart[$i]; + # size + print COMPILEDSHADER pack $sInt, $byteCodeSize[$i]; +} + +close COMPILEDSHADER; + + diff --git a/mp/src/devtools/bin/shaderinfo.pl b/mp/src/devtools/bin/shaderinfo.pl index ae0b96c8..57a81578 100644 --- a/mp/src/devtools/bin/shaderinfo.pl +++ b/mp/src/devtools/bin/shaderinfo.pl @@ -1,36 +1,36 @@ -#! perl
-
-my $fname=shift || die "format is shaderinfo blah.vcs";
-
-open(SHADER, $fname) || die "can't open $fname";
-binmode SHADER;
-
-read(SHADER,$header,20);
-($ver,$ntotal,$ndynamic,$flags,$centroidmask)=unpack("LLLLL",$header);
-
-#print "Version $ver total combos=$ntotal, num dynamic combos=$ndynamic,\n flags=$flags, centroid mask=$centroidmask\n";
-
-read(SHADER,$refsize,4);
-$refsize=unpack("L",$refsize);
-#print "Size of reference shader for diffing=$refsize\n";
-
-seek(SHADER,$refsize,1);
-
-$nskipped_combos=0;
-for(1..$ntotal)
- {
- read(SHADER,$combodata,8);
- ($ofs,$combosize)=unpack("LL",$combodata);
- if ( $ofs == 0xffffffff)
- {
- $nskipped_combos++;
- }
- else
- {
- }
- }
-#print "$nskipped_combos skipped, for an actual total of ",$ntotal-$nskipped_combos,"\n";
-#print "Real to skipped ratio = ",($ntotal-$nskipped_combos)/$ntotal,"\n";
-# csv output - name, real combos, virtual combos, dynamic combos
-my $real_combos=$ntotal-$nskipped_combos;
-print "$fname,$real_combos,$ntotal,$ndynamic\n";
+#! perl + +my $fname=shift || die "format is shaderinfo blah.vcs"; + +open(SHADER, $fname) || die "can't open $fname"; +binmode SHADER; + +read(SHADER,$header,20); +($ver,$ntotal,$ndynamic,$flags,$centroidmask)=unpack("LLLLL",$header); + +#print "Version $ver total combos=$ntotal, num dynamic combos=$ndynamic,\n flags=$flags, centroid mask=$centroidmask\n"; + +read(SHADER,$refsize,4); +$refsize=unpack("L",$refsize); +#print "Size of reference shader for diffing=$refsize\n"; + +seek(SHADER,$refsize,1); + +$nskipped_combos=0; +for(1..$ntotal) + { + read(SHADER,$combodata,8); + ($ofs,$combosize)=unpack("LL",$combodata); + if ( $ofs == 0xffffffff) + { + $nskipped_combos++; + } + else + { + } + } +#print "$nskipped_combos skipped, for an actual total of ",$ntotal-$nskipped_combos,"\n"; +#print "Real to skipped ratio = ",($ntotal-$nskipped_combos)/$ntotal,"\n"; +# csv output - name, real combos, virtual combos, dynamic combos +my $real_combos=$ntotal-$nskipped_combos; +print "$fname,$real_combos,$ntotal,$ndynamic\n"; diff --git a/mp/src/devtools/bin/splitdiff3.pl b/mp/src/devtools/bin/splitdiff3.pl index e38b493a..ccba3a95 100644 --- a/mp/src/devtools/bin/splitdiff3.pl +++ b/mp/src/devtools/bin/splitdiff3.pl @@ -1,54 +1,54 @@ -$infilename = shift;
-$outfilename1 = shift;
-$outfilename2 = shift;
-open INPUT, $infilename || die;
-@input = <INPUT>;
-close INPUT;
-
-open MERGEDMINE, ">$outfilename1" || die;
-open MERGEDTHEIRS, ">$outfilename2" || die;
-
-for( $i = 0; $i < scalar( @input ); $i++ )
-{
- $line = $input[$i];
-
- if( $line =~ m/^(.*)<<<<<<</ )
- {
- $first = 1;
- $second = 0;
- print MERGEDMINE $1;
- print MERGEDTHEIRS $1;
- next;
- }
- # Make sure that we are in a split block so that comments with ======= don't mess us up.
- if( $line =~ m/^(.*)=======$/ && $first == 1 )
- {
- $first = 0;
- $second = 1;
- print MERGEDMINE $1;
- next;
- }
- if( $line =~ m/^(.*)>>>>>>>/ )
- {
- $first = $second = 0;
- print MERGEDTHEIRS $1;
- next;
- }
-
- if( $first )
- {
- print MERGEDMINE $line;
- }
- elsif( $second )
- {
- print MERGEDTHEIRS $line;
- }
- else
- {
- print MERGEDMINE $line;
- print MERGEDTHEIRS $line;
- }
-}
-
-close MERGEDMINE;
-close MERGEDTHEIRS;
+$infilename = shift; +$outfilename1 = shift; +$outfilename2 = shift; +open INPUT, $infilename || die; +@input = <INPUT>; +close INPUT; + +open MERGEDMINE, ">$outfilename1" || die; +open MERGEDTHEIRS, ">$outfilename2" || die; + +for( $i = 0; $i < scalar( @input ); $i++ ) +{ + $line = $input[$i]; + + if( $line =~ m/^(.*)<<<<<<</ ) + { + $first = 1; + $second = 0; + print MERGEDMINE $1; + print MERGEDTHEIRS $1; + next; + } + # Make sure that we are in a split block so that comments with ======= don't mess us up. + if( $line =~ m/^(.*)=======$/ && $first == 1 ) + { + $first = 0; + $second = 1; + print MERGEDMINE $1; + next; + } + if( $line =~ m/^(.*)>>>>>>>/ ) + { + $first = $second = 0; + print MERGEDTHEIRS $1; + next; + } + + if( $first ) + { + print MERGEDMINE $line; + } + elsif( $second ) + { + print MERGEDTHEIRS $line; + } + else + { + print MERGEDMINE $line; + print MERGEDTHEIRS $line; + } +} + +close MERGEDMINE; +close MERGEDTHEIRS; diff --git a/mp/src/devtools/bin/uniqifylist.pl b/mp/src/devtools/bin/uniqifylist.pl index d8d40afd..1c3fd9c9 100644 --- a/mp/src/devtools/bin/uniqifylist.pl +++ b/mp/src/devtools/bin/uniqifylist.pl @@ -1,6 +1,6 @@ -foreach $_ (sort <> )
-{
- next if( defined( $prevline ) && $_ eq $prevline );
- $prevline = $_;
- print;
-}
+foreach $_ (sort <> ) +{ + next if( defined( $prevline ) && $_ eq $prevline ); + $prevline = $_; + print; +} diff --git a/mp/src/devtools/bin/updateshaders.pl b/mp/src/devtools/bin/updateshaders.pl index 005e96a0..93f57ffd 100644 --- a/mp/src/devtools/bin/updateshaders.pl +++ b/mp/src/devtools/bin/updateshaders.pl @@ -1,305 +1,305 @@ -use String::CRC32;
-BEGIN {use File::Basename; push @INC, dirname($0); }
-require "valve_perl_helpers.pl";
-
-$dynamic_compile = defined $ENV{"dynamic_shaders"} && $ENV{"dynamic_shaders"} != 0;
-
-$depnum = 0;
-$baseSourceDir = ".";
-
-my %dep;
-
-sub GetAsmShaderDependencies_R
-{
- local( $shadername ) = shift;
- local( *SHADER );
-
- open SHADER, "<$shadername";
- while( <SHADER> )
- {
- if( m/^\s*\#\s*include\s+\"(.*)\"/ )
- {
- # make sure it isn't in there already.
- if( !defined( $dep{$1} ) )
- {
- $dep{$1} = 1;
- GetAsmShaderDependencies_R( $1 );
- }
- }
- }
- close SHADER;
-}
-
-sub GetAsmShaderDependencies
-{
- local( $shadername ) = shift;
- undef %dep;
- GetAsmShaderDependencies_R( $shadername );
-# local( $i );
-# foreach $i ( keys( %dep ) )
-# {
-# print "$shadername depends on $i\n";
-# }
- return keys( %dep );
-}
-
-sub GetShaderType
-{
- my $shadername = shift;
- my $shadertype;
- if( $shadername =~ m/\.vsh/i )
- {
- $shadertype = "vsh";
- }
- elsif( $shadername =~ m/\.psh/i )
- {
- $shadertype = "psh";
- }
- elsif( $shadername =~ m/\.fxc/i )
- {
- $shadertype = "fxc";
- }
- else
- {
- die;
- }
- return $shadertype;
-}
-
-sub GetShaderSrc
-{
- my $shadername = shift;
- if ( $shadername =~ m/^(.*)-----/i )
- {
- return $1;
- }
- else
- {
- return $shadername;
- }
-}
-
-sub GetShaderBase
-{
- my $shadername = shift;
- if ( $shadername =~ m/-----(.*)$/i )
- {
- return $1;
- }
- else
- {
- my $shadertype = &GetShaderType( $shadername );
- $shadername =~ s/\.$shadertype//i;
- return $shadername;
- }
-}
-
-sub DoAsmShader
-{
- my $argstring = shift;
- my $shadername = &GetShaderSrc( $argstring );
- my $shaderbase = &GetShaderBase( $argstring );
- my $shadertype = &GetShaderType( $argstring );
- my $incfile = "";
- if( $shadertype eq "fxc" || $shadertype eq "vsh" )
- {
- $incfile = $shadertype . "tmp9" . $g_tmpfolder . "\\$shaderbase.inc ";
- }
-
- my $vcsfile = $shaderbase . $g_vcsext;
- my $bWillCompileVcs = 1;
- if( ( $shadertype eq "fxc") && $dynamic_compile )
- {
- $bWillCompileVcs = 0;
- }
- if( $shadercrcpass{$argstring} )
- {
- $bWillCompileVcs = 0;
- }
-
- if( $bWillCompileVcs )
- {
- &output_makefile_line( $incfile . "shaders\\$shadertype\\$vcsfile: $shadername @dep\n") ;
- }
- else
- {
- # psh files don't need a rule at this point since they don't have inc files and we aren't compiling a vcs.
- if( $shadertype eq "fxc" || $shadertype eq "vsh" )
- {
- &output_makefile_line( $incfile . ": $shadername @dep\n") ;
- }
- }
-
-
- my $x360switch = "";
- my $moreswitches = "";
- if( !$bWillCompileVcs && $shadertype eq "fxc" )
- {
- $moreswitches .= "-novcs ";
- }
- if( $g_x360 )
- {
- $x360switch = "-x360";
-
- if( $bWillCompileVcs && ( $shaderbase =~ m/_ps20$/i ) )
- {
- $moreswitches .= "-novcs ";
- $bWillCompileVcs = 0;
- }
- }
-
- # if we are psh and we are compiling the vcs, we don't need this rule.
- if( !( $shadertype eq "psh" && !$bWillCompileVcs ) )
- {
- &output_makefile_line( "\tperl $g_SourceDir\\devtools\\bin\\" . $shadertype . "_prep.pl $moreswitches $x360switch -source \"$g_SourceDir\" $argstring\n") ;
- }
-
- if( $bWillCompileVcs )
- {
- &output_makefile_line( "\techo $shadername>> filestocopy.txt\n") ;
- my $dep;
- foreach $dep( @dep )
- {
- &output_makefile_line( "\techo $dep>> filestocopy.txt\n") ;
- }
- }
- &output_makefile_line( "\n") ;
-}
-
-if( scalar( @ARGV ) == 0 )
-{
- die "Usage updateshaders.pl shaderprojectbasename\n\tie: updateshaders.pl stdshaders_dx6\n";
-}
-
-$g_x360 = 0;
-$g_tmpfolder = "_tmp";
-$g_vcsext = ".vcs";
-
-while( 1 )
-{
- $inputbase = shift;
-
- if( $inputbase =~ m/-source/ )
- {
- $g_SourceDir = shift;
- }
- elsif( $inputbase =~ m/-x360/ )
- {
- $g_x360 = 1;
- $g_tmpfolder = "_360_tmp";
- $g_vcsext = ".360.vcs";
- }
- elsif( $inputbase =~ m/-execute/ )
- {
- $g_execute = 1;
- }
- elsif( $inputbase =~ m/-nv3x/ )
- {
- $nv3x = 1;
- }
- else
- {
- last;
- }
-}
-
-my @srcfiles = &LoadShaderListFile( $inputbase );
-
-open MAKEFILE, ">makefile\.$inputbase";
-open COPYFILE, ">makefile\.$inputbase\.copy";
-open INCLIST, ">inclist.txt";
-open VCSLIST, ">vcslist.txt";
-
-# make a default dependency that depends on all of the shaders.
-&output_makefile_line( "default: ") ;
-foreach $shader ( @srcfiles )
-{
- my $shadertype = &GetShaderType( $shader );
- my $shaderbase = &GetShaderBase( $shader );
- my $shadersrc = &GetShaderSrc( $shader );
- if( $shadertype eq "fxc" || $shadertype eq "vsh" )
- {
- # We only generate inc files for fxc and vsh files.
- my $incFileName = "$shadertype" . "tmp9" . $g_tmpfolder . "\\" . $shaderbase . "\.inc";
- &output_makefile_line( " $incFileName" );
- &output_inclist_line( "$incFileName\n" );
- }
-
- my $vcsfile = $shaderbase . $g_vcsext;
-
- my $compilevcs = 1;
- if( $shadertype eq "fxc" && $dynamic_compile )
- {
- $compilevcs = 0;
- }
- if( $g_x360 && ( $shaderbase =~ m/_ps20$/i ) )
- {
- $compilevcs = 0;
- }
- if( $compilevcs )
- {
- my $vcsFileName = "..\\..\\..\\game\\hl2\\shaders\\$shadertype\\$shaderbase" . $g_vcsext;
- # We want to check for perforce operations even if the crc matches in the event that a file has been manually reverted and needs to be checked out again.
- &output_vcslist_line( "$vcsFileName\n" );
- $shadercrcpass{$shader} = &CheckCRCAgainstTarget( $shadersrc, $vcsFileName, 0 );
- if( $shadercrcpass{$shader} )
- {
- $compilevcs = 0;
- }
- }
- if( $compilevcs )
- {
- &output_makefile_line( " shaders\\$shadertype\\$vcsfile" );
- # emit a list of vcs files to copy to the target since we want to build them.
- &output_copyfile_line( GetShaderSrc($shader) . "-----" . GetShaderBase($shader) . "\n" );
- }
-}
-&output_makefile_line( "\n\n") ;
-
-# Insert all of our vertex shaders and depencencies
-$lastshader = "";
-foreach $shader ( @srcfiles )
-{
- my $currentshader = &GetShaderSrc( $shader );
- if ( $lastshader ne $currentshader )
- {
- $lastshader = $currentshader;
- @dep = &GetAsmShaderDependencies( $lastshader );
- }
- &DoAsmShader( $shader );
-}
-close VCSLIST;
-close INCLIST;
-close COPYFILE;
-close MAKEFILE;
-
-# nuke the copyfile if it is zero length
-if( ( stat "makefile\.$inputbase\.copy" )[7] == 0 )
-{
- unlink "makefile\.$inputbase\.copy";
-}
-
-sub output_makefile_line
-{
- local ($_)=@_;
- print MAKEFILE $_;
-}
-
-sub output_copyfile_line
-{
- local ($_)=@_;
- print COPYFILE $_;
-}
-
-sub output_vcslist_line
-{
- local ($_)=@_;
- print VCSLIST $_;
-}
-
-sub output_inclist_line
-{
- local ($_)=@_;
- print INCLIST $_;
-}
-
+use String::CRC32; +BEGIN {use File::Basename; push @INC, dirname($0); } +require "valve_perl_helpers.pl"; + +$dynamic_compile = defined $ENV{"dynamic_shaders"} && $ENV{"dynamic_shaders"} != 0; + +$depnum = 0; +$baseSourceDir = "."; + +my %dep; + +sub GetAsmShaderDependencies_R +{ + local( $shadername ) = shift; + local( *SHADER ); + + open SHADER, "<$shadername"; + while( <SHADER> ) + { + if( m/^\s*\#\s*include\s+\"(.*)\"/ ) + { + # make sure it isn't in there already. + if( !defined( $dep{$1} ) ) + { + $dep{$1} = 1; + GetAsmShaderDependencies_R( $1 ); + } + } + } + close SHADER; +} + +sub GetAsmShaderDependencies +{ + local( $shadername ) = shift; + undef %dep; + GetAsmShaderDependencies_R( $shadername ); +# local( $i ); +# foreach $i ( keys( %dep ) ) +# { +# print "$shadername depends on $i\n"; +# } + return keys( %dep ); +} + +sub GetShaderType +{ + my $shadername = shift; + my $shadertype; + if( $shadername =~ m/\.vsh/i ) + { + $shadertype = "vsh"; + } + elsif( $shadername =~ m/\.psh/i ) + { + $shadertype = "psh"; + } + elsif( $shadername =~ m/\.fxc/i ) + { + $shadertype = "fxc"; + } + else + { + die; + } + return $shadertype; +} + +sub GetShaderSrc +{ + my $shadername = shift; + if ( $shadername =~ m/^(.*)-----/i ) + { + return $1; + } + else + { + return $shadername; + } +} + +sub GetShaderBase +{ + my $shadername = shift; + if ( $shadername =~ m/-----(.*)$/i ) + { + return $1; + } + else + { + my $shadertype = &GetShaderType( $shadername ); + $shadername =~ s/\.$shadertype//i; + return $shadername; + } +} + +sub DoAsmShader +{ + my $argstring = shift; + my $shadername = &GetShaderSrc( $argstring ); + my $shaderbase = &GetShaderBase( $argstring ); + my $shadertype = &GetShaderType( $argstring ); + my $incfile = ""; + if( $shadertype eq "fxc" || $shadertype eq "vsh" ) + { + $incfile = $shadertype . "tmp9" . $g_tmpfolder . "\\$shaderbase.inc "; + } + + my $vcsfile = $shaderbase . $g_vcsext; + my $bWillCompileVcs = 1; + if( ( $shadertype eq "fxc") && $dynamic_compile ) + { + $bWillCompileVcs = 0; + } + if( $shadercrcpass{$argstring} ) + { + $bWillCompileVcs = 0; + } + + if( $bWillCompileVcs ) + { + &output_makefile_line( $incfile . "shaders\\$shadertype\\$vcsfile: $shadername @dep\n") ; + } + else + { + # psh files don't need a rule at this point since they don't have inc files and we aren't compiling a vcs. + if( $shadertype eq "fxc" || $shadertype eq "vsh" ) + { + &output_makefile_line( $incfile . ": $shadername @dep\n") ; + } + } + + + my $x360switch = ""; + my $moreswitches = ""; + if( !$bWillCompileVcs && $shadertype eq "fxc" ) + { + $moreswitches .= "-novcs "; + } + if( $g_x360 ) + { + $x360switch = "-x360"; + + if( $bWillCompileVcs && ( $shaderbase =~ m/_ps20$/i ) ) + { + $moreswitches .= "-novcs "; + $bWillCompileVcs = 0; + } + } + + # if we are psh and we are compiling the vcs, we don't need this rule. + if( !( $shadertype eq "psh" && !$bWillCompileVcs ) ) + { + &output_makefile_line( "\tperl $g_SourceDir\\devtools\\bin\\" . $shadertype . "_prep.pl $moreswitches $x360switch -source \"$g_SourceDir\" $argstring\n") ; + } + + if( $bWillCompileVcs ) + { + &output_makefile_line( "\techo $shadername>> filestocopy.txt\n") ; + my $dep; + foreach $dep( @dep ) + { + &output_makefile_line( "\techo $dep>> filestocopy.txt\n") ; + } + } + &output_makefile_line( "\n") ; +} + +if( scalar( @ARGV ) == 0 ) +{ + die "Usage updateshaders.pl shaderprojectbasename\n\tie: updateshaders.pl stdshaders_dx6\n"; +} + +$g_x360 = 0; +$g_tmpfolder = "_tmp"; +$g_vcsext = ".vcs"; + +while( 1 ) +{ + $inputbase = shift; + + if( $inputbase =~ m/-source/ ) + { + $g_SourceDir = shift; + } + elsif( $inputbase =~ m/-x360/ ) + { + $g_x360 = 1; + $g_tmpfolder = "_360_tmp"; + $g_vcsext = ".360.vcs"; + } + elsif( $inputbase =~ m/-execute/ ) + { + $g_execute = 1; + } + elsif( $inputbase =~ m/-nv3x/ ) + { + $nv3x = 1; + } + else + { + last; + } +} + +my @srcfiles = &LoadShaderListFile( $inputbase ); + +open MAKEFILE, ">makefile\.$inputbase"; +open COPYFILE, ">makefile\.$inputbase\.copy"; +open INCLIST, ">inclist.txt"; +open VCSLIST, ">vcslist.txt"; + +# make a default dependency that depends on all of the shaders. +&output_makefile_line( "default: ") ; +foreach $shader ( @srcfiles ) +{ + my $shadertype = &GetShaderType( $shader ); + my $shaderbase = &GetShaderBase( $shader ); + my $shadersrc = &GetShaderSrc( $shader ); + if( $shadertype eq "fxc" || $shadertype eq "vsh" ) + { + # We only generate inc files for fxc and vsh files. + my $incFileName = "$shadertype" . "tmp9" . $g_tmpfolder . "\\" . $shaderbase . "\.inc"; + &output_makefile_line( " $incFileName" ); + &output_inclist_line( "$incFileName\n" ); + } + + my $vcsfile = $shaderbase . $g_vcsext; + + my $compilevcs = 1; + if( $shadertype eq "fxc" && $dynamic_compile ) + { + $compilevcs = 0; + } + if( $g_x360 && ( $shaderbase =~ m/_ps20$/i ) ) + { + $compilevcs = 0; + } + if( $compilevcs ) + { + my $vcsFileName = "..\\..\\..\\game\\hl2\\shaders\\$shadertype\\$shaderbase" . $g_vcsext; + # We want to check for perforce operations even if the crc matches in the event that a file has been manually reverted and needs to be checked out again. + &output_vcslist_line( "$vcsFileName\n" ); + $shadercrcpass{$shader} = &CheckCRCAgainstTarget( $shadersrc, $vcsFileName, 0 ); + if( $shadercrcpass{$shader} ) + { + $compilevcs = 0; + } + } + if( $compilevcs ) + { + &output_makefile_line( " shaders\\$shadertype\\$vcsfile" ); + # emit a list of vcs files to copy to the target since we want to build them. + &output_copyfile_line( GetShaderSrc($shader) . "-----" . GetShaderBase($shader) . "\n" ); + } +} +&output_makefile_line( "\n\n") ; + +# Insert all of our vertex shaders and depencencies +$lastshader = ""; +foreach $shader ( @srcfiles ) +{ + my $currentshader = &GetShaderSrc( $shader ); + if ( $lastshader ne $currentshader ) + { + $lastshader = $currentshader; + @dep = &GetAsmShaderDependencies( $lastshader ); + } + &DoAsmShader( $shader ); +} +close VCSLIST; +close INCLIST; +close COPYFILE; +close MAKEFILE; + +# nuke the copyfile if it is zero length +if( ( stat "makefile\.$inputbase\.copy" )[7] == 0 ) +{ + unlink "makefile\.$inputbase\.copy"; +} + +sub output_makefile_line +{ + local ($_)=@_; + print MAKEFILE $_; +} + +sub output_copyfile_line +{ + local ($_)=@_; + print COPYFILE $_; +} + +sub output_vcslist_line +{ + local ($_)=@_; + print VCSLIST $_; +} + +sub output_inclist_line +{ + local ($_)=@_; + print INCLIST $_; +} + diff --git a/mp/src/devtools/bin/valve_perl_helpers.pl b/mp/src/devtools/bin/valve_perl_helpers.pl index 5cd2aa04..9257767a 100644 --- a/mp/src/devtools/bin/valve_perl_helpers.pl +++ b/mp/src/devtools/bin/valve_perl_helpers.pl @@ -1,558 +1,558 @@ -sub BackToForwardSlash
-{
- my( $path ) = shift;
- $path =~ s,\\,/,g;
- return $path;
-}
-
-sub RemoveFileName
-{
- my( $in ) = shift;
- $in = &BackToForwardSlash( $in );
- $in =~ s,/[^/]*$,,;
- return $in;
-}
-
-sub RemovePath
-{
- my( $in ) = shift;
- $in = &BackToForwardSlash( $in );
- $in =~ s,^(.*)/([^/]*)$,$2,;
- return $in;
-}
-
-sub MakeDirHier
-{
- my( $in ) = shift;
-# print "MakeDirHier( $in )\n";
- $in = &BackToForwardSlash( $in );
- my( @path );
- while( $in =~ m,/, ) # while $in still has a slash
- {
- my( $end ) = &RemovePath( $in );
- push @path, $end;
-# print $in . "\n";
- $in = &RemoveFileName( $in );
- }
- my( $i );
- my( $numelems ) = scalar( @path );
- my( $curpath );
- for( $i = $numelems - 1; $i >= 0; $i-- )
- {
- $curpath .= "/" . $path[$i];
- my( $dir ) = $in . $curpath;
- if( !stat $dir )
- {
-# print "mkdir $dir\n";
- mkdir $dir, 0777;
- }
- }
-}
-
-sub FileExists
-{
- my $filename = shift;
- my @statresult = stat $filename;
- my $iswritable = @statresult != 0;
- return $iswritable;
-}
-
-sub MakeFileWritable
-{
- my $filename = shift;
- if ( &FileExists( $filename ) )
- {
- chmod 0666, $filename || die;
- }
-}
-
-sub MakeFileReadOnly
-{
- my $filename = shift;
- chmod 0444, $filename || die;
-}
-
-# Run a command and get stdout and stderr to an array
-sub RunCommand
-{
- my $cmd = shift;
-# print STDERR "command: $cmd\n";
- system "$cmd > cmdout.txt 2>&1" || die;
- local( *FILE );
- open FILE, "<cmdout.txt" || die;
- my @output = <FILE>;
-# print STDERR "command output: @output\n";
- close FILE;
- unlink "cmdout.txt" || die;
- return @output;
-}
-
-sub PerforceEditOrAdd
-{
- return;
- my $filename = shift;
- my $changelistarg = shift;
-
- # Is the file on the client?
- my $cmd = "p4 fstat \"$filename\"";
- my @p4output = &RunCommand( $cmd );
- my $p4output = join "", @p4output;
- if( $p4output =~ m/no such file/ )
- {
- # not on client. . add
- my $cmd = "p4 add $changelistarg $filename";
- my @p4output = &RunCommand( $cmd );
- my $p4output = join "", @p4output;
- if( $p4output =~ m/opened for add/ )
- {
- print $p4output;
- return;
- }
- print "ERROR: $p4output";
- return;
- }
-
- # The file is known to be on the client at this point.
-
- # Is it open for edit?
- if( $p4output =~ m/action edit/ )
- {
- # Is is open for edit, let's see if it's still different.
- # check for opened files that are not different from the revision in the depot.
- my $cmd = "p4 diff -sr \"$filename\"";
- my @p4output = &RunCommand( $cmd );
- my $outputstring = join "", @p4output;
- # check for empty string
- if( !( $outputstring =~ m/^\s*$/ ) )
- {
- my $cmd = "p4 revert \"$filename\"";
- my @p4output = &RunCommand( $cmd );
- my $outputstring = join "", @p4output;
- print $outputstring;
- return;
- }
- }
-
- # check for unopened files that are different from the revision in the depot.
- my $cmd = "p4 diff -se \"$filename\"";
- my @p4output = &RunCommand( $cmd );
- my $outputstring = join "", @p4output;
- # check for empty string
- if( $outputstring =~ m/^\s*$/ )
- {
- &MakeFileReadOnly( $filename );
- return;
- }
-
- # We need to edit the file since it is known to be different here.
- my $cmd = "p4 edit $changelistarg \"$filename\"";
- my @p4output = &RunCommand( $cmd );
-
- my $line;
- foreach $line ( @p4output )
- {
- if( $line =~ m/not on client/ )
- {
- #print "notonclient...";
- print "ERROR: @p4output\n";
- return;
- }
- if( $line =~ m/currently opened for edit/ )
- {
- return;
- }
- if( $line =~ m/opened for edit/ )
- {
- print $line;
- }
- }
-}
-
-sub FileIsWritable
-{
- local( $filename ) = shift;
- local( @statresult ) = stat $filename;
- local( $mode, $iswritable );
- $mode = oct( $statresult[2] );
- $iswritable = ( $mode & 2 ) != 0;
- return $iswritable;
-}
-
-sub TouchFile
-{
- my $filename = shift;
- if( !&FileExists( $filename ) )
- {
- if( !open FILE, ">$filename" )
- {
- die;
- }
- close FILE;
- }
- my $now = time;
- local( *FILE );
- utime $now, $now, $filename;
-}
-
-sub FileExistsInPerforce
-{
- my $filename = shift;
- my @output = &RunCommand( "p4 fstat $filename" );
- my $line;
- foreach $line (@output)
- {
- if( $line =~ m/no such file/ )
- {
- return 0;
- }
- }
- return 1;
-}
-
-sub PerforceWriteFile
-{
- my $filename = shift;
- my $filecontents = shift;
-# my $changelistname = shift;
-
- # Get the changelist number for the Shader Auto Checkout changelist. Will create the changelist if it doesn't exist.
-# my $changelistnumber = `valve_p4_create_changelist.cmd . \"$changelistname\"`;
- # Get rid of the newline
-# $changelistnumber =~ s/\n//g;
-
-# my $changelistarg = "";
-# if( $changelistnumber != 0 )
-# {
-# $changelistarg = "-c $changelistnumber"
-# }
-
- # Make the target vcs writable if it exists
- MakeFileWritable( $filename );
-
- # Write the file.
- local( *FP );
- open FP, ">$filename";
- print FP $filecontents;
- close FP;
-
- # Do whatever needs to happen with perforce for this file.
-# &PerforceEditOrAdd( $filename, $changelistarg );
-}
-
-sub WriteFile
-{
- my $filename = shift;
- my $filecontents = shift;
-
- # Make the target vcs writable if it exists
- MakeFileWritable( $filename );
-
- # Write the file.
- local( *FP );
- open FP, ">$filename";
- print FP $filecontents;
- close FP;
-}
-
-sub PrintCleanPerforceOutput
-{
- my $line;
- while( $line = shift )
- {
- if( $line =~ m/currently opened/i )
- {
- next;
- }
- if( $line =~ m/already opened for edit/i )
- {
- next;
- }
- if( $line =~ m/also opened/i )
- {
- next;
- }
- if( $line =~ m/add of existing file/i )
- {
- next;
- }
- print $line;
- }
-}
-
-# HACK!!!! Need to pass something in to do this rather than hard coding.
-sub NormalizePerforceFilename
-{
- my $line = shift;
-
- # remove newlines.
- $line =~ s/\n//;
- # downcase.
- $line =~ tr/[A-Z]/[a-z]/;
- # backslash to forwardslash
- $line =~ s,\\,/,g;
-
- # for inc files HACK!
- $line =~ s/^.*(fxctmp9.*)/$1/i;
- $line =~ s/^.*(vshtmp9.*)/$1/i;
-
- # for vcs files. HACK!
- $line =~ s,^.*game/hl2/shaders/,,i;
-
- return $line;
-}
-
-sub MakeSureFileExists
-{
- local( $filename ) = shift;
- local( $testexists ) = shift;
- local( $testwrite ) = shift;
-
- local( @statresult ) = stat $filename;
- if( !@statresult && $testexists )
- {
- die "$filename doesn't exist!\n";
- }
- local( $mode, $iswritable );
- $mode = oct( $statresult[2] );
- $iswritable = ( $mode & 2 ) != 0;
- if( !$iswritable && $testwrite )
- {
- die "$filename isn't writable!\n";
- }
-}
-
-sub LoadShaderListFile_GetShaderType
-{
- my $shadername = shift;
- my $shadertype;
- if( $shadername =~ m/\.vsh/i )
- {
- $shadertype = "vsh";
- }
- elsif( $shadername =~ m/\.psh/i )
- {
- $shadertype = "psh";
- }
- elsif( $shadername =~ m/\.fxc/i )
- {
- $shadertype = "fxc";
- }
- else
- {
- die;
- }
- return $shadertype;
-}
-
-sub LoadShaderListFile_GetShaderSrc
-{
- my $shadername = shift;
- if ( $shadername =~ m/^(.*)-----/i )
- {
- return $1;
- }
- else
- {
- return $shadername;
- }
-}
-
-sub LoadShaderListFile_GetShaderBase
-{
- my $shadername = shift;
- if ( $shadername =~ m/-----(.*)$/i )
- {
- return $1;
- }
- else
- {
- my $shadertype = &LoadShaderListFile_GetShaderType( $shadername );
- $shadername =~ s/\.$shadertype//i;
- return $shadername;
- }
-}
-
-sub LoadShaderListFile
-{
- my $inputbase = shift;
-
- my @srcfiles;
- &MakeSureFileExists( "$inputbase.txt", 1, 0 );
-
- open SHADERLISTFILE, "<$inputbase.txt" || die;
- my $line;
- while( $line = <SHADERLISTFILE> )
- {
- $line =~ s/\/\/.*$//; # remove comments "//..."
- $line =~ s/^\s*//; # trim leading whitespace
- $line =~ s/\s*$//; # trim trailing whitespace
- next if( $line =~ m/^\s*$/ );
- if( $line =~ m/\.fxc/ || $line =~ m/\.vsh/ || $line =~ m/\.psh/ )
- {
- my $shaderbase = &LoadShaderListFile_GetShaderBase( $line );
-
- if( $ENV{"DIRECTX_FORCE_MODEL"} =~ m/^30$/i ) # forcing all shaders to be ver. 30
- {
- my $targetbase = $shaderbase;
- $targetbase =~ s/_ps2x/_ps30/i;
- $targetbase =~ s/_ps20b/_ps30/i;
- $targetbase =~ s/_ps20/_ps30/i;
- $targetbase =~ s/_vs20/_vs30/i;
- $targetbase =~ s/_vsxx/_vs30/i;
- push @srcfiles, ( $line . "-----" . $targetbase );
- }
- else
- {
- if( $shaderbase =~ m/_ps2x/i )
- {
- my $targetbase = $shaderbase;
- $targetbase =~ s/_ps2x/_ps20/i;
- push @srcfiles, ( $line . "-----" . $targetbase );
-
- $targetbase = $shaderbase;
- $targetbase =~ s/_ps2x/_ps20b/i;
- push @srcfiles, ( $line . "-----" . $targetbase );
- }
- elsif( $shaderbase =~ m/_vsxx/i )
- {
- my $targetbase = $shaderbase;
- $targetbase =~ s/_vsxx/_vs11/i;
- push @srcfiles, ( $line . "-----" . $targetbase );
-
- $targetbase = $shaderbase;
- $targetbase =~ s/_vsxx/_vs20/i;
- push @srcfiles, ( $line . "-----" . $targetbase );
- }
- else
- {
- push @srcfiles, ( $line . "-----" . $shaderbase );
- }
- }
- }
- }
- close SHADERLISTFILE;
- return @srcfiles;
-}
-
-sub ReadInputFileWithIncludes
-{
- local( $filename ) = shift;
-# print STDERR "ReadInputFileWithIncludes: $filename\n";
-
- local( *INPUT );
- local( $output );
-
-# print STDERR "before open\n";
- open INPUT, "<$filename" || die;
-# print STDERR "after open\n";
-
- local( $line );
- while( $line = <INPUT> )
- {
-# print STDERR $line;
- if( $line =~ m/\#include\s+\"(.*)\"/i )
- {
- $output.= ReadInputFileWithIncludes( $1 );
- }
- else
- {
- $output .= $line;
- }
- }
-
- close INPUT;
- return $output;
-}
-
-sub GetCRCFromSourceFile
-{
- my $filename = shift;
- my $data = &ReadInputFileWithIncludes( $filename );
-# print STDERR $data;
- $crc = crc32( $data );
-# print STDERR "GetCRCFromSourceFile: $crc\n";
- return $crc;
-}
-
-sub GetCRCFromVCSFile
-{
- my $filename = shift;
-# print STDERR "GetCRCFromVCSFile $filename\n";
- local( *FP );
- open FP, "<$filename" || die "GetCRCFromVCSFile: can't open file $filename\n";
- binmode( FP );
-
- # unpack arguments
- my $sInt = "i";
- my $uInt = "I";
- if( $filename =~ m/\.360\./ )
- {
- # Change arguments to "big endian long"
- $sInt = "N";
- $uInt = "N";
- }
-
- my $header;
- read FP, $header, 7 * 4 || die "updateshaders.pl:GetCRCFromVCSFile: can't read header for $filename\n";
- my $version,$numCombos,$numDynamicCombos,$flags,$centroidMask,$refSize,$crc;
- ($version,$numCombos,$numDynamicCombos,$flags,$centroidMask,$refSize,$crc) = unpack "$sInt$sInt$sInt$uInt$uInt$uInt$uInt", $header;
- unless( $version == 4 || $version == 5 || $version == 6 )
- {
- print STDERR "ERROR: GetCRCFromVCSFile: $filename is version $version\n";
- return 0;
- }
-# print STDERR "version: $version\n";
-# print STDERR "numCombos: $numCombos\n";
-# print STDERR "numDynamicCombos: $numDynamicCombos\n";
-# print STDERR "flags: $flags\n";
-# print STDERR "centroidMask: $centroidMask\n";
-# print STDERR "refSize: $refSize\n";
-# print STDERR "GetCRCFromVCSFile: $crc\n";
- close( FP );
- return $crc;
-}
-
-sub CheckCRCAgainstTarget
-{
- my $srcFileName = shift;
- my $vcsFileName = shift;
- my $warn = shift;
-
- # Make sure both files exist.
-# print STDERR "$srcFileName doesn't exist\n" if( !( -e $srcFileName ) );
-# print STDERR "$vcsFileName doesn't exist\n" if( !( -e $vcsFileName ) );
- if( !( -e $srcFileName ) )
- {
- if( $warn )
- {
- print "$srcFileName missing\n";
- }
- return 0;
- }
- if( !( -e $vcsFileName ) )
- {
- if( $warn )
- {
- print "$vcsFileName missing\n";
- }
- return 0;
- }
-# print STDERR "CheckCRCAgainstTarget( $srcFileName, $vcsFileName );\n";
-# print STDERR "vcsFileName: $vcsFileName\n";
-# print STDERR "vcsFileName: $srcFileName\n";
- my $vcsCRC = &GetCRCFromVCSFile( $vcsFileName );
- my $srcCRC = &GetCRCFromSourceFile( $srcFileName );
- if( $warn && ( $vcsCRC != $srcCRC ) )
- {
- print "$vcsFileName checksum ($vcsCRC) != $srcFileName checksum: ($srcCRC)\n";
- }
-
-# return 0; # use this to skip crc checking.
-# if( $vcsCRC == $srcCRC )
-# {
-# print STDERR "CRC passed for $srcFileName $vcsFileName $vcsCRC\n";
-# }
- return $vcsCRC == $srcCRC;
-}
-
-1;
+sub BackToForwardSlash +{ + my( $path ) = shift; + $path =~ s,\\,/,g; + return $path; +} + +sub RemoveFileName +{ + my( $in ) = shift; + $in = &BackToForwardSlash( $in ); + $in =~ s,/[^/]*$,,; + return $in; +} + +sub RemovePath +{ + my( $in ) = shift; + $in = &BackToForwardSlash( $in ); + $in =~ s,^(.*)/([^/]*)$,$2,; + return $in; +} + +sub MakeDirHier +{ + my( $in ) = shift; +# print "MakeDirHier( $in )\n"; + $in = &BackToForwardSlash( $in ); + my( @path ); + while( $in =~ m,/, ) # while $in still has a slash + { + my( $end ) = &RemovePath( $in ); + push @path, $end; +# print $in . "\n"; + $in = &RemoveFileName( $in ); + } + my( $i ); + my( $numelems ) = scalar( @path ); + my( $curpath ); + for( $i = $numelems - 1; $i >= 0; $i-- ) + { + $curpath .= "/" . $path[$i]; + my( $dir ) = $in . $curpath; + if( !stat $dir ) + { +# print "mkdir $dir\n"; + mkdir $dir, 0777; + } + } +} + +sub FileExists +{ + my $filename = shift; + my @statresult = stat $filename; + my $iswritable = @statresult != 0; + return $iswritable; +} + +sub MakeFileWritable +{ + my $filename = shift; + if ( &FileExists( $filename ) ) + { + chmod 0666, $filename || die; + } +} + +sub MakeFileReadOnly +{ + my $filename = shift; + chmod 0444, $filename || die; +} + +# Run a command and get stdout and stderr to an array +sub RunCommand +{ + my $cmd = shift; +# print STDERR "command: $cmd\n"; + system "$cmd > cmdout.txt 2>&1" || die; + local( *FILE ); + open FILE, "<cmdout.txt" || die; + my @output = <FILE>; +# print STDERR "command output: @output\n"; + close FILE; + unlink "cmdout.txt" || die; + return @output; +} + +sub PerforceEditOrAdd +{ + return; + my $filename = shift; + my $changelistarg = shift; + + # Is the file on the client? + my $cmd = "p4 fstat \"$filename\""; + my @p4output = &RunCommand( $cmd ); + my $p4output = join "", @p4output; + if( $p4output =~ m/no such file/ ) + { + # not on client. . add + my $cmd = "p4 add $changelistarg $filename"; + my @p4output = &RunCommand( $cmd ); + my $p4output = join "", @p4output; + if( $p4output =~ m/opened for add/ ) + { + print $p4output; + return; + } + print "ERROR: $p4output"; + return; + } + + # The file is known to be on the client at this point. + + # Is it open for edit? + if( $p4output =~ m/action edit/ ) + { + # Is is open for edit, let's see if it's still different. + # check for opened files that are not different from the revision in the depot. + my $cmd = "p4 diff -sr \"$filename\""; + my @p4output = &RunCommand( $cmd ); + my $outputstring = join "", @p4output; + # check for empty string + if( !( $outputstring =~ m/^\s*$/ ) ) + { + my $cmd = "p4 revert \"$filename\""; + my @p4output = &RunCommand( $cmd ); + my $outputstring = join "", @p4output; + print $outputstring; + return; + } + } + + # check for unopened files that are different from the revision in the depot. + my $cmd = "p4 diff -se \"$filename\""; + my @p4output = &RunCommand( $cmd ); + my $outputstring = join "", @p4output; + # check for empty string + if( $outputstring =~ m/^\s*$/ ) + { + &MakeFileReadOnly( $filename ); + return; + } + + # We need to edit the file since it is known to be different here. + my $cmd = "p4 edit $changelistarg \"$filename\""; + my @p4output = &RunCommand( $cmd ); + + my $line; + foreach $line ( @p4output ) + { + if( $line =~ m/not on client/ ) + { + #print "notonclient..."; + print "ERROR: @p4output\n"; + return; + } + if( $line =~ m/currently opened for edit/ ) + { + return; + } + if( $line =~ m/opened for edit/ ) + { + print $line; + } + } +} + +sub FileIsWritable +{ + local( $filename ) = shift; + local( @statresult ) = stat $filename; + local( $mode, $iswritable ); + $mode = oct( $statresult[2] ); + $iswritable = ( $mode & 2 ) != 0; + return $iswritable; +} + +sub TouchFile +{ + my $filename = shift; + if( !&FileExists( $filename ) ) + { + if( !open FILE, ">$filename" ) + { + die; + } + close FILE; + } + my $now = time; + local( *FILE ); + utime $now, $now, $filename; +} + +sub FileExistsInPerforce +{ + my $filename = shift; + my @output = &RunCommand( "p4 fstat $filename" ); + my $line; + foreach $line (@output) + { + if( $line =~ m/no such file/ ) + { + return 0; + } + } + return 1; +} + +sub PerforceWriteFile +{ + my $filename = shift; + my $filecontents = shift; +# my $changelistname = shift; + + # Get the changelist number for the Shader Auto Checkout changelist. Will create the changelist if it doesn't exist. +# my $changelistnumber = `valve_p4_create_changelist.cmd . \"$changelistname\"`; + # Get rid of the newline +# $changelistnumber =~ s/\n//g; + +# my $changelistarg = ""; +# if( $changelistnumber != 0 ) +# { +# $changelistarg = "-c $changelistnumber" +# } + + # Make the target vcs writable if it exists + MakeFileWritable( $filename ); + + # Write the file. + local( *FP ); + open FP, ">$filename"; + print FP $filecontents; + close FP; + + # Do whatever needs to happen with perforce for this file. +# &PerforceEditOrAdd( $filename, $changelistarg ); +} + +sub WriteFile +{ + my $filename = shift; + my $filecontents = shift; + + # Make the target vcs writable if it exists + MakeFileWritable( $filename ); + + # Write the file. + local( *FP ); + open FP, ">$filename"; + print FP $filecontents; + close FP; +} + +sub PrintCleanPerforceOutput +{ + my $line; + while( $line = shift ) + { + if( $line =~ m/currently opened/i ) + { + next; + } + if( $line =~ m/already opened for edit/i ) + { + next; + } + if( $line =~ m/also opened/i ) + { + next; + } + if( $line =~ m/add of existing file/i ) + { + next; + } + print $line; + } +} + +# HACK!!!! Need to pass something in to do this rather than hard coding. +sub NormalizePerforceFilename +{ + my $line = shift; + + # remove newlines. + $line =~ s/\n//; + # downcase. + $line =~ tr/[A-Z]/[a-z]/; + # backslash to forwardslash + $line =~ s,\\,/,g; + + # for inc files HACK! + $line =~ s/^.*(fxctmp9.*)/$1/i; + $line =~ s/^.*(vshtmp9.*)/$1/i; + + # for vcs files. HACK! + $line =~ s,^.*game/hl2/shaders/,,i; + + return $line; +} + +sub MakeSureFileExists +{ + local( $filename ) = shift; + local( $testexists ) = shift; + local( $testwrite ) = shift; + + local( @statresult ) = stat $filename; + if( !@statresult && $testexists ) + { + die "$filename doesn't exist!\n"; + } + local( $mode, $iswritable ); + $mode = oct( $statresult[2] ); + $iswritable = ( $mode & 2 ) != 0; + if( !$iswritable && $testwrite ) + { + die "$filename isn't writable!\n"; + } +} + +sub LoadShaderListFile_GetShaderType +{ + my $shadername = shift; + my $shadertype; + if( $shadername =~ m/\.vsh/i ) + { + $shadertype = "vsh"; + } + elsif( $shadername =~ m/\.psh/i ) + { + $shadertype = "psh"; + } + elsif( $shadername =~ m/\.fxc/i ) + { + $shadertype = "fxc"; + } + else + { + die; + } + return $shadertype; +} + +sub LoadShaderListFile_GetShaderSrc +{ + my $shadername = shift; + if ( $shadername =~ m/^(.*)-----/i ) + { + return $1; + } + else + { + return $shadername; + } +} + +sub LoadShaderListFile_GetShaderBase +{ + my $shadername = shift; + if ( $shadername =~ m/-----(.*)$/i ) + { + return $1; + } + else + { + my $shadertype = &LoadShaderListFile_GetShaderType( $shadername ); + $shadername =~ s/\.$shadertype//i; + return $shadername; + } +} + +sub LoadShaderListFile +{ + my $inputbase = shift; + + my @srcfiles; + &MakeSureFileExists( "$inputbase.txt", 1, 0 ); + + open SHADERLISTFILE, "<$inputbase.txt" || die; + my $line; + while( $line = <SHADERLISTFILE> ) + { + $line =~ s/\/\/.*$//; # remove comments "//..." + $line =~ s/^\s*//; # trim leading whitespace + $line =~ s/\s*$//; # trim trailing whitespace + next if( $line =~ m/^\s*$/ ); + if( $line =~ m/\.fxc/ || $line =~ m/\.vsh/ || $line =~ m/\.psh/ ) + { + my $shaderbase = &LoadShaderListFile_GetShaderBase( $line ); + + if( $ENV{"DIRECTX_FORCE_MODEL"} =~ m/^30$/i ) # forcing all shaders to be ver. 30 + { + my $targetbase = $shaderbase; + $targetbase =~ s/_ps2x/_ps30/i; + $targetbase =~ s/_ps20b/_ps30/i; + $targetbase =~ s/_ps20/_ps30/i; + $targetbase =~ s/_vs20/_vs30/i; + $targetbase =~ s/_vsxx/_vs30/i; + push @srcfiles, ( $line . "-----" . $targetbase ); + } + else + { + if( $shaderbase =~ m/_ps2x/i ) + { + my $targetbase = $shaderbase; + $targetbase =~ s/_ps2x/_ps20/i; + push @srcfiles, ( $line . "-----" . $targetbase ); + + $targetbase = $shaderbase; + $targetbase =~ s/_ps2x/_ps20b/i; + push @srcfiles, ( $line . "-----" . $targetbase ); + } + elsif( $shaderbase =~ m/_vsxx/i ) + { + my $targetbase = $shaderbase; + $targetbase =~ s/_vsxx/_vs11/i; + push @srcfiles, ( $line . "-----" . $targetbase ); + + $targetbase = $shaderbase; + $targetbase =~ s/_vsxx/_vs20/i; + push @srcfiles, ( $line . "-----" . $targetbase ); + } + else + { + push @srcfiles, ( $line . "-----" . $shaderbase ); + } + } + } + } + close SHADERLISTFILE; + return @srcfiles; +} + +sub ReadInputFileWithIncludes +{ + local( $filename ) = shift; +# print STDERR "ReadInputFileWithIncludes: $filename\n"; + + local( *INPUT ); + local( $output ); + +# print STDERR "before open\n"; + open INPUT, "<$filename" || die; +# print STDERR "after open\n"; + + local( $line ); + while( $line = <INPUT> ) + { +# print STDERR $line; + if( $line =~ m/\#include\s+\"(.*)\"/i ) + { + $output.= ReadInputFileWithIncludes( $1 ); + } + else + { + $output .= $line; + } + } + + close INPUT; + return $output; +} + +sub GetCRCFromSourceFile +{ + my $filename = shift; + my $data = &ReadInputFileWithIncludes( $filename ); +# print STDERR $data; + $crc = crc32( $data ); +# print STDERR "GetCRCFromSourceFile: $crc\n"; + return $crc; +} + +sub GetCRCFromVCSFile +{ + my $filename = shift; +# print STDERR "GetCRCFromVCSFile $filename\n"; + local( *FP ); + open FP, "<$filename" || die "GetCRCFromVCSFile: can't open file $filename\n"; + binmode( FP ); + + # unpack arguments + my $sInt = "i"; + my $uInt = "I"; + if( $filename =~ m/\.360\./ ) + { + # Change arguments to "big endian long" + $sInt = "N"; + $uInt = "N"; + } + + my $header; + read FP, $header, 7 * 4 || die "updateshaders.pl:GetCRCFromVCSFile: can't read header for $filename\n"; + my $version,$numCombos,$numDynamicCombos,$flags,$centroidMask,$refSize,$crc; + ($version,$numCombos,$numDynamicCombos,$flags,$centroidMask,$refSize,$crc) = unpack "$sInt$sInt$sInt$uInt$uInt$uInt$uInt", $header; + unless( $version == 4 || $version == 5 || $version == 6 ) + { + print STDERR "ERROR: GetCRCFromVCSFile: $filename is version $version\n"; + return 0; + } +# print STDERR "version: $version\n"; +# print STDERR "numCombos: $numCombos\n"; +# print STDERR "numDynamicCombos: $numDynamicCombos\n"; +# print STDERR "flags: $flags\n"; +# print STDERR "centroidMask: $centroidMask\n"; +# print STDERR "refSize: $refSize\n"; +# print STDERR "GetCRCFromVCSFile: $crc\n"; + close( FP ); + return $crc; +} + +sub CheckCRCAgainstTarget +{ + my $srcFileName = shift; + my $vcsFileName = shift; + my $warn = shift; + + # Make sure both files exist. +# print STDERR "$srcFileName doesn't exist\n" if( !( -e $srcFileName ) ); +# print STDERR "$vcsFileName doesn't exist\n" if( !( -e $vcsFileName ) ); + if( !( -e $srcFileName ) ) + { + if( $warn ) + { + print "$srcFileName missing\n"; + } + return 0; + } + if( !( -e $vcsFileName ) ) + { + if( $warn ) + { + print "$vcsFileName missing\n"; + } + return 0; + } +# print STDERR "CheckCRCAgainstTarget( $srcFileName, $vcsFileName );\n"; +# print STDERR "vcsFileName: $vcsFileName\n"; +# print STDERR "vcsFileName: $srcFileName\n"; + my $vcsCRC = &GetCRCFromVCSFile( $vcsFileName ); + my $srcCRC = &GetCRCFromSourceFile( $srcFileName ); + if( $warn && ( $vcsCRC != $srcCRC ) ) + { + print "$vcsFileName checksum ($vcsCRC) != $srcFileName checksum: ($srcCRC)\n"; + } + +# return 0; # use this to skip crc checking. +# if( $vcsCRC == $srcCRC ) +# { +# print STDERR "CRC passed for $srcFileName $vcsFileName $vcsCRC\n"; +# } + return $vcsCRC == $srcCRC; +} + +1; diff --git a/mp/src/devtools/bin/vsh_prep.pl b/mp/src/devtools/bin/vsh_prep.pl index 1ba8b6f1..8161c494 100644 --- a/mp/src/devtools/bin/vsh_prep.pl +++ b/mp/src/devtools/bin/vsh_prep.pl @@ -1,1106 +1,1106 @@ -use String::CRC32;
-BEGIN {use File::Basename; push @INC, dirname($0); }
-require "valve_perl_helpers.pl";
-
-sub WriteHelperVar
-{
- local( $name ) = shift;
- local( $min ) = shift;
- local( $max ) = shift;
- local( $varname ) = "m_n" . $name;
- local( $boolname ) = "m_b" . $name;
- push @outputHeader, "private:\n";
- push @outputHeader, "\tint $varname;\n";
- push @outputHeader, "#ifdef _DEBUG\n";
- push @outputHeader, "\tbool $boolname;\n";
- push @outputHeader, "#endif\n";
- push @outputHeader, "public:\n";
- # int version of set function
- push @outputHeader, "\tvoid Set" . $name . "( int i )\n";
- push @outputHeader, "\t{\n";
- if ( $min != $max )
- {
- push @outputHeader, "\t\tAssert( i >= $min && i <= $max );\n";
- push @outputHeader, "\t\t$varname = i;\n";
- push @outputHeader, "#ifdef _DEBUG\n";
- push @outputHeader, "\t\t$boolname = true;\n";
- push @outputHeader, "#endif\n";
- }
- push @outputHeader, "\t}\n";
- # bool version of set function
- push @outputHeader, "\tvoid Set" . $name . "( bool i )\n";
- push @outputHeader, "\t{\n";
- if ( $min != $max )
- {
-# push @outputHeader, "\t\tAssert( i >= $min && i <= $max );\n";
- push @outputHeader, "\t\t$varname = i ? 1 : 0;\n";
- push @outputHeader, "#ifdef _DEBUG\n";
- push @outputHeader, "\t\t$boolname = true;\n";
- push @outputHeader, "#endif\n";
- }
- push @outputHeader, "\t}\n";
-}
-
-sub WriteStaticBoolExpression
-{
- local( $prefix ) = shift;
- local( $operator ) = shift;
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- if( $i )
- {
- push @outputHeader, " $operator ";
- }
- local( $name ) = @staticDefineNames[$i];
- local( $boolname ) = "m_b" . $name;
- push @outputHeader, "$prefix$boolname";
- }
- push @outputHeader, ";\n";
-}
-
-sub WriteDynamicBoolExpression
-{
- local( $prefix ) = shift;
- local( $operator ) = shift;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- if( $i )
- {
- push @outputHeader, " $operator ";
- }
- local( $name ) = @dynamicDefineNames[$i];
- local( $boolname ) = "m_b" . $name;
- push @outputHeader, "$prefix$boolname";
- }
- push @outputHeader, ";\n";
-}
-
-sub WriteDynamicHelperClasses
-{
- local( $basename ) = $fxc_filename;
- $basename =~ s/\.fxc//i;
- $basename =~ tr/A-Z/a-z/;
- local( $classname ) = $basename . "_Dynamic_Index";
- push @outputHeader, "class $classname\n";
- push @outputHeader, "{\n";
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $name = $dynamicDefineNames[$i];
- $min = $dynamicDefineMin[$i];
- $max = $dynamicDefineMax[$i];
- &WriteHelperVar( $name, $min, $max );
- }
- push @outputHeader, "public:\n";
- push @outputHeader, "\t$classname()\n";
- push @outputHeader, "\t{\n";
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $min = $dynamicDefineMin[$i];
- $max = $dynamicDefineMax[$i];
-
- local( $name ) = @dynamicDefineNames[$i];
- local( $boolname ) = "m_b" . $name;
- local( $varname ) = "m_n" . $name;
- push @outputHeader, "#ifdef _DEBUG\n";
- if ( $min != $max )
- {
- push @outputHeader, "\t\t$boolname = false;\n";
- }
- else
- {
- push @outputHeader, "\t\t$boolname = true;\n";
- }
- push @outputHeader, "#endif // _DEBUG\n";
- push @outputHeader, "\t\t$varname = 0;\n";
- }
- push @outputHeader, "\t}\n";
- push @outputHeader, "\tint GetIndex()\n";
- push @outputHeader, "\t{\n";
- push @outputHeader, "\t\t// Asserts to make sure that we aren't using any skipped combinations.\n";
- foreach $skip (@perlskipcodeindividual)
- {
- $skip =~ s/\$/m_n/g;
-# push @outputHeader, "\t\tAssert( !( $skip ) );\n";
- }
- push @outputHeader, "\t\t// Asserts to make sure that we are setting all of the combination vars.\n";
-
- push @outputHeader, "#ifdef _DEBUG\n";
- if( scalar( @dynamicDefineNames ) > 0 )
- {
- push @outputHeader, "\t\tbool bAllDynamicVarsDefined = ";
- WriteDynamicBoolExpression( "", "&&" );
- }
- if( scalar( @dynamicDefineNames ) > 0 )
- {
- push @outputHeader, "\t\tAssert( bAllDynamicVarsDefined );\n";
- }
- push @outputHeader, "#endif // _DEBUG\n";
-
- if( $spewCombos && scalar( @dynamicDefineNames ) )
- {
- push @outputHeader, &CreateCCodeToSpewDynamicCombo();
- }
- push @outputHeader, "\t\treturn ";
- local( $scale ) = 1;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- local( $name ) = @dynamicDefineNames[$i];
- local( $varname ) = "m_n" . $name;
- push @outputHeader, "( $scale * $varname ) + ";
- $scale *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
- }
- push @outputHeader, "0;\n";
- push @outputHeader, "\t}\n";
- push @outputHeader, "};\n";
-}
-
-sub WriteStaticHelperClasses
-{
- local( $basename ) = $fxc_filename;
- $basename =~ s/\.fxc//i;
- $basename =~ tr/A-Z/a-z/;
- local( $classname ) = $basename . "_Static_Index";
- push @outputHeader, "class $classname\n";
- push @outputHeader, "{\n";
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- $name = $staticDefineNames[$i];
- $min = $staticDefineMin[$i];
- $max = $staticDefineMax[$i];
- &WriteHelperVar( $name, $min, $max );
- }
- push @outputHeader, "public:\n";
- push @outputHeader, "\t$classname()\n";
- push @outputHeader, "\t{\n";
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- $min = $staticDefineMin[$i];
- $max = $staticDefineMax[$i];
-
- local( $name ) = @staticDefineNames[$i];
- local( $boolname ) = "m_b" . $name;
- local( $varname ) = "m_n" . $name;
-
- push @outputHeader, "#ifdef _DEBUG\n";
- if ( $min != $max )
- {
- push @outputHeader, "\t\t$boolname = false;\n";
- }
- else
- {
- push @outputHeader, "\t\t$boolname = true;\n";
- }
- push @outputHeader, "#endif // _DEBUG\n";
- push @outputHeader, "\t\t$varname = 0;\n";
- }
- push @outputHeader, "\t}\n";
- push @outputHeader, "\tint GetIndex()\n";
- push @outputHeader, "\t{\n";
- push @outputHeader, "\t\t// Asserts to make sure that we aren't using any skipped combinations.\n";
- foreach $skip (@perlskipcodeindividual)
- {
- $skip =~ s/\$/m_n/g;
-# push @outputHeader, "\t\tAssert( !( $skip ) );\n";
- }
- push @outputHeader, "\t\t// Asserts to make sure that we are setting all of the combination vars.\n";
-
- push @outputHeader, "#ifdef _DEBUG\n";
- if( scalar( @staticDefineNames ) > 0 )
- {
- push @outputHeader, "\t\tbool bAllStaticVarsDefined = ";
- WriteStaticBoolExpression( "", "&&" );
-
- }
- if( scalar( @staticDefineNames ) > 0 )
- {
- push @outputHeader, "\t\tAssert( bAllStaticVarsDefined );\n";
- }
- push @outputHeader, "#endif // _DEBUG\n";
-
- if( $spewCombos && scalar( @staticDefineNames ) )
- {
- push @outputHeader, &CreateCCodeToSpewStaticCombo();
- }
- push @outputHeader, "\t\treturn ";
- local( $scale ) = 1;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $scale *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
- }
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- local( $name ) = @staticDefineNames[$i];
- local( $varname ) = "m_n" . $name;
- push @outputHeader, "( $scale * $varname ) + ";
- $scale *= $staticDefineMax[$i] - $staticDefineMin[$i] + 1;
- }
- push @outputHeader, "0;\n";
- push @outputHeader, "\t}\n";
- push @outputHeader, "};\n";
-}
-
-sub CreateFuncToSetPerlVars
-{
- local( $out ) = "";
-
- $out .= "sub SetPerlVarsFunc\n";
- $out .= "{\n";
- $out .= " local( \$combo ) = shift;\n";
- $out .= " local( \$i );\n";
- local( $i );
- for( $i = 0; $i < scalar( @dynamicDefineNames ); \$i++ )
- {
- $out .= " \$$dynamicDefineNames[$i] = \$combo % ";
- $out .= ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) + $dynamicDefineMin[$i];
- $out .= ";\n";
- $out .= " \$combo = \$combo / " . ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) . ";\n";
- }
- for( $i = 0; $i < scalar( @staticDefineNames ); \$i++ )
- {
- $out .= " \$$staticDefineNames[$i] = \$combo % ";
- $out .= ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) + $staticDefineMin[$i];
- $out .= ";\n";
- $out .= " \$combo = \$combo / " . ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) . ";\n";
- }
- $out .= "}\n";
-
-# print $out;
- eval $out;
-}
-
-# These sections can be interchanged to enable profiling.
-#$ShowTimers = 1;
-#use Time::HiRes;
-#sub SampleTime()
-#{
-# return Time::HiRes::time();
-#}
-
-$ShowTimers = 0;
-sub SampleTime() { return 0; }
-
-$total_start_time = SampleTime();
-
-# NOTE: These must match the same values in macros.vsh!
-$vPos = "v0";
-$vBoneWeights = "v1";
-$vBoneIndices = "v2";
-$vNormal = "v3";
-if( $g_x360 )
-{
- $vPosFlex = "v4";
- $vNormalFlex = "v13";
-}
-$vColor = "v5";
-$vSpecular = "v6";
-$vTexCoord0 = "v7";
-$vTexCoord1 = "v8";
-$vTexCoord2 = "v9";
-$vTexCoord3 = "v10";
-$vTangentS = "v11";
-$vTangentT = "v12";
-$vUserData = "v14";
-
-sub ReadInputFileWithLineInfo
-{
- local( $base_filename ) = shift;
-
- local( *INPUT );
- local( @output );
-
- # Look in the stdshaders directory, followed by the current directory.
- # (This is for the SDK, since some of its files are under stdshaders).
- local( $filename ) = $base_filename;
- if ( !-e $filename )
- {
- $filename = "$g_SourceDir\\materialsystem\\stdshaders\\$base_filename";
- if ( !-e $filename )
- {
- die "\nvsh_prep.pl ERROR: missing include file: $filename.\n\n";
- }
- }
-
- open INPUT, "<$filename" || die;
-
- local( $line );
- local( $linenum ) = 1;
- while( $line = <INPUT> )
- {
- $line =~ s/\n//g;
- local( $postfix ) = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
- $postfix .= "; LINEINFO($filename)($linenum)\n";
- if( $line =~ m/\#include\s+\"(.*)\"/i )
- {
- push @output, &ReadInputFileWithLineInfo( $1 );
- }
- else
- {
- push @output, $line . $postfix;
- }
- $linenum++;
- }
-
- close INPUT;
- return @output;
-}
-
-sub ReadInputFileWithoutLineInfo
-{
- local( $base_filename ) = shift;
-
- local( *INPUT );
- local( @output );
-
- # Look in the stdshaders directory, followed by the current directory.
- # (This is for the SDK, since some of its files are under stdshaders).
- local( $filename ) = $base_filename;
- if ( !-e $filename )
- {
- $filename = "$g_SourceDir\\materialsystem\\stdshaders\\$base_filename";
- if ( !-e $filename )
- {
- die "\nERROR: missing include file: $filename.\n\n";
- }
- }
-
- open INPUT, "<$filename" || die;
-
- local( $line );
- while( $line = <INPUT> )
- {
- if( $line =~ m/\#include\s+\"(.*)\"/i )
- {
- push @output, &ReadInputFileWithoutLineInfo( $1 );
- }
- else
- {
- push @output, $line;
- }
- }
-
- close INPUT;
- return @output;
-}
-
-sub IsPerl
-{
- local( $line ) = shift;
- if( $line =~ m/^\s*sub.*\,/ )
- {
- return 0;
- }
- if( $line =~ m/^\#include/ ||
- $line =~ m/^\#define/ ||
- $line =~ m/^\#undef/ ||
- $line =~ m/^\#ifdef/ ||
- $line =~ m/^\#ifndef/ ||
- $line =~ m/^\#else/ ||
- $line =~ m/^\#endif/ ||
- $line =~ m/^\#error/
- )
- {
- return 0;
- }
- if( $line =~ m/^\s*if\s*\(/ ||
- $line =~ m/^\s*else/ ||
- $line =~ m/^\s*elsif/ ||
- $line =~ m/^\s*for\s*\(/ ||
- $line =~ m/^\s*\{/ ||
- $line =~ m/^sub\s*/ ||
- $line =~ m/^\s*\}/ ||
- $line =~ m/^\s*\&/ ||
- $line =~ m/^\s*\#/ ||
- $line =~ m/^\s*\$/ ||
- $line =~ m/^\s*print/ ||
- $line =~ m/^\s*return/ ||
- $line =~ m/^\s*exit/ ||
- $line =~ m/^\s*die/ ||
- $line =~ m/^\s*eval/ ||
- $line =~ m/^\s*local/ ||
- $line =~ m/^\s*my\s+/ ||
- $line =~ m/^\s*@/ ||
- $line =~ m/^\s*alloc\s+/ ||
- $line =~ m/^\s*free\s+/
- )
- {
- return 1;
- }
- return 0;
-}
-
-# translate the output into something that takes us back to the source line
-# that we care about in msdev
-sub TranslateErrorMessages
-{
- local( $origline );
- while( $origline = shift )
- {
- if( $origline =~ m/(.*)\((\d+)\)\s*:\s*(.*)$/i )
- {
- local( $filename ) = $1;
- local( $linenum ) = $2;
- local( $error ) = $3;
- local( *FILE );
- open FILE, "<$filename" || die;
- local( $i );
- local( $line );
- for( $i = 1; $i < $linenum; $i++ )
- {
- $line = <FILE>;
- }
- if( $line =~ m/LINEINFO\((.*)\)\((.*)\)/ )
- {
- print "$1\($2\) : $error\n";
- my $num = $linenum - 1;
- print "$filename\($num\) : original error location\n";
- }
- close FILE;
- }
- else
- {
- $origline =~ s/successful compile\!.*//gi;
- if( !( $origline =~ m/^\s*$/ ) )
- {
-# print "WTF: $origline\n";
- }
- }
- }
-}
-
-
-sub CountInstructions
-{
- local( $line );
- local( $count ) = 0;
- while( $line = shift )
- {
- # get rid of comments
- $line =~ s/;.*//gi;
- $line =~ s/\/\/.*//gi;
- # skip the vs1.1 statement
- $line =~ s/^\s*vs.*//gi;
- # if there's any text left, it's an instruction
- if( $line =~ /\S/gi )
- {
- $count++;
- }
- }
- return $count;
-}
-
-
-%compiled = ();
-
-sub UsesRegister
-{
- my $registerName = shift;
- my $str = shift;
-
- # Cache a compiled RE for each register name. This makes UsesRegister about 2.5x faster.
- if ( !$compiled{$registerName} )
- {
- $compiled{$registerName} = qr/\b$registerName\b/;
- }
-
- $ret = 0;
- if( $str =~ /$compiled{$registerName}/gi )
- {
- $ret = 1;
- }
-
- return $ret;
-}
-
-sub PadString
-{
- local( $str ) = shift;
- local( $desiredLen ) = shift;
- local( $len ) = length $str;
- while( $len < $desiredLen )
- {
- $str .= " ";
- $len++;
- }
- return $str;
-}
-
-sub FixupAllocateFree
-{
- local( $line ) = shift;
- $line =~ s/\&AllocateRegister\s*\(\s*\\(\S+)\s*\)/&AllocateRegister( \\$1, \"\\$1\" )/g;
- $line =~ s/\&FreeRegister\s*\(\s*\\(\S+)\s*\)/&FreeRegister( \\$1, \"\\$1\" )/g;
- $line =~ s/alloc\s+(\S+)\s*/local( $1 ); &AllocateRegister( \\$1, \"\\$1\" );/g;
- $line =~ s/free\s+(\S+)\s*/&FreeRegister( \\$1, \"\\$1\" );/g;
- return $line;
-}
-
-sub TranslateDXKeywords
-{
- local( $line ) = shift;
- $line =~ s/\bENDIF\b/endif/g;
- $line =~ s/\bIF\b/if/g;
- $line =~ s/\bELSE\b/else/g;
-
- return $line;
-}
-
-# This is used to make the generated pl files all pretty.
-sub GetLeadingWhiteSpace
-{
- local( $str ) = shift;
- if( $str =~ m/^;\S/ || $str =~ m/^; \S/ )
- {
- return "";
- }
- $str =~ s/^;/ /g; # count a leading ";" as whitespace as far as this is concerned.
- $str =~ m/^(\s*)/;
- return $1;
-}
-
-$g_dx9 = 1;
-$g_SourceDir = "..\\..";
-
-while( 1 )
-{
- $filename = shift;
-
- if ( $filename =~ m/-source/i )
- {
- $g_SourceDir = shift;
- }
- elsif( $filename =~ m/-x360/i )
- {
- $g_x360 = 1;
- }
- else
- {
- last;
- }
-}
-
-$filename =~ s/-----.*$//;
-
-
-#
-# Get the shader binary version number from a header file.
-#
-open FILE, "<$g_SourceDir\\public\\materialsystem\\shader_vcs_version.h" || die;
-while( $line = <FILE> )
-{
- if( $line =~ m/^\#define\s+SHADER_VCS_VERSION_NUMBER\s+(\d+)\s*$/ )
- {
- $shaderVersion = $1;
- last;
- }
-}
-if( !defined $shaderVersion )
-{
- die "couldn't get shader version from shader_vcs_version.h";
-}
-close FILE;
-
-
-if( $g_x360 )
-{
- $vshtmp = "vshtmp9_360_tmp";
-}
-else
-{
- $vshtmp = "vshtmp9_tmp";
-}
-
-if( !stat $vshtmp )
-{
- mkdir $vshtmp, 0777 || die $!;
-}
-
-# suck in all files, including $include files.
-@input = &ReadInputFileWithLineInfo( $filename );
-
-sub CalcNumCombos
-{
- local( $i, $numCombos );
- $numCombos = 1;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
- }
- for( $i = 0; $i < scalar( @staticDefineNames ); $i++ )
- {
- $numCombos *= $staticDefineMax[$i] - $staticDefineMin[$i] + 1;
- }
- return $numCombos;
-}
-
-sub CalcNumDynamicCombos
-{
- local( $i, $numCombos );
- $numCombos = 1;
- for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ )
- {
- $numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1;
- }
- return $numCombos;
-}
-
-# READ THE TOP OF THE FILE TO FIND SHADER COMBOS
-foreach $_ ( @input )
-{
- next if( m/^\s*$/ );
-# last if( !m,^//, );
- s,^//\s*,,;
- if( m/\s*STATIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ )
- {
- local( $name, $min, $max );
- $name = $1;
- $min = $2;
- $max = $3;
-# print "\"$name\" \"$min..$max\"\n";
- if (/\[(.*)\]/)
- {
- $platforms=$1;
- next if ( ($g_x360) && (!($platforms=~/XBOX/i)) );
- next if ( (!$g_x360) && (!($platforms=~/PC/i)) );
- }
- push @staticDefineNames, $name;
- push @staticDefineMin, $min;
- push @staticDefineMax, $max;
- }
- elsif( m/\s*DYNAMIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ )
- {
- local( $name, $min, $max );
- $name = $1;
- $min = $2;
- $max = $3;
- if (/\[(.*)\]/)
- {
- $platforms=$1;
- next if ( ($g_x360) && (!($platforms=~/XBOX/i)) );
- next if ( (!$g_x360) && (!($platforms=~/PC/i)) );
- }
-# print "\"$name\" \"$min..$max\"\n";
- push @dynamicDefineNames, $name;
- push @dynamicDefineMin, $min;
- push @dynamicDefineMax, $max;
- }
-}
-
-# READ THE WHOLE FILE AND FIND SKIP STATEMENTS
-foreach $_ ( @input )
-{
- if( m/^\s*\#\s*SKIP\s*\:\s*(.*\S+)\s*\; LINEINFO.*$/ )
- {
- $perlskipcode .= "(" . $1 . ")||";
- push @perlskipcodeindividual, $1;
- }
-}
-if( defined $perlskipcode )
-{
- $perlskipcode .= "0";
- $perlskipcode =~ s/\n//g;
-}
-else
-{
- $perlskipcode = "0";
-}
-
-#print $perlskipcode . "\n";
-
-
-# Translate the input into a perl program that'll unroll everything and
-# substitute variables.
-while( $inputLine = shift @input )
-{
- $inputLine =~ s/\n//g;
- # leave out lines that are only whitespace.
- if( $inputLine =~ m/^\s*; LINEINFO.*$/ )
- {
- next;
- }
- local( $inputLineNoLineNum ) = $inputLine;
- $inputLineNoLineNum =~ s/; LINEINFO.*//gi;
- if( &IsPerl( $inputLineNoLineNum ) )
- {
- $inputLineNoLineNum = &FixupAllocateFree( $inputLineNoLineNum );
- push @outputProgram, $inputLineNoLineNum . "\n";
- }
- else
- {
- # make asm lines that have quotes in them not barf.
- $inputLine =~ s/\"/\\\"/g;
- $inputLine = &TranslateDXKeywords( $inputLine );
- push @outputProgram, &GetLeadingWhiteSpace( $inputLine ) . "push \@output, \"" .
- $inputLine . "\\n\";\n";
- }
-}
-
-$outputProgram = join "", @outputProgram;
-
-$filename_base = $filename;
-$filename_base =~ s/\.vsh//i;
-
-open DEBUGOUT, ">$vshtmp" . "/$filename_base.pl" || die;
-print DEBUGOUT $outputProgram;
-close DEBUGOUT;
-
-# Make a function called OutputProgram()
-$bigProg = "sub OutputProgram { " . $outputProgram . "}";
-eval( $bigProg );
-
-
-#print $outputProgram;
-
-#push @finalheader, "// hack to force dependency checking\n";
-#push @finalheader, "\#ifdef NEVER\n";
-#push @finalheader, "\#include \"" . $filename_base . "\.vsh\"\n";
-#push @finalheader, "\#include \"..\\..\\devtools\\bin\\vsh_prep.pl\"\n";
-#push @finalheader, "\#endif\n";
-
-%g_TimingBlocks = ();
-$main_start_time = SampleTime();
-
-$numCombos = &CalcNumCombos();
-$numDynamicCombos = &CalcNumDynamicCombos();
-#print "$numCombos total combos\n";
-#print "$numDynamicCombos dynamic combos\n";
-#print $numCombos / $numDynamicCombos . " static combos\n";
-
-# Write out the C++ helper class for picking shader combos
-$fxc_filename = $filename_base;
-&WriteStaticHelperClasses();
-&WriteDynamicHelperClasses();
-
-# Create a subroutine out of $perlskipcode
-$perlskipfunc = "sub SkipCombo { return $perlskipcode; }\n";
-#print $perlskipfunc;
-
-eval $perlskipfunc;
-&CreateFuncToSetPerlVars();
-
-my $incfilename = "$vshtmp/$filename_base" . ".inc";
-
-# Write the inc file that has indexing helpers, etc.
-&WriteFile( $incfilename, join( "", @outputHeader ) );
-
-
-# Run the output program for all the combinations of bones and lights.
-print "$filename_base.vsh\n";
-for( $i = 0; $i < $numCombos; $i++ )
-{
-# print "combo $i\n";
- &SetPerlVarsFunc( $i );
- local( $compileFailed );
- $ret = &SkipCombo;
- if( !defined $ret )
- {
- die "$@\n";
- }
- if( $ret )
- {
- # skip this combo!
- $compileFailed = 1;
- $numSkipped++;
- next;
- }
-
- $start = SampleTime();
-
- $g_usesPos = 0;
- $g_usesPosFlex = 0;
- $g_usesBoneWeights = 0;
- $g_usesBoneIndices = 0;
- $g_usesNormal = 0;
- $g_usesNormalFlex = 0;
- $g_usesColor = 0;
- $g_usesSpecular = 0;
- $g_usesTexCoord0 = 0;
- $g_usesTexCoord1 = 0;
- $g_usesTexCoord2 = 0;
- $g_usesTexCoord3 = 0;
- $g_usesTangentS = 0;
- $g_usesTangentT = 0;
- $g_usesUserData = 0;
-
- undef @output;
-
- $g_TimingBlocks{"inner1"} += SampleTime() - $start;
-
- $eval_start_time = SampleTime();
- &OutputProgram();
- $eval_total_time += (SampleTime() - $eval_start_time);
-
- $start = SampleTime();
-
- # Strip out comments once so we don't have to do it in all the UsesRegister calls.
- @stripped = @output;
- map
- {
- $_ =~ s/;.*//gi;
- $_ =~ s/\/\/.*//gi;
- } @stripped;
- my $strippedStr = join( "", @stripped );
-
- $g_TimingBlocks{"inner2"} += SampleTime() - $start;
-
- $start = SampleTime();
-
- # Have to make another pass through after we know which v registers are used. . yuck.
- $g_usesPos = &UsesRegister( $vPos, $strippedStr );
- if( $g_x360 )
- {
- $g_usesPosFlex = &UsesRegister( $vPosFlex, $strippedStr );
- $g_usesNormalFlex = &UsesRegister( $vNormalFlex, $strippedStr );
- }
- $g_usesBoneWeights = &UsesRegister( $vBoneWeights, $strippedStr );
- $g_usesBoneIndices = &UsesRegister( $vBoneIndices, $strippedStr );
- $g_usesNormal = &UsesRegister( $vNormal, $strippedStr );
- $g_usesColor = &UsesRegister( $vColor, $strippedStr );
- $g_usesSpecular = &UsesRegister( $vSpecular, $strippedStr );
- $g_usesTexCoord0 = &UsesRegister( $vTexCoord0, $strippedStr );
- $g_usesTexCoord1 = &UsesRegister( $vTexCoord1, $strippedStr );
- $g_usesTexCoord2 = &UsesRegister( $vTexCoord2, $strippedStr );
- $g_usesTexCoord3 = &UsesRegister( $vTexCoord3, $strippedStr );
- $g_usesTangentS = &UsesRegister( $vTangentS, $strippedStr );
- $g_usesTangentT = &UsesRegister( $vTangentT, $strippedStr );
- $g_usesUserData = &UsesRegister( $vUserData, $strippedStr );
- undef @output;
-
- $g_TimingBlocks{"inner2"} += SampleTime() - $start;
-
- $eval_start_time = SampleTime();
- # Running OutputProgram generates $outfilename
- &OutputProgram();
- $eval_total_time += (SampleTime() - $eval_start_time);
-
- $start = SampleTime();
-
- &CheckUnfreedRegisters();
-
- for( $j = 0; $j < scalar( @output ); $j++ )
- {
- # remove whitespace from the beginning of each line.
- $output[$j] =~ s/^\s+//;
- # remove LINEINFO from empty lines.
- $output[$j] =~ s/^; LINEINFO.*//;
- }
-
- $g_TimingBlocks{"inner3"} += SampleTime() - $start;
- $start = SampleTime();
-
-
- $outfilename_base = $filename_base . "_" . $i;
-
- # $outfilename is the name of the file generated from executing the perl code
- # for this shader. This file is generated once per combo.
- # We will assemble this shader with vsa.exe.
- $outfilename = "$vshtmp\\" . $outfilename_base . ".tmp";
-
-# $outhdrfilename = "$vshtmp\\" . $outfilename_base . ".h";
-# unlink $outhdrfilename;
-
- open OUTPUT, ">$outfilename" || die;
- print OUTPUT @output;
- close OUTPUT;
-
- $g_TimingBlocks{"inner4"} += SampleTime() - $start;
- $start = SampleTime();
-
- local( $instructionCount ) = &CountInstructions( @output );
- $g_TimingBlocks{"inner5"} += SampleTime() - $start;
-
- local( $debug );
-
- $debug = 1;
-# for( $debug = 1; $debug >= 0; $debug-- )
- {
- # assemble the vertex shader
- unlink "shader$i.o";
- if( $g_x360 )
- {
- $vsa = "..\\..\\x360xdk\\bin\\win32\\vsa";
- }
- else
- {
- $vsa = "..\\..\\dx9sdk\\utilities\\vsa";
- }
- $vsadebug = "$vsa /nologo /Foshader$i.o $outfilename";
- $vsanodebug = "$vsa /nologo /Foshader$i.o $outfilename";
-
- $vsa_start_time = SampleTime();
-
- if( $debug )
- {
-# print $vsadebug . "\n";
- @vsaoutput = `$vsadebug 2>&1`;
-# print @vsaoutput;
- }
- else
- {
- @vsaoutput = `$vsanodebug 2>&1`;
- }
-
- $vsa_total_time += SampleTime() - $vsa_start_time;
-
- $start = SampleTime();
-
- &TranslateErrorMessages( @vsaoutput );
-
- $g_TimingBlocks{"inner6"} += SampleTime() - $start;
-
- push @finalheader, @hdr;
- }
-}
-
-
-$main_total_time = SampleTime() - $main_start_time;
-
-# stick info about the shaders at the end of the inc file.
-push @finalheader, "static PrecompiledShaderByteCode_t $filename_base" . "_vertex_shaders[] = {\n";
-for( $i = 0; $i < $numCombos; $i++ )
-{
- $outfilename_base = $filename_base . "_" . $i;
- push @finalheader, "{ $outfilename_base, sizeof( $outfilename_base ) },\n";
-}
-push @finalheader, "};\n";
-
-
-push @finalheader, "struct $filename_base" . "_VertexShader_t : public PrecompiledShader_t\n";
-push @finalheader, "{\n";
-push @finalheader, "\t$filename_base" . "_VertexShader_t()\n";
-push @finalheader, "\t{\n";
-push @finalheader, "\t\tm_nFlags = 0;\n";
-
-$flags = 0;
-#push @finalheader, "\t\tppVertexShaders = $filename_base" . "_vertex_shaders;\n";
-push @finalheader, "\t\tm_pByteCode = $filename_base" . "_vertex_shaders;\n";
-push @finalheader, "\t\tm_pName = \"$filename_base\";\n";
-push @finalheader, "\t\tm_nShaderCount = " . ( $maxNumBones + 1 ) * $totalFogCombos * $totalLightCombos . ";\n";
-push @finalheader, "\t\tm_nDynamicCombos = m_nShaderCount;\n";
-push @finalheader, "\t\tGetShaderDLL()->InsertPrecompiledShader( PRECOMPILED_VERTEX_SHADER, this );\n";
-push @finalheader, "\t}\n";
-push @finalheader, "\tvirtual const PrecompiledShaderByteCode_t &GetByteCode( int shaderID )\n";
-push @finalheader, "\t{\n";
-push @finalheader, "\t\treturn m_pByteCode[shaderID];\n";
-push @finalheader, "\t}\n";
-push @finalheader, "};\n";
-push @finalheader, "static $filename_base" . "_VertexShader_t $filename_base" . "_VertexShaderInstance;\n";
-
-# Write the final header file with the compiled vertex shader programs.
-$finalheadername = "$vshtmp\\" . $filename_base . ".inc";
-#print "writing $finalheadername\n";
-#open FINALHEADER, ">$finalheadername" || die;
-#print FINALHEADER @finalheader;
-#close FINALHEADER;
-
-&MakeDirHier( "shaders/vsh" );
-
-my $vcsName = "";
-if( $g_x360 )
-{
- $vcsName = $filename_base . ".360.vcs";
-}
-else
-{
- $vcsName = $filename_base . ".vcs";
-}
-open COMPILEDSHADER, ">shaders/vsh/$vcsName" || die;
-binmode( COMPILEDSHADER );
-
-#
-# Write out the part of the header that we know. . we'll write the rest after writing the object code.
-#
-
-# Pack arguments
-my $sInt = "i";
-my $uInt = "I";
-if ( $g_x360 )
-{
- # Change arguments to "big endian long"
- $sInt = "N";
- $uInt = "N";
-}
-
-my $undecoratedinput = join "", &ReadInputFileWithoutLineInfo( $filename );
-#print STDERR "undecoratedinput: $undecoratedinput\n";
-my $crc = crc32( $undecoratedinput );
-#print STDERR "crc for $filename: $crc\n";
-
-# version
-print COMPILEDSHADER pack $sInt, 4;
-# totalCombos
-print COMPILEDSHADER pack $sInt, $numCombos;
-# dynamic combos
-print COMPILEDSHADER pack $sInt, $numDynamicCombos;
-# flags
-print COMPILEDSHADER pack $uInt, $flags;
-# centroid mask
-print COMPILEDSHADER pack $uInt, 0;
-# reference size
-print COMPILEDSHADER pack $uInt, 0;
-# crc32 of the source code
-print COMPILEDSHADER pack $uInt, $crc;
-
-my $beginningOfDir = tell COMPILEDSHADER;
-
-# Write out a blank directionary. . we'll fill it in later.
-for( $i = 0; $i < $numCombos; $i++ )
-{
- # offset from beginning of file.
- print COMPILEDSHADER pack $sInt, 0;
- # size
- print COMPILEDSHADER pack $sInt, 0;
-}
-
-my $startByteCode = tell COMPILEDSHADER;
-my @byteCodeStart;
-my @byteCodeSize;
-
-# Write out the shader object code.
-for( $shaderCombo = 0; $shaderCombo < $numCombos; $shaderCombo++ )
-{
- my $filename = "shader$shaderCombo\.o";
- my $filesize = (stat $filename)[7];
- $byteCodeStart[$shaderCombo] = tell COMPILEDSHADER;
- $byteCodeSize[$shaderCombo] = $filesize;
- open SHADERBYTECODE, "<$filename" || die;
- binmode SHADERBYTECODE;
- my $bin;
- my $numread = read SHADERBYTECODE, $bin, $filesize;
-# print "filename: $filename numread: $numread filesize: $filesize\n";
- close SHADERBYTECODE;
- unlink $filename;
-
- print COMPILEDSHADER $bin;
-}
-
-# Seek back to the directory and write it out.
-seek COMPILEDSHADER, $beginningOfDir, 0;
-for( $i = 0; $i < $numCombos; $i++ )
-{
- # offset from beginning of file.
- print COMPILEDSHADER pack $sInt, $byteCodeStart[$i];
- # size
- print COMPILEDSHADER pack $sInt, $byteCodeSize[$i];
-}
-
-close COMPILEDSHADER;
-
-$total_time = SampleTime() - $total_start_time;
-
-if ( $ShowTimers )
-{
- print "\n\n";
- print sprintf( "Main loop time : %0.4f sec, (%0.2f%%)\n", $main_total_time, 100*$main_total_time / $total_time );
- print sprintf( "Inner1 time : %0.4f sec, (%0.2f%%)\n", $inner1_total_time, 100*$inner1_total_time / $total_time );
- print sprintf( "VSA time : %0.4f sec, (%0.2f%%)\n", $vsa_total_time, 100*$vsa_total_time / $total_time );
- print sprintf( "eval() time : %0.4f sec, (%0.2f%%)\n", $eval_total_time, 100*$eval_total_time / $total_time );
- print sprintf( "UsesRegister time: %0.4f sec, (%0.2f%%)\n", $usesr_total_time, 100*$usesr_total_time / $total_time );
-
- foreach $key ( keys %g_TimingBlocks )
- {
- print sprintf( "$key time: %0.4f sec, (%0.2f%%)\n", $g_TimingBlocks{$key}, 100*$g_TimingBlocks{$key} / $total_time );
- }
-
- print sprintf( "Total time : %0.4f sec\n", $total_time );
-}
-
+use String::CRC32; +BEGIN {use File::Basename; push @INC, dirname($0); } +require "valve_perl_helpers.pl"; + +sub WriteHelperVar +{ + local( $name ) = shift; + local( $min ) = shift; + local( $max ) = shift; + local( $varname ) = "m_n" . $name; + local( $boolname ) = "m_b" . $name; + push @outputHeader, "private:\n"; + push @outputHeader, "\tint $varname;\n"; + push @outputHeader, "#ifdef _DEBUG\n"; + push @outputHeader, "\tbool $boolname;\n"; + push @outputHeader, "#endif\n"; + push @outputHeader, "public:\n"; + # int version of set function + push @outputHeader, "\tvoid Set" . $name . "( int i )\n"; + push @outputHeader, "\t{\n"; + if ( $min != $max ) + { + push @outputHeader, "\t\tAssert( i >= $min && i <= $max );\n"; + push @outputHeader, "\t\t$varname = i;\n"; + push @outputHeader, "#ifdef _DEBUG\n"; + push @outputHeader, "\t\t$boolname = true;\n"; + push @outputHeader, "#endif\n"; + } + push @outputHeader, "\t}\n"; + # bool version of set function + push @outputHeader, "\tvoid Set" . $name . "( bool i )\n"; + push @outputHeader, "\t{\n"; + if ( $min != $max ) + { +# push @outputHeader, "\t\tAssert( i >= $min && i <= $max );\n"; + push @outputHeader, "\t\t$varname = i ? 1 : 0;\n"; + push @outputHeader, "#ifdef _DEBUG\n"; + push @outputHeader, "\t\t$boolname = true;\n"; + push @outputHeader, "#endif\n"; + } + push @outputHeader, "\t}\n"; +} + +sub WriteStaticBoolExpression +{ + local( $prefix ) = shift; + local( $operator ) = shift; + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + if( $i ) + { + push @outputHeader, " $operator "; + } + local( $name ) = @staticDefineNames[$i]; + local( $boolname ) = "m_b" . $name; + push @outputHeader, "$prefix$boolname"; + } + push @outputHeader, ";\n"; +} + +sub WriteDynamicBoolExpression +{ + local( $prefix ) = shift; + local( $operator ) = shift; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + if( $i ) + { + push @outputHeader, " $operator "; + } + local( $name ) = @dynamicDefineNames[$i]; + local( $boolname ) = "m_b" . $name; + push @outputHeader, "$prefix$boolname"; + } + push @outputHeader, ";\n"; +} + +sub WriteDynamicHelperClasses +{ + local( $basename ) = $fxc_filename; + $basename =~ s/\.fxc//i; + $basename =~ tr/A-Z/a-z/; + local( $classname ) = $basename . "_Dynamic_Index"; + push @outputHeader, "class $classname\n"; + push @outputHeader, "{\n"; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $name = $dynamicDefineNames[$i]; + $min = $dynamicDefineMin[$i]; + $max = $dynamicDefineMax[$i]; + &WriteHelperVar( $name, $min, $max ); + } + push @outputHeader, "public:\n"; + push @outputHeader, "\t$classname()\n"; + push @outputHeader, "\t{\n"; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $min = $dynamicDefineMin[$i]; + $max = $dynamicDefineMax[$i]; + + local( $name ) = @dynamicDefineNames[$i]; + local( $boolname ) = "m_b" . $name; + local( $varname ) = "m_n" . $name; + push @outputHeader, "#ifdef _DEBUG\n"; + if ( $min != $max ) + { + push @outputHeader, "\t\t$boolname = false;\n"; + } + else + { + push @outputHeader, "\t\t$boolname = true;\n"; + } + push @outputHeader, "#endif // _DEBUG\n"; + push @outputHeader, "\t\t$varname = 0;\n"; + } + push @outputHeader, "\t}\n"; + push @outputHeader, "\tint GetIndex()\n"; + push @outputHeader, "\t{\n"; + push @outputHeader, "\t\t// Asserts to make sure that we aren't using any skipped combinations.\n"; + foreach $skip (@perlskipcodeindividual) + { + $skip =~ s/\$/m_n/g; +# push @outputHeader, "\t\tAssert( !( $skip ) );\n"; + } + push @outputHeader, "\t\t// Asserts to make sure that we are setting all of the combination vars.\n"; + + push @outputHeader, "#ifdef _DEBUG\n"; + if( scalar( @dynamicDefineNames ) > 0 ) + { + push @outputHeader, "\t\tbool bAllDynamicVarsDefined = "; + WriteDynamicBoolExpression( "", "&&" ); + } + if( scalar( @dynamicDefineNames ) > 0 ) + { + push @outputHeader, "\t\tAssert( bAllDynamicVarsDefined );\n"; + } + push @outputHeader, "#endif // _DEBUG\n"; + + if( $spewCombos && scalar( @dynamicDefineNames ) ) + { + push @outputHeader, &CreateCCodeToSpewDynamicCombo(); + } + push @outputHeader, "\t\treturn "; + local( $scale ) = 1; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + local( $name ) = @dynamicDefineNames[$i]; + local( $varname ) = "m_n" . $name; + push @outputHeader, "( $scale * $varname ) + "; + $scale *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1; + } + push @outputHeader, "0;\n"; + push @outputHeader, "\t}\n"; + push @outputHeader, "};\n"; +} + +sub WriteStaticHelperClasses +{ + local( $basename ) = $fxc_filename; + $basename =~ s/\.fxc//i; + $basename =~ tr/A-Z/a-z/; + local( $classname ) = $basename . "_Static_Index"; + push @outputHeader, "class $classname\n"; + push @outputHeader, "{\n"; + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + $name = $staticDefineNames[$i]; + $min = $staticDefineMin[$i]; + $max = $staticDefineMax[$i]; + &WriteHelperVar( $name, $min, $max ); + } + push @outputHeader, "public:\n"; + push @outputHeader, "\t$classname()\n"; + push @outputHeader, "\t{\n"; + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + $min = $staticDefineMin[$i]; + $max = $staticDefineMax[$i]; + + local( $name ) = @staticDefineNames[$i]; + local( $boolname ) = "m_b" . $name; + local( $varname ) = "m_n" . $name; + + push @outputHeader, "#ifdef _DEBUG\n"; + if ( $min != $max ) + { + push @outputHeader, "\t\t$boolname = false;\n"; + } + else + { + push @outputHeader, "\t\t$boolname = true;\n"; + } + push @outputHeader, "#endif // _DEBUG\n"; + push @outputHeader, "\t\t$varname = 0;\n"; + } + push @outputHeader, "\t}\n"; + push @outputHeader, "\tint GetIndex()\n"; + push @outputHeader, "\t{\n"; + push @outputHeader, "\t\t// Asserts to make sure that we aren't using any skipped combinations.\n"; + foreach $skip (@perlskipcodeindividual) + { + $skip =~ s/\$/m_n/g; +# push @outputHeader, "\t\tAssert( !( $skip ) );\n"; + } + push @outputHeader, "\t\t// Asserts to make sure that we are setting all of the combination vars.\n"; + + push @outputHeader, "#ifdef _DEBUG\n"; + if( scalar( @staticDefineNames ) > 0 ) + { + push @outputHeader, "\t\tbool bAllStaticVarsDefined = "; + WriteStaticBoolExpression( "", "&&" ); + + } + if( scalar( @staticDefineNames ) > 0 ) + { + push @outputHeader, "\t\tAssert( bAllStaticVarsDefined );\n"; + } + push @outputHeader, "#endif // _DEBUG\n"; + + if( $spewCombos && scalar( @staticDefineNames ) ) + { + push @outputHeader, &CreateCCodeToSpewStaticCombo(); + } + push @outputHeader, "\t\treturn "; + local( $scale ) = 1; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $scale *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1; + } + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + local( $name ) = @staticDefineNames[$i]; + local( $varname ) = "m_n" . $name; + push @outputHeader, "( $scale * $varname ) + "; + $scale *= $staticDefineMax[$i] - $staticDefineMin[$i] + 1; + } + push @outputHeader, "0;\n"; + push @outputHeader, "\t}\n"; + push @outputHeader, "};\n"; +} + +sub CreateFuncToSetPerlVars +{ + local( $out ) = ""; + + $out .= "sub SetPerlVarsFunc\n"; + $out .= "{\n"; + $out .= " local( \$combo ) = shift;\n"; + $out .= " local( \$i );\n"; + local( $i ); + for( $i = 0; $i < scalar( @dynamicDefineNames ); \$i++ ) + { + $out .= " \$$dynamicDefineNames[$i] = \$combo % "; + $out .= ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) + $dynamicDefineMin[$i]; + $out .= ";\n"; + $out .= " \$combo = \$combo / " . ( $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1 ) . ";\n"; + } + for( $i = 0; $i < scalar( @staticDefineNames ); \$i++ ) + { + $out .= " \$$staticDefineNames[$i] = \$combo % "; + $out .= ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) + $staticDefineMin[$i]; + $out .= ";\n"; + $out .= " \$combo = \$combo / " . ( $staticDefineMax[$i] - $staticDefineMin[$i] + 1 ) . ";\n"; + } + $out .= "}\n"; + +# print $out; + eval $out; +} + +# These sections can be interchanged to enable profiling. +#$ShowTimers = 1; +#use Time::HiRes; +#sub SampleTime() +#{ +# return Time::HiRes::time(); +#} + +$ShowTimers = 0; +sub SampleTime() { return 0; } + +$total_start_time = SampleTime(); + +# NOTE: These must match the same values in macros.vsh! +$vPos = "v0"; +$vBoneWeights = "v1"; +$vBoneIndices = "v2"; +$vNormal = "v3"; +if( $g_x360 ) +{ + $vPosFlex = "v4"; + $vNormalFlex = "v13"; +} +$vColor = "v5"; +$vSpecular = "v6"; +$vTexCoord0 = "v7"; +$vTexCoord1 = "v8"; +$vTexCoord2 = "v9"; +$vTexCoord3 = "v10"; +$vTangentS = "v11"; +$vTangentT = "v12"; +$vUserData = "v14"; + +sub ReadInputFileWithLineInfo +{ + local( $base_filename ) = shift; + + local( *INPUT ); + local( @output ); + + # Look in the stdshaders directory, followed by the current directory. + # (This is for the SDK, since some of its files are under stdshaders). + local( $filename ) = $base_filename; + if ( !-e $filename ) + { + $filename = "$g_SourceDir\\materialsystem\\stdshaders\\$base_filename"; + if ( !-e $filename ) + { + die "\nvsh_prep.pl ERROR: missing include file: $filename.\n\n"; + } + } + + open INPUT, "<$filename" || die; + + local( $line ); + local( $linenum ) = 1; + while( $line = <INPUT> ) + { + $line =~ s/\n//g; + local( $postfix ) = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; + $postfix .= "; LINEINFO($filename)($linenum)\n"; + if( $line =~ m/\#include\s+\"(.*)\"/i ) + { + push @output, &ReadInputFileWithLineInfo( $1 ); + } + else + { + push @output, $line . $postfix; + } + $linenum++; + } + + close INPUT; + return @output; +} + +sub ReadInputFileWithoutLineInfo +{ + local( $base_filename ) = shift; + + local( *INPUT ); + local( @output ); + + # Look in the stdshaders directory, followed by the current directory. + # (This is for the SDK, since some of its files are under stdshaders). + local( $filename ) = $base_filename; + if ( !-e $filename ) + { + $filename = "$g_SourceDir\\materialsystem\\stdshaders\\$base_filename"; + if ( !-e $filename ) + { + die "\nERROR: missing include file: $filename.\n\n"; + } + } + + open INPUT, "<$filename" || die; + + local( $line ); + while( $line = <INPUT> ) + { + if( $line =~ m/\#include\s+\"(.*)\"/i ) + { + push @output, &ReadInputFileWithoutLineInfo( $1 ); + } + else + { + push @output, $line; + } + } + + close INPUT; + return @output; +} + +sub IsPerl +{ + local( $line ) = shift; + if( $line =~ m/^\s*sub.*\,/ ) + { + return 0; + } + if( $line =~ m/^\#include/ || + $line =~ m/^\#define/ || + $line =~ m/^\#undef/ || + $line =~ m/^\#ifdef/ || + $line =~ m/^\#ifndef/ || + $line =~ m/^\#else/ || + $line =~ m/^\#endif/ || + $line =~ m/^\#error/ + ) + { + return 0; + } + if( $line =~ m/^\s*if\s*\(/ || + $line =~ m/^\s*else/ || + $line =~ m/^\s*elsif/ || + $line =~ m/^\s*for\s*\(/ || + $line =~ m/^\s*\{/ || + $line =~ m/^sub\s*/ || + $line =~ m/^\s*\}/ || + $line =~ m/^\s*\&/ || + $line =~ m/^\s*\#/ || + $line =~ m/^\s*\$/ || + $line =~ m/^\s*print/ || + $line =~ m/^\s*return/ || + $line =~ m/^\s*exit/ || + $line =~ m/^\s*die/ || + $line =~ m/^\s*eval/ || + $line =~ m/^\s*local/ || + $line =~ m/^\s*my\s+/ || + $line =~ m/^\s*@/ || + $line =~ m/^\s*alloc\s+/ || + $line =~ m/^\s*free\s+/ + ) + { + return 1; + } + return 0; +} + +# translate the output into something that takes us back to the source line +# that we care about in msdev +sub TranslateErrorMessages +{ + local( $origline ); + while( $origline = shift ) + { + if( $origline =~ m/(.*)\((\d+)\)\s*:\s*(.*)$/i ) + { + local( $filename ) = $1; + local( $linenum ) = $2; + local( $error ) = $3; + local( *FILE ); + open FILE, "<$filename" || die; + local( $i ); + local( $line ); + for( $i = 1; $i < $linenum; $i++ ) + { + $line = <FILE>; + } + if( $line =~ m/LINEINFO\((.*)\)\((.*)\)/ ) + { + print "$1\($2\) : $error\n"; + my $num = $linenum - 1; + print "$filename\($num\) : original error location\n"; + } + close FILE; + } + else + { + $origline =~ s/successful compile\!.*//gi; + if( !( $origline =~ m/^\s*$/ ) ) + { +# print "WTF: $origline\n"; + } + } + } +} + + +sub CountInstructions +{ + local( $line ); + local( $count ) = 0; + while( $line = shift ) + { + # get rid of comments + $line =~ s/;.*//gi; + $line =~ s/\/\/.*//gi; + # skip the vs1.1 statement + $line =~ s/^\s*vs.*//gi; + # if there's any text left, it's an instruction + if( $line =~ /\S/gi ) + { + $count++; + } + } + return $count; +} + + +%compiled = (); + +sub UsesRegister +{ + my $registerName = shift; + my $str = shift; + + # Cache a compiled RE for each register name. This makes UsesRegister about 2.5x faster. + if ( !$compiled{$registerName} ) + { + $compiled{$registerName} = qr/\b$registerName\b/; + } + + $ret = 0; + if( $str =~ /$compiled{$registerName}/gi ) + { + $ret = 1; + } + + return $ret; +} + +sub PadString +{ + local( $str ) = shift; + local( $desiredLen ) = shift; + local( $len ) = length $str; + while( $len < $desiredLen ) + { + $str .= " "; + $len++; + } + return $str; +} + +sub FixupAllocateFree +{ + local( $line ) = shift; + $line =~ s/\&AllocateRegister\s*\(\s*\\(\S+)\s*\)/&AllocateRegister( \\$1, \"\\$1\" )/g; + $line =~ s/\&FreeRegister\s*\(\s*\\(\S+)\s*\)/&FreeRegister( \\$1, \"\\$1\" )/g; + $line =~ s/alloc\s+(\S+)\s*/local( $1 ); &AllocateRegister( \\$1, \"\\$1\" );/g; + $line =~ s/free\s+(\S+)\s*/&FreeRegister( \\$1, \"\\$1\" );/g; + return $line; +} + +sub TranslateDXKeywords +{ + local( $line ) = shift; + $line =~ s/\bENDIF\b/endif/g; + $line =~ s/\bIF\b/if/g; + $line =~ s/\bELSE\b/else/g; + + return $line; +} + +# This is used to make the generated pl files all pretty. +sub GetLeadingWhiteSpace +{ + local( $str ) = shift; + if( $str =~ m/^;\S/ || $str =~ m/^; \S/ ) + { + return ""; + } + $str =~ s/^;/ /g; # count a leading ";" as whitespace as far as this is concerned. + $str =~ m/^(\s*)/; + return $1; +} + +$g_dx9 = 1; +$g_SourceDir = "..\\.."; + +while( 1 ) +{ + $filename = shift; + + if ( $filename =~ m/-source/i ) + { + $g_SourceDir = shift; + } + elsif( $filename =~ m/-x360/i ) + { + $g_x360 = 1; + } + else + { + last; + } +} + +$filename =~ s/-----.*$//; + + +# +# Get the shader binary version number from a header file. +# +open FILE, "<$g_SourceDir\\public\\materialsystem\\shader_vcs_version.h" || die; +while( $line = <FILE> ) +{ + if( $line =~ m/^\#define\s+SHADER_VCS_VERSION_NUMBER\s+(\d+)\s*$/ ) + { + $shaderVersion = $1; + last; + } +} +if( !defined $shaderVersion ) +{ + die "couldn't get shader version from shader_vcs_version.h"; +} +close FILE; + + +if( $g_x360 ) +{ + $vshtmp = "vshtmp9_360_tmp"; +} +else +{ + $vshtmp = "vshtmp9_tmp"; +} + +if( !stat $vshtmp ) +{ + mkdir $vshtmp, 0777 || die $!; +} + +# suck in all files, including $include files. +@input = &ReadInputFileWithLineInfo( $filename ); + +sub CalcNumCombos +{ + local( $i, $numCombos ); + $numCombos = 1; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1; + } + for( $i = 0; $i < scalar( @staticDefineNames ); $i++ ) + { + $numCombos *= $staticDefineMax[$i] - $staticDefineMin[$i] + 1; + } + return $numCombos; +} + +sub CalcNumDynamicCombos +{ + local( $i, $numCombos ); + $numCombos = 1; + for( $i = 0; $i < scalar( @dynamicDefineNames ); $i++ ) + { + $numCombos *= $dynamicDefineMax[$i] - $dynamicDefineMin[$i] + 1; + } + return $numCombos; +} + +# READ THE TOP OF THE FILE TO FIND SHADER COMBOS +foreach $_ ( @input ) +{ + next if( m/^\s*$/ ); +# last if( !m,^//, ); + s,^//\s*,,; + if( m/\s*STATIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ ) + { + local( $name, $min, $max ); + $name = $1; + $min = $2; + $max = $3; +# print "\"$name\" \"$min..$max\"\n"; + if (/\[(.*)\]/) + { + $platforms=$1; + next if ( ($g_x360) && (!($platforms=~/XBOX/i)) ); + next if ( (!$g_x360) && (!($platforms=~/PC/i)) ); + } + push @staticDefineNames, $name; + push @staticDefineMin, $min; + push @staticDefineMax, $max; + } + elsif( m/\s*DYNAMIC\s*\:\s*\"(.*)\"\s+\"(\d+)\.\.(\d+)\"/ ) + { + local( $name, $min, $max ); + $name = $1; + $min = $2; + $max = $3; + if (/\[(.*)\]/) + { + $platforms=$1; + next if ( ($g_x360) && (!($platforms=~/XBOX/i)) ); + next if ( (!$g_x360) && (!($platforms=~/PC/i)) ); + } +# print "\"$name\" \"$min..$max\"\n"; + push @dynamicDefineNames, $name; + push @dynamicDefineMin, $min; + push @dynamicDefineMax, $max; + } +} + +# READ THE WHOLE FILE AND FIND SKIP STATEMENTS +foreach $_ ( @input ) +{ + if( m/^\s*\#\s*SKIP\s*\:\s*(.*\S+)\s*\; LINEINFO.*$/ ) + { + $perlskipcode .= "(" . $1 . ")||"; + push @perlskipcodeindividual, $1; + } +} +if( defined $perlskipcode ) +{ + $perlskipcode .= "0"; + $perlskipcode =~ s/\n//g; +} +else +{ + $perlskipcode = "0"; +} + +#print $perlskipcode . "\n"; + + +# Translate the input into a perl program that'll unroll everything and +# substitute variables. +while( $inputLine = shift @input ) +{ + $inputLine =~ s/\n//g; + # leave out lines that are only whitespace. + if( $inputLine =~ m/^\s*; LINEINFO.*$/ ) + { + next; + } + local( $inputLineNoLineNum ) = $inputLine; + $inputLineNoLineNum =~ s/; LINEINFO.*//gi; + if( &IsPerl( $inputLineNoLineNum ) ) + { + $inputLineNoLineNum = &FixupAllocateFree( $inputLineNoLineNum ); + push @outputProgram, $inputLineNoLineNum . "\n"; + } + else + { + # make asm lines that have quotes in them not barf. + $inputLine =~ s/\"/\\\"/g; + $inputLine = &TranslateDXKeywords( $inputLine ); + push @outputProgram, &GetLeadingWhiteSpace( $inputLine ) . "push \@output, \"" . + $inputLine . "\\n\";\n"; + } +} + +$outputProgram = join "", @outputProgram; + +$filename_base = $filename; +$filename_base =~ s/\.vsh//i; + +open DEBUGOUT, ">$vshtmp" . "/$filename_base.pl" || die; +print DEBUGOUT $outputProgram; +close DEBUGOUT; + +# Make a function called OutputProgram() +$bigProg = "sub OutputProgram { " . $outputProgram . "}"; +eval( $bigProg ); + + +#print $outputProgram; + +#push @finalheader, "// hack to force dependency checking\n"; +#push @finalheader, "\#ifdef NEVER\n"; +#push @finalheader, "\#include \"" . $filename_base . "\.vsh\"\n"; +#push @finalheader, "\#include \"..\\..\\devtools\\bin\\vsh_prep.pl\"\n"; +#push @finalheader, "\#endif\n"; + +%g_TimingBlocks = (); +$main_start_time = SampleTime(); + +$numCombos = &CalcNumCombos(); +$numDynamicCombos = &CalcNumDynamicCombos(); +#print "$numCombos total combos\n"; +#print "$numDynamicCombos dynamic combos\n"; +#print $numCombos / $numDynamicCombos . " static combos\n"; + +# Write out the C++ helper class for picking shader combos +$fxc_filename = $filename_base; +&WriteStaticHelperClasses(); +&WriteDynamicHelperClasses(); + +# Create a subroutine out of $perlskipcode +$perlskipfunc = "sub SkipCombo { return $perlskipcode; }\n"; +#print $perlskipfunc; + +eval $perlskipfunc; +&CreateFuncToSetPerlVars(); + +my $incfilename = "$vshtmp/$filename_base" . ".inc"; + +# Write the inc file that has indexing helpers, etc. +&WriteFile( $incfilename, join( "", @outputHeader ) ); + + +# Run the output program for all the combinations of bones and lights. +print "$filename_base.vsh\n"; +for( $i = 0; $i < $numCombos; $i++ ) +{ +# print "combo $i\n"; + &SetPerlVarsFunc( $i ); + local( $compileFailed ); + $ret = &SkipCombo; + if( !defined $ret ) + { + die "$@\n"; + } + if( $ret ) + { + # skip this combo! + $compileFailed = 1; + $numSkipped++; + next; + } + + $start = SampleTime(); + + $g_usesPos = 0; + $g_usesPosFlex = 0; + $g_usesBoneWeights = 0; + $g_usesBoneIndices = 0; + $g_usesNormal = 0; + $g_usesNormalFlex = 0; + $g_usesColor = 0; + $g_usesSpecular = 0; + $g_usesTexCoord0 = 0; + $g_usesTexCoord1 = 0; + $g_usesTexCoord2 = 0; + $g_usesTexCoord3 = 0; + $g_usesTangentS = 0; + $g_usesTangentT = 0; + $g_usesUserData = 0; + + undef @output; + + $g_TimingBlocks{"inner1"} += SampleTime() - $start; + + $eval_start_time = SampleTime(); + &OutputProgram(); + $eval_total_time += (SampleTime() - $eval_start_time); + + $start = SampleTime(); + + # Strip out comments once so we don't have to do it in all the UsesRegister calls. + @stripped = @output; + map + { + $_ =~ s/;.*//gi; + $_ =~ s/\/\/.*//gi; + } @stripped; + my $strippedStr = join( "", @stripped ); + + $g_TimingBlocks{"inner2"} += SampleTime() - $start; + + $start = SampleTime(); + + # Have to make another pass through after we know which v registers are used. . yuck. + $g_usesPos = &UsesRegister( $vPos, $strippedStr ); + if( $g_x360 ) + { + $g_usesPosFlex = &UsesRegister( $vPosFlex, $strippedStr ); + $g_usesNormalFlex = &UsesRegister( $vNormalFlex, $strippedStr ); + } + $g_usesBoneWeights = &UsesRegister( $vBoneWeights, $strippedStr ); + $g_usesBoneIndices = &UsesRegister( $vBoneIndices, $strippedStr ); + $g_usesNormal = &UsesRegister( $vNormal, $strippedStr ); + $g_usesColor = &UsesRegister( $vColor, $strippedStr ); + $g_usesSpecular = &UsesRegister( $vSpecular, $strippedStr ); + $g_usesTexCoord0 = &UsesRegister( $vTexCoord0, $strippedStr ); + $g_usesTexCoord1 = &UsesRegister( $vTexCoord1, $strippedStr ); + $g_usesTexCoord2 = &UsesRegister( $vTexCoord2, $strippedStr ); + $g_usesTexCoord3 = &UsesRegister( $vTexCoord3, $strippedStr ); + $g_usesTangentS = &UsesRegister( $vTangentS, $strippedStr ); + $g_usesTangentT = &UsesRegister( $vTangentT, $strippedStr ); + $g_usesUserData = &UsesRegister( $vUserData, $strippedStr ); + undef @output; + + $g_TimingBlocks{"inner2"} += SampleTime() - $start; + + $eval_start_time = SampleTime(); + # Running OutputProgram generates $outfilename + &OutputProgram(); + $eval_total_time += (SampleTime() - $eval_start_time); + + $start = SampleTime(); + + &CheckUnfreedRegisters(); + + for( $j = 0; $j < scalar( @output ); $j++ ) + { + # remove whitespace from the beginning of each line. + $output[$j] =~ s/^\s+//; + # remove LINEINFO from empty lines. + $output[$j] =~ s/^; LINEINFO.*//; + } + + $g_TimingBlocks{"inner3"} += SampleTime() - $start; + $start = SampleTime(); + + + $outfilename_base = $filename_base . "_" . $i; + + # $outfilename is the name of the file generated from executing the perl code + # for this shader. This file is generated once per combo. + # We will assemble this shader with vsa.exe. + $outfilename = "$vshtmp\\" . $outfilename_base . ".tmp"; + +# $outhdrfilename = "$vshtmp\\" . $outfilename_base . ".h"; +# unlink $outhdrfilename; + + open OUTPUT, ">$outfilename" || die; + print OUTPUT @output; + close OUTPUT; + + $g_TimingBlocks{"inner4"} += SampleTime() - $start; + $start = SampleTime(); + + local( $instructionCount ) = &CountInstructions( @output ); + $g_TimingBlocks{"inner5"} += SampleTime() - $start; + + local( $debug ); + + $debug = 1; +# for( $debug = 1; $debug >= 0; $debug-- ) + { + # assemble the vertex shader + unlink "shader$i.o"; + if( $g_x360 ) + { + $vsa = "..\\..\\x360xdk\\bin\\win32\\vsa"; + } + else + { + $vsa = "..\\..\\dx9sdk\\utilities\\vsa"; + } + $vsadebug = "$vsa /nologo /Foshader$i.o $outfilename"; + $vsanodebug = "$vsa /nologo /Foshader$i.o $outfilename"; + + $vsa_start_time = SampleTime(); + + if( $debug ) + { +# print $vsadebug . "\n"; + @vsaoutput = `$vsadebug 2>&1`; +# print @vsaoutput; + } + else + { + @vsaoutput = `$vsanodebug 2>&1`; + } + + $vsa_total_time += SampleTime() - $vsa_start_time; + + $start = SampleTime(); + + &TranslateErrorMessages( @vsaoutput ); + + $g_TimingBlocks{"inner6"} += SampleTime() - $start; + + push @finalheader, @hdr; + } +} + + +$main_total_time = SampleTime() - $main_start_time; + +# stick info about the shaders at the end of the inc file. +push @finalheader, "static PrecompiledShaderByteCode_t $filename_base" . "_vertex_shaders[] = {\n"; +for( $i = 0; $i < $numCombos; $i++ ) +{ + $outfilename_base = $filename_base . "_" . $i; + push @finalheader, "{ $outfilename_base, sizeof( $outfilename_base ) },\n"; +} +push @finalheader, "};\n"; + + +push @finalheader, "struct $filename_base" . "_VertexShader_t : public PrecompiledShader_t\n"; +push @finalheader, "{\n"; +push @finalheader, "\t$filename_base" . "_VertexShader_t()\n"; +push @finalheader, "\t{\n"; +push @finalheader, "\t\tm_nFlags = 0;\n"; + +$flags = 0; +#push @finalheader, "\t\tppVertexShaders = $filename_base" . "_vertex_shaders;\n"; +push @finalheader, "\t\tm_pByteCode = $filename_base" . "_vertex_shaders;\n"; +push @finalheader, "\t\tm_pName = \"$filename_base\";\n"; +push @finalheader, "\t\tm_nShaderCount = " . ( $maxNumBones + 1 ) * $totalFogCombos * $totalLightCombos . ";\n"; +push @finalheader, "\t\tm_nDynamicCombos = m_nShaderCount;\n"; +push @finalheader, "\t\tGetShaderDLL()->InsertPrecompiledShader( PRECOMPILED_VERTEX_SHADER, this );\n"; +push @finalheader, "\t}\n"; +push @finalheader, "\tvirtual const PrecompiledShaderByteCode_t &GetByteCode( int shaderID )\n"; +push @finalheader, "\t{\n"; +push @finalheader, "\t\treturn m_pByteCode[shaderID];\n"; +push @finalheader, "\t}\n"; +push @finalheader, "};\n"; +push @finalheader, "static $filename_base" . "_VertexShader_t $filename_base" . "_VertexShaderInstance;\n"; + +# Write the final header file with the compiled vertex shader programs. +$finalheadername = "$vshtmp\\" . $filename_base . ".inc"; +#print "writing $finalheadername\n"; +#open FINALHEADER, ">$finalheadername" || die; +#print FINALHEADER @finalheader; +#close FINALHEADER; + +&MakeDirHier( "shaders/vsh" ); + +my $vcsName = ""; +if( $g_x360 ) +{ + $vcsName = $filename_base . ".360.vcs"; +} +else +{ + $vcsName = $filename_base . ".vcs"; +} +open COMPILEDSHADER, ">shaders/vsh/$vcsName" || die; +binmode( COMPILEDSHADER ); + +# +# Write out the part of the header that we know. . we'll write the rest after writing the object code. +# + +# Pack arguments +my $sInt = "i"; +my $uInt = "I"; +if ( $g_x360 ) +{ + # Change arguments to "big endian long" + $sInt = "N"; + $uInt = "N"; +} + +my $undecoratedinput = join "", &ReadInputFileWithoutLineInfo( $filename ); +#print STDERR "undecoratedinput: $undecoratedinput\n"; +my $crc = crc32( $undecoratedinput ); +#print STDERR "crc for $filename: $crc\n"; + +# version +print COMPILEDSHADER pack $sInt, 4; +# totalCombos +print COMPILEDSHADER pack $sInt, $numCombos; +# dynamic combos +print COMPILEDSHADER pack $sInt, $numDynamicCombos; +# flags +print COMPILEDSHADER pack $uInt, $flags; +# centroid mask +print COMPILEDSHADER pack $uInt, 0; +# reference size +print COMPILEDSHADER pack $uInt, 0; +# crc32 of the source code +print COMPILEDSHADER pack $uInt, $crc; + +my $beginningOfDir = tell COMPILEDSHADER; + +# Write out a blank directionary. . we'll fill it in later. +for( $i = 0; $i < $numCombos; $i++ ) +{ + # offset from beginning of file. + print COMPILEDSHADER pack $sInt, 0; + # size + print COMPILEDSHADER pack $sInt, 0; +} + +my $startByteCode = tell COMPILEDSHADER; +my @byteCodeStart; +my @byteCodeSize; + +# Write out the shader object code. +for( $shaderCombo = 0; $shaderCombo < $numCombos; $shaderCombo++ ) +{ + my $filename = "shader$shaderCombo\.o"; + my $filesize = (stat $filename)[7]; + $byteCodeStart[$shaderCombo] = tell COMPILEDSHADER; + $byteCodeSize[$shaderCombo] = $filesize; + open SHADERBYTECODE, "<$filename" || die; + binmode SHADERBYTECODE; + my $bin; + my $numread = read SHADERBYTECODE, $bin, $filesize; +# print "filename: $filename numread: $numread filesize: $filesize\n"; + close SHADERBYTECODE; + unlink $filename; + + print COMPILEDSHADER $bin; +} + +# Seek back to the directory and write it out. +seek COMPILEDSHADER, $beginningOfDir, 0; +for( $i = 0; $i < $numCombos; $i++ ) +{ + # offset from beginning of file. + print COMPILEDSHADER pack $sInt, $byteCodeStart[$i]; + # size + print COMPILEDSHADER pack $sInt, $byteCodeSize[$i]; +} + +close COMPILEDSHADER; + +$total_time = SampleTime() - $total_start_time; + +if ( $ShowTimers ) +{ + print "\n\n"; + print sprintf( "Main loop time : %0.4f sec, (%0.2f%%)\n", $main_total_time, 100*$main_total_time / $total_time ); + print sprintf( "Inner1 time : %0.4f sec, (%0.2f%%)\n", $inner1_total_time, 100*$inner1_total_time / $total_time ); + print sprintf( "VSA time : %0.4f sec, (%0.2f%%)\n", $vsa_total_time, 100*$vsa_total_time / $total_time ); + print sprintf( "eval() time : %0.4f sec, (%0.2f%%)\n", $eval_total_time, 100*$eval_total_time / $total_time ); + print sprintf( "UsesRegister time: %0.4f sec, (%0.2f%%)\n", $usesr_total_time, 100*$usesr_total_time / $total_time ); + + foreach $key ( keys %g_TimingBlocks ) + { + print sprintf( "$key time: %0.4f sec, (%0.2f%%)\n", $g_TimingBlocks{$key}, 100*$g_TimingBlocks{$key} / $total_time ); + } + + print sprintf( "Total time : %0.4f sec\n", $total_time ); +} + |