diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..47afc81 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "thirdparty/smol-v"] + path = thirdparty/smol-v + url = https://github.com/aras-p/smol-v diff --git a/ShaderRecomp/CMakeLists.txt b/ShaderRecomp/CMakeLists.txt index 8fbef91..a7a72b0 100644 --- a/ShaderRecomp/CMakeLists.txt +++ b/ShaderRecomp/CMakeLists.txt @@ -1,5 +1,7 @@ project(ShaderRecomp) +set(SMOLV_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty/smol-v/source") + add_executable(ShaderRecomp constant_table.h dxc_compiler.cpp @@ -9,7 +11,8 @@ add_executable(ShaderRecomp shader.h shader_code.h shader_recompiler.cpp - shader_recompiler.h) + shader_recompiler.h + "${SMOLV_SOURCE_DIR}/smolv.cpp") find_package(directx-dxc CONFIG REQUIRED) find_package(xxhash CONFIG REQUIRED) @@ -20,6 +23,8 @@ target_link_libraries(ShaderRecomp PRIVATE xxHash::xxhash $,zstd::libzstd_shared,zstd::libzstd_static>) +target_include_directories(ShaderRecomp PRIVATE ${SMOLV_SOURCE_DIR}) + target_precompile_headers(ShaderRecomp PRIVATE pch.h) if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") diff --git a/ShaderRecomp/dxc_compiler.cpp b/ShaderRecomp/dxc_compiler.cpp index e33a05e..bde73ad 100644 --- a/ShaderRecomp/dxc_compiler.cpp +++ b/ShaderRecomp/dxc_compiler.cpp @@ -17,7 +17,7 @@ IDxcBlob* DxcCompiler::compile(const std::string& shaderSource, bool compilePixe source.Ptr = shaderSource.c_str(); source.Size = shaderSource.size(); - const wchar_t* args[16]{}; + const wchar_t* args[32]{}; uint32_t argCount = 0; const wchar_t* target = nullptr; @@ -49,8 +49,11 @@ IDxcBlob* DxcCompiler::compile(const std::string& shaderSource, bool compilePixe else { args[argCount++] = L"-Wno-ignored-attributes"; + args[argCount++] = L"-Qstrip_reflect"; } + args[argCount++] = L"-Qstrip_debug"; + IDxcResult* result = nullptr; HRESULT hr = dxcCompiler->Compile(&source, args, argCount, nullptr, IID_PPV_ARGS(&result)); diff --git a/ShaderRecomp/main.cpp b/ShaderRecomp/main.cpp index 258c466..dce0323 100644 --- a/ShaderRecomp/main.cpp +++ b/ShaderRecomp/main.cpp @@ -25,7 +25,7 @@ struct RecompiledShader { uint8_t* data = nullptr; IDxcBlob* dxil = nullptr; - IDxcBlob* spirv = nullptr; + std::vector spirv; uint32_t specConstantsMask = 0; }; @@ -114,11 +114,16 @@ int main(int argc, char** argv) thread_local DxcCompiler dxcCompiler; 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(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; if ((currentProgress % 10) == 0 || (currentProgress == shaders.size() - 1)) 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) { 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(shader.dxil->GetBufferPointer()), reinterpret_cast(shader.dxil->GetBufferPointer()) + shader.dxil->GetBufferSize()); - spirv.insert(spirv.end(), reinterpret_cast(shader.spirv->GetBufferPointer()), - reinterpret_cast(shader.spirv->GetBufferPointer()) + shader.spirv->GetBufferSize()); + spirv.insert(spirv.end(), shader.spirv.begin(), shader.spirv.end()); } f.println("}};"); diff --git a/ShaderRecomp/pch.h b/ShaderRecomp/pch.h index 829eb2b..7619813 100644 --- a/ShaderRecomp/pch.h +++ b/ShaderRecomp/pch.h @@ -15,6 +15,7 @@ #include #include #include +#include template struct be diff --git a/thirdparty/smol-v b/thirdparty/smol-v new file mode 160000 index 0000000..9dd54c3 --- /dev/null +++ b/thirdparty/smol-v @@ -0,0 +1 @@ +Subproject commit 9dd54c379ac29fa148cb1b829bb939ba7381d8f4