/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // the programs a graphics driver crashed on while it compiled them. a fault inside the driver (an access violation of its // compiler, not an error it reports) takes the whole simulator down: the NVIDIA driver 610.88 did that on water_snowlayer.comp // as the cab loaded, at every start. so a program a renderer can go without (the water and the snow on the windscreens) is made // under this guard: // - where the fault can be caught (built with msvc), it is, and the session goes on without the program; // - the program is written down in the cache of the renderer before the driver gets it and crossed out after, so a session the // driver took down anyway (a fault not caught, on a thread of the driver) leaves it behind. the next session takes it as // suspect, and as one the driver crashed on when a session ends while it is made a second time: a session ended from outside // while the driver compiled (some programs take seconds) doesn't leave the program out. made well, it is no longer suspect; // - a program the driver crashed on isn't made again with that driver. the records name the driver and the program with the hash // of its code, so a new version of the driver, or a changed program, is tried again. // // no graphics api here (the unit tests build it on its own) #pragma once #include #include #include #include #include namespace gfx { class DriverCrashGuard { public: enum class Outcome { made, // the program was made (whether the driver could make it or not is the caller's to tell) skipped, // the driver crashed on the program before: nothing was done crashed // the driver faulted while it made the program, caught }; // Directory: the cache of the renderer, with a separator at the end (made when it isn't there); Driver: the device and the // version of its driver. a program the session before left written down is taken as suspect, or as one the driver crashed on // when it was suspect already void Init(std::string_view directory, std::string_view driver); // Make(Context) run for the program Key (its name and the hash of its code) under the guard. a c++ exception of Make goes on // through, the program crossed out. one program is made under the guard at a time Outcome Run(std::string_view key, void (*make)(void *), void *context); // whether the driver crashed on the program Key before bool Crashed(std::string_view key) const; // whether a session ended once while the driver made the program Key bool Suspect(std::string_view key) const; private: void writeAttempt(std::string const &key) const; void removeAttempt() const; void recordCrash(std::string const &key); void clearSuspect(std::string const &key); mutable std::mutex mutex; // driver_crashes.txt, driver_crash_suspects.txt and driver_crash_attempt.txt of the cache, lines of the driver and the program // parted by a tab; empty before Init(), when nothing is written down (the programs are still guarded) std::string recordsPath; std::string suspectsPath; std::string attemptPath; std::string driver; std::set> crashedKeys; std::set> suspectKeys; }; // Function(Context); false when it raised a fault (a structured exception of windows other than one of c++, and other than the // overflow of the stack, which leaves the thread unable to go on) which was caught. a c++ exception goes on through. where faults // can't be caught (not built with msvc) the call is made as it is and true returned bool CallCatchingFaults(void (*function)(void *), void *context); } // namespace gfx