Add SPIR-V compression with LZ4 of Vulkan shaders (35% avg smaller)

This commit is contained in:
Wojtek Figat
2026-03-07 23:24:40 +01:00
parent 3038c56af4
commit c4342b0a20
4 changed files with 44 additions and 7 deletions

View File

@@ -12,6 +12,7 @@
#include "Engine/Core/Types/DataContainer.h"
#include "Engine/Serialization/MemoryReadStream.h"
#include "Engine/Profiler/ProfilerMemory.h"
#include <ThirdParty/LZ4/lz4.h>
#if PLATFORM_DESKTOP
#define VULKAN_UNIFORM_RING_BUFFER_SIZE (24 * 1024 * 1024)
@@ -108,8 +109,28 @@ GPUShaderProgram* GPUShaderVulkan::CreateGPUShaderProgram(ShaderStage type, cons
// Extract the SPIR-V bytecode
BytesContainer spirv;
ASSERT(header->Type == SpirvShaderHeader::Types::SPIRV);
spirv.Link(bytecode);
switch (header->Type)
{
case SpirvShaderHeader::Types::SPIRV:
spirv.Link(bytecode);
break;
case SpirvShaderHeader::Types::SPIRV_LZ4:
{
int32 originalSize = *(int32*)bytecode.Get();
bytecode = bytecode.Slice(sizeof(int32));
spirv.Allocate(originalSize);
const int32 res = LZ4_decompress_safe((const char*)bytecode.Get(), (char*)spirv.Get(), bytecode.Length(), originalSize);
if (res <= 0)
{
LOG(Error, "Failed to decompress shader");
return nullptr;
}
break;
}
default:
LOG(Error, "Invalid shader program format");
return nullptr;
}
// Create shader module from SPIR-V bytecode
VkShaderModule shaderModule = VK_NULL_HANDLE;