From 63f096837512f2ff018325d8dee35705dc2bc166 Mon Sep 17 00:00:00 2001 From: PancakeTAS Date: Thu, 10 Jul 2025 18:52:36 +0200 Subject: [PATCH] improve benchmark and fix init order --- CMakeLists.txt | 6 +++++- src/extract/extract.cpp | 17 ++++++++++------- src/utils/benchmark.cpp | 10 ++++++++-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3adae89..ca7a3c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,15 @@ cmake_minimum_required(VERSION 3.29) +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) + +set(CMAKE_SKIP_RPATH ON) + if(CMAKE_BUILD_TYPE STREQUAL "Release") add_definitions("-DLSFG_NO_DEBUG") endif() # subprojects -set(CMAKE_SKIP_RPATH ON) include(cmake/FetchDXVK.cmake) include(cmake/FetchPeParse.cmake) diff --git a/src/extract/extract.cpp b/src/extract/extract.cpp index 5706dd7..a7add33 100644 --- a/src/extract/extract.cpp +++ b/src/extract/extract.cpp @@ -42,7 +42,10 @@ const std::unordered_map nameHashTable = {{ }}; namespace { - std::unordered_map> shaderData; + auto& shaders() { + static std::unordered_map> shaderData; + return shaderData; + } uint32_t fnv1a_hash(const std::vector& data) { uint32_t hash = 0x811C9DC5; @@ -60,13 +63,13 @@ namespace { std::copy_n(res.buf->buf, res.buf->bufLen, resource_data.data()); const uint32_t hash = fnv1a_hash(resource_data); - shaderData[hash] = resource_data; + shaders()[hash] = resource_data; return 0; } } void Extract::extractShaders() { - if (!shaderData.empty()) + if (!shaders().empty()) return; // find path to dll (absolutely beautiful code) @@ -99,15 +102,15 @@ void Extract::extractShaders() { } std::vector Extract::getShader(const std::string& name) { - if (shaderData.empty()) + if (shaders().empty()) throw std::runtime_error("Shaders are not loaded."); auto hit = nameHashTable.find(name); if (hit == nameHashTable.end()) - throw std::runtime_error("Shader not found: " + name); + throw std::runtime_error("Shader hash not found: " + name); - auto sit = shaderData.find(hit->second); - if (sit == shaderData.end()) + auto sit = shaders().find(hit->second); + if (sit == shaders().end()) throw std::runtime_error("Shader not found: " + name); return sit->second; diff --git a/src/utils/benchmark.cpp b/src/utils/benchmark.cpp index 91db75e..3f805e7 100644 --- a/src/utils/benchmark.cpp +++ b/src/utils/benchmark.cpp @@ -12,7 +12,7 @@ #include namespace { - void __attribute__((constructor)) init() { + void __attribute__((constructor)) benchmark_init() { // continue if preloaded const char* preload = std::getenv("LD_PRELOAD"); if (!preload || *preload == '\0') @@ -74,8 +74,14 @@ namespace { // run the benchmark (run 8*n + 1 so the fences are waited on) const auto now = std::chrono::high_resolution_clock::now(); const uint64_t iterations = (8 * 500) + 1; - for (uint64_t count = 0; count < iterations; count++) + for (uint64_t count = 0; count < iterations; count++) { LSFG::presentContext(ctx, -1, {}); + + if (count % 500 == 0) + Log::info("bench", "{:.2f}% done ({}/{})", + static_cast(count) / static_cast(iterations) * 100.0F, + count + 1, iterations); + } const auto then = std::chrono::high_resolution_clock::now(); // print results