Downgrade to C++17 & switch to fmtlib.

This commit is contained in:
Skyth 2024-12-13 16:54:10 +03:00
parent f936ed2212
commit 12b38144b9
7 changed files with 41 additions and 23 deletions

View file

@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.29)
cmake_minimum_required(VERSION 3.20)
include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD 17)
project(ShaderRecomp-ALL)
add_subdirectory(ShaderRecomp)
add_subdirectory(ShaderRecomp)

View file

@ -17,11 +17,13 @@ add_executable(ShaderRecomp
find_package(directx-dxc CONFIG REQUIRED)
find_package(xxhash CONFIG REQUIRED)
find_package(zstd CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
target_link_libraries(ShaderRecomp PRIVATE
Microsoft::DirectXShaderCompiler
xxHash::xxhash
$<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>)
$<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>
fmt::fmt)
target_include_directories(ShaderRecomp PRIVATE ${SMOLV_SOURCE_DIR})

View file

@ -126,10 +126,10 @@ int main(int argc, char** argv)
size_t currentProgress = ++progress;
if ((currentProgress % 10) == 0 || (currentProgress == shaders.size() - 1))
std::println("Recompiling shaders... {}%", currentProgress / float(shaders.size()) * 100.0f);
fmt::println("Recompiling shaders... {}%", currentProgress / float(shaders.size()) * 100.0f);
});
std::println("Creating shader cache...");
fmt::println("Creating shader cache...");
StringBuffer f;
f.println("#include \"shader_cache.h\"");
@ -151,7 +151,7 @@ int main(int argc, char** argv)
f.println("}};");
std::println("Compressing DXIL cache...");
fmt::println("Compressing DXIL cache...");
int level = ZSTD_maxCLevel();
//level = ZSTD_defaultCLevel();
@ -165,7 +165,7 @@ int main(int argc, char** argv)
f.println("}};");
std::println("Compressing SPIRV cache...");
fmt::println("Compressing SPIRV cache...");
std::vector<uint8_t> spirvCompressed(ZSTD_compressBound(spirv.size()));
spirvCompressed.resize(ZSTD_compress(spirvCompressed.data(), spirvCompressed.size(), spirv.data(), spirv.size(), level));

View file

@ -8,14 +8,29 @@
#include <cstdint>
#include <execution>
#include <filesystem>
#include <print>
#include <format>
#include <map>
#include <smolv.h>
#include <fmt/core.h>
#include <string>
#include <unordered_map>
#include <xxhash.h>
#include <zstd.h>
#include <smolv.h>
template<typename T>
static T byteSwap(T value)
{
if constexpr (sizeof(T) == 1)
return value;
else if constexpr (sizeof(T) == 2)
return static_cast<T>(__builtin_bswap16(static_cast<uint16_t>(value)));
else if constexpr (sizeof(T) == 4)
return static_cast<T>(__builtin_bswap32(static_cast<uint32_t>(value)));
else if constexpr (sizeof(T) == 8)
return static_cast<T>(__builtin_bswap64(static_cast<uint64_t>(value)));
assert(false && "Unexpected byte size.");
return value;
}
template<typename T>
struct be
@ -25,9 +40,9 @@ struct be
T get() const
{
if constexpr (std::is_enum_v<T>)
return T(std::byteswap(std::underlying_type_t<T>(value)));
return T(byteSwap(std::underlying_type_t<T>(value)));
else
return std::byteswap(value);
return byteSwap(value);
}
operator T() const

View file

@ -257,7 +257,7 @@ void ShaderRecompiler::recompile(const TextureFetchInstruction& instr, bool bicu
}
else
{
constName = std::format("s{}", instr.constIndex);
constName = fmt::format("s{}", instr.constIndex);
constNamePtr = constName.c_str();
}
@ -437,7 +437,7 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
if (select)
{
regFormatted = std::format("r{}", reg);
regFormatted = fmt::format("r{}", reg);
}
else
{
@ -449,12 +449,12 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
{
if (hasMtxProjection && strcmp(constantName, "g_MtxProjection") == 0)
{
regFormatted = std::format("(iterationIndex == 0 ? mtxProjectionReverseZ[{0}] : mtxProjection[{0}])",
regFormatted = fmt::format("(iterationIndex == 0 ? mtxProjectionReverseZ[{0}] : mtxProjection[{0}])",
reg - findResult->second->registerIndex);
}
else
{
regFormatted = std::format("{}({}{})", constantName,
regFormatted = fmt::format("{}({}{})", constantName,
reg - findResult->second->registerIndex, instr.const0Relative ? (instr.constAddressRegisterRelative ? " + a0" : " + aL") : "");
}
}
@ -467,7 +467,7 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
else
{
assert(!instr.const0Relative && !instr.const1Relative);
regFormatted = std::format("c{}", reg);
regFormatted = fmt::format("c{}", reg);
}
}
@ -1408,7 +1408,7 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
{
auto vertexShader = reinterpret_cast<const VertexShader*>(shader);
value = vertexShader->vertexElementsAndInterpolators[vertexShader->field18 + vertexShader->vertexElementCount + i];
interpolators.emplace(i, std::format("o{}{}", USAGE_VARIABLES[uint32_t(interpolator.usage)], uint32_t(interpolator.usageIndex)));
interpolators.emplace(i, fmt::format("o{}{}", USAGE_VARIABLES[uint32_t(interpolator.usage)], uint32_t(interpolator.usageIndex)));
}
}

View file

@ -8,15 +8,15 @@ struct StringBuffer
std::string out;
template<class... Args>
void print(std::format_string<Args...> fmt, Args&&... args)
void print(fmt::format_string<Args...> fmt, Args&&... args)
{
std::vformat_to(std::back_inserter(out), fmt.get(), std::make_format_args(args...));
fmt::vformat_to(std::back_inserter(out), fmt.get(), fmt::make_format_args(args...));
}
template<class... Args>
void println(std::format_string<Args...> fmt, Args&&... args)
void println(fmt::format_string<Args...> fmt, Args&&... args)
{
std::vformat_to(std::back_inserter(out), fmt.get(), std::make_format_args(args...));
fmt::vformat_to(std::back_inserter(out), fmt.get(), fmt::make_format_args(args...));
out += '\n';
}
};

View file

@ -2,6 +2,7 @@
"builtin-baseline": "e63bd09dc0b7204467705c1c7c71d0e2a3f8860b",
"dependencies": [
"directx-dxc",
"fmt",
"xxhash",
"zstd"
]