Compare commits
43
Commits
e4b2638b08
..
Vulkan
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2fcb2fd64c | ||
|
|
df985d0397 | ||
|
|
130ea26f4f | ||
|
|
1799ff01c4 | ||
|
|
3cde56717f | ||
|
|
cd5f7b3823 | ||
|
|
e1e16268a2 | ||
|
|
c4e9f6f7d9 | ||
|
|
6ee035843e | ||
|
|
3c19e0e931 | ||
|
|
fc2f947557 | ||
|
|
2cce2e40e6 | ||
|
|
22e16561dc | ||
|
|
8d86fe007e | ||
|
|
087114b21b | ||
|
|
5703e25773 | ||
|
|
71dfb57179 | ||
|
|
d8b7698d4b | ||
|
|
e27d69b36e | ||
|
|
7f3b46867f | ||
|
|
fcf9bfa19e | ||
|
|
6895daa676 | ||
|
|
246ea70e93 | ||
|
|
7e6c2b62f3 | ||
|
|
2e512ad556 | ||
|
|
db0b5da1f3 | ||
|
|
aef49e7f11 | ||
|
|
10f4a09c37 | ||
|
|
0c3974cdec | ||
|
|
2303fe6182 | ||
|
|
23f623d9de | ||
|
|
16d5d0fffb | ||
|
|
f82d40532c | ||
|
|
310d16b9ed | ||
|
|
9f034fed3c | ||
|
|
33a79ed12f | ||
|
|
c4467ea2f2 | ||
|
|
8c9f78dbc7 | ||
|
|
1558a19f19 | ||
|
|
3a5dd1affe | ||
|
|
dc534acdd5 | ||
|
|
9fd1cd0d68 | ||
|
|
b7f4677c68 |
+52
-16
@@ -121,36 +121,72 @@ SpaceInEmptyBlock: true
|
||||
PenaltyBreakAssignment: 200
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
IncludeCategories:
|
||||
- Regex: '^<Engine/'
|
||||
- Regex: '^<GraphicsCore/.*_generated\.h(pp)?>$'
|
||||
Priority: 16
|
||||
- Regex: '^<GraphicsVulkan/.*_generated\.h(pp)?>$'
|
||||
Priority: 17
|
||||
- Regex: '^<GraphicsInterface/.*_generated\.h(pp)?>$'
|
||||
Priority: 18
|
||||
- Regex: '^<Engine/.*_generated\.h(pp)?>$'
|
||||
Priority: 19
|
||||
- Regex: '^<System/.*_generated\.h(pp)?>$'
|
||||
Priority: 20
|
||||
- Regex: '^<Utils/.*_generated\.h(pp)?>$'
|
||||
Priority: 21
|
||||
- Regex: '^<SasquatchBaker/.*_generated\.h(pp)?>$'
|
||||
Priority: 22
|
||||
- Regex: '^<EngineTests/.*_generated\.h(pp)?>$'
|
||||
Priority: 23
|
||||
- Regex: '^<SystemTests/.*_generated\.h(pp)?>$'
|
||||
Priority: 24
|
||||
- Regex: '^<UtilsTests/.*_generated\.h(pp)?>$'
|
||||
Priority: 25
|
||||
- Regex: '^<AssetsForTesting/.*_generated\.h(pp)?>$'
|
||||
Priority: 26
|
||||
- Regex: '^<SasquatchBakerTests/.*_generated\.h(pp)?>$'
|
||||
Priority: 27
|
||||
- Regex: '^<EngineBenchmarks/.*_generated\.h(pp)?>$'
|
||||
Priority: 28
|
||||
- Regex: '^<AssetsForBenchmarking/.*_generated\.h(pp)?>$'
|
||||
Priority: 29
|
||||
- Regex: '^<SasquatchBakerBenchmarks/.*_generated\.h(pp)?>$'
|
||||
Priority: 30
|
||||
- Regex: '^<GraphicsCore/'
|
||||
Priority: 1
|
||||
- Regex: '^<System/'
|
||||
- Regex: '^<GraphicsVulkan/'
|
||||
Priority: 2
|
||||
- Regex: '^<Utils/'
|
||||
- Regex: '^<GraphicsInterface/'
|
||||
Priority: 3
|
||||
- Regex: '^<SasquatchBaker/'
|
||||
- Regex: '^<Engine/'
|
||||
Priority: 4
|
||||
- Regex: '^<EngineTests/'
|
||||
- Regex: '^<System/'
|
||||
Priority: 5
|
||||
- Regex: '^<SystemTests/'
|
||||
- Regex: '^<Utils/'
|
||||
Priority: 6
|
||||
- Regex: '^<UtilsTests/'
|
||||
- Regex: '^<SasquatchBaker/'
|
||||
Priority: 7
|
||||
- Regex: '^<AssetsForTesting/'
|
||||
- Regex: '^<EngineTests/'
|
||||
Priority: 8
|
||||
- Regex: '^<SasquatchBakerTests/'
|
||||
- Regex: '^<SystemTests/'
|
||||
Priority: 9
|
||||
- Regex: '^<EngineBenchmarks/'
|
||||
- Regex: '^<UtilsTests/'
|
||||
Priority: 10
|
||||
- Regex: '^<AssetsForBenchmarking/'
|
||||
- Regex: '^<AssetsForTesting/'
|
||||
Priority: 11
|
||||
- Regex: '^<SasquatchBakerBenchmarks/'
|
||||
- Regex: '^<SasquatchBakerTests/'
|
||||
Priority: 12
|
||||
- Regex: '^<[a-zA-Z0-9_/]+\.h>'
|
||||
- Regex: '^<EngineBenchmarks/'
|
||||
Priority: 13
|
||||
- Regex: '^<[a-zA-Z0-9_/]+\.hpp>'
|
||||
Priority: 13
|
||||
- Regex: '^<[a-zA-Z0-9_/]+>'
|
||||
- Regex: '^<AssetsForBenchmarking/'
|
||||
Priority: 14
|
||||
- Regex: '^<SasquatchBakerBenchmarks/'
|
||||
Priority: 15
|
||||
- Regex: '^<[a-zA-Z0-9_/]+\.h>'
|
||||
Priority: 31
|
||||
- Regex: '^<[a-zA-Z0-9_/]+\.hpp>'
|
||||
Priority: 31
|
||||
- Regex: '^<[a-zA-Z0-9_/]+>'
|
||||
Priority: 32
|
||||
MainIncludeChar: AngleBracket
|
||||
Macros:
|
||||
- 'BIGFOOT_OPTIMIZED_ONLY(x)=x'
|
||||
|
||||
+5
-1
@@ -11,9 +11,13 @@ Checks: >
|
||||
portability-*,
|
||||
|
||||
-modernize-use-trailing-return-type,
|
||||
-modernize-use-auto,
|
||||
-readability-avoid-const-params-in-decls,
|
||||
-cppcoreguidelines-macro-usage,
|
||||
-cppcoreguidelines-avoid-do-while
|
||||
-cppcoreguidelines-avoid-do-while,
|
||||
-cppcoreguidelines-pro-bounds-avoid-unchecked-container-access,
|
||||
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||
-cppcoreguidelines-pro-type-reinterpret-cast
|
||||
|
||||
ExcludeHeaderFilterRegex: '_generated.*'
|
||||
|
||||
|
||||
+17
-15
@@ -15,13 +15,16 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
build_type: ["Debug", "RelWithDebInfo", "Release"]
|
||||
build_type:
|
||||
- { value: "Debug", profile: "debug" }
|
||||
- { value: "RelWithDebInfo", profile: "relwithdebinfo" }
|
||||
- { value: "Release", profile: "release" }
|
||||
unity_build: ["ON", "OFF"]
|
||||
conan_profile: ["./ConanProfiles/host/clang", "./ConanProfiles/host/clang_asan"]
|
||||
toolmode:
|
||||
conan_profile: ["clang", "clang_asan"]
|
||||
variant:
|
||||
- { value: "True", name: "toolmode" }
|
||||
- { value: "False", name: "game" }
|
||||
name: "Build & Test ${{ matrix.build_type }} with ${{ matrix.conan_profile }} (Unity Build: ${{ matrix.unity_build }}, Variant: ${{ matrix.toolmode.name }})"
|
||||
name: "Build & Test ${{ matrix.build_type.value }} with ${{ matrix.conan_profile }} (Unity Build: ${{ matrix.unity_build }}, Variant: ${{ matrix.variant.name }})"
|
||||
steps:
|
||||
- name: Install Node.js
|
||||
run: apt-get update && apt-get install -y nodejs
|
||||
@@ -33,18 +36,17 @@ jobs:
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
conan install . --remote=bigfootpackages -pr:h=${{ matrix.conan_profile }} -pr:b=./ConanProfiles/build/clang --build=missing -s build_type=${{ matrix.build_type }} -o bigfoot/*:build_tests=True -o bigfoot/*:build_benchmarks=True -o bigfoot/*:tracy=False -o bigfoot/*:vulkan=True -o bigfoot/*:toolmode=${{ matrix.toolmode.value }} -of build-${{ matrix.toolmode.name }}
|
||||
. ./build-${{ matrix.toolmode.name }}/build/${{ matrix.build_type }}/generators/conanbuild.sh
|
||||
cmake -S . -B ./build-${{ matrix.toolmode.name }}/${{ matrix.build_type }} --toolchain ./build-${{ matrix.toolmode.name }}/build/${{ matrix.build_type }}/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_UNITY_BUILD=${{ matrix.unity_build }} -G "Ninja"
|
||||
cmake --build build-${{ matrix.toolmode.name }}/${{ matrix.build_type }} --parallel $(nproc)
|
||||
. ./build-${{ matrix.toolmode.name }}/build/${{ matrix.build_type }}/generators/deactivate_conanbuild.sh
|
||||
bash ./generate_bigfoot.sh missing ${{ matrix.build_type.value }} --profile=${{ matrix.conan_profile }} --variant=${{ matrix.variant.name }} --unity=${{ matrix.unity_build }} --tracy=False
|
||||
. ./build-linux-${{ matrix.variant.name }}/build/${{ matrix.build_type.value }}/generators/conanbuild.sh
|
||||
cmake --build build-linux-${{ matrix.variant.name }}/${{ matrix.build_type.value }} --parallel $(nproc)
|
||||
. ./build-linux-${{ matrix.variant.name }}/build/${{ matrix.build_type.value }}/generators/deactivate_conanbuild.sh
|
||||
|
||||
- name: Unit Tests
|
||||
run: |
|
||||
cd ./build-${{ matrix.toolmode.name }}/${{ matrix.build_type }}
|
||||
. ../../build-${{ matrix.toolmode.name }}/build/${{ matrix.build_type }}/generators/conanbuild.sh
|
||||
xvfb-run ctest . --output-on-failure
|
||||
. ../../build-${{ matrix.toolmode.name }}/build/${{ matrix.build_type }}/generators/deactivate_conanbuild.sh
|
||||
cd ./build-linux-${{ matrix.variant.name }}/${{ matrix.build_type.value }}
|
||||
. ../../build-linux-${{ matrix.variant.name }}/build/${{ matrix.build_type.value }}/generators/conanbuild.sh
|
||||
weston-run ctest . --output-on-failure
|
||||
. ../../build-linux-${{ matrix.variant.name }}/build/${{ matrix.build_type.value }}/generators/deactivate_conanbuild.sh
|
||||
|
||||
clang-format:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -60,6 +62,6 @@ jobs:
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
|
||||
- name: Clang Format Checks
|
||||
run: chmod +x format.sh && ./format.sh --check Bigfoot
|
||||
run: chmod +x format.sh && ./format.sh --check Bigfoot
|
||||
|
||||
@@ -5,6 +5,10 @@ on:
|
||||
branches:
|
||||
- main
|
||||
- Development
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- Development
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
@@ -13,7 +17,14 @@ jobs:
|
||||
container:
|
||||
image: git.romainboullard.com/bigfootdev/linuxcppbuilder:development
|
||||
|
||||
name: "Sonarqube"
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
variant:
|
||||
- { value: "True", name: "toolmode", projectKey: "Bigfoot-Tool", projectName: "Bigfoot Tool" }
|
||||
- { value: "False", name: "game", projectKey: "Bigfoot-Game", projectName: "Bigfoot Game" }
|
||||
|
||||
name: "Sonarqube (${{ matrix.variant.name }})"
|
||||
steps:
|
||||
- name: Install Node.js
|
||||
run: apt-get update && apt-get install -y nodejs
|
||||
@@ -23,28 +34,63 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: recursive
|
||||
ref: ${{ github.event.pull_request.head.sha || github.sha }}
|
||||
|
||||
- name: Read version
|
||||
id: version
|
||||
run: echo "version=$(cat VERSION)" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
conan install . --remote=bigfootpackages -pr:h=./ConanProfiles/host/clang_coverage -pr:b=./ConanProfiles/build/clang --build=missing -s build_type=Debug -o bigfoot/*:build_tests=True -o bigfoot/*:build_benchmarks=True -o bigfoot/*:tracy=False -o bigfoot/*:build_tools=True -o bigfoot/*:vulkan=True
|
||||
. ./build/Debug/generators/conanbuild.sh
|
||||
cmake -S . -B ./build/Debug --toolchain ./build/Debug/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug -G "Ninja"
|
||||
cmake --build build/Debug --parallel $(nproc)
|
||||
. ./build/Debug/generators/deactivate_conanbuild.sh
|
||||
bash ./generate_bigfoot.sh missing Debug --profile=clang_coverage --variant=${{ matrix.variant.name }} --tracy=False
|
||||
. ./build-linux-${{ matrix.variant.name }}/build/Debug/generators/conanbuild.sh
|
||||
cmake --build build-linux-${{ matrix.variant.name }}/Debug --parallel $(nproc)
|
||||
. ./build-linux-${{ matrix.variant.name }}/build/Debug/generators/deactivate_conanbuild.sh
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
cd ./build-linux-${{ matrix.variant.name }}/Debug
|
||||
. ../../build-linux-${{ matrix.variant.name }}/build/Debug/generators/conanbuild.sh
|
||||
LLVM_PROFILE_FILE="%p.profraw%c" weston-run ctest --output-on-failure
|
||||
. ../../build-linux-${{ matrix.variant.name }}/build/Debug/generators/deactivate_conanbuild.sh
|
||||
|
||||
- name: Clang-Tidy
|
||||
run: run-clang-tidy -p ./build/Debug/ >> tidy_result.txt
|
||||
run: run-clang-tidy -p ./build-linux-${{ matrix.variant.name }}/Debug/ > tidy_result.txt
|
||||
|
||||
- name: Infer
|
||||
run: infer run --compilation-database build/Debug/compile_commands.json
|
||||
run: infer run --compilation-database build-linux-${{ matrix.variant.name }}/Debug/compile_commands.json
|
||||
|
||||
- name: Generate coverage report
|
||||
shell: bash
|
||||
run: |
|
||||
# gcovr's own LLVM-JSON reader only understands coverage-mapping format
|
||||
# 2.x; this image's clang 22 llvm-cov emits format 3.x, which gcovr
|
||||
# rejects outright ("Wrong major version"). Bypassing gcovr's JSON
|
||||
# path entirely: llvm-cov's lcov exporter is a separate, unaffected
|
||||
# code path, so merge -> export lcov -> convert lcov to Cobertura.
|
||||
llvm-profdata merge -sparse $(find build-linux-${{ matrix.variant.name }}/Debug -name "*.profraw") -o merged.profdata
|
||||
BINARIES=($(find build-linux-${{ matrix.variant.name }}/Debug -maxdepth 8 -type f -executable -iname "*Tests"))
|
||||
OBJECT_ARGS=$(printf -- '-object %s ' "${BINARIES[@]:1}")
|
||||
llvm-cov export -format=lcov -instr-profile=merged.profdata "${BINARIES[0]}" $OBJECT_ARGS > coverage.lcov
|
||||
# lcov_cobertura isn't preinstalled on the image; inject it into
|
||||
# gcovr's existing pipx venv and expose its CLI on PATH.
|
||||
pipx inject gcovr lcov_cobertura --include-apps
|
||||
lcov_cobertura coverage.lcov -b . -o coverage.xml
|
||||
|
||||
- name: SonarQube Scan
|
||||
if: github.head_ref == 'main' || github.ref_name == 'main'
|
||||
uses: SonarSource/sonarqube-scan-action@v7.0.0
|
||||
with:
|
||||
args: >
|
||||
-Dsonar.cxx.jsonCompilationDatabase=./build/Debug/compile_commands.json
|
||||
-Dsonar.verbose=true
|
||||
-Dsonar.projectKey=${{ matrix.variant.projectKey }}
|
||||
"-Dsonar.projectName=${{ matrix.variant.projectName }}"
|
||||
-Dsonar.projectVersion=${{ steps.version.outputs.version }}
|
||||
-Dsonar.cxx.jsonCompilationDatabase=./build-linux-${{ matrix.variant.name }}/Debug/compile_commands.json
|
||||
-Dsonar.cxx.xunit.reportPaths=build-linux-${{ matrix.variant.name }}/Debug/TestResults/*.xml
|
||||
-Dsonar.qualitygate.wait=true
|
||||
${{ github.event_name == 'pull_request' &&
|
||||
format('-Dsonar.pullrequest.key={0} -Dsonar.pullrequest.branch={1} -Dsonar.pullrequest.base={2} -Dsonar.analysis.sqbot={3}',
|
||||
github.event.pull_request.number, github.head_ref, github.base_ref, github.event.pull_request.head.sha)
|
||||
|| format('-Dsonar.branch.name={0}', github.ref_name) }}
|
||||
env:
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
SONAR_HOST_URL: ${{ secrets.SONAR_HOST }}
|
||||
SONAR_HOST_URL: ${{ secrets.SONAR_HOST }}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
InheritParentConfig: true
|
||||
Checks: >
|
||||
-cppcoreguidelines-non-private-member-variables-in-classes,
|
||||
-cppcoreguidelines-avoid-magic-numbers,
|
||||
-readability-magic-numbers
|
||||
@@ -12,6 +12,4 @@ bigfoot_create_package_lib(
|
||||
"${PrivateDependencies}"
|
||||
"${BigfootPublicDependencies}"
|
||||
"${BigfootPrivateDependencies}"
|
||||
"")
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Benchmarks/Bigfoot)
|
||||
"Bigfoot/Benchmarks")
|
||||
|
||||
@@ -2,6 +2,4 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/AssetsForBenchmarking)
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Engine)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Utils)
|
||||
if(${TOOLMODE})
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Tools)
|
||||
endif()
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Graphics)
|
||||
|
||||
@@ -30,13 +30,13 @@ class ReferenceFixture: public benchmark::Fixture
|
||||
SetActiveAssetLibrary(&m_library);
|
||||
std::ignore = m_library.Insert(&m_container);
|
||||
|
||||
m_uuid = m_container.Insert()->GetAsset()->GetHeader().uuid;
|
||||
m_uuid = CreateAsset<BenchmarkAsset>()->GetHeader().uuid;
|
||||
m_reference.emplace(m_uuid);
|
||||
}
|
||||
|
||||
void TearDown(benchmark::State&) override
|
||||
{
|
||||
SetActiveAssetLibrary(&g_assetLibrary);
|
||||
SetActiveAssetLibrary(g_assetLibrary);
|
||||
}
|
||||
|
||||
AssetLibrary m_library;
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
#include <System/File/File.hpp>
|
||||
#include <System/UUID/UUID.hpp>
|
||||
|
||||
#include <EngineBenchmarks/BigFileInfo_generated.hpp>
|
||||
|
||||
#include <AssetsForBenchmarking/Asset/BenchmarkAsset.hpp>
|
||||
#include <AssetsForBenchmarking/Asset/BenchmarkAssetReferred.hpp>
|
||||
|
||||
#include <EngineBenchmarks/BigFileInfo_generated.hpp>
|
||||
|
||||
#include <EASTL/optional.h>
|
||||
#include <EASTL/span.h>
|
||||
#include <EASTL/vector.h>
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <effolkronium/random.hpp>
|
||||
@@ -30,40 +32,22 @@ class BigFileFixture: public benchmark::Fixture
|
||||
{
|
||||
protected:
|
||||
static constexpr std::uint32_t ASSET_COUNT = 20'000;
|
||||
static constexpr std::uint32_t REFS_PER_ASSET = 4;
|
||||
static constexpr std::size_t ASSET_PAYLOAD_SIZE = 256;
|
||||
|
||||
void SetUp(benchmark::State&) override
|
||||
void SetUp([[maybe_unused]] benchmark::State& p_state) override
|
||||
{
|
||||
m_bigFile.Clear();
|
||||
// The DB is populated exactly once for the entire benchmark process.
|
||||
// SetUp is called before every calibration round (Google Benchmark doubles
|
||||
// iteration counts until it reaches a stable measurement), so rebuilding
|
||||
// the DB each time would dominate the total benchmark time.
|
||||
m_uuids = BuildData();
|
||||
m_bigFile.emplace(File {BIGFILE_ENGINEBENCHMARKS_LOCATION});
|
||||
}
|
||||
|
||||
m_uuids.clear();
|
||||
m_uuids.reserve(ASSET_COUNT);
|
||||
|
||||
eastl::vector<eastl::vector<std::byte>> flatbuffers;
|
||||
eastl::vector<eastl::vector<UUID>> hardReferences;
|
||||
flatbuffers.reserve(ASSET_COUNT);
|
||||
hardReferences.reserve(ASSET_COUNT);
|
||||
|
||||
for (std::uint32_t i = 0; i < ASSET_COUNT; ++i)
|
||||
{
|
||||
BenchmarkAsset asset;
|
||||
asset.SetName(asset.GetHeader().uuid.ToString().c_str());
|
||||
asset.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB});
|
||||
for (std::uint32_t j = 0; j < 4; ++j)
|
||||
{
|
||||
BenchmarkAssetReferred assetReferred;
|
||||
assetReferred.SetName(assetReferred.GetHeader().uuid.ToString().c_str());
|
||||
|
||||
asset.GetAsset().refs.emplace_back(assetReferred.GetHeader().uuid);
|
||||
}
|
||||
|
||||
const eastl::vector<std::byte> flatbuffer = asset.Pack();
|
||||
flatbuffers.push_back(flatbuffer);
|
||||
hardReferences.push_back(asset.GetHardReferences(flatbuffer));
|
||||
m_uuids.push_back(asset.GetHeader().uuid);
|
||||
}
|
||||
|
||||
m_bigFile.SaveAssetFlatbuffers(m_uuids, flatbuffers, hardReferences);
|
||||
void TearDown([[maybe_unused]] benchmark::State& p_state) override
|
||||
{
|
||||
m_bigFile.reset();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
@@ -93,8 +77,49 @@ class BigFileFixture: public benchmark::Fixture
|
||||
return pool;
|
||||
}
|
||||
|
||||
BigFile m_bigFile {File {BIGFILE_ENGINEBENCHMARKS_LOCATION}};
|
||||
eastl::vector<UUID> m_uuids;
|
||||
eastl::optional<BigFile> m_bigFile;
|
||||
eastl::span<const UUID> m_uuids;
|
||||
|
||||
private:
|
||||
static const eastl::vector<UUID>& BuildData()
|
||||
{
|
||||
static const eastl::vector<UUID> s_uuids = []()
|
||||
{
|
||||
eastl::vector<UUID> uuids;
|
||||
eastl::vector<eastl::vector<std::byte>> flatbuffers;
|
||||
eastl::vector<eastl::vector<UUID>> hardReferences;
|
||||
uuids.reserve(ASSET_COUNT);
|
||||
flatbuffers.reserve(ASSET_COUNT);
|
||||
hardReferences.reserve(ASSET_COUNT);
|
||||
|
||||
for (std::uint32_t i = 0; i < ASSET_COUNT; ++i)
|
||||
{
|
||||
BenchmarkAsset asset;
|
||||
asset.SetName(asset.GetHeader().uuid.ToString());
|
||||
asset.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB});
|
||||
for (std::uint32_t j = 0; j < REFS_PER_ASSET; ++j)
|
||||
{
|
||||
BenchmarkAssetReferred assetReferred;
|
||||
assetReferred.SetName(assetReferred.GetHeader().uuid.ToString());
|
||||
|
||||
asset.GetAsset().refs.emplace_back(assetReferred.GetHeader().uuid);
|
||||
}
|
||||
|
||||
eastl::vector<std::byte> flatbuffer = asset.Pack();
|
||||
hardReferences.push_back(asset.GetHardReferences(flatbuffer));
|
||||
flatbuffers.push_back(std::move(flatbuffer));
|
||||
uuids.push_back(asset.GetHeader().uuid);
|
||||
}
|
||||
|
||||
BigFile bigFile {File {BIGFILE_ENGINEBENCHMARKS_LOCATION}};
|
||||
bigFile.Clear();
|
||||
bigFile.SaveAssetFlatbuffers(uuids, flatbuffers, hardReferences);
|
||||
|
||||
return uuids;
|
||||
}();
|
||||
|
||||
return s_uuids;
|
||||
}
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
@@ -105,7 +130,7 @@ BENCHMARK_DEFINE_F(BigFileFixture, GetAssetFlatbuffer)(benchmark::State& state)
|
||||
|
||||
for (auto _: state)
|
||||
{
|
||||
eastl::vector<std::byte> flatbuffer = m_bigFile.GetAssetFlatbuffer(
|
||||
eastl::vector<std::byte> flatbuffer = m_bigFile->GetAssetFlatbuffer(
|
||||
m_uuids[Random::get<std::size_t>(0, m_uuids.size() - 1)]);
|
||||
benchmark::DoNotOptimize(flatbuffer);
|
||||
|
||||
@@ -116,7 +141,7 @@ BENCHMARK_DEFINE_F(BigFileFixture, GetAssetFlatbuffer)(benchmark::State& state)
|
||||
state.SetBytesProcessed(bytesProcessed);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(BigFileFixture, GetAssetFlatbuffer)->Name("BigFile/GetAssetFlatbuffer");
|
||||
BENCHMARK_REGISTER_F(BigFileFixture, GetAssetFlatbuffer)->Name("BigFile/GetAssetFlatbuffer")->UseRealTime();
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
@@ -132,7 +157,7 @@ BENCHMARK_DEFINE_F(BigFileFixture, GetAssetFlatbuffers)(benchmark::State& state)
|
||||
|
||||
for (auto _: state)
|
||||
{
|
||||
eastl::vector<eastl::vector<std::byte>> flatbuffers = m_bigFile.GetAssetFlatbuffers(batchPool[batchIndex]);
|
||||
eastl::vector<eastl::vector<std::byte>> flatbuffers = m_bigFile->GetAssetFlatbuffers(batchPool[batchIndex]);
|
||||
benchmark::DoNotOptimize(flatbuffers);
|
||||
|
||||
for (const eastl::vector<std::byte>& flatbuffer: flatbuffers)
|
||||
@@ -153,7 +178,8 @@ BENCHMARK_REGISTER_F(BigFileFixture, GetAssetFlatbuffers)
|
||||
->Arg(8)
|
||||
->Arg(64)
|
||||
->Arg(512)
|
||||
->Arg(4096);
|
||||
->Arg(4096)
|
||||
->UseRealTime();
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
@@ -162,13 +188,14 @@ BENCHMARK_DEFINE_F(BigFileFixture, GetAssetHardReferences)(benchmark::State& sta
|
||||
for (auto _: state)
|
||||
{
|
||||
benchmark::DoNotOptimize(
|
||||
m_bigFile.GetAssetHardReferences(m_uuids[Random::get<std::size_t>(0, m_uuids.size() - 1)]));
|
||||
m_bigFile->GetAssetHardReferences(m_uuids[Random::get<std::size_t>(0, m_uuids.size() - 1)]));
|
||||
}
|
||||
|
||||
state.SetItemsProcessed(state.iterations());
|
||||
state.SetBytesProcessed(static_cast<std::int64_t>(state.iterations()) * REFS_PER_ASSET * UUID::UUID_BYTE_SIZE);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(BigFileFixture, GetAssetHardReferences)->Name("BigFile/GetAssetHardReferences");
|
||||
BENCHMARK_REGISTER_F(BigFileFixture, GetAssetHardReferences)->Name("BigFile/GetAssetHardReferences")->UseRealTime();
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
@@ -182,11 +209,13 @@ BENCHMARK_DEFINE_F(BigFileFixture, GetAssetsHardReferences)(benchmark::State& st
|
||||
std::size_t batchIndex = 0;
|
||||
for (auto _: state)
|
||||
{
|
||||
benchmark::DoNotOptimize(m_bigFile.GetAssetsHardReferences(batchPool[batchIndex]));
|
||||
benchmark::DoNotOptimize(m_bigFile->GetAssetsHardReferences(batchPool[batchIndex]));
|
||||
batchIndex = (batchIndex + 1) % BATCH_POOL_SIZE;
|
||||
}
|
||||
|
||||
state.SetItemsProcessed(state.iterations() * batchSize);
|
||||
state.SetBytesProcessed(static_cast<std::int64_t>(state.iterations()) * batchSize * REFS_PER_ASSET *
|
||||
UUID::UUID_BYTE_SIZE);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(BigFileFixture, GetAssetsHardReferences)
|
||||
@@ -195,7 +224,8 @@ BENCHMARK_REGISTER_F(BigFileFixture, GetAssetsHardReferences)
|
||||
->Arg(8)
|
||||
->Arg(64)
|
||||
->Arg(512)
|
||||
->Arg(4096);
|
||||
->Arg(4096)
|
||||
->UseRealTime();
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
@@ -207,22 +237,26 @@ BENCHMARK_DEFINE_F(BigFileFixture, SaveAssetFlatbuffer)(benchmark::State& state)
|
||||
{
|
||||
state.PauseTiming();
|
||||
BenchmarkAsset asset;
|
||||
asset.SetName(asset.GetHeader().uuid.ToString().c_str());
|
||||
asset.SetName(asset.GetHeader().uuid.ToString());
|
||||
asset.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB});
|
||||
for (std::uint32_t j = 0; j < REFS_PER_ASSET; ++j)
|
||||
{
|
||||
asset.GetAsset().refs.emplace_back(m_uuids[Random::get<std::size_t>(0, m_uuids.size() - 1)]);
|
||||
}
|
||||
|
||||
const eastl::vector<std::byte> flatbuffer = asset.Pack();
|
||||
const eastl::vector<UUID> hardReferences = asset.GetHardReferences(flatbuffer);
|
||||
bytesProcessed += static_cast<std::int64_t>(flatbuffer.size());
|
||||
state.ResumeTiming();
|
||||
|
||||
m_bigFile.SaveAssetFlatbuffer(asset.GetHeader().uuid, flatbuffer, hardReferences);
|
||||
m_bigFile->SaveAssetFlatbuffer(asset.GetHeader().uuid, flatbuffer, hardReferences);
|
||||
}
|
||||
|
||||
state.SetItemsProcessed(state.iterations());
|
||||
state.SetBytesProcessed(bytesProcessed);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(BigFileFixture, SaveAssetFlatbuffer)->Name("BigFile/SaveAssetFlatbuffer");
|
||||
BENCHMARK_REGISTER_F(BigFileFixture, SaveAssetFlatbuffer)->Name("BigFile/SaveAssetFlatbuffer")->UseRealTime();
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
@@ -234,25 +268,32 @@ BENCHMARK_DEFINE_F(BigFileFixture, SaveAssetFlatbuffers)(benchmark::State& state
|
||||
for (auto _: state)
|
||||
{
|
||||
state.PauseTiming();
|
||||
eastl::vector<UUID> uuids;
|
||||
eastl::vector<eastl::vector<std::byte>> flatbuffers;
|
||||
eastl::vector<eastl::vector<UUID>> hardReferences;
|
||||
uuids.reserve(batchSize);
|
||||
flatbuffers.reserve(batchSize);
|
||||
hardReferences.reserve(batchSize);
|
||||
|
||||
for (std::size_t i = 0; i < batchSize; ++i)
|
||||
{
|
||||
BenchmarkAsset asset;
|
||||
asset.SetName(asset.GetHeader().uuid.ToString().c_str());
|
||||
asset.SetName(asset.GetHeader().uuid.ToString());
|
||||
asset.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB});
|
||||
for (std::uint32_t j = 0; j < REFS_PER_ASSET; ++j)
|
||||
{
|
||||
asset.GetAsset().refs.emplace_back(m_uuids[Random::get<std::size_t>(0, m_uuids.size() - 1)]);
|
||||
}
|
||||
|
||||
const eastl::vector<std::byte> flatbuffer = asset.Pack();
|
||||
flatbuffers.push_back(flatbuffer);
|
||||
hardReferences.push_back(asset.GetHardReferences(flatbuffer));
|
||||
eastl::vector<std::byte> flatbuffer = asset.Pack();
|
||||
uuids.push_back(asset.GetHeader().uuid);
|
||||
bytesProcessed += static_cast<std::int64_t>(flatbuffer.size());
|
||||
hardReferences.push_back(asset.GetHardReferences(flatbuffer));
|
||||
flatbuffers.push_back(std::move(flatbuffer));
|
||||
}
|
||||
state.ResumeTiming();
|
||||
|
||||
m_bigFile.SaveAssetFlatbuffers(m_uuids, flatbuffers, hardReferences);
|
||||
m_bigFile->SaveAssetFlatbuffers(uuids, flatbuffers, hardReferences);
|
||||
}
|
||||
|
||||
state.SetItemsProcessed(state.iterations() * batchSize);
|
||||
@@ -265,6 +306,7 @@ BENCHMARK_REGISTER_F(BigFileFixture, SaveAssetFlatbuffers)
|
||||
->Arg(8)
|
||||
->Arg(64)
|
||||
->Arg(512)
|
||||
->Arg(4096);
|
||||
->Arg(4096)
|
||||
->UseRealTime();
|
||||
#endif
|
||||
} // namespace Bigfoot
|
||||
|
||||
@@ -2,13 +2,13 @@ get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
project(${PackageName}Benchmarks)
|
||||
|
||||
bigfoot_create_package_benchmarks(
|
||||
"")
|
||||
"Bigfoot/Benchmarks")
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
effolkronium_random
|
||||
$<LINK_LIBRARY:WHOLE_ARCHIVE,AssetsForBenchmarking>)
|
||||
|
||||
bigfoot_create_bigfile("Benchmarks/Bigfoot")
|
||||
bigfoot_create_bigfile("Bigfoot/Benchmarks")
|
||||
|
||||
bigfoot_create_sasquatch_info()
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
#include <System/File/File.hpp>
|
||||
#include <System/UUID/UUID.hpp>
|
||||
|
||||
#include <EngineBenchmarks/SasquatchInfo_generated.hpp>
|
||||
|
||||
#include <AssetsForBenchmarking/Asset/BenchmarkAsset.hpp>
|
||||
#include <AssetsForBenchmarking/Asset/BenchmarkAssetReferred.hpp>
|
||||
|
||||
#include <EngineBenchmarks/SasquatchInfo_generated.hpp>
|
||||
|
||||
#include <EASTL/optional.h>
|
||||
#include <EASTL/span.h>
|
||||
#include <EASTL/vector.h>
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <effolkronium/random.hpp>
|
||||
@@ -30,79 +31,21 @@ using Random = effolkronium::random_static;
|
||||
class SasquatchFixture: public benchmark::Fixture
|
||||
{
|
||||
protected:
|
||||
struct SasquatchData
|
||||
{
|
||||
UUID m_uuid;
|
||||
eastl::span<const std::byte> m_flatbuffer;
|
||||
eastl::span<const UUID> m_hardReferences;
|
||||
};
|
||||
|
||||
static constexpr std::uint32_t ASSET_COUNT = 20'000;
|
||||
static constexpr std::uint32_t REFS_PER_ASSET = 4;
|
||||
static constexpr std::size_t ASSET_PAYLOAD_SIZE = 256;
|
||||
|
||||
void SetUp([[maybe_unused]] benchmark::State& p_state) override
|
||||
{
|
||||
File {SASQUATCH_ENGINEBENCHMARKS_LOCATION}.Delete();
|
||||
|
||||
eastl::vector<eastl::vector<std::byte>> flatbuffers;
|
||||
eastl::vector<eastl::vector<UUID>> hardReferences;
|
||||
flatbuffers.reserve(ASSET_COUNT);
|
||||
hardReferences.reserve(ASSET_COUNT);
|
||||
|
||||
m_uuids.clear();
|
||||
m_uuids.reserve(ASSET_COUNT);
|
||||
|
||||
for (std::uint32_t i = 0; i < ASSET_COUNT; ++i)
|
||||
{
|
||||
BenchmarkAsset asset;
|
||||
asset.SetName(asset.GetHeader().uuid.ToString().c_str());
|
||||
asset.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB});
|
||||
for (std::uint32_t j = 0; j < 4; ++j)
|
||||
{
|
||||
BenchmarkAssetReferred assetReferred;
|
||||
assetReferred.SetName(assetReferred.GetHeader().uuid.ToString().c_str());
|
||||
|
||||
asset.GetAsset().refs.emplace_back(assetReferred.GetHeader().uuid);
|
||||
}
|
||||
|
||||
const eastl::vector<std::byte> flatbuffer = asset.Pack();
|
||||
flatbuffers.push_back(flatbuffer);
|
||||
hardReferences.push_back(asset.GetHardReferences(flatbuffer));
|
||||
m_uuids.push_back(asset.GetHeader().uuid);
|
||||
}
|
||||
|
||||
eastl::vector<SasquatchData> assets;
|
||||
assets.reserve(ASSET_COUNT);
|
||||
for (std::uint32_t i = 0; i < ASSET_COUNT; ++i)
|
||||
{
|
||||
assets.push_back(SasquatchData {.m_uuid = m_uuids[i],
|
||||
.m_flatbuffer = flatbuffers[i],
|
||||
.m_hardReferences = hardReferences[i]});
|
||||
}
|
||||
|
||||
std::size_t totalFlatbufferBytes = 0;
|
||||
std::size_t totalHardReferencesBytes = 0;
|
||||
for (const SasquatchData& asset: assets)
|
||||
{
|
||||
totalFlatbufferBytes += asset.m_flatbuffer.size();
|
||||
totalHardReferencesBytes += asset.m_hardReferences.size() * UUID::UUID_BYTE_SIZE;
|
||||
}
|
||||
|
||||
{
|
||||
SasquatchWriter writer {File {SASQUATCH_ENGINEBENCHMARKS_LOCATION},
|
||||
assets.size(),
|
||||
totalFlatbufferBytes,
|
||||
totalHardReferencesBytes};
|
||||
for (const SasquatchData& asset: assets)
|
||||
{
|
||||
writer.WriteAsset(asset.m_uuid, asset.m_flatbuffer, asset.m_hardReferences);
|
||||
}
|
||||
}
|
||||
|
||||
// The Sasquatch file is built exactly once for the entire benchmark process.
|
||||
// SetUp is called before every calibration round (Google Benchmark doubles
|
||||
// iteration counts until it reaches a stable measurement), so rebuilding
|
||||
// the file each time would dominate the total benchmark time.
|
||||
m_uuids = BuildData();
|
||||
m_sasquatch.emplace(File {SASQUATCH_ENGINEBENCHMARKS_LOCATION});
|
||||
}
|
||||
|
||||
void TearDown(benchmark::State&) override
|
||||
void TearDown([[maybe_unused]] benchmark::State& p_state) override
|
||||
{
|
||||
m_sasquatch.reset();
|
||||
}
|
||||
@@ -135,7 +78,63 @@ class SasquatchFixture: public benchmark::Fixture
|
||||
}
|
||||
|
||||
eastl::optional<Sasquatch> m_sasquatch;
|
||||
eastl::vector<UUID> m_uuids;
|
||||
eastl::span<const UUID> m_uuids;
|
||||
|
||||
private:
|
||||
static const eastl::vector<UUID>& BuildData()
|
||||
{
|
||||
static const eastl::vector<UUID> s_uuids = []()
|
||||
{
|
||||
File {SASQUATCH_ENGINEBENCHMARKS_LOCATION}.Delete();
|
||||
|
||||
eastl::vector<UUID> uuids;
|
||||
eastl::vector<eastl::vector<std::byte>> flatbuffers;
|
||||
eastl::vector<eastl::vector<UUID>> hardReferences;
|
||||
uuids.reserve(ASSET_COUNT);
|
||||
flatbuffers.reserve(ASSET_COUNT);
|
||||
hardReferences.reserve(ASSET_COUNT);
|
||||
|
||||
for (std::uint32_t i = 0; i < ASSET_COUNT; ++i)
|
||||
{
|
||||
BenchmarkAsset asset;
|
||||
asset.SetName(asset.GetHeader().uuid.ToString());
|
||||
asset.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB});
|
||||
for (std::uint32_t j = 0; j < REFS_PER_ASSET; ++j)
|
||||
{
|
||||
BenchmarkAssetReferred assetReferred;
|
||||
assetReferred.SetName(assetReferred.GetHeader().uuid.ToString());
|
||||
|
||||
asset.GetAsset().refs.emplace_back(assetReferred.GetHeader().uuid);
|
||||
}
|
||||
|
||||
eastl::vector<std::byte> flatbuffer = asset.Pack();
|
||||
hardReferences.push_back(asset.GetHardReferences(flatbuffer));
|
||||
flatbuffers.push_back(std::move(flatbuffer));
|
||||
uuids.push_back(asset.GetHeader().uuid);
|
||||
}
|
||||
|
||||
std::size_t totalFlatbufferBytes = 0;
|
||||
std::size_t totalHardReferencesBytes = 0;
|
||||
for (std::size_t i = 0; i < uuids.size(); ++i)
|
||||
{
|
||||
totalFlatbufferBytes += flatbuffers[i].size();
|
||||
totalHardReferencesBytes += hardReferences[i].size() * UUID::UUID_BYTE_SIZE;
|
||||
}
|
||||
|
||||
SasquatchWriter writer {File {SASQUATCH_ENGINEBENCHMARKS_LOCATION},
|
||||
uuids.size(),
|
||||
totalFlatbufferBytes,
|
||||
totalHardReferencesBytes};
|
||||
for (std::size_t i = 0; i < uuids.size(); ++i)
|
||||
{
|
||||
writer.WriteAsset(uuids[i], flatbuffers[i], hardReferences[i]);
|
||||
}
|
||||
|
||||
return uuids;
|
||||
}();
|
||||
|
||||
return s_uuids;
|
||||
}
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
@@ -149,9 +148,10 @@ BENCHMARK_DEFINE_F(SasquatchFixture, GetAssetHardReferences)(benchmark::State& s
|
||||
}
|
||||
|
||||
state.SetItemsProcessed(state.iterations());
|
||||
state.SetBytesProcessed(static_cast<std::int64_t>(state.iterations()) * REFS_PER_ASSET * UUID::UUID_BYTE_SIZE);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(SasquatchFixture, GetAssetHardReferences)->Name("Sasquatch/GetAssetHardReferences");
|
||||
BENCHMARK_REGISTER_F(SasquatchFixture, GetAssetHardReferences)->Name("Sasquatch/GetAssetHardReferences")->UseRealTime();
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
@@ -170,6 +170,8 @@ BENCHMARK_DEFINE_F(SasquatchFixture, GetAssetsHardReferences)(benchmark::State&
|
||||
}
|
||||
|
||||
state.SetItemsProcessed(state.iterations() * batchSize);
|
||||
state.SetBytesProcessed(static_cast<std::int64_t>(state.iterations()) * batchSize * REFS_PER_ASSET *
|
||||
UUID::UUID_BYTE_SIZE);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(SasquatchFixture, GetAssetsHardReferences)
|
||||
@@ -178,7 +180,8 @@ BENCHMARK_REGISTER_F(SasquatchFixture, GetAssetsHardReferences)
|
||||
->Arg(8)
|
||||
->Arg(64)
|
||||
->Arg(512)
|
||||
->Arg(4096);
|
||||
->Arg(4096)
|
||||
->UseRealTime();
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
@@ -199,7 +202,7 @@ BENCHMARK_DEFINE_F(SasquatchFixture, GetAssetFlatbuffer)(benchmark::State& state
|
||||
state.SetBytesProcessed(bytesProcessed);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(SasquatchFixture, GetAssetFlatbuffer)->Name("Sasquatch/GetAssetFlatbuffer");
|
||||
BENCHMARK_REGISTER_F(SasquatchFixture, GetAssetFlatbuffer)->Name("Sasquatch/GetAssetFlatbuffer")->UseRealTime();
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
@@ -236,6 +239,7 @@ BENCHMARK_REGISTER_F(SasquatchFixture, GetAssetFlatbuffers)
|
||||
->Arg(8)
|
||||
->Arg(64)
|
||||
->Arg(512)
|
||||
->Arg(4096);
|
||||
->Arg(4096)
|
||||
->UseRealTime();
|
||||
#endif
|
||||
} // namespace Bigfoot
|
||||
|
||||
@@ -0,0 +1,391 @@
|
||||
/*********************************************************************
|
||||
* \file SerializationManager.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date August 2026
|
||||
*********************************************************************/
|
||||
#include <Engine/SerializationManager/SerializationManager.hpp>
|
||||
|
||||
#include <Engine/Asset/AssetLibrary.hpp>
|
||||
#include <Engine/DataAccessor/DataAccessor.hpp>
|
||||
|
||||
#if defined BIGFOOT_TOOLMODE
|
||||
#include <Engine/BigFile/BigFile.hpp>
|
||||
|
||||
#include <EngineBenchmarks/BigFileInfo_generated.hpp>
|
||||
#elif defined BIGFOOT_GAME
|
||||
#include <Engine/Sasquatch/Sasquatch.hpp>
|
||||
|
||||
#include <EngineBenchmarks/SasquatchInfo_generated.hpp>
|
||||
#endif
|
||||
|
||||
#include <System/File/File.hpp>
|
||||
#include <System/UUID/UUID.hpp>
|
||||
|
||||
#include <AssetsForBenchmarking/Asset/BenchmarkAsset.hpp>
|
||||
#include <AssetsForBenchmarking/Asset/BenchmarkAssetReferred.hpp>
|
||||
|
||||
#include <EASTL/optional.h>
|
||||
#include <EASTL/span.h>
|
||||
#include <EASTL/vector.h>
|
||||
#include <ankerl/unordered_dense.h>
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <effolkronium/random.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <tuple>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
using Random = effolkronium::random_static;
|
||||
|
||||
class SerializationManagerFixture: public benchmark::Fixture
|
||||
{
|
||||
protected:
|
||||
static constexpr std::uint32_t ROOT_ASSET_COUNT = 20'000;
|
||||
static constexpr std::uint32_t REFS_PER_ROOT = 4;
|
||||
static constexpr std::size_t ASSET_PAYLOAD_SIZE = 256;
|
||||
|
||||
void SetUp([[maybe_unused]] benchmark::State& p_state) override
|
||||
{
|
||||
m_previousDataAccessor = g_dataAccessor;
|
||||
m_previousAssetLibrary = g_activeAssetLibrary;
|
||||
|
||||
// The data store is populated exactly once for the entire benchmark process.
|
||||
// SetUp is called before every calibration round (Google Benchmark doubles
|
||||
// iteration counts until it reaches a stable measurement), so rebuilding
|
||||
// the data store each time would dominate the total benchmark time.
|
||||
static const SharedData& s_data = BuildData();
|
||||
m_rootUuids = s_data.rootUuids;
|
||||
m_leafUuids = s_data.leafUuids;
|
||||
m_rootTotalBytes = &s_data.rootTotalBytes;
|
||||
|
||||
#if defined BIGFOOT_TOOLMODE
|
||||
m_bigFile.emplace(File {BIGFILE_ENGINEBENCHMARKS_LOCATION});
|
||||
SetDataAccessor(&*m_bigFile);
|
||||
#elif defined BIGFOOT_GAME
|
||||
m_sasquatch.emplace(File {SASQUATCH_ENGINEBENCHMARKS_LOCATION});
|
||||
SetDataAccessor(&*m_sasquatch);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TearDown([[maybe_unused]] benchmark::State& p_state) override
|
||||
{
|
||||
#if defined BIGFOOT_TOOLMODE
|
||||
m_bigFile.reset();
|
||||
#elif defined BIGFOOT_GAME
|
||||
m_sasquatch.reset();
|
||||
#endif
|
||||
SetDataAccessor(m_previousDataAccessor);
|
||||
SetActiveAssetLibrary(m_previousAssetLibrary);
|
||||
}
|
||||
|
||||
/*
|
||||
* Registers a fresh, empty AssetLibrary as the active one, so that every root and leaf asset appears unloaded
|
||||
*
|
||||
* \param p_library The library to register
|
||||
* \param p_leafContainer The container to register leaves into
|
||||
* \param p_rootContainer The container to register roots into
|
||||
*/
|
||||
static void ResetActiveLibrary(AssetLibrary& p_library,
|
||||
AssetContainer<BenchmarkAssetReferred>& p_leafContainer,
|
||||
AssetContainer<BenchmarkAsset>& p_rootContainer)
|
||||
{
|
||||
std::ignore = p_library.Insert(&p_leafContainer);
|
||||
std::ignore = p_library.Insert(&p_rootContainer);
|
||||
SetActiveAssetLibrary(&p_library);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
eastl::vector<UUID> RandomRootBatch(const std::size_t p_batchSize) const
|
||||
{
|
||||
eastl::vector<UUID> batch;
|
||||
batch.reserve(p_batchSize);
|
||||
for (std::size_t i = 0; i < p_batchSize; ++i)
|
||||
{
|
||||
batch.push_back(m_rootUuids[Random::get<std::size_t>(0, m_rootUuids.size() - 1)]);
|
||||
}
|
||||
|
||||
return batch;
|
||||
}
|
||||
|
||||
/*
|
||||
* Total flatbuffer bytes (root + its leaves) that loading p_roots will actually read, deduplicated the same way
|
||||
* SerializationManager::LoadAssets deduplicates its own transitive discovery
|
||||
*
|
||||
* \param p_roots The root assets that would be loaded
|
||||
* \return The total flatbuffer bytes across the unique roots
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::int64_t TotalBytes(const eastl::vector<UUID>& p_roots) const
|
||||
{
|
||||
ankerl::unordered_dense::set<UUID> unique;
|
||||
unique.reserve(p_roots.size());
|
||||
for (const UUID& uuid: p_roots)
|
||||
{
|
||||
unique.insert(uuid);
|
||||
}
|
||||
|
||||
std::int64_t bytes = 0;
|
||||
for (const UUID& uuid: unique)
|
||||
{
|
||||
bytes += static_cast<std::int64_t>(m_rootTotalBytes->at(uuid));
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
DataAccessor* m_previousDataAccessor = nullptr;
|
||||
AssetLibrary* m_previousAssetLibrary = nullptr;
|
||||
|
||||
eastl::span<const UUID> m_rootUuids;
|
||||
eastl::span<const UUID> m_leafUuids;
|
||||
const ankerl::unordered_dense::map<UUID, std::size_t>* m_rootTotalBytes = nullptr;
|
||||
|
||||
#if defined BIGFOOT_TOOLMODE
|
||||
eastl::optional<BigFile> m_bigFile;
|
||||
#elif defined BIGFOOT_GAME
|
||||
eastl::optional<Sasquatch> m_sasquatch;
|
||||
#endif
|
||||
|
||||
private:
|
||||
struct SharedData
|
||||
{
|
||||
eastl::vector<UUID> rootUuids;
|
||||
eastl::vector<UUID> leafUuids;
|
||||
ankerl::unordered_dense::map<UUID, std::size_t> rootTotalBytes;
|
||||
};
|
||||
|
||||
static const SharedData& BuildData()
|
||||
{
|
||||
static const SharedData s_data = []()
|
||||
{
|
||||
SharedData data;
|
||||
data.rootUuids.reserve(ROOT_ASSET_COUNT);
|
||||
data.leafUuids.reserve(ROOT_ASSET_COUNT * REFS_PER_ROOT);
|
||||
data.rootTotalBytes.reserve(ROOT_ASSET_COUNT);
|
||||
|
||||
eastl::vector<UUID> uuids;
|
||||
eastl::vector<eastl::vector<std::byte>> flatbuffers;
|
||||
eastl::vector<eastl::vector<UUID>> hardReferences;
|
||||
uuids.reserve(ROOT_ASSET_COUNT * (1 + REFS_PER_ROOT));
|
||||
flatbuffers.reserve(uuids.capacity());
|
||||
hardReferences.reserve(uuids.capacity());
|
||||
|
||||
for (std::uint32_t i = 0; i < ROOT_ASSET_COUNT; ++i)
|
||||
{
|
||||
BenchmarkAsset root;
|
||||
root.SetName(root.GetHeader().uuid.ToString());
|
||||
root.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB});
|
||||
|
||||
std::size_t totalBytes = 0;
|
||||
for (std::uint32_t j = 0; j < REFS_PER_ROOT; ++j)
|
||||
{
|
||||
BenchmarkAssetReferred leaf;
|
||||
leaf.SetName(leaf.GetHeader().uuid.ToString());
|
||||
|
||||
root.GetAsset().refs.emplace_back(leaf.GetHeader().uuid);
|
||||
|
||||
eastl::vector<std::byte> leafFlatbuffer = leaf.Pack();
|
||||
totalBytes += leafFlatbuffer.size();
|
||||
data.leafUuids.push_back(leaf.GetHeader().uuid);
|
||||
uuids.push_back(leaf.GetHeader().uuid);
|
||||
hardReferences.push_back(leaf.GetHardReferences(leafFlatbuffer));
|
||||
flatbuffers.push_back(std::move(leafFlatbuffer));
|
||||
}
|
||||
|
||||
eastl::vector<std::byte> rootFlatbuffer = root.Pack();
|
||||
totalBytes += rootFlatbuffer.size();
|
||||
data.rootTotalBytes.emplace(root.GetHeader().uuid, totalBytes);
|
||||
data.rootUuids.push_back(root.GetHeader().uuid);
|
||||
uuids.push_back(root.GetHeader().uuid);
|
||||
hardReferences.push_back(root.GetHardReferences(rootFlatbuffer));
|
||||
flatbuffers.push_back(std::move(rootFlatbuffer));
|
||||
}
|
||||
|
||||
#if defined BIGFOOT_TOOLMODE
|
||||
BigFile bigFile {File { BIGFILE_ENGINEBENCHMARKS_LOCATION }};
|
||||
bigFile.Clear();
|
||||
bigFile.SaveAssetFlatbuffers(uuids, flatbuffers, hardReferences);
|
||||
#elif defined BIGFOOT_GAME
|
||||
std::size_t totalFlatbufferBytes = 0;
|
||||
std::size_t totalHardReferencesBytes = 0;
|
||||
for (std::size_t i = 0; i < uuids.size(); ++i)
|
||||
{
|
||||
totalFlatbufferBytes += flatbuffers[i].size();
|
||||
totalHardReferencesBytes += hardReferences[i].size() * UUID::UUID_BYTE_SIZE;
|
||||
}
|
||||
|
||||
File {SASQUATCH_ENGINEBENCHMARKS_LOCATION}.Delete();
|
||||
SasquatchWriter writer {File {SASQUATCH_ENGINEBENCHMARKS_LOCATION},
|
||||
uuids.size(),
|
||||
totalFlatbufferBytes,
|
||||
totalHardReferencesBytes};
|
||||
for (std::size_t i = 0; i < uuids.size(); ++i)
|
||||
{
|
||||
writer.WriteAsset(uuids[i], flatbuffers[i], hardReferences[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
return data;
|
||||
}();
|
||||
|
||||
return s_data;
|
||||
}
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
BENCHMARK_DEFINE_F(SerializationManagerFixture, LoadAsset)(benchmark::State& state)
|
||||
{
|
||||
std::int64_t bytesProcessed = 0;
|
||||
|
||||
for (auto _: state)
|
||||
{
|
||||
state.PauseTiming();
|
||||
AssetLibrary library;
|
||||
// leafContainer must outlive rootContainer: the loaded root's HardReferences release into leafContainer's
|
||||
// handles on destruction, so declaring it second would tear it down first and use-after-free those handles.
|
||||
AssetContainer<BenchmarkAssetReferred> leafContainer;
|
||||
AssetContainer<BenchmarkAsset> rootContainer;
|
||||
ResetActiveLibrary(library, leafContainer, rootContainer);
|
||||
|
||||
const UUID uuid = m_rootUuids[Random::get<std::size_t>(0, m_rootUuids.size() - 1)];
|
||||
const std::size_t uuidBytes = m_rootTotalBytes->at(uuid);
|
||||
state.ResumeTiming();
|
||||
|
||||
SerializationManager::LoadAsset(uuid);
|
||||
bytesProcessed += static_cast<std::int64_t>(uuidBytes);
|
||||
}
|
||||
|
||||
state.SetItemsProcessed(state.iterations() * (1 + REFS_PER_ROOT));
|
||||
state.SetBytesProcessed(bytesProcessed);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(SerializationManagerFixture, LoadAsset)->Name("SerializationManager/LoadAsset")->UseRealTime();
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
BENCHMARK_DEFINE_F(SerializationManagerFixture, LoadAssets)(benchmark::State& state)
|
||||
{
|
||||
const auto batchSize = static_cast<std::size_t>(state.range(0));
|
||||
std::int64_t bytesProcessed = 0;
|
||||
|
||||
for (auto _: state)
|
||||
{
|
||||
state.PauseTiming();
|
||||
AssetLibrary library;
|
||||
// leafContainer must outlive rootContainer, see the same comment in the LoadAsset benchmark above.
|
||||
AssetContainer<BenchmarkAssetReferred> leafContainer;
|
||||
AssetContainer<BenchmarkAsset> rootContainer;
|
||||
ResetActiveLibrary(library, leafContainer, rootContainer);
|
||||
|
||||
const eastl::vector<UUID> batch = RandomRootBatch(batchSize);
|
||||
const std::int64_t batchBytes = TotalBytes(batch);
|
||||
state.ResumeTiming();
|
||||
|
||||
SerializationManager::LoadAssets(batch);
|
||||
bytesProcessed += batchBytes;
|
||||
}
|
||||
|
||||
state.SetItemsProcessed(state.iterations() * batchSize * (1 + REFS_PER_ROOT));
|
||||
state.SetBytesProcessed(bytesProcessed);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(SerializationManagerFixture, LoadAssets)
|
||||
->Name("SerializationManager/LoadAssets")
|
||||
->Arg(1)
|
||||
->Arg(8)
|
||||
->Arg(64)
|
||||
->Arg(512)
|
||||
->Arg(4096)
|
||||
->UseRealTime();
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
#if defined BIGFOOT_TOOLMODE
|
||||
BENCHMARK_DEFINE_F(SerializationManagerFixture, SaveAsset)(benchmark::State& state)
|
||||
{
|
||||
AssetLibrary library;
|
||||
AssetContainer<BenchmarkAsset> container;
|
||||
std::ignore = library.Insert(&container);
|
||||
SetActiveAssetLibrary(&library);
|
||||
|
||||
std::int64_t bytesProcessed = 0;
|
||||
|
||||
for (auto _: state)
|
||||
{
|
||||
state.PauseTiming();
|
||||
auto* asset = CreateAsset<BenchmarkAsset>();
|
||||
asset->SetName(asset->GetHeader().uuid.ToString());
|
||||
asset->GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB});
|
||||
for (std::uint32_t j = 0; j < REFS_PER_ROOT; ++j)
|
||||
{
|
||||
asset->GetAsset().refs.emplace_back(m_leafUuids[Random::get<std::size_t>(0, m_leafUuids.size() - 1)]);
|
||||
}
|
||||
const UUID uuid = asset->GetHeader().uuid;
|
||||
const std::size_t assetBytes = asset->Pack().size();
|
||||
bytesProcessed += static_cast<std::int64_t>(assetBytes);
|
||||
state.ResumeTiming();
|
||||
|
||||
benchmark::DoNotOptimize(SerializationManager::SaveAsset(uuid));
|
||||
}
|
||||
|
||||
state.SetItemsProcessed(state.iterations());
|
||||
state.SetBytesProcessed(bytesProcessed);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(SerializationManagerFixture, SaveAsset)->Name("SerializationManager/SaveAsset")->UseRealTime();
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
BENCHMARK_DEFINE_F(SerializationManagerFixture, SaveAssets)(benchmark::State& state)
|
||||
{
|
||||
const auto batchSize = static_cast<std::size_t>(state.range(0));
|
||||
|
||||
AssetLibrary library;
|
||||
AssetContainer<BenchmarkAsset> container;
|
||||
std::ignore = library.Insert(&container);
|
||||
SetActiveAssetLibrary(&library);
|
||||
|
||||
std::int64_t bytesProcessed = 0;
|
||||
|
||||
for (auto _: state)
|
||||
{
|
||||
state.PauseTiming();
|
||||
eastl::vector<UUID> uuids;
|
||||
uuids.reserve(batchSize);
|
||||
std::size_t batchBytes = 0;
|
||||
for (std::size_t i = 0; i < batchSize; ++i)
|
||||
{
|
||||
auto* asset = CreateAsset<BenchmarkAsset>();
|
||||
asset->SetName(asset->GetHeader().uuid.ToString());
|
||||
asset->GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB});
|
||||
for (std::uint32_t j = 0; j < REFS_PER_ROOT; ++j)
|
||||
{
|
||||
asset->GetAsset().refs.emplace_back(m_leafUuids[Random::get<std::size_t>(0, m_leafUuids.size() - 1)]);
|
||||
}
|
||||
|
||||
batchBytes += asset->Pack().size();
|
||||
uuids.push_back(asset->GetHeader().uuid);
|
||||
}
|
||||
state.ResumeTiming();
|
||||
|
||||
benchmark::DoNotOptimize(SerializationManager::SaveAssets(uuids));
|
||||
bytesProcessed += static_cast<std::int64_t>(batchBytes);
|
||||
}
|
||||
|
||||
state.SetItemsProcessed(state.iterations() * batchSize);
|
||||
state.SetBytesProcessed(bytesProcessed);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(SerializationManagerFixture, SaveAssets)
|
||||
->Name("SerializationManager/SaveAssets")
|
||||
->Arg(1)
|
||||
->Arg(8)
|
||||
->Arg(64)
|
||||
->Arg(512)
|
||||
->UseRealTime();
|
||||
#endif
|
||||
} // namespace Bigfoot
|
||||
@@ -0,0 +1,26 @@
|
||||
/*********************************************************************
|
||||
* \file main.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#include <Utils/Log/LogMacros.hpp>
|
||||
#include <Utils/TargetMacros.h>
|
||||
|
||||
#include <benchmark/benchmark.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
|
||||
|
||||
::benchmark::Initialize(&argc, argv);
|
||||
if (::benchmark::ReportUnrecognizedArguments(argc, argv))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
::benchmark::RunSpecifiedBenchmarks();
|
||||
::benchmark::Shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
if(${VULKAN})
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/GraphicsVulkan)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/GraphicsCore)
|
||||
endif()
|
||||
@@ -0,0 +1,5 @@
|
||||
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
project(${PackageName}Benchmarks)
|
||||
|
||||
bigfoot_create_package_benchmarks(
|
||||
"Bigfoot/Benchmarks/Graphics")
|
||||
@@ -0,0 +1,26 @@
|
||||
/*********************************************************************
|
||||
* \file main.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#include <Utils/Log/LogMacros.hpp>
|
||||
#include <Utils/TargetMacros.h>
|
||||
|
||||
#include <benchmark/benchmark.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
|
||||
|
||||
::benchmark::Initialize(&argc, argv);
|
||||
if (::benchmark::ReportUnrecognizedArguments(argc, argv))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
::benchmark::RunSpecifiedBenchmarks();
|
||||
::benchmark::Shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
project(${PackageName}Benchmarks)
|
||||
|
||||
bigfoot_create_package_benchmarks(
|
||||
"Bigfoot/Benchmarks/Graphics")
|
||||
@@ -0,0 +1,26 @@
|
||||
/*********************************************************************
|
||||
* \file main.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#include <Utils/Log/LogMacros.hpp>
|
||||
#include <Utils/TargetMacros.h>
|
||||
|
||||
#include <benchmark/benchmark.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
|
||||
|
||||
::benchmark::Initialize(&argc, argv);
|
||||
if (::benchmark::ReportUnrecognizedArguments(argc, argv))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
::benchmark::RunSpecifiedBenchmarks();
|
||||
::benchmark::Shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2,4 +2,4 @@ get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
project(${PackageName}Benchmarks)
|
||||
|
||||
bigfoot_create_package_benchmarks(
|
||||
"")
|
||||
"Bigfoot/Benchmarks")
|
||||
@@ -0,0 +1,26 @@
|
||||
/*********************************************************************
|
||||
* \file main.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#include <Utils/Log/LogMacros.hpp>
|
||||
#include <Utils/TargetMacros.h>
|
||||
|
||||
#include <benchmark/benchmark.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
|
||||
|
||||
::benchmark::Initialize(&argc, argv);
|
||||
if (::benchmark::ReportUnrecognizedArguments(argc, argv))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
::benchmark::RunSpecifiedBenchmarks();
|
||||
::benchmark::Shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Utils)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/System)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Engine)
|
||||
if(${TOOLMODE})
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Tools)
|
||||
endif()
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Graphics)
|
||||
@@ -1,10 +1,10 @@
|
||||
/*********************************************************************
|
||||
* \file Asset.cpp
|
||||
* \file AssetBase.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date April 2026
|
||||
*********************************************************************/
|
||||
#include <Engine/Asset/Asset.hpp>
|
||||
#include <Engine/Asset/AssetBase.hpp>
|
||||
|
||||
#include <Engine/Asset/Reference_generated.hpp>
|
||||
|
||||
@@ -40,14 +40,7 @@ eastl::vector<UUID> AssetBase::HardReferenceVisitor::GetUUIDs() const
|
||||
{
|
||||
eastl::vector<UUID> uuids;
|
||||
uuids.reserve(m_uuids.size());
|
||||
|
||||
std::transform(m_uuids.begin(),
|
||||
m_uuids.end(),
|
||||
eastl::back_inserter(uuids),
|
||||
[](const UUID& p_uuid)
|
||||
{
|
||||
return p_uuid;
|
||||
});
|
||||
std::copy(m_uuids.begin(), m_uuids.end(), eastl::back_inserter(uuids));
|
||||
return uuids;
|
||||
}
|
||||
|
||||
@@ -63,7 +56,8 @@ void AssetBase::HardReferenceVisitor::Visit(const flatbuffers::ElementaryType p_
|
||||
return;
|
||||
}
|
||||
|
||||
const ::Flat::Bigfoot::HardReference* hardReference = std::bit_cast<const ::Flat::Bigfoot::HardReference*>(p_val);
|
||||
const ::Flat::Bigfoot::HardReference* hardReference = reinterpret_cast<const ::Flat::Bigfoot::HardReference*>(
|
||||
p_val);
|
||||
m_uuids.emplace(flatbuffers::UnPack(hardReference->uuid()));
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
+11
-11
@@ -128,10 +128,10 @@ void AssetContainerBase::QueueForRemoval(const UUID& p_uuid)
|
||||
|
||||
void AssetContainerBase::CancelRemoval(const UUID& p_uuid)
|
||||
{
|
||||
const auto it = eastl::find(m_pendingRemovalUuids.begin(), m_pendingRemovalUuids.end(), p_uuid);
|
||||
if (it != m_pendingRemovalUuids.end())
|
||||
auto* const pendingIt = eastl::find(m_pendingRemovalUuids.begin(), m_pendingRemovalUuids.end(), p_uuid);
|
||||
if (pendingIt != m_pendingRemovalUuids.end())
|
||||
{
|
||||
m_pendingRemovalUuids.erase_unsorted(it);
|
||||
m_pendingRemovalUuids.erase_unsorted(pendingIt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,29 +160,29 @@ bool AssetContainerBase::IsMarkedForRemove(const UUID& p_uuid)
|
||||
|
||||
AssetContainerBase::Entry* AssetContainerBase::FindEntry(const UUID& p_uuid)
|
||||
{
|
||||
const auto it = m_uuidToEntry.find(p_uuid);
|
||||
return it != m_uuidToEntry.end() ? &it->second : nullptr;
|
||||
const auto entryIt = m_uuidToEntry.find(p_uuid);
|
||||
return entryIt != m_uuidToEntry.end() ? &entryIt->second : nullptr;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
const AssetContainerBase::Entry* AssetContainerBase::FindEntry(const UUID& p_uuid) const
|
||||
{
|
||||
const auto it = m_uuidToEntry.find(p_uuid);
|
||||
return it != m_uuidToEntry.end() ? &it->second : nullptr;
|
||||
const auto entryIt = m_uuidToEntry.find(p_uuid);
|
||||
return entryIt != m_uuidToEntry.end() ? &entryIt->second : nullptr;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
AssetContainerBase::Entry& AssetContainerBase::GetOrCreateEntry(const UUID& p_uuid)
|
||||
{
|
||||
auto [it, inserted] = m_uuidToEntry.try_emplace(p_uuid);
|
||||
auto [entryIt, inserted] = m_uuidToEntry.try_emplace(p_uuid);
|
||||
if (inserted)
|
||||
{
|
||||
it->second.m_handleSlotKey = m_handles.Insert(this, p_uuid);
|
||||
it->second.m_handle = m_handles.Get(it->second.m_handleSlotKey);
|
||||
entryIt->second.m_handleSlotKey = m_handles.Insert(this, p_uuid);
|
||||
entryIt->second.m_handle = m_handles.Get(entryIt->second.m_handleSlotKey);
|
||||
}
|
||||
|
||||
return it->second;
|
||||
return entryIt->second;
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
+3
-3
@@ -69,9 +69,9 @@ bool AssetLibrary::IsLoaded(const UUID& p_uuid) const
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
void AssetLibrary::ProcessPendingRemovals() {
|
||||
|
||||
for (const auto [typeId, container] : m_assetContainers)
|
||||
void AssetLibrary::ProcessPendingRemovals()
|
||||
{
|
||||
for (const auto [typeId, container]: m_assetContainers)
|
||||
{
|
||||
container->ProcessPendingRemovals();
|
||||
}
|
||||
+94
-82
@@ -8,8 +8,9 @@
|
||||
|
||||
#include <Engine/EngineAssertHandler.hpp>
|
||||
|
||||
#include <Utils/Format.hpp>
|
||||
|
||||
#include <EASTL/algorithm.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
@@ -149,9 +150,9 @@ eastl::vector<eastl::vector<std::byte>> BigFile::GetAssetFlatbuffers(const eastl
|
||||
placeholders += "?";
|
||||
}
|
||||
|
||||
const std::string sql = fmt::format("SELECT UUID, Asset FROM Asset WHERE UUID IN ({});", placeholders);
|
||||
const eastl::string sql = Format("SELECT UUID, Asset FROM Asset WHERE UUID IN ({});", placeholders);
|
||||
|
||||
BigFile::Request assetRequest {*this, sql.c_str()};
|
||||
BigFile::Request assetRequest {*this, sql};
|
||||
for (std::size_t i = 0; i < chunkSize; ++i)
|
||||
{
|
||||
assetRequest.Bind(static_cast<std::uint32_t>(i + 1), distinctUUIDs[chunkStart + i].ToBytes());
|
||||
@@ -159,19 +160,19 @@ eastl::vector<eastl::vector<std::byte>> BigFile::GetAssetFlatbuffers(const eastl
|
||||
|
||||
while (assetRequest.Step())
|
||||
{
|
||||
const eastl::span<const std::byte, UUID::UUID_BYTE_SIZE> rawUUID =
|
||||
static_cast<eastl::span<const std::byte>>(assetRequest.Get(0));
|
||||
const UUID uuid {std::span<const std::byte, UUID::UUID_BYTE_SIZE> {rawUUID.begin(), rawUUID.end()}};
|
||||
const std::span<const std::byte, UUID::UUID_BYTE_SIZE> rawUUID {
|
||||
static_cast<std::span<const std::byte>>(assetRequest.Get(0))};
|
||||
const UUID uuid {rawUUID};
|
||||
|
||||
const auto it = uuidToIndices.find(uuid);
|
||||
const auto indicesIt = uuidToIndices.find(uuid);
|
||||
ASSERT(EngineAssertHandler,
|
||||
it != uuidToIndices.end(),
|
||||
indicesIt != uuidToIndices.end(),
|
||||
"Returned UUID {} not found in requested UUIDs",
|
||||
uuid);
|
||||
|
||||
const eastl::span<const std::byte> flatbuffer = assetRequest.Get(1);
|
||||
|
||||
for (const std::size_t index: it->second)
|
||||
for (const std::size_t index: indicesIt->second)
|
||||
{
|
||||
flatbuffers[index].assign(flatbuffer.begin(), flatbuffer.end());
|
||||
}
|
||||
@@ -191,9 +192,9 @@ eastl::vector<UUID> BigFile::GetAssetHardReferences(const UUID& p_uuid) const
|
||||
eastl::vector<UUID> hardReferences;
|
||||
while (hardReferencesRequest.Step())
|
||||
{
|
||||
const eastl::span<const std::byte, UUID::UUID_BYTE_SIZE> rawUUID = static_cast<eastl::span<const std::byte>>(
|
||||
hardReferencesRequest.Get(0));
|
||||
hardReferences.emplace_back(std::span<const std::byte, UUID::UUID_BYTE_SIZE>(rawUUID.begin(), rawUUID.end()));
|
||||
const std::span<const std::byte, UUID::UUID_BYTE_SIZE> rawUUID {
|
||||
static_cast<std::span<const std::byte>>(hardReferencesRequest.Get(0))};
|
||||
hardReferences.emplace_back(rawUUID);
|
||||
}
|
||||
|
||||
return hardReferences;
|
||||
@@ -244,10 +245,10 @@ eastl::vector<eastl::vector<UUID>> BigFile::GetAssetsHardReferences(eastl::span<
|
||||
placeholders += "?";
|
||||
}
|
||||
|
||||
const std::string sql = fmt::format("SELECT UUID, HardReference FROM AssetHardReference WHERE UUID IN ({});",
|
||||
placeholders);
|
||||
const eastl::string sql = Format("SELECT UUID, HardReference FROM AssetHardReference WHERE UUID IN ({});",
|
||||
placeholders);
|
||||
|
||||
BigFile::Request hardReferencesRequest {*this, sql.c_str()};
|
||||
BigFile::Request hardReferencesRequest {*this, sql};
|
||||
for (std::size_t i = 0; i < chunkSize; ++i)
|
||||
{
|
||||
hardReferencesRequest.Bind(static_cast<std::uint32_t>(i + 1), distinctUUIDs[chunkStart + i].ToBytes());
|
||||
@@ -255,25 +256,22 @@ eastl::vector<eastl::vector<UUID>> BigFile::GetAssetsHardReferences(eastl::span<
|
||||
|
||||
while (hardReferencesRequest.Step())
|
||||
{
|
||||
const eastl::span<const std::byte, UUID::UUID_BYTE_SIZE> rawOwnerUUID =
|
||||
static_cast<eastl::span<const std::byte>>(hardReferencesRequest.Get(0));
|
||||
const UUID ownerUUID {
|
||||
std::span<const std::byte, UUID::UUID_BYTE_SIZE> {rawOwnerUUID.begin(), rawOwnerUUID.end()}};
|
||||
const std::span<const std::byte, UUID::UUID_BYTE_SIZE> rawOwnerUUID {
|
||||
static_cast<std::span<const std::byte>>(hardReferencesRequest.Get(0))};
|
||||
const UUID ownerUUID {rawOwnerUUID};
|
||||
|
||||
const auto it = uuidToIndices.find(ownerUUID);
|
||||
const auto indicesIt = uuidToIndices.find(ownerUUID);
|
||||
ASSERT(EngineAssertHandler,
|
||||
it != uuidToIndices.end(),
|
||||
indicesIt != uuidToIndices.end(),
|
||||
"Returned UUID {} not found in requested UUIDs",
|
||||
ownerUUID);
|
||||
|
||||
const eastl::span<const std::byte, UUID::UUID_BYTE_SIZE> rawHardReference =
|
||||
static_cast<eastl::span<const std::byte>>(hardReferencesRequest.Get(1));
|
||||
const std::span<const std::byte, UUID::UUID_BYTE_SIZE> rawHardReference {
|
||||
static_cast<std::span<const std::byte>>(hardReferencesRequest.Get(1))};
|
||||
|
||||
for (const std::size_t index: it->second)
|
||||
for (const std::size_t index: indicesIt->second)
|
||||
{
|
||||
hardReferences[index].emplace_back(
|
||||
std::span<const std::byte, UUID::UUID_BYTE_SIZE> {rawHardReference.begin(),
|
||||
rawHardReference.end()});
|
||||
hardReferences[index].emplace_back(rawHardReference);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -342,11 +340,11 @@ eastl::vector<eastl::optional<BigFile::AssetTime>> BigFile::GetAssetsTime(const
|
||||
placeholders += "?";
|
||||
}
|
||||
|
||||
const std::string sql = fmt::format(
|
||||
const eastl::string sql = Format(
|
||||
"SELECT UUID, CreateTime, ModificationTime FROM AssetMetadata WHERE UUID IN ({});",
|
||||
placeholders);
|
||||
|
||||
BigFile::Request timeRequest {*this, sql.c_str()};
|
||||
BigFile::Request timeRequest {*this, sql};
|
||||
for (std::size_t i = 0; i < chunkSize; ++i)
|
||||
{
|
||||
timeRequest.Bind(static_cast<std::uint32_t>(i + 1), distinctUUIDs[chunkStart + i].ToBytes());
|
||||
@@ -354,20 +352,20 @@ eastl::vector<eastl::optional<BigFile::AssetTime>> BigFile::GetAssetsTime(const
|
||||
|
||||
while (timeRequest.Step())
|
||||
{
|
||||
const eastl::span<const std::byte, UUID::UUID_BYTE_SIZE> rawUUID =
|
||||
static_cast<eastl::span<const std::byte>>(timeRequest.Get(0));
|
||||
const UUID uuid {std::span<const std::byte, UUID::UUID_BYTE_SIZE> {rawUUID.begin(), rawUUID.end()}};
|
||||
const std::span<const std::byte, UUID::UUID_BYTE_SIZE> rawUUID {
|
||||
static_cast<std::span<const std::byte>>(timeRequest.Get(0))};
|
||||
const UUID uuid {rawUUID};
|
||||
|
||||
const auto it = uuidToIndices.find(uuid);
|
||||
const auto indicesIt = uuidToIndices.find(uuid);
|
||||
ASSERT(EngineAssertHandler,
|
||||
it != uuidToIndices.end(),
|
||||
indicesIt != uuidToIndices.end(),
|
||||
"Returned UUID {} not found in requested UUIDs",
|
||||
uuid);
|
||||
|
||||
const AssetTime assetTime {.m_creationTime = Time {static_cast<std::uint64_t>(timeRequest.Get(1))},
|
||||
.m_modificationTime = Time {static_cast<std::uint64_t>(timeRequest.Get(2))}};
|
||||
|
||||
for (const std::size_t index: it->second)
|
||||
for (const std::size_t index: indicesIt->second)
|
||||
{
|
||||
times[index] = assetTime;
|
||||
}
|
||||
@@ -403,6 +401,7 @@ void BigFile::SaveAssetFlatbuffer(const UUID& p_uuid,
|
||||
deleteHardReferencesRequest.Execute();
|
||||
|
||||
constexpr std::size_t HARDREF_PARAMS_PER_ROW = 2;
|
||||
constexpr std::size_t HARDREF_PLACEHOLDER_RESERVE_CHARS_PER_ROW = 8;
|
||||
const std::size_t maxHardRefRowsPerStatement = static_cast<std::size_t>(
|
||||
sqlite3_limit(m_db, SQLITE_LIMIT_VARIABLE_NUMBER, -1)) /
|
||||
HARDREF_PARAMS_PER_ROW;
|
||||
@@ -412,7 +411,7 @@ void BigFile::SaveAssetFlatbuffer(const UUID& p_uuid,
|
||||
const std::size_t chunkSize = eastl::min(maxHardRefRowsPerStatement, p_hardReferences.size() - chunkStart);
|
||||
|
||||
eastl::string hardReferencePlaceholders;
|
||||
hardReferencePlaceholders.reserve(chunkSize * 8);
|
||||
hardReferencePlaceholders.reserve(chunkSize * HARDREF_PLACEHOLDER_RESERVE_CHARS_PER_ROW);
|
||||
for (std::size_t i = 0; i < chunkSize; ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
@@ -422,12 +421,11 @@ void BigFile::SaveAssetFlatbuffer(const UUID& p_uuid,
|
||||
hardReferencePlaceholders += "(?, ?)";
|
||||
}
|
||||
|
||||
const std::string hardReferenceSQL = fmt::format(
|
||||
"INSERT INTO AssetHardReference (UUID, HardReference) VALUES {} "
|
||||
"ON CONFLICT(UUID, HardReference) DO NOTHING;",
|
||||
hardReferencePlaceholders);
|
||||
const eastl::string hardReferenceSQL = Format("INSERT INTO AssetHardReference (UUID, HardReference) VALUES {} "
|
||||
"ON CONFLICT(UUID, HardReference) DO NOTHING;",
|
||||
hardReferencePlaceholders);
|
||||
|
||||
BigFile::Request hardReferenceRequest {*this, hardReferenceSQL.c_str()};
|
||||
BigFile::Request hardReferenceRequest {*this, hardReferenceSQL};
|
||||
std::uint32_t bindIndex = 1;
|
||||
for (std::size_t i = 0; i < chunkSize; ++i)
|
||||
{
|
||||
@@ -458,6 +456,8 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span<const UUID> p_uuids,
|
||||
BeginTransaction();
|
||||
|
||||
constexpr std::size_t METADATA_PARAMS_PER_ROW = 4;
|
||||
constexpr std::size_t METADATA_PLACEHOLDER_RESERVE_CHARS_PER_ROW = 14;
|
||||
constexpr std::size_t ASSET_PLACEHOLDER_RESERVE_CHARS_PER_ROW = 8;
|
||||
const std::size_t maxRowsPerStatement = static_cast<std::size_t>(
|
||||
sqlite3_limit(m_db, SQLITE_LIMIT_VARIABLE_NUMBER, -1)) /
|
||||
METADATA_PARAMS_PER_ROW;
|
||||
@@ -467,7 +467,7 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span<const UUID> p_uuids,
|
||||
const std::size_t chunkSize = eastl::min(maxRowsPerStatement, p_uuids.size() - chunkStart);
|
||||
|
||||
eastl::string metadataPlaceholders;
|
||||
metadataPlaceholders.reserve(chunkSize * 14);
|
||||
metadataPlaceholders.reserve(chunkSize * METADATA_PLACEHOLDER_RESERVE_CHARS_PER_ROW);
|
||||
for (std::size_t i = 0; i < chunkSize; ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
@@ -477,11 +477,11 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span<const UUID> p_uuids,
|
||||
metadataPlaceholders += "(?)";
|
||||
}
|
||||
|
||||
const std::string metadataSQL = fmt::format(
|
||||
const eastl::string metadataSQL = Format(
|
||||
"INSERT INTO AssetMetadata (UUID) VALUES {} ON CONFLICT(UUID) DO NOTHING;",
|
||||
metadataPlaceholders);
|
||||
|
||||
BigFile::Request metadataRequest {*this, metadataSQL.c_str()};
|
||||
BigFile::Request metadataRequest {*this, metadataSQL};
|
||||
std::uint32_t metadataBindIndex = 1;
|
||||
for (std::size_t i = 0; i < chunkSize; ++i)
|
||||
{
|
||||
@@ -490,7 +490,7 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span<const UUID> p_uuids,
|
||||
metadataRequest.Execute();
|
||||
|
||||
eastl::string assetPlaceholders;
|
||||
assetPlaceholders.reserve(chunkSize * 8);
|
||||
assetPlaceholders.reserve(chunkSize * ASSET_PLACEHOLDER_RESERVE_CHARS_PER_ROW);
|
||||
for (std::size_t i = 0; i < chunkSize; ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
@@ -500,11 +500,11 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span<const UUID> p_uuids,
|
||||
assetPlaceholders += "(?, ?)";
|
||||
}
|
||||
|
||||
const std::string assetSQL = fmt::format(
|
||||
const eastl::string assetSQL = Format(
|
||||
"INSERT INTO Asset (UUID, Asset) VALUES {} ON CONFLICT(UUID) DO UPDATE SET Asset = excluded.Asset;",
|
||||
assetPlaceholders);
|
||||
|
||||
BigFile::Request assetRequest {*this, assetSQL.c_str()};
|
||||
BigFile::Request assetRequest {*this, assetSQL};
|
||||
std::uint32_t assetBindIndex = 1;
|
||||
for (std::size_t i = 0; i < chunkSize; ++i)
|
||||
{
|
||||
@@ -525,10 +525,10 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span<const UUID> p_uuids,
|
||||
deleteInPlaceholders += "?";
|
||||
}
|
||||
|
||||
const std::string deleteHardReferencesSQL = fmt::format("DELETE FROM AssetHardReference WHERE UUID IN ({});",
|
||||
deleteInPlaceholders);
|
||||
const eastl::string deleteHardReferencesSQL = Format("DELETE FROM AssetHardReference WHERE UUID IN ({});",
|
||||
deleteInPlaceholders);
|
||||
|
||||
BigFile::Request deleteHardReferencesRequest {*this, deleteHardReferencesSQL.c_str()};
|
||||
BigFile::Request deleteHardReferencesRequest {*this, deleteHardReferencesSQL};
|
||||
for (std::size_t i = 0; i < chunkSize; ++i)
|
||||
{
|
||||
deleteHardReferencesRequest.Bind(static_cast<std::uint32_t>(i + 1), p_uuids[chunkStart + i].ToBytes());
|
||||
@@ -545,6 +545,7 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span<const UUID> p_uuids,
|
||||
}
|
||||
|
||||
constexpr std::size_t HARDREF_PARAMS_PER_ROW = 2;
|
||||
constexpr std::size_t HARDREF_PLACEHOLDER_RESERVE_CHARS_PER_ROW = 8;
|
||||
const std::size_t maxHardRefRowsPerStatement = static_cast<std::size_t>(
|
||||
sqlite3_limit(m_db, SQLITE_LIMIT_VARIABLE_NUMBER, -1)) /
|
||||
HARDREF_PARAMS_PER_ROW;
|
||||
@@ -556,7 +557,7 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span<const UUID> p_uuids,
|
||||
hardReferencePairs.size() - hardRefChunkStart);
|
||||
|
||||
eastl::string hardReferencePlaceholders;
|
||||
hardReferencePlaceholders.reserve(hardRefChunkSize * 8);
|
||||
hardReferencePlaceholders.reserve(hardRefChunkSize * HARDREF_PLACEHOLDER_RESERVE_CHARS_PER_ROW);
|
||||
for (std::size_t i = 0; i < hardRefChunkSize; ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
@@ -566,12 +567,12 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span<const UUID> p_uuids,
|
||||
hardReferencePlaceholders += "(?, ?)";
|
||||
}
|
||||
|
||||
const std::string hardReferenceSQL = fmt::format(
|
||||
const eastl::string hardReferenceSQL = Format(
|
||||
"INSERT INTO AssetHardReference (UUID, HardReference) VALUES {} "
|
||||
"ON CONFLICT(UUID, HardReference) DO NOTHING;",
|
||||
hardReferencePlaceholders);
|
||||
|
||||
BigFile::Request hardReferenceRequest {*this, hardReferenceSQL.c_str()};
|
||||
BigFile::Request hardReferenceRequest {*this, hardReferenceSQL};
|
||||
std::uint32_t bindIndex = 1;
|
||||
for (std::size_t i = 0; i < hardRefChunkSize; ++i)
|
||||
{
|
||||
@@ -604,7 +605,7 @@ BigFile::Request::Request(const BigFile& p_bigFile, const eastl::string_view p_r
|
||||
[[maybe_unused]]
|
||||
const int result = sqlite3_prepare_v2(m_db,
|
||||
p_request.data(),
|
||||
static_cast<std::uint32_t>(p_request.size()),
|
||||
static_cast<int>(p_request.size()),
|
||||
&m_statement,
|
||||
nullptr);
|
||||
CRITICAL_ASSERT(EngineAssertHandler,
|
||||
@@ -618,11 +619,11 @@ BigFile::Request::Request(const BigFile& p_bigFile, const eastl::string_view p_r
|
||||
void BigFile::Request::Bind(const std::uint32_t p_index, const std::int32_t p_value)
|
||||
{
|
||||
ASSERT(EngineAssertHandler,
|
||||
(p_index >= 1) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
(p_index >= 1U) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
"Invalid index for statement");
|
||||
|
||||
[[maybe_unused]]
|
||||
const int result = sqlite3_bind_int(m_statement, p_index, p_value);
|
||||
const int result = sqlite3_bind_int(m_statement, static_cast<int>(p_index), p_value);
|
||||
ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db));
|
||||
}
|
||||
|
||||
@@ -631,11 +632,11 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const std::int32_t p_va
|
||||
void BigFile::Request::Bind(const std::uint32_t p_index, const std::uint32_t p_value)
|
||||
{
|
||||
ASSERT(EngineAssertHandler,
|
||||
(p_index >= 1) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
(p_index >= 1U) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
"Invalid index for statement");
|
||||
|
||||
[[maybe_unused]]
|
||||
const int result = sqlite3_bind_int(m_statement, p_index, p_value);
|
||||
const int result = sqlite3_bind_int(m_statement, static_cast<int>(p_index), static_cast<int>(p_value));
|
||||
ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db));
|
||||
}
|
||||
|
||||
@@ -644,11 +645,11 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const std::uint32_t p_v
|
||||
void BigFile::Request::Bind(const std::uint32_t p_index, const std::int64_t p_value)
|
||||
{
|
||||
ASSERT(EngineAssertHandler,
|
||||
(p_index >= 1) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
(p_index >= 1U) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
"Invalid index for statement");
|
||||
|
||||
[[maybe_unused]]
|
||||
const int result = sqlite3_bind_int64(m_statement, p_index, p_value);
|
||||
const int result = sqlite3_bind_int64(m_statement, static_cast<int>(p_index), p_value);
|
||||
ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db));
|
||||
}
|
||||
|
||||
@@ -657,11 +658,11 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const std::int64_t p_va
|
||||
void BigFile::Request::Bind(const std::uint32_t p_index, const std::uint64_t p_value)
|
||||
{
|
||||
ASSERT(EngineAssertHandler,
|
||||
(p_index >= 1) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
(p_index >= 1U) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
"Invalid index for statement");
|
||||
|
||||
[[maybe_unused]]
|
||||
const int result = sqlite3_bind_int64(m_statement, p_index, std::bit_cast<std::int64_t>(p_value));
|
||||
const int result = sqlite3_bind_int64(m_statement, static_cast<int>(p_index), std::bit_cast<std::int64_t>(p_value));
|
||||
ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db));
|
||||
}
|
||||
|
||||
@@ -670,11 +671,11 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const std::uint64_t p_v
|
||||
void BigFile::Request::Bind(const std::uint32_t p_index, const float p_value)
|
||||
{
|
||||
ASSERT(EngineAssertHandler,
|
||||
(p_index >= 1) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
(p_index >= 1U) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
"Invalid index for statement");
|
||||
|
||||
[[maybe_unused]]
|
||||
const int result = sqlite3_bind_double(m_statement, p_index, p_value);
|
||||
const int result = sqlite3_bind_double(m_statement, static_cast<int>(p_index), p_value);
|
||||
ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db));
|
||||
}
|
||||
|
||||
@@ -683,11 +684,11 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const float p_value)
|
||||
void BigFile::Request::Bind(const std::uint32_t p_index, const double p_value)
|
||||
{
|
||||
ASSERT(EngineAssertHandler,
|
||||
(p_index >= 1) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
(p_index >= 1U) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
"Invalid index for statement");
|
||||
|
||||
[[maybe_unused]]
|
||||
const int result = sqlite3_bind_double(m_statement, p_index, p_value);
|
||||
const int result = sqlite3_bind_double(m_statement, static_cast<int>(p_index), p_value);
|
||||
ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db));
|
||||
}
|
||||
|
||||
@@ -696,14 +697,14 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const double p_value)
|
||||
void BigFile::Request::Bind(const std::uint32_t p_index, const eastl::string_view p_value, const CopyValue p_copy)
|
||||
{
|
||||
ASSERT(EngineAssertHandler,
|
||||
(p_index >= 1) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
(p_index >= 1U) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
"Invalid index for statement");
|
||||
|
||||
[[maybe_unused]]
|
||||
const int result = sqlite3_bind_text(m_statement,
|
||||
p_index,
|
||||
static_cast<int>(p_index),
|
||||
p_value.data(),
|
||||
static_cast<std::uint32_t>(p_value.size()),
|
||||
static_cast<int>(p_value.size()),
|
||||
p_copy ? SQLITE_TRANSIENT : SQLITE_STATIC);
|
||||
ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db));
|
||||
}
|
||||
@@ -715,14 +716,14 @@ void BigFile::Request::Bind(const std::uint32_t p_index,
|
||||
const CopyValue p_copy)
|
||||
{
|
||||
ASSERT(EngineAssertHandler,
|
||||
(p_index >= 1) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
(p_index >= 1U) && (p_index <= static_cast<std::uint32_t>(sqlite3_bind_parameter_count(m_statement))),
|
||||
"Invalid index for statement");
|
||||
|
||||
[[maybe_unused]]
|
||||
const int result = sqlite3_bind_blob(m_statement,
|
||||
p_index,
|
||||
static_cast<int>(p_index),
|
||||
p_value.data(),
|
||||
static_cast<std::uint32_t>(p_value.size()),
|
||||
static_cast<int>(p_value.size()),
|
||||
p_copy ? SQLITE_TRANSIENT : SQLITE_STATIC);
|
||||
ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db));
|
||||
}
|
||||
@@ -763,58 +764,69 @@ BigFile::Request::Column::Column(const Request& p_request, const std::uint32_t p
|
||||
|
||||
BigFile::Request::Column::operator std::int32_t() const
|
||||
{
|
||||
return sqlite3_column_int(m_statement, m_index);
|
||||
return sqlite3_column_int(m_statement, static_cast<int>(m_index));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
BigFile::Request::Column::operator std::uint32_t() const
|
||||
{
|
||||
return sqlite3_column_int(m_statement, m_index);
|
||||
return sqlite3_column_int(m_statement, static_cast<int>(m_index));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
BigFile::Request::Column::operator std::int64_t() const
|
||||
{
|
||||
return sqlite3_column_int64(m_statement, m_index);
|
||||
return sqlite3_column_int64(m_statement, static_cast<int>(m_index));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
BigFile::Request::Column::operator std::uint64_t() const
|
||||
{
|
||||
return std::bit_cast<std::uint64_t>(sqlite3_column_int64(m_statement, m_index));
|
||||
return std::bit_cast<std::uint64_t>(sqlite3_column_int64(m_statement, static_cast<int>(m_index)));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
BigFile::Request::Column::operator float() const
|
||||
{
|
||||
return static_cast<float>(sqlite3_column_double(m_statement, m_index));
|
||||
return static_cast<float>(sqlite3_column_double(m_statement, static_cast<int>(m_index)));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
BigFile::Request::Column::operator double() const
|
||||
{
|
||||
return sqlite3_column_double(m_statement, m_index);
|
||||
return sqlite3_column_double(m_statement, static_cast<int>(m_index));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
BigFile::Request::Column::operator eastl::string_view() const
|
||||
{
|
||||
return eastl::string_view {reinterpret_cast<const char*>(sqlite3_column_text(m_statement, m_index)),
|
||||
static_cast<std::size_t>(sqlite3_column_bytes(m_statement, m_index))};
|
||||
return eastl::string_view {
|
||||
reinterpret_cast<const char*>(sqlite3_column_text(m_statement, static_cast<int>(m_index))),
|
||||
static_cast<std::size_t>(sqlite3_column_bytes(m_statement, static_cast<int>(m_index)))};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
BigFile::Request::Column::operator eastl::span<const std::byte>() const
|
||||
{
|
||||
return eastl::span<const std::byte> {static_cast<const std::byte*>(sqlite3_column_blob(m_statement, m_index)),
|
||||
static_cast<std::size_t>(sqlite3_column_bytes(m_statement, m_index))};
|
||||
return eastl::span<const std::byte> {
|
||||
static_cast<const std::byte*>(sqlite3_column_blob(m_statement, static_cast<int>(m_index))),
|
||||
static_cast<std::size_t>(sqlite3_column_bytes(m_statement, static_cast<int>(m_index)))};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
BigFile::Request::Column::operator std::span<const std::byte>() const
|
||||
{
|
||||
return std::span<const std::byte> {
|
||||
static_cast<const std::byte*>(sqlite3_column_blob(m_statement, static_cast<int>(m_index))),
|
||||
static_cast<std::size_t>(sqlite3_column_bytes(m_statement, static_cast<int>(m_index)))};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
@@ -21,4 +21,4 @@ bigfoot_create_package_lib(
|
||||
"${PrivateDependencies}"
|
||||
"${BigfootPublicDependencies}"
|
||||
"${BigfootPrivateDependencies}"
|
||||
"")
|
||||
"Bigfoot/Libs")
|
||||
+34
-98
@@ -6,10 +6,14 @@
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_ENGINE_ASSET_ASSET_HPP
|
||||
#define BIGFOOT_ENGINE_ASSET_ASSET_HPP
|
||||
#include <Engine/Asset/AssetBase.hpp>
|
||||
#include <Engine/Asset/AssetConcepts.hpp>
|
||||
#include <Engine/Asset/Asset_generated.hpp>
|
||||
#include <Engine/Asset/AssetContainer.hpp>
|
||||
#include <Engine/Asset/AssetLibrary.hpp>
|
||||
#include <Engine/EngineAssertHandler.hpp>
|
||||
|
||||
#include <Engine/Asset/Asset_generated.hpp>
|
||||
|
||||
#include <EASTL/span.h>
|
||||
#include <EASTL/vector.h>
|
||||
#include <ankerl/unordered_dense.h>
|
||||
@@ -18,101 +22,12 @@
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class AssetBase
|
||||
{
|
||||
public:
|
||||
virtual ~AssetBase() = default;
|
||||
|
||||
/**
|
||||
* Get the header of the asset
|
||||
*
|
||||
* \return The header of the asset
|
||||
*/
|
||||
[[nodiscard]]
|
||||
virtual const ::Flat::Bigfoot::AssetHeaderT& GetHeader() const = 0;
|
||||
|
||||
/**
|
||||
* Get the HardReferences the flatbuffer has
|
||||
*
|
||||
* \param p_flatbuffer The flatbuffer
|
||||
* \return The UUIDs of the HardReferences
|
||||
*/
|
||||
[[nodiscard]]
|
||||
virtual eastl::vector<UUID> GetHardReferences(const eastl::span<const std::byte> p_flatbuffer) const = 0;
|
||||
|
||||
/**
|
||||
* Unpack a flatbuffer to the asset
|
||||
*
|
||||
* \param p_flatbuffer The flatbuffer to unpack
|
||||
*/
|
||||
virtual void Unpack(const eastl::span<const std::byte> p_flatbuffer) = 0;
|
||||
|
||||
/**
|
||||
* Pack the asset to a flatbuffer
|
||||
*
|
||||
* \return The packed asset
|
||||
*/
|
||||
[[nodiscard]]
|
||||
virtual eastl::vector<std::byte> Pack() const = 0;
|
||||
|
||||
protected:
|
||||
AssetBase() = default;
|
||||
|
||||
AssetBase(const AssetBase& p_asset) = delete;
|
||||
AssetBase(AssetBase&& p_asset) = default;
|
||||
|
||||
AssetBase& operator=(const AssetBase& p_asset) = delete;
|
||||
AssetBase& operator=(AssetBase&& p_asset) = default;
|
||||
|
||||
class HardReferenceVisitor: public flatbuffers::IterationVisitor
|
||||
{
|
||||
public:
|
||||
void Field(size_t p_fieldIndex,
|
||||
size_t p_setIndex,
|
||||
const flatbuffers::ElementaryType p_type,
|
||||
const bool p_isVector,
|
||||
const flatbuffers::TypeTable* p_typeTable,
|
||||
const char* p_name,
|
||||
const std::uint8_t* p_val) override;
|
||||
|
||||
void Element(size_t p_index,
|
||||
const flatbuffers::ElementaryType p_type,
|
||||
const flatbuffers::TypeTable* p_typeTable,
|
||||
const std::uint8_t* p_val) override;
|
||||
|
||||
/**
|
||||
* Get the visited HardReference
|
||||
*
|
||||
* \return The visited HardReferences
|
||||
*/
|
||||
[[nodiscard]]
|
||||
eastl::vector<UUID> GetUUIDs() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Visit an element in the flatbuffer
|
||||
*
|
||||
* \param p_type The element type
|
||||
* \param p_typeTable The element typetable
|
||||
* \param p_val The element
|
||||
*/
|
||||
void Visit(const flatbuffers::ElementaryType p_type,
|
||||
const flatbuffers::TypeTable* p_typeTable,
|
||||
const std::uint8_t* p_val);
|
||||
|
||||
/**
|
||||
* The HardReferences visited so far
|
||||
*/
|
||||
ankerl::unordered_dense::set<UUID> m_uuids;
|
||||
};
|
||||
};
|
||||
|
||||
template<class ASSET>
|
||||
requires AssetTraits<ASSET>
|
||||
class Asset: public AssetBase
|
||||
{
|
||||
public:
|
||||
using FLAT_ASSET = typename ASSET::FLAT;
|
||||
using FLAT_ASSET = ASSET::FLAT;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -153,7 +68,7 @@ class Asset: public AssetBase
|
||||
* \return The asset
|
||||
*/
|
||||
[[nodiscard]]
|
||||
const typename FLAT_ASSET::NativeTableType& GetAsset() const
|
||||
const FLAT_ASSET::NativeTableType& GetAsset() const
|
||||
{
|
||||
return m_asset;
|
||||
}
|
||||
@@ -164,7 +79,7 @@ class Asset: public AssetBase
|
||||
* \return The asset
|
||||
*/
|
||||
[[nodiscard]]
|
||||
typename FLAT_ASSET::NativeTableType& GetAsset()
|
||||
FLAT_ASSET::NativeTableType& GetAsset()
|
||||
{
|
||||
return m_asset;
|
||||
}
|
||||
@@ -177,7 +92,8 @@ class Asset: public AssetBase
|
||||
void Unpack(const eastl::span<const std::byte> p_flatbuffer) override
|
||||
{
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
flatbuffers::Verifier verifier {std::bit_cast<std::uint8_t*>(p_flatbuffer.data()), p_flatbuffer.size()};
|
||||
flatbuffers::Verifier verifier {reinterpret_cast<const std::uint8_t*>(p_flatbuffer.data()),
|
||||
p_flatbuffer.size()};
|
||||
const bool assetVerified = ::Flat::Bigfoot::VerifyAssetBuffer(verifier);
|
||||
CRITICAL_ASSERT(EngineAssertHandler, assetVerified, "Given asset could not be verified!");
|
||||
#endif
|
||||
@@ -210,8 +126,9 @@ class Asset: public AssetBase
|
||||
const auto innerAsset = assetFbb.CreateVector(innerAssetFbb.GetBufferPointer(), innerAssetFbb.GetSize());
|
||||
assetFbb.Finish(::Flat::Bigfoot::CreateAsset(assetFbb, header, innerAsset));
|
||||
|
||||
return eastl::vector<std::byte> {std::bit_cast<std::byte*>(assetFbb.GetBufferPointer()),
|
||||
std::bit_cast<std::byte*>(assetFbb.GetBufferPointer() + assetFbb.GetSize())};
|
||||
return eastl::vector<std::byte> {
|
||||
reinterpret_cast<std::byte*>(assetFbb.GetBufferPointer()),
|
||||
reinterpret_cast<std::byte*>(assetFbb.GetBufferPointer() + assetFbb.GetSize())};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,7 +141,8 @@ class Asset: public AssetBase
|
||||
eastl::vector<UUID> GetHardReferences(const eastl::span<const std::byte> p_flatbuffer) const override
|
||||
{
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
flatbuffers::Verifier verifier {std::bit_cast<std::uint8_t*>(p_flatbuffer.data()), p_flatbuffer.size()};
|
||||
flatbuffers::Verifier verifier {reinterpret_cast<const std::uint8_t*>(p_flatbuffer.data()),
|
||||
p_flatbuffer.size()};
|
||||
const bool assetVerified = ::Flat::Bigfoot::VerifyAssetBuffer(verifier);
|
||||
CRITICAL_ASSERT(EngineAssertHandler, assetVerified, "Given asset could not be verified!");
|
||||
#endif
|
||||
@@ -271,12 +189,30 @@ class Asset: public AssetBase
|
||||
/**
|
||||
* The asset
|
||||
*/
|
||||
typename FLAT_ASSET::NativeTableType m_asset;
|
||||
FLAT_ASSET::NativeTableType m_asset;
|
||||
/**
|
||||
* The asset header
|
||||
*/
|
||||
::Flat::Bigfoot::AssetHeaderT m_header;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create an asset and insert it into its corresponding AssetContainer
|
||||
*
|
||||
* \tparam ASSET The Asset type
|
||||
* \return The created asset, nullptr if no AssetContainer is registered for ASSET
|
||||
*/
|
||||
template<class ASSET>
|
||||
requires AssetType<ASSET>
|
||||
[[nodiscard]]
|
||||
ASSET* CreateAsset()
|
||||
{
|
||||
AssetContainerBase* container = g_activeAssetLibrary->GetAssetContainer(ASSET::GetTypeID());
|
||||
CRITICAL_ASSERT(EngineAssertHandler, container != nullptr, "No AssetContainer registered for this asset type!");
|
||||
|
||||
ContainerHandle* handle = container->Insert();
|
||||
return static_cast<ASSET*>(handle->GetAsset());
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,111 @@
|
||||
/*********************************************************************
|
||||
* \file AssetBase.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date April 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_ENGINE_ASSET_ASSETBASE_HPP
|
||||
#define BIGFOOT_ENGINE_ASSET_ASSETBASE_HPP
|
||||
#include <System/UUID/UUID.hpp>
|
||||
|
||||
#include <Engine/Asset/Asset_generated.hpp>
|
||||
|
||||
#include <EASTL/span.h>
|
||||
#include <EASTL/vector.h>
|
||||
#include <ankerl/unordered_dense.h>
|
||||
#include <flatbuffers/minireflect.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class AssetBase
|
||||
{
|
||||
public:
|
||||
virtual ~AssetBase() = default;
|
||||
|
||||
/**
|
||||
* Get the header of the asset
|
||||
*
|
||||
* \return The header of the asset
|
||||
*/
|
||||
[[nodiscard]]
|
||||
virtual const ::Flat::Bigfoot::AssetHeaderT& GetHeader() const = 0;
|
||||
|
||||
/**
|
||||
* Get the HardReferences the flatbuffer has
|
||||
*
|
||||
* \param p_flatbuffer The flatbuffer
|
||||
* \return The UUIDs of the HardReferences
|
||||
*/
|
||||
[[nodiscard]]
|
||||
virtual eastl::vector<UUID> GetHardReferences(const eastl::span<const std::byte> p_flatbuffer) const = 0;
|
||||
|
||||
/**
|
||||
* Unpack a flatbuffer to the asset
|
||||
*
|
||||
* \param p_flatbuffer The flatbuffer to unpack
|
||||
*/
|
||||
virtual void Unpack(const eastl::span<const std::byte> p_flatbuffer) = 0;
|
||||
|
||||
/**
|
||||
* Pack the asset to a flatbuffer
|
||||
*
|
||||
* \return The packed asset
|
||||
*/
|
||||
[[nodiscard]]
|
||||
virtual eastl::vector<std::byte> Pack() const = 0;
|
||||
|
||||
AssetBase(const AssetBase& p_asset) = delete;
|
||||
AssetBase& operator=(const AssetBase& p_asset) = delete;
|
||||
|
||||
protected:
|
||||
AssetBase() = default;
|
||||
|
||||
AssetBase(AssetBase&& p_asset) = default;
|
||||
|
||||
AssetBase& operator=(AssetBase&& p_asset) = default;
|
||||
|
||||
class HardReferenceVisitor: public flatbuffers::IterationVisitor
|
||||
{
|
||||
public:
|
||||
void Field(size_t p_fieldIndex,
|
||||
size_t p_setIndex,
|
||||
const flatbuffers::ElementaryType p_type,
|
||||
const bool p_isVector,
|
||||
const flatbuffers::TypeTable* p_typeTable,
|
||||
const char* p_name,
|
||||
const std::uint8_t* p_val) override;
|
||||
|
||||
void Element(size_t p_index,
|
||||
const flatbuffers::ElementaryType p_type,
|
||||
const flatbuffers::TypeTable* p_typeTable,
|
||||
const std::uint8_t* p_val) override;
|
||||
|
||||
/**
|
||||
* Get the visited HardReference
|
||||
*
|
||||
* \return The visited HardReferences
|
||||
*/
|
||||
[[nodiscard]]
|
||||
eastl::vector<UUID> GetUUIDs() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Visit an element in the flatbuffer
|
||||
*
|
||||
* \param p_type The element type
|
||||
* \param p_typeTable The element typetable
|
||||
* \param p_val The element
|
||||
*/
|
||||
void Visit(const flatbuffers::ElementaryType p_type,
|
||||
const flatbuffers::TypeTable* p_typeTable,
|
||||
const std::uint8_t* p_val);
|
||||
|
||||
/**
|
||||
* The HardReferences visited so far
|
||||
*/
|
||||
ankerl::unordered_dense::set<UUID> m_uuids;
|
||||
};
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif
|
||||
+10
-9
@@ -6,7 +6,7 @@
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_ENGINE_ASSET_ASSETCONTAINER_HPP
|
||||
#define BIGFOOT_ENGINE_ASSET_ASSETCONTAINER_HPP
|
||||
#include <Engine/Asset/Asset.hpp>
|
||||
#include <Engine/Asset/AssetBase.hpp>
|
||||
#include <Engine/Asset/AssetConcepts.hpp>
|
||||
#include <Engine/EngineAssertHandler.hpp>
|
||||
|
||||
@@ -27,11 +27,11 @@ class ContainerHandle
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param p_assetContainer The originating assetcontainer
|
||||
* \param p_uuid The UUID of tha asset
|
||||
*/
|
||||
* Constructor
|
||||
*
|
||||
* \param p_assetContainer The originating assetcontainer
|
||||
* \param p_uuid The UUID of tha asset
|
||||
*/
|
||||
ContainerHandle(AssetContainerBase* p_assetContainer, const UUID p_uuid);
|
||||
|
||||
/*
|
||||
@@ -200,8 +200,12 @@ class AssetContainerBase
|
||||
[[nodiscard]]
|
||||
bool IsMarkedForRemove(const UUID& p_uuid);
|
||||
|
||||
AssetContainerBase& operator=(const AssetContainerBase& p_container) = delete;
|
||||
AssetContainerBase& operator=(AssetContainerBase&& p_container) = delete;
|
||||
|
||||
AssetContainerBase(const AssetContainerBase& p_container) = delete;
|
||||
AssetContainerBase(AssetContainerBase&& p_container) = delete;
|
||||
|
||||
protected:
|
||||
struct Entry
|
||||
{
|
||||
@@ -223,8 +227,6 @@ class AssetContainerBase
|
||||
|
||||
AssetContainerBase() = default;
|
||||
|
||||
AssetContainerBase(AssetContainerBase&& p_container) = delete;
|
||||
|
||||
/*
|
||||
* Finds an entry matching the Asset
|
||||
*
|
||||
@@ -352,7 +354,6 @@ class AssetContainer: public AssetContainerBase
|
||||
m_assets.Remove(p_key);
|
||||
}
|
||||
|
||||
private:
|
||||
/*
|
||||
* The assets
|
||||
*/
|
||||
+4
-3
@@ -19,13 +19,14 @@
|
||||
return AssetType::GetTypeID(); \
|
||||
} \
|
||||
AssetContainer<AssetType> g_containerFor##AssetName; \
|
||||
const bool g_insertedContainerFor##AssetName = []() \
|
||||
bool RegisterAssetContainerFor##AssetName() \
|
||||
{ \
|
||||
const bool inserted = g_assetLibrary.Insert(&g_containerFor##AssetName); \
|
||||
const bool inserted = g_assetLibrary->Insert(&g_containerFor##AssetName); \
|
||||
CRITICAL_ASSERT(EngineAssertHandler, \
|
||||
inserted, \
|
||||
"AssetTypeID collision or duplicate registration for asset type '" #AssetName "'"); \
|
||||
return inserted; \
|
||||
}(); \
|
||||
} \
|
||||
const bool g_insertedContainerFor##AssetName = RegisterAssetContainerFor##AssetName(); \
|
||||
}
|
||||
#endif
|
||||
+45
-5
@@ -10,6 +10,8 @@
|
||||
#include <Engine/Asset/AssetContainer.hpp>
|
||||
#include <Engine/Asset/AssetTypeID.hpp>
|
||||
|
||||
#include <Utils/LazyGlobal.hpp>
|
||||
|
||||
#include <ankerl/unordered_dense.h>
|
||||
|
||||
namespace Bigfoot
|
||||
@@ -91,14 +93,16 @@ class AssetLibrary
|
||||
bool IsLoaded(const UUID& p_uuid) const;
|
||||
|
||||
/**
|
||||
* Loop through the AssetContainers to remove the pending assets marked for removal
|
||||
*
|
||||
*/
|
||||
* Loop through the AssetContainers to remove the pending assets marked for removal
|
||||
*
|
||||
*/
|
||||
void ProcessPendingRemovals();
|
||||
|
||||
AssetLibrary& operator=(const AssetLibrary& p_library) = default;
|
||||
AssetLibrary& operator=(AssetLibrary&& p_library) = delete;
|
||||
|
||||
~AssetLibrary() = default;
|
||||
|
||||
private:
|
||||
// All the asset containers
|
||||
ankerl::unordered_dense::map<AssetTypeID, AssetContainerBase*> m_assetContainers;
|
||||
@@ -107,8 +111,44 @@ class AssetLibrary
|
||||
/****************************************************************************************/
|
||||
|
||||
// The global asset library for Bigfoot
|
||||
inline AssetLibrary g_assetLibrary;
|
||||
inline AssetLibrary* g_activeAssetLibrary = &g_assetLibrary;
|
||||
inline LazyGlobal<AssetLibrary> g_assetLibrary;
|
||||
|
||||
class ActiveAssetLibrary
|
||||
{
|
||||
public:
|
||||
ActiveAssetLibrary& operator=(AssetLibrary* p_assetLibrary)
|
||||
{
|
||||
Get() = p_assetLibrary;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
AssetLibrary* operator->() const
|
||||
{
|
||||
return Get();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
operator AssetLibrary*() const
|
||||
{
|
||||
return Get();
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Get the ActiveAssetLibrary
|
||||
*
|
||||
* \return The ActiveAssetLibrary
|
||||
*/
|
||||
[[nodiscard]]
|
||||
static AssetLibrary*& Get()
|
||||
{
|
||||
static AssetLibrary* activeLibrary = g_assetLibrary;
|
||||
return activeLibrary;
|
||||
}
|
||||
};
|
||||
|
||||
inline ActiveAssetLibrary g_activeAssetLibrary;
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
+2
-5
@@ -15,13 +15,10 @@ using AssetTypeID = std::uint64_t;
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
namespace Flat
|
||||
{
|
||||
namespace Bigfoot
|
||||
namespace Flat::Bigfoot
|
||||
{
|
||||
struct AssetTypeID;
|
||||
}
|
||||
} // namespace Flat
|
||||
} // namespace Flat::Bigfoot
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
+3
-3
@@ -94,7 +94,9 @@ class ReferenceBase
|
||||
return m_uuid == p_reference.m_uuid;
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
friend DERIVED;
|
||||
|
||||
ReferenceBase() = default;
|
||||
|
||||
ReferenceBase(const UUID& p_uuid):
|
||||
@@ -116,7 +118,6 @@ class ReferenceBase
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Get the associated handle container for the asset
|
||||
* Register the reference inside the handle
|
||||
@@ -152,7 +153,6 @@ class ReferenceBase
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* The UUID
|
||||
*/
|
||||
+13
-3
@@ -15,8 +15,11 @@
|
||||
|
||||
#include <EASTL/optional.h>
|
||||
#include <EASTL/span.h>
|
||||
#include <EASTL/string_view.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include <span>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
#ifdef BIGFOOT_TOOLMODE
|
||||
@@ -57,7 +60,7 @@ class BigFile: public DataAccessor
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
~BigFile();
|
||||
~BigFile() override;
|
||||
|
||||
/**
|
||||
* Get an Asset flatbuffer
|
||||
@@ -325,6 +328,13 @@ class BigFile: public DataAccessor
|
||||
*/
|
||||
operator eastl::span<const std::byte>() const;
|
||||
|
||||
/*
|
||||
* Get value as a blob
|
||||
*
|
||||
* \return The value
|
||||
*/
|
||||
operator std::span<const std::byte>() const;
|
||||
|
||||
private:
|
||||
/*
|
||||
* The statement
|
||||
@@ -359,14 +369,14 @@ class BigFile: public DataAccessor
|
||||
/*
|
||||
* The statement
|
||||
*/
|
||||
sqlite3_stmt* m_statement;
|
||||
sqlite3_stmt* m_statement = nullptr;
|
||||
};
|
||||
|
||||
private:
|
||||
/**
|
||||
* The BigFile DB
|
||||
*/
|
||||
sqlite3* m_db;
|
||||
sqlite3* m_db = nullptr;
|
||||
};
|
||||
#endif
|
||||
} // namespace Bigfoot
|
||||
+3
-3
@@ -6,11 +6,11 @@
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_ENGINE_ENGINEASSERTHANDLER_HPP
|
||||
#define BIGFOOT_ENGINE_ENGINEASSERTHANDLER_HPP
|
||||
#include <Engine/EngineLogger_generated.hpp>
|
||||
|
||||
#include <Utils/Assert/AssertHandler.hpp>
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
#include <Engine/EngineLogger_generated.hpp>
|
||||
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
+1
-1
@@ -15,7 +15,7 @@ namespace Bigfoot
|
||||
/*
|
||||
* Logger
|
||||
*/
|
||||
inline Log::LoggerInfo ENGINE_LOGGER {"ENGINE_LOGGER", Flat::LogLevel::Trace};
|
||||
inline Log::LoggerInfo ENGINE_LOGGER { .m_name = "ENGINE_LOGGER", .m_level = LogLevel::Trace};
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
#endif
|
||||
+8
-2
@@ -95,7 +95,7 @@ class SasquatchWriter
|
||||
SasquatchWriter& operator=(SasquatchWriter&& p_writer) = delete;
|
||||
|
||||
private:
|
||||
static constexpr std::uint64_t PREFETCH_BYTES = 4 * 1024 * 1024;
|
||||
static constexpr std::uint64_t PREFETCH_BYTES = 4ULL * 1024 * 1024;
|
||||
|
||||
/**
|
||||
* The number of assets expected
|
||||
@@ -105,7 +105,12 @@ class SasquatchWriter
|
||||
/**
|
||||
* How far into m_file has already been prefetched
|
||||
*/
|
||||
std::size_t m_prefetchedUpTo;
|
||||
std::size_t m_prefetchedUpTo = 0;
|
||||
|
||||
/**
|
||||
* Current write position in the data region
|
||||
*/
|
||||
std::size_t m_currentDataOffset;
|
||||
|
||||
/**
|
||||
* The Sasquatch file being written, mapped at its final size
|
||||
@@ -140,6 +145,7 @@ class Sasquatch: public DataAccessor
|
||||
*
|
||||
* \return The header
|
||||
*/
|
||||
[[nodiscard]]
|
||||
const SasquatchHeader& GetHeader() const;
|
||||
|
||||
/**
|
||||
+1
-1
@@ -28,7 +28,7 @@ void LoadAsset(const UUID& p_uuid);
|
||||
*/
|
||||
void LoadAssets(const eastl::span<const UUID> p_uuids);
|
||||
|
||||
#if defined BIGFOOT_TOOLMODE
|
||||
#ifdef BIGFOOT_TOOLMODE
|
||||
/**
|
||||
* Save an Asset
|
||||
* Fails without saving if a cyclic dependency is detected starting from this asset
|
||||
+19
-24
@@ -19,9 +19,9 @@ SasquatchWriter::SasquatchWriter(const File& p_file,
|
||||
const std::size_t p_totalFlatbufferBytes,
|
||||
const std::size_t p_totalHardReferencesBytes):
|
||||
m_assetCount(p_assetCount),
|
||||
m_prefetchedUpTo(0),
|
||||
m_currentDataOffset(sizeof(SasquatchHeader) + (m_assetCount * sizeof(SasquatchEntry))),
|
||||
m_file(p_file,
|
||||
sizeof(SasquatchHeader) + m_assetCount * sizeof(SasquatchEntry) + p_totalFlatbufferBytes +
|
||||
sizeof(SasquatchHeader) + (m_assetCount * sizeof(SasquatchEntry)) + p_totalFlatbufferBytes +
|
||||
p_totalHardReferencesBytes)
|
||||
{
|
||||
m_entries.reserve(m_assetCount);
|
||||
@@ -63,21 +63,15 @@ void SasquatchWriter::WriteAsset(const UUID& p_uuid,
|
||||
"SasquatchWriter can only hold {} assets",
|
||||
m_assetCount);
|
||||
|
||||
const std::size_t offset = std::accumulate(m_entries.begin(),
|
||||
m_entries.end(),
|
||||
sizeof(SasquatchHeader) + m_assetCount * sizeof(SasquatchEntry),
|
||||
[](const std::size_t p_value, const SasquatchEntry& p_entry)
|
||||
{
|
||||
return p_value + p_entry.m_assetSize + p_entry.m_hardReferencesSize;
|
||||
});
|
||||
const std::size_t offset = m_currentDataOffset;
|
||||
|
||||
const eastl::span<std::byte> data = m_file.GetData();
|
||||
ASSERT(EngineAssertHandler,
|
||||
offset + p_flatbuffer.size() + p_hardReferences.size() * UUID::UUID_BYTE_SIZE <= data.size(),
|
||||
offset + p_flatbuffer.size() + (p_hardReferences.size() * UUID::UUID_BYTE_SIZE) <= data.size(),
|
||||
"SasquatchWriter can only write {} bytes",
|
||||
data.size());
|
||||
|
||||
const std::size_t writeEnd = offset + p_flatbuffer.size() + p_hardReferences.size() * UUID::UUID_BYTE_SIZE;
|
||||
const std::size_t writeEnd = offset + p_flatbuffer.size() + (p_hardReferences.size() * UUID::UUID_BYTE_SIZE);
|
||||
if (writeEnd > m_prefetchedUpTo)
|
||||
{
|
||||
const std::size_t prefetchEnd = std::min(writeEnd + PREFETCH_BYTES, data.size());
|
||||
@@ -97,11 +91,12 @@ void SasquatchWriter::WriteAsset(const UUID& p_uuid,
|
||||
for (std::uint32_t i = 0; i < p_hardReferences.size(); ++i)
|
||||
{
|
||||
const std::span<const std::byte, UUID::UUID_BYTE_SIZE> rawUUID = p_hardReferences[i].ToBytes();
|
||||
std::memcpy(data.data() + entry.m_hardReferencesOffset + i * UUID::UUID_BYTE_SIZE,
|
||||
std::memcpy(data.data() + entry.m_hardReferencesOffset + (static_cast<std::size_t>(i) * UUID::UUID_BYTE_SIZE),
|
||||
rawUUID.data(),
|
||||
UUID::UUID_BYTE_SIZE);
|
||||
}
|
||||
|
||||
m_currentDataOffset += entry.m_assetSize + entry.m_hardReferencesSize;
|
||||
m_entries.push_back(entry);
|
||||
}
|
||||
|
||||
@@ -133,11 +128,11 @@ Sasquatch::Sasquatch(const File& p_file):
|
||||
SasquatchHeader::VERSION);
|
||||
|
||||
CRITICAL_ASSERT(EngineAssertHandler,
|
||||
data.size() >= sizeof(SasquatchHeader) + m_header.m_assetCount * sizeof(SasquatchEntry),
|
||||
data.size() >= sizeof(SasquatchHeader) + (m_header.m_assetCount * sizeof(SasquatchEntry)),
|
||||
"Sasquatch file {} index is truncated (got {} / expected at least {})",
|
||||
p_file.GetPath(),
|
||||
data.size(),
|
||||
sizeof(SasquatchHeader) + m_header.m_assetCount * sizeof(SasquatchEntry));
|
||||
sizeof(SasquatchHeader) + (m_header.m_assetCount * sizeof(SasquatchEntry)));
|
||||
|
||||
eastl::vector<SasquatchEntry> entries(m_header.m_assetCount);
|
||||
if (!entries.empty())
|
||||
@@ -172,15 +167,15 @@ const SasquatchHeader& Sasquatch::GetHeader() const
|
||||
|
||||
eastl::vector<std::byte> Sasquatch::GetAssetFlatbuffer(const UUID& p_uuid) const
|
||||
{
|
||||
const auto it = m_entries.find(p_uuid);
|
||||
if (it == m_entries.end())
|
||||
const auto entryIt = m_entries.find(p_uuid);
|
||||
if (entryIt == m_entries.end())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
const eastl::span<const std::byte> data = m_file.GetData();
|
||||
const eastl::span<const std::byte> bytes {data.data() + it->second.m_assetOffset,
|
||||
static_cast<std::size_t>(it->second.m_assetSize)};
|
||||
const eastl::span<const std::byte> bytes {data.data() + entryIt->second.m_assetOffset,
|
||||
static_cast<std::size_t>(entryIt->second.m_assetSize)};
|
||||
return eastl::vector<std::byte> {bytes.begin(), bytes.end()};
|
||||
}
|
||||
|
||||
@@ -205,15 +200,15 @@ eastl::vector<UUID> Sasquatch::GetAssetHardReferences(const UUID& p_uuid) const
|
||||
{
|
||||
eastl::vector<UUID> hardReferences;
|
||||
|
||||
const auto it = m_entries.find(p_uuid);
|
||||
if (it == m_entries.end())
|
||||
const auto entryIt = m_entries.find(p_uuid);
|
||||
if (entryIt == m_entries.end())
|
||||
{
|
||||
return hardReferences;
|
||||
}
|
||||
|
||||
const eastl::span<const std::byte> data = m_file.GetData();
|
||||
const eastl::span<const std::byte> bytes {data.data() + it->second.m_hardReferencesOffset,
|
||||
static_cast<std::size_t>(it->second.m_hardReferencesSize)};
|
||||
const eastl::span<const std::byte> bytes {data.data() + entryIt->second.m_hardReferencesOffset,
|
||||
static_cast<std::size_t>(entryIt->second.m_hardReferencesSize)};
|
||||
|
||||
const std::size_t hardReferenceCount = bytes.size() / UUID::UUID_BYTE_SIZE;
|
||||
hardReferences.reserve(hardReferenceCount);
|
||||
@@ -221,7 +216,7 @@ eastl::vector<UUID> Sasquatch::GetAssetHardReferences(const UUID& p_uuid) const
|
||||
for (std::size_t i = 0; i < hardReferenceCount; ++i)
|
||||
{
|
||||
std::array<std::byte, UUID::UUID_BYTE_SIZE> rawUUID;
|
||||
std::memcpy(rawUUID.data(), bytes.data() + i * UUID::UUID_BYTE_SIZE, UUID::UUID_BYTE_SIZE);
|
||||
std::memcpy(rawUUID.data(), bytes.data() + (i * UUID::UUID_BYTE_SIZE), UUID::UUID_BYTE_SIZE);
|
||||
hardReferences.emplace_back(rawUUID);
|
||||
}
|
||||
|
||||
@@ -265,7 +260,7 @@ void Sasquatch::SaveAssetFlatbuffers([[maybe_unused]] const eastl::span<const UU
|
||||
|
||||
bool Sasquatch::Has(const UUID& p_uuid) const
|
||||
{
|
||||
return m_entries.find(p_uuid) != m_entries.end();
|
||||
return m_entries.contains(p_uuid);
|
||||
}
|
||||
#endif
|
||||
} // namespace Bigfoot
|
||||
+10
-43
@@ -95,7 +95,8 @@ void LoadAssets(const eastl::span<const UUID> p_uuids)
|
||||
}
|
||||
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
flatbuffers::Verifier verifier {std::bit_cast<std::uint8_t*>(flatbuffer.data()), flatbuffer.size()};
|
||||
flatbuffers::Verifier verifier {reinterpret_cast<const std::uint8_t*>(flatbuffer.data()),
|
||||
flatbuffer.size()};
|
||||
const bool assetVerified = ::Flat::Bigfoot::VerifyAssetBuffer(verifier);
|
||||
CRITICAL_ASSERT(EngineAssertHandler, assetVerified, "Given asset could not be verified!");
|
||||
#endif
|
||||
@@ -104,6 +105,10 @@ void LoadAssets(const eastl::span<const UUID> p_uuids)
|
||||
|
||||
AssetContainerBase* container = g_activeAssetLibrary->GetAssetContainer(
|
||||
flatbuffers::UnPack(*asset->header()->type_id()));
|
||||
CRITICAL_ASSERT(EngineAssertHandler,
|
||||
container != nullptr,
|
||||
"No AssetContainer registered for asset {}",
|
||||
wave[i]);
|
||||
std::ignore = container->Insert(flatbuffer);
|
||||
}
|
||||
}
|
||||
@@ -113,52 +118,12 @@ void LoadAssets(const eastl::span<const UUID> p_uuids)
|
||||
|
||||
void LoadAsset(const UUID& p_uuid)
|
||||
{
|
||||
ankerl::unordered_dense::set<UUID> discovered;
|
||||
const ankerl::unordered_dense::map<UUID, eastl::vector<UUID>> graph = BuildDependencyGraph(
|
||||
eastl::span<const UUID> {&p_uuid, 1},
|
||||
discovered);
|
||||
|
||||
// Assets that are part of a cyclic HardReference dependency are left out of waves and simply never loaded.
|
||||
eastl::vector<eastl::vector<UUID>> waves;
|
||||
eastl::vector<UUID> cyclicUuids;
|
||||
std::ignore = LayeredTopologicalSort(graph, discovered, waves, cyclicUuids);
|
||||
BIGFOOT_LOG_ERROR_IF(!cyclicUuids.empty(),
|
||||
ENGINE_LOGGER,
|
||||
"Cyclic HardReference dependency detected while loading asset {}, involved UUIDs: {}",
|
||||
p_uuid,
|
||||
cyclicUuids);
|
||||
|
||||
// Waves are loaded one after another since a wave's assets may HardReference the previous wave's; within a
|
||||
// wave, every asset is independent of the others, so this is where loading could later be parallelized.
|
||||
for (const eastl::vector<UUID>& wave: waves)
|
||||
{
|
||||
for (const UUID& uuid: wave)
|
||||
{
|
||||
const eastl::vector<std::byte> flatbuffer = g_dataAccessor->GetAssetFlatbuffer(uuid);
|
||||
if (flatbuffer.empty())
|
||||
{
|
||||
BIGFOOT_LOG_ERROR(ENGINE_LOGGER, "Asset {} could not be found while loading, skipping it", uuid);
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
flatbuffers::Verifier verifier {std::bit_cast<std::uint8_t*>(flatbuffer.data()), flatbuffer.size()};
|
||||
const bool assetVerified = ::Flat::Bigfoot::VerifyAssetBuffer(verifier);
|
||||
CRITICAL_ASSERT(EngineAssertHandler, assetVerified, "Given asset could not be verified!");
|
||||
#endif
|
||||
|
||||
const ::Flat::Bigfoot::Asset* asset = flatbuffers::GetRoot<::Flat::Bigfoot::Asset>(flatbuffer.data());
|
||||
|
||||
AssetContainerBase* container = g_activeAssetLibrary->GetAssetContainer(
|
||||
flatbuffers::UnPack(*asset->header()->type_id()));
|
||||
std::ignore = container->Insert(flatbuffer);
|
||||
}
|
||||
}
|
||||
LoadAssets(eastl::span<const UUID> {&p_uuid, 1});
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
#if defined BIGFOOT_TOOLMODE
|
||||
#ifdef BIGFOOT_TOOLMODE
|
||||
/*
|
||||
* Finds the cyclic dependencies that may exist in Assets
|
||||
*
|
||||
@@ -223,6 +188,7 @@ eastl::vector<UUID> FindCyclicDependencies(const eastl::span<const UUID> p_uuids
|
||||
bool SaveAsset(const UUID& p_uuid)
|
||||
{
|
||||
AssetContainerBase* container = g_activeAssetLibrary->GetAssetContainer(p_uuid);
|
||||
CRITICAL_ASSERT(EngineAssertHandler, container != nullptr, "No AssetContainer registered for asset {}", p_uuid);
|
||||
const AssetBase* asset = container->AcquireContainerHandle(p_uuid)->GetAsset();
|
||||
|
||||
const eastl::vector<std::byte> flatbuffer = asset->Pack();
|
||||
@@ -257,6 +223,7 @@ bool SaveAssets(const eastl::span<const UUID> p_uuids)
|
||||
for (const UUID& uuid: p_uuids)
|
||||
{
|
||||
AssetContainerBase* container = g_activeAssetLibrary->GetAssetContainer(uuid);
|
||||
CRITICAL_ASSERT(EngineAssertHandler, container != nullptr, "No AssetContainer registered for asset {}", uuid);
|
||||
const AssetBase* asset = container->AcquireContainerHandle(uuid)->GetAsset();
|
||||
|
||||
const eastl::vector<std::byte> flatbuffer = asset->Pack();
|
||||
@@ -0,0 +1,5 @@
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/GraphicsInterface)
|
||||
if(${VULKAN})
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/GraphicsVulkan)
|
||||
endif()
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/GraphicsCore)
|
||||
@@ -0,0 +1,18 @@
|
||||
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
project(${PackageName})
|
||||
|
||||
set(PublicDependencies)
|
||||
set(PrivateDependencies)
|
||||
set(BigfootPublicDependencies
|
||||
GraphicsVulkan
|
||||
Engine)
|
||||
set(BigfootPrivateDependencies)
|
||||
|
||||
bigfoot_create_package_lib(
|
||||
"${PublicDependencies}"
|
||||
"${PrivateDependencies}"
|
||||
"${BigfootPublicDependencies}"
|
||||
"${BigfootPrivateDependencies}"
|
||||
"Bigfoot/Libs/Graphics")
|
||||
|
||||
bigfoot_create_logger()
|
||||
@@ -0,0 +1,71 @@
|
||||
/*********************************************************************
|
||||
* \file GraphicsContext.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#include <GraphicsCore/GraphicsContext.hpp>
|
||||
|
||||
#include <GraphicsCore/GraphicsCoreAssertHandler.hpp>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
GraphicsContext::GraphicsContext(const GraphicsContextCreateInfo& p_createInfo)
|
||||
{
|
||||
m_instance = g_graphicsInstanceFactory->Create(p_createInfo.m_api,
|
||||
p_createInfo.m_applicationName,
|
||||
p_createInfo.m_applicationVersion);
|
||||
CRITICAL_ASSERT(GraphicsCoreAssertHandler,
|
||||
m_instance != nullptr,
|
||||
"No graphics instance registered for GraphicsAPI '{}'",
|
||||
EnumNameGraphicsAPI(p_createInfo.m_api));
|
||||
|
||||
m_surface = g_graphicsSurfaceFactory->Create(p_createInfo.m_api, *m_instance, p_createInfo.m_surfaceCreateInfo);
|
||||
CRITICAL_ASSERT(GraphicsCoreAssertHandler,
|
||||
m_surface != nullptr,
|
||||
"No graphics surface registered for GraphicsAPI '{}'",
|
||||
EnumNameGraphicsAPI(p_createInfo.m_api));
|
||||
|
||||
const DeviceCreateInfo deviceCreateInfo {p_createInfo.m_deviceNameHint, m_surface.get()};
|
||||
m_device = g_graphicsDeviceFactory->Create(p_createInfo.m_api, *m_instance, deviceCreateInfo);
|
||||
CRITICAL_ASSERT(GraphicsCoreAssertHandler,
|
||||
m_device != nullptr,
|
||||
"No graphics device registered for GraphicsAPI '{}'",
|
||||
EnumNameGraphicsAPI(p_createInfo.m_api));
|
||||
|
||||
const SwapchainCreateInfo swapchainCreateInfo {m_device.get(), m_surface.get(), p_createInfo.m_extent};
|
||||
m_swapchain = g_graphicsSwapchainFactory->Create(p_createInfo.m_api, swapchainCreateInfo);
|
||||
CRITICAL_ASSERT(GraphicsCoreAssertHandler,
|
||||
m_swapchain != nullptr,
|
||||
"No graphics swapchain registered for GraphicsAPI '{}'",
|
||||
EnumNameGraphicsAPI(p_createInfo.m_api));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
GraphicsInstance& GraphicsContext::GetInstance() const
|
||||
{
|
||||
return *m_instance;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
GraphicsSurface& GraphicsContext::GetSurface() const
|
||||
{
|
||||
return *m_surface;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
GraphicsDevice& GraphicsContext::GetDevice() const
|
||||
{
|
||||
return *m_device;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
GraphicsSwapchain& GraphicsContext::GetSwapchain() const
|
||||
{
|
||||
return *m_swapchain;
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
@@ -0,0 +1 @@
|
||||
#include <GraphicsCore/GraphicsCoreAssertHandler.hpp>
|
||||
@@ -0,0 +1,128 @@
|
||||
/*********************************************************************
|
||||
* \file GraphicsContext.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSCORE_GRAPHICSCONTEXT_HPP
|
||||
#define BIGFOOT_GRAPHICSCORE_GRAPHICSCONTEXT_HPP
|
||||
#include <GraphicsInterface/GraphicsDevice.hpp>
|
||||
#include <GraphicsInterface/GraphicsInstance.hpp>
|
||||
#include <GraphicsInterface/GraphicsSurface.hpp>
|
||||
#include <GraphicsInterface/GraphicsSwapchain.hpp>
|
||||
|
||||
#include <Utils/Version.hpp>
|
||||
|
||||
#include <GraphicsInterface/GraphicsAPI_generated.hpp>
|
||||
|
||||
#include <EASTL/string_view.h>
|
||||
#include <EASTL/unique_ptr.h>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
struct GraphicsContextCreateInfo
|
||||
{
|
||||
/**
|
||||
* The graphics API to use
|
||||
*/
|
||||
GraphicsAPI m_api = GraphicsAPI::Vulkan;
|
||||
|
||||
/**
|
||||
* The name of the application
|
||||
*/
|
||||
eastl::string_view m_applicationName;
|
||||
|
||||
/**
|
||||
* The version of the application
|
||||
*/
|
||||
Version m_applicationVersion;
|
||||
|
||||
/**
|
||||
* The native window handles
|
||||
*/
|
||||
SurfaceCreateInfo m_surfaceCreateInfo;
|
||||
|
||||
/**
|
||||
* Pick a specific physical device by name.
|
||||
*/
|
||||
eastl::string_view m_deviceNameHint;
|
||||
|
||||
/**
|
||||
* The desired size of the swapchain images.
|
||||
*/
|
||||
glm::uvec2 m_extent = {};
|
||||
};
|
||||
|
||||
class GraphicsContext
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* \param p_createInfo The create info
|
||||
*/
|
||||
explicit GraphicsContext(const GraphicsContextCreateInfo& p_createInfo);
|
||||
|
||||
GraphicsContext(const GraphicsContext& p_context) = delete;
|
||||
GraphicsContext(GraphicsContext&& p_context) = delete;
|
||||
|
||||
GraphicsContext& operator=(const GraphicsContext& p_context) = delete;
|
||||
GraphicsContext& operator=(GraphicsContext&& p_context) = delete;
|
||||
|
||||
/**
|
||||
* Get the graphics instance
|
||||
*
|
||||
* \return The graphics instance
|
||||
*/
|
||||
[[nodiscard]]
|
||||
GraphicsInstance& GetInstance() const;
|
||||
|
||||
/**
|
||||
* Get the graphics surface
|
||||
*
|
||||
* \return The graphics surface
|
||||
*/
|
||||
[[nodiscard]]
|
||||
GraphicsSurface& GetSurface() const;
|
||||
|
||||
/**
|
||||
* Get the graphics device
|
||||
*
|
||||
* \return The graphics device
|
||||
*/
|
||||
[[nodiscard]]
|
||||
GraphicsDevice& GetDevice() const;
|
||||
|
||||
/**
|
||||
* Get the graphics swapchain
|
||||
*
|
||||
* \return The graphics swapchain
|
||||
*/
|
||||
[[nodiscard]]
|
||||
GraphicsSwapchain& GetSwapchain() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The graphics instance.
|
||||
*/
|
||||
eastl::unique_ptr<GraphicsInstance> m_instance;
|
||||
|
||||
/**
|
||||
* The graphics surface.
|
||||
*/
|
||||
eastl::unique_ptr<GraphicsSurface> m_surface;
|
||||
|
||||
/**
|
||||
* The graphics device.
|
||||
*/
|
||||
eastl::unique_ptr<GraphicsDevice> m_device;
|
||||
|
||||
/**
|
||||
* The graphics swapchain.
|
||||
*/
|
||||
eastl::unique_ptr<GraphicsSwapchain> m_swapchain;
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
/*********************************************************************
|
||||
* \file GraphicsCoreAssertHandler.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSCORE_GRAPHICSCOREASSERTHANDLER_HPP
|
||||
#define BIGFOOT_GRAPHICSCORE_GRAPHICSCOREASSERTHANDLER_HPP
|
||||
#include <Utils/Assert/AssertHandler.hpp>
|
||||
|
||||
#include <GraphicsCore/GraphicsCoreLogger_generated.hpp>
|
||||
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
using GraphicsCoreAssertHandler = AssertHandler<GRAPHICSCORE_LOGGER>;
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
#endif
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// AUTO-GENERATED DO NOT TOUCH
|
||||
|
||||
/*********************************************************************
|
||||
* \file GraphicsCoreLogger.generated.hpp
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSCORELOGGER_GENERATED_HPP
|
||||
#define BIGFOOT_GRAPHICSCORELOGGER_GENERATED_HPP
|
||||
#include <Utils/Log/LogMacros.hpp>
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
/*
|
||||
* Logger
|
||||
*/
|
||||
inline Log::LoggerInfo GRAPHICSCORE_LOGGER { .m_name = "GRAPHICSCORE_LOGGER", .m_level = LogLevel::Trace};
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
project(${PackageName})
|
||||
|
||||
set(PublicDependencies
|
||||
glm::glm)
|
||||
set(PrivateDependencies)
|
||||
set(BigfootPublicDependencies
|
||||
Utils)
|
||||
set(BigfootPrivateDependencies)
|
||||
|
||||
bigfoot_create_package_lib(
|
||||
"${PublicDependencies}"
|
||||
"${PrivateDependencies}"
|
||||
"${BigfootPublicDependencies}"
|
||||
"${BigfootPrivateDependencies}"
|
||||
"Bigfoot/Libs/Graphics")
|
||||
|
||||
bigfoot_create_logger()
|
||||
@@ -0,0 +1 @@
|
||||
#include <GraphicsInterface/GraphicsInterfaceAssertHandler.hpp>
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Bigfoot;
|
||||
|
||||
enum GraphicsAPI: byte
|
||||
{
|
||||
Vulkan
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_GRAPHICSAPI_BIGFOOT_H_
|
||||
#define FLATBUFFERS_GENERATED_GRAPHICSAPI_BIGFOOT_H_
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 25 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 12 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 19,
|
||||
"Non-compatible flatbuffers version included");
|
||||
// Ensure the included flatbuffers.h is Bigfoot's fork - stock
|
||||
// flatbuffers (or a differently versioned Bigfoot fork) is not compatible.
|
||||
#ifndef FLATBUFFERS_BIGFOOT_VERSION
|
||||
#error "This file requires Bigfoot's flatbuffers fork - stock flatbuffers is not compatible"
|
||||
#endif
|
||||
static_assert(FLATBUFFERS_BIGFOOT_VERSION == 1,
|
||||
"Non-compatible Bigfoot flatbuffers fork version included");
|
||||
|
||||
#include "EASTL/unique_ptr.h"
|
||||
#include "EASTL/string.h"
|
||||
#include "EASTL/vector.h"
|
||||
|
||||
namespace Bigfoot {
|
||||
|
||||
enum class GraphicsAPI : int8_t {
|
||||
Vulkan = 0,
|
||||
MIN = Vulkan,
|
||||
MAX = Vulkan
|
||||
};
|
||||
|
||||
inline const GraphicsAPI (&EnumValuesGraphicsAPI())[1] {
|
||||
static const GraphicsAPI values[] = {
|
||||
GraphicsAPI::Vulkan
|
||||
};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char * const *EnumNamesGraphicsAPI() {
|
||||
static const char * const names[2] = {
|
||||
"Vulkan",
|
||||
nullptr
|
||||
};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNameGraphicsAPI(GraphicsAPI e) {
|
||||
if (::flatbuffers::IsOutRange(e, GraphicsAPI::Vulkan, GraphicsAPI::Vulkan)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesGraphicsAPI()[index];
|
||||
}
|
||||
|
||||
inline const ::flatbuffers::TypeTable *GraphicsAPITypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 }
|
||||
};
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
Bigfoot::GraphicsAPITypeTable
|
||||
};
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_ENUM, 1, type_codes, type_refs, nullptr, nullptr, nullptr
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_GRAPHICSAPI_BIGFOOT_H_
|
||||
@@ -0,0 +1,75 @@
|
||||
/*********************************************************************
|
||||
* \file GraphicsDevice.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSINTERFACE_GRAPHICSDEVICE_HPP
|
||||
#define BIGFOOT_GRAPHICSINTERFACE_GRAPHICSDEVICE_HPP
|
||||
#include <GraphicsInterface/GraphicsInstance.hpp>
|
||||
#include <GraphicsInterface/GraphicsQueue.hpp>
|
||||
#include <GraphicsInterface/GraphicsSurface.hpp>
|
||||
|
||||
#include <Utils/Factory.hpp>
|
||||
#include <Utils/LazyGlobal.hpp>
|
||||
|
||||
#include <GraphicsInterface/GraphicsAPI_generated.hpp>
|
||||
|
||||
#include <EASTL/functional.h>
|
||||
#include <EASTL/string_view.h>
|
||||
#include <EASTL/unique_ptr.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
|
||||
struct DeviceCreateInfo
|
||||
{
|
||||
/**
|
||||
* When empty, the most suitable discrete GPU is preferred.
|
||||
*/
|
||||
eastl::string_view m_deviceNameHint;
|
||||
|
||||
/**
|
||||
* The surface the device must be able to present to.
|
||||
*/
|
||||
const GraphicsSurface* m_surface = nullptr;
|
||||
};
|
||||
|
||||
class GraphicsDevice
|
||||
{
|
||||
public:
|
||||
virtual ~GraphicsDevice() = default;
|
||||
|
||||
/**
|
||||
* Get a queue of the given type
|
||||
*
|
||||
* \param p_type The kind of work the queue should support
|
||||
* \return The queue, or nullptr if the device has no queue of this type
|
||||
*/
|
||||
[[nodiscard]]
|
||||
virtual const GraphicsQueue* GetQueue(GraphicsQueueType p_type) const = 0;
|
||||
|
||||
GraphicsDevice(const GraphicsDevice& p_device) = delete;
|
||||
GraphicsDevice(GraphicsDevice&& p_device) = delete;
|
||||
|
||||
GraphicsDevice& operator=(const GraphicsDevice& p_device) = delete;
|
||||
GraphicsDevice& operator=(GraphicsDevice&& p_device) = delete;
|
||||
|
||||
protected:
|
||||
GraphicsDevice() = default;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
using GraphicsDeviceFactory =
|
||||
Factory<GraphicsDevice,
|
||||
GraphicsAPI,
|
||||
eastl::function<eastl::unique_ptr<GraphicsDevice>(const GraphicsInstance&, const DeviceCreateInfo&)>>;
|
||||
|
||||
/**
|
||||
* The global factory graphics libraries register themselves into, keyed by GraphicsAPI
|
||||
*/
|
||||
inline LazyGlobal<GraphicsDeviceFactory> g_graphicsDeviceFactory;
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
/*********************************************************************
|
||||
* \file GraphicsImage.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSINTERFACE_GRAPHICSIMAGE_HPP
|
||||
#define BIGFOOT_GRAPHICSINTERFACE_GRAPHICSIMAGE_HPP
|
||||
#include <GraphicsInterface/PixelFormat_generated.hpp>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class GraphicsImage
|
||||
{
|
||||
public:
|
||||
virtual ~GraphicsImage() = default;
|
||||
|
||||
/**
|
||||
* Get the pixel format of the image
|
||||
*
|
||||
* \return The image format
|
||||
*/
|
||||
[[nodiscard]]
|
||||
virtual PixelFormat GetFormat() const = 0;
|
||||
|
||||
/**
|
||||
* Get the size of the image
|
||||
*
|
||||
* \return The image extent, in pixels
|
||||
*/
|
||||
[[nodiscard]]
|
||||
virtual glm::uvec2 GetExtent() const = 0;
|
||||
|
||||
GraphicsImage(const GraphicsImage& p_image) = delete;
|
||||
GraphicsImage(GraphicsImage&& p_image) = delete;
|
||||
|
||||
GraphicsImage& operator=(const GraphicsImage& p_image) = delete;
|
||||
GraphicsImage& operator=(GraphicsImage&& p_image) = delete;
|
||||
|
||||
protected:
|
||||
GraphicsImage() = default;
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*********************************************************************
|
||||
* \file GraphicsInstance.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSINTERFACE_GRAPHICSINSTANCE_HPP
|
||||
#define BIGFOOT_GRAPHICSINTERFACE_GRAPHICSINSTANCE_HPP
|
||||
#include <Utils/Factory.hpp>
|
||||
#include <Utils/LazyGlobal.hpp>
|
||||
#include <Utils/Version.hpp>
|
||||
|
||||
#include <GraphicsInterface/GraphicsAPI_generated.hpp>
|
||||
|
||||
#include <EASTL/functional.h>
|
||||
#include <EASTL/string_view.h>
|
||||
#include <EASTL/unique_ptr.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class GraphicsInstance
|
||||
{
|
||||
public:
|
||||
virtual ~GraphicsInstance() = default;
|
||||
|
||||
GraphicsInstance(const GraphicsInstance& p_instance) = delete;
|
||||
GraphicsInstance(GraphicsInstance&& p_instance) = delete;
|
||||
|
||||
GraphicsInstance& operator=(const GraphicsInstance& p_instance) = delete;
|
||||
GraphicsInstance& operator=(GraphicsInstance&& p_instance) = delete;
|
||||
|
||||
protected:
|
||||
GraphicsInstance() = default;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
using GraphicsInstanceFactory =
|
||||
Factory<GraphicsInstance,
|
||||
GraphicsAPI,
|
||||
eastl::function<eastl::unique_ptr<GraphicsInstance>(eastl::string_view, Version)>>;
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
inline LazyGlobal<GraphicsInstanceFactory> g_graphicsInstanceFactory;
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*********************************************************************
|
||||
* \file GraphicsInterfaceAssertHandler.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSINTERFACE_GRAPHICSINTERFACEASSERTHANDLER_HPP
|
||||
#define BIGFOOT_GRAPHICSINTERFACE_GRAPHICSINTERFACEASSERTHANDLER_HPP
|
||||
#include <Utils/Assert/AssertHandler.hpp>
|
||||
|
||||
#include <GraphicsInterface/GraphicsInterfaceLogger_generated.hpp>
|
||||
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
using GraphicsInterfaceAssertHandler = AssertHandler<GRAPHICSINTERFACE_LOGGER>;
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
#endif
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// AUTO-GENERATED DO NOT TOUCH
|
||||
|
||||
/*********************************************************************
|
||||
* \file GraphicsInterfaceLogger.generated.hpp
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSINTERFACELOGGER_GENERATED_HPP
|
||||
#define BIGFOOT_GRAPHICSINTERFACELOGGER_GENERATED_HPP
|
||||
#include <Utils/Log/LogMacros.hpp>
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
/*
|
||||
* Logger
|
||||
*/
|
||||
inline Log::LoggerInfo GRAPHICSINTERFACE_LOGGER { .m_name = "GRAPHICSINTERFACE_LOGGER", .m_level = LogLevel::Trace};
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
/*********************************************************************
|
||||
* \file GraphicsQueue.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSINTERFACE_GRAPHICSQUEUE_HPP
|
||||
#define BIGFOOT_GRAPHICSINTERFACE_GRAPHICSQUEUE_HPP
|
||||
#include <GraphicsInterface/GraphicsQueueType_generated.hpp>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class GraphicsQueue
|
||||
{
|
||||
public:
|
||||
virtual ~GraphicsQueue() = default;
|
||||
|
||||
/**
|
||||
* Get the kind of work this queue can be submitted
|
||||
*
|
||||
* \return The queue type
|
||||
*/
|
||||
[[nodiscard]]
|
||||
virtual GraphicsQueueType GetType() const = 0;
|
||||
|
||||
GraphicsQueue(const GraphicsQueue& p_queue) = delete;
|
||||
GraphicsQueue(GraphicsQueue&& p_queue) = delete;
|
||||
|
||||
GraphicsQueue& operator=(const GraphicsQueue& p_queue) = delete;
|
||||
GraphicsQueue& operator=(GraphicsQueue&& p_queue) = delete;
|
||||
|
||||
protected:
|
||||
GraphicsQueue() = default;
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
namespace Bigfoot;
|
||||
|
||||
enum GraphicsQueueType: byte
|
||||
{
|
||||
Graphics,
|
||||
Compute,
|
||||
Transfer,
|
||||
Present
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_GRAPHICSQUEUETYPE_BIGFOOT_H_
|
||||
#define FLATBUFFERS_GENERATED_GRAPHICSQUEUETYPE_BIGFOOT_H_
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 25 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 12 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 19,
|
||||
"Non-compatible flatbuffers version included");
|
||||
// Ensure the included flatbuffers.h is Bigfoot's fork - stock
|
||||
// flatbuffers (or a differently versioned Bigfoot fork) is not compatible.
|
||||
#ifndef FLATBUFFERS_BIGFOOT_VERSION
|
||||
#error "This file requires Bigfoot's flatbuffers fork - stock flatbuffers is not compatible"
|
||||
#endif
|
||||
static_assert(FLATBUFFERS_BIGFOOT_VERSION == 1,
|
||||
"Non-compatible Bigfoot flatbuffers fork version included");
|
||||
|
||||
#include "EASTL/unique_ptr.h"
|
||||
#include "EASTL/string.h"
|
||||
#include "EASTL/vector.h"
|
||||
|
||||
namespace Bigfoot {
|
||||
|
||||
enum class GraphicsQueueType : int8_t {
|
||||
Graphics = 0,
|
||||
Compute = 1,
|
||||
Transfer = 2,
|
||||
Present = 3,
|
||||
MIN = Graphics,
|
||||
MAX = Present
|
||||
};
|
||||
|
||||
inline const GraphicsQueueType (&EnumValuesGraphicsQueueType())[4] {
|
||||
static const GraphicsQueueType values[] = {
|
||||
GraphicsQueueType::Graphics,
|
||||
GraphicsQueueType::Compute,
|
||||
GraphicsQueueType::Transfer,
|
||||
GraphicsQueueType::Present
|
||||
};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char * const *EnumNamesGraphicsQueueType() {
|
||||
static const char * const names[5] = {
|
||||
"Graphics",
|
||||
"Compute",
|
||||
"Transfer",
|
||||
"Present",
|
||||
nullptr
|
||||
};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNameGraphicsQueueType(GraphicsQueueType e) {
|
||||
if (::flatbuffers::IsOutRange(e, GraphicsQueueType::Graphics, GraphicsQueueType::Present)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesGraphicsQueueType()[index];
|
||||
}
|
||||
|
||||
inline const ::flatbuffers::TypeTable *GraphicsQueueTypeTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 }
|
||||
};
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
Bigfoot::GraphicsQueueTypeTypeTable
|
||||
};
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_ENUM, 4, type_codes, type_refs, nullptr, nullptr, nullptr
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_GRAPHICSQUEUETYPE_BIGFOOT_H_
|
||||
@@ -0,0 +1,70 @@
|
||||
/*********************************************************************
|
||||
* \file GraphicsSurface.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSINTERFACE_GRAPHICSSURFACE_HPP
|
||||
#define BIGFOOT_GRAPHICSINTERFACE_GRAPHICSSURFACE_HPP
|
||||
#include <GraphicsInterface/GraphicsInstance.hpp>
|
||||
|
||||
#include <Utils/Factory.hpp>
|
||||
#include <Utils/LazyGlobal.hpp>
|
||||
#include <Utils/TargetMacros.h>
|
||||
|
||||
#include <GraphicsInterface/GraphicsAPI_generated.hpp>
|
||||
|
||||
#include <EASTL/functional.h>
|
||||
#include <EASTL/unique_ptr.h>
|
||||
|
||||
#ifdef BIGFOOT_WINDOWS
|
||||
#include <Windows.h>
|
||||
#elif defined BIGFOOT_LINUX
|
||||
struct wl_display;
|
||||
struct wl_surface;
|
||||
#endif
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
/**
|
||||
* The native window handles needed to create a GraphicsSurface
|
||||
*/
|
||||
struct SurfaceCreateInfo
|
||||
{
|
||||
#ifdef BIGFOOT_WINDOWS
|
||||
HWND m_windowHandle = nullptr;
|
||||
HINSTANCE m_windowInstance = nullptr;
|
||||
#elif defined BIGFOOT_LINUX
|
||||
wl_display* m_display = nullptr;
|
||||
wl_surface* m_surface = nullptr;
|
||||
#endif
|
||||
};
|
||||
|
||||
class GraphicsSurface
|
||||
{
|
||||
public:
|
||||
virtual ~GraphicsSurface() = default;
|
||||
|
||||
GraphicsSurface(const GraphicsSurface& p_surface) = delete;
|
||||
GraphicsSurface(GraphicsSurface&& p_surface) = delete;
|
||||
|
||||
GraphicsSurface& operator=(const GraphicsSurface& p_surface) = delete;
|
||||
GraphicsSurface& operator=(GraphicsSurface&& p_surface) = delete;
|
||||
|
||||
protected:
|
||||
GraphicsSurface() = default;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
using GraphicsSurfaceFactory =
|
||||
Factory<GraphicsSurface,
|
||||
GraphicsAPI,
|
||||
eastl::function<eastl::unique_ptr<GraphicsSurface>(const GraphicsInstance&, const SurfaceCreateInfo&)>>;
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
inline LazyGlobal<GraphicsSurfaceFactory> g_graphicsSurfaceFactory;
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
/*********************************************************************
|
||||
* \file GraphicsSwapchain.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSINTERFACE_GRAPHICSSWAPCHAIN_HPP
|
||||
#define BIGFOOT_GRAPHICSINTERFACE_GRAPHICSSWAPCHAIN_HPP
|
||||
#include <GraphicsInterface/GraphicsDevice.hpp>
|
||||
#include <GraphicsInterface/GraphicsImage.hpp>
|
||||
#include <GraphicsInterface/GraphicsInstance.hpp>
|
||||
#include <GraphicsInterface/GraphicsSurface.hpp>
|
||||
|
||||
#include <Utils/Factory.hpp>
|
||||
#include <Utils/LazyGlobal.hpp>
|
||||
|
||||
#include <GraphicsInterface/GraphicsAPI_generated.hpp>
|
||||
|
||||
#include <EASTL/functional.h>
|
||||
#include <EASTL/unique_ptr.h>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
struct SwapchainCreateInfo
|
||||
{
|
||||
/**
|
||||
* The device to create the swapchain from. Must be able to present to m_surface.
|
||||
*/
|
||||
const GraphicsDevice* m_device = nullptr;
|
||||
|
||||
/**
|
||||
* The surface the swapchain will present to.
|
||||
*/
|
||||
const GraphicsSurface* m_surface = nullptr;
|
||||
|
||||
/**
|
||||
* The desired size of the swapchain images.
|
||||
*/
|
||||
glm::uvec2 m_extent = {};
|
||||
};
|
||||
|
||||
class GraphicsSwapchain
|
||||
{
|
||||
public:
|
||||
virtual ~GraphicsSwapchain() = default;
|
||||
|
||||
/**
|
||||
* Get the number of images owned by the swapchain
|
||||
*
|
||||
* \return The image count
|
||||
*/
|
||||
[[nodiscard]]
|
||||
virtual std::uint32_t GetImageCount() const = 0;
|
||||
|
||||
/**
|
||||
* Get one of the images owned by the swapchain
|
||||
*
|
||||
* \param p_index The index of the image to get.
|
||||
* \return The image
|
||||
*/
|
||||
[[nodiscard]]
|
||||
virtual const GraphicsImage& GetImage(std::uint32_t p_index) const = 0;
|
||||
|
||||
GraphicsSwapchain(const GraphicsSwapchain& p_swapchain) = delete;
|
||||
GraphicsSwapchain(GraphicsSwapchain&& p_swapchain) = delete;
|
||||
|
||||
GraphicsSwapchain& operator=(const GraphicsSwapchain& p_swapchain) = delete;
|
||||
GraphicsSwapchain& operator=(GraphicsSwapchain&& p_swapchain) = delete;
|
||||
|
||||
protected:
|
||||
GraphicsSwapchain() = default;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
using GraphicsSwapchainFactory =
|
||||
Factory<GraphicsSwapchain,
|
||||
GraphicsAPI,
|
||||
eastl::function<eastl::unique_ptr<GraphicsSwapchain>(const SwapchainCreateInfo&)>>;
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
inline LazyGlobal<GraphicsSwapchainFactory> g_graphicsSwapchainFactory;
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Bigfoot;
|
||||
|
||||
enum PixelFormat: byte
|
||||
{
|
||||
Undefined,
|
||||
R8G8B8A8Unorm,
|
||||
R8G8B8A8Srgb,
|
||||
B8G8R8A8Unorm,
|
||||
B8G8R8A8Srgb,
|
||||
A2B10G10R10UnormPack32,
|
||||
R16G16B16A16Sfloat
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_PIXELFORMAT_BIGFOOT_H_
|
||||
#define FLATBUFFERS_GENERATED_PIXELFORMAT_BIGFOOT_H_
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 25 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 12 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 19,
|
||||
"Non-compatible flatbuffers version included");
|
||||
// Ensure the included flatbuffers.h is Bigfoot's fork - stock
|
||||
// flatbuffers (or a differently versioned Bigfoot fork) is not compatible.
|
||||
#ifndef FLATBUFFERS_BIGFOOT_VERSION
|
||||
#error "This file requires Bigfoot's flatbuffers fork - stock flatbuffers is not compatible"
|
||||
#endif
|
||||
static_assert(FLATBUFFERS_BIGFOOT_VERSION == 1,
|
||||
"Non-compatible Bigfoot flatbuffers fork version included");
|
||||
|
||||
#include "EASTL/unique_ptr.h"
|
||||
#include "EASTL/string.h"
|
||||
#include "EASTL/vector.h"
|
||||
|
||||
namespace Bigfoot {
|
||||
|
||||
enum class PixelFormat : int8_t {
|
||||
Undefined = 0,
|
||||
R8G8B8A8Unorm = 1,
|
||||
R8G8B8A8Srgb = 2,
|
||||
B8G8R8A8Unorm = 3,
|
||||
B8G8R8A8Srgb = 4,
|
||||
A2B10G10R10UnormPack32 = 5,
|
||||
R16G16B16A16Sfloat = 6,
|
||||
MIN = Undefined,
|
||||
MAX = R16G16B16A16Sfloat
|
||||
};
|
||||
|
||||
inline const PixelFormat (&EnumValuesPixelFormat())[7] {
|
||||
static const PixelFormat values[] = {
|
||||
PixelFormat::Undefined,
|
||||
PixelFormat::R8G8B8A8Unorm,
|
||||
PixelFormat::R8G8B8A8Srgb,
|
||||
PixelFormat::B8G8R8A8Unorm,
|
||||
PixelFormat::B8G8R8A8Srgb,
|
||||
PixelFormat::A2B10G10R10UnormPack32,
|
||||
PixelFormat::R16G16B16A16Sfloat
|
||||
};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char * const *EnumNamesPixelFormat() {
|
||||
static const char * const names[8] = {
|
||||
"Undefined",
|
||||
"R8G8B8A8Unorm",
|
||||
"R8G8B8A8Srgb",
|
||||
"B8G8R8A8Unorm",
|
||||
"B8G8R8A8Srgb",
|
||||
"A2B10G10R10UnormPack32",
|
||||
"R16G16B16A16Sfloat",
|
||||
nullptr
|
||||
};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNamePixelFormat(PixelFormat e) {
|
||||
if (::flatbuffers::IsOutRange(e, PixelFormat::Undefined, PixelFormat::R16G16B16A16Sfloat)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesPixelFormat()[index];
|
||||
}
|
||||
|
||||
inline const ::flatbuffers::TypeTable *PixelFormatTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 }
|
||||
};
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
Bigfoot::PixelFormatTypeTable
|
||||
};
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_ENUM, 7, type_codes, type_refs, nullptr, nullptr, nullptr
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_PIXELFORMAT_BIGFOOT_H_
|
||||
@@ -0,0 +1,27 @@
|
||||
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
project(${PackageName})
|
||||
|
||||
set(PublicDependencies
|
||||
vulkan-headers::vulkan-headers
|
||||
GPUOpen::VulkanMemoryAllocator)
|
||||
set(PrivateDependencies)
|
||||
set(BigfootPublicDependencies
|
||||
GraphicsInterface)
|
||||
set(BigfootPrivateDependencies
|
||||
Engine)
|
||||
|
||||
bigfoot_create_package_lib(
|
||||
"${PublicDependencies}"
|
||||
"${PrivateDependencies}"
|
||||
"${BigfootPublicDependencies}"
|
||||
"${BigfootPrivateDependencies}"
|
||||
"Bigfoot/Libs/Graphics")
|
||||
|
||||
bigfoot_create_logger()
|
||||
|
||||
target_compile_definitions(${PackageName}
|
||||
PRIVATE VULKAN_HPP_NO_EXCEPTIONS
|
||||
PRIVATE VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1
|
||||
PRIVATE $<$<PLATFORM_ID:Windows>:VK_USE_PLATFORM_WIN32_KHR>
|
||||
PRIVATE $<$<PLATFORM_ID:Linux>:VK_USE_PLATFORM_WAYLAND_KHR>
|
||||
PUBLIC BIGFOOT_VULKAN)
|
||||
@@ -0,0 +1 @@
|
||||
#include <GraphicsVulkan/GraphicsVulkanAssertHandler.hpp>
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*********************************************************************
|
||||
* \file GraphicsVulkanAssertHandler.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSVULKAN_GRAPHICSVULKANASSERTHANDLER_HPP
|
||||
#define BIGFOOT_GRAPHICSVULKAN_GRAPHICSVULKANASSERTHANDLER_HPP
|
||||
#include <Utils/Assert/AssertHandler.hpp>
|
||||
|
||||
#include <GraphicsVulkan/GraphicsVulkanLogger_generated.hpp>
|
||||
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
using GraphicsVulkanAssertHandler = AssertHandler<GRAPHICSVULKAN_LOGGER>;
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
#endif
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// AUTO-GENERATED DO NOT TOUCH
|
||||
|
||||
/*********************************************************************
|
||||
* \file GraphicsVulkanLogger.generated.hpp
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSVULKANLOGGER_GENERATED_HPP
|
||||
#define BIGFOOT_GRAPHICSVULKANLOGGER_GENERATED_HPP
|
||||
#include <Utils/Log/LogMacros.hpp>
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
/*
|
||||
* Logger
|
||||
*/
|
||||
inline Log::LoggerInfo GRAPHICSVULKAN_LOGGER { .m_name = "GRAPHICSVULKAN_LOGGER", .m_level = LogLevel::Trace};
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanDevice.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSVULKAN_VULKANDEVICE_HPP
|
||||
#define BIGFOOT_GRAPHICSVULKAN_VULKANDEVICE_HPP
|
||||
#include <GraphicsVulkan/VulkanInclude.hpp>
|
||||
#include <GraphicsVulkan/VulkanInstance.hpp>
|
||||
#include <GraphicsVulkan/VulkanQueue.hpp>
|
||||
#include <GraphicsVulkan/VulkanSurface.hpp>
|
||||
|
||||
#include <GraphicsInterface/GraphicsDevice.hpp>
|
||||
|
||||
#include <EASTL/array.h>
|
||||
#include <EASTL/optional.h>
|
||||
#include <EASTL/string_view.h>
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
class VulkanDevice final: public GraphicsDevice
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* \param p_instance The instance to create the device from
|
||||
* \param p_surface The surface the device must be able to present to. Can be null to create a device with no
|
||||
* present queue
|
||||
* \param p_deviceNameHint Pick a specific physical device by name.
|
||||
*/
|
||||
VulkanDevice(const VulkanInstance& p_instance, const VulkanSurface* p_surface, eastl::string_view p_deviceNameHint);
|
||||
|
||||
~VulkanDevice() override;
|
||||
|
||||
/**
|
||||
* Get a queue of the given type
|
||||
*
|
||||
* \param p_type The kind of work the queue should support
|
||||
* \return The queue, or nullptr if the device has no queue of this type
|
||||
*/
|
||||
[[nodiscard]]
|
||||
const GraphicsQueue* GetQueue(GraphicsQueueType p_type) const override;
|
||||
|
||||
/**
|
||||
* Get the underlying Vulkan physical device handle
|
||||
*
|
||||
* \return The vk::PhysicalDevice handle
|
||||
*/
|
||||
[[nodiscard]]
|
||||
vk::PhysicalDevice GetPhysicalDeviceHandle() const;
|
||||
|
||||
/**
|
||||
* Get the underlying Vulkan device handle
|
||||
*
|
||||
* \return The vk::Device handle
|
||||
*/
|
||||
[[nodiscard]]
|
||||
vk::Device GetHandle() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The physical device this device was created from
|
||||
*/
|
||||
vk::PhysicalDevice m_physicalDevice;
|
||||
|
||||
/**
|
||||
* The logical device
|
||||
*/
|
||||
vk::Device m_device;
|
||||
|
||||
/**
|
||||
* The queues. A slot is empty if the device has no queue of that type
|
||||
*/
|
||||
eastl::array<eastl::optional<VulkanQueue>, static_cast<size_t>(GraphicsQueueType::MAX) + 1> m_queues;
|
||||
};
|
||||
} // namespace Bigfoot::Vulkan
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanFormatters.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSVULKAN_VULKANFORMATTERS_HPP
|
||||
#define BIGFOOT_GRAPHICSVULKAN_VULKANFORMATTERS_HPP
|
||||
#include <GraphicsVulkan/VulkanInclude.hpp>
|
||||
|
||||
#include <Utils/TargetMacros.h>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
template<>
|
||||
struct fmt::formatter<vk::Result>
|
||||
{
|
||||
static constexpr auto parse(format_parse_context& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
static auto format(const vk::Result p_result, format_context& ctx)
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "{}", vk::to_string(p_result));
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
#include <quill/DeferredFormatCodec.h>
|
||||
|
||||
template<>
|
||||
struct fmtquill::formatter<vk::Result>
|
||||
{
|
||||
static constexpr auto parse(format_parse_context& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
static auto format(const vk::Result p_result, format_context& ctx)
|
||||
{
|
||||
return fmtquill::format_to(ctx.out(), "{}", vk::to_string(p_result));
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct quill::Codec<vk::Result>: quill::DeferredFormatCodec<vk::Result>
|
||||
{
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanImage.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSVULKAN_VULKANIMAGE_HPP
|
||||
#define BIGFOOT_GRAPHICSVULKAN_VULKANIMAGE_HPP
|
||||
#include <GraphicsVulkan/VulkanInclude.hpp>
|
||||
|
||||
#include <GraphicsInterface/GraphicsImage.hpp>
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
class VulkanImage final: public GraphicsImage
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param p_image The underlying Vulkan image handle
|
||||
* \param p_format The pixel format of the image
|
||||
* \param p_extent The size of the image
|
||||
*/
|
||||
VulkanImage(vk::Image p_image, PixelFormat p_format, vk::Extent2D p_extent);
|
||||
|
||||
VulkanImage(const VulkanImage& p_image) = delete;
|
||||
VulkanImage(VulkanImage&& p_image) noexcept;
|
||||
|
||||
VulkanImage& operator=(const VulkanImage& p_image) = delete;
|
||||
VulkanImage& operator=(VulkanImage&& p_image) noexcept;
|
||||
|
||||
/**
|
||||
* Get the pixel format of the image
|
||||
*
|
||||
* \return The image format
|
||||
*/
|
||||
[[nodiscard]]
|
||||
PixelFormat GetFormat() const override;
|
||||
|
||||
/**
|
||||
* Get the size of the image
|
||||
*
|
||||
* \return The image extent, in pixels
|
||||
*/
|
||||
[[nodiscard]]
|
||||
glm::uvec2 GetExtent() const override;
|
||||
|
||||
/**
|
||||
* Get the underlying Vulkan image handle
|
||||
*
|
||||
* \return The vk::Image handle
|
||||
*/
|
||||
[[nodiscard]]
|
||||
vk::Image GetHandle() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The vulkan image
|
||||
*/
|
||||
vk::Image m_image;
|
||||
|
||||
/**
|
||||
* The pixel format of the image
|
||||
*/
|
||||
PixelFormat m_format;
|
||||
|
||||
/**
|
||||
* The size of the image
|
||||
*/
|
||||
vk::Extent2D m_extent;
|
||||
};
|
||||
} // namespace Bigfoot::Vulkan
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,13 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanInclude.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSVULKAN_VULKANINCLUDE_HPP
|
||||
#define BIGFOOT_GRAPHICSVULKAN_VULKANINCLUDE_HPP
|
||||
#define VULKAN_HPP_ASSERT(result)
|
||||
#define VULKAN_HPP_ASSERT_ON_RESULT(result)
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,59 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanInstance.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSVULKAN_VULKANINSTANCE_HPP
|
||||
#define BIGFOOT_GRAPHICSVULKAN_VULKANINSTANCE_HPP
|
||||
#include <GraphicsVulkan/VulkanInclude.hpp>
|
||||
|
||||
#include <GraphicsInterface/GraphicsInstance.hpp>
|
||||
|
||||
#include <Utils/TargetMacros.h>
|
||||
#include <Utils/Version.hpp>
|
||||
|
||||
#include <EASTL/string_view.h>
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
class VulkanInstance final: public GraphicsInstance
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor. Creates a vk::Instance
|
||||
*
|
||||
* \param p_applicationName The name of the application
|
||||
* \param p_applicationVersion The version of the application
|
||||
*/
|
||||
VulkanInstance(eastl::string_view p_applicationName, Version p_applicationVersion);
|
||||
|
||||
~VulkanInstance() override;
|
||||
|
||||
/**
|
||||
* Get the underlying Vulkan instance handle
|
||||
*
|
||||
* \return The vk::Instance handle
|
||||
*/
|
||||
[[nodiscard]]
|
||||
vk::Instance GetHandle() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The vulkan loader.
|
||||
*/
|
||||
vk::detail::DynamicLoader m_loader;
|
||||
|
||||
/**
|
||||
* The vulkan instance.
|
||||
*/
|
||||
vk::Instance m_instance;
|
||||
|
||||
/**
|
||||
* The debug messenger (used for validation callbacks).
|
||||
*/
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(vk::DebugUtilsMessengerEXT m_debugMessenger;)
|
||||
};
|
||||
} // namespace Bigfoot::Vulkan
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanPixelFormat.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSVULKAN_VULKANPIXELFORMAT_HPP
|
||||
#define BIGFOOT_GRAPHICSVULKAN_VULKANPIXELFORMAT_HPP
|
||||
#include <GraphicsVulkan/VulkanInclude.hpp>
|
||||
|
||||
#include <GraphicsInterface/PixelFormat_generated.hpp>
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
/**
|
||||
* Convert PixelFormat to its vk::Format equivalent
|
||||
*
|
||||
* \param p_format The format to convert
|
||||
* \return The equivalent vk::Format
|
||||
*/
|
||||
[[nodiscard]]
|
||||
vk::Format ToVulkanFormat(PixelFormat p_format);
|
||||
|
||||
/**
|
||||
* Convert a vk::Format to its PixelFormat equivalent
|
||||
*
|
||||
* \param p_format The format to convert
|
||||
* \return The equivalent PixelFormat
|
||||
*/
|
||||
[[nodiscard]]
|
||||
PixelFormat FromVulkanFormat(vk::Format p_format);
|
||||
} // namespace Bigfoot::Vulkan
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,77 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanQueue.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSVULKAN_VULKANQUEUE_HPP
|
||||
#define BIGFOOT_GRAPHICSVULKAN_VULKANQUEUE_HPP
|
||||
#include <GraphicsVulkan/VulkanInclude.hpp>
|
||||
|
||||
#include <GraphicsInterface/GraphicsQueue.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
class VulkanQueue final: public GraphicsQueue
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param p_queue The underlying Vulkan queue handle
|
||||
* \param p_familyIndex The queue family index this queue was retrieved from
|
||||
* \param p_type The kind of work this queue can submit
|
||||
*/
|
||||
VulkanQueue(vk::Queue p_queue, std::uint32_t p_familyIndex, GraphicsQueueType p_type);
|
||||
|
||||
VulkanQueue(const VulkanQueue& p_queue) = delete;
|
||||
VulkanQueue(VulkanQueue&& p_queue) noexcept;
|
||||
|
||||
VulkanQueue& operator=(const VulkanQueue& p_queue) = delete;
|
||||
VulkanQueue& operator=(VulkanQueue&& p_queue) noexcept;
|
||||
|
||||
/**
|
||||
* Get the kind of work this queue can be submitted
|
||||
*
|
||||
* \return The queue type
|
||||
*/
|
||||
[[nodiscard]]
|
||||
GraphicsQueueType GetType() const override;
|
||||
|
||||
/**
|
||||
* Get the underlying Vulkan queue handle
|
||||
*
|
||||
* \return The vk::Queue handle
|
||||
*/
|
||||
[[nodiscard]]
|
||||
vk::Queue GetHandle() const;
|
||||
|
||||
/**
|
||||
* Get the index of the queue family this queue was retrieved from
|
||||
*
|
||||
* \return The queue family index
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::uint32_t GetFamilyIndex() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The vulkn queue
|
||||
*/
|
||||
vk::Queue m_queue;
|
||||
|
||||
/**
|
||||
* The index of the queue family this queue was retrieved from
|
||||
*/
|
||||
std::uint32_t m_familyIndex;
|
||||
|
||||
/**
|
||||
* The kind of work this queue can submit
|
||||
*/
|
||||
GraphicsQueueType m_type;
|
||||
};
|
||||
} // namespace Bigfoot::Vulkan
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanSurface.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSVULKAN_VULKANSURFACE_HPP
|
||||
#define BIGFOOT_GRAPHICSVULKAN_VULKANSURFACE_HPP
|
||||
#include <GraphicsVulkan/VulkanInclude.hpp>
|
||||
#include <GraphicsVulkan/VulkanInstance.hpp>
|
||||
|
||||
#include <GraphicsInterface/GraphicsSurface.hpp>
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
class VulkanSurface final: public GraphicsSurface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* Creates a vk::SurfaceKHR for the given native window.
|
||||
*
|
||||
* \param p_instance The instance to create the surface from
|
||||
* \param p_surfaceCreateInfo The native window handles to create the surface for
|
||||
*/
|
||||
VulkanSurface(const VulkanInstance& p_instance, const SurfaceCreateInfo& p_surfaceCreateInfo);
|
||||
|
||||
~VulkanSurface() override;
|
||||
|
||||
/**
|
||||
* Get the underlying Vulkan surface handle
|
||||
*
|
||||
* \return The vk::SurfaceKHR handle
|
||||
*/
|
||||
[[nodiscard]]
|
||||
vk::SurfaceKHR GetHandle() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The instance
|
||||
*/
|
||||
const VulkanInstance& m_instance;
|
||||
|
||||
/**
|
||||
* The surface
|
||||
*/
|
||||
vk::SurfaceKHR m_surface;
|
||||
};
|
||||
} // namespace Bigfoot::Vulkan
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,88 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanSwapchain.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_GRAPHICSVULKAN_VULKANSWAPCHAIN_HPP
|
||||
#define BIGFOOT_GRAPHICSVULKAN_VULKANSWAPCHAIN_HPP
|
||||
#include <GraphicsVulkan/VulkanDevice.hpp>
|
||||
#include <GraphicsVulkan/VulkanImage.hpp>
|
||||
#include <GraphicsVulkan/VulkanInclude.hpp>
|
||||
#include <GraphicsVulkan/VulkanSurface.hpp>
|
||||
|
||||
#include <GraphicsInterface/GraphicsSwapchain.hpp>
|
||||
|
||||
#include <EASTL/span.h>
|
||||
#include <EASTL/vector.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
class VulkanSwapchain final: public GraphicsSwapchain
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* \param p_device The device to create the swapchain from.
|
||||
* \param p_surface The surface the swapchain will present to.
|
||||
* \param p_extent The desired size of the swapchain images.
|
||||
*/
|
||||
VulkanSwapchain(const VulkanDevice& p_device, const VulkanSurface& p_surface, glm::uvec2 p_extent);
|
||||
|
||||
~VulkanSwapchain() override;
|
||||
|
||||
/**
|
||||
* Get the number of images owned by the swapchain
|
||||
*
|
||||
* \return The image count
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::uint32_t GetImageCount() const override;
|
||||
|
||||
/**
|
||||
* Get one of the images owned by the swapchain
|
||||
*
|
||||
* \param p_index The index of the image to get. Must be less than GetImageCount()
|
||||
* \return The image
|
||||
*/
|
||||
[[nodiscard]]
|
||||
const GraphicsImage& GetImage(std::uint32_t p_index) const override;
|
||||
|
||||
/**
|
||||
* Get the underlying Vulkan swapchain handle
|
||||
*
|
||||
* \return The vk::SwapchainKHR handle
|
||||
*/
|
||||
[[nodiscard]]
|
||||
vk::SwapchainKHR GetHandle() const;
|
||||
|
||||
/**
|
||||
* Get the swapchain images
|
||||
*
|
||||
* \return The images owned by the swapchain
|
||||
*/
|
||||
[[nodiscard]]
|
||||
eastl::span<const VulkanImage> GetImages() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The device the swapchain was created from
|
||||
*/
|
||||
const VulkanDevice& m_device;
|
||||
|
||||
/**
|
||||
* The swapchain
|
||||
*/
|
||||
vk::SwapchainKHR m_swapchain;
|
||||
|
||||
/**
|
||||
* The images owned by the swapchain
|
||||
*/
|
||||
eastl::vector<VulkanImage> m_images;
|
||||
};
|
||||
} // namespace Bigfoot::Vulkan
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,352 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanDevice.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#include <GraphicsVulkan/VulkanDevice.hpp>
|
||||
|
||||
#include <GraphicsVulkan/GraphicsVulkanAssertHandler.hpp>
|
||||
#include <GraphicsVulkan/VulkanFormatters.hpp>
|
||||
|
||||
#include <Utils/String.hpp>
|
||||
#include <Utils/TargetMacros.h>
|
||||
|
||||
#include <EASTL/algorithm.h>
|
||||
#include <EASTL/optional.h>
|
||||
#include <EASTL/span.h>
|
||||
#include <EASTL/vector.h>
|
||||
|
||||
#include <bit>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
[[nodiscard]]
|
||||
std::uint32_t GetPhysicalDeviceTypeRank(const vk::PhysicalDeviceType p_type)
|
||||
{
|
||||
switch (p_type)
|
||||
{
|
||||
case vk::PhysicalDeviceType::eDiscreteGpu:
|
||||
return 0;
|
||||
case vk::PhysicalDeviceType::eIntegratedGpu:
|
||||
return 1;
|
||||
case vk::PhysicalDeviceType::eVirtualGpu:
|
||||
return 2;
|
||||
case vk::PhysicalDeviceType::eCpu:
|
||||
return 3;
|
||||
case vk::PhysicalDeviceType::eOther:
|
||||
default:
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
struct SelectedQueueFamilies
|
||||
{
|
||||
eastl::optional<std::uint32_t> m_graphics;
|
||||
eastl::optional<std::uint32_t> m_compute;
|
||||
eastl::optional<std::uint32_t> m_transfer;
|
||||
eastl::optional<std::uint32_t> m_present;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
eastl::optional<std::uint32_t> FindQueueFamily(const std::span<const vk::QueueFamilyProperties> p_families,
|
||||
const vk::QueueFlagBits p_required)
|
||||
{
|
||||
eastl::optional<std::uint32_t> best;
|
||||
int bestBitCount = 0;
|
||||
|
||||
for (std::uint32_t index = 0; index < p_families.size(); ++index)
|
||||
{
|
||||
const vk::QueueFlags flags = p_families[index].queueFlags;
|
||||
if (!(flags & p_required))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const int bitCount = std::popcount(static_cast<vk::QueueFlags::MaskType>(flags));
|
||||
if (!best.has_value() || bitCount < bestBitCount)
|
||||
{
|
||||
best = index;
|
||||
bestBitCount = bitCount;
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
eastl::optional<std::uint32_t> FindPresentQueueFamily(const vk::PhysicalDevice p_physicalDevice,
|
||||
const vk::SurfaceKHR p_surface,
|
||||
const std::uint32_t p_familyCount,
|
||||
const eastl::optional<std::uint32_t> p_graphicsFamily)
|
||||
{
|
||||
if (p_graphicsFamily.has_value())
|
||||
{
|
||||
const vk::ResultValue<vk::Bool32> support = p_physicalDevice.getSurfaceSupportKHR(*p_graphicsFamily, p_surface);
|
||||
if (support.result == vk::Result::eSuccess && support.value)
|
||||
{
|
||||
return *p_graphicsFamily;
|
||||
}
|
||||
}
|
||||
|
||||
for (std::uint32_t index = 0; index < p_familyCount; ++index)
|
||||
{
|
||||
const vk::ResultValue<vk::Bool32> support = p_physicalDevice.getSurfaceSupportKHR(index, p_surface);
|
||||
if (support.result == vk::Result::eSuccess && support.value)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
return eastl::nullopt;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
SelectedQueueFamilies SelectQueueFamilies(const vk::PhysicalDevice p_physicalDevice, const vk::SurfaceKHR p_surface)
|
||||
{
|
||||
const std::vector<vk::QueueFamilyProperties> families = p_physicalDevice.getQueueFamilyProperties();
|
||||
|
||||
SelectedQueueFamilies selected;
|
||||
selected.m_graphics = FindQueueFamily(families, vk::QueueFlagBits::eGraphics);
|
||||
selected.m_compute = FindQueueFamily(families, vk::QueueFlagBits::eCompute);
|
||||
selected.m_transfer = FindQueueFamily(families, vk::QueueFlagBits::eTransfer);
|
||||
if (!selected.m_transfer.has_value())
|
||||
{
|
||||
// Per the Vulkan spec, any queue family supporting Graphics or Compute implicitly supports
|
||||
// Transfer even when it doesn't explicitly report the bit, so the graphics family always works.
|
||||
selected.m_transfer = selected.m_graphics;
|
||||
}
|
||||
|
||||
if (p_surface)
|
||||
{
|
||||
selected.m_present = FindPresentQueueFamily(p_physicalDevice,
|
||||
p_surface,
|
||||
static_cast<std::uint32_t>(families.size()),
|
||||
selected.m_graphics);
|
||||
}
|
||||
|
||||
return selected;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
bool IsPhysicalDeviceSuitable(const SelectedQueueFamilies& p_families, const bool p_needsPresent)
|
||||
{
|
||||
return p_families.m_graphics.has_value() && p_families.m_compute.has_value() &&
|
||||
(!p_needsPresent || p_families.m_present.has_value());
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
struct PhysicalDeviceCandidate
|
||||
{
|
||||
vk::PhysicalDevice m_handle;
|
||||
vk::PhysicalDeviceProperties m_properties;
|
||||
SelectedQueueFamilies m_queueFamilies;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
const PhysicalDeviceCandidate& SelectPhysicalDevice(const eastl::span<const PhysicalDeviceCandidate> p_candidates,
|
||||
const eastl::string_view p_deviceNameHint)
|
||||
{
|
||||
if (!p_deviceNameHint.empty())
|
||||
{
|
||||
const auto it = eastl::find_if(p_candidates.begin(),
|
||||
p_candidates.end(),
|
||||
[p_deviceNameHint](const PhysicalDeviceCandidate& p_candidate)
|
||||
{
|
||||
return EqualNoCase(p_candidate.m_properties.deviceName.data(),
|
||||
p_deviceNameHint);
|
||||
});
|
||||
if (it != p_candidates.end())
|
||||
{
|
||||
return *it;
|
||||
}
|
||||
|
||||
BIGFOOT_LOG_WARN(GRAPHICSVULKAN_LOGGER,
|
||||
"No Vulkan device matching hint '{}' found, falling back to automatic selection",
|
||||
p_deviceNameHint);
|
||||
}
|
||||
|
||||
return *eastl::min_element(p_candidates.begin(),
|
||||
p_candidates.end(),
|
||||
[](const PhysicalDeviceCandidate& p_lhs, const PhysicalDeviceCandidate& p_rhs)
|
||||
{
|
||||
return GetPhysicalDeviceTypeRank(p_lhs.m_properties.deviceType) <
|
||||
GetPhysicalDeviceTypeRank(p_rhs.m_properties.deviceType);
|
||||
});
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
eastl::optional<VulkanQueue> CreateQueue(const vk::Device p_device,
|
||||
const eastl::optional<std::uint32_t> p_familyIndex,
|
||||
const GraphicsQueueType p_type)
|
||||
{
|
||||
if (!p_familyIndex.has_value())
|
||||
{
|
||||
return eastl::nullopt;
|
||||
}
|
||||
|
||||
return VulkanQueue {p_device.getQueue(*p_familyIndex, 0), *p_familyIndex, p_type};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
VulkanDevice::VulkanDevice(const VulkanInstance& p_instance,
|
||||
const VulkanSurface* p_surface,
|
||||
const eastl::string_view p_deviceNameHint)
|
||||
{
|
||||
const vk::SurfaceKHR surfaceHandle = p_surface != nullptr ? p_surface->GetHandle() : vk::SurfaceKHR {};
|
||||
|
||||
const vk::ResultValue<std::vector<vk::PhysicalDevice>> physicalDevices = p_instance.GetHandle()
|
||||
.enumeratePhysicalDevices();
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||
physicalDevices.result == vk::Result::eSuccess,
|
||||
"({}) Failed to enumerate Vulkan physical devices",
|
||||
physicalDevices.result);
|
||||
|
||||
eastl::vector<PhysicalDeviceCandidate> candidates;
|
||||
for (const vk::PhysicalDevice physicalDevice: physicalDevices.value)
|
||||
{
|
||||
SelectedQueueFamilies queueFamilies = SelectQueueFamilies(physicalDevice, surfaceHandle);
|
||||
if (!IsPhysicalDeviceSuitable(queueFamilies, static_cast<bool>(surfaceHandle)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
candidates.push_back({physicalDevice, physicalDevice.getProperties(), eastl::move(queueFamilies)});
|
||||
}
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler, !candidates.empty(), "No suitable Vulkan physical device found");
|
||||
|
||||
const PhysicalDeviceCandidate& selected = SelectPhysicalDevice(candidates, p_deviceNameHint);
|
||||
m_physicalDevice = selected.m_handle;
|
||||
|
||||
BIGFOOT_LOG_INFO(GRAPHICSVULKAN_LOGGER,
|
||||
"Selected Vulkan physical device '{}' ({})",
|
||||
selected.m_properties.deviceName.data(),
|
||||
vk::to_string(selected.m_properties.deviceType));
|
||||
|
||||
eastl::vector<std::uint32_t> uniqueFamilies;
|
||||
for (const eastl::optional<std::uint32_t> family: {selected.m_queueFamilies.m_graphics,
|
||||
selected.m_queueFamilies.m_compute,
|
||||
selected.m_queueFamilies.m_transfer,
|
||||
selected.m_queueFamilies.m_present})
|
||||
{
|
||||
if (family.has_value() &&
|
||||
eastl::find(uniqueFamilies.begin(), uniqueFamilies.end(), *family) == uniqueFamilies.end())
|
||||
{
|
||||
uniqueFamilies.push_back(*family);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr float queuePriority = 1.0f;
|
||||
eastl::vector<vk::DeviceQueueCreateInfo> queueCreateInfos;
|
||||
queueCreateInfos.reserve(uniqueFamilies.size());
|
||||
for (const std::uint32_t family: uniqueFamilies)
|
||||
{
|
||||
queueCreateInfos.push_back({{}, family, 1u, &queuePriority});
|
||||
}
|
||||
|
||||
eastl::vector<const char*> enabledExtensions;
|
||||
if (surfaceHandle)
|
||||
{
|
||||
enabledExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
|
||||
}
|
||||
|
||||
const vk::DeviceCreateInfo deviceCreateInfo {{}, queueCreateInfos, {}, enabledExtensions};
|
||||
|
||||
vk::ResultValue<vk::Device> device {vk::Result::eSuccess, vk::Device {}};
|
||||
{
|
||||
BIGFOOT_LSAN_ONLY(const __lsan::ScopedDisabler lsanDisabler;)
|
||||
device = m_physicalDevice.createDevice(deviceCreateInfo);
|
||||
}
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||
device.result == vk::Result::eSuccess,
|
||||
"({}) Failed to create Vulkan device",
|
||||
device.result);
|
||||
m_device = device.value;
|
||||
|
||||
m_queues[static_cast<size_t>(GraphicsQueueType::Graphics)] = CreateQueue(m_device,
|
||||
selected.m_queueFamilies.m_graphics,
|
||||
GraphicsQueueType::Graphics);
|
||||
m_queues[static_cast<size_t>(GraphicsQueueType::Compute)] = CreateQueue(m_device,
|
||||
selected.m_queueFamilies.m_compute,
|
||||
GraphicsQueueType::Compute);
|
||||
m_queues[static_cast<size_t>(GraphicsQueueType::Transfer)] = CreateQueue(m_device,
|
||||
selected.m_queueFamilies.m_transfer,
|
||||
GraphicsQueueType::Transfer);
|
||||
m_queues[static_cast<size_t>(GraphicsQueueType::Present)] = CreateQueue(m_device,
|
||||
selected.m_queueFamilies.m_present,
|
||||
GraphicsQueueType::Present);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
VulkanDevice::~VulkanDevice()
|
||||
{
|
||||
m_device.destroy();
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
const GraphicsQueue* VulkanDevice::GetQueue(const GraphicsQueueType p_type) const
|
||||
{
|
||||
const eastl::optional<VulkanQueue>& queue = m_queues[static_cast<size_t>(p_type)];
|
||||
return queue.has_value() ? &*queue : nullptr;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
vk::PhysicalDevice VulkanDevice::GetPhysicalDeviceHandle() const
|
||||
{
|
||||
return m_physicalDevice;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
vk::Device VulkanDevice::GetHandle() const
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
eastl::unique_ptr<GraphicsDevice> CreateVulkanDevice(const GraphicsInstance& p_instance,
|
||||
const DeviceCreateInfo& p_createInfo)
|
||||
{
|
||||
return eastl::make_unique<VulkanDevice>(static_cast<const VulkanInstance&>(p_instance),
|
||||
static_cast<const VulkanSurface*>(p_createInfo.m_surface),
|
||||
p_createInfo.m_deviceNameHint);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
bool RegisterVulkanDeviceFactory()
|
||||
{
|
||||
const bool inserted = g_graphicsDeviceFactory->Register(GraphicsAPI::Vulkan, &CreateVulkanDevice);
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler, inserted, "Failed to register the Vulkan graphics device factory");
|
||||
return inserted;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
const bool g_vulkanDeviceFactoryRegistered = RegisterVulkanDeviceFactory();
|
||||
} // namespace Bigfoot::Vulkan
|
||||
@@ -0,0 +1,58 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanImage.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#include <GraphicsVulkan/VulkanImage.hpp>
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
VulkanImage::VulkanImage(const vk::Image p_image, const PixelFormat p_format, const vk::Extent2D p_extent):
|
||||
m_image(p_image),
|
||||
m_format(p_format),
|
||||
m_extent(p_extent)
|
||||
{
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
VulkanImage::VulkanImage(VulkanImage&& p_image) noexcept:
|
||||
GraphicsImage(),
|
||||
m_image(p_image.m_image),
|
||||
m_format(p_image.m_format),
|
||||
m_extent(p_image.m_extent)
|
||||
{
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
VulkanImage& VulkanImage::operator=(VulkanImage&& p_image) noexcept
|
||||
{
|
||||
m_image = p_image.m_image;
|
||||
m_format = p_image.m_format;
|
||||
m_extent = p_image.m_extent;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
PixelFormat VulkanImage::GetFormat() const
|
||||
{
|
||||
return m_format;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
glm::uvec2 VulkanImage::GetExtent() const
|
||||
{
|
||||
return {m_extent.width, m_extent.height};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
vk::Image VulkanImage::GetHandle() const
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
} // namespace Bigfoot::Vulkan
|
||||
@@ -0,0 +1,189 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanInstance.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#include <GraphicsVulkan/VulkanInstance.hpp>
|
||||
|
||||
#include <GraphicsVulkan/GraphicsVulkanAssertHandler.hpp>
|
||||
#include <GraphicsVulkan/VulkanFormatters.hpp>
|
||||
|
||||
#include <Utils/TargetMacros.h>
|
||||
|
||||
#include <Engine/EngineInfo_generated.hpp>
|
||||
|
||||
#include <EASTL/algorithm.h>
|
||||
#include <EASTL/string.h>
|
||||
#include <EASTL/vector.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
[[nodiscard]]
|
||||
std::uint32_t ToVulkanVersion(const Bigfoot::Version p_version)
|
||||
{
|
||||
return VK_MAKE_VERSION(p_version.GetMajor(), p_version.GetMinor(), p_version.GetPatch());
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
vk::Bool32 VulkanDebugCallback(const vk::DebugUtilsMessageSeverityFlagBitsEXT p_severity,
|
||||
[[maybe_unused]] vk::DebugUtilsMessageTypeFlagsEXT p_type,
|
||||
const vk::DebugUtilsMessengerCallbackDataEXT* p_callbackData,
|
||||
[[maybe_unused]] void* p_userData)
|
||||
{
|
||||
switch (p_severity)
|
||||
{
|
||||
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eError:
|
||||
BIGFOOT_LOG_ERROR(::Bigfoot::GRAPHICSVULKAN_LOGGER, "{}", p_callbackData->pMessage);
|
||||
break;
|
||||
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning:
|
||||
BIGFOOT_LOG_WARN(::Bigfoot::GRAPHICSVULKAN_LOGGER, "{}", p_callbackData->pMessage);
|
||||
break;
|
||||
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eInfo:
|
||||
BIGFOOT_LOG_INFO(::Bigfoot::GRAPHICSVULKAN_LOGGER, "{}", p_callbackData->pMessage);
|
||||
break;
|
||||
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eVerbose:
|
||||
default:
|
||||
BIGFOOT_LOG_TRACE(::Bigfoot::GRAPHICSVULKAN_LOGGER, "{}", p_callbackData->pMessage);
|
||||
break;
|
||||
}
|
||||
return VK_FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
VulkanInstance::VulkanInstance(const eastl::string_view p_applicationName, const Version p_applicationVersion)
|
||||
{
|
||||
const PFN_vkGetInstanceProcAddr getInstanceProcAddr = m_loader.getProcAddress<PFN_vkGetInstanceProcAddr>(
|
||||
"vkGetInstanceProcAddr");
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler, getInstanceProcAddr != nullptr, "vkGetInstanceProcAddr not found!");
|
||||
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init(getInstanceProcAddr);
|
||||
|
||||
const eastl::string applicationName {p_applicationName};
|
||||
const vk::ApplicationInfo applicationInfo {applicationName.c_str(),
|
||||
ToVulkanVersion(p_applicationVersion),
|
||||
BIGFOOT_NAME.data(),
|
||||
ToVulkanVersion(BIGFOOT_VERSION),
|
||||
VK_API_VERSION_1_3};
|
||||
|
||||
eastl::vector<const char*> enabledLayers;
|
||||
eastl::vector<const char*> enabledExtensions {
|
||||
VK_KHR_SURFACE_EXTENSION_NAME,
|
||||
BIGFOOT_WINDOWS_OR_LINUX(VK_KHR_WIN32_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME)};
|
||||
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
const vk::ResultValue<std::vector<vk::LayerProperties>> availableLayers = vk::enumerateInstanceLayerProperties();
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||
availableLayers.result == vk::Result::eSuccess,
|
||||
"({}) Failed to enumerate Vulkan instance layers",
|
||||
availableLayers.result);
|
||||
|
||||
const bool validationLayerAvailable = eastl::find_if(availableLayers.value.begin(),
|
||||
availableLayers.value.end(),
|
||||
[](const vk::LayerProperties& p_layer)
|
||||
{
|
||||
return eastl::string_view {p_layer.layerName.data()} ==
|
||||
"VK_LAYER_KHRONOS_validation";
|
||||
}) != availableLayers.value.end();
|
||||
|
||||
if (validationLayerAvailable)
|
||||
{
|
||||
enabledLayers.push_back("VK_LAYER_KHRONOS_validation");
|
||||
enabledExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
BIGFOOT_LOG_WARN(GRAPHICSVULKAN_LOGGER, "Vulkan validation layer requested but not available");
|
||||
}
|
||||
#endif
|
||||
|
||||
const vk::InstanceCreateInfo instanceCreateInfo {{}, &applicationInfo, enabledLayers, enabledExtensions};
|
||||
|
||||
vk::ResultValue<vk::Instance> instance {vk::Result::eSuccess, vk::Instance {}};
|
||||
{
|
||||
BIGFOOT_LSAN_ONLY(const __lsan::ScopedDisabler lsanDisabler;)
|
||||
instance = vk::createInstance(instanceCreateInfo);
|
||||
}
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||
instance.result == vk::Result::eSuccess,
|
||||
"({}) Failed to create Vulkan instance",
|
||||
instance.result);
|
||||
m_instance = instance.value;
|
||||
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init(m_instance);
|
||||
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
if (validationLayerAvailable)
|
||||
{
|
||||
vk::DebugUtilsMessengerCreateInfoEXT messengerCreateInfo {};
|
||||
messengerCreateInfo.messageSeverity = vk::DebugUtilsMessageSeverityFlagsEXT {
|
||||
vk::DebugUtilsMessageSeverityFlagBitsEXT::eVerbose | vk::DebugUtilsMessageSeverityFlagBitsEXT::eInfo |
|
||||
vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning | vk::DebugUtilsMessageSeverityFlagBitsEXT::eError};
|
||||
messengerCreateInfo.messageType = vk::DebugUtilsMessageTypeFlagsEXT {
|
||||
vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation |
|
||||
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance};
|
||||
messengerCreateInfo.pfnUserCallback = &VulkanDebugCallback;
|
||||
|
||||
const vk::ResultValue<vk::DebugUtilsMessengerEXT> messenger = m_instance.createDebugUtilsMessengerEXT(
|
||||
messengerCreateInfo);
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||
messenger.result == vk::Result::eSuccess,
|
||||
"({}) Failed to create Vulkan debug messenger",
|
||||
messenger.result);
|
||||
m_debugMessenger = messenger.value;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
VulkanInstance::~VulkanInstance()
|
||||
{
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
if (m_debugMessenger)
|
||||
{
|
||||
m_instance.destroyDebugUtilsMessengerEXT(m_debugMessenger);
|
||||
}
|
||||
#endif
|
||||
m_instance.destroy();
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
vk::Instance VulkanInstance::GetHandle() const
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
eastl::unique_ptr<GraphicsInstance> CreateVulkanInstance(const eastl::string_view p_applicationName,
|
||||
const Version p_applicationVersion)
|
||||
{
|
||||
return eastl::make_unique<VulkanInstance>(p_applicationName, p_applicationVersion);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
bool RegisterVulkanInstanceFactory()
|
||||
{
|
||||
const bool inserted = g_graphicsInstanceFactory->Register(GraphicsAPI::Vulkan, &CreateVulkanInstance);
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler, inserted, "Failed to register the Vulkan graphics instance factory");
|
||||
return inserted;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
const bool g_vulkanInstanceFactoryRegistered = RegisterVulkanInstanceFactory();
|
||||
} // namespace Bigfoot::Vulkan
|
||||
@@ -0,0 +1,55 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanPixelFormat.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#include <GraphicsVulkan/VulkanPixelFormat.hpp>
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
vk::Format ToVulkanFormat(const PixelFormat p_format)
|
||||
{
|
||||
switch (p_format)
|
||||
{
|
||||
case PixelFormat::R8G8B8A8Unorm:
|
||||
return vk::Format::eR8G8B8A8Unorm;
|
||||
case PixelFormat::R8G8B8A8Srgb:
|
||||
return vk::Format::eR8G8B8A8Srgb;
|
||||
case PixelFormat::B8G8R8A8Unorm:
|
||||
return vk::Format::eB8G8R8A8Unorm;
|
||||
case PixelFormat::B8G8R8A8Srgb:
|
||||
return vk::Format::eB8G8R8A8Srgb;
|
||||
case PixelFormat::A2B10G10R10UnormPack32:
|
||||
return vk::Format::eA2B10G10R10UnormPack32;
|
||||
case PixelFormat::R16G16B16A16Sfloat:
|
||||
return vk::Format::eR16G16B16A16Sfloat;
|
||||
case PixelFormat::Undefined:
|
||||
default:
|
||||
return vk::Format::eUndefined;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
PixelFormat FromVulkanFormat(const vk::Format p_format)
|
||||
{
|
||||
switch (p_format)
|
||||
{
|
||||
case vk::Format::eR8G8B8A8Unorm:
|
||||
return PixelFormat::R8G8B8A8Unorm;
|
||||
case vk::Format::eR8G8B8A8Srgb:
|
||||
return PixelFormat::R8G8B8A8Srgb;
|
||||
case vk::Format::eB8G8R8A8Unorm:
|
||||
return PixelFormat::B8G8R8A8Unorm;
|
||||
case vk::Format::eB8G8R8A8Srgb:
|
||||
return PixelFormat::B8G8R8A8Srgb;
|
||||
case vk::Format::eA2B10G10R10UnormPack32:
|
||||
return PixelFormat::A2B10G10R10UnormPack32;
|
||||
case vk::Format::eR16G16B16A16Sfloat:
|
||||
return PixelFormat::R16G16B16A16Sfloat;
|
||||
default:
|
||||
return PixelFormat::Undefined;
|
||||
}
|
||||
}
|
||||
} // namespace Bigfoot::Vulkan
|
||||
@@ -0,0 +1,58 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanQueue.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#include <GraphicsVulkan/VulkanQueue.hpp>
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
VulkanQueue::VulkanQueue(const vk::Queue p_queue, const std::uint32_t p_familyIndex, const GraphicsQueueType p_type):
|
||||
m_queue(p_queue),
|
||||
m_familyIndex(p_familyIndex),
|
||||
m_type(p_type)
|
||||
{
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
VulkanQueue::VulkanQueue(VulkanQueue&& p_queue) noexcept:
|
||||
GraphicsQueue(),
|
||||
m_queue(p_queue.m_queue),
|
||||
m_familyIndex(p_queue.m_familyIndex),
|
||||
m_type(p_queue.m_type)
|
||||
{
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
VulkanQueue& VulkanQueue::operator=(VulkanQueue&& p_queue) noexcept
|
||||
{
|
||||
m_queue = p_queue.m_queue;
|
||||
m_familyIndex = p_queue.m_familyIndex;
|
||||
m_type = p_queue.m_type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
GraphicsQueueType VulkanQueue::GetType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
vk::Queue VulkanQueue::GetHandle() const
|
||||
{
|
||||
return m_queue;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
std::uint32_t VulkanQueue::GetFamilyIndex() const
|
||||
{
|
||||
return m_familyIndex;
|
||||
}
|
||||
} // namespace Bigfoot::Vulkan
|
||||
@@ -0,0 +1,70 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanSurface.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#include <GraphicsVulkan/VulkanSurface.hpp>
|
||||
|
||||
#include <GraphicsVulkan/GraphicsVulkanAssertHandler.hpp>
|
||||
#include <GraphicsVulkan/VulkanFormatters.hpp>
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
VulkanSurface::VulkanSurface(const VulkanInstance& p_instance, const SurfaceCreateInfo& p_surfaceCreateInfo):
|
||||
m_instance(p_instance)
|
||||
{
|
||||
#ifdef BIGFOOT_WINDOWS
|
||||
const vk::Win32SurfaceCreateInfoKHR createInfo {{},
|
||||
p_surfaceCreateInfo.m_windowInstance,
|
||||
p_surfaceCreateInfo.m_windowHandle};
|
||||
const vk::ResultValue<vk::SurfaceKHR> surface = m_instance.GetHandle().createWin32SurfaceKHR(createInfo);
|
||||
#elif defined BIGFOOT_LINUX
|
||||
const vk::WaylandSurfaceCreateInfoKHR createInfo {{}, p_surfaceCreateInfo.m_display, p_surfaceCreateInfo.m_surface};
|
||||
const vk::ResultValue<vk::SurfaceKHR> surface = m_instance.GetHandle().createWaylandSurfaceKHR(createInfo);
|
||||
#endif
|
||||
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||
surface.result == vk::Result::eSuccess,
|
||||
"({}) Failed to create Vulkan surface",
|
||||
surface.result);
|
||||
m_surface = surface.value;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
VulkanSurface::~VulkanSurface()
|
||||
{
|
||||
m_instance.GetHandle().destroySurfaceKHR(m_surface);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
vk::SurfaceKHR VulkanSurface::GetHandle() const
|
||||
{
|
||||
return m_surface;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
eastl::unique_ptr<GraphicsSurface> CreateVulkanSurface(const GraphicsInstance& p_instance,
|
||||
const SurfaceCreateInfo& p_surfaceCreateInfo)
|
||||
{
|
||||
return eastl::make_unique<VulkanSurface>(static_cast<const VulkanInstance&>(p_instance), p_surfaceCreateInfo);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
bool RegisterVulkanSurfaceFactory()
|
||||
{
|
||||
const bool inserted = g_graphicsSurfaceFactory->Register(GraphicsAPI::Vulkan, &CreateVulkanSurface);
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler, inserted, "Failed to register the Vulkan graphics surface factory");
|
||||
return inserted;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
const bool g_vulkanSurfaceFactoryRegistered = RegisterVulkanSurfaceFactory();
|
||||
} // namespace Bigfoot::Vulkan
|
||||
@@ -0,0 +1,235 @@
|
||||
/*********************************************************************
|
||||
* \file VulkanSwapchain.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date September 2026
|
||||
*********************************************************************/
|
||||
#include <GraphicsVulkan/VulkanSwapchain.hpp>
|
||||
|
||||
#include <GraphicsVulkan/GraphicsVulkanAssertHandler.hpp>
|
||||
#include <GraphicsVulkan/VulkanFormatters.hpp>
|
||||
#include <GraphicsVulkan/VulkanPixelFormat.hpp>
|
||||
#include <GraphicsVulkan/VulkanQueue.hpp>
|
||||
|
||||
#include <EASTL/algorithm.h>
|
||||
#include <EASTL/vector.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
namespace Bigfoot::Vulkan
|
||||
{
|
||||
[[nodiscard]]
|
||||
vk::SurfaceFormatKHR SelectSurfaceFormat(const std::span<const vk::SurfaceFormatKHR> p_formats)
|
||||
{
|
||||
const auto it = eastl::find_if(p_formats.begin(),
|
||||
p_formats.end(),
|
||||
[](const vk::SurfaceFormatKHR& p_format)
|
||||
{
|
||||
return p_format.format == vk::Format::eB8G8R8A8Srgb &&
|
||||
p_format.colorSpace == vk::ColorSpaceKHR::eSrgbNonlinear;
|
||||
});
|
||||
|
||||
return it != p_formats.end() ? *it : p_formats.front();
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
vk::PresentModeKHR SelectPresentMode(const std::span<const vk::PresentModeKHR> p_presentModes)
|
||||
{
|
||||
const auto it = eastl::find(p_presentModes.begin(), p_presentModes.end(), vk::PresentModeKHR::eMailbox);
|
||||
|
||||
// eFifo is guaranteed by the spec to always be supported
|
||||
return it != p_presentModes.end() ? *it : vk::PresentModeKHR::eFifo;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
vk::Extent2D SelectExtent(const vk::SurfaceCapabilitiesKHR& p_capabilities, const glm::uvec2 p_extent)
|
||||
{
|
||||
constexpr std::uint32_t undefinedExtent = std::numeric_limits<std::uint32_t>::max();
|
||||
if (p_capabilities.currentExtent.width != undefinedExtent)
|
||||
{
|
||||
return p_capabilities.currentExtent;
|
||||
}
|
||||
|
||||
return {eastl::clamp(p_extent.x, p_capabilities.minImageExtent.width, p_capabilities.maxImageExtent.width),
|
||||
eastl::clamp(p_extent.y, p_capabilities.minImageExtent.height, p_capabilities.maxImageExtent.height)};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
vk::CompositeAlphaFlagBitsKHR SelectCompositeAlpha(const vk::CompositeAlphaFlagsKHR p_supportedCompositeAlpha)
|
||||
{
|
||||
for (const vk::CompositeAlphaFlagBitsKHR candidate: {vk::CompositeAlphaFlagBitsKHR::eOpaque,
|
||||
vk::CompositeAlphaFlagBitsKHR::ePreMultiplied,
|
||||
vk::CompositeAlphaFlagBitsKHR::ePostMultiplied,
|
||||
vk::CompositeAlphaFlagBitsKHR::eInherit})
|
||||
{
|
||||
if (p_supportedCompositeAlpha & candidate)
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
return vk::CompositeAlphaFlagBitsKHR::eOpaque;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
VulkanSwapchain::VulkanSwapchain(const VulkanDevice& p_device,
|
||||
const VulkanSurface& p_surface,
|
||||
const glm::uvec2 p_extent):
|
||||
m_device(p_device)
|
||||
{
|
||||
const vk::PhysicalDevice physicalDevice = p_device.GetPhysicalDeviceHandle();
|
||||
const vk::SurfaceKHR surface = p_surface.GetHandle();
|
||||
|
||||
const vk::ResultValue<vk::SurfaceCapabilitiesKHR> capabilities = physicalDevice.getSurfaceCapabilitiesKHR(surface);
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||
capabilities.result == vk::Result::eSuccess,
|
||||
"({}) Failed to get Vulkan surface capabilities",
|
||||
capabilities.result);
|
||||
|
||||
const vk::ResultValue<std::vector<vk::SurfaceFormatKHR>> formats = physicalDevice.getSurfaceFormatsKHR(surface);
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||
formats.result == vk::Result::eSuccess && !formats.value.empty(),
|
||||
"({}) Failed to get Vulkan surface formats",
|
||||
formats.result);
|
||||
|
||||
const vk::ResultValue<std::vector<vk::PresentModeKHR>> presentModes = physicalDevice.getSurfacePresentModesKHR(
|
||||
surface);
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||
presentModes.result == vk::Result::eSuccess && !presentModes.value.empty(),
|
||||
"({}) Failed to get Vulkan surface present modes",
|
||||
presentModes.result);
|
||||
|
||||
const vk::SurfaceFormatKHR surfaceFormat = SelectSurfaceFormat(formats.value);
|
||||
const vk::PresentModeKHR presentMode = SelectPresentMode(presentModes.value);
|
||||
const vk::Extent2D extent = SelectExtent(capabilities.value, p_extent);
|
||||
|
||||
std::uint32_t imageCount = capabilities.value.minImageCount + 1;
|
||||
if (capabilities.value.maxImageCount > 0)
|
||||
{
|
||||
imageCount = eastl::min(imageCount, capabilities.value.maxImageCount);
|
||||
}
|
||||
|
||||
const auto* const graphicsQueue = static_cast<const VulkanQueue*>(p_device.GetQueue(GraphicsQueueType::Graphics));
|
||||
const auto* const presentQueue = static_cast<const VulkanQueue*>(p_device.GetQueue(GraphicsQueueType::Present));
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||
graphicsQueue != nullptr && presentQueue != nullptr,
|
||||
"Cannot create a swapchain on a device with no graphics or present queue");
|
||||
|
||||
const bool sameQueueFamily = graphicsQueue->GetFamilyIndex() == presentQueue->GetFamilyIndex();
|
||||
|
||||
eastl::vector<std::uint32_t> queueFamilyIndices;
|
||||
if (!sameQueueFamily)
|
||||
{
|
||||
queueFamilyIndices = {graphicsQueue->GetFamilyIndex(), presentQueue->GetFamilyIndex()};
|
||||
}
|
||||
|
||||
const vk::SwapchainCreateInfoKHR swapchainCreateInfo {
|
||||
{},
|
||||
surface,
|
||||
imageCount,
|
||||
surfaceFormat.format,
|
||||
surfaceFormat.colorSpace,
|
||||
extent,
|
||||
1,
|
||||
vk::ImageUsageFlagBits::eColorAttachment,
|
||||
sameQueueFamily ? vk::SharingMode::eExclusive : vk::SharingMode::eConcurrent,
|
||||
queueFamilyIndices,
|
||||
capabilities.value.currentTransform,
|
||||
SelectCompositeAlpha(capabilities.value.supportedCompositeAlpha),
|
||||
presentMode,
|
||||
VK_TRUE};
|
||||
|
||||
const vk::ResultValue<vk::SwapchainKHR> swapchain = p_device.GetHandle().createSwapchainKHR(swapchainCreateInfo);
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||
swapchain.result == vk::Result::eSuccess,
|
||||
"({}) Failed to create Vulkan swapchain",
|
||||
swapchain.result);
|
||||
m_swapchain = swapchain.value;
|
||||
|
||||
const vk::ResultValue<std::vector<vk::Image>> images = p_device.GetHandle().getSwapchainImagesKHR(m_swapchain);
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||
images.result == vk::Result::eSuccess,
|
||||
"({}) Failed to get Vulkan swapchain images",
|
||||
images.result);
|
||||
const PixelFormat imageFormat = FromVulkanFormat(surfaceFormat.format);
|
||||
m_images.reserve(images.value.size());
|
||||
for (const vk::Image image: images.value)
|
||||
{
|
||||
m_images.emplace_back(image, imageFormat, extent);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
VulkanSwapchain::~VulkanSwapchain()
|
||||
{
|
||||
m_device.GetHandle().destroySwapchainKHR(m_swapchain);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
std::uint32_t VulkanSwapchain::GetImageCount() const
|
||||
{
|
||||
return static_cast<std::uint32_t>(m_images.size());
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
const GraphicsImage& VulkanSwapchain::GetImage(const std::uint32_t p_index) const
|
||||
{
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||
p_index < m_images.size(),
|
||||
"Swapchain image index {} out of range (swapchain has {} images)",
|
||||
p_index,
|
||||
m_images.size());
|
||||
return m_images[p_index];
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
vk::SwapchainKHR VulkanSwapchain::GetHandle() const
|
||||
{
|
||||
return m_swapchain;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
eastl::span<const VulkanImage> VulkanSwapchain::GetImages() const
|
||||
{
|
||||
return {m_images.data(), m_images.size()};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
eastl::unique_ptr<GraphicsSwapchain> CreateVulkanSwapchain(const SwapchainCreateInfo& p_createInfo)
|
||||
{
|
||||
return eastl::make_unique<VulkanSwapchain>(static_cast<const VulkanDevice&>(*p_createInfo.m_device),
|
||||
static_cast<const VulkanSurface&>(*p_createInfo.m_surface),
|
||||
p_createInfo.m_extent);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
[[nodiscard]]
|
||||
bool RegisterVulkanSwapchainFactory()
|
||||
{
|
||||
const bool inserted = g_graphicsSwapchainFactory->Register(GraphicsAPI::Vulkan, &CreateVulkanSwapchain);
|
||||
CRITICAL_ASSERT(GraphicsVulkanAssertHandler, inserted, "Failed to register the Vulkan graphics swapchain factory");
|
||||
return inserted;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
const bool g_vulkanSwapchainFactoryRegistered = RegisterVulkanSwapchainFactory();
|
||||
} // namespace Bigfoot::Vulkan
|
||||
@@ -13,6 +13,6 @@ bigfoot_create_package_lib(
|
||||
"${PrivateLibraries}"
|
||||
"${BigfootPublicDependencies}"
|
||||
"${BigfootPrivateDependencies}"
|
||||
"")
|
||||
"Bigfoot/Libs")
|
||||
|
||||
bigfoot_create_logger()
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <System/SystemAssertHandler.hpp>
|
||||
|
||||
#include <bit>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
@@ -83,7 +82,7 @@ eastl::vector<std::byte> File::Read(const std::size_t p_offset, const std::size_
|
||||
|
||||
eastl::vector<std::byte> data;
|
||||
data.resize(p_size);
|
||||
file.read(std::bit_cast<char*>(data.data()), static_cast<std::streamsize>(data.size()));
|
||||
file.read(reinterpret_cast<char*>(data.data()), static_cast<std::streamsize>(data.size()));
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -100,7 +99,7 @@ void File::Write(const eastl::span<const std::byte> p_data, const std::size_t p_
|
||||
CRITICAL_ASSERT(SystemAssertHandler, file.is_open(), "Failed to open file {} for writing", path);
|
||||
|
||||
file.seekp(static_cast<std::streamoff>(p_offset), std::ios::beg);
|
||||
file.write(std::bit_cast<const char*>(p_data.data()), static_cast<std::streamsize>(p_data.size()));
|
||||
file.write(reinterpret_cast<const char*>(p_data.data()), static_cast<std::streamsize>(p_data.size()));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
@@ -112,8 +111,8 @@ void File::Delete() const
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
File::File(const std::filesystem::path& p_path):
|
||||
m_path(p_path),
|
||||
File::File(std::filesystem::path p_path):
|
||||
m_path(std::move(p_path)),
|
||||
m_pathString(m_path.string().c_str())
|
||||
{
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user