improve benchmark and fix init order

This commit is contained in:
PancakeTAS 2025-07-10 18:52:36 +02:00
parent 5da49bed0f
commit 63f0968375
No known key found for this signature in database
3 changed files with 23 additions and 10 deletions

View file

@ -1,11 +1,15 @@
cmake_minimum_required(VERSION 3.29) 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") if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions("-DLSFG_NO_DEBUG") add_definitions("-DLSFG_NO_DEBUG")
endif() endif()
# subprojects # subprojects
set(CMAKE_SKIP_RPATH ON)
include(cmake/FetchDXVK.cmake) include(cmake/FetchDXVK.cmake)
include(cmake/FetchPeParse.cmake) include(cmake/FetchPeParse.cmake)

View file

@ -42,7 +42,10 @@ const std::unordered_map<std::string, uint32_t> nameHashTable = {{
}}; }};
namespace { namespace {
std::unordered_map<uint32_t, std::vector<uint8_t>> shaderData; auto& shaders() {
static std::unordered_map<uint32_t, std::vector<uint8_t>> shaderData;
return shaderData;
}
uint32_t fnv1a_hash(const std::vector<uint8_t>& data) { uint32_t fnv1a_hash(const std::vector<uint8_t>& data) {
uint32_t hash = 0x811C9DC5; uint32_t hash = 0x811C9DC5;
@ -60,13 +63,13 @@ namespace {
std::copy_n(res.buf->buf, res.buf->bufLen, resource_data.data()); std::copy_n(res.buf->buf, res.buf->bufLen, resource_data.data());
const uint32_t hash = fnv1a_hash(resource_data); const uint32_t hash = fnv1a_hash(resource_data);
shaderData[hash] = resource_data; shaders()[hash] = resource_data;
return 0; return 0;
} }
} }
void Extract::extractShaders() { void Extract::extractShaders() {
if (!shaderData.empty()) if (!shaders().empty())
return; return;
// find path to dll (absolutely beautiful code) // find path to dll (absolutely beautiful code)
@ -99,15 +102,15 @@ void Extract::extractShaders() {
} }
std::vector<uint8_t> Extract::getShader(const std::string& name) { std::vector<uint8_t> Extract::getShader(const std::string& name) {
if (shaderData.empty()) if (shaders().empty())
throw std::runtime_error("Shaders are not loaded."); throw std::runtime_error("Shaders are not loaded.");
auto hit = nameHashTable.find(name); auto hit = nameHashTable.find(name);
if (hit == nameHashTable.end()) 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); auto sit = shaders().find(hit->second);
if (sit == shaderData.end()) if (sit == shaders().end())
throw std::runtime_error("Shader not found: " + name); throw std::runtime_error("Shader not found: " + name);
return sit->second; return sit->second;

View file

@ -12,7 +12,7 @@
#include <vector> #include <vector>
namespace { namespace {
void __attribute__((constructor)) init() { void __attribute__((constructor)) benchmark_init() {
// continue if preloaded // continue if preloaded
const char* preload = std::getenv("LD_PRELOAD"); const char* preload = std::getenv("LD_PRELOAD");
if (!preload || *preload == '\0') if (!preload || *preload == '\0')
@ -74,8 +74,14 @@ namespace {
// run the benchmark (run 8*n + 1 so the fences are waited on) // run the benchmark (run 8*n + 1 so the fences are waited on)
const auto now = std::chrono::high_resolution_clock::now(); const auto now = std::chrono::high_resolution_clock::now();
const uint64_t iterations = (8 * 500) + 1; 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, {}); LSFG::presentContext(ctx, -1, {});
if (count % 500 == 0)
Log::info("bench", "{:.2f}% done ({}/{})",
static_cast<float>(count) / static_cast<float>(iterations) * 100.0F,
count + 1, iterations);
}
const auto then = std::chrono::high_resolution_clock::now(); const auto then = std::chrono::high_resolution_clock::now();
// print results // print results