Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various gfx_api and debugging tweaks #3412

Merged
merged 13 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions .github/workflows/CI_flatpak.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
WZ_FLATPAK_BUILD_DIR: flatpak_app
WZ_FLATPAK_TARGET_ARCH: ${{ matrix.flatpak-arch }}
WZ_FLATPAK_BUILD_ARCH: x86_64
WZ_FREEDESKTOP_RUNTIME_VERSION: 23.08 # should match runtime-version in .ci/flatpak/net.wz2100.wz2100.yaml.in
container:
image: fedora:latest
options: --privileged
Expand Down Expand Up @@ -200,15 +201,15 @@ jobs:
- name: Install Flatpak manifest deps
run: |
# Build SDK
flatpak --system install -y --noninteractive flathub org.freedesktop.Sdk//23.08
flatpak --system install -y --noninteractive flathub org.freedesktop.Sdk//${WZ_FREEDESKTOP_RUNTIME_VERSION}
# Target runtime
flatpak --system install -y --noninteractive flathub org.freedesktop.Platform/${WZ_FLATPAK_TARGET_ARCH}/23.08
flatpak --system install -y --noninteractive flathub org.freedesktop.Platform/${WZ_FLATPAK_TARGET_ARCH}/${WZ_FREEDESKTOP_RUNTIME_VERSION}

if [[ "$WZ_FLATPAK_TARGET_ARCH" != "$WZ_FLATPAK_BUILD_ARCH" ]]; then
# Cross compiler
flatpak --system install -y --noninteractive flathub org.freedesktop.Sdk.Extension.toolchain-${WZ_FLATPAK_TARGET_ARCH}//23.08
flatpak --system install -y --noninteractive flathub org.freedesktop.Sdk.Extension.toolchain-${WZ_FLATPAK_TARGET_ARCH}//${WZ_FREEDESKTOP_RUNTIME_VERSION}
# SDK For target runtime
flatpak --system install -y --noninteractive flathub org.freedesktop.Sdk.Compat.${WZ_FLATPAK_TARGET_ARCH}//23.08
flatpak --system install -y --noninteractive flathub org.freedesktop.Sdk.Compat.${WZ_FLATPAK_TARGET_ARCH}//${WZ_FREEDESKTOP_RUNTIME_VERSION}
fi
- name: Build Flatpak
id: build
Expand Down Expand Up @@ -239,9 +240,32 @@ jobs:
with:
name: 'debugsymbols_linux_flatpak_${{ matrix.arch }}'
path: |
flatpak_app/files/bin
flatpak_app/files/lib/*.so.*
flatpak_app/files/lib/debug/bin
flatpak_app/files/lib/debug/lib
if-no-files-found: 'error'
- name: Collect additional debug dependency info
shell: bash
run: |
mkdir output_debug_dependency_snapshot
set +e
# Note: These libraries will be from the runtime that is installed at the time of the build
ldd flatpak_app/files/bin/warzone2100 | grep -E -v 'linux-vdso|ld-linux-' | awk 'NF == 4 { system("echo " $1) }'
ret="$?"
if [ $ret -eq 0 ]; then
ldd flatpak_app/files/bin/warzone2100 | grep -E -v 'linux-vdso|ld-linux-' | awk 'NF == 4 { system("cp /var/lib/flatpak/runtime/org.freedesktop.Platform/${WZ_FLATPAK_TARGET_ARCH}/${WZ_FREEDESKTOP_RUNTIME_VERSION}/active/files/lib/${WZ_FLATPAK_TARGET_ARCH}-linux-gnu/" $1 " output_debug_dependency_snapshot") }'
else
# ldd fails for non-native architecture, so use objdump for cross-compiled builds
objdump -p flatpak_app/files/bin/warzone2100 | grep NEEDED | grep -E -v 'linux-vdso|ld-linux-' | awk 'NF == 2 { system("echo " $2 " && cp /var/lib/flatpak/runtime/org.freedesktop.Platform/${WZ_FLATPAK_TARGET_ARCH}/${WZ_FREEDESKTOP_RUNTIME_VERSION}/active/files/lib/${WZ_FLATPAK_TARGET_ARCH}-linux-gnu/" $2 " output_debug_dependency_snapshot") }'
fi
- name: Upload additional debug dependency info
uses: actions/upload-artifact@v3
with:
name: 'debugdependencylibsnapshot_linux_flatpak_${{ matrix.arch }}'
path: |
output_debug_dependency_snapshot
if-no-files-found: 'error'
###############################################################
# Package the ostree repo (for use in later publish-release-to-flathub job)
- name: Tar ostree repo
Expand Down Expand Up @@ -285,19 +309,25 @@ jobs:
steps:
- name: Prep Environment
run: |
mkdir dl-debug-symbols
- name: Download Artifacts
mkdir -p dl-debug/symbols
mkdir -p dl-debug/additional
- name: Download Debug Symbols
uses: actions/download-artifact@v3
with:
name: 'debugsymbols_linux_flatpak_${{ matrix.arch }}'
path: ./dl-debug-symbols
path: ./dl-debug/symbols
- name: Download Additional Debug Files
uses: actions/download-artifact@v3
with:
name: 'debugdependencylibsnapshot_linux_flatpak_${{ matrix.arch }}'
path: ./dl-debug/additional
- name: Display structure of downloaded files
run: ls -R
working-directory: ./dl-debug-symbols
working-directory: ./dl-debug
- name: 'Upload debug symbols'
env:
SENTRY_AUTH_TOKEN: '${{ secrets.SENTRY_AUTH_TOKEN }}'
WZ_ARCHIVE_DIR: './dl-debug-symbols'
WZ_ARCHIVE_DIR: './dl-debug'
WZ_GITHUB_REF: ${{needs.build-flatpak.outputs.WZ_GITHUB_REF}}
run: |
echo "WZ_GITHUB_REF=${WZ_GITHUB_REF}"
Expand All @@ -306,7 +336,7 @@ jobs:
exit 0
fi
docker pull getsentry/sentry-cli
docker run --rm -e SENTRY_AUTH_TOKEN -v "$(pwd):/work" getsentry/sentry-cli upload-dif --no-zips -o warzone2100 -p warzone2100 "${WZ_ARCHIVE_DIR}"
docker run --rm -e SENTRY_AUTH_TOKEN -v "$(pwd):/work" getsentry/sentry-cli debug-files upload --no-zips -o warzone2100 -p warzone2100 "${WZ_ARCHIVE_DIR}"

upload-release-builds:
strategy:
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
url = https://github.com/Warzone2100/maptools-cli.git
[submodule "3rdparty/basis_universal"]
path = 3rdparty/basis_universal
url = https://github.com/past-due/basis_universal.git
url = https://github.com/BinomialLLC/basis_universal.git
shallow = true
[submodule "data/terrain_overrides/classic"]
path = data/terrain_overrides/classic
Expand Down
1 change: 0 additions & 1 deletion lib/framework/wzapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ enum DialogType {
WZ_DECL_NONNULL(2, 3) void wzDisplayDialog(DialogType type, const char *title, const char *message); ///< Throw up a modal warning dialog - title & message are UTF-8 text

WzString wzGetPlatform();
uint32_t wzGetSystemRAM(); // in MiB
std::vector<screeninfo> wzAvailableResolutions();
screeninfo wzGetCurrentFullscreenDisplayMode();
std::vector<unsigned int> wzAvailableDisplayScales();
Expand Down
2 changes: 1 addition & 1 deletion lib/ivis_opengl/gfx_api_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3036,7 +3036,7 @@ uint32_t gl_context::getSuggestedDefaultDepthBufferResolution() const

// don't currently have a good way of checking video memory on this system
// instead, check system RAM
auto systemRAMinMiB = wzGetSystemRAM();
auto systemRAMinMiB = wzGetCurrentSystemRAM();
if (systemRAMinMiB >= 16384) // If >= 16 GB of system RAM
{
#if defined(WZ_OS_WIN)
Expand Down
5 changes: 3 additions & 2 deletions lib/ivis_opengl/gfx_api_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ static uint32_t findProperties(const vk::PhysicalDeviceMemoryProperties& memprop
{
// FUTURE TODO: Output a bunch more debugging info to the debug log?
}
debug(LOG_ERROR, "Vulkan backend encountered error: %s", vk::to_string(reason).c_str());
// Display a message and prompt the user to try a different graphics backend next time
wzPromptToChangeGfxBackendOnFailure("Failed with error: " + vk::to_string(reason));
abort();
Expand Down Expand Up @@ -2694,7 +2695,7 @@ static bool createDepthStencilImage(const vk::PhysicalDevice& physicalDevice, co

void VkRoot::createDefaultRenderpass(vk::Format swapchainFormat, vk::Format depthFormat)
{
bool msaaEnabled = (msaaSamples != vk::SampleCountFlagBits::e1);
bool msaaEnabled = false; // default render pass doesn't get MSAA

auto attachments =
std::vector<vk::AttachmentDescription>{
Expand Down Expand Up @@ -2777,7 +2778,7 @@ void VkRoot::createDefaultRenderpass(vk::Format swapchainFormat, vk::Format dept

renderPasses[DEFAULT_RENDER_PASS_ID].rp_compat_info = std::make_shared<VkhRenderPassCompat>(createInfo);
renderPasses[DEFAULT_RENDER_PASS_ID].rp = dev.createRenderPass(createInfo, nullptr, vkDynLoader);
renderPasses[DEFAULT_RENDER_PASS_ID].msaaSamples = msaaSamples;
renderPasses[DEFAULT_RENDER_PASS_ID].msaaSamples = (msaaEnabled) ? msaaSamples : vk::SampleCountFlagBits::e1;

// createFramebuffers for default render pass
ASSERT(!swapchainImageView.empty(), "No swapchain image views?");
Expand Down
17 changes: 3 additions & 14 deletions lib/sdl/main_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,6 @@ WzString wzGetPlatform()
return WzString::fromUtf8(SDL_GetPlatform());
}

// Get system RAM (in MiB)
uint32_t wzGetSystemRAM()
{
auto systemRAMResult = SDL_GetSystemRAM();
return (systemRAMResult > 0) ? static_cast<uint32_t>(systemRAMResult) : 0;
}

// See if we have TEXT in the clipboard
bool has_scrap(void)
{
Expand Down Expand Up @@ -2560,11 +2553,8 @@ void wzSDLPreWindowCreate_InitOpenGLAttributes(int antialiasing, bool useOpenGLE
// Enable stencil buffer, needed for shadows to work.
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);

if (antialiasing)
{
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, antialiasing);
}
// Do *not* enable multisampling on the default framebuffer (i.e. setting SDL_GL_MULTISAMPLEBUFFERS)
// This is handled separately for the scene render buffer / frame buffer

if (!sdl_OpenGL_Impl::configureOpenGLContextRequest(sdl_OpenGL_Impl::getInitialContextRequest(useOpenGLES), useOpenGLESLibrary))
{
Expand Down Expand Up @@ -3599,6 +3589,5 @@ bool wzBackendAttemptOpenURL(const char *url)
uint64_t wzGetCurrentSystemRAM()
{
int value = SDL_GetSystemRAM();
if (value <= 0) { return 0; }
return static_cast<uint64_t>(value);
return (value > 0) ? static_cast<uint64_t>(value) : 0;
}
5 changes: 5 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,11 @@ static bool initializeCrashHandlingContext(optional<video_backend> gfxbackend)
gfxBackendString = to_string(gfxbackend.value());
}
crashHandlingProviderSetTag("wz.gfx_backend", gfxBackendString);

auto systemRamMiB = wzGetCurrentSystemRAM();
std::string systemRamString = std::to_string(systemRamMiB);
crashHandlingProviderSetTag("wz.system_ram", systemRamString);

auto backendInfo = gfx_api::context::get().getBackendGameInfo();
// Truncate absurdly long backend info values (if needed - common culprit is GL_EXTENSIONS)
const size_t MAX_BACKENDINFO_VALUE_LENGTH = 2048;
Expand Down
11 changes: 10 additions & 1 deletion src/terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "display3d.h"
#include "hci.h"
#include "loop.h"
#include "wzcrashhandlingproviders.h"

// TODO: Fix and remove after merging terrain rendering changes
#if defined(__clang__)
Expand Down Expand Up @@ -2301,6 +2302,10 @@ bool setTerrainShaderQuality(TerrainShaderQuality newValue, bool force, bool for

if (success)
{
uint32_t debugQualityUint = static_cast<uint32_t>(terrainShaderQuality);
std::string terrainQualityUintStr = std::to_string(debugQualityUint);
crashHandlingProviderSetTag("wz.terrain_quality", terrainQualityUintStr);

if (sectors)
{
// mark all tiles dirty
Expand Down Expand Up @@ -2379,12 +2384,16 @@ bool debugToggleTerrainShaderType()
break;
case TerrainShaderType::SINGLE_PASS:
terrainShaderType = TerrainShaderType::FALLBACK;
terrainShaderQuality = TerrainShaderQuality::MEDIUM;
break;
}

// have to reload many things (currently)
shutdownTerrain();
setTerrainShaderQuality(terrainShaderQuality, true, true);
if (!setTerrainShaderQuality(terrainShaderQuality, true, true))
{
debug(LOG_INFO, "setTerrainShaderQuality failed?");
}
initTerrain();
return true;
}
Expand Down
23 changes: 23 additions & 0 deletions src/wzcrashhandlingproviders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,29 @@ bool crashHandlingProviderSetContext(const std::string& key, const nlohmann::jso
#endif
}

bool crashHandlingProviderCaptureException(const std::string& errorMessage, bool captureStackTrace)
{
#if !defined(WZ_CRASHHANDLING_PROVIDER)
return false;
#elif defined(WZ_CRASHHANDLING_PROVIDER_SENTRY)
// Sentry crash-handling provider
if (!enabledSentryProvider) { return false; }

sentry_value_t event = sentry_value_new_event();
sentry_value_t exc = sentry_value_new_exception("Exception", errorMessage.c_str());
if (captureStackTrace)
{
sentry_value_set_stacktrace(exc, NULL, 0);
}
sentry_event_add_exception(event, exc);
auto event_id = sentry_capture_event(event);
return !sentry_uuid_is_nil(&event_id);
#else
// Not available for crash handling provider
return false;
#endif
}

bool useCrashHandlingProvider(int argc, const char * const *argv, bool& out_debugCrashHandler)
{
#if !defined(WZ_CRASHHANDLING_PROVIDER)
Expand Down
1 change: 1 addition & 0 deletions src/wzcrashhandlingproviders.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bool shutdownCrashHandlingProvider();

bool crashHandlingProviderSetTag(const std::string& key, const std::string& value);
bool crashHandlingProviderSetContext(const std::string& key, const nlohmann::json& contextDictionary);
bool crashHandlingProviderCaptureException(const std::string& errorMessage, bool captureStackTrace);

bool crashHandlingProviderTestCrash();

Expand Down
Loading