Skip to content

Commit

Permalink
added errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JungerBoyo authored and JungerBoyo committed Jan 5, 2024
1 parent e7da429 commit bc59d0e
Show file tree
Hide file tree
Showing 30 changed files with 201 additions and 249 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ ve001_log
maps/
ve001_frame_samples.csv
ve001_meshing_samples.csv
data/
3 changes: 2 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ def requirements(self):
self.requires("glad/0.1.36")
self.requires("spdlog/1.11.0")
self.requires("cli11/2.3.2")
self.requires("fastnoise2/0.10.0-alpha")
if (os != 'Windows'):
self.requires("fastnoise2/0.10.0-alpha")
self.requires("glfw/3.3.8")
13 changes: 5 additions & 8 deletions plot_benchmark_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,15 @@ def getAxis(axes, i, number_of_plots):

columns_count = int(app_args.columns_count)

number_of_plots = app_args.frame_timings * 2 + app_args.meshing_timings * 2 + app_args.prims_samples_ratio + app_args.data_usage_server + app_args.data_usage_client
number_of_plots = app_args.frame_timings * 1 + app_args.meshing_timings * 2 + app_args.prims_samples_ratio + app_args.data_usage_server + app_args.data_usage_client + app_args.chunks_count + 1

figure,axes = plt.subplots(int(number_of_plots/columns_count)+int(number_of_plots%columns_count), number_of_plots if columns_count > number_of_plots else columns_count)

i = 0

if app_args.frame_timings:
showPlot('Czas klatki (serwer)', 'klatka', 'czas [ms]', [], [frame_samples_data['gpu_frame_time_elapsed_ns']/1_000_000], False, getAxis(axes, i, number_of_plots))
showPlot('Czas klatki', 'klatka', 'czas [ms]', [], [frame_samples_data['gpu_frame_time_elapsed_ns']/1_000_000], False, getAxis(axes, i, number_of_plots))
i += 1
showPlot('Czas klatki (klient)', 'klatka', 'czas [ms]', [], [frame_samples_data['cpu_frame_time_elapsed_ns']/1_000_000], False, getAxis(axes, i, number_of_plots))
i += 1


if app_args.meshing_timings:
showPlot('Czasy siatkowania kawałków (same wykonanie)', 'kawałek', 'czas [ms]', [], [meshing_samples_data['gpu_meshing_time_elapsed_ns']/1_000_000], False, getAxis(axes, i, number_of_plots))
Expand Down Expand Up @@ -125,11 +122,11 @@ def getAxis(axes, i, number_of_plots):
)
i += 1
if app_args.chunks_count:
showPlot('Ilość użytych kawałków', 'klatka', 'ilość kawałków', [], [frame_samples_data['chunks_in_use']], False, getAxis(axes, i, number_of_plots))
showPlot('Ilość użytych kawałków na klatkę', 'klatka', 'ilość kawałków', [], [frame_samples_data['chunks_in_use']], False, getAxis(axes, i, number_of_plots))
i += 1

if float(app_args.h_space) != 0.0:
plt.subplots_adjust(hspace=float(app_args.h_space))
if float(app_args.w_space) != 0.0:
plt.subplots_adjust(wspace=float(app_args.w_space))
plt.show()
plt.show()
6 changes: 3 additions & 3 deletions res/vmath/vmath.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef VE001_VMATH_H
#define VE001_VMATH_H
#ifndef VMATH_H
#define VMATH_H

#include <numbers>
#include <cmath>
Expand Down Expand Up @@ -458,7 +458,7 @@ struct misc {

const auto rotated_q_point =
Q::mul(Q::mul(
qy,
qz,
Q::mul(Q::mul(
qy,
Q::mul(Q::mul(
Expand Down
28 changes: 3 additions & 25 deletions shaders/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
add_library(sh_config INTERFACE)
target_compile_definitions(sh_config INTERFACE
VE001_SH_CONIFG_GL_VERSION_MAJOR=4
VE001_SH_CONIFG_GL_VERSION_MINOR=5

VE001_SH_CONFIG_ATTRIB_INDEX_POSITION=0
VE001_SH_CONFIG_ATTRIB_INDEX_TEXCOORD=1

VE001_SH_CONFIG_TEX_BINDING_MATERIAL_TEXTURES=0
VE001_SH_CONFIG_TEX_BINDING_DIR_SHADOW_MAPS=1
VE001_SH_CONFIG_TEX_BINDING_OMNI_DIR_SHADOW_MAPS=2

VE001_SH_CONFIG_UBO_BINDING_GENERAL=0
VE001_SH_CONFIG_UBO_BINDING_LIGHTS_DESCRIPTOR=1
VE001_SH_CONFIG_UBO_BINDING_MESHING_DESCRIPTOR=2

VE001_SH_CONFIG_SSBO_BINDING_MATERIAL_PARAMS=0
VE001_SH_CONFIG_SSBO_BINDING_MATERIAL_DESCRIPTORS=1
VE001_SH_CONFIG_SSBO_BINDING_DIRECTIONAL_LIGHTS=2
VE001_SH_CONFIG_SSBO_BINDING_POINT_LIGHTS=3
VE001_SH_CONFIG_SSBO_BINDING_SPOT_LIGHTS=4
VE001_SH_CONFIG_SSBO_BINDING_VOXEL_DATA=5
VE001_SH_CONFIG_SSBO_BINDING_MESHING_TEMP=6
VE001_SH_CONFIG_SSBO_BINDING_MESH_DATA=7
)
#add_library(sh_config INTERFACE)
#target_compile_definitions(sh_config INTERFACE
#)

if(REMOTE_BUILD)
add_custom_target(compile_and_copy_shaders_dirs
Expand Down
Binary file modified shaders/bin/greedy_meshing_shader/comp.spv
Binary file not shown.
11 changes: 7 additions & 4 deletions shaders/src/greedy_meshing_shader/shader.comp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ void main() {

const int plane_size = chunk_size.x * chunk_size.y;
ivec3 i = ivec3(0, 0, int(axis_step));


bool any_visible = false;
/// Fill the visibility query
for (;i[1] < logical_extent[1]; ++i[1]) {
i[0] = 0;
Expand All @@ -110,19 +111,21 @@ void main() {
if (i[2] == edge_value) {
uint state_index = i[0] + i[1] * logical_extent[0];
states[state_index >> 5] |= (uint(1) << (state_index & uint(31)));
any_visible = true;
continue;
}
i[2] += polarity;
voxel_index = i[real_indices[0]] + i[real_indices[1]] * chunk_size.x + i[real_indices[2]] * plane_size;
if (bitfieldExtract(voxel_data[voxel_index >> 1], int((voxel_index & uint(1)) << 4), 16) == 0) {
uint state_index = i[0] + i[1] * logical_extent[0];
states[state_index >> 5] |= (uint(1) << (state_index & uint(31)));
any_visible = true;
}
i[2] -= polarity;
}
}
}

if (any_visible) {
i[1] = 0;
for (;i[1] < logical_extent[1]; ++i[1]) {
i[0] = 0;
Expand Down Expand Up @@ -255,7 +258,7 @@ void main() {
}
}
}

}
}
/// END ///
memoryBarrierShared();
Expand All @@ -265,4 +268,4 @@ void main() {
axes_steps[face_id] += gl_WorkGroupSize.x;
}
///////////////////////////////
}
}
15 changes: 11 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
find_package(glad REQUIRED)
find_package(spdlog REQUIRED)
find_package(FastNoise2 REQUIRED)

if (NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
find_package(FastNoise2 REQUIRED)
endif()

find_package(CLI11 REQUIRED)
find_package(glfw3 REQUIRED)

Expand All @@ -11,6 +15,12 @@ add_subdirectory(engine)
add_subdirectory(sandbox_utils)
add_subdirectory(logger)


if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
target_compile_definitions(logger PRIVATE WINDOWS)
target_compile_definitions(sandbox_utils PRIVATE WINDOWS)
endif()

add_library(gl_context STATIC gl_context.h gl_context.cpp)
target_link_libraries(gl_context PUBLIC glad::glad)
target_link_libraries(gl_context PRIVATE glfw)
Expand All @@ -29,11 +39,8 @@ target_link_libraries(ve001-benchmark PRIVATE
sandbox_utils
ve001
glfw
sh_config
logger
CLI11::CLI11
)

target_precompile_headers(ve001-benchmark PRIVATE "<CLI/CLI.hpp>")

add_dependencies(ve001-benchmark compile_and_copy_shaders_dirs)
35 changes: 25 additions & 10 deletions src/engine/chunk_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ void ChunkPool::init() noexcept {
0
);

if (glGetError() == GL_OUT_OF_MEMORY) {
_engine_context.error |= Error::GPU_ALLOCATION_FAILED;
return;
}

glCreateVertexArrays(1, &_vao_id);
setVertexLayout(_vao_id, _vbo_id);

Expand All @@ -59,12 +64,24 @@ void ChunkPool::init() noexcept {
GL_MAP_WRITE_BIT|GL_MAP_PERSISTENT_BIT|GL_MAP_COHERENT_BIT
);

if (glGetError() == GL_OUT_OF_MEMORY) {
_engine_context.error |= Error::GPU_ALLOCATION_FAILED;
return;
}

_dibo_mapped_ptr = glMapNamedBufferRange(
_dibo_id,
0, 6 * _chunks_count * sizeof(DrawElementsIndirectCmd),
GL_MAP_WRITE_BIT|GL_MAP_PERSISTENT_BIT|GL_MAP_COHERENT_BIT
);

if (_dibo_mapped_ptr == nullptr) {
glDeleteBuffers(3, tmp);
glDeleteVertexArrays(1, &_vao_id);
_engine_context.error |= Error::GPU_BUFFER_MAPPING_FAILED;
return;
}

try {
_chunks.reserve(_chunks_count);
_chunk_id_to_index.resize(_chunks_count, INVALID_CHUNK_INDEX);
Expand Down Expand Up @@ -93,19 +110,16 @@ void ChunkPool::init() noexcept {
} catch ([[maybe_unsused]] const std::exception& e) {
glDeleteBuffers(3, tmp);
glDeleteVertexArrays(1, &_vao_id);
return; // TODO: Error
_engine_context.error |= Error::CPU_ALLOCATION_FAILED;
return;
}

_meshing_engine.init(_vbo_id);
}

vmath::u32 ChunkPool::allocateChunk(std::span<const vmath::u16> src, Vec3i32 position) noexcept {
if (poll()) {
chunk_completed_callback(_meshing_engine.result_gpu_meshing_time_ns, _meshing_engine.result_real_meshing_time_ns);
}

if (_free_chunks.empty()) {
return INVALID_CHUNK_ID; // TODO: Error
return INVALID_CHUNK_ID;
}

FreeChunk free_chunk{};
Expand Down Expand Up @@ -213,6 +227,11 @@ void ChunkPool::recreatePool(MeshingEngine::Result overflow_result) {

glNamedBufferStorage(_vbo_id, static_cast<u64>(_chunks_count) * _engine_context.chunk_max_current_mesh_size, nullptr, 0);

if (glGetError() == GL_OUT_OF_MEMORY) {
_engine_context.error |= Error::GPU_ALLOCATION_FAILED;
return;
}

rebindVaoToVbo(_vao_id, _vbo_id);

_meshing_engine.updateMetadata(_vbo_id);
Expand Down Expand Up @@ -256,10 +275,6 @@ bool ChunkPool::poll() {
}

void ChunkPool::deallocateChunk(u32 chunk_id) noexcept {
if (poll()) {
chunk_completed_callback(_meshing_engine.result_gpu_meshing_time_ns, _meshing_engine.result_real_meshing_time_ns);
}

if (chunk_id == INVALID_CHUNK_ID) {
return;
}
Expand Down
3 changes: 0 additions & 3 deletions src/engine/chunk_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ struct ChunkPool {
vmath::u64 cpu_active_memory_usage{ 0UL };
/// @brief gpu region usage
vmath::u64 chunks_used{ 0UL };
/// @brief called when chunk was completed
/// with its meshing times
void(*chunk_completed_callback)(vmath::u64, vmath::u64);
#endif

////////////////////////////////////////
Expand Down
4 changes: 3 additions & 1 deletion src/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static bool frustumCullingUnaryOp(


Engine::Engine(Config config) : _engine_context(EngineContext{
.error = this->error,
.chunk_size = config.chunk_size,
.half_chunk_size = Vec3i32::divScalar(config.chunk_size, 2),
.chunk_size_1D = static_cast<u64>(config.chunk_size[0]) * static_cast<u64>(config.chunk_size[1]) * static_cast<u64>(config.chunk_size[2]),
Expand All @@ -37,8 +38,9 @@ Engine::Engine(Config config) : _engine_context(EngineContext{
_world_grid(_engine_context, config.world_size, config.initial_position, config.chunk_data_streamer_threads_count, std::move(config.chunk_data_generator))
{}

void Engine::init() {
bool Engine::init() {
_world_grid.init();
return (error != Error::NO_ERROR);
}
void Engine::deinit() {
_world_grid.deinit();
Expand Down
6 changes: 5 additions & 1 deletion src/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ struct Engine {
std::optional<std::filesystem::path> meshing_shader_bin_path{"/home/regu/codium_repos/VE-001/shaders/bin/greedy_meshing_shader/comp.spv"};
};

/// @brief engine's error flags
Error error{ Error::NO_ERROR };

/// @brief if true partitioning is used based on applied partitions
bool partitioning{ false };
/// @brief engine context containing common metadata for modules
Expand Down Expand Up @@ -80,7 +83,8 @@ struct Engine {
}

/// @brief initalization of the opengl resources
void init();
/// @return true if there were errors during engine's initialization
bool init();
/// @brief updates world grid state based on camera position
/// @param position new camera position
void updateCameraPosition(vmath::Vec3f32 position);
Expand Down
4 changes: 4 additions & 0 deletions src/engine/engine_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

#include <vmath/vmath.h>

#include "enums.h"

namespace ve001 {

/// @brief context holds common state for different engine components/modules
struct EngineContext {
/// @brief errors
Error& error;
/// @brief chunk size/resolution
vmath::Vec3i32 chunk_size;
/// @brief half chunk size/resolution
Expand Down
21 changes: 21 additions & 0 deletions src/engine/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ enum Face : vmath::u32 {
Z_POS, Z_NEG
};

enum Error : vmath::u32 {
NO_ERROR = 0x0U,
GPU_ALLOCATION_FAILED = 0x01U,
CPU_ALLOCATION_FAILED = 0x02U,
GPU_BUFFER_MAPPING_FAILED = 0x04U,
FENCE_WAIT_FAILED = 0x08U,
SHADER_ATTACH_FAILED = 0x10U,
MESHING_COMMAND_QUEUE_FULL = 0x20U,
CHUNK_DATA_STREAMER_THREAD_ALLOCATION_FAILED = 0x40U,
};

inline Error operator|(Error lhs, Error rhs) {
return static_cast<Error>(static_cast<vmath::u32>(lhs) | static_cast<vmath::u32>(rhs));
}
inline Error operator&(Error lhs, Error rhs) {
return static_cast<Error>(static_cast<vmath::u32>(lhs) & static_cast<vmath::u32>(rhs));
}
inline Error& operator|=(Error& lhs, Error rhs) {
return lhs = lhs | rhs;
}

}


Expand Down
10 changes: 5 additions & 5 deletions src/engine/gpu_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
using namespace ve001;
using namespace vmath;

void GPUBuffer::init() {
Error GPUBuffer::init() {
glCreateBuffers(1, &_id);
glNamedBufferStorage(_id, _size, nullptr, GL_DYNAMIC_STORAGE_BIT);
}
void GPUBuffer::init(u32 id) {
_id = id;
glNamedBufferStorage(_id, _size, nullptr, GL_DYNAMIC_STORAGE_BIT);
if (glGetError() == GL_OUT_OF_MEMORY) {
return Error::GPU_ALLOCATION_FAILED;
}
return Error::NO_ERROR;
}
void GPUBuffer::write(const void* data) {
glNamedBufferSubData(_id, 0, _size, data);
Expand Down
Loading

0 comments on commit bc59d0e

Please sign in to comment.