mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2025-10-30 07:01:10 +00:00
improve benchmark and fix init order
This commit is contained in:
parent
5da49bed0f
commit
63f0968375
3 changed files with 23 additions and 10 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,10 @@ const std::unordered_map<std::string, uint32_t> nameHashTable = {{
|
|||
}};
|
||||
|
||||
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 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<uint8_t> 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;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
#include <vector>
|
||||
|
||||
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<float>(count) / static_cast<float>(iterations) * 100.0F,
|
||||
count + 1, iterations);
|
||||
}
|
||||
const auto then = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// print results
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue