Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: Use simdjson's ondemand API #5

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ if (SIMDJSON_TARGET_VERSION)
target_compile_definitions(fastgltf PRIVATE SIMDJSON_TARGET_VERSION="${SIMDJSON_TARGET_VERSION}")
endif()

if (SIMDJSON_VERBOSE_LOGGING)
target_compile_definitions(fastgltf PUBLIC SIMDJSON_VERBOSE_LOGGING=1)
endif()

target_compile_definitions(fastgltf PUBLIC "FASTGLTF_USE_CUSTOM_SMALLVECTOR=$<BOOL:${FASTGLTF_USE_CUSTOM_SMALLVECTOR}>")
target_compile_definitions(fastgltf PUBLIC "FASTGLTF_ENABLE_DEPRECATED_EXT=$<BOOL:${FASTGLTF_ENABLE_DEPRECATED_EXT}>")
target_compile_definitions(fastgltf PUBLIC "FASTGLTF_DISABLE_CUSTOM_MEMORY_POOL=$<BOOL:${FASTGLTF_DISABLE_CUSTOM_MEMORY_POOL}>")
Expand Down
38 changes: 20 additions & 18 deletions include/fastgltf/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
struct AAssetManager;
#endif

#include <simdjson.h>
namespace simdjson::dom {
class array;
class object;
Expand Down Expand Up @@ -688,7 +689,7 @@ namespace fastgltf {
class Parser {
// The simdjson parser object. We want to share it between runs, so it does not need to
// reallocate over and over again. We're hiding it here to not leak the simdjson header.
std::unique_ptr<simdjson::dom::parser> jsonParser;
std::unique_ptr<simdjson::ondemand::parser> jsonParser;

ParserInternalConfig config = {};
DataSource glbBuffer;
Expand All @@ -706,23 +707,24 @@ namespace fastgltf {

Error generateMeshIndices(Asset& asset) const;

Error parseAccessors(simdjson::dom::array& array, Asset& asset);
Error parseAnimations(simdjson::dom::array& array, Asset& asset);
Error parseBuffers(simdjson::dom::array& array, Asset& asset);
Error parseBufferViews(simdjson::dom::array& array, Asset& asset);
Error parseCameras(simdjson::dom::array& array, Asset& asset);
Error parseExtensions(simdjson::dom::object& extensionsObject, Asset& asset);
Error parseImages(simdjson::dom::array& array, Asset& asset);
Error parseLights(simdjson::dom::array& array, Asset& asset);
Error parseMaterialExtensions(simdjson::dom::object& object, Material& material);
Error parseMaterials(simdjson::dom::array& array, Asset& asset);
Error parseMeshes(simdjson::dom::array& array, Asset& asset);
Error parseNodes(simdjson::dom::array& array, Asset& asset);
Error parseSamplers(simdjson::dom::array& array, Asset& asset);
Error parseScenes(simdjson::dom::array& array, Asset& asset);
Error parseSkins(simdjson::dom::array& array, Asset& asset);
Error parseTextures(simdjson::dom::array& array, Asset& asset);
Expected<Asset> parse(simdjson::dom::object root, Category categories);
Error parseAccessors(simdjson::ondemand::array& array, Asset& asset);
Error parseAnimations(simdjson::ondemand::array& array, Asset& asset);
Error parseBuffers(simdjson::ondemand::array& array, Asset& asset);
Error parseBufferViews(simdjson::ondemand::array& array, Asset& asset);
Error parseCameras(simdjson::ondemand::array& array, Asset& asset);
Error parseExtensions(simdjson::ondemand::object& extensionsObject, Asset& asset);
Error parseImages(simdjson::ondemand::array& array, Asset& asset);
Error parseLights(simdjson::ondemand::array& array, Asset& asset);
Error parseMaterialExtensions(simdjson::ondemand::object& object, Material& material);
Error parseMaterials(simdjson::ondemand::array& array, Asset& asset);
Error parseMeshPrimitives(simdjson::ondemand::array& array, Asset& asset, Mesh& mesh);
Error parseMeshes(simdjson::ondemand::array& array, Asset& asset);
Error parseNodes(simdjson::ondemand::array& array, Asset& asset);
Error parseSamplers(simdjson::ondemand::array& array, Asset& asset);
Error parseScenes(simdjson::ondemand::array& array, Asset& asset);
Error parseSkins(simdjson::ondemand::array& array, Asset& asset);
Error parseTextures(simdjson::ondemand::array& array, Asset& asset);
Expected<Asset> parse(simdjson::ondemand::object root, Category categories);

public:
explicit Parser(Extensions extensionsToLoad = Extensions::None) noexcept;
Expand Down
30 changes: 3 additions & 27 deletions include/fastgltf/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ namespace fastgltf {
}

template <typename U = T, std::enable_if_t<std::is_copy_constructible_v<T>, int> = 0>
OptionalWithFlagValue(const OptionalWithFlagValue<U>& other) {
OptionalWithFlagValue(const OptionalWithFlagValue<U>& other) noexcept(std::is_nothrow_copy_constructible_v<T>) {
if (other.has_value()) {
new (std::addressof(_value)) T(*other);
} else {
Expand All @@ -1014,7 +1014,7 @@ namespace fastgltf {
}

template <typename U = T, std::enable_if_t<std::is_move_constructible_v<T>, int> = 0>
OptionalWithFlagValue(OptionalWithFlagValue<U>&& other) {
OptionalWithFlagValue(OptionalWithFlagValue<U>&& other) noexcept(std::is_nothrow_move_constructible_v<T>) {
if (other.has_value()) {
new (std::addressof(_value)) T(std::move(*other));
} else {
Expand Down Expand Up @@ -2055,31 +2055,7 @@ namespace fastgltf {
availableCategories(other.availableCategories) {}

Asset& operator=(const Asset& other) = delete;
Asset& operator=(Asset&& other) noexcept {
#if !FASTGLTF_DISABLE_CUSTOM_MEMORY_POOL
memoryResource = std::move(other.memoryResource);
#endif
assetInfo = std::move(other.assetInfo);
extensionsUsed = std::move(other.extensionsUsed);
extensionsRequired = std::move(other.extensionsRequired);
defaultScene = other.defaultScene;
accessors = std::move(other.accessors);
animations = std::move(other.animations);
buffers = std::move(other.buffers);
bufferViews = std::move(other.bufferViews);
cameras = std::move(other.cameras);
images = std::move(other.images);
lights = std::move(other.lights);
materials = std::move(other.materials);
meshes = std::move(other.meshes);
nodes = std::move(other.nodes);
samplers = std::move(other.samplers);
scenes = std::move(other.scenes);
skins = std::move(other.skins);
textures = std::move(other.textures);
availableCategories = other.availableCategories;
return *this;
}
Asset& operator=(Asset&& other) noexcept = delete;
};
#pragma endregion
} // namespace fastgltf
Expand Down
Loading
Loading