mirror of
https://github.com/hedge-dev/XenosRecomp.git
synced 2025-10-30 07:12:17 +00:00
Integrate smol-v.
This commit is contained in:
parent
bd98728944
commit
53cee76796
6 changed files with 25 additions and 8 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "thirdparty/smol-v"]
|
||||||
|
path = thirdparty/smol-v
|
||||||
|
url = https://github.com/aras-p/smol-v
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
project(ShaderRecomp)
|
project(ShaderRecomp)
|
||||||
|
|
||||||
|
set(SMOLV_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty/smol-v/source")
|
||||||
|
|
||||||
add_executable(ShaderRecomp
|
add_executable(ShaderRecomp
|
||||||
constant_table.h
|
constant_table.h
|
||||||
dxc_compiler.cpp
|
dxc_compiler.cpp
|
||||||
|
|
@ -9,7 +11,8 @@ add_executable(ShaderRecomp
|
||||||
shader.h
|
shader.h
|
||||||
shader_code.h
|
shader_code.h
|
||||||
shader_recompiler.cpp
|
shader_recompiler.cpp
|
||||||
shader_recompiler.h)
|
shader_recompiler.h
|
||||||
|
"${SMOLV_SOURCE_DIR}/smolv.cpp")
|
||||||
|
|
||||||
find_package(directx-dxc CONFIG REQUIRED)
|
find_package(directx-dxc CONFIG REQUIRED)
|
||||||
find_package(xxhash CONFIG REQUIRED)
|
find_package(xxhash CONFIG REQUIRED)
|
||||||
|
|
@ -20,6 +23,8 @@ target_link_libraries(ShaderRecomp PRIVATE
|
||||||
xxHash::xxhash
|
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>)
|
||||||
|
|
||||||
|
target_include_directories(ShaderRecomp PRIVATE ${SMOLV_SOURCE_DIR})
|
||||||
|
|
||||||
target_precompile_headers(ShaderRecomp PRIVATE pch.h)
|
target_precompile_headers(ShaderRecomp PRIVATE pch.h)
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ IDxcBlob* DxcCompiler::compile(const std::string& shaderSource, bool compilePixe
|
||||||
source.Ptr = shaderSource.c_str();
|
source.Ptr = shaderSource.c_str();
|
||||||
source.Size = shaderSource.size();
|
source.Size = shaderSource.size();
|
||||||
|
|
||||||
const wchar_t* args[16]{};
|
const wchar_t* args[32]{};
|
||||||
uint32_t argCount = 0;
|
uint32_t argCount = 0;
|
||||||
|
|
||||||
const wchar_t* target = nullptr;
|
const wchar_t* target = nullptr;
|
||||||
|
|
@ -49,8 +49,11 @@ IDxcBlob* DxcCompiler::compile(const std::string& shaderSource, bool compilePixe
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
args[argCount++] = L"-Wno-ignored-attributes";
|
args[argCount++] = L"-Wno-ignored-attributes";
|
||||||
|
args[argCount++] = L"-Qstrip_reflect";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args[argCount++] = L"-Qstrip_debug";
|
||||||
|
|
||||||
IDxcResult* result = nullptr;
|
IDxcResult* result = nullptr;
|
||||||
HRESULT hr = dxcCompiler->Compile(&source, args, argCount, nullptr, IID_PPV_ARGS(&result));
|
HRESULT hr = dxcCompiler->Compile(&source, args, argCount, nullptr, IID_PPV_ARGS(&result));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ struct RecompiledShader
|
||||||
{
|
{
|
||||||
uint8_t* data = nullptr;
|
uint8_t* data = nullptr;
|
||||||
IDxcBlob* dxil = nullptr;
|
IDxcBlob* dxil = nullptr;
|
||||||
IDxcBlob* spirv = nullptr;
|
std::vector<uint8_t> spirv;
|
||||||
uint32_t specConstantsMask = 0;
|
uint32_t specConstantsMask = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -114,11 +114,16 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
thread_local DxcCompiler dxcCompiler;
|
thread_local DxcCompiler dxcCompiler;
|
||||||
shader.dxil = dxcCompiler.compile(recompiler.out, recompiler.isPixelShader, recompiler.specConstantsMask != 0, false);
|
shader.dxil = dxcCompiler.compile(recompiler.out, recompiler.isPixelShader, recompiler.specConstantsMask != 0, false);
|
||||||
shader.spirv = dxcCompiler.compile(recompiler.out, recompiler.isPixelShader, false, true);
|
IDxcBlob* spirv = dxcCompiler.compile(recompiler.out, recompiler.isPixelShader, false, true);
|
||||||
|
|
||||||
assert(shader.dxil != nullptr && shader.spirv != nullptr);
|
assert(shader.dxil != nullptr && spirv != nullptr);
|
||||||
assert(*(reinterpret_cast<uint32_t*>(shader.dxil->GetBufferPointer()) + 1) != 0 && "DXIL was not signed properly!");
|
assert(*(reinterpret_cast<uint32_t*>(shader.dxil->GetBufferPointer()) + 1) != 0 && "DXIL was not signed properly!");
|
||||||
|
|
||||||
|
bool result = smolv::Encode(spirv->GetBufferPointer(), spirv->GetBufferSize(), shader.spirv, smolv::kEncodeFlagStripDebugInfo);
|
||||||
|
assert(result);
|
||||||
|
|
||||||
|
spirv->Release();
|
||||||
|
|
||||||
size_t currentProgress = ++progress;
|
size_t currentProgress = ++progress;
|
||||||
if ((currentProgress % 10) == 0 || (currentProgress == shaders.size() - 1))
|
if ((currentProgress % 10) == 0 || (currentProgress == shaders.size() - 1))
|
||||||
std::println("Recompiling shaders... {}%", currentProgress / float(shaders.size()) * 100.0f);
|
std::println("Recompiling shaders... {}%", currentProgress / float(shaders.size()) * 100.0f);
|
||||||
|
|
@ -136,13 +141,12 @@ int main(int argc, char** argv)
|
||||||
for (auto& [hash, shader] : shaders)
|
for (auto& [hash, shader] : shaders)
|
||||||
{
|
{
|
||||||
f.println("\t{{ 0x{:X}, {}, {}, {}, {}, {} }},",
|
f.println("\t{{ 0x{:X}, {}, {}, {}, {}, {} }},",
|
||||||
hash, dxil.size(), shader.dxil->GetBufferSize(), spirv.size(), shader.spirv->GetBufferSize(), shader.specConstantsMask);
|
hash, dxil.size(), shader.dxil->GetBufferSize(), spirv.size(), shader.spirv.size(), shader.specConstantsMask);
|
||||||
|
|
||||||
dxil.insert(dxil.end(), reinterpret_cast<uint8_t*>(shader.dxil->GetBufferPointer()),
|
dxil.insert(dxil.end(), reinterpret_cast<uint8_t*>(shader.dxil->GetBufferPointer()),
|
||||||
reinterpret_cast<uint8_t*>(shader.dxil->GetBufferPointer()) + shader.dxil->GetBufferSize());
|
reinterpret_cast<uint8_t*>(shader.dxil->GetBufferPointer()) + shader.dxil->GetBufferSize());
|
||||||
|
|
||||||
spirv.insert(spirv.end(), reinterpret_cast<uint8_t*>(shader.spirv->GetBufferPointer()),
|
spirv.insert(spirv.end(), shader.spirv.begin(), shader.spirv.end());
|
||||||
reinterpret_cast<uint8_t*>(shader.spirv->GetBufferPointer()) + shader.spirv->GetBufferSize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
f.println("}};");
|
f.println("}};");
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <xxhash.h>
|
#include <xxhash.h>
|
||||||
#include <zstd.h>
|
#include <zstd.h>
|
||||||
|
#include <smolv.h>
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct be
|
struct be
|
||||||
|
|
|
||||||
1
thirdparty/smol-v
vendored
Submodule
1
thirdparty/smol-v
vendored
Submodule
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 9dd54c379ac29fa148cb1b829bb939ba7381d8f4
|
||||||
Loading…
Add table
Reference in a new issue