Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

325 lines
6.7 KiB

  1. use String::CRC32;
  2. BEGIN {use File::Basename; push @INC, dirname($0); }
  3. require "valve_perl_helpers.pl";
  4. $dynamic_compile = defined $ENV{"dynamic_shaders"} && $ENV{"dynamic_shaders"} != 0;
  5. $depnum = 0;
  6. $baseSourceDir = ".";
  7. my %dep;
  8. sub GetAsmShaderDependencies_R
  9. {
  10. local( $shadername ) = shift;
  11. local( *SHADER );
  12. open SHADER, "<$shadername";
  13. while( <SHADER> )
  14. {
  15. if( m/^\s*\#\s*include\s+\"(.*)\"/ )
  16. {
  17. # make sure it isn't in there already.
  18. if( !defined( $dep{$1} ) )
  19. {
  20. $dep{$1} = 1;
  21. GetAsmShaderDependencies_R( $1 );
  22. }
  23. }
  24. }
  25. close SHADER;
  26. }
  27. sub GetAsmShaderDependencies
  28. {
  29. local( $shadername ) = shift;
  30. undef %dep;
  31. GetAsmShaderDependencies_R( $shadername );
  32. # local( $i );
  33. # foreach $i ( keys( %dep ) )
  34. # {
  35. # print "$shadername depends on $i\n";
  36. # }
  37. return keys( %dep );
  38. }
  39. sub GetShaderType
  40. {
  41. my $shadername = shift;
  42. my $shadertype;
  43. if( $shadername =~ m/\.vsh/i )
  44. {
  45. $shadertype = "vsh";
  46. }
  47. elsif( $shadername =~ m/\.psh/i )
  48. {
  49. $shadertype = "psh";
  50. }
  51. elsif( $shadername =~ m/\.fxc/i )
  52. {
  53. $shadertype = "fxc";
  54. }
  55. else
  56. {
  57. die;
  58. }
  59. return $shadertype;
  60. }
  61. sub GetShaderSrc
  62. {
  63. my $shadername = shift;
  64. if ( $shadername =~ m/^(.*)-----/i )
  65. {
  66. return $1;
  67. }
  68. else
  69. {
  70. return $shadername;
  71. }
  72. }
  73. sub GetShaderBase
  74. {
  75. my $shadername = shift;
  76. if ( $shadername =~ m/-----(.*)$/i )
  77. {
  78. return $1;
  79. }
  80. else
  81. {
  82. my $shadertype = &GetShaderType( $shadername );
  83. $shadername =~ s/\.$shadertype//i;
  84. return $shadername;
  85. }
  86. }
  87. sub DoAsmShader
  88. {
  89. my $argstring = shift;
  90. my $shadername = &GetShaderSrc( $argstring );
  91. my $shaderbase = &GetShaderBase( $argstring );
  92. my $shadertype = &GetShaderType( $argstring );
  93. my $incfile = "";
  94. if( $shadertype eq "fxc" || $shadertype eq "vsh" )
  95. {
  96. $incfile = $shadertype . "tmp9" . $g_tmpfolder . "\\$shaderbase.inc ";
  97. }
  98. my $vcsfile = $shaderbase . $g_vcsext;
  99. my $bWillCompileVcs = 1;
  100. if( ( $shadertype eq "fxc") && $dynamic_compile )
  101. {
  102. $bWillCompileVcs = 0;
  103. }
  104. if( $shadercrcpass{$argstring} )
  105. {
  106. $bWillCompileVcs = 0;
  107. }
  108. if( $bWillCompileVcs )
  109. {
  110. &output_makefile_line( $incfile . "shaders\\$shadertype\\$vcsfile: $shadername ..\\..\\devtools\\bin\\updateshaders.pl ..\\..\\devtools\\bin\\" . $shadertype . "_prep.pl" . " @dep\n") ;
  111. }
  112. else
  113. {
  114. # psh files don't need a rule at this point since they don't have inc files and we aren't compiling a vcs.
  115. if( $shadertype eq "fxc" || $shadertype eq "vsh" )
  116. {
  117. &output_makefile_line( $incfile . ": $shadername ..\\..\\devtools\\bin\\updateshaders.pl ..\\..\\devtools\\bin\\" . $shadertype . "_prep.pl" . " @dep\n") ;
  118. }
  119. }
  120. my $x360switch = "";
  121. my $ps3switch = "";
  122. my $moreswitches = "";
  123. if( !$bWillCompileVcs && $shadertype eq "fxc" )
  124. {
  125. $moreswitches .= "-novcs ";
  126. }
  127. if( $g_x360 )
  128. {
  129. $x360switch = "-x360";
  130. if( $bWillCompileVcs && ( $shaderbase =~ m/_ps20$/i ) )
  131. {
  132. $moreswitches .= "-novcs ";
  133. $bWillCompileVcs = 0;
  134. }
  135. }
  136. if( $g_ps3 )
  137. {
  138. $ps3switch = "-ps3";
  139. if( $bWillCompileVcs && ( $shaderbase =~ m/_ps20$/i ) )
  140. {
  141. $moreswitches .= "-novcs ";
  142. $bWillCompileVcs = 0;
  143. }
  144. }
  145. # if we are psh and we are compiling the vcs, we don't need this rule.
  146. if( !( $shadertype eq "psh" && !$bWillCompileVcs ) )
  147. {
  148. &output_makefile_line( "\tperl $g_SourceDir\\devtools\\bin\\" . $shadertype . "_prep.pl $moreswitches $x360switch $ps3switch -source \"$g_SourceDir\" $argstring\n") ;
  149. }
  150. if( $bWillCompileVcs )
  151. {
  152. &output_makefile_line( "\techo $shadername>> filestocopy.txt\n") ;
  153. my $dep;
  154. foreach $dep( @dep )
  155. {
  156. &output_makefile_line( "\techo $dep>> filestocopy.txt\n") ;
  157. }
  158. }
  159. &output_makefile_line( "\n") ;
  160. }
  161. if( scalar( @ARGV ) == 0 )
  162. {
  163. die "Usage updateshaders.pl shaderprojectbasename\n\tie: updateshaders.pl stdshaders_dx6\n";
  164. }
  165. $g_x360 = 0;
  166. $g_ps3 = 0;
  167. $g_tmpfolder = "_tmp";
  168. $g_vcsext = ".vcs";
  169. while( 1 )
  170. {
  171. $inputbase = shift;
  172. if( $inputbase =~ m/-source/ )
  173. {
  174. $g_SourceDir = shift;
  175. }
  176. elsif( $inputbase =~ m/-x360/ )
  177. {
  178. $g_x360 = 1;
  179. $g_tmpfolder = "_360_tmp";
  180. $g_vcsext = ".360.vcs";
  181. }
  182. elsif( $inputbase =~ m/-ps3/ )
  183. {
  184. $g_ps3 = 1;
  185. $g_tmpfolder = "_ps3_tmp";
  186. $g_vcsext = ".ps3.vcs";
  187. }
  188. elsif( $inputbase =~ m/-execute/ )
  189. {
  190. $g_execute = 1;
  191. }
  192. elsif( $inputbase =~ m/-nv3x/ )
  193. {
  194. $nv3x = 1;
  195. }
  196. else
  197. {
  198. last;
  199. }
  200. }
  201. my @srcfiles = &LoadShaderListFile( $inputbase );
  202. open MAKEFILE, ">makefile\.$inputbase";
  203. open COPYFILE, ">makefile\.$inputbase\.copy";
  204. open INCLIST, ">inclist.txt";
  205. open VCSLIST, ">vcslist.txt";
  206. # make a default dependency that depends on all of the shaders.
  207. &output_makefile_line( "default: ") ;
  208. foreach $shader ( @srcfiles )
  209. {
  210. my $shadertype = &GetShaderType( $shader );
  211. my $shaderbase = &GetShaderBase( $shader );
  212. my $shadersrc = &GetShaderSrc( $shader );
  213. if( $shadertype eq "fxc" || $shadertype eq "vsh" )
  214. {
  215. # We only generate inc files for fxc and vsh files.
  216. my $incFileName = "$shadertype" . "tmp9" . $g_tmpfolder . "\\" . $shaderbase . "\.inc";
  217. &output_makefile_line( " $incFileName" );
  218. &output_inclist_line( "$incFileName\n" );
  219. }
  220. my $vcsfile = $shaderbase . $g_vcsext;
  221. my $compilevcs = 1;
  222. if( $shadertype eq "fxc" && $dynamic_compile )
  223. {
  224. $compilevcs = 0;
  225. }
  226. # Do not compile ps2.0 shaders on PS3/X360
  227. if( ( $g_x360 || $g_ps3 ) && ( $shaderbase =~ m/_ps20$/i ) )
  228. {
  229. $compilevcs = 0;
  230. }
  231. if( $compilevcs )
  232. {
  233. my $vcsFileName = "..\\..\\..\\game\\platform\\shaders\\$shadertype\\$shaderbase" . $g_vcsext;
  234. # 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.
  235. &output_vcslist_line( "$vcsFileName\n" );
  236. $shadercrcpass{$shader} = &CheckCRCAgainstTarget( $shadersrc, $vcsFileName, 0 );
  237. if( $shadercrcpass{$shader} )
  238. {
  239. $compilevcs = 0;
  240. }
  241. }
  242. if( $compilevcs )
  243. {
  244. &output_makefile_line( " shaders\\$shadertype\\$vcsfile" );
  245. # emit a list of vcs files to copy to the target since we want to build them.
  246. &output_copyfile_line( GetShaderSrc($shader) . "-----" . GetShaderBase($shader) . "\n" );
  247. }
  248. }
  249. &output_makefile_line( "\n\n") ;
  250. # Insert all of our vertex shaders and depencencies
  251. $lastshader = "";
  252. foreach $shader ( @srcfiles )
  253. {
  254. my $currentshader = &GetShaderSrc( $shader );
  255. if ( $lastshader ne $currentshader )
  256. {
  257. $lastshader = $currentshader;
  258. @dep = &GetAsmShaderDependencies( $lastshader );
  259. }
  260. &DoAsmShader( $shader );
  261. }
  262. close VCSLIST;
  263. close INCLIST;
  264. close COPYFILE;
  265. close MAKEFILE;
  266. # nuke the copyfile if it is zero length
  267. if( ( stat "makefile\.$inputbase\.copy" )[7] == 0 )
  268. {
  269. unlink "makefile\.$inputbase\.copy";
  270. }
  271. sub output_makefile_line
  272. {
  273. local ($_)=@_;
  274. print MAKEFILE $_;
  275. }
  276. sub output_copyfile_line
  277. {
  278. local ($_)=@_;
  279. print COPYFILE $_;
  280. }
  281. sub output_vcslist_line
  282. {
  283. local ($_)=@_;
  284. print VCSLIST $_;
  285. }
  286. sub output_inclist_line
  287. {
  288. local ($_)=@_;
  289. print INCLIST $_;
  290. }