From e76a4399e50aefdae8031561bc5211a76d4a260e Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Sat, 19 Oct 2024 15:56:43 -0400 Subject: [PATCH] game: Update game's GPU test to output the GPU vendor info (#3717) This is so I can get rid of wgpu from the launcher, where it's only purpose is to figure out the GPU name for the support package. The problem with it is that on some environments, it errors, but the function cannot have it's errors gracefully handled (it panics and crashes instead). So I'm tired of it, do it ourselves. ![image](https://github.com/user-attachments/assets/fa8ae365-b3f7-4794-81ed-fde0c2ffc651) --- .gitignore | 1 + .vs/launch.vs.json | 13 +++++++++++++ Taskfile.yml | 7 +++++++ game/graphics/gfx_test.cpp | 27 +++++++++++++++++++++------ game/graphics/gfx_test.h | 2 ++ 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 3dc67daa45..3f3bed8ad1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # logs /log prof.json +/gpu-test.json # for CMake /Testing diff --git a/.vs/launch.vs.json b/.vs/launch.vs.json index a7a463646c..801a04453d 100644 --- a/.vs/launch.vs.json +++ b/.vs/launch.vs.json @@ -138,6 +138,19 @@ "-debug" ] }, + { + "type": "default", + "project": "CMakeLists.txt", + "projectTarget": "gk.exe (bin\\gk.exe)", + "name": "Game - GPU Test", + "args": [ + "-v", + "--gpu-test", + "opengl", + "--gpu-test-out-path", + "./gpu-test.json" + ] + }, { "type": "default", "project": "CMakeLists.txt", diff --git a/Taskfile.yml b/Taskfile.yml index f691c677de..0dbea08e39 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -164,6 +164,13 @@ tasks: lint: cmds: - python ./scripts/ci/lint-trailing-whitespace.py + run-gpu-test: + desc: "Runs the game's built in GPU test" + preconditions: + - sh: test -f {{.GK_BIN_RELEASE_DIR}}/gk{{.EXE_FILE_EXTENSION}} + msg: "Couldn't locate runtime executable in '{{.GK_BIN_RELEASE_DIR}}/gk'" + cmds: + - "{{.GK_BIN_RELEASE_DIR}}/gk -v --gpu-test opengl --gpu-test-out-path ./gpu-test.json" # TESTS offline-tests: # ran by jenkins cmds: diff --git a/game/graphics/gfx_test.cpp b/game/graphics/gfx_test.cpp index a07809ae1e..de5ec0dd5f 100644 --- a/game/graphics/gfx_test.cpp +++ b/game/graphics/gfx_test.cpp @@ -2,13 +2,15 @@ #include "game/system/hid/sdl_util.h" +#include "third-party/glad/include/glad/glad.h" + namespace tests { void to_json(json& j, const GPUTestOutput& obj) { - j = json{ - {"success", obj.success}, - {"error", obj.error}, - {"errorCause", obj.errorCause}, - }; + json_serialize(success); + json_serialize(error); + json_serialize(errorCause); + json_serialize_optional(gpuRendererString); + json_serialize_optional(gpuVendorString); } GPUTestOutput run_gpu_test(const std::string& test_type) { @@ -40,7 +42,20 @@ GPUTestOutput run_gpu_test(const std::string& test_type) { output = {false, "Required OpenGL Version is not supported", sdl_util::log_and_return_error("SDL initialization failed")}; } else { - output = {true, "", ""}; + gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress); + if (!gladLoadGL()) { + output = {false, "Unable to init GLAD", ""}; + } else { + output = {true, "", ""}; + const auto rendererString = glGetString(GL_RENDERER); + if (rendererString) { + output.gpuRendererString = (const char*)rendererString; + } + const auto vendorString = glGetString(GL_VENDOR); + if (vendorString) { + output.gpuVendorString = (const char*)vendorString; + } + } SDL_GL_DeleteContext(glContext); } SDL_DestroyWindow(window); diff --git a/game/graphics/gfx_test.h b/game/graphics/gfx_test.h index 6fbc6bc0d0..f2693105da 100644 --- a/game/graphics/gfx_test.h +++ b/game/graphics/gfx_test.h @@ -9,6 +9,8 @@ struct GPUTestOutput { bool success; std::string error; std::string errorCause; + std::optional gpuRendererString; + std::optional gpuVendorString; }; void to_json(json& j, const GPUTestOutput& obj);