@@ -125,12 +125,29 @@ bool ShaderRenderTester::validate(const mx::FilePath optionsFilePath)
125125 // Data search path
126126 mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath ();
127127
128+ const std::string MTLX_EXTENSION (" mtlx" );
128129 mx::ScopedTimer ioTimer (&profileTimes.ioTime );
129- mx::FilePathVec dirs ;
130+ mx::FilePathVec files ;
130131 for (const auto & root : options.renderTestPaths )
131132 {
132- mx::FilePathVec testRootDirs = searchPath.find (root).getSubDirectories ();
133- dirs.insert (std::end (dirs), std::begin (testRootDirs), std::end (testRootDirs));
133+ auto resolvedRoot = searchPath.find (root);
134+ if (!resolvedRoot.exists ())
135+ continue ;
136+ if (resolvedRoot.isDirectory ())
137+ {
138+ mx::FilePathVec testRootDirs = searchPath.find (root).getSubDirectories ();
139+ for (auto & dir : testRootDirs)
140+ {
141+ mx::FilePathVec dirFiles = dir.getFilesInDirectory (MTLX_EXTENSION);
142+ files.reserve (files.size () + dirFiles.size ());
143+ for (auto & file: dirFiles)
144+ files.push_back (dir / file);
145+ }
146+ }
147+ else
148+ {
149+ files.push_back (resolvedRoot);
150+ }
134151 }
135152 ioTimer.endTimer ();
136153
@@ -206,101 +223,89 @@ bool ShaderRenderTester::validate(const mx::FilePath optionsFilePath)
206223
207224 mx::StringSet usedImpls;
208225
209- const std::string MTLX_EXTENSION (" mtlx" );
210- for (const auto & dir : dirs)
226+ for (const mx::FilePath& filename : files)
211227 {
212228 ioTimer.startTimer ();
213- mx::FilePathVec files;
214- files = dir.getFilesInDirectory (MTLX_EXTENSION);
215- ioTimer.endTimer ();
229+ // Check if a file override set is used and ignore all files
230+ // not part of the override set
231+ if (testfileOverride.size () && testfileOverride.count (filename.getBaseName ()) == 0 )
232+ {
233+ ioTimer.endTimer ();
234+ continue ;
235+ }
216236
217- for ( const mx::FilePath& file : files )
237+ if (_skipFiles. count (filename. getBaseName ()) > 0 )
218238 {
219- ioTimer.startTimer ();
220- // Check if a file override set is used and ignore all files
221- // not part of the override set
222- if (testfileOverride.size () && testfileOverride.count (file) == 0 )
223- {
224- ioTimer.endTimer ();
225- continue ;
226- }
239+ ioTimer.endTimer ();
240+ continue ;
241+ }
227242
228- if (_skipFiles.count (file) > 0 )
229- {
230- ioTimer.endTimer ();
231- continue ;
232- }
243+ mx::DocumentPtr doc = mx::createDocument ();
244+ try
245+ {
246+ mx::readFromXmlFile (doc, filename, searchPath);
247+ }
248+ catch (mx::Exception& e)
249+ {
250+ docValidLog << " Failed to load in file: " << filename.asString () << " . Error: " << e.what () << std::endl;
251+ WARN (" Failed to load in file: " + filename.asString () + " See: " + docValidLogFilename + " for details." );
252+ }
233253
234- const mx::FilePath filename = mx::FilePath (dir) / mx::FilePath (file);
235- mx::DocumentPtr doc = mx::createDocument ();
236- try
237- {
238- mx::FileSearchPath readSearchPath (searchPath);
239- readSearchPath.append (dir);
240- mx::readFromXmlFile (doc, filename, readSearchPath);
241- }
242- catch (mx::Exception& e)
243- {
244- docValidLog << " Failed to load in file: " << filename.asString () << " . Error: " << e.what () << std::endl;
245- WARN (" Failed to load in file: " + filename.asString () + " See: " + docValidLogFilename + " for details." );
246- }
254+ // For each new file clear the implementation cache.
255+ // Since the new file might contain implementations with names
256+ // colliding with implementations in previous test cases.
257+ context.clearNodeImplementations ();
258+
259+ doc->setDataLibrary (dependLib);
247260
248- // For each new file clear the implementation cache.
249- // Since the new file might contain implementations with names
250- // colliding with implementations in previous test cases.
251- context.clearNodeImplementations ();
261+ // Register types from the document.
262+ _shaderGenerator->registerTypeDefs (doc);
252263
253- doc-> setDataLibrary (dependLib );
264+ ioTimer. endTimer ( );
254265
255- // Register types from the document.
256- _shaderGenerator-> registerTypeDefs (doc) ;
266+ validateTimer. startTimer ();
267+ log << " MTLX Filename: " << filename. asString () << std::endl ;
257268
258- ioTimer.endTimer ();
269+ // Validate the test document
270+ std::string validationErrors;
271+ bool validDoc = doc->validate (&validationErrors);
272+ if (!validDoc)
273+ {
274+ docValidLog << filename.asString () << std::endl;
275+ docValidLog << validationErrors << std::endl;
276+ }
277+ validateTimer.endTimer ();
278+ CHECK (validDoc);
259279
260- validateTimer. startTimer ( );
261- log << " MTLX Filename: " << filename. asString () << std::endl ;
280+ mx::FileSearchPath imageSearchPath (filename. getParentPath () );
281+ imageSearchPath. append (searchPath) ;
262282
263- // Validate the test document
264- std::string validationErrors;
265- bool validDoc = doc->validate (&validationErrors);
266- if (!validDoc)
267- {
268- docValidLog << filename.asString () << std::endl;
269- docValidLog << validationErrors << std::endl;
270- }
271- validateTimer.endTimer ();
272- CHECK (validDoc);
273-
274- mx::FileSearchPath imageSearchPath (dir);
275- imageSearchPath.append (searchPath);
276-
277- // Resolve file names if specified
278- if (_resolveImageFilenames)
279- {
280- mx::flattenFilenames (doc, imageSearchPath, _customFilenameResolver);
281- }
283+ // Resolve file names if specified
284+ if (_resolveImageFilenames)
285+ {
286+ mx::flattenFilenames (doc, imageSearchPath, _customFilenameResolver);
287+ }
282288
283- mx::FilePath outputPath = mx::FilePath (dir) / file ;
284- outputPath.removeExtension ();
289+ mx::FilePath outputPath = filename ;
290+ outputPath.removeExtension ();
285291
286- renderableSearchTimer.startTimer ();
287- std::vector<mx::TypedElementPtr> elements;
288- try
289- {
290- elements = mx::findRenderableElements (doc);
291- }
292- catch (mx::Exception& e)
293- {
294- docValidLog << e.what () << std::endl;
295- WARN (" Shader generation error in " + filename.asString () + " : " + e.what ());
296- }
297- renderableSearchTimer.endTimer ();
292+ renderableSearchTimer.startTimer ();
293+ std::vector<mx::TypedElementPtr> elements;
294+ try
295+ {
296+ elements = mx::findRenderableElements (doc);
297+ }
298+ catch (mx::Exception& e)
299+ {
300+ docValidLog << e.what () << std::endl;
301+ WARN (" Shader generation error in " + filename.asString () + " : " + e.what ());
302+ }
303+ renderableSearchTimer.endTimer ();
298304
299- for (const auto & element : elements)
300- {
301- mx::string elementName = mx::createValidName (mx::replaceSubstrings (element->getNamePath (), pathMap));
302- runRenderer (elementName, element, context, doc, log, options, profileTimes, imageSearchPath, outputPath, nullptr );
303- }
305+ for (const auto & element : elements)
306+ {
307+ mx::string elementName = mx::createValidName (mx::replaceSubstrings (element->getNamePath (), pathMap));
308+ runRenderer (elementName, element, context, doc, log, options, profileTimes, imageSearchPath, outputPath, nullptr );
304309 }
305310 }
306311
0 commit comments