mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2026-04-22 02:11:43 +00:00
get rid of libcrypto
This commit is contained in:
parent
ccf71234c1
commit
9e20702180
5 changed files with 52 additions and 64 deletions
|
|
@ -13,7 +13,6 @@ In order to compile LSFG, make sure you have the following components installed
|
|||
- CMake build system
|
||||
- Meson build system (for DXVK)
|
||||
- Ninja build system (backend for CMake)
|
||||
- openssl's libcrypto
|
||||
|
||||
Compiling lsfg-vk is relatively straight forward, as everything is neatly integrated into CMake:
|
||||
```bash
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ target_include_directories(lsfg-vk-gen
|
|||
PRIVATE include
|
||||
PUBLIC public)
|
||||
target_link_libraries(lsfg-vk-gen
|
||||
PUBLIC vulkan peparse crypto dxvk)
|
||||
PUBLIC vulkan peparse dxvk)
|
||||
set_target_properties(lsfg-vk-gen
|
||||
PROPERTIES CXX_CLANG_TIDY clang-tidy)
|
||||
target_compile_options(lsfg-vk-gen PRIVATE
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace LSFG::Pool {
|
|||
///
|
||||
/// @throws std::runtime_error if the resource is not found.
|
||||
///
|
||||
[[nodiscard]] std::vector<uint8_t> getResource(const std::string& hash) const;
|
||||
[[nodiscard]] std::vector<uint8_t> getResource(uint32_t hash) const;
|
||||
|
||||
// Trivially copyable, moveable and destructible
|
||||
Extractor(const Extractor&) = delete;
|
||||
|
|
@ -44,7 +44,7 @@ namespace LSFG::Pool {
|
|||
Extractor& operator=(Extractor&&) = default;
|
||||
~Extractor() = default;
|
||||
private:
|
||||
std::unordered_map<std::string, std::vector<uint8_t>> resources;
|
||||
std::unordered_map<uint32_t, std::vector<uint8_t>> resources;
|
||||
};
|
||||
|
||||
///
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
#include <openssl/sha.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
|
@ -21,28 +20,29 @@ using namespace LSFG::Pool;
|
|||
|
||||
namespace {
|
||||
|
||||
using ResourceMap = std::unordered_map<std::string, std::vector<uint8_t>>;
|
||||
using ResourceMap = std::unordered_map<uint32_t, std::vector<uint8_t>>;
|
||||
|
||||
uint32_t fnv1a_hash(const std::vector<uint8_t>& data) {
|
||||
// does not need be secure
|
||||
uint32_t hash = 0x811C9DC5;
|
||||
for (auto byte : data) {
|
||||
hash ^= byte;
|
||||
hash *= 0x01000193;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
/// Callback function for each resource.
|
||||
int on_resource(void* data, const peparse::resource& res) {
|
||||
if (res.type != peparse::RT_RCDATA || res.buf == nullptr || res.buf->bufLen <= 0)
|
||||
return 0;
|
||||
|
||||
// hash the resource data
|
||||
std::array<uint8_t, SHA256_DIGEST_LENGTH> hash{};
|
||||
SHA256(res.buf->buf, res.buf->bufLen, hash.data());
|
||||
|
||||
std::array<uint8_t, SHA256_DIGEST_LENGTH * 2 + 1> base64{};
|
||||
const int base64_len = EVP_EncodeBlock(base64.data(), hash.data(), hash.size());
|
||||
const std::string hash_str(reinterpret_cast<const char*>(base64.data()),
|
||||
static_cast<size_t>(base64_len));
|
||||
|
||||
// store the resource
|
||||
std::vector<uint8_t> resource_data(res.buf->bufLen);
|
||||
std::copy_n(res.buf->buf, res.buf->bufLen, resource_data.data());
|
||||
|
||||
const uint32_t hash = fnv1a_hash(resource_data);
|
||||
|
||||
auto* map = reinterpret_cast<ResourceMap*>(data);
|
||||
(*map)[hash_str] = resource_data;
|
||||
(*map)[hash] = resource_data;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -58,27 +58,19 @@ Extractor::Extractor(const std::string& path) {
|
|||
peparse::DestructParsedPE(pe);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Extractor::getResource(const std::string& hash) const {
|
||||
std::vector<uint8_t> Extractor::getResource(uint32_t hash) const {
|
||||
auto it = this->resources.find(hash);
|
||||
if (it != this->resources.end())
|
||||
return it->second;
|
||||
throw std::runtime_error("Resource not found: " + hash);
|
||||
throw std::runtime_error("Resource not found.");
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Pool::dxbcToSpirv(const std::vector<uint8_t>& dxbc) {
|
||||
// create sha1 hash of the dxbc data
|
||||
std::array<uint8_t, SHA_DIGEST_LENGTH> hash{};
|
||||
SHA1(dxbc.data(), dxbc.size(), hash.data());
|
||||
std::stringstream ss;
|
||||
for (const auto& byte : hash)
|
||||
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte);
|
||||
const std::string hash_str = ss.str();
|
||||
|
||||
// compile the shader
|
||||
dxvk::DxbcReader reader(reinterpret_cast<const char*>(dxbc.data()), dxbc.size());
|
||||
dxvk::DxbcModule module(reader);
|
||||
const dxvk::DxbcModuleInfo info{};
|
||||
auto shader = module.compile(info, "CS_" + hash_str);
|
||||
auto shader = module.compile(info, "CS");
|
||||
|
||||
// extract spir-v from d3d11 shader
|
||||
auto code = shader->getRawCode();
|
||||
|
|
|
|||
|
|
@ -1,43 +1,40 @@
|
|||
#include "pool/shaderpool.hpp"
|
||||
|
||||
#include "pool/extract.hpp"
|
||||
|
||||
using namespace LSFG;
|
||||
using namespace LSFG::Pool;
|
||||
|
||||
const std::unordered_map<std::string, std::string> SHADERS = {
|
||||
{ "alpha/0.spv", "lilEUr7nBgA8P6VSqCms09t9b+DZH6dVlcefVuFHlc8=" },
|
||||
{ "alpha/1.spv", "2TRNidol3BNs/aeLl2/Om7z8bAlpehkOPVtmMao1q84=" },
|
||||
{ "alpha/2.spv", "tP6qIJZhd4pGr1pop1e9ztW1gwp97ufQa2GaBZBYZJE=" },
|
||||
{ "alpha/3.spv", "gA4ZejNp+RwtqjtTzGdGf5D/CjSGlwFB2nOgDAIv91k=" },
|
||||
{ "beta/0.spv", "uQ/xsBMKRuJhbxstBukWMhXYuppPAYygxkb/3kNu4vI=" },
|
||||
{ "beta/1.spv", "BUbrL9fZREXLlg1lmlTYD6n8DwpzHkho5bI3RLbfNJg=" },
|
||||
{ "beta/2.spv", "bz0lxQjMYp6HLqw12X3jfV7H0SOZKrqUhgtw17WgTx4=" },
|
||||
{ "beta/3.spv", "JA5/8p7yiiiCxmuiTsOR9Fb/z1qp8KlyU2wo9Wfpbcc=" },
|
||||
{ "beta/4.spv", "/I+iYEwzOFylXZJWWNQ/oUT6SeLVnpotNXGV8y/FUVk=" },
|
||||
{ "delta/0.spv", "gtBWy1WtP8NO+Z1sSPMgOJ75NaPEKvthc7imNGzJkGI=" },
|
||||
{ "delta/1.spv", "JiqZZIoHay/uS1ptzlz3EWKUPct/jQHoFtN0qlEtVUU=" },
|
||||
{ "delta/2.spv", "zkBa37GvAG8izeIv4o/3OowpxiobfOdNmPyVWl2BSWY=" },
|
||||
{ "delta/3.spv", "neIMl/PCPonXqjtZykMb9tR4yW7JkZfMTqZPGOmJQUg=" },
|
||||
{ "downsample.spv", "F9BppS+ytDjO3aoMEY7deMzLaSUhX8EuI+eH8654Fpw=" },
|
||||
{ "epsilon/0.spv", "YHECg9LrgTCM8lABFOXkC5qTKoHsIMWnZ6ST3dexD08=" },
|
||||
{ "epsilon/1.spv", "Uv7CfTi6x69c9Exuc16UqA7fvLTUGicHZVi5jhHKo0w=" },
|
||||
{ "epsilon/2.spv", "0vmxxGRa6gbl5dqmKTBO9x/ZM2oEUJ5JtGfqcHhvouQ=" },
|
||||
{ "epsilon/3.spv", "Sa/gkbCCDyCyUh8BSOa882t4qDc51oeP6+Kj3O3EaxM=" },
|
||||
{ "extract.spv", "xKUdoEwFJDsc/kX/aY1FyzlMlOaJX4iHQLlthe2MvBs=" },
|
||||
{ "gamma/0.spv", "AJuuF/X9NnypgBd89GbXMKcXC2meysYayiZQZwu3WhU=" },
|
||||
{ "gamma/1.spv", "LLr/3D+whLd6XuKkBS7rlaNN+r8qB/Khr4ii+M7KSxY=" },
|
||||
{ "gamma/2.spv", "KjHXdawBR8AMK7Kud/vXJmJTddXFKppREEpsykjwZDc=" },
|
||||
{ "gamma/3.spv", "zAnAC73i76AJjv0o1To3bBu2jnIWXzX3NlSMvU3Lgxw=" },
|
||||
{ "gamma/4.spv", "ivQ7ltprazBOXb46yxul9HJ5ByJk2LbG034cC6NkEpk=" },
|
||||
{ "gamma/5.spv", "lHYgyCpWnMIB74HL22BKQyoqUGvUjgR79W4vXFXzXe4=" },
|
||||
{ "magic.spv", "ZdoTjEhrlbAxq0MtaJyk6jQ5+hrySEsnvn+jseukAuI=" },
|
||||
{ "merge.spv", "dnluf4IHKNaqz6WvH7qodn+fZ56ORx+w3MUOwH7huok=" },
|
||||
{ "zeta/0.spv", "LLr/3D+whLd6XuKkBS7rlaNN+r8qB/Khr4ii+M7KSxY=" },
|
||||
{ "zeta/1.spv", "KjHXdawBR8AMK7Kud/vXJmJTddXFKppREEpsykjwZDc=" },
|
||||
{ "zeta/2.spv", "zAnAC73i76AJjv0o1To3bBu2jnIWXzX3NlSMvU3Lgxw=" },
|
||||
{ "zeta/3.spv", "ivQ7ltprazBOXb46yxul9HJ5ByJk2LbG034cC6NkEpk=" },
|
||||
{ "zeta/4.spv", "lHYgyCpWnMIB74HL22BKQyoqUGvUjgR79W4vXFXzXe4=" }
|
||||
const std::unordered_map<std::string, uint32_t> SHADERS = {
|
||||
{ "downsample.spv", 0xe365474d },
|
||||
{ "alpha/0.spv", 0x35f63c83 },
|
||||
{ "alpha/1.spv", 0x83e5240d },
|
||||
{ "alpha/2.spv", 0x5d64d9f1 },
|
||||
{ "alpha/3.spv", 0xad77afe1 },
|
||||
{ "beta/0.spv", 0xa986ccbb },
|
||||
{ "beta/1.spv", 0x60944cf5 },
|
||||
{ "beta/2.spv", 0xb1c8f69b },
|
||||
{ "beta/3.spv", 0x87cbe880 },
|
||||
{ "beta/4.spv", 0xc2c5507d },
|
||||
{ "gamma/0.spv", 0xccce9dab },
|
||||
{ "gamma/1.spv", 0x7719e229 },
|
||||
{ "gamma/2.spv", 0xfb1a7643 },
|
||||
{ "gamma/3.spv", 0xe0553cd8 },
|
||||
{ "gamma/4.spv", 0xf73c136f },
|
||||
{ "gamma/5.spv", 0xa34959c },
|
||||
{ "magic.spv", 0x443ea7a1 },
|
||||
{ "delta/0.spv", 0x141daaac },
|
||||
{ "delta/1.spv", 0x2a0ed691 },
|
||||
{ "delta/2.spv", 0x23bdc583 },
|
||||
{ "delta/3.spv", 0x52bc5e0f },
|
||||
{ "epsilon/0.spv", 0x128eb7d7 },
|
||||
{ "epsilon/1.spv", 0xbab811ad },
|
||||
{ "epsilon/2.spv", 0x1d4b902d },
|
||||
{ "epsilon/3.spv", 0x91236549 },
|
||||
{ "zeta/0.spv", 0x7719e229 },
|
||||
{ "zeta/1.spv", 0xfb1a7643 },
|
||||
{ "zeta/2.spv", 0xe0553cd8 },
|
||||
{ "zeta/3.spv", 0xf73c136f },
|
||||
{ "extract.spv", 0xb6cb084a },
|
||||
{ "merge.spv", 0xfc0aedfa }
|
||||
};
|
||||
|
||||
Core::ShaderModule ShaderPool::getShader(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue