Skip to content

Commit

Permalink
Extended gpu-crash logging for Metal
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Jul 2, 2024
1 parent a3d6c93 commit e857c17
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion game/graphics/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ void Renderer::drawShadowMap(Encoder<CommandBuffer>& cmd, uint8_t fId, WorldView
return;

for(uint8_t i=0; i<Resources::ShadowLayers; ++i) {
cmd.setFramebuffer({}, {shadowMap[i], 0.f, Tempest::Preserve});
cmd.setDebugMarker(string_frm("ShadowMap #",i));
cmd.setFramebuffer({}, {shadowMap[i], 0.f, Tempest::Preserve});
if(view.mainLight().dir().y > Camera::minShadowY)
view.drawShadow(cmd,fId,i);
}
Expand Down
20 changes: 17 additions & 3 deletions game/utils/crashlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ static void signalHandler(int sig) {
sname = buf;
}

CrashLog::dumpStack(sname);
CrashLog::dumpStack(sname, nullptr);
std::raise(sig);
}

[[noreturn]]
static void terminateHandler() {
char msg[128] = "std::terminate";
std::exception_ptr p = std::current_exception();
std::string extGpuLog;
if(p) {
try {
std::rethrow_exception(p);
Expand All @@ -66,6 +67,7 @@ static void terminateHandler() {
}
catch (Tempest::DeviceLostException& e) {
std::snprintf(msg,sizeof(msg),"DeviceLostException(%s)",e.what());
extGpuLog = e.log();
}
catch (std::system_error& e) {
std::snprintf(msg,sizeof(msg),"std::system_error(%s)",e.what());
Expand All @@ -82,7 +84,7 @@ static void terminateHandler() {
catch (...) {
}
}
CrashLog::dumpStack(msg);
CrashLog::dumpStack(msg, extGpuLog.c_str());
std::signal(SIGABRT, SIG_DFL); // avoid recursion
std::abort();
}
Expand All @@ -105,7 +107,7 @@ void CrashLog::setGpu(std::string_view name) {
std::strncpy(gpuName,name.data(),sizeof(gpuName)-1);
}

void CrashLog::dumpStack(const char *sig) {
void CrashLog::dumpStack(const char *sig, const char *extGpuLog) {
#ifdef __WINDOWS__
dbg::symdb db;
dbg::call_stack<64> traceback;
Expand All @@ -116,6 +118,7 @@ void CrashLog::dumpStack(const char *sig) {
std::cout.setf(std::ios::unitbuf);
std::cout << std::endl << "---crashlog(" << sig << ")---" << std::endl;
writeSysInfo(std::cout);
tracebackGpu(std::cout, extGpuLog);
#ifdef __WINDOWS__
traceback.collect(0);
traceback.log(db, std::cout);
Expand All @@ -128,6 +131,7 @@ void CrashLog::dumpStack(const char *sig) {
fout.setf(std::ios::unitbuf);
fout << "---crashlog(" << sig << ")---" << std::endl;
writeSysInfo(fout);
tracebackGpu(std::cout, extGpuLog);
#ifdef __WINDOWS__
traceback.log(db, fout);
#elif defined(__LINUX__) || defined(__APPLE__)
Expand Down Expand Up @@ -170,6 +174,16 @@ void CrashLog::tracebackLinux(std::ostream &out) {
#endif
}

void CrashLog::tracebackGpu(std::ostream& out, const char* extGpuLog) {
if(extGpuLog==nullptr || extGpuLog[0]=='\0')
return;
out << std::endl;
out << "---gpulog begin---" << std::endl;
out << extGpuLog << std::endl;
out << "---gpulog end ---" << std::endl;
out << std::endl;
}

void CrashLog::writeSysInfo(std::ostream &fout) {
fout << "GPU: " << gpuName << std::endl;
}
3 changes: 2 additions & 1 deletion game/utils/crashlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ class CrashLog final {
static void setup();
static void setGpu(std::string_view name);

static void dumpStack(const char* sig);
static void dumpStack(const char* sig, const char* extGpuLog);

private:
static void tracebackLinux(std::ostream &out);
static void tracebackGpu(std::ostream &out, const char* extGpuLog);
static void writeSysInfo(std::ostream& fout);
};

0 comments on commit e857c17

Please sign in to comment.