KhronosGroup / Vulkan-Samples

One stop solution for all Vulkan samples
Apache License 2.0
4.34k stars 648 forks source link

Move vkb::filesystem to components #894

Closed tomadamatkinson closed 8 months ago

tomadamatkinson commented 9 months ago

Description

Simplifies our filesystem implementation by using std::filesystem underneath. This is the filesystem used in #846 which can be easily used in different executables to perform small tasks (See shader_reflector and variant_reflector. Moved to components and can be used using vkb__filesystem. Filesystem is influenced by the decisions made on the framework/2.0 branch

The existing "legacy" api is kept to maintain compatibility with samples. In the future asset loaders may choose to use the filesystem directly with vkb::filesystem::get()

Merging this will help simplify the review on #846

Tested on MacOS (M1), Linux (Ubuntu 22.04), Windows (11) and Android (Pixel 3). Samples work as expected

General Checklist:

Please ensure the following points are checked:

Sample Checklist

If your PR contains a new or modified sample, these further checks must be carried out in addition to the General Checklist:

gary-sweet commented 9 months ago

I'm seeing a couple of build problems. The first is a redefinition of LOGE:

[100%] Building CXX object app/CMakeFiles/vulkan_samples.dir/main.cpp.o
In file included from Vulkan-Samples/components/filesystem/include/filesystem/filesystem.hpp:26,
                 from Vulkan-Samples/app/main.cpp:23:
Vulkan-Samples/components/core/include/core/util/logging.hpp:28: warning: "LOGE" redefined
   28 | #define LOGE(...) spdlog::error("{}", fmt::format(__VA_ARGS__));
      | 
In file included from Vulkan-Samples/app/main.cpp:18:
Vulkan-Samples/framework/common/logging.h:35: note: this is the location of the previous definition
   35 | #define LOGE(...) spdlog::error("[{}:{}] {}", __FILENAME__, __LINE__, fmt::format(__VA_ARGS__));
gary-sweet commented 9 months ago

The second issue is that std::filesystem isn't available before gcc8 unless you explicitly include stdc++fs as a link library.

We've had to work around that a number of times using something like:

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
   target_link_libraries(${TGT} PRIVATE stdc++fs)
endif()
tomadamatkinson commented 8 months ago

I'm seeing a couple of build problems. The first is a redefinition of LOGE:

[100%] Building CXX object app/CMakeFiles/vulkan_samples.dir/main.cpp.o
In file included from Vulkan-Samples/components/filesystem/include/filesystem/filesystem.hpp:26,
                 from Vulkan-Samples/app/main.cpp:23:
Vulkan-Samples/components/core/include/core/util/logging.hpp:28: warning: "LOGE" redefined
   28 | #define LOGE(...) spdlog::error("{}", fmt::format(__VA_ARGS__));
      | 
In file included from Vulkan-Samples/app/main.cpp:18:
Vulkan-Samples/framework/common/logging.h:35: note: this is the location of the previous definition
   35 | #define LOGE(...) spdlog::error("[{}:{}] {}", __FILENAME__, __LINE__, fmt::format(__VA_ARGS__));

Due to a conflict with logging.h and logging.hpp I will remove the original version in favour of the one that is ported to the components folders

tomadamatkinson commented 8 months ago

Thanks all for taking the time to review! Branch is updated