asset compression
This commit is contained in:
parent
b9b9ecb84c
commit
30a283c1b3
57 changed files with 13237 additions and 8 deletions
59
interfaces/Crafter.Asset-Compression.cppm
Normal file
59
interfaces/Crafter.Asset-Compression.cppm
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
Crafter®.Asset
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License version 3.0 as published by the Free Software Foundation;
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
export module Crafter.Asset:Compression;
|
||||
import std;
|
||||
|
||||
export namespace Crafter::Compression {
|
||||
// One independently-decompressable GDeflate stream inside CompressedBlob::bytes.
|
||||
// Layout matches what VK_EXT_memory_decompression's VkDecompressMemoryRegionEXT
|
||||
// expects, minus the device addresses (which the consumer fills in).
|
||||
struct RegionMeta {
|
||||
std::uint64_t srcOffset;
|
||||
std::uint64_t compressedSize;
|
||||
std::uint64_t decompressedSize;
|
||||
};
|
||||
|
||||
struct CompressedBlob {
|
||||
std::vector<std::byte> bytes;
|
||||
std::vector<RegionMeta> regions;
|
||||
|
||||
std::uint64_t TotalDecompressedSize() const noexcept {
|
||||
std::uint64_t sum = 0;
|
||||
for (const RegionMeta& r : regions) sum += r.decompressedSize;
|
||||
return sum;
|
||||
}
|
||||
};
|
||||
|
||||
// Compresses each input span as its own GDeflate tile-stream; concatenates
|
||||
// them into one byte buffer with a parallel region table. Streams are
|
||||
// independent and can be addressed individually by VkDecompressMemoryRegionEXT
|
||||
// entries on the GPU path.
|
||||
CompressedBlob CompressStreams(std::span<const std::span<const std::byte>> streams);
|
||||
|
||||
// CPU fallback decoder. outputs.size() must equal blob.regions.size();
|
||||
// outputs[i].size() must equal blob.regions[i].decompressedSize.
|
||||
void DecompressCPU(const CompressedBlob& blob, std::span<const std::span<std::byte>> outputs);
|
||||
|
||||
// Length-prefixed serialization of a CompressedBlob. Used by per-asset
|
||||
// SaveCompressed/LoadCompressed implementations after they've written
|
||||
// their own type-specific header.
|
||||
void WriteBlob(std::ostream& file, const CompressedBlob& blob);
|
||||
CompressedBlob ReadBlob(std::istream& file);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue