1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 20:16:10 +08:00

SDK sync.

This commit is contained in:
Scott Ehlert
2012-07-06 20:35:59 -05:00
parent 4fb33274fb
commit fdd0bbf277
413 changed files with 67257 additions and 4 deletions

View File

@ -0,0 +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";
unlink "__tmpshaderlist.txt";

View File

@ -0,0 +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\\platform\\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 );
}

View File

@ -0,0 +1,81 @@
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];
if( $dstexists && !$srcexists )
{
printf STDERR "$src doesn't exist, deleting $dst\n";
unlink $dst;
}
# 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;

161
devtools/bin/copyshaders.pl Normal file
View File

@ -0,0 +1,161 @@
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";
}
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\\platform\\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;

BIN
devtools/bin/d3dx10_33.dll Normal file

Binary file not shown.

BIN
devtools/bin/d3dx9_33.dll Normal file

Binary file not shown.

View File

@ -0,0 +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";
}

1004
devtools/bin/fxc_prep.pl Normal file

File diff suppressed because it is too large Load Diff

333
devtools/bin/psh_prep.pl Normal file
View File

@ -0,0 +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;

View File

@ -0,0 +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";

View File

@ -0,0 +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;

View File

@ -0,0 +1,6 @@
foreach $_ (sort <> )
{
next if( defined( $prevline ) && $_ eq $prevline );
$prevline = $_;
print;
}

View File

@ -0,0 +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 ..\\..\\devtools\\bin\\updateshaders.pl ..\\..\\devtools\\bin\\" . $shadertype . "_prep.pl" . " @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 ..\\..\\devtools\\bin\\updateshaders.pl ..\\..\\devtools\\bin\\" . $shadertype . "_prep.pl" . " @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\\platform\\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 $_;
}

View File

@ -0,0 +1,539 @@
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;
# Make the target vcs writable if it exists
MakeFileWritable( $filename );
# Write the file.
local( *FP );
open FP, ">$filename";
print FP $filecontents;
close FP;
}
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/platform/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/_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;

1106
devtools/bin/vsh_prep.pl Normal file

File diff suppressed because it is too large Load Diff