Skip to content

Commit 9803aef

Browse files
author
devsh
committed
correct bad ZLIB macro usage and the mistuba loader cmakedefine, zlib linking for ext::MitsubaLoader
Also realize that premature optimization is the root of all evil and decompressed data can't be adopted.
1 parent 95809fa commit 9803aef

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

3rdparty/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,11 @@ if (NBL_BUILD_MITSUBA_LOADER)
434434
add_subdirectory(libexpat/expat EXCLUDE_FROM_ALL)
435435

436436
set(MITSUBA_LOADER_DEPENDENTS
437-
expat
437+
expat zlibstatic
438438
)
439439
set(MITSUBA_LOADER_DEPENDENTS ${MITSUBA_LOADER_DEPENDENTS} PARENT_SCOPE)
440440
set(MITSUBA_LOADER_DEPENDENT_LIBS
441-
expat
441+
expat "${ZLIB_LIBRARY}"
442442
)
443443
set(MITSUBA_LOADER_DEPENDENT_LIBS ${MITSUBA_LOADER_DEPENDENT_LIBS} PARENT_SCOPE)
444444
endif()

include/nbl/config/BuildConfigOptions.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#cmakedefine _NBL_COMPILE_WITH_VULKAN_
2424

2525
// loaders
26-
#cmakedefine _NBL_COMPILE_WITH_MITSUBA_SERIALIZED_LOADER_
26+
#cmakedefine NBL_BUILD_MITSUBA_LOADER
2727
#cmakedefine _NBL_COMPILE_WITH_MTL_LOADER_
2828
#cmakedefine _NBL_COMPILE_WITH_OBJ_LOADER_
2929
#cmakedefine _NBL_COMPILE_WITH_STL_LOADER_

src/nbl/ext/MitsubaLoader/CSerializedLoader.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// need Zlib to get this loader
1212
#ifdef _NBL_COMPILE_WITH_ZLIB_
1313
#include "zlib/zlib.h"
14+
#include "zlib/zconf.h"
1415

1516

1617
namespace nbl::ext::MitsubaLoader
@@ -107,8 +108,7 @@ asset::SAssetBundle CSerializedLoader::loadAsset(system::IFile* _file, const ass
107108

108109
constexpr size_t CHUNK = 256<<10;
109110
using page_t = Page<>;
110-
auto decompressedResource = make_smart_refctd_ptr<adoption_memory_resource<core::vector<page_t>>>(core::vector<page_t>(CHUNK/sizeof(page_t)));
111-
auto& decompressed = decompressedResource->getBacker();
111+
auto decompressed = core::vector<page_t>(CHUNK/sizeof(page_t));
112112
for (uint32_t i=0; i<ctx.meshCount; i++)
113113
{
114114
auto localSize = ctx.meshOffsets->operator[](i+ctx.meshCount);
@@ -132,7 +132,7 @@ asset::SAssetBundle CSerializedLoader::loadAsset(system::IFile* _file, const ass
132132
stream.zalloc = (alloc_func)0;
133133
stream.zfree = (free_func)0;
134134

135-
int32_t err = inflateInit2(&stream, -MAX_WBITS);
135+
int32_t err = inflateInit(&stream);
136136
if (err == Z_OK)
137137
{
138138
while (err == Z_OK && err != Z_STREAM_END)
@@ -226,9 +226,9 @@ asset::SAssetBundle CSerializedLoader::loadAsset(system::IFile* _file, const ass
226226
auto geo = make_smart_refctd_ptr<ICPUPolygonGeometry>();
227227
geo->setIndexing(IPolygonGeometryBase::TriangleList());
228228

229+
// overall cannot adopt memory because `decompressed` contains padding and other attributes we don't adopt
229230
{
230-
const auto alignment = 0x1ull<<hlsl::findLSB(ptrdiff_t(ptr));
231-
auto view = createView<true>(sourceIsDoubles ? EF_R64G64B64_SFLOAT:EF_R32G32B32_SFLOAT,vertexCount,ptr,smart_refctd_ptr(decompressedResource),alignment);
231+
auto view = createView(sourceIsDoubles ? EF_R64G64B64_SFLOAT:EF_R32G32B32_SFLOAT,vertexCount,ptr);
232232
ptr += view.src.actualSize();
233233
geo->setPositionView(std::move(view));
234234
}
@@ -278,8 +278,7 @@ asset::SAssetBundle CSerializedLoader::loadAsset(system::IFile* _file, const ass
278278
}
279279

280280
{
281-
const auto alignment = 0x1ull<<hlsl::findLSB(ptrdiff_t(ptr));
282-
auto view = createView<true>(EF_R32_UINT,triangleCount*3,ptr,smart_refctd_ptr(decompressedResource),alignment);
281+
auto view = createView(EF_R32_UINT,triangleCount*3,ptr);
283282
ptr += view.src.actualSize();
284283
geo->setIndexView(std::move(view));
285284
}

0 commit comments

Comments
 (0)