17
17
package com .graphicsfuzz .generator ;
18
18
19
19
import com .graphicsfuzz .common .glslversion .ShadingLanguageVersion ;
20
+ import com .graphicsfuzz .common .transformreduce .GlslShaderJob ;
21
+ import com .graphicsfuzz .common .transformreduce .ShaderJob ;
22
+ import com .graphicsfuzz .common .util .Helper ;
20
23
import com .graphicsfuzz .common .util .ParseTimeoutException ;
24
+ import com .graphicsfuzz .common .util .RandomWrapper ;
25
+ import com .graphicsfuzz .common .util .UniformsInfo ;
21
26
import com .graphicsfuzz .generator .tool .Generate ;
22
27
import com .graphicsfuzz .shadersets .ShaderDispatchException ;
23
28
import java .io .File ;
24
29
import java .io .IOException ;
30
+ import java .nio .charset .StandardCharsets ;
25
31
import java .util .ArrayList ;
32
+ import java .util .Arrays ;
33
+ import java .util .HashSet ;
26
34
import java .util .List ;
35
+ import java .util .Optional ;
36
+ import java .util .Set ;
27
37
import java .util .concurrent .BlockingQueue ;
28
38
import java .util .concurrent .LinkedBlockingQueue ;
39
+ import java .util .stream .Collectors ;
29
40
import net .sourceforge .argparse4j .ArgumentParsers ;
41
+ import net .sourceforge .argparse4j .impl .Arguments ;
30
42
import net .sourceforge .argparse4j .inf .ArgumentParser ;
31
43
import net .sourceforge .argparse4j .inf .ArgumentParserException ;
32
44
import net .sourceforge .argparse4j .inf .Namespace ;
33
45
import org .apache .commons .io .FileUtils ;
34
46
import org .apache .commons .io .FilenameUtils ;
47
+ import org .apache .commons .lang3 .tuple .Pair ;
35
48
36
49
public class GenerateAndRunShaders {
37
50
@@ -70,6 +83,15 @@ private static Namespace parse(String[] args) {
70
83
// Optional arguments
71
84
Generate .addGeneratorCommonArguments (parser );
72
85
86
+ parser .addArgument ("--ignore_crash_strings" )
87
+ .help ("File containing crash strings to ignore, one per line." )
88
+ .type (File .class );
89
+
90
+ parser .addArgument ("--only_variants" )
91
+ .help ("Only run variant shaders (so sacrifice finding wrong images in favour of crashes." )
92
+ .type (Boolean .class )
93
+ .action (Arguments .storeTrue ());
94
+
73
95
try {
74
96
return parser .parseArgs (args );
75
97
} catch (ArgumentParserException exception ) {
@@ -81,7 +103,7 @@ private static Namespace parse(String[] args) {
81
103
}
82
104
83
105
public static void main (String [] args )
84
- throws IOException , ParseTimeoutException , InterruptedException , ShaderDispatchException {
106
+ throws IOException , InterruptedException {
85
107
final Namespace ns = parse (args );
86
108
final File referencesDir = ns .get ("references" );
87
109
if (!referencesDir .exists ()) {
@@ -98,57 +120,52 @@ public static void main(String[] args)
98
120
final ShadingLanguageVersion shadingLanguageVersion = ns .get ("webgl" )
99
121
? ShadingLanguageVersion .webGlFromVersionString (ns .get ("glsl_version" ))
100
122
: ShadingLanguageVersion .fromVersionString (ns .get ("glsl_version" ));
101
- final boolean replaceFloatLiterals = ns .getBoolean ("replace_float_literals" );
102
123
103
- final List <File > referenceShaders = populateReferenceShaders (referencesDir );
124
+ final BlockingQueue <Pair <ShaderJob , ShaderJob >> queue =
125
+ new LinkedBlockingQueue <>();
104
126
105
- final BlockingQueue <ReferenceVariantPair > queue = new LinkedBlockingQueue <>();
127
+ final File crashStringsToIgnoreFile = ns .get ("ignore_crash_strings" );
128
+ final Set <String > crashStringsToIgnore = new HashSet <>();
129
+ if (crashStringsToIgnoreFile != null ) {
130
+ crashStringsToIgnore .addAll (FileUtils .readLines (crashStringsToIgnoreFile ,
131
+ StandardCharsets .UTF_8 ));
132
+ }
133
+
134
+ final List <String > shaderJobPrefixes =
135
+ Arrays .stream (referencesDir .listFiles ((dir , name ) -> name .endsWith (".json" )))
136
+ .map (item -> FilenameUtils .removeExtension (item .getName ()))
137
+ .collect (Collectors .toList ());
138
+ if (shaderJobPrefixes .isEmpty ()) {
139
+ throw new IllegalArgumentException ("No shader jobs found." );
140
+ }
106
141
107
- new Thread (new ShaderConsumer (
142
+ final Thread consumer = new Thread (new ShaderConsumer (
108
143
LIMIT ,
109
144
queue ,
110
145
outputDir ,
111
146
ns .get ("server" ),
112
147
ns .get ("token" ),
113
- referenceShaders ,
114
- shadingLanguageVersion ,
115
- replaceFloatLiterals
116
- )).start ();
148
+ shadingLanguageVersion ,
149
+ crashStringsToIgnore ,
150
+ ns
151
+ ));
152
+ consumer .start ();
117
153
118
- new Thread (new ShaderProducer (
154
+ final Thread producer = new Thread (new ShaderProducer (
119
155
LIMIT ,
156
+ shaderJobPrefixes ,
157
+ new RandomWrapper (ns .get ("seed" )),
120
158
queue ,
121
- outputDir ,
122
- referenceShaders ,
123
- shadingLanguageVersion ,
124
- replaceFloatLiterals ,
159
+ referencesDir ,
160
+ shadingLanguageVersion ,
125
161
donors ,
126
162
ns
127
- )).start ();
163
+ ));
164
+ producer .start ();
128
165
129
- }
166
+ consumer .join ();
167
+ producer .join ();
130
168
131
- private static List <File > populateReferenceShaders (File shaders )
132
- throws IOException , ParseTimeoutException {
133
- final List <File > files = new ArrayList <>();
134
- for (File shader : shaders .listFiles ((dir , name ) -> name .endsWith (".frag" ))) {
135
- final File uniforms = new File (FilenameUtils
136
- .removeExtension (shader .getAbsolutePath ()) + ".json" );
137
- if (!uniforms
138
- .exists ()) {
139
- throw new IllegalArgumentException ("Shader " + shader .getName ()
140
- + " has no associated JSON file." );
141
- }
142
- final String license = FilenameUtils .removeExtension (shader .getAbsolutePath ()) + ".license" ;
143
- if (!new File (license )
144
- .exists ()) {
145
- throw new IllegalArgumentException ("Shader " + shader .getName ()
146
- + " has no associated license file." );
147
- }
148
- files .add (shader );
149
- }
150
- return files ;
151
169
}
152
170
153
-
154
171
}
0 commit comments