Skip to content

Commit b2927ba

Browse files
committed
ready
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
1 parent afa4935 commit b2927ba

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

include/nbl/asset/utils/IShaderCompiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
360360
// Making the copy constructor deep-copy everything but the shader
361361
inline SEntry(const SEntry& other)
362362
: mainFileContents(other.mainFileContents), compilerArgs(other.compilerArgs), hash(other.hash), lookupHash(other.lookupHash),
363-
dependencies(other.dependencies), spirv(other.spirv) {}
363+
dependencies(other.dependencies), spirv(other.spirv), uncompressedSize(other.uncompressedSize) {}
364364

365365
inline SEntry& operator=(SEntry& other) = delete;
366366
inline SEntry(SEntry&& other) = default;

src/nbl/asset/utils/IShaderCompiler.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,31 @@ inline core::smart_refctd_ptr<ICPUShader> nbl::asset::IShaderCompiler::compileTo
6262
auto* spirvBuffer = retVal->getContent();
6363
size_t propsSize = LZMA_PROPS_SIZE;
6464
size_t destLen = spirvBuffer->getSize() + spirvBuffer->getSize() / 3 + 128;
65-
auto compressedSpirvBuffer = core::make_smart_refctd_ptr<ICPUBuffer>(propsSize + destLen);
65+
std::vector<unsigned char> compressedSpirv = {};
66+
compressedSpirv.resize(propsSize + destLen);
6667

6768
CLzmaEncProps props;
6869
LzmaEncProps_Init(&props);
69-
props.dictSize = 1 << 16; // 64 KB
70-
props.writeEndMark = 1; // 0 or 1
70+
props.dictSize = 1 << 16; // 64KB
71+
props.writeEndMark = 1;
7172

7273
ISzAlloc alloc = { SzAlloc, SzFree };
7374
int res = LzmaEncode(
74-
reinterpret_cast<unsigned char*>(compressedSpirvBuffer->getPointer()) + LZMA_PROPS_SIZE, &destLen,
75+
compressedSpirv.data() + LZMA_PROPS_SIZE, &destLen,
7576
reinterpret_cast<const unsigned char*>(spirvBuffer->getPointer()), spirvBuffer->getSize(),
76-
&props, reinterpret_cast<unsigned char*>(compressedSpirvBuffer->getPointer()), &propsSize, props.writeEndMark,
77+
&props, compressedSpirv.data(), &propsSize, props.writeEndMark,
7778
nullptr, &alloc, &alloc);
7879

7980
assert(propsSize == LZMA_PROPS_SIZE);
8081
assert(res == SZ_OK);
8182

83+
auto compressedSpirvBuffer = core::make_smart_refctd_ptr<ICPUBuffer>(propsSize + destLen);
84+
memcpy(compressedSpirvBuffer->getPointer(), compressedSpirv.data(), compressedSpirvBuffer->getSize());
85+
8286
entry.dependencies = std::move(dependencies);
8387
entry.spirv = std::move(compressedSpirvBuffer);
8488
entry.uncompressedSize = spirvBuffer->getSize();
8589

86-
std::cout << "original: " << spirvBuffer->getSize() << ", compressed: " << compressedSpirvBuffer->getSize() << "\n";
87-
8890
options.writeCache->insert(std::move(entry));
8991
}
9092
return retVal;
@@ -398,7 +400,6 @@ core::smart_refctd_ptr<IShaderCompiler::CCache> IShaderCompiler::CCache::deseria
398400
return nullptr;
399401
}
400402
}
401-
402403

403404
// Now retrieve two vectors, one with the entries and one with the extra data to recreate the CPUShaders
404405
std::vector<SEntry> entries;

0 commit comments

Comments
 (0)