Skip to content

Commit

Permalink
obj.cpp: don't use memory-mapped I/O on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
wjakob committed Nov 21, 2022
1 parent 56ea910 commit 28660f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ext/drjit
Submodule drjit updated 1 files
+2 −2 include/drjit/loop.h
28 changes: 21 additions & 7 deletions src/shapes/obj.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <mitsuba/render/mesh.h>
#include <mitsuba/core/fresolver.h>
#include <mitsuba/core/fstream.h>
#include <mitsuba/core/properties.h>
#include <mitsuba/core/mmap.h>
#include <mitsuba/core/util.h>
Expand All @@ -8,6 +9,7 @@

#include <array>


NAMESPACE_BEGIN(mitsuba)

/**!
Expand Down Expand Up @@ -148,8 +150,8 @@ class OBJMesh final : public Mesh<Float, Spectrum> {
Enabled by default, for consistence with the Mitsuba 1 behavior. */
bool flip_tex_coords = props.get<bool>("flip_tex_coords", true);

auto fs = Thread::thread()->file_resolver();
fs::path file_path = fs->resolve(props.string("filename"));
auto fr = Thread::thread()->file_resolver();
fs::path file_path = fr->resolve(props.string("filename"));
m_name = file_path.filename().string();


Expand All @@ -162,7 +164,6 @@ class OBJMesh final : public Mesh<Float, Spectrum> {
if (!fs::exists(file_path))
fail("file not found");

ref<MemoryMappedFile> mmap = new MemoryMappedFile(file_path);
ScopedPhase phase(ProfilerPhase::LoadGeometry);

using ScalarIndex3 = std::array<ScalarIndex, 3>;
Expand All @@ -180,7 +181,23 @@ class OBJMesh final : public Mesh<Float, Spectrum> {
std::vector<ScalarIndex3> triangles;
std::vector<VertexBinding> vertex_map;

size_t vertex_guess = mmap->size() / 100;
#if !defined(_WIN32)
ref<MemoryMappedFile> mmap = new MemoryMappedFile(file_path);
size_t file_size = mmap->size();
const char *ptr = (const char *) mmap->data();
#else
// Memory-mapped IO performs surprisingly poorly on Windows
ref<FileStream> fs = new FileStream(file_path);
size_t file_size = fs->size();
std::unique_ptr<char[]> tmp(new char[file_size]);
fs->read(tmp.get(), file_size);
const char *ptr = tmp.get();
#endif

size_t vertex_guess = file_size / 100;
const char *eof = ptr + file_size;
char buf[1025];

vertices.reserve(vertex_guess);
normals.reserve(vertex_guess);
texcoords.reserve(vertex_guess);
Expand All @@ -189,9 +206,6 @@ class OBJMesh final : public Mesh<Float, Spectrum> {

ScalarIndex vertex_ctr = 0;

const char *ptr = (const char *) mmap->data();
const char *eof = ptr + mmap->size();
char buf[1025];
Timer timer;

while (ptr < eof) {
Expand Down

0 comments on commit 28660f3

Please sign in to comment.