diff --git a/CMakeLists.txt b/CMakeLists.txt index 05bc721..e805f96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") set(3RDPARTY_INCLUDES "") set(3RDPARTY_DLLS "") +set(3RDPARTY_PDBS "") set(3RDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Extern/3rdParty) add_subdirectory(${3RDPARTY_DIR}) @@ -49,30 +50,53 @@ add_subdirectory(${EVOENGINE_SDK_DIR}) # ------------------------------------------------------------------ # EvoEngine - Plugins # ------------------------------------------------------------------ - set(PLUGINS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/EvoEngine_Plugins) add_subdirectory(${PLUGINS_DIR}) - set(EVOENGINE_DEFS ${EVOENGINE_SDK_DEFS} ${EVOENGINE_PLUGINS_DEFS}) set(EVOENGINE_INCLUDES ${EVOENGINE_SDK_INCLUDES} ${EVOENGINE_PLUGINS_INCLUDES}) set(EVOENGINE_PCHS ${EVOENGINE_SDK_PCH} ${EVOENGINE_PLUGINS_PCHS}) -set(EVOENGINE_DLLS ${EVOENGINE_SDK_DLLS} ${EVOENGINE_PLUGINS_DLLS}) + +set(EVOENGINE_DLLS ${EVOENGINE_SDK_DLLS} ${3RDPARTY_DLLS} ${EVOENGINE_PLUGINS_DLLS}) +set(EVOENGINE_PDBS ${EVOENGINE_SDK_PDBS} ${3RDPARTY_PDBS} ${EVOENGINE_PLUGINS_PDBS}) + +set(EVOENGINE_RESOURCES ${EVOENGINE_SDK_RESOURCES} ${EVOENGINE_PLUGINS_RESOURCES}) # ------------------------------------------------------------------ # EvoEngine SDK - Copy resources # ------------------------------------------------------------------ function(evoengine_copy_resources dst_target dst_dir) + if (WIN32) + foreach (file_i ${EVOENGINE_DLLS}) + string(REPLACE "/" "\\" file_i ${file_i}) + add_custom_command(TARGET ${dst_target} POST_BUILD + COMMAND cmd /c "if exist \"${file_i}\" copy \"${file_i}\" \"${dst_dir}\\\"") + endforeach(file_i) + + foreach(file_i ${EVOENGINE_PDBS}) + string(REPLACE "/" "\\" file_i ${file_i}) + add_custom_command(TARGET ${dst_target} POST_BUILD + COMMAND cmd /c "if exist \"${file_i}\" copy \"${file_i}\" \"${dst_dir}\\\"") + endforeach(file_i) + else() + foreach (file_i ${EVOENGINE_DLLS}) + add_custom_command(TARGET ${dst_target} POST_BUILD + /bin/sh -c "if [ -e \"${file_i}\" ]; then cp \"${file_i}\" \"${dst_dir}\\\"; fi") + endforeach(file_i) + + foreach(file_i ${EVOENGINE_PDBS}) + add_custom_command(TARGET ${dst_target} POST_BUILD + /bin/sh -c "if [ -e \"${file_i}\" ]; then cp \"${file_i}\" \"${dst_dir}\\\"; fi") + endforeach(file_i) + endif() evoengine_sdk_copy_resources(${dst_target} ${dst_dir}) - foreach (EVOENGINE_DLL ${EVOENGINE_DLLS}) - add_custom_command( - TARGET ${dst_target} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${EVOENGINE_DLL} - ${dst_dir} - ) - endforeach () + foreach(folder_i ${EVOENGINE_RESOURCES}) + add_custom_command(TARGET ${dst_target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${folder_i} ${dst_dir} + VERBATIM) + endforeach(folder_i) + endfunction() # ------------------------------------------------------------------ @@ -110,5 +134,7 @@ if (NOT ${CMAKE_BINARY_DIR} STREQUAL ${PROJECT_BINARY_DIR}) set(EVOENGINE_DLLS ${EVOENGINE_DLLS} PARENT_SCOPE) set(EVOENGINE_SDK_DIR ${EVOENGINE_SDK_DIR} PARENT_SCOPE) + set(EVOENGINE_RESOURCES ${EVOENGINE_RESOURCES} PARENT_SCOPE) + set(EvoEngine_Plugins ${EvoEngine_Plugins} PARENT_SCOPE) endif () \ No newline at end of file diff --git a/EvoEngine_App/Demo/CMakeLists.txt b/EvoEngine_App/Demo/CMakeLists.txt index c044fe8..7a54af2 100644 --- a/EvoEngine_App/Demo/CMakeLists.txt +++ b/EvoEngine_App/Demo/CMakeLists.txt @@ -25,5 +25,8 @@ if (${CMAKE_BINARY_DIR} STREQUAL ${PROJECT_BINARY_DIR}) ) file(COPY imgui.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) evoengine_copy_resources(DemoApp ${CMAKE_CURRENT_BINARY_DIR}) + + + endif () endif () \ No newline at end of file diff --git a/EvoEngine_App/Demo/Demo.cpp b/EvoEngine_App/Demo/Demo.cpp index 17a3c9d..425cec9 100644 --- a/EvoEngine_App/Demo/Demo.cpp +++ b/EvoEngine_App/Demo/Demo.cpp @@ -13,9 +13,9 @@ #include "WindowLayer.hpp" #ifdef UNIVERSE_PLUGIN -#include "PerlinNoiseStage.hpp" -#include "PlanetTerrainSystem.hpp" -#include "StarClusterSystem.hpp" +# include "PerlinNoiseStage.hpp" +# include "PlanetTerrainSystem.hpp" +# include "StarClusterSystem.hpp" #endif #include "PostProcessingStack.hpp" @@ -30,10 +30,10 @@ #endif #ifdef RAY_TRACER_PLUGIN # include "CpuRayTracerCamera.hpp" +# include "GpuRayTracerCamera.hpp" #endif using namespace evo_engine; using namespace Universe; -using namespace Universe; #pragma region Helpers #ifdef PHYSICS_PLUGIN Entity CreateDynamicCube(const float& mass, const glm::vec3& color, const glm::vec3& position, @@ -81,6 +81,7 @@ int main() { #ifdef RAY_TRACER_PLUGIN PrivateComponentRegistration("CpuRayTracerCamera"); + PrivateComponentRegistration("GpuRayTracerCamera"); #endif ApplicationInfo application_info; SetupDemoScene(demo_setup, application_info); @@ -331,7 +332,7 @@ void SetupDemoScene(DemoSetup demo_setup, ApplicationInfo& application_info) { } break; case DemoSetup::Galaxy: { application_info.application_name = "Universe Demo"; - + application_info.project_path = resource_folder_path / "Example Projects/Universe/Universe.eveproj"; #ifdef UNIVERSE_PLUGIN ProjectManager::SetActionAfterNewScene([&](const std::shared_ptr& scene) { @@ -339,9 +340,9 @@ void SetupDemoScene(DemoSetup demo_setup, ApplicationInfo& application_info) { main_camera->Resize({640, 480}); const auto main_camera_entity = main_camera->GetOwner(); scene->GetOrSetPrivateComponent(main_camera_entity); -#pragma region Star System +# pragma region Star System auto star_cluster_system = scene->GetOrCreateSystem(SystemGroup::SimulationSystemGroup); -#pragma endregion +# pragma endregion main_camera->use_clear_color = true; }); #endif @@ -351,7 +352,7 @@ void SetupDemoScene(DemoSetup demo_setup, ApplicationInfo& application_info) { application_info.project_path = resource_folder_path / "Example Projects/Planet/Planet.eveproj"; #ifdef UNIVERSE_PLUGIN ProjectManager::SetActionAfterNewScene([&](const std::shared_ptr& scene) { -#pragma region Preparations +# pragma region Preparations const auto main_camera = scene->main_camera.Get(); main_camera->Resize({640, 480}); const auto main_camera_entity = main_camera->GetOwner(); @@ -411,9 +412,9 @@ void SetupDemoScene(DemoSetup demo_setup, ApplicationInfo& application_info) { planet_terrain3->surface_material = surface_material; planet_terrain3->SetPlanetInfo(pi); scene->SetDataComponent(planet3, planet_transform); -#pragma endregion +# pragma endregion -#pragma region Lights +# pragma region Lights const auto shared_mat = ProjectManager::CreateTemporaryAsset(); Transform ltw; @@ -449,12 +450,12 @@ void SetupDemoScene(DemoSetup demo_setup, ApplicationInfo& application_info) { plmmc2->mesh = Resources::GetResource("PRIMITIVE_SPHERE"); plmmc2->material.Set(shared_mat); -#pragma endregion +# pragma endregion Application::RegisterLateUpdateFunction([=]() { auto scene = Application::GetActiveScene(); Transform ltw; ltw.SetScale(glm::vec3(0.5f)); -#pragma region LightsPosition +# pragma region LightsPosition ltw.SetPosition(glm::vec4( glm::vec3(0.0f, 20.0f * glm::sin(Times::Now() / 2.0f), -20.0f * glm::cos(Times::Now() / 2.0f)), 0.0f)); scene->SetDataComponent(dle, ltw); @@ -464,7 +465,7 @@ void SetupDemoScene(DemoSetup demo_setup, ApplicationInfo& application_info) { ltw.SetPosition(glm::vec4( glm::vec3(20.0f * glm::cos(Times::Now() / 2.0f), 15.0f, 20.0f * glm::sin(Times::Now() / 2.0f)), 0.0f)); scene->SetDataComponent(ple2, ltw); -#pragma endregion +# pragma endregion #endif }); }); diff --git a/EvoEngine_Plugins/CMakeLists.txt b/EvoEngine_Plugins/CMakeLists.txt index 278962b..7b4f5d5 100644 --- a/EvoEngine_Plugins/CMakeLists.txt +++ b/EvoEngine_Plugins/CMakeLists.txt @@ -4,6 +4,7 @@ set(EVOENGINE_PLUGINS_INCLUDES "") set(EVOENGINE_PLUGINS_PCHS "") set(EVOENGINE_PLUGINS_DEFS "") set(EVOENGINE_PLUGINS_DLLS "") +set(EVOENGINE_PLUGINS_RESOURCES "") #if (WIN32) # option(EVOENGINE_PLUGIN_PHYSICS "Build the physics plugin" ON) @@ -72,3 +73,4 @@ set(EVOENGINE_PLUGINS_INCLUDES ${EVOENGINE_PLUGINS_INCLUDES} PARENT_SCOPE) set(EVOENGINE_PLUGINS_PCHS ${EVOENGINE_PLUGINS_PCHS} PARENT_SCOPE) set(EVOENGINE_PLUGINS_DEFS ${EVOENGINE_PLUGINS_DEFS} PARENT_SCOPE) set(EVOENGINE_PLUGINS_DLLS ${EVOENGINE_PLUGINS_DLLS} PARENT_SCOPE) +set(EVOENGINE_PLUGINS_RESOURCES ${EVOENGINE_PLUGINS_RESOURCES} PARENT_SCOPE) diff --git a/EvoEngine_Plugins/DigitalAgriculture/src/SorghumLayer.cpp b/EvoEngine_Plugins/DigitalAgriculture/src/SorghumLayer.cpp index aa01624..f7530d0 100644 --- a/EvoEngine_Plugins/DigitalAgriculture/src/SorghumLayer.cpp +++ b/EvoEngine_Plugins/DigitalAgriculture/src/SorghumLayer.cpp @@ -5,7 +5,7 @@ #endif #include #include "ClassRegistry.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "SkyIlluminance.hpp" #include "SorghumStateGenerator.hpp" #include "Times.hpp" diff --git a/EvoEngine_Plugins/EcoSysLab/CMakeLists.txt b/EvoEngine_Plugins/EcoSysLab/CMakeLists.txt index 985880b..0a52413 100644 --- a/EvoEngine_Plugins/EcoSysLab/CMakeLists.txt +++ b/EvoEngine_Plugins/EcoSysLab/CMakeLists.txt @@ -54,15 +54,8 @@ target_precompile_headers(EcoSysLabPlugin set(EVOENGINE_PLUGINS_INCLUDES ${EVOENGINE_PLUGINS_INCLUDES} ${ECOSYSLAB_INCLUDES} PARENT_SCOPE) set(EVOENGINE_PLUGINS_PCHS ${EVOENGINE_PLUGINS_PCHS} ${ECOSYSLAB_PCH} PARENT_SCOPE) set(EVOENGINE_PLUGINS_DEFS ${EVOENGINE_PLUGINS_DEFS} ECOSYSLAB_PLUGIN PARENT_SCOPE) +set(EVOENGINE_PLUGINS_RESOURCES ${EVOENGINE_PLUGINS_RESOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/Internals PARENT_SCOPE) set(EvoEngine_Plugins ${EvoEngine_Plugins} EcoSysLabPlugin PARENT_SCOPE) -# ------------------------------------------------------------------ -# Copy Internal resources -# ------------------------------------------------------------------ -add_custom_command(TARGET EcoSysLabPlugin POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_CURRENT_SOURCE_DIR}/Internals - ${CMAKE_BINARY_DIR}) - set_target_properties(EcoSysLabPlugin PROPERTIES FOLDER "Plugins") \ No newline at end of file diff --git a/EvoEngine_Plugins/EcoSysLab/include/Utilities/TreeVisualizer.hpp b/EvoEngine_Plugins/EcoSysLab/include/Utilities/TreeVisualizer.hpp index 573434b..b14cc84 100644 --- a/EvoEngine_Plugins/EcoSysLab/include/Utilities/TreeVisualizer.hpp +++ b/EvoEngine_Plugins/EcoSysLab/include/Utilities/TreeVisualizer.hpp @@ -2,7 +2,7 @@ #include "Application.hpp" #include "EditorLayer.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "Jobs.hpp" #include "StrandModel.hpp" #include "TreeModel.hpp" diff --git a/EvoEngine_Plugins/EcoSysLab/src/ForestDescriptor.cpp b/EvoEngine_Plugins/EcoSysLab/src/ForestDescriptor.cpp index ac272d9..d78d18d 100644 --- a/EvoEngine_Plugins/EcoSysLab/src/ForestDescriptor.cpp +++ b/EvoEngine_Plugins/EcoSysLab/src/ForestDescriptor.cpp @@ -7,7 +7,7 @@ #include "Climate.hpp" #include "EcoSysLabLayer.hpp" #include "EditorLayer.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "Tree.hpp" using namespace eco_sys_lab; diff --git a/EvoEngine_Plugins/EcoSysLab/src/RadialBoundingVolume.cpp b/EvoEngine_Plugins/EcoSysLab/src/RadialBoundingVolume.cpp index 1a1e70a..c1ac20a 100644 --- a/EvoEngine_Plugins/EcoSysLab/src/RadialBoundingVolume.cpp +++ b/EvoEngine_Plugins/EcoSysLab/src/RadialBoundingVolume.cpp @@ -2,7 +2,7 @@ #include -#include "Graphics.hpp" +#include "Platform.hpp" #include "PointCloud.hpp" #include "Tree.hpp" diff --git a/EvoEngine_Plugins/EcoSysLab/src/Soil.cpp b/EvoEngine_Plugins/EcoSysLab/src/Soil.cpp index f7d97c7..d0aba32 100644 --- a/EvoEngine_Plugins/EcoSysLab/src/Soil.cpp +++ b/EvoEngine_Plugins/EcoSysLab/src/Soil.cpp @@ -5,7 +5,7 @@ #include "EcoSysLabLayer.hpp" #include "EditorLayer.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "HeightField.hpp" using namespace eco_sys_lab; diff --git a/EvoEngine_Plugins/EcoSysLab/src/TreeStructor.cpp b/EvoEngine_Plugins/EcoSysLab/src/TreeStructor.cpp index 2e7029f..b2649ad 100644 --- a/EvoEngine_Plugins/EcoSysLab/src/TreeStructor.cpp +++ b/EvoEngine_Plugins/EcoSysLab/src/TreeStructor.cpp @@ -2,7 +2,7 @@ #include #include "EcoSysLabLayer.hpp" #include "FoliageDescriptor.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "rapidcsv.h" using namespace eco_sys_lab; diff --git a/EvoEngine_Plugins/MeshRepair/src/MeshColoring.cpp b/EvoEngine_Plugins/MeshRepair/src/MeshColoring.cpp index 1f63e36..1192a96 100644 --- a/EvoEngine_Plugins/MeshRepair/src/MeshColoring.cpp +++ b/EvoEngine_Plugins/MeshRepair/src/MeshColoring.cpp @@ -1,7 +1,7 @@ #include "MeshColoring.hpp" #include "ClassRegistry.hpp" -#include "CpuRayTracer.hpp" +#include "RayTracer.hpp" #include "Prefab.hpp" #include "Times.hpp" #include "VisibilityTest.hpp" diff --git a/EvoEngine_Plugins/MeshRepair/src/VisibilityTest.cpp b/EvoEngine_Plugins/MeshRepair/src/VisibilityTest.cpp index 830544c..c791582 100644 --- a/EvoEngine_Plugins/MeshRepair/src/VisibilityTest.cpp +++ b/EvoEngine_Plugins/MeshRepair/src/VisibilityTest.cpp @@ -1,5 +1,5 @@ #include "VisibilityTest.hpp" -#include "CpuRayTracer.hpp" +#include "RayTracer.hpp" #include "Times.hpp" using namespace evo_engine; @@ -46,7 +46,7 @@ void VisibilityTest::Execute(const std::shared_ptr& mesh, std::vector& visibility_results) { const auto& input_triangles = mesh->UnsafeGetTriangles(); const auto& input_vertices = mesh->UnsafeGetVertices(); - CpuRayTracer cpu_ray_tracer; + RayTracer cpu_ray_tracer; cpu_ray_tracer.Initialize(mesh); visibility_results.resize(input_triangles.size()); @@ -55,10 +55,10 @@ void VisibilityTest::Execute(const std::shared_ptr& mesh, // for(uint32_t triangle_index = 0; triangle_index < input_triangles.size(); triangle_index++){ const auto& sample = input_samples.at(triangle_index); RandomSampler random_sampler; - CpuRayTracer::RayDescriptor current_ray_descriptor{}; + RayTracer::RayDescriptor current_ray_descriptor{}; if (visibility_test_params.cull_back_faces) current_ray_descriptor.flags = - CpuRayTracer::TraceFlags::CullBackFace; + RayTracer::TraceFlags::CullBackFace; random_sampler.SetSeed(triangle_index); glm::vec3 current_ray_direction; bool visible = false; @@ -115,14 +115,14 @@ void VisibilityTest::Execute(const std::shared_ptr& mesh, current_ray_descriptor.t_max = FLT_MAX; cpu_ray_tracer.Trace( current_ray_descriptor, - [&](const CpuRayTracer::HitInfo& hit_info) { + [&](const RayTracer::HitInfo& hit_info) { barycentric = hit_info.barycentric; source_triangle = input_triangles[hit_info.triangle_index]; }, [&]() { visible = true; }, - [](const CpuRayTracer::HitInfo& hit_info) { + [](const RayTracer::HitInfo& hit_info) { }); if (visible) { break; @@ -166,7 +166,7 @@ void VisibilityTest::Execute(const std::shared_ptr& scene, const Entity& struct VisibilityTestingMeshData {}; struct VisibilityTestingNodeData {}; - CpuRayTracer cpu_ray_tracer; + RayTracer cpu_ray_tracer; cpu_ray_tracer.Initialize( scene, @@ -179,10 +179,10 @@ void VisibilityTest::Execute(const std::shared_ptr& scene, const Entity& Jobs::RunParallelFor(input_triangles.size(), [&](const size_t triangle_index) { const auto& sample = input_samples.at(triangle_index); RandomSampler random_sampler; - CpuRayTracer::RayDescriptor current_ray_descriptor{}; + RayTracer::RayDescriptor current_ray_descriptor{}; if (visibility_test_params.cull_back_faces) current_ray_descriptor.flags = - CpuRayTracer::TraceFlags::CullBackFace; + RayTracer::TraceFlags::CullBackFace; random_sampler.SetSeed(triangle_index); glm::vec3 current_ray_direction; bool visible = false; @@ -241,14 +241,14 @@ void VisibilityTest::Execute(const std::shared_ptr& scene, const Entity& current_ray_descriptor.t_max = FLT_MAX; cpu_ray_tracer.Trace( current_ray_descriptor, - [&](const CpuRayTracer::HitInfo& hit_info) { + [&](const RayTracer::HitInfo& hit_info) { current_ray_origin = hit_info.hit; current_triangle_normal = glm::normalize(hit_info.normal); }, [&]() { visible = true; }, - [](const CpuRayTracer::HitInfo& hit_info) { + [](const RayTracer::HitInfo& hit_info) { }); if (visible) { break; diff --git a/EvoEngine_Plugins/RayTracer/CMakeLists.txt b/EvoEngine_Plugins/RayTracer/CMakeLists.txt index be037d4..d30d75d 100644 --- a/EvoEngine_Plugins/RayTracer/CMakeLists.txt +++ b/EvoEngine_Plugins/RayTracer/CMakeLists.txt @@ -2,8 +2,6 @@ set(RAY_TRACER_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) set(RAY_TRACER_INCLUDES ${RAY_TRACER_DIRECTORY}/include - ${RAY_TRACER_DIRECTORY}/include/Gpu - ${RAY_TRACER_DIRECTORY}/include/Cpu ) file(GLOB RAY_TRACER_SOURCES ${RAY_TRACER_DIRECTORY}/src/*.cpp) @@ -37,6 +35,7 @@ target_precompile_headers(RayTracerPlugin set(EVOENGINE_PLUGINS_INCLUDES ${EVOENGINE_PLUGINS_INCLUDES} ${RAY_TRACER_INCLUDES} PARENT_SCOPE) set(EVOENGINE_PLUGINS_PCHS ${EVOENGINE_PLUGINS_PCHS} ${RAY_TRACER_PCH} PARENT_SCOPE) set(EVOENGINE_PLUGINS_DEFS ${EVOENGINE_PLUGINS_DEFS} RAY_TRACER_PLUGIN PARENT_SCOPE) +set(EVOENGINE_PLUGINS_RESOURCES ${EVOENGINE_PLUGINS_RESOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/Internals PARENT_SCOPE) set(EvoEngine_Plugins ${EvoEngine_Plugins} RayTracerPlugin PARENT_SCOPE) diff --git a/EvoEngine_Plugins/RayTracer/Internals/RayTracerResources/Shaders/Compute/Trace.comp b/EvoEngine_Plugins/RayTracer/Internals/RayTracerResources/Shaders/Compute/Trace.comp new file mode 100644 index 0000000..177fdc7 --- /dev/null +++ b/EvoEngine_Plugins/RayTracer/Internals/RayTracerResources/Shaders/Compute/Trace.comp @@ -0,0 +1,321 @@ +#extension GL_EXT_gpu_shader4 : enable + +layout(std140, binding = 0) readonly buffer SCENE_LEVEL_BVH_BLOCK{ + vec4 scene_level_bvh_nodes[]; +}; + +layout(std140, binding = 1) readonly buffer NODE_INDICES_BLOCK{ + vec4 node_indices[]; +}; + +layout(std140, binding = 2) readonly buffer NODE_INFO_LIST_BLOCK{ + vec4 node_info_list[]; +}; + +layout(std140, binding = 3) readonly buffer NODE_LEVEL_BVH_NODES_BLOCK{ + vec4 node_level_bvh_nodes[]; +}; + +layout(std140, binding = 4) readonly buffer MESH_INDICES_BLOCK{ + vec4 mesh_indices[]; +}; + +layout(std140, binding = 5) readonly buffer MESH_INFO_LIST_BLOCK{ + vec4 mesh_info_list[]; +}; +layout(std140, binding = 6) readonly buffer MESH_LEVEL_BVH_NODES_BLOCK{ + vec4 mesh_level_bvh_nodes[]; +}; +layout(std140, binding = 7) readonly buffer TRIANGLE_INDICES_BLOCK{ + vec4 triangle_indices[]; +}; +layout(std140, binding = 8) readonly buffer LOCAL_TRIANGLE_INDICES_BLOCK{ + vec4 local_triangle_indices[]; +}; + +layout(std140, binding = 9) readonly buffer SCENE_TRIANGLES_BLOCK{ + vec4 scene_triangles[]; +}; +layout(std140, binding = 10) readonly buffer SCENE_VERTEX_POSITIONS_BLOCK{ + vec4 scene_vertex_positions[]; +}; + +layout(std140, binding = 11) readonly buffer RAYS_BLOCK{ + vec4 rays[]; +}; + +layout(std140, binding = 12) writeonly buffer RAY_CASTING_RESULTS_BLOCK{ + vec4 ray_casting_results[]; +}; + +layout(push_constant) uniform RAY_CASTING_CONSTANTS{ + vec4 ray_casting_sizes; + vec4 ray_casting_config; +}; + +layout (local_size_x = 256, local_size_y = 1, local_size_z = 1) in; + +struct RayDescriptor{ + vec3 origin; + vec3 direction; + float t_min; + float t_max; +}; + +struct HitInfo{ + vec3 hit; + vec3 barycentric; + bool back_face; + vec3 normal; + float distance; + uint triangle_index; + uint mesh_index; + uint node_index; +}; + +HitInfo Trace(in RayDescriptor ray_descriptor, in float cull_back_face, in float cull_front_face, out bool has_hit); + + +void Execute(uint current_ray_index); + +void main() { + uint current_ray_index = gl_GlobalInvocationID.x; + Execute(current_ray_index); +} + + +bool RayAabb(vec3 r_o, vec3 r_inv_d, vec3 aabb_min, vec3 aabb_max) { + float tx1 = (aabb_min.x - r_o.x) * r_inv_d.x; + float tx2 = (aabb_max.x - r_o.x) * r_inv_d.x; + + float t_min = min(tx1, tx2); + float t_max = max(tx1, tx2); + + float ty1 = (aabb_min.y - r_o.y) * r_inv_d.y; + float ty2 = (aabb_max.y - r_o.y) * r_inv_d.y; + + t_min = max(t_min, min(ty1, ty2)); + t_max = min(t_max, max(ty1, ty2)); + + float tz1 = (aabb_min.z - r_o.z) * r_inv_d.z; + float tz2 = (aabb_max.z - r_o.z) * r_inv_d.z; + + t_min = max(t_min, min(tz1, tz2)); + t_max = min(t_max, max(tz1, tz2)); + + return t_max >= t_min; +} + +struct BvhNode{ + vec3 aabb_min; + vec3 aabb_max; + uint alternate_node_index; + uint begin_next_level_element_index; + uint end_next_level_element_index; +}; + +void GetBvhNode(in vec4 buffer_0, in vec4 buffer_1, in vec4 buffer_2, out BvhNode bvh_node) { + bvh_node.aabb_min = buffer_0.xyz; + bvh_node.aabb_max = buffer_1.xyz; + bvh_node.alternate_node_index = floatBitsToUint(buffer_2.x); + bvh_node.begin_next_level_element_index = floatBitsToUint(buffer_2.y); + bvh_node.end_next_level_element_index = floatBitsToUint(buffer_2.z); +} + +vec3 TransformPosition(mat4 transform, vec3 position) { + vec4 p = vec4(position, 1.0); + return (transform * p).xyz; +} + +vec3 TransformDirection(mat4 transform, vec3 direction) { + vec4 d = vec4(direction, 0.0); + return (transform * d).xyz; +} + +vec3 Barycentric(vec3 p, vec3 a, vec3 b, vec3 c) { + vec3 v0 = b - a; + vec3 v1 = c - a; + vec3 v2 = p - a; + float d00 = dot(v0, v0); + float d01 = dot(v0, v1); + float d11 = dot(v1, v1); + float d20 = dot(v2, v0); + float d21 = dot(v2, v1); + float denominator = d00 * d11 - d01 * d01; + float y = (d11 * d20 - d01 * d21) / denominator; + float z = (d00 * d21 - d01 * d20) / denominator; + return vec3(1.0f - y - z, y, z); +} + +HitInfo Trace(in RayDescriptor ray_descriptor, in float cull_back_face, in float cull_front_face, out bool has_hit) { + HitInfo hit_info; + hit_info.distance = ray_descriptor.t_max; + has_hit = false; + vec3 scene_space_ray_direction = normalize(ray_descriptor.direction); + vec3 scene_space_ray_origin = ray_descriptor.origin; + vec3 scene_space_inv_ray_direction = vec3(1.0 / scene_space_ray_direction.x, 1.0 / scene_space_ray_direction.y, 1.0 / scene_space_ray_direction.z); + uint node_group_index = 0; + while (node_group_index < floatBitsToUint(ray_casting_sizes.x)) { + BvhNode node_group; + GetBvhNode(scene_level_bvh_nodes[node_group_index * 3], scene_level_bvh_nodes[node_group_index * 3 + 1], scene_level_bvh_nodes[node_group_index * 3 + 2], node_group); + if (!RayAabb(scene_space_ray_origin, scene_space_inv_ray_direction, node_group.aabb_min, node_group.aabb_max)) { + node_group_index = node_group.alternate_node_index; + continue; + } + for (uint test_node_index = node_group.begin_next_level_element_index; test_node_index < node_group.end_next_level_element_index; test_node_index += 1) { + //=============DO NOT TOUCH UNLESS YOU UNDERSTAND WHY========================== + uint node_index = floatBitsToUint(node_indices[test_node_index / 4][test_node_index % 4]);// >>>--> This doesn't work on dx. + //vec4 node_index_v = node_indices[test_node_index / 4]; + //float node_index_l[4] = {node_index_v.x, node_index_v.y, node_index_v.z, node_index_v.w}; + //uint node_index = floatBitsToUint(node_index_l[test_node_index % 4]); + //============================================================================= + mat4 node_global_transform; + node_global_transform[0] = node_info_list[node_index * 9]; + node_global_transform[1] = node_info_list[node_index * 9 + 1]; + node_global_transform[2] = node_info_list[node_index * 9 + 2]; + node_global_transform[3] = node_info_list[node_index * 9 + 3]; + mat4 node_inverse_global_transform; + node_inverse_global_transform[0] = node_info_list[node_index * 9 + 4]; + node_inverse_global_transform[1] = node_info_list[node_index * 9 + 5]; + node_inverse_global_transform[2] = node_info_list[node_index * 9 + 6]; + node_inverse_global_transform[3] = node_info_list[node_index * 9 + 7]; + uint node_level_bvh_node_offset = floatBitsToUint(node_info_list[node_index * 9 + 8].x); + uint node_level_bvh_node_size = floatBitsToUint(node_info_list[node_index * 9 + 8].y); + uint mesh_indices_offset = floatBitsToUint(node_info_list[node_index * 9 + 8].z); + uint mesh_indices_size = floatBitsToUint(node_info_list[node_index * 9 + 8].w); + vec3 node_space_ray_origin = TransformPosition(node_inverse_global_transform, scene_space_ray_origin); + vec3 node_space_ray_direction = TransformDirection(node_inverse_global_transform, scene_space_ray_direction); + vec3 node_space_inv_ray_direction = vec3(1.0 / node_space_ray_direction.x, 1.0 / node_space_ray_direction.y, 1.0 / node_space_ray_direction.z); + uint mesh_group_index = 0; + while (mesh_group_index < node_level_bvh_node_size) { + BvhNode mesh_group; + GetBvhNode(node_level_bvh_nodes[(mesh_group_index + node_level_bvh_node_offset) * 3], + node_level_bvh_nodes[(mesh_group_index + node_level_bvh_node_offset) * 3 + 1], + node_level_bvh_nodes[(mesh_group_index + node_level_bvh_node_offset) * 3 + 2], + mesh_group); + + if (!RayAabb(node_space_ray_origin, node_space_inv_ray_direction, mesh_group.aabb_min, mesh_group.aabb_max)) { + mesh_group_index = mesh_group.alternate_node_index; + continue; + } + for (uint test_mesh_index = mesh_group.begin_next_level_element_index + mesh_indices_offset; + test_mesh_index < mesh_group.end_next_level_element_index + mesh_indices_offset; test_mesh_index += 1) { + //=============DO NOT TOUCH UNLESS YOU UNDERSTAND WHY========================== + uint mesh_index = floatBitsToUint(mesh_indices[test_mesh_index / 4][test_mesh_index % 4]); //>>>--> This doesn't work on dx. + //vec4 mesh_index_v = mesh_indices[test_mesh_index / 4]; + //float mesh_index_l[4] = {mesh_index_v.x, mesh_index_v.y, mesh_index_v.z, mesh_index_v.w}; + //uint mesh_index = floatBitsToUint(mesh_index_l[test_mesh_index % 4]); + //============================================================================= + uint triangle_group_index = 0; + uint mesh_level_bvh_node_offset = floatBitsToUint(mesh_info_list[mesh_index].x); + uint mesh_level_bvh_node_size = floatBitsToUint(mesh_info_list[mesh_index].y); + uint triangle_indices_offset = floatBitsToUint(mesh_info_list[mesh_index].z); + while (triangle_group_index < mesh_level_bvh_node_size) { + BvhNode triangle_group; + GetBvhNode(mesh_level_bvh_nodes[(triangle_group_index + mesh_level_bvh_node_offset) * 3], + mesh_level_bvh_nodes[(triangle_group_index + mesh_level_bvh_node_offset) * 3 + 1], + mesh_level_bvh_nodes[(triangle_group_index + mesh_level_bvh_node_offset) * 3 + 2], + triangle_group); + if (!RayAabb(node_space_ray_origin, node_space_inv_ray_direction, triangle_group.aabb_min, triangle_group.aabb_max)) { + triangle_group_index = triangle_group.alternate_node_index; + continue; + } + for (uint test_triangle_index = triangle_group.begin_next_level_element_index + triangle_indices_offset; + test_triangle_index < triangle_group.end_next_level_element_index + triangle_indices_offset; test_triangle_index += 1) { + //=============DO NOT TOUCH UNLESS YOU UNDERSTAND WHY========================== + uint triangle_index = floatBitsToUint(triangle_indices[test_triangle_index / 4][test_triangle_index % 4]); //>>>--> This doesn't work on dx. + //vec4 triangle_index_v = triangle_indices[test_triangle_index / 4]; + //float triangle_index_l[4] = {triangle_index_v.x, triangle_index_v.y, triangle_index_v.z, triangle_index_v.w}; + //uint triangle_index = floatBitsToUint(triangle_index_l[test_triangle_index % 4]); + //============================================================================= + + uint t_x = floatBitsToUint(scene_triangles[triangle_index].x); + uint t_y = floatBitsToUint(scene_triangles[triangle_index].y); + uint t_z = floatBitsToUint(scene_triangles[triangle_index].z); + vec3 p0 = scene_vertex_positions[t_x].xyz; + vec3 p1 = scene_vertex_positions[t_y].xyz; + vec3 p2 = scene_vertex_positions[t_z].xyz; + if(p0.x == p1.x && p0.y == p1.y && p0.z == p1.z + && p1.x == p2.x && p1.y == p2.y && p1.z == p2.z) continue; + vec3 node_space_triangle_normal = normalize(cross(p1 - p0, p2 - p0)); + float normal_test = dot(node_space_ray_direction, node_space_triangle_normal); + if (cull_back_face != 0.0 && normal_test > 0.0) continue; + if (cull_front_face != 0.0 && normal_test < 0.0) continue; + if (normal_test == 0.0) continue; + float node_space_hit_distance = (dot(p0, node_space_triangle_normal) - + dot(node_space_ray_origin, node_space_triangle_normal)) / normal_test; + if (node_space_hit_distance > 0) { + vec3 node_space_hit = node_space_ray_origin + node_space_ray_direction * node_space_hit_distance; + vec3 scene_space_hit = TransformPosition(node_global_transform, node_space_hit); + float scene_hit_distance = distance(scene_space_ray_origin, scene_space_hit); + if (scene_hit_distance >= ray_descriptor.t_min && scene_hit_distance <= hit_info.distance) { + vec3 barycentric = Barycentric(node_space_hit, p0, p1, p2); + if (barycentric.x >= 0.0 && barycentric.x <= 1.0 && barycentric.y >= 0.0 && barycentric.y <= 1.0 && + barycentric.z >= 0.0 && barycentric.z <= 1.0) { + hit_info.hit = scene_space_hit; + hit_info.normal = TransformDirection(node_global_transform, node_space_triangle_normal); + hit_info.distance = scene_hit_distance; + hit_info.barycentric = barycentric; + hit_info.back_face = normal_test > 0.0 ? true : false; + //=============DO NOT TOUCH UNLESS YOU UNDERSTAND WHY========================== + hit_info.triangle_index = floatBitsToUint(local_triangle_indices[test_triangle_index / 4][test_triangle_index % 4]); //>>>--> This doesn't work on dx. + //vec4 local_triangle_index_v = local_triangle_indices[test_triangle_index / 4]; + //float local_triangle_index_l[4] = {local_triangle_index_v.x, local_triangle_index_v.y, local_triangle_index_v.z, local_triangle_index_v.w}; + //hit_info.triangle_index = floatBitsToUint(local_triangle_index_l[test_triangle_index % 4]); + //============================================================================= + hit_info.mesh_index = mesh_index; + hit_info.node_index = node_index; + has_hit = true; + } + } + } + } + triangle_group_index += 1; + } + } + mesh_group_index += 1; + } + } + node_group_index += 1; + } + return hit_info; +} + +void Execute(uint current_ray_index) { + float thin_scale = ray_casting_config.y; + float max_ray_cast_distance = ray_casting_config.z; + uint rays_count = floatBitsToUint(ray_casting_sizes.y); + uint texture_width = floatBitsToUint(ray_casting_sizes.z); + if (current_ray_index < rays_count) { + vec3 sample_origin = rays[current_ray_index * 2].xyz; + vec3 sample_direction = rays[current_ray_index * 2 + 1].xyz; + RayDescriptor ray_descriptor; + ray_descriptor.origin = sample_origin + sample_direction * thin_scale; + ray_descriptor.direction = -sample_direction; + ray_descriptor.t_min = 0.0; + ray_descriptor.t_max = thin_scale + max_ray_cast_distance; + bool hit = false; + HitInfo hit_info = Trace(ray_descriptor, ray_casting_config.x, 0.0, hit); + if (!hit) { + ray_descriptor.direction = sample_direction; + ray_descriptor.t_max = max_ray_cast_distance - thin_scale; + hit_info = Trace(ray_descriptor, 0.0, ray_casting_config.x, hit); + } + if (!hit) { + ray_descriptor.direction = -sample_direction; + ray_descriptor.t_max = thin_scale + max_ray_cast_distance; + hit_info = Trace(ray_descriptor, 0.0, 0.0, hit); + } + if (!hit) { + ray_descriptor.direction = sample_direction; + ray_descriptor.t_max = max_ray_cast_distance - thin_scale; + hit_info = Trace(ray_descriptor, 0.0, 0.0, hit); + } + if (hit) { + imageStore(ray_casting_results, uint2(current_ray_index * 4 % texture_width, current_ray_index * 4 / texture_width), vec4(hit_info.hit, 1)); + imageStore(ray_casting_results, uint2((current_ray_index * 4 + 1) % texture_width, (current_ray_index * 4 + 1) / texture_width), vec4(hit_info.barycentric, hit_info.back_face ? 1.0 : 0.0)); + imageStore(ray_casting_results, uint2((current_ray_index * 4 + 2) % texture_width, (current_ray_index * 4 + 2) / texture_width), vec4(hit_info.normal, hit_info.distance)); + imageStore(ray_casting_results, uint2((current_ray_index * 4 + 3) % texture_width, (current_ray_index * 4 + 3) / texture_width), vec4(uintBitsToFloat(hit_info.node_index), uintBitsToFloat(hit_info.mesh_index), uintBitsToFloat(hit_info.triangle_index), 0.0)); + } + } +} \ No newline at end of file diff --git a/EvoEngine_Plugins/RayTracer/include/Cpu/CpuRayTracerCamera.hpp b/EvoEngine_Plugins/RayTracer/include/CpuRayTracerCamera.hpp similarity index 100% rename from EvoEngine_Plugins/RayTracer/include/Cpu/CpuRayTracerCamera.hpp rename to EvoEngine_Plugins/RayTracer/include/CpuRayTracerCamera.hpp diff --git a/EvoEngine_Plugins/RayTracer/include/GpuRayTracerCamera.hpp b/EvoEngine_Plugins/RayTracer/include/GpuRayTracerCamera.hpp new file mode 100644 index 0000000..b67cf60 --- /dev/null +++ b/EvoEngine_Plugins/RayTracer/include/GpuRayTracerCamera.hpp @@ -0,0 +1,22 @@ +#pragma once + +namespace evo_engine { +class GpuRayTracerCamera : public IPrivateComponent { + public: + struct CaptureParameters { + size_t sample = 1; + size_t bounce = 5; + }; + CaptureParameters capture_parameters {}; + [[nodiscard]] float GetSizeRatio() const; + void UpdateCameraInfoBlock(CameraInfoBlock& camera_info_block, const GlobalTransform& global_transform) const; + float near_distance = 0.1f; + float far_distance = 200.0f; + float fov = 120; + void OnCreate() override; + AssetRef texture_ref; + void Capture(const CaptureParameters& capture_parameters, const std::shared_ptr& target_texture) const; + glm::uvec2 resolution = {64, 64}; + bool OnInspect(const std::shared_ptr& editor_layer) override; +}; +} // namespace evo_engine \ No newline at end of file diff --git a/EvoEngine_Plugins/RayTracer/include/Cpu/CpuRayTracer.hpp b/EvoEngine_Plugins/RayTracer/include/RayTracer.hpp similarity index 93% rename from EvoEngine_Plugins/RayTracer/include/Cpu/CpuRayTracer.hpp rename to EvoEngine_Plugins/RayTracer/include/RayTracer.hpp index 509010c..755a7af 100644 --- a/EvoEngine_Plugins/RayTracer/include/Cpu/CpuRayTracer.hpp +++ b/EvoEngine_Plugins/RayTracer/include/RayTracer.hpp @@ -1,10 +1,10 @@ #pragma once namespace evo_engine { /** - * @class CpuRayTracer + * @class RayTracer * @brief This class provides the cpu ray tracing service. */ -class CpuRayTracer final { +class RayTracer final { public: enum class TraceFlags { // No special flag set. @@ -234,7 +234,18 @@ class CpuRayTracer final { */ std::vector vertex_positions; - [[nodiscard]] bool Trace(const RayDescriptor& ray_descriptor, HitInfo& hit_info) const; + /** + * @brief Trace a ray within the scene. Function is thread-safe. + * @param ray_descriptor Configuration for the ray. + * @param closest_hit_func Action to take for closest hit point. + * @param miss_func Action to take for escaping ray. + * @param any_hit_func Action to take for any hit point(s) along the ray shooting path. You should never assume this + * will cover all possible intersections unless EnforceAnyHit flag is set to on. + */ + void Trace(const RayDescriptor& ray_descriptor, + const std::function& closest_hit_func, + const std::function& miss_func, + const std::function& any_hit_func) const; }; /** diff --git a/EvoEngine_Plugins/RayTracer/src/CpuRayTracerCamera.cpp b/EvoEngine_Plugins/RayTracer/src/CpuRayTracerCamera.cpp index a5693bb..6a55c24 100644 --- a/EvoEngine_Plugins/RayTracer/src/CpuRayTracerCamera.cpp +++ b/EvoEngine_Plugins/RayTracer/src/CpuRayTracerCamera.cpp @@ -1,8 +1,7 @@ #include "CpuRayTracerCamera.hpp" #include "ClassRegistry.hpp" -#include "CpuRayTracer.hpp" -#include "TextureStorage.hpp" +#include "RayTracer.hpp" using namespace evo_engine; float CpuRayTracerCamera::GetSizeRatio() const { @@ -40,7 +39,7 @@ void CpuRayTracerCamera::Capture(const CaptureParameters& capture_parameters, const auto global_transform = scene->GetDataComponent(owner); UpdateCameraInfoBlock(camera_info_block, global_transform); std::vector entities; - CpuRayTracer cpu_ray_tracer; + RayTracer cpu_ray_tracer; cpu_ray_tracer.Initialize( scene, [&](uint32_t, const std::shared_ptr&) { @@ -62,7 +61,7 @@ void CpuRayTracerCamera::Capture(const CaptureParameters& capture_parameters, const float half_y = resolution.y * .5f; RandomSampler random_sampler; random_sampler.SetSeed(pixel_index); - CpuRayTracer::RayDescriptor current_ray_descriptor{}; + RayTracer::RayDescriptor current_ray_descriptor{}; float hit_count = 0; float temp = 0; for (uint32_t sample_index = 0; sample_index < capture_parameters.sample; sample_index++) { @@ -77,13 +76,13 @@ void CpuRayTracerCamera::Capture(const CaptureParameters& capture_parameters, cpu_ray_tracer.Trace( current_ray_descriptor, - [&](const CpuRayTracer::HitInfo& hit_info) { + [&](const RayTracer::HitInfo& hit_info) { hit_count += 1; temp += static_cast(entities[hit_info.node_index].GetIndex()); }, [&]() { }, - [](const CpuRayTracer::HitInfo& hit_info) { + [](const RayTracer::HitInfo& hit_info) { }); } if (hit_count > 0.f) { diff --git a/EvoEngine_Plugins/RayTracer/src/GpuRayTracerCamera.cpp b/EvoEngine_Plugins/RayTracer/src/GpuRayTracerCamera.cpp new file mode 100644 index 0000000..5f90f85 --- /dev/null +++ b/EvoEngine_Plugins/RayTracer/src/GpuRayTracerCamera.cpp @@ -0,0 +1,127 @@ +#include "GpuRayTracerCamera.hpp" + +#include "ClassRegistry.hpp" +#include "RayTracer.hpp" +using namespace evo_engine; + +float GpuRayTracerCamera::GetSizeRatio() const { + if (resolution.x == 0 || resolution.y == 0) + return 0; + return static_cast(resolution.x) / static_cast(resolution.y); +} + +void GpuRayTracerCamera::UpdateCameraInfoBlock(CameraInfoBlock& camera_info_block, + const GlobalTransform& global_transform) const { + const auto rotation = global_transform.GetRotation(); + const auto position = global_transform.GetPosition(); + const glm::vec3 front = rotation * glm::vec3(0, 0, -1); + const glm::vec3 up = rotation * glm::vec3(0, 1, 0); + const auto ratio = GetSizeRatio(); + camera_info_block.projection = glm::perspective(glm::radians(fov * 0.5f), ratio, near_distance, far_distance); + camera_info_block.view = glm::lookAt(position, position + front, up); + camera_info_block.projection_view = camera_info_block.projection * camera_info_block.view; + camera_info_block.inverse_projection = glm::inverse(camera_info_block.projection); + camera_info_block.inverse_view = glm::inverse(camera_info_block.view); + camera_info_block.inverse_projection_view = glm::inverse(camera_info_block.projection * camera_info_block.view); + camera_info_block.reserved_parameters1 = + glm::vec4(near_distance, far_distance, glm::tan(glm::radians(fov * 0.5f)), glm::tan(glm::radians(fov * 0.25f))); +} + +std::shared_ptr trace_shader; + +void GpuRayTracerCamera::OnCreate() { + if (!trace_shader) { + trace_shader = ProjectManager::CreateTemporaryAsset(); + const auto shader_code = FileUtils::LoadFileAsString(std::filesystem::path("./RayTracerResources") / + "Shaders/Compute/Trace.comp"); + trace_shader->Set(ShaderType::Compute, shader_code); + } +} + +void GpuRayTracerCamera::Capture(const CaptureParameters& capture_parameters, + const std::shared_ptr& target_texture) const { + std::vector pixels{resolution.x * resolution.y}; + CameraInfoBlock camera_info_block; + const auto scene = GetScene(); + const auto owner = GetOwner(); + const auto global_transform = scene->GetDataComponent(owner); + UpdateCameraInfoBlock(camera_info_block, global_transform); + std::vector entities; + RayTracer cpu_ray_tracer; + cpu_ray_tracer.Initialize( + scene, + [&](uint32_t, const std::shared_ptr&) { + + }, + [&](const uint32_t node_index, const Entity& entity) { + entities.resize(glm::max(entities.size(), static_cast(node_index) + 1)); + entities[node_index] = entity; + }); + std::vector colors(65536); + for (auto& color : colors) { + color = glm::vec4(glm::abs(glm::sphericalRand(1.f)), 1.f); + } + + Jobs::RunParallelFor(resolution.x * resolution.y, [&](const size_t pixel_index) { + const float x_coordinate = pixel_index % resolution.y; + const float y_coordinate = pixel_index / resolution.y; + const float half_x = resolution.x * .5f; + const float half_y = resolution.y * .5f; + RandomSampler random_sampler; + random_sampler.SetSeed(pixel_index); + RayTracer::RayDescriptor current_ray_descriptor{}; + float hit_count = 0; + float temp = 0; + for (uint32_t sample_index = 0; sample_index < capture_parameters.sample; sample_index++) { + const auto screen = glm::vec2((x_coordinate + random_sampler.Get1D() - half_x) / half_x, + (y_coordinate + random_sampler.Get1D() - half_y) / half_y); + auto start = camera_info_block.inverse_projection_view * glm::vec4(screen.x, screen.y, 0.0f, 1.0f); + auto end = camera_info_block.inverse_projection_view * glm::vec4(screen.x, screen.y, 1.0f, 1.0f); + start /= start.w; + end /= end.w; + current_ray_descriptor.origin = start; + current_ray_descriptor.direction = glm::normalize(end - start); + + cpu_ray_tracer.Trace( + current_ray_descriptor, + [&](const RayTracer::HitInfo& hit_info) { + hit_count += 1; + temp += static_cast(entities[hit_info.node_index].GetIndex()); + }, + [&]() { + }, + [](const RayTracer::HitInfo& hit_info) { + }); + } + if (hit_count > 0.f) { + size_t entity_index = temp / hit_count; + pixels[pixel_index] = colors[entity_index]; + // pixels[pixel_index] = glm::vec4(1); + } else { + pixels[pixel_index] = glm::vec4(0, 0, 0, 1); + } + }); + + target_texture->SetRgbaChannelData(pixels, resolution, true); +} + +bool GpuRayTracerCamera::OnInspect(const std::shared_ptr& editor_layer) { + bool changed = false; + if (!texture_ref.Get()) { + auto new_texture = ProjectManager::CreateTemporaryAsset(); + new_texture->SetRgbaChannelData({glm::vec4(1.f)}, {1, 1}); + texture_ref = new_texture; + } + if (EditorLayer::DragAndDropButton(texture_ref, "Target texture")) + changed = true; + + static glm::ivec2 new_resolution = {64, 64}; + ImGui::DragInt2("Resolution", &new_resolution.x, 1, 1, 2048); + + if (const auto texture = texture_ref.Get(); texture && ImGui::Button("Capture")) { + resolution = new_resolution; + Capture(capture_parameters, texture); + } + + return changed; +} \ No newline at end of file diff --git a/EvoEngine_Plugins/RayTracer/src/CpuRayTracer.cpp b/EvoEngine_Plugins/RayTracer/src/RayTracer.cpp similarity index 75% rename from EvoEngine_Plugins/RayTracer/src/CpuRayTracer.cpp rename to EvoEngine_Plugins/RayTracer/src/RayTracer.cpp index 1bfeef6..6b10ab3 100644 --- a/EvoEngine_Plugins/RayTracer/src/CpuRayTracer.cpp +++ b/EvoEngine_Plugins/RayTracer/src/RayTracer.cpp @@ -1,7 +1,7 @@ -#include "CpuRayTracer.hpp" +#include "RayTracer.hpp" using namespace evo_engine; -void CpuRayTracer::Initialize( +void RayTracer::Initialize( const std::shared_ptr& input_scene, const std::function& mesh)>& mesh_binding, const std::function& node_binding) { @@ -66,7 +66,29 @@ void CpuRayTracer::Initialize( FlattenBvh(scene_bvh, flattened_bvh_node_group_, 0); } -void CpuRayTracer::Trace(const RayDescriptor& ray_descriptor, +bool RayAabb(const glm::vec3& r_o, const glm::vec3& r_inv_d, const Bound& aabb) { + const auto tx1 = (aabb.min.x - r_o.x) * r_inv_d.x; + const auto tx2 = (aabb.max.x - r_o.x) * r_inv_d.x; + + float t_min = std::min(tx1, tx2); + float t_max = std::max(tx1, tx2); + + const auto ty1 = (aabb.min.y - r_o.y) * r_inv_d.y; + const auto ty2 = (aabb.max.y - r_o.y) * r_inv_d.y; + + t_min = std::max(t_min, std::min(ty1, ty2)); + t_max = std::min(t_max, std::max(ty1, ty2)); + + const auto tz1 = (aabb.min.z - r_o.z) * r_inv_d.z; + const auto tz2 = (aabb.max.z - r_o.z) * r_inv_d.z; + + t_min = std::max(t_min, std::min(tz1, tz2)); + t_max = std::min(t_max, std::max(tz1, tz2)); + + return t_max >= t_min; +} + +void RayTracer::Trace(const RayDescriptor& ray_descriptor, const std::function& closest_hit_func, const std::function& miss_func, const std::function& any_hit_func) const { @@ -78,27 +100,7 @@ void CpuRayTracer::Trace(const RayDescriptor& ray_descriptor, const bool cull_back_face = flags & static_cast(TraceFlags::CullBackFace); const bool cull_front_face = flags & static_cast(TraceFlags::CullFrontFace); float test_distance = ray_descriptor.t_max; - auto ray_aabb = [](const glm::vec3& r_o, const glm::vec3& r_inv_d, const Bound& aabb) { - const auto tx1 = (aabb.min.x - r_o.x) * r_inv_d.x; - const auto tx2 = (aabb.max.x - r_o.x) * r_inv_d.x; - - float t_min = std::min(tx1, tx2); - float t_max = std::max(tx1, tx2); - - const auto ty1 = (aabb.min.y - r_o.y) * r_inv_d.y; - const auto ty2 = (aabb.max.y - r_o.y) * r_inv_d.y; - - t_min = std::max(t_min, std::min(ty1, ty2)); - t_max = std::min(t_max, std::max(ty1, ty2)); - - const auto tz1 = (aabb.min.z - r_o.z) * r_inv_d.z; - const auto tz2 = (aabb.max.z - r_o.z) * r_inv_d.z; - - t_min = std::max(t_min, std::min(tz1, tz2)); - t_max = std::min(t_max, std::max(tz1, tz2)); - - return t_max >= t_min; - }; + const auto scene_space_ray_direction = glm::normalize(ray_descriptor.direction); const auto& scene_space_ray_origin = ray_descriptor.origin; @@ -108,7 +110,7 @@ void CpuRayTracer::Trace(const RayDescriptor& ray_descriptor, uint32_t node_group_index = 0; while (node_group_index < flattened_bvh_node_group_.nodes.size()) { const auto& node_group = flattened_bvh_node_group_.nodes[node_group_index]; - if (!ray_aabb(scene_space_ray_origin, scene_space_inv_ray_direction, node_group.aabb)) { + if (!RayAabb(scene_space_ray_origin, scene_space_inv_ray_direction, node_group.aabb)) { node_group_index = node_group.alternate_node_index; continue; } @@ -127,7 +129,7 @@ void CpuRayTracer::Trace(const RayDescriptor& ray_descriptor, while (mesh_group_index < node_instance.flattened_bvh_mesh_group.nodes.size()) { const auto& mesh_group = node_instance.flattened_bvh_mesh_group.nodes[mesh_group_index]; - if (!ray_aabb(node_space_ray_origin, node_space_inv_ray_direction, mesh_group.aabb)) { + if (!RayAabb(node_space_ray_origin, node_space_inv_ray_direction, mesh_group.aabb)) { mesh_group_index = mesh_group.alternate_node_index; continue; } @@ -138,13 +140,14 @@ void CpuRayTracer::Trace(const RayDescriptor& ray_descriptor, const auto& mesh_instance = geometry_instances_[mesh_index]; while (triangle_group_index < mesh_instance.flattened_bvh_triangle_group.nodes.size()) { const auto& triangle_group = mesh_instance.flattened_bvh_triangle_group.nodes[triangle_group_index]; - if (!ray_aabb(node_space_ray_origin, node_space_inv_ray_direction, triangle_group.aabb)) { + if (!RayAabb(node_space_ray_origin, node_space_inv_ray_direction, triangle_group.aabb)) { triangle_group_index = triangle_group.alternate_node_index; continue; } for (uint32_t test_triangle_index = triangle_group.begin_next_level_element_index; test_triangle_index < triangle_group.end_next_level_element_index; ++test_triangle_index) { - const auto& triangle_index = mesh_instance.flattened_bvh_triangle_group.element_indices[test_triangle_index]; + const auto& triangle_index = + mesh_instance.flattened_bvh_triangle_group.element_indices[test_triangle_index]; const auto& triangle = mesh_instance.triangles[triangle_index]; const auto& p0 = mesh_instance.vertex_positions[triangle.x]; const auto& p1 = mesh_instance.vertex_positions[triangle.y]; @@ -156,11 +159,11 @@ void CpuRayTracer::Trace(const RayDescriptor& ray_descriptor, if ((cull_back_face && normal_test > 0.f) || (cull_front_face && normal_test < 0.f) || normal_test == 0.f) continue; - const auto node_space_hit_distance = (glm::dot(p0, node_space_triangle_normal) - - glm::dot(node_space_ray_origin, node_space_triangle_normal)) / - normal_test; // node_space_hit_distance > 0 instead of node_space_hit_distance >= 0 to avoid self-intersection - if (node_space_hit_distance > 0) { + if (const auto node_space_hit_distance = (glm::dot(p0, node_space_triangle_normal) - + glm::dot(node_space_ray_origin, node_space_triangle_normal)) / + normal_test; + node_space_hit_distance > 0) { const auto node_space_hit = node_space_ray_origin + node_space_ray_direction * node_space_hit_distance; const auto scene_space_hit = node_global_transform.TransformPoint(node_space_hit); if (const auto scene_hit_distance = glm::distance(scene_space_ray_origin, scene_space_hit); @@ -204,14 +207,14 @@ void CpuRayTracer::Trace(const RayDescriptor& ray_descriptor, } } -void CpuRayTracer::Clear() noexcept { +void RayTracer::Clear() noexcept { flattened_bvh_node_group_.nodes.clear(); flattened_bvh_node_group_.element_indices.clear(); geometry_instances_.clear(); node_instances_.clear(); } -void CpuRayTracer::Initialize(const std::shared_ptr& input_mesh) { +void RayTracer::Initialize(const std::shared_ptr& input_mesh) { Clear(); geometry_instances_.resize(1); node_instances_.resize(1); @@ -244,23 +247,23 @@ void CpuRayTracer::Initialize(const std::shared_ptr& input_mesh) { FlattenBvh(scene_bvh, flattened_bvh_node_group_, 0); } -void CpuRayTracer::BucketBound::AddPoint(const glm::vec3& p) { +void RayTracer::BucketBound::AddPoint(const glm::vec3& p) { min_v = glm::min(min_v, p); max_v = glm::max(max_v, p); } -void CpuRayTracer::BucketBound::Combine(const BucketBound& other) { +void RayTracer::BucketBound::Combine(const BucketBound& other) { min_v = glm::min(min_v, other.min_v); max_v = glm::max(max_v, other.max_v); } -float CpuRayTracer::BucketBound::ComputeCost(const int triangle_count) const { +float RayTracer::BucketBound::ComputeCost(const int triangle_count) const { const auto size = max_v - min_v; const float surface_area = 2.0f * (size.x * size.y + size.x * size.z + size.x * size.y); return static_cast(triangle_count) * surface_area; } -CpuRayTracer::BucketSplit CpuRayTracer::SelectSplitFromBuckets(const uint32_t buckets[16], +RayTracer::BucketSplit RayTracer::SelectSplitFromBuckets(const uint32_t buckets[16], const BucketBound buckets_aabb[16], const size_t triangle_count) { // Pass to compute AABB on the right side of the split @@ -294,7 +297,7 @@ CpuRayTracer::BucketSplit CpuRayTracer::SelectSplitFromBuckets(const uint32_t bu return BucketSplit{static_cast(best_split_idx), best_cost}; } -CpuRayTracer::SplitResult CpuRayTracer::FindBestSplit(const Bvh& parent, const std::vector& aabbs) { +RayTracer::SplitResult RayTracer::FindBestSplit(const Bvh& parent, const std::vector& aabbs) { SplitResult ret; BucketBound centroids_aabb; @@ -351,7 +354,7 @@ CpuRayTracer::SplitResult CpuRayTracer::FindBestSplit(const Bvh& parent, const s return ret; } -void CpuRayTracer::BinaryDivisionBvh(Bvh& parent, const uint32_t current_tree_depth, const std::vector& aabbs) { +void RayTracer::BinaryDivisionBvh(Bvh& parent, const uint32_t current_tree_depth, const std::vector& aabbs) { if (parent.element_indices.size() == 1) { parent.subtree_element_size = static_cast(1); return; @@ -386,7 +389,7 @@ void CpuRayTracer::BinaryDivisionBvh(Bvh& parent, const uint32_t current_tree_de parent.subtree_element_size = parent.children[0].subtree_element_size + parent.children[1].subtree_element_size; } -void CpuRayTracer::FlattenBvh(const Bvh& current_bvh, FlattenedBvh& flattened_bvh, const uint32_t level) { +void RayTracer::FlattenBvh(const Bvh& current_bvh, FlattenedBvh& flattened_bvh, const uint32_t level) { if (current_bvh.children.empty() && current_bvh.element_indices.empty()) { // Children scene without triangles? Skip it return; @@ -418,7 +421,7 @@ void CpuRayTracer::FlattenBvh(const Bvh& current_bvh, FlattenedBvh& flattened_bv flattened_bvh.nodes[current_scene_index].alternate_node_index = static_cast(flattened_bvh.nodes.size()); } -glm::vec3 CpuRayTracer::Barycentric(const glm::vec3& p, const glm::vec3& a, const glm::vec3& b, const glm::vec3& c) { +glm::vec3 RayTracer::Barycentric(const glm::vec3& p, const glm::vec3& a, const glm::vec3& b, const glm::vec3& c) { const auto v0 = b - a; const auto v1 = c - a; const auto v2 = p - a; @@ -433,69 +436,50 @@ glm::vec3 CpuRayTracer::Barycentric(const glm::vec3& p, const glm::vec3& a, cons return {1.0f - y - z, y, z}; } -bool CpuRayTracer::AggregatedScene::Trace(const RayDescriptor& ray_descriptor, HitInfo& hit_info) const { - /* - GpuRayCastingResult ray_casting_result; - ray_casting_result.hit.w = 0.0f; - ray_casting_result.normal_distance.w = ray_descriptor.t_max; +void RayTracer::AggregatedScene::Trace(const RayDescriptor& ray_descriptor, + const std::function& closest_hit_func, + const std::function& miss_func, + const std::function& any_hit_func) const { + HitInfo closest_hit_info{}; + closest_hit_info.distance = FLT_MAX; + bool has_hit = false; const auto flags = static_cast(ray_descriptor.flags); - const bool cull_back_face = flags & static_cast(CpuRayTracingService::TraceFlags::CullBackFace); - const bool cull_front_face = flags & static_cast(CpuRayTracingService::TraceFlags::CullFrontFace); - auto ray_aabb = [](const CGVecF3& r_o, const CGVecF3& r_inv_d, const CGAABBF& aabb) { - const auto tx1 = (aabb.min.x - r_o.x) * r_inv_d.x; - const auto tx2 = (aabb.max.x - r_o.x) * r_inv_d.x; - - float t_min = std::min(tx1, tx2); - float t_max = std::max(tx1, tx2); - - const auto ty1 = (aabb.min.y - r_o.y) * r_inv_d.y; - const auto ty2 = (aabb.max.y - r_o.y) * r_inv_d.y; - - t_min = std::max(t_min, std::min(ty1, ty2)); - t_max = std::min(t_max, std::max(ty1, ty2)); - - const auto tz1 = (aabb.min.z - r_o.z) * r_inv_d.z; - const auto tz2 = (aabb.max.z - r_o.z) * r_inv_d.z; - - t_min = std::max(t_min, std::min(tz1, tz2)); - t_max = std::min(t_max, std::max(tz1, tz2)); - - return t_max >= t_min; - }; - - auto scene_space_ray_direction = ray_descriptor.direction; - scene_space_ray_direction.normalise(); + const bool enforce_any_hit = flags & static_cast(TraceFlags::EnforceAnyHit); + const bool cull_back_face = flags & static_cast(TraceFlags::CullBackFace); + const bool cull_front_face = flags & static_cast(TraceFlags::CullFrontFace); + float test_distance = ray_descriptor.t_max; + auto scene_space_ray_direction = glm::normalize(ray_descriptor.direction); const auto& scene_space_ray_origin = ray_descriptor.origin; - const auto scene_space_inv_ray_direction = - CGVecF3(1.f / scene_space_ray_direction.x, 1.f / scene_space_ray_direction.y, 1.f / scene_space_ray_direction.z); + const auto scene_space_inv_ray_direction = glm::vec3( + 1.f / scene_space_ray_direction.x, 1.f / scene_space_ray_direction.y, 1.f / scene_space_ray_direction.z); uint32_t node_group_index = 0; std::unordered_set node_group_index_test; - while (node_group_index < aggregated_scene.scene_level_bvh_nodes.size()) { + while (node_group_index < scene_level_bvh_nodes.size()) { if (node_group_index_test.find(node_group_index) == node_group_index_test.end()) { node_group_index_test.emplace(node_group_index); } else { throw std::runtime_error("Duplicate node!"); } - const auto& node_group = aggregated_scene.scene_level_bvh_nodes[node_group_index]; - if (!ray_aabb(scene_space_ray_origin, scene_space_inv_ray_direction, node_group.aabb)) { + const auto& node_group = scene_level_bvh_nodes[node_group_index]; + if (!RayAabb(scene_space_ray_origin, scene_space_inv_ray_direction, node_group.aabb)) { node_group_index = node_group.alternate_node_index; continue; } for (uint32_t test_node_element_index = node_group.begin_next_level_element_index; test_node_element_index < node_group.end_next_level_element_index; ++test_node_element_index) { uint32_t mesh_group_index = 0; - const auto node_index = aggregated_scene.node_indices[test_node_element_index]; - const auto& node_global_transform = aggregated_scene.node_transforms[node_index]; - const auto& node_inverse_global_transform = aggregated_scene.node_inverse_transforms[node_index]; + const auto node_index = node_indices[test_node_element_index]; + const auto& node_global_transform = node_transforms[node_index]; + const auto& node_inverse_global_transform = node_inverse_transforms[node_index]; const auto node_space_ray_origin = node_inverse_global_transform.TransformPoint(scene_space_ray_origin); - auto node_space_ray_direction = node_inverse_global_transform.TransformVector(scene_space_ray_direction); - node_space_ray_direction.normalise(); - const auto node_space_inv_ray_direction = - CGVecF3(1.f / node_space_ray_direction.x, 1.f / node_space_ray_direction.y, 1.f / node_space_ray_direction.z); - const auto node_level_bvh_node_offset = aggregated_scene.node_level_bvh_node_offsets[node_index]; - const auto node_level_bvh_node_size = aggregated_scene.node_level_bvh_node_sizes[node_index]; - const auto mesh_indices_offset = aggregated_scene.mesh_indices_offsets[node_index]; + auto node_space_ray_direction = + glm::normalize(node_inverse_global_transform.TransformVector(scene_space_ray_direction)); + const auto node_space_inv_ray_direction = glm::vec3( + 1.f / node_space_ray_direction.x, 1.f / node_space_ray_direction.y, 1.f / node_space_ray_direction.z); + const auto node_level_bvh_node_offset = node_level_bvh_node_offsets[node_index]; + const auto node_level_bvh_node_size = node_level_bvh_node_sizes[node_index]; + const auto mesh_indices_offset = mesh_indices_offsets[node_index]; std::unordered_set mesh_group_index_test; while (mesh_group_index < node_level_bvh_node_size) { if (mesh_group_index_test.find(mesh_group_index) == mesh_group_index_test.end()) { @@ -503,8 +487,8 @@ bool CpuRayTracer::AggregatedScene::Trace(const RayDescriptor& ray_descriptor, H } else { throw std::runtime_error("Duplicate mesh!"); } - const auto &mesh_group = aggregated_scene.node_level_bvh_nodes[mesh_group_index + node_level_bvh_node_offset]; - if (!ray_aabb(node_space_ray_origin, node_space_inv_ray_direction, mesh_group.aabb)) { + const auto& mesh_group = node_level_bvh_nodes[mesh_group_index + node_level_bvh_node_offset]; + if (!RayAabb(node_space_ray_origin, node_space_inv_ray_direction, mesh_group.aabb)) { mesh_group_index = mesh_group.alternate_node_index; continue; } @@ -512,10 +496,10 @@ bool CpuRayTracer::AggregatedScene::Trace(const RayDescriptor& ray_descriptor, H test_mesh_element_index < mesh_group.end_next_level_element_index + mesh_indices_offset; ++test_mesh_element_index) { uint32_t triangle_group_index = 0; - const auto mesh_index = aggregated_scene.mesh_indices[test_mesh_element_index]; - const auto mesh_level_bvh_node_offset = aggregated_scene.mesh_level_bvh_node_offsets[mesh_index]; - const auto mesh_level_bvh_node_size = aggregated_scene.mesh_level_bvh_node_sizes[mesh_index]; - const auto triangle_indices_offset = aggregated_scene.triangle_indices_offsets[mesh_index]; + const auto mesh_index = mesh_indices[test_mesh_element_index]; + const auto mesh_level_bvh_node_offset = mesh_level_bvh_node_offsets[mesh_index]; + const auto mesh_level_bvh_node_size = mesh_level_bvh_node_sizes[mesh_index]; + const auto triangle_indices_offset = triangle_indices_offsets[mesh_index]; std::unordered_set triangle_group_index_test; while (triangle_group_index < mesh_level_bvh_node_size) { if (triangle_group_index_test.find(triangle_group_index) == triangle_group_index_test.end()) { @@ -523,66 +507,55 @@ bool CpuRayTracer::AggregatedScene::Trace(const RayDescriptor& ray_descriptor, H } else { throw std::runtime_error("Duplicate triangle!"); } - const auto& triangle_group = - aggregated_scene.mesh_level_bvh_nodes[triangle_group_index + mesh_level_bvh_node_offset]; - if (!ray_aabb(node_space_ray_origin, node_space_inv_ray_direction, triangle_group.aabb)) { + const auto& triangle_group = mesh_level_bvh_nodes[triangle_group_index + mesh_level_bvh_node_offset]; + if (!RayAabb(node_space_ray_origin, node_space_inv_ray_direction, triangle_group.aabb)) { triangle_group_index = triangle_group.alternate_node_index; continue; } for (uint32_t test_triangle_index = triangle_group.begin_next_level_element_index + triangle_indices_offset; test_triangle_index < triangle_group.end_next_level_element_index + triangle_indices_offset; ++test_triangle_index) { - const auto triangle_index = aggregated_scene.triangle_indices[test_triangle_index]; - const auto& triangle = aggregated_scene.triangles[triangle_index]; - const auto& p0 = aggregated_scene.vertex_positions[triangle.x]; - const auto& p1 = aggregated_scene.vertex_positions[triangle.y]; - const auto& p2 = aggregated_scene.vertex_positions[triangle.z]; + const auto triangle_index = triangle_indices[test_triangle_index]; + const auto& triangle = triangles[triangle_index]; + const auto& p0 = vertex_positions[triangle.x]; + const auto& p1 = vertex_positions[triangle.y]; + const auto& p2 = vertex_positions[triangle.z]; if (p0 == p1 && p1 == p2) continue; - auto node_space_triangle_normal = (p1 - p0).crossProduct(p2 - p0); - node_space_triangle_normal.normalise(); - const auto normal_test = node_space_ray_direction.dotProduct(node_space_triangle_normal); + auto node_space_triangle_normal = glm::normalize(glm::cross(p1 - p0, p2 - p0)); + const auto normal_test = glm::dot(node_space_ray_direction, node_space_triangle_normal); if ((cull_back_face && normal_test > 0.f) || (cull_front_face && normal_test < 0.f) || normal_test == 0.f) continue; // node_space_hit_distance > 0 instead of node_space_hit_distance >= 0 to avoid self-intersection - if (const auto node_space_hit_distance = (p0.dotProduct(node_space_triangle_normal) - - node_space_ray_origin.dotProduct(node_space_triangle_normal)) / - normal_test; + if (const auto node_space_hit_distance = + glm::dot(p0, node_space_triangle_normal) - + glm::dot(node_space_ray_origin, node_space_triangle_normal) / normal_test; node_space_hit_distance > 0) { const auto node_space_hit = node_space_ray_origin + node_space_ray_direction * node_space_hit_distance; const auto scene_space_hit = node_global_transform.TransformPoint(node_space_hit); - if (const auto scene_hit_distance = (scene_space_ray_origin - scene_space_hit).length(); - scene_hit_distance >= ray_descriptor.t_min && - scene_hit_distance <= ray_casting_result.normal_distance.w) { - auto calculate_barycentric = [](const CGVecF3& p, const CGVecF3& a, const CGVecF3& b, - const CGVecF3& c) { - const auto v0 = b - a; - const auto v1 = c - a; - const auto v2 = p - a; - const auto d00 = v0.dotProduct(v0); - const auto d01 = v0.dotProduct(v1); - const auto d11 = v1.dotProduct(v1); - const auto d20 = v2.dotProduct(v0); - const auto d21 = v2.dotProduct(v1); - const auto denominator = d00 * d11 - d01 * d01; - const auto y = (d11 * d20 - d01 * d21) / denominator; - const auto z = (d00 * d21 - d01 * d20) / denominator; - return CGVecF3{1.0f - y - z, y, z}; - }; - if (const auto barycentric = calculate_barycentric(node_space_hit, p0, p1, p2); + if (const auto scene_hit_distance = glm::distance(scene_space_ray_origin, scene_space_hit); + scene_hit_distance >= ray_descriptor.t_min && scene_hit_distance <= test_distance) { + if (const auto barycentric = Barycentric(node_space_hit, p0, p1, p2); barycentric.x >= 0.f && barycentric.x <= 1.f && barycentric.y >= 0.f && barycentric.y <= 1.f && barycentric.z >= 0.f && barycentric.z <= 1.f) { - ray_casting_result.hit = CGVecF4(scene_space_hit.x, scene_space_hit.y, scene_space_hit.z, 1.0); - const auto scene_space_normal = node_global_transform.TransformVector(node_space_triangle_normal); - ray_casting_result.normal_distance = - CGVecF4(scene_space_normal.x, scene_space_normal.y, scene_space_normal.z, scene_hit_distance); - ray_casting_result.barycentric_back_face = - CGVecF4(barycentric.x, barycentric.y, barycentric.z, normal_test > 0.f); - UintBitsToFloat(node_index, ray_casting_result.node_mesh_triangle_indices.x); - UintBitsToFloat(mesh_index, ray_casting_result.node_mesh_triangle_indices.y); - UintBitsToFloat(aggregated_scene.local_triangle_indices[test_triangle_index], - ray_casting_result.node_mesh_triangle_indices.z); + HitInfo any_hit_info; + any_hit_info.hit = scene_space_hit; + any_hit_info.normal = node_global_transform.TransformVector(node_space_triangle_normal); + any_hit_info.distance = scene_hit_distance; + any_hit_info.barycentric = barycentric; + any_hit_info.back_face = normal_test > 0.f; + any_hit_info.triangle_index = local_triangle_indices[test_triangle_index]; + any_hit_info.mesh_index = mesh_index; + any_hit_info.node_index = node_index; + any_hit_func(any_hit_info); + if (!enforce_any_hit) { + test_distance = scene_hit_distance; + } + if (any_hit_info.distance < closest_hit_info.distance) { + has_hit = true; + closest_hit_info = any_hit_info; + } } } } @@ -595,13 +568,14 @@ bool CpuRayTracer::AggregatedScene::Trace(const RayDescriptor& ray_descriptor, H } node_group_index++; } - - return ray_casting_result; - */ - return false; + if (has_hit) { + closest_hit_func(closest_hit_info); + } else { + miss_func(); + } } -CpuRayTracer::AggregatedScene CpuRayTracer::Aggregate() const { +RayTracer::AggregatedScene RayTracer::Aggregate() const { AggregatedScene aggregated_scene; aggregated_scene.scene_level_bvh_nodes = flattened_bvh_node_group_.nodes; aggregated_scene.node_indices = flattened_bvh_node_group_.element_indices; @@ -672,7 +646,7 @@ CpuRayTracer::AggregatedScene CpuRayTracer::Aggregate() const { return aggregated_scene; } -void CpuRayTracer::GeometryInstance::Initialize(const std::shared_ptr& input_mesh) { +void RayTracer::GeometryInstance::Initialize(const std::shared_ptr& input_mesh) { Clear(); const auto& input_vertices = input_mesh->UnsafeGetVertices(); triangles = input_mesh->UnsafeGetTriangles(); @@ -705,7 +679,7 @@ void CpuRayTracer::GeometryInstance::Initialize(const std::shared_ptr& inp FlattenBvh(mesh_bvh, flattened_bvh_triangle_group, 0); } -void CpuRayTracer::GeometryInstance::Clear() noexcept { +void RayTracer::GeometryInstance::Clear() noexcept { flattened_bvh_triangle_group.nodes.clear(); flattened_bvh_triangle_group.element_indices.clear(); aabb = {}; @@ -713,7 +687,7 @@ void CpuRayTracer::GeometryInstance::Clear() noexcept { vertex_positions.clear(); } -void CpuRayTracer::NodeInstance::Initialize(const std::shared_ptr& input_scene, const Entity& input_entity, +void RayTracer::NodeInstance::Initialize(const std::shared_ptr& input_scene, const Entity& input_entity, const std::vector& mesh_instances, const std::map& mesh_instances_map) { const auto mesh_renderer = input_scene->GetOrSetPrivateComponent(input_entity).lock(); @@ -735,7 +709,7 @@ void CpuRayTracer::NodeInstance::Initialize(const std::shared_ptr& input_ FlattenBvh(node_bvh, flattened_bvh_mesh_group, 0); } -void CpuRayTracer::NodeInstance::Clear() noexcept { +void RayTracer::NodeInstance::Clear() noexcept { aabb = {}; transformation = {}; inverse_transformation = {}; diff --git a/EvoEngine_Plugins/TextureBaking/src/TextureBaker.cpp b/EvoEngine_Plugins/TextureBaking/src/TextureBaker.cpp index 9aa3f6f..cdb83f5 100644 --- a/EvoEngine_Plugins/TextureBaking/src/TextureBaker.cpp +++ b/EvoEngine_Plugins/TextureBaking/src/TextureBaker.cpp @@ -1,6 +1,6 @@ #include "TextureBaker.hpp" -#include "CpuRayTracer.hpp" +#include "RayTracer.hpp" #include "Times.hpp" using namespace evo_engine; @@ -101,19 +101,19 @@ void CompressedMapUv::Initialize(const std::vector& target_vertices, struct RayCastingResult { bool miss = false; - CpuRayTracer::HitInfo hit_info; + RayTracer::HitInfo hit_info; }; std::vector RayCastingSolver(const TextureBaker::Parameters& parameters, const CompressedMapUv& compressed_map_uv, - const CpuRayTracer& ray_tracer, const float thin_scale, + const RayTracer& ray_tracer, const float thin_scale, const float max_ray_casting_distance) { auto ray_casting_results = std::vector(compressed_map_uv.indices.size(), RayCastingResult()); Jobs::RunParallelFor(compressed_map_uv.positions.size(), [&](const size_t i) { - CpuRayTracer::RayDescriptor ray_descriptor{}; + RayTracer::RayDescriptor ray_descriptor{}; auto& result = ray_casting_results[i]; - ray_descriptor.flags = parameters.cull_back_face ? CpuRayTracer::TraceFlags::CullBackFace - : CpuRayTracer::TraceFlags::None; + ray_descriptor.flags = parameters.cull_back_face ? RayTracer::TraceFlags::CullBackFace + : RayTracer::TraceFlags::None; // Compare and get closest triangle. // Diagram: // @@ -131,7 +131,7 @@ std::vector RayCastingSolver(const TextureBaker::Parameters& p bool hit = false; ray_tracer.Trace( ray_descriptor, - [&](const CpuRayTracer::HitInfo& hit_info) { + [&](const RayTracer::HitInfo& hit_info) { result.hit_info = hit_info; hit = true; }, @@ -143,11 +143,11 @@ std::vector RayCastingSolver(const TextureBaker::Parameters& p if (!hit) { ray_descriptor.direction = sample_direction; ray_descriptor.t_max = max_ray_casting_distance - thin_scale; - ray_descriptor.flags = parameters.cull_back_face ? CpuRayTracer::TraceFlags::CullFrontFace - : CpuRayTracer::TraceFlags::None; + ray_descriptor.flags = parameters.cull_back_face ? RayTracer::TraceFlags::CullFrontFace + : RayTracer::TraceFlags::None; ray_tracer.Trace( ray_descriptor, - [&](const CpuRayTracer::HitInfo& hit_info) { + [&](const RayTracer::HitInfo& hit_info) { result.hit_info = hit_info; hit = true; }, @@ -472,7 +472,7 @@ void TextureBaker::Execute(const Parameters& parameters, const std::shared_ptrGetBound().Size()); float max_ray_casting_distance = parameters.ray_casting_range * diagonal_length; diff --git a/EvoEngine_Plugins/Universe/src/StarClusterSystem.cpp b/EvoEngine_Plugins/Universe/src/StarClusterSystem.cpp index 5fb2d04..3b5a15c 100644 --- a/EvoEngine_Plugins/Universe/src/StarClusterSystem.cpp +++ b/EvoEngine_Plugins/Universe/src/StarClusterSystem.cpp @@ -4,7 +4,7 @@ #include "Serialization.hpp" #include "Resources.hpp" #include "ClassRegistry.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "Jobs.hpp" #include "Particles.hpp" #include "Times.hpp" diff --git a/EvoEngine_SDK/CMakeLists.txt b/EvoEngine_SDK/CMakeLists.txt index a66e25d..56a5e5f 100644 --- a/EvoEngine_SDK/CMakeLists.txt +++ b/EvoEngine_SDK/CMakeLists.txt @@ -130,22 +130,4 @@ function(evoengine_sdk_copy_resources dst_target dst_dir) COMMAND ${CMAKE_COMMAND} -E copy_directory ${EVOENGINE_SDK_DIR}/Internals ${dst_dir} VERBATIM) - foreach(file_i ${EVOENGINE_SDK_DLLS}) - add_custom_command(TARGET ${dst_target} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${file_i} ${dst_dir} || (exit 0) - VERBATIM) - endforeach(file_i) - foreach(file_i ${3RDPARTY_DLLS}) - add_custom_command(TARGET ${dst_target} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${file_i} ${dst_dir} || (exit 0) - VERBATIM) - endforeach(file_i) - foreach(file_i ${3RDPARTY_PDBS}) - add_custom_command(TARGET ${dst_target} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${file_i} ${dst_dir} || (exit 0) - VERBATIM) - endforeach(file_i) endfunction() \ No newline at end of file diff --git a/EvoEngine_SDK/include/Core/Input.hpp b/EvoEngine_SDK/include/Core/Input.hpp index 54bffbd..fee2dc6 100644 --- a/EvoEngine_SDK/include/Core/Input.hpp +++ b/EvoEngine_SDK/include/Core/Input.hpp @@ -14,7 +14,7 @@ class Input final { static glm::vec2 GetMousePosition(); private: - friend class Graphics; + friend class Platform; friend class Application; friend class EditorLayer; std::unordered_map pressed_keys_ = {}; diff --git a/EvoEngine_SDK/include/Layers/RenderLayer.hpp b/EvoEngine_SDK/include/Layers/RenderLayer.hpp index 7c4cb9f..0e79a10 100644 --- a/EvoEngine_SDK/include/Layers/RenderLayer.hpp +++ b/EvoEngine_SDK/include/Layers/RenderLayer.hpp @@ -172,7 +172,12 @@ class RenderLayer final : public ILayer { void ClearAllCameras(); void RenderAllCameras(); + + public: + + + bool wire_frame = false; bool count_shadow_rendering_draw_calls = false; diff --git a/EvoEngine_SDK/include/Layers/WindowLayer.hpp b/EvoEngine_SDK/include/Layers/WindowLayer.hpp index 717e523..fd3cefd 100644 --- a/EvoEngine_SDK/include/Layers/WindowLayer.hpp +++ b/EvoEngine_SDK/include/Layers/WindowLayer.hpp @@ -2,7 +2,7 @@ #include "ILayer.hpp" namespace evo_engine { class WindowLayer final : public ILayer { - friend class Graphics; + friend class Platform; friend class RenderLayer; #pragma region Presenters std::vector monitors_; diff --git a/EvoEngine_SDK/include/Rendering/Camera.hpp b/EvoEngine_SDK/include/Rendering/Camera.hpp index d5c4537..a4cecc7 100644 --- a/EvoEngine_SDK/include/Rendering/Camera.hpp +++ b/EvoEngine_SDK/include/Rendering/Camera.hpp @@ -24,7 +24,7 @@ struct CameraInfoBlock { }; class Camera final : public IPrivateComponent { - friend class Graphics; + friend class Platform; friend class RenderLayer; friend class EditorLayer; friend struct CameraInfoBlock; @@ -56,7 +56,7 @@ class Camera final : public IPrivateComponent { void UpdateGBuffer(); public: - void TransitGBufferImageLayout(VkCommandBuffer command_buffer, VkImageLayout target_layout) const; + void TransitGBufferImageLayout(VkCommandBuffer vk_command_buffer, VkImageLayout target_layout) const; void UpdateCameraInfoBlock(CameraInfoBlock& camera_info_block, const GlobalTransform& global_transform); void AppendGBufferColorAttachmentInfos(std::vector& attachment_infos, diff --git a/EvoEngine_SDK/include/Rendering/Geometry/GeometryStorage.hpp b/EvoEngine_SDK/include/Rendering/Geometry/GeometryStorage.hpp index 6dfe4e6..4bf4be6 100644 --- a/EvoEngine_SDK/include/Rendering/Geometry/GeometryStorage.hpp +++ b/EvoEngine_SDK/include/Rendering/Geometry/GeometryStorage.hpp @@ -1,36 +1,36 @@ #pragma once -#include "Graphics.hpp" +#include "Platform.hpp" #include "GraphicsResources.hpp" #include "ISingleton.hpp" #include "Vertex.hpp" namespace evo_engine { struct VertexDataChunk { - Vertex vertex_data[Graphics::Constants::meshlet_max_vertices_size] = {}; + Vertex vertex_data[Platform::Constants::meshlet_max_vertices_size] = {}; }; struct Meshlet { - glm::u8vec3 triangles[Graphics::Constants::meshlet_max_triangles_size] = {}; // up to 126 triangles + glm::u8vec3 triangles[Platform::Constants::meshlet_max_triangles_size] = {}; // up to 126 triangles uint32_t vertices_size = 0; uint32_t triangle_size = 0; uint32_t vertex_chunk_index = 0; }; struct SkinnedVertexDataChunk { - SkinnedVertex skinned_vertex_data[Graphics::Constants::meshlet_max_vertices_size] = {}; + SkinnedVertex skinned_vertex_data[Platform::Constants::meshlet_max_vertices_size] = {}; }; struct SkinnedMeshlet { - glm::u8vec3 skinned_triangles[Graphics::Constants::meshlet_max_triangles_size] = {}; // up to 126 triangles + glm::u8vec3 skinned_triangles[Platform::Constants::meshlet_max_triangles_size] = {}; // up to 126 triangles uint32_t skinned_vertices_size = 0; uint32_t skinned_triangle_size = 0; uint32_t skinned_vertex_chunk_index = 0; }; struct StrandPointDataChunk { - StrandPoint strand_point_data[Graphics::Constants::meshlet_max_vertices_size] = {}; + StrandPoint strand_point_data[Platform::Constants::meshlet_max_vertices_size] = {}; }; struct StrandMeshlet { - glm::u8vec4 segments[Graphics::Constants::meshlet_max_triangles_size] = {}; // up to 126 triangles + glm::u8vec4 segments[Platform::Constants::meshlet_max_triangles_size] = {}; // up to 126 triangles uint32_t strand_points_size = 0; uint32_t segment_size = 0; uint32_t strand_point_chunk_index = 0; @@ -105,7 +105,7 @@ class GeometryStorage final { void UploadData(); friend class RenderLayer; friend class Resources; - friend class Graphics; + friend class Platform; static void DeviceSync(); static void Initialize(); @@ -121,9 +121,9 @@ class GeometryStorage final { static const std::unique_ptr& GetStrandPointBuffer(); static const std::unique_ptr& GetStrandMeshletBuffer(); - static void BindVertices(VkCommandBuffer command_buffer); - static void BindSkinnedVertices(VkCommandBuffer command_buffer); - static void BindStrandPoints(VkCommandBuffer command_buffer); + static void BindVertices(VkCommandBuffer vk_command_buffer); + static void BindSkinnedVertices(VkCommandBuffer vk_command_buffer); + static void BindStrandPoints(VkCommandBuffer vk_command_buffer); [[nodiscard]] static const Vertex& PeekVertex(size_t vertex_index); [[nodiscard]] static const SkinnedVertex& PeekSkinnedVertex(size_t skinned_vertex_index); diff --git a/EvoEngine_SDK/include/Rendering/Geometry/IGeometry.hpp b/EvoEngine_SDK/include/Rendering/Geometry/IGeometry.hpp index 7fcf0ed..6895b8b 100644 --- a/EvoEngine_SDK/include/Rendering/Geometry/IGeometry.hpp +++ b/EvoEngine_SDK/include/Rendering/Geometry/IGeometry.hpp @@ -1,4 +1,5 @@ #pragma once +#include "GraphicsResources.hpp" #include "Transform.hpp" #include "Vertex.hpp" namespace evo_engine { diff --git a/EvoEngine_SDK/include/Rendering/Geometry/Mesh.hpp b/EvoEngine_SDK/include/Rendering/Geometry/Mesh.hpp index 4e020fd..5eb84b5 100644 --- a/EvoEngine_SDK/include/Rendering/Geometry/Mesh.hpp +++ b/EvoEngine_SDK/include/Rendering/Geometry/Mesh.hpp @@ -1,7 +1,7 @@ #pragma once #include "Bound.hpp" #include "GeometryStorage.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "GraphicsResources.hpp" #include "IAsset.hpp" #include "IGeometry.hpp" diff --git a/EvoEngine_SDK/include/Rendering/Geometry/SkinnedMesh.hpp b/EvoEngine_SDK/include/Rendering/Geometry/SkinnedMesh.hpp index 4e37907..340acd9 100644 --- a/EvoEngine_SDK/include/Rendering/Geometry/SkinnedMesh.hpp +++ b/EvoEngine_SDK/include/Rendering/Geometry/SkinnedMesh.hpp @@ -33,7 +33,7 @@ class SkinnedMesh : public IAsset, public IGeometry { Bound bound_; friend class SkinnedMeshRenderer; friend class Particles; - friend class Graphics; + friend class Platform; friend class RenderLayer; SkinnedVertexAttributes skinned_vertex_attributes_ = {}; std::vector skinned_vertices_; diff --git a/EvoEngine_SDK/include/Rendering/PBR/EnvironmentalMap.hpp b/EvoEngine_SDK/include/Rendering/PBR/EnvironmentalMap.hpp index 947ce61..97126bf 100644 --- a/EvoEngine_SDK/include/Rendering/PBR/EnvironmentalMap.hpp +++ b/EvoEngine_SDK/include/Rendering/PBR/EnvironmentalMap.hpp @@ -6,7 +6,7 @@ namespace evo_engine { class EnvironmentalMap final : public IAsset { - friend class Graphics; + friend class Platform; friend class Camera; friend class Environment; friend class RenderLayer; diff --git a/EvoEngine_SDK/include/Rendering/PBR/Material.hpp b/EvoEngine_SDK/include/Rendering/PBR/Material.hpp index 2397094..89af8b7 100644 --- a/EvoEngine_SDK/include/Rendering/PBR/Material.hpp +++ b/EvoEngine_SDK/include/Rendering/PBR/Material.hpp @@ -1,6 +1,6 @@ #pragma once #include "AssetRef.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "IAsset.hpp" #include "MaterialProperties.hpp" #include "Texture2D.hpp" diff --git a/EvoEngine_SDK/include/Rendering/Platform/ComputePipeline.hpp b/EvoEngine_SDK/include/Rendering/Platform/ComputePipeline.hpp new file mode 100644 index 0000000..723a5da --- /dev/null +++ b/EvoEngine_SDK/include/Rendering/Platform/ComputePipeline.hpp @@ -0,0 +1,34 @@ +#pragma once +#include "GraphicsResources.hpp" +namespace evo_engine { +class Shader; +class ComputePipeline final : public IGraphicsResource{ + friend class Platform; + + std::unique_ptr pipeline_layout_ = {}; + + VkPipeline vk_compute_pipeline_ = VK_NULL_HANDLE; + + public: + ~ComputePipeline() override; + std::vector push_constant_ranges; + std::vector> descriptor_set_layouts; + + std::shared_ptr compute_shader; + + void Initialize(); + [[nodiscard]] bool Initialized() const; + + void Bind(const CommandBuffer& command_buffer) const; + void BindDescriptorSet(const CommandBuffer& command_buffer, uint32_t first_set, VkDescriptorSet descriptor_set) const; + template + void PushConstant(const CommandBuffer& command_buffer, size_t range_index, const T& data); +}; + +template +void ComputePipeline::PushConstant(const CommandBuffer& command_buffer, const size_t range_index, const T& data) { + vkCmdPushConstants(command_buffer.GetVkCommandBuffer(), pipeline_layout_->GetVkPipelineLayout(), + push_constant_ranges[range_index].stageFlags, push_constant_ranges[range_index].offset, + push_constant_ranges[range_index].size, &data); +} +} // namespace evo_engine diff --git a/EvoEngine_SDK/include/Rendering/Platform/GraphicsPipeline.hpp b/EvoEngine_SDK/include/Rendering/Platform/GraphicsPipeline.hpp index bee397c..2bd8013 100644 --- a/EvoEngine_SDK/include/Rendering/Platform/GraphicsPipeline.hpp +++ b/EvoEngine_SDK/include/Rendering/Platform/GraphicsPipeline.hpp @@ -96,8 +96,8 @@ struct PipelineDynamicState { }; #pragma endregion -class GraphicsPipeline { - friend class Graphics; +class GraphicsPipeline final : public IGraphicsResource { + friend class Platform; friend class RenderLayer; friend class GraphicsPipelineStates; @@ -106,6 +106,7 @@ class GraphicsPipeline { VkPipeline vk_graphics_pipeline_ = VK_NULL_HANDLE; public: + ~GraphicsPipeline() override; GraphicsPipelineStates states{}; std::vector> descriptor_set_layouts; @@ -129,17 +130,18 @@ class GraphicsPipeline { std::vector push_constant_ranges; - void PreparePipeline(); - [[nodiscard]] bool PipelineReady() const; - void Bind(VkCommandBuffer command_buffer); - void BindDescriptorSet(VkCommandBuffer command_buffer, uint32_t first_set, VkDescriptorSet descriptor_set) const; + void Initialize(); + + [[nodiscard]] bool Initialized() const; + void Bind(VkCommandBuffer vk_command_buffer); + void BindDescriptorSet(VkCommandBuffer vk_command_buffer, uint32_t first_set, VkDescriptorSet descriptor_set) const; template - void PushConstant(VkCommandBuffer command_buffer, size_t range_index, const T& data); + void PushConstant(VkCommandBuffer vk_command_buffer, size_t range_index, const T& data); }; template -void GraphicsPipeline::PushConstant(const VkCommandBuffer command_buffer, const size_t range_index, const T& data) { - vkCmdPushConstants(command_buffer, pipeline_layout_->GetVkPipelineLayout(), +void GraphicsPipeline::PushConstant(const VkCommandBuffer vk_command_buffer, const size_t range_index, const T& data) { + vkCmdPushConstants(vk_command_buffer, pipeline_layout_->GetVkPipelineLayout(), push_constant_ranges[range_index].stageFlags, push_constant_ranges[range_index].offset, push_constant_ranges[range_index].size, &data); } diff --git a/EvoEngine_SDK/include/Rendering/Platform/GraphicsPipelineStates.hpp b/EvoEngine_SDK/include/Rendering/Platform/GraphicsPipelineStates.hpp index be3f167..3d3a5ad 100644 --- a/EvoEngine_SDK/include/Rendering/Platform/GraphicsPipelineStates.hpp +++ b/EvoEngine_SDK/include/Rendering/Platform/GraphicsPipelineStates.hpp @@ -1,7 +1,9 @@ #pragma once +#include "GraphicsResources.hpp" + namespace evo_engine { class GraphicsPipelineStates { - friend class Graphics; + friend class Platform; VkViewport view_port_applied_ = {}; VkRect2D scissor_applied_ = {}; @@ -59,6 +61,6 @@ class GraphicsPipelineStates { VkLogicOp logic_op = VK_LOGIC_OP_COPY; std::vector color_blend_attachment_states = {}; float blend_constants[4] = {0, 0, 0, 0}; - void ApplyAllStates(VkCommandBuffer command_buffer, bool force_set = false); + void ApplyAllStates(VkCommandBuffer vk_command_buffer, bool force_set = false); }; } // namespace evo_engine \ No newline at end of file diff --git a/EvoEngine_SDK/include/Rendering/Platform/GraphicsResources.hpp b/EvoEngine_SDK/include/Rendering/Platform/GraphicsResources.hpp index c0cef23..14c400a 100644 --- a/EvoEngine_SDK/include/Rendering/Platform/GraphicsResources.hpp +++ b/EvoEngine_SDK/include/Rendering/Platform/GraphicsResources.hpp @@ -1,6 +1,8 @@ #pragma once #include "shaderc/shaderc.h" namespace evo_engine { +class CommandBuffer; + class IGraphicsResource { protected: IGraphicsResource() = default; @@ -73,10 +75,11 @@ class Image final : public IGraphicsResource { Image(VkImageCreateInfo image_create_info, const VmaAllocationCreateInfo& vma_allocation_create_info); bool HasStencilComponent() const; ~Image() override; - void TransitImageLayout(VkCommandBuffer command_buffer, VkImageLayout new_layout); - void CopyFromBuffer(VkCommandBuffer command_buffer, const VkBuffer& src_buffer, VkDeviceSize src_offset = 0) const; + void TransitImageLayout(VkCommandBuffer vk_command_buffer, VkImageLayout new_layout); + void CopyFromBuffer(VkCommandBuffer vk_command_buffer, const VkBuffer& src_buffer, + VkDeviceSize src_offset = 0) const; - void GenerateMipmaps(VkCommandBuffer command_buffer); + void GenerateMipmaps(VkCommandBuffer vk_command_buffer); [[nodiscard]] VkImage GetVkImage() const; [[nodiscard]] VkFormat GetFormat() const; @@ -102,7 +105,7 @@ class ImageView final : public IGraphicsResource { VkComponentMapping components_; VkImageSubresourceRange subresource_range_; friend class Swapchain; - friend class Graphics; + friend class Platform; public: explicit ImageView(const VkImageViewCreateInfo& image_view_create_info); @@ -328,16 +331,15 @@ class ShaderExt final : public IGraphicsResource { }; enum class CommandBufferStatus { Ready, Recording, Recorded, Invalid }; -class CommandBuffer { - friend class Graphics; +class CommandBuffer final : public IGraphicsResource { + friend class Platform; CommandBufferStatus status_ = CommandBufferStatus::Invalid; VkCommandBuffer vk_command_buffer_ = VK_NULL_HANDLE; public: CommandBufferStatus GetStatus() const; - void Allocate(const VkQueueFlagBits& queue_type = VK_QUEUE_GRAPHICS_BIT, - const VkCommandBufferLevel& buffer_level = VK_COMMAND_BUFFER_LEVEL_PRIMARY); - void Free(); + CommandBuffer(const VkCommandBufferLevel& buffer_level = VK_COMMAND_BUFFER_LEVEL_PRIMARY); + ~CommandBuffer() override; [[nodiscard]] const VkCommandBuffer& GetVkCommandBuffer() const; /** * Begins the recording state for this command buffer. @@ -349,20 +351,33 @@ class CommandBuffer { * Ends the recording state for this command buffer. */ void End(); - /** - * Submits the command buffer to the queue and will hold the current thread idle until it has finished. - */ - void SubmitIdle(); - /** - * Submits the command buffer. - * @param wait_semaphore A optional semaphore that will waited upon before the command buffer is executed. - * @param signal_semaphore A optional that is signaled once the command buffer has been executed. - * @param fence A optional fence that is signaled once the command buffer has completed. - */ - void Submit(const VkSemaphore& wait_semaphore = VK_NULL_HANDLE, const VkSemaphore& signal_semaphore = VK_NULL_HANDLE, - VkFence fence = VK_NULL_HANDLE) const; + void Record(const std::function& commands); void Reset(); }; + +class CommandQueue final : public IGraphicsResource { + friend class Platform; + VkQueue vk_queue_ = VK_NULL_HANDLE; + +public: + void Submit(const std::vector>& command_buffers, + const std::vector, VkPipelineStageFlags>>& wait_semaphores, + const std::vector>& signal_semaphores, const std::shared_ptr& fence) const; + + void Submit(const std::vector>& command_buffers, + const std::vector, VkPipelineStageFlags>>& wait_semaphores, + const std::vector>& signal_semaphores) const; + + void ImmediateSubmit(const std::vector>& command_buffers, + const std::vector, VkPipelineStageFlags>>& wait_semaphores, + const std::vector>& signal_semaphores) const; + + void Present(const std::vector>& wait_semaphores, + const std::vector, uint32_t>>& targets) const; + + void WaitIdle() const; +}; + } // namespace evo_engine diff --git a/EvoEngine_SDK/include/Rendering/Platform/Graphics.hpp b/EvoEngine_SDK/include/Rendering/Platform/Platform.hpp similarity index 81% rename from EvoEngine_SDK/include/Rendering/Platform/Graphics.hpp rename to EvoEngine_SDK/include/Rendering/Platform/Platform.hpp index e4045ac..77712d8 100644 --- a/EvoEngine_SDK/include/Rendering/Platform/Graphics.hpp +++ b/EvoEngine_SDK/include/Rendering/Platform/Platform.hpp @@ -1,14 +1,15 @@ #pragma once #include "GraphicsPipeline.hpp" +#include "ComputePipeline.hpp" #include "GraphicsResources.hpp" #include "ISingleton.hpp" namespace evo_engine { struct QueueFamilyIndices { - std::optional graphics_family; + std::optional graphics_and_compute_family; std::optional present_family; [[nodiscard]] bool IsComplete() const { - return graphics_family.has_value() && present_family.has_value(); + return graphics_and_compute_family.has_value() && present_family.has_value(); } }; @@ -18,8 +19,8 @@ struct SwapChainSupportDetails { std::vector present_modes; }; -class Graphics final { - EVOENGINE_SINGLETON_INSTANCE(Graphics) +class Platform final { + EVOENGINE_SINGLETON_INSTANCE(Platform) friend class Application; friend class Resources; friend class Lighting; @@ -53,10 +54,12 @@ class Graphics final { QueueFamilyIndices queue_family_indices_ = {}; - VkQueue vk_graphics_queue_ = VK_NULL_HANDLE; - VkQueue vk_present_queue_ = VK_NULL_HANDLE; + std::unique_ptr immediate_submit_queue_ {}; - std::unique_ptr swapchain_ = {}; + std::unique_ptr main_queue_{}; + std::unique_ptr present_queue_{}; + + std::shared_ptr swapchain_ = {}; VkSurfaceFormatKHR vk_surface_format_ = {}; @@ -67,12 +70,10 @@ class Graphics final { int max_frame_in_flight_ = 2; - int used_command_buffer_size_ = 0; - std::vector> command_buffer_pool_ = {}; - - std::vector> image_available_semaphores_ = {}; - std::vector> render_finished_semaphores_ = {}; - std::vector> in_flight_fences_ = {}; + + std::vector> image_available_semaphores_ = {}; + std::vector> render_finished_semaphores_ = {}; + std::vector> in_flight_fences_ = {}; uint32_t current_frame_index_ = 0; @@ -128,16 +129,28 @@ class Graphics final { static uint32_t FindMemoryType(uint32_t type_filter, VkMemoryPropertyFlags properties); std::unordered_map> graphics_pipelines_; + std::unordered_map> compute_pipelines_; + + std::shared_ptr bound_graphics_pipeline; + std::shared_ptr bound_compute_pipeline; + std::unordered_map> descriptor_set_layouts_; void CreateGraphicsPipelines() const; static void PrepareDescriptorSetLayouts(); - + int used_command_buffer_size_ = 0; + std::vector>> command_buffer_pool_ = {}; + std::shared_ptr immediate_submit_command_buffer; public: + static void RecordCommandsMainQueue(const std::function& action); + + double cpu_wait_time = 0.0f; static void WaitForDeviceIdle(); static void RegisterGraphicsPipeline(const std::string& name, const std::shared_ptr& graphics_pipeline); + static void RegisterComputePipeline(const std::string& name, + const std::shared_ptr& compute_pipeline); [[nodiscard]] static const std::shared_ptr& GetGraphicsPipeline(const std::string& name); static void RegisterDescriptorSetLayout(const std::string& name, const std::shared_ptr& descriptor_set_layout); @@ -183,9 +196,9 @@ class Graphics final { constexpr static uint32_t meshlet_max_triangles_size = 40; }; - static void EverythingBarrier(VkCommandBuffer command_buffer); + static void EverythingBarrier(VkCommandBuffer vk_command_buffer); - static void TransitImageLayout(VkCommandBuffer command_buffer, VkImage target_image, VkFormat image_format, + static void TransitImageLayout(VkCommandBuffer vk_command_buffer, VkImage target_image, VkFormat image_format, uint32_t layer_count, VkImageLayout old_layout, VkImageLayout new_layout, uint32_t mip_levels = 1); @@ -194,8 +207,7 @@ class Graphics final { static size_t GetMaxBoneAmount(); static size_t GetMaxShadowCascadeAmount(); - static void AppendCommands(const std::function& action); - static void ImmediateSubmit(const std::function& action); + static void ImmediateSubmit(const std::function& action); static QueueFamilyIndices GetQueueFamilyIndices(); static int GetMaxFramesInFlight(); static void NotifyRecreateSwapChain(); @@ -205,10 +217,11 @@ class Graphics final { static uint32_t GetCurrentFrameIndex(); static uint32_t GetNextImageIndex(); static VkCommandPool GetVkCommandPool(); - static VkQueue GetGraphicsVkQueue(); - static VkQueue GetPresentVkQueue(); + static const std::unique_ptr& GetMainQueue(); + static const std::unique_ptr& GetImmediateSubmitQueue(); + static const std::unique_ptr& GetPresentQueue(); static VmaAllocator GetVmaAllocator(); - static const std::unique_ptr& GetSwapchain(); + static const std::shared_ptr& GetSwapchain(); static const std::unique_ptr& GetDescriptorPool(); static unsigned GetSwapchainVersion(); static VkSurfaceFormatKHR GetVkSurfaceFormat(); diff --git a/EvoEngine_SDK/include/Rendering/Platform/Shader.hpp b/EvoEngine_SDK/include/Rendering/Platform/Shader.hpp index ff2ebc0..2c75c6f 100644 --- a/EvoEngine_SDK/include/Rendering/Platform/Shader.hpp +++ b/EvoEngine_SDK/include/Rendering/Platform/Shader.hpp @@ -15,7 +15,6 @@ enum class ShaderType { Unknown }; class Shader final : public IAsset { - friend class GraphicsPipeline; std::unique_ptr shader_module_ = {}; std::string code_ = {}; ShaderType shader_type_ = ShaderType::Unknown; @@ -24,5 +23,6 @@ class Shader final : public IAsset { [[nodiscard]] bool Compiled() const; void Set(ShaderType shader_type, const std::string& shader_code); [[nodiscard]] const std::unique_ptr& GetShaderModule() const; + [[nodiscard]] ShaderType GetShaderType() const; }; } // namespace evo_engine diff --git a/EvoEngine_SDK/include/Rendering/Renderer/SkinnedMeshRenderer.hpp b/EvoEngine_SDK/include/Rendering/Renderer/SkinnedMeshRenderer.hpp index face12f..5070b60 100644 --- a/EvoEngine_SDK/include/Rendering/Renderer/SkinnedMeshRenderer.hpp +++ b/EvoEngine_SDK/include/Rendering/Renderer/SkinnedMeshRenderer.hpp @@ -10,7 +10,7 @@ class SkinnedMeshRenderer : public IPrivateComponent { friend class Prefab; friend class RenderLayer; void RenderBound(const std::shared_ptr& editor_layer, glm::vec4& color); - friend class Graphics; + friend class Platform; bool rag_doll_ = false; std::vector rag_doll_transform_chain_; std::vector bound_entities_; diff --git a/EvoEngine_SDK/include/Rendering/Texture/Cubemap.hpp b/EvoEngine_SDK/include/Rendering/Texture/Cubemap.hpp index 8999c79..55342bf 100644 --- a/EvoEngine_SDK/include/Rendering/Texture/Cubemap.hpp +++ b/EvoEngine_SDK/include/Rendering/Texture/Cubemap.hpp @@ -1,5 +1,5 @@ #pragma once -#include "Graphics.hpp" +#include "Platform.hpp" #include "GraphicsResources.hpp" #include "IAsset.hpp" #include "Texture2D.hpp" diff --git a/EvoEngine_SDK/include/Rendering/Texture/RenderTexture.hpp b/EvoEngine_SDK/include/Rendering/Texture/RenderTexture.hpp index b305c72..2c97ca7 100644 --- a/EvoEngine_SDK/include/Rendering/Texture/RenderTexture.hpp +++ b/EvoEngine_SDK/include/Rendering/Texture/RenderTexture.hpp @@ -10,7 +10,7 @@ struct RenderTextureCreateInfo { }; class RenderTexture { - friend class Graphics; + friend class Platform; friend class RenderLayer; friend class Camera; std::shared_ptr color_image_ = {}; @@ -31,7 +31,7 @@ class RenderTexture { std::shared_ptr descriptor_set_; public: - void Clear(VkCommandBuffer command_buffer) const; + void Clear(VkCommandBuffer vk_command_buffer ) const; explicit RenderTexture(const RenderTextureCreateInfo& render_texture_create_info); void Resize(VkExtent3D extent); void AppendColorAttachmentInfos(std::vector& attachment_infos, VkAttachmentLoadOp load_op, @@ -47,8 +47,9 @@ class RenderTexture { [[nodiscard]] const std::shared_ptr& GetDepthImage(); [[nodiscard]] const std::shared_ptr& GetColorImageView(); [[nodiscard]] const std::shared_ptr& GetDepthImageView(); - void BeginRendering(VkCommandBuffer command_buffer, VkAttachmentLoadOp load_op, VkAttachmentStoreOp store_op) const; - void EndRendering(VkCommandBuffer command_buffer) const; + void BeginRendering(VkCommandBuffer vk_command_buffer , VkAttachmentLoadOp load_op, + VkAttachmentStoreOp store_op) const; + void EndRendering(VkCommandBuffer vk_command_buffer ) const; [[nodiscard]] ImTextureID GetColorImTextureId() const; void ApplyGraphicsPipelineStates(GraphicsPipelineStates& global_pipeline_state) const; [[maybe_unused]] bool Save(const std::filesystem::path& path) const; diff --git a/EvoEngine_SDK/include/Rendering/Texture/TextureStorage.hpp b/EvoEngine_SDK/include/Rendering/Texture/TextureStorage.hpp index 7cf5c18..8133df4 100644 --- a/EvoEngine_SDK/include/Rendering/Texture/TextureStorage.hpp +++ b/EvoEngine_SDK/include/Rendering/Texture/TextureStorage.hpp @@ -60,7 +60,7 @@ class TextureStorage final { std::vector cubemaps_; friend class RenderLayer; - friend class Graphics; + friend class Platform; friend class Resources; static void DeviceSync(); diff --git a/EvoEngine_SDK/src/Application.cpp b/EvoEngine_SDK/src/Application.cpp index bffc4d3..20d22a4 100644 --- a/EvoEngine_SDK/src/Application.cpp +++ b/EvoEngine_SDK/src/Application.cpp @@ -5,7 +5,7 @@ #include "Cubemap.hpp" #include "EditorLayer.hpp" #include "EnvironmentalMap.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "Input.hpp" #include "Jobs.hpp" #include "Json.hpp" @@ -96,7 +96,7 @@ void Application::PreUpdateInternal() { application.application_execution_status_ = ApplicationExecutionStatus::PreUpdate; Input::PreUpdate(); - Graphics::PreUpdate(); + Platform::PreUpdate(); if (application.application_status_ == ApplicationStatus::NoProject) return; @@ -239,19 +239,19 @@ void Application::LateUpdateInternal() { } } - Graphics::AppendCommands([&](const VkCommandBuffer command_buffer) { - Graphics::EverythingBarrier(command_buffer); + Platform::RecordCommandsMainQueue([&](const VkCommandBuffer vk_command_buffer) { + Platform::EverythingBarrier(vk_command_buffer); constexpr VkClearValue clear_color = {{{0.0f, 0.0f, 0.0f, 1.0f}}}; VkRect2D render_area; render_area.offset = {0, 0}; - render_area.extent = Graphics::GetSwapchain()->GetImageExtent(); - Graphics::TransitImageLayout(command_buffer, Graphics::GetSwapchain()->GetVkImage(), - Graphics::GetSwapchain()->GetImageFormat(), 1, VK_IMAGE_LAYOUT_UNDEFINED, + render_area.extent = Platform::GetSwapchain()->GetImageExtent(); + Platform::TransitImageLayout(vk_command_buffer, Platform::GetSwapchain()->GetVkImage(), + Platform::GetSwapchain()->GetImageFormat(), 1, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); VkRenderingAttachmentInfo color_attachment_info{}; color_attachment_info.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO; - color_attachment_info.imageView = Graphics::GetSwapchain()->GetVkImageView(); + color_attachment_info.imageView = Platform::GetSwapchain()->GetVkImageView(); color_attachment_info.imageLayout = VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR; color_attachment_info.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; color_attachment_info.storeOp = VK_ATTACHMENT_STORE_OP_STORE; @@ -264,14 +264,14 @@ void Application::LateUpdateInternal() { render_info.colorAttachmentCount = 1; render_info.pColorAttachments = &color_attachment_info; - vkCmdBeginRendering(command_buffer, &render_info); + vkCmdBeginRendering(vk_command_buffer, &render_info); ImGui::Render(); - ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), command_buffer); + ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), vk_command_buffer); - vkCmdEndRendering(command_buffer); - Graphics::TransitImageLayout(command_buffer, Graphics::GetSwapchain()->GetVkImage(), - Graphics::GetSwapchain()->GetImageFormat(), 1, + vkCmdEndRendering(vk_command_buffer); + Platform::TransitImageLayout(vk_command_buffer, Platform::GetSwapchain()->GetVkImage(), + Platform::GetSwapchain()->GetImageFormat(), 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR); }); @@ -299,7 +299,7 @@ void Application::LateUpdateInternal() { if (application.application_status_ == ApplicationStatus::Step) application.application_status_ = ApplicationStatus::Pause; } - Graphics::LateUpdate(); + Platform::LateUpdate(); } const ApplicationInfo& Application::GetApplicationInfo() { @@ -346,9 +346,9 @@ void Application::Initialize(const ApplicationInfo& application_create_info) { Jobs::Initialize(default_thread_size - 2); Entities::Initialize(); TransformGraph::Initialize(); - Graphics::Initialize(); + Platform::Initialize(); Resources::Initialize(); - Graphics::PostResourceLoadingInitialization(); + Platform::PostResourceLoadingInitialization(); Resources::InitializeEnvironmentalMap(); for (const auto& layer : application.layers_) { diff --git a/EvoEngine_SDK/src/Camera.cpp b/EvoEngine_SDK/src/Camera.cpp index 8fcf12f..b861412 100644 --- a/EvoEngine_SDK/src/Camera.cpp +++ b/EvoEngine_SDK/src/Camera.cpp @@ -35,7 +35,7 @@ void Camera::UpdateGBuffer() { image_info.extent = render_texture_->GetExtent(); image_info.mipLevels = 1; image_info.arrayLayers = 1; - image_info.format = Graphics::Constants::g_buffer_color; + image_info.format = Platform::Constants::g_buffer_color; image_info.tiling = VK_IMAGE_TILING_OPTIMAL; image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; image_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | @@ -49,7 +49,7 @@ void Camera::UpdateGBuffer() { view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; view_info.image = g_buffer_normal_->GetVkImage(); view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; - view_info.format = Graphics::Constants::g_buffer_color; + view_info.format = Platform::Constants::g_buffer_color; view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; view_info.subresourceRange.baseMipLevel = 0; view_info.subresourceRange.levelCount = 1; @@ -66,7 +66,7 @@ void Camera::UpdateGBuffer() { sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; sampler_info.anisotropyEnable = VK_TRUE; - sampler_info.maxAnisotropy = Graphics::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; + sampler_info.maxAnisotropy = Platform::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; sampler_info.unnormalizedCoordinates = VK_FALSE; sampler_info.compareEnable = VK_FALSE; @@ -82,7 +82,7 @@ void Camera::UpdateGBuffer() { image_info.extent = render_texture_->GetExtent(); image_info.mipLevels = 1; image_info.arrayLayers = 1; - image_info.format = Graphics::Constants::g_buffer_color; + image_info.format = Platform::Constants::g_buffer_color; image_info.tiling = VK_IMAGE_TILING_OPTIMAL; image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; image_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | @@ -96,7 +96,7 @@ void Camera::UpdateGBuffer() { view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; view_info.image = g_buffer_material_->GetVkImage(); view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; - view_info.format = Graphics::Constants::g_buffer_material; + view_info.format = Platform::Constants::g_buffer_material; view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; view_info.subresourceRange.baseMipLevel = 0; view_info.subresourceRange.levelCount = 1; @@ -113,7 +113,7 @@ void Camera::UpdateGBuffer() { sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; sampler_info.anisotropyEnable = VK_TRUE; - sampler_info.maxAnisotropy = Graphics::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; + sampler_info.maxAnisotropy = Platform::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; sampler_info.unnormalizedCoordinates = VK_FALSE; sampler_info.compareEnable = VK_FALSE; @@ -122,8 +122,8 @@ void Camera::UpdateGBuffer() { g_buffer_material_sampler_ = std::make_unique(sampler_info); } - Graphics::ImmediateSubmit([&](const VkCommandBuffer command_buffer) { - TransitGBufferImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { + TransitGBufferImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); }); EditorLayer::UpdateTextureId(g_buffer_normal_im_texture_id_, g_buffer_normal_sampler_->GetVkSampler(), @@ -146,9 +146,9 @@ void Camera::UpdateGBuffer() { } } -void Camera::TransitGBufferImageLayout(VkCommandBuffer command_buffer, VkImageLayout target_layout) const { - g_buffer_normal_->TransitImageLayout(command_buffer, target_layout); - g_buffer_material_->TransitImageLayout(command_buffer, target_layout); +void Camera::TransitGBufferImageLayout(const VkCommandBuffer vk_command_buffer, VkImageLayout target_layout) const { + g_buffer_normal_->TransitImageLayout(vk_command_buffer, target_layout); + g_buffer_material_->TransitImageLayout(vk_command_buffer, target_layout); } void Camera::UpdateCameraInfoBlock(CameraInfoBlock& camera_info_block, const GlobalTransform& global_transform) { @@ -250,7 +250,7 @@ void Camera::OnCreate() { render_texture_create_info.extent.depth = 1; render_texture_ = std::make_unique(render_texture_create_info); - g_buffer_descriptor_set_ = std::make_shared(Graphics::GetDescriptorSetLayout("CAMERA_GBUFFER_LAYOUT")); + g_buffer_descriptor_set_ = std::make_shared(Platform::GetDescriptorSetLayout("CAMERA_GBUFFER_LAYOUT")); UpdateGBuffer(); } diff --git a/EvoEngine_SDK/src/ComputePipeline.cpp b/EvoEngine_SDK/src/ComputePipeline.cpp new file mode 100644 index 0000000..a8f2fd5 --- /dev/null +++ b/EvoEngine_SDK/src/ComputePipeline.cpp @@ -0,0 +1,56 @@ +#include "ComputePipeline.hpp" +#include "Platform.hpp" +#include "Shader.hpp" +using namespace evo_engine; + +ComputePipeline::~ComputePipeline() { + if (vk_compute_pipeline_ != VK_NULL_HANDLE) { + vkDestroyPipeline(Platform::GetVkDevice(), vk_compute_pipeline_, nullptr); + vk_compute_pipeline_ = nullptr; + } +} + +void ComputePipeline::Initialize() { + std::vector set_layouts = {}; + set_layouts.reserve(descriptor_set_layouts.size()); + for (const auto& i : descriptor_set_layouts) { + set_layouts.push_back(i->GetVkDescriptorSetLayout()); + } + VkPipelineLayoutCreateInfo pipeline_layout_info{}; + pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_info.setLayoutCount = set_layouts.size(); + pipeline_layout_info.pSetLayouts = set_layouts.data(); + pipeline_layout_info.pushConstantRangeCount = push_constant_ranges.size(); + pipeline_layout_info.pPushConstantRanges = push_constant_ranges.data(); + + pipeline_layout_ = std::make_unique(pipeline_layout_info); + + VkPipelineShaderStageCreateInfo shader_stage_create_info; + shader_stage_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stage_create_info.stage = VK_SHADER_STAGE_VERTEX_BIT; + shader_stage_create_info.module = compute_shader->GetShaderModule()->GetVkShaderModule(); + shader_stage_create_info.pName = "main"; + shader_stage_create_info.flags = 0; + shader_stage_create_info.pNext = nullptr; + + VkComputePipelineCreateInfo pipeline_info{}; + pipeline_info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; + pipeline_info.layout = pipeline_layout_->GetVkPipelineLayout(); + pipeline_info.stage = shader_stage_create_info; + Platform::CheckVk(vkCreateComputePipelines(Platform::GetVkDevice(), VK_NULL_HANDLE, 1, &pipeline_info, nullptr, + &vk_compute_pipeline_)); +} + +bool ComputePipeline::Initialized() const { + return vk_compute_pipeline_ != VK_NULL_HANDLE; +} + +void ComputePipeline::Bind(const CommandBuffer& command_buffer) const { + vkCmdBindPipeline(command_buffer.GetVkCommandBuffer(), VK_PIPELINE_BIND_POINT_COMPUTE, vk_compute_pipeline_); +} + +void ComputePipeline::BindDescriptorSet(const CommandBuffer& command_buffer, const uint32_t first_set, + const VkDescriptorSet descriptor_set) const { + vkCmdBindDescriptorSets(command_buffer.GetVkCommandBuffer(), VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_layout_->GetVkPipelineLayout(), + first_set, 1, &descriptor_set, 0, nullptr); +} \ No newline at end of file diff --git a/EvoEngine_SDK/src/Cubemap.cpp b/EvoEngine_SDK/src/Cubemap.cpp index 77bdd17..4af6720 100644 --- a/EvoEngine_SDK/src/Cubemap.cpp +++ b/EvoEngine_SDK/src/Cubemap.cpp @@ -2,7 +2,7 @@ #include "Application.hpp" #include "Console.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "RenderLayer.hpp" #include "Resources.hpp" #include "TextureStorage.hpp" @@ -49,7 +49,7 @@ void Cubemap::ConvertFromEquirectangularTexture(const std::shared_ptr depth_image_info.extent.depth = 1; depth_image_info.mipLevels = 1; depth_image_info.arrayLayers = 1; - depth_image_info.format = Graphics::Constants::shadow_map; + depth_image_info.format = Platform::Constants::shadow_map; depth_image_info.tiling = VK_IMAGE_TILING_OPTIMAL; depth_image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; depth_image_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; @@ -57,15 +57,15 @@ void Cubemap::ConvertFromEquirectangularTexture(const std::shared_ptr depth_image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; const auto depth_image = std::make_shared(depth_image_info); - Graphics::ImmediateSubmit([&](const VkCommandBuffer command_buffer) { - depth_image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { + depth_image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); }); VkImageViewCreateInfo depth_view_info{}; depth_view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; depth_view_info.image = depth_image->GetVkImage(); depth_view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; - depth_view_info.format = Graphics::Constants::shadow_map; + depth_view_info.format = Platform::Constants::shadow_map; depth_view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; depth_view_info.subresourceRange.baseMipLevel = 0; depth_view_info.subresourceRange.levelCount = 1; @@ -75,7 +75,7 @@ void Cubemap::ConvertFromEquirectangularTexture(const std::shared_ptr #pragma endregion const std::unique_ptr temp_set = - std::make_unique(Graphics::GetDescriptorSetLayout("RENDER_TEXTURE_PRESENT_LAYOUT")); + std::make_unique(Platform::GetDescriptorSetLayout("RENDER_TEXTURE_PRESENT_LAYOUT")); VkDescriptorImageInfo descriptor_image_info{}; descriptor_image_info.imageView = target_texture->GetVkImageView(); descriptor_image_info.imageLayout = target_texture->GetLayout(); @@ -92,9 +92,9 @@ void Cubemap::ConvertFromEquirectangularTexture(const std::shared_ptr glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f)), glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f))}; - const auto equirectangular_to_cubemap = Graphics::GetGraphicsPipeline("EQUIRECTANGULAR_TO_CUBEMAP"); - Graphics::ImmediateSubmit([&](VkCommandBuffer command_buffer) { - storage.image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + const auto equirectangular_to_cubemap = Platform::GetGraphicsPipeline("EQUIRECTANGULAR_TO_CUBEMAP"); + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { + storage.image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); #pragma region Viewport and scissor VkRect2D render_area; render_area.offset = {0, 0}; @@ -152,21 +152,21 @@ void Cubemap::ConvertFromEquirectangularTexture(const std::shared_ptr VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; i.blendEnable = VK_FALSE; } - vkCmdBeginRendering(command_buffer, &render_info); - equirectangular_to_cubemap->Bind(command_buffer); - equirectangular_to_cubemap->BindDescriptorSet(command_buffer, 0, temp_set->GetVkDescriptorSet()); + vkCmdBeginRendering(vk_command_buffer, &render_info); + equirectangular_to_cubemap->Bind(vk_command_buffer); + equirectangular_to_cubemap->BindDescriptorSet(vk_command_buffer, 0, temp_set->GetVkDescriptorSet()); const auto mesh = Resources::GetResource("PRIMITIVE_RENDERING_CUBE"); - GeometryStorage::BindVertices(command_buffer); + GeometryStorage::BindVertices(vk_command_buffer); EquirectangularToCubemapConstant constant{}; constant.projection_view = capture_projection * capture_views[i]; - equirectangular_to_cubemap->PushConstant(command_buffer, 0, constant); - mesh->DrawIndexed(command_buffer, equirectangular_to_cubemap->states, 1); - vkCmdEndRendering(command_buffer); + equirectangular_to_cubemap->PushConstant(vk_command_buffer, 0, constant); + mesh->DrawIndexed(vk_command_buffer, equirectangular_to_cubemap->states, 1); + vkCmdEndRendering(vk_command_buffer); #pragma endregion - Graphics::EverythingBarrier(command_buffer); + Platform::EverythingBarrier(vk_command_buffer); } - storage.image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + storage.image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); }); } bool Cubemap::OnInspect(const std::shared_ptr& editor_layer) { diff --git a/EvoEngine_SDK/src/DescriptorLayoutsRegistry.cpp b/EvoEngine_SDK/src/DescriptorLayoutsRegistry.cpp index 0d0fbe2..5cc377c 100644 --- a/EvoEngine_SDK/src/DescriptorLayoutsRegistry.cpp +++ b/EvoEngine_SDK/src/DescriptorLayoutsRegistry.cpp @@ -1,8 +1,8 @@ -#include "Graphics.hpp" +#include "Platform.hpp" #include "Utilities.hpp" using namespace evo_engine; -void Graphics::PrepareDescriptorSetLayouts() { +void Platform::PrepareDescriptorSetLayouts() { const auto render_texture_present = std::make_shared(); render_texture_present->PushDescriptorBinding(0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 0); diff --git a/EvoEngine_SDK/src/EditorLayer.cpp b/EvoEngine_SDK/src/EditorLayer.cpp index ec5aca1..0a0d4a9 100644 --- a/EvoEngine_SDK/src/EditorLayer.cpp +++ b/EvoEngine_SDK/src/EditorLayer.cpp @@ -2,7 +2,7 @@ #include "Application.hpp" #include "Cubemap.hpp" #include "EnvironmentalMap.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "ILayer.hpp" #include "Material.hpp" #include "Mesh.hpp" @@ -109,7 +109,7 @@ void EditorLayer::OnCreate() { entity_index_read_buffer_create_info.usage = VMA_MEMORY_USAGE_AUTO; entity_index_read_buffer_create_info.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT; entity_index_read_buffer_ = std::make_unique(entity_index_read_buffer, entity_index_read_buffer_create_info); - vmaMapMemory(Graphics::GetVmaAllocator(), entity_index_read_buffer_->GetVmaAllocation(), + vmaMapMemory(Platform::GetVmaAllocator(), entity_index_read_buffer_->GetVmaAllocation(), static_cast(static_cast(&mapped_entity_index_data_))); const auto scene_camera = Serialization::ProduceSerializable(); @@ -631,20 +631,20 @@ void EditorLayer::LateUpdate() { } } - Graphics::AppendCommands([&](const VkCommandBuffer command_buffer) { - Graphics::EverythingBarrier(command_buffer); - Graphics::TransitImageLayout(command_buffer, Graphics::GetSwapchain()->GetVkImage(), - Graphics::GetSwapchain()->GetImageFormat(), 1, VK_IMAGE_LAYOUT_UNDEFINED, + Platform::RecordCommandsMainQueue([&](const VkCommandBuffer vk_command_buffer) { + Platform::EverythingBarrier(vk_command_buffer); + Platform::TransitImageLayout(vk_command_buffer, Platform::GetSwapchain()->GetVkImage(), + Platform::GetSwapchain()->GetImageFormat(), 1, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR); constexpr VkClearValue clear_color = {{{0.0f, 0.0f, 0.0f, 1.0f}}}; VkRect2D render_area; render_area.offset = {0, 0}; - render_area.extent = Graphics::GetSwapchain()->GetImageExtent(); + render_area.extent = Platform::GetSwapchain()->GetImageExtent(); VkRenderingAttachmentInfo color_attachment_info{}; color_attachment_info.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO; - color_attachment_info.imageView = Graphics::GetSwapchain()->GetVkImageView(); + color_attachment_info.imageView = Platform::GetSwapchain()->GetVkImageView(); color_attachment_info.imageLayout = VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR; color_attachment_info.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; color_attachment_info.storeOp = VK_ATTACHMENT_STORE_OP_STORE; @@ -657,13 +657,13 @@ void EditorLayer::LateUpdate() { render_info.colorAttachmentCount = 1; render_info.pColorAttachments = &color_attachment_info; - vkCmdBeginRendering(command_buffer, &render_info); + vkCmdBeginRendering(vk_command_buffer, &render_info); ImGui::Render(); - ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), command_buffer); + ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), vk_command_buffer); - vkCmdEndRendering(command_buffer); - Graphics::TransitImageLayout(command_buffer, Graphics::GetSwapchain()->GetVkImage(), - Graphics::GetSwapchain()->GetImageFormat(), 1, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR, + vkCmdEndRendering(vk_command_buffer); + Platform::TransitImageLayout(vk_command_buffer, Platform::GetSwapchain()->GetVkImage(), + Platform::GetSwapchain()->GetImageFormat(), 1, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR); }); } @@ -757,7 +757,7 @@ void EditorLayer::InspectComponentData(const Entity entity, IDataComponent* data void EditorLayer::SceneCameraWindow() { const auto scene = GetScene(); auto window_layer = Application::GetLayer(); - const auto& graphics = Graphics::GetInstance(); + const auto& graphics = Platform::GetInstance(); auto& [sceneCameraRotation, sceneCameraPosition, sceneCamera] = editor_cameras_.at(scene_camera_handle_); #pragma region Scene Window ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{0, 0}); @@ -794,7 +794,7 @@ void EditorLayer::SceneCameraWindow() { ImGui::Text("Info & Settings"); ImGui::Text("%.1f FPS", ImGui::GetIO().Framerate); std::string draw_call_info = {}; - const auto current_frame_index = Graphics::GetCurrentFrameIndex(); + const auto current_frame_index = Platform::GetCurrentFrameIndex(); if (graphics.triangles[current_frame_index] < 999) draw_call_info += std::to_string(graphics.triangles[current_frame_index]); else if (graphics.triangles[current_frame_index] < 999999) @@ -955,7 +955,7 @@ void EditorLayer::SceneCameraWindow() { void EditorLayer::MainCameraWindow() { if (const auto render_layer = Application::GetLayer(); !render_layer) return; - const auto& graphics = Graphics::GetInstance(); + const auto& graphics = Platform::GetInstance(); const auto scene = GetScene(); #pragma region Window ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{0, 0}); @@ -999,7 +999,7 @@ void EditorLayer::MainCameraWindow() { } ImGui::PopItemWidth(); std::string draw_call_info = {}; - const auto current_frame_index = Graphics::GetCurrentFrameIndex(); + const auto current_frame_index = Platform::GetCurrentFrameIndex(); if (graphics.triangles[current_frame_index] < 999) draw_call_info += std::to_string(graphics.triangles[current_frame_index]); else if (graphics.triangles[current_frame_index] < 999999) diff --git a/EvoEngine_SDK/src/GeometryStorage.cpp b/EvoEngine_SDK/src/GeometryStorage.cpp index ae564d1..0e17de1 100644 --- a/EvoEngine_SDK/src/GeometryStorage.cpp +++ b/EvoEngine_SDK/src/GeometryStorage.cpp @@ -147,43 +147,43 @@ const std::unique_ptr& GeometryStorage::GetStrandMeshletBuffer() { return storage.strand_meshlet_buffer_; } -void GeometryStorage::BindVertices(const VkCommandBuffer command_buffer) { +void GeometryStorage::BindVertices(const VkCommandBuffer vk_command_buffer) { const auto& storage = GetInstance(); constexpr VkDeviceSize offsets[1] = {}; - vkCmdBindVertexBuffers(command_buffer, 0, 1, &storage.vertex_buffer_->GetVkBuffer(), offsets); - vkCmdBindIndexBuffer(command_buffer, storage.triangle_buffer_->GetVkBuffer(), 0, VK_INDEX_TYPE_UINT32); + vkCmdBindVertexBuffers(vk_command_buffer, 0, 1, &storage.vertex_buffer_->GetVkBuffer(), offsets); + vkCmdBindIndexBuffer(vk_command_buffer, storage.triangle_buffer_->GetVkBuffer(), 0, VK_INDEX_TYPE_UINT32); } -void GeometryStorage::BindSkinnedVertices(const VkCommandBuffer command_buffer) { +void GeometryStorage::BindSkinnedVertices(const VkCommandBuffer vk_command_buffer) { const auto& storage = GetInstance(); constexpr VkDeviceSize offsets[1] = {}; - vkCmdBindVertexBuffers(command_buffer, 0, 1, &storage.skinned_vertex_buffer_->GetVkBuffer(), offsets); - vkCmdBindIndexBuffer(command_buffer, storage.skinned_triangle_buffer_->GetVkBuffer(), 0, VK_INDEX_TYPE_UINT32); + vkCmdBindVertexBuffers(vk_command_buffer, 0, 1, &storage.skinned_vertex_buffer_->GetVkBuffer(), offsets); + vkCmdBindIndexBuffer(vk_command_buffer, storage.skinned_triangle_buffer_->GetVkBuffer(), 0, VK_INDEX_TYPE_UINT32); } -void GeometryStorage::BindStrandPoints(const VkCommandBuffer command_buffer) { +void GeometryStorage::BindStrandPoints(const VkCommandBuffer vk_command_buffer) { const auto& storage = GetInstance(); constexpr VkDeviceSize offsets[1] = {}; - vkCmdBindVertexBuffers(command_buffer, 0, 1, &storage.strand_point_buffer_->GetVkBuffer(), offsets); - vkCmdBindIndexBuffer(command_buffer, storage.segment_buffer_->GetVkBuffer(), 0, VK_INDEX_TYPE_UINT32); + vkCmdBindVertexBuffers(vk_command_buffer, 0, 1, &storage.strand_point_buffer_->GetVkBuffer(), offsets); + vkCmdBindIndexBuffer(vk_command_buffer, storage.segment_buffer_->GetVkBuffer(), 0, VK_INDEX_TYPE_UINT32); } const Vertex& GeometryStorage::PeekVertex(const size_t vertex_index) { const auto& storage = GetInstance(); - return storage.vertex_data_chunks_[vertex_index / Graphics::Constants::meshlet_max_vertices_size] - .vertex_data[vertex_index % Graphics::Constants::meshlet_max_vertices_size]; + return storage.vertex_data_chunks_[vertex_index / Platform::Constants::meshlet_max_vertices_size] + .vertex_data[vertex_index % Platform::Constants::meshlet_max_vertices_size]; } const SkinnedVertex& GeometryStorage::PeekSkinnedVertex(const size_t skinned_vertex_index) { const auto& storage = GetInstance(); - return storage.skinned_vertex_data_chunks_[skinned_vertex_index / Graphics::Constants::meshlet_max_vertices_size] - .skinned_vertex_data[skinned_vertex_index % Graphics::Constants::meshlet_max_vertices_size]; + return storage.skinned_vertex_data_chunks_[skinned_vertex_index / Platform::Constants::meshlet_max_vertices_size] + .skinned_vertex_data[skinned_vertex_index % Platform::Constants::meshlet_max_vertices_size]; } const StrandPoint& GeometryStorage::PeekStrandPoint(const size_t strand_point_index) { const auto& storage = GetInstance(); - return storage.strand_point_data_chunks_[strand_point_index / Graphics::Constants::meshlet_max_vertices_size] - .strand_point_data[strand_point_index % Graphics::Constants::meshlet_max_vertices_size]; + return storage.strand_point_data_chunks_[strand_point_index / Platform::Constants::meshlet_max_vertices_size] + .strand_point_data[strand_point_index % Platform::Constants::meshlet_max_vertices_size]; } void GeometryStorage::AllocateMesh(const Handle& handle, const std::vector& vertices, @@ -210,15 +210,15 @@ void GeometryStorage::AllocateMesh(const Handle& handle, const std::vector meshlet_result_vertices; std::vector meshlet_result_triangles; const auto max_meshlets = - meshopt_buildMeshletsBound(triangles.size() * 3, Graphics::Constants::meshlet_max_vertices_size, - Graphics::Constants::meshlet_max_triangles_size); + meshopt_buildMeshletsBound(triangles.size() * 3, Platform::Constants::meshlet_max_vertices_size, + Platform::Constants::meshlet_max_triangles_size); meshlets_results.resize(max_meshlets); - meshlet_result_vertices.resize(max_meshlets * Graphics::Constants::meshlet_max_vertices_size); - meshlet_result_triangles.resize(max_meshlets * Graphics::Constants::meshlet_max_triangles_size * 3); + meshlet_result_vertices.resize(max_meshlets * Platform::Constants::meshlet_max_vertices_size); + meshlet_result_triangles.resize(max_meshlets * Platform::Constants::meshlet_max_triangles_size * 3); const auto meshlet_size = meshopt_buildMeshlets( meshlets_results.data(), meshlet_result_vertices.data(), meshlet_result_triangles.data(), &triangles.at(0).x, triangles.size() * 3, &vertices.at(0).position.x, vertices.size(), sizeof(Vertex), - Graphics::Constants::meshlet_max_vertices_size, Graphics::Constants::meshlet_max_triangles_size, 0); + Platform::Constants::meshlet_max_vertices_size, Platform::Constants::meshlet_max_triangles_size, 0); target_meshlet_range->range = meshlet_size; for (size_t meshlet_index = 0; meshlet_index < meshlet_size; meshlet_index++) { @@ -244,11 +244,11 @@ void GeometryStorage::AllocateMesh(const Handle& handle, const std::vectorrange += current_meshlet.triangle_size; } @@ -279,16 +279,16 @@ void GeometryStorage::AllocateSkinnedMesh(const Handle& handle, const std::vecto std::vector skinned_meshlet_result_vertices{}; std::vector skinned_meshlet_result_triangles{}; const auto max_meshlets = - meshopt_buildMeshletsBound(skinned_triangles.size() * 3, Graphics::Constants::meshlet_max_vertices_size, - Graphics::Constants::meshlet_max_triangles_size); + meshopt_buildMeshletsBound(skinned_triangles.size() * 3, Platform::Constants::meshlet_max_vertices_size, + Platform::Constants::meshlet_max_triangles_size); skinned_meshlets_results.resize(max_meshlets); - skinned_meshlet_result_vertices.resize(max_meshlets * Graphics::Constants::meshlet_max_vertices_size); - skinned_meshlet_result_triangles.resize(max_meshlets * Graphics::Constants::meshlet_max_triangles_size * 3); + skinned_meshlet_result_vertices.resize(max_meshlets * Platform::Constants::meshlet_max_vertices_size); + skinned_meshlet_result_triangles.resize(max_meshlets * Platform::Constants::meshlet_max_triangles_size * 3); const auto skinned_meshlet_size = meshopt_buildMeshlets( skinned_meshlets_results.data(), skinned_meshlet_result_vertices.data(), skinned_meshlet_result_triangles.data(), &skinned_triangles.at(0).x, skinned_triangles.size() * 3, &skinned_vertices.at(0).position.x, - skinned_vertices.size(), sizeof(SkinnedVertex), Graphics::Constants::meshlet_max_vertices_size, - Graphics::Constants::meshlet_max_triangles_size, 0); + skinned_vertices.size(), sizeof(SkinnedVertex), Platform::Constants::meshlet_max_vertices_size, + Platform::Constants::meshlet_max_triangles_size, 0); target_skinned_meshlet_range->range = skinned_meshlet_size; for (size_t skinned_meshlet_index = 0; skinned_meshlet_index < skinned_meshlet_size; skinned_meshlet_index++) { @@ -316,11 +316,11 @@ void GeometryStorage::AllocateSkinnedMesh(const Handle& handle, const std::vecto storage.skinned_triangles_.emplace_back(); auto& global_triangle = storage.skinned_triangles_.back(); global_triangle.x = current_meshlet_triangle.x + current_skinned_meshlet.skinned_vertex_chunk_index * - Graphics::Constants::meshlet_max_vertices_size; + Platform::Constants::meshlet_max_vertices_size; global_triangle.y = current_meshlet_triangle.y + current_skinned_meshlet.skinned_vertex_chunk_index * - Graphics::Constants::meshlet_max_vertices_size; + Platform::Constants::meshlet_max_vertices_size; global_triangle.z = current_meshlet_triangle.z + current_skinned_meshlet.skinned_vertex_chunk_index * - Graphics::Constants::meshlet_max_vertices_size; + Platform::Constants::meshlet_max_vertices_size; } target_skinned_triangle_range->range += current_skinned_meshlet.skinned_triangle_size; } @@ -361,7 +361,7 @@ void GeometryStorage::AllocateStrands(const Handle& handle, const std::vector assigned_strand_points{}; - while (current_strand_meshlet.segment_size < Graphics::Constants::meshlet_max_triangles_size && + while (current_strand_meshlet.segment_size < Platform::Constants::meshlet_max_triangles_size && current_segment_index < segments.size()) { const auto& current_segment = segments[current_segment_index]; uint32_t new_strand_points_amount = 0; @@ -382,7 +382,7 @@ void GeometryStorage::AllocateStrands(const Handle& handle, const std::vector - Graphics::Constants::meshlet_max_vertices_size) { + Platform::Constants::meshlet_max_vertices_size) { break; } auto& current_strand_meshlet_segment = current_strand_meshlet.segments[current_strand_meshlet.segment_size]; @@ -442,13 +442,13 @@ void GeometryStorage::AllocateStrands(const Handle& handle, const std::vectorrange++; } } @@ -506,9 +506,9 @@ void GeometryStorage::FreeMesh(const Handle& handle) { } for (uint32_t i = triangle_range_descriptor->offset; i < storage.triangles_.size(); i++) { - storage.triangles_[i].x -= remove_chunk_size * Graphics::Constants::meshlet_max_vertices_size; - storage.triangles_[i].y -= remove_chunk_size * Graphics::Constants::meshlet_max_vertices_size; - storage.triangles_[i].z -= remove_chunk_size * Graphics::Constants::meshlet_max_vertices_size; + storage.triangles_[i].x -= remove_chunk_size * Platform::Constants::meshlet_max_vertices_size; + storage.triangles_[i].y -= remove_chunk_size * Platform::Constants::meshlet_max_vertices_size; + storage.triangles_[i].z -= remove_chunk_size * Platform::Constants::meshlet_max_vertices_size; } storage.triangle_range_descriptor_.erase(storage.triangle_range_descriptor_.begin() + triangle_range_descriptor_index); @@ -530,8 +530,9 @@ void GeometryStorage::FreeSkinnedMesh(const Handle& handle) { const auto& skinned_meshlet_range_descriptor = storage.skinned_meshlet_range_descriptor_[skinned_meshlet_range_descriptor_index]; const uint32_t remove_chunk_size = skinned_meshlet_range_descriptor->range; - storage.skinned_meshlets_.erase(storage.skinned_meshlets_.begin() + skinned_meshlet_range_descriptor->offset, - storage.skinned_meshlets_.begin() + skinned_meshlet_range_descriptor->offset + remove_chunk_size); + storage.skinned_meshlets_.erase( + storage.skinned_meshlets_.begin() + skinned_meshlet_range_descriptor->offset, + storage.skinned_meshlets_.begin() + skinned_meshlet_range_descriptor->offset + remove_chunk_size); storage.skinned_vertex_data_chunks_.erase( storage.skinned_vertex_data_chunks_.begin() + skinned_meshlet_range_descriptor->offset, storage.skinned_vertex_data_chunks_.begin() + skinned_meshlet_range_descriptor->offset + remove_chunk_size); @@ -568,9 +569,9 @@ void GeometryStorage::FreeSkinnedMesh(const Handle& handle) { } for (uint32_t i = skinned_triangle_range_descriptor->offset; i < storage.skinned_triangles_.size(); i++) { - storage.skinned_triangles_[i].x -= remove_chunk_size * Graphics::Constants::meshlet_max_vertices_size; - storage.skinned_triangles_[i].y -= remove_chunk_size * Graphics::Constants::meshlet_max_vertices_size; - storage.skinned_triangles_[i].z -= remove_chunk_size * Graphics::Constants::meshlet_max_vertices_size; + storage.skinned_triangles_[i].x -= remove_chunk_size * Platform::Constants::meshlet_max_vertices_size; + storage.skinned_triangles_[i].y -= remove_chunk_size * Platform::Constants::meshlet_max_vertices_size; + storage.skinned_triangles_[i].z -= remove_chunk_size * Platform::Constants::meshlet_max_vertices_size; } storage.skinned_triangle_range_descriptor_.erase(storage.skinned_triangle_range_descriptor_.begin() + @@ -630,10 +631,10 @@ void GeometryStorage::FreeStrands(const Handle& handle) { } for (uint32_t i = segment_range_descriptor->offset; i < storage.segments_.size(); i++) { - storage.segments_[i].x -= remove_chunk_size * Graphics::Constants::meshlet_max_vertices_size; - storage.segments_[i].y -= remove_chunk_size * Graphics::Constants::meshlet_max_vertices_size; - storage.segments_[i].z -= remove_chunk_size * Graphics::Constants::meshlet_max_vertices_size; - storage.segments_[i].w -= remove_chunk_size * Graphics::Constants::meshlet_max_vertices_size; + storage.segments_[i].x -= remove_chunk_size * Platform::Constants::meshlet_max_vertices_size; + storage.segments_[i].y -= remove_chunk_size * Platform::Constants::meshlet_max_vertices_size; + storage.segments_[i].z -= remove_chunk_size * Platform::Constants::meshlet_max_vertices_size; + storage.segments_[i].w -= remove_chunk_size * Platform::Constants::meshlet_max_vertices_size; } storage.segment_range_descriptor_.erase(storage.segment_range_descriptor_.begin() + segment_range_descriptor_index); @@ -656,7 +657,7 @@ void GeometryStorage::AllocateParticleInfo(const Handle& handle, VmaAllocationCreateInfo buffer_vma_allocation_create_info{}; buffer_vma_allocation_create_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE; info_data.m_buffer = std::make_shared(buffer_create_info, buffer_vma_allocation_create_info); - info_data.descriptor_set = std::make_shared(Graphics::GetDescriptorSetLayout("INSTANCED_DATA_LAYOUT")); + info_data.descriptor_set = std::make_shared(Platform::GetDescriptorSetLayout("INSTANCED_DATA_LAYOUT")); info_data.m_status = ParticleInfoListDataStatus::UpdatePending; } diff --git a/EvoEngine_SDK/src/GraphicsPipeline.cpp b/EvoEngine_SDK/src/GraphicsPipeline.cpp index 97b8648..d7feeba 100644 --- a/EvoEngine_SDK/src/GraphicsPipeline.cpp +++ b/EvoEngine_SDK/src/GraphicsPipeline.cpp @@ -2,17 +2,18 @@ #include "Application.hpp" #include "Console.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "RenderLayer.hpp" #include "Shader.hpp" #include "Utilities.hpp" using namespace evo_engine; -void GraphicsPipeline::PreparePipeline() { +void GraphicsPipeline::Initialize() { const auto render_layer = Application::GetLayer(); std::vector set_layouts = {}; + set_layouts.reserve(descriptor_set_layouts.size()); for (const auto& i : descriptor_set_layouts) { set_layouts.push_back(i->GetVkDescriptorSetLayout()); } @@ -32,64 +33,64 @@ void GraphicsPipeline::PreparePipeline() { input_assembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; input_assembly.primitiveRestartEnable = VK_FALSE; - if (vertex_shader && vertex_shader->shader_type_ == ShaderType::Vertex && vertex_shader->Compiled()) { + if (vertex_shader && vertex_shader->GetShaderType() == ShaderType::Vertex && vertex_shader->Compiled()) { VkPipelineShaderStageCreateInfo vert_shader_stage_info{}; vert_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; vert_shader_stage_info.stage = VK_SHADER_STAGE_VERTEX_BIT; - vert_shader_stage_info.module = vertex_shader->shader_module_->GetVkShaderModule(); + vert_shader_stage_info.module = vertex_shader->GetShaderModule()->GetVkShaderModule(); vert_shader_stage_info.pName = "main"; shader_stages.emplace_back(vert_shader_stage_info); } - if (tessellation_control_shader && tessellation_control_shader->shader_type_ == ShaderType::TessellationControl && + if (tessellation_control_shader && tessellation_control_shader->GetShaderType() == ShaderType::TessellationControl && tessellation_control_shader->Compiled()) { VkPipelineShaderStageCreateInfo tess_control_shader_stage_info{}; tess_control_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; tess_control_shader_stage_info.stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; - tess_control_shader_stage_info.module = tessellation_control_shader->shader_module_->GetVkShaderModule(); + tess_control_shader_stage_info.module = tessellation_control_shader->GetShaderModule()->GetVkShaderModule(); tess_control_shader_stage_info.pName = "main"; shader_stages.emplace_back(tess_control_shader_stage_info); input_assembly.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; } if (tessellation_evaluation_shader && - tessellation_evaluation_shader->shader_type_ == ShaderType::TessellationEvaluation && + tessellation_evaluation_shader->GetShaderType() == ShaderType::TessellationEvaluation && tessellation_evaluation_shader->Compiled()) { VkPipelineShaderStageCreateInfo tess_evaluation_shader_stage_info{}; tess_evaluation_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; tess_evaluation_shader_stage_info.stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; - tess_evaluation_shader_stage_info.module = tessellation_evaluation_shader->shader_module_->GetVkShaderModule(); + tess_evaluation_shader_stage_info.module = tessellation_evaluation_shader->GetShaderModule()->GetVkShaderModule(); tess_evaluation_shader_stage_info.pName = "main"; shader_stages.emplace_back(tess_evaluation_shader_stage_info); input_assembly.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; } - if (geometry_shader && geometry_shader->shader_type_ == ShaderType::Geometry && geometry_shader->Compiled()) { + if (geometry_shader && geometry_shader->GetShaderType() == ShaderType::Geometry && geometry_shader->Compiled()) { VkPipelineShaderStageCreateInfo geometry_shader_stage_info{}; geometry_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; geometry_shader_stage_info.stage = VK_SHADER_STAGE_GEOMETRY_BIT; - geometry_shader_stage_info.module = geometry_shader->shader_module_->GetVkShaderModule(); + geometry_shader_stage_info.module = geometry_shader->GetShaderModule()->GetVkShaderModule(); geometry_shader_stage_info.pName = "main"; shader_stages.emplace_back(geometry_shader_stage_info); } - if (task_shader && task_shader->shader_type_ == ShaderType::Task && task_shader->Compiled()) { + if (task_shader && task_shader->GetShaderType() == ShaderType::Task && task_shader->Compiled()) { VkPipelineShaderStageCreateInfo task_shader_stage_info{}; task_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; task_shader_stage_info.stage = VK_SHADER_STAGE_TASK_BIT_EXT; - task_shader_stage_info.module = task_shader->shader_module_->GetVkShaderModule(); + task_shader_stage_info.module = task_shader->GetShaderModule()->GetVkShaderModule(); task_shader_stage_info.pName = "main"; shader_stages.emplace_back(task_shader_stage_info); } - if (mesh_shader && mesh_shader->shader_type_ == ShaderType::Mesh && mesh_shader->Compiled()) { + if (mesh_shader && mesh_shader->GetShaderType() == ShaderType::Mesh && mesh_shader->Compiled()) { VkPipelineShaderStageCreateInfo mesh_shader_stage_info{}; mesh_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; mesh_shader_stage_info.stage = VK_SHADER_STAGE_MESH_BIT_EXT; - mesh_shader_stage_info.module = mesh_shader->shader_module_->GetVkShaderModule(); + mesh_shader_stage_info.module = mesh_shader->GetShaderModule()->GetVkShaderModule(); mesh_shader_stage_info.pName = "main"; shader_stages.emplace_back(mesh_shader_stage_info); } - if (fragment_shader && fragment_shader->shader_type_ == ShaderType::Fragment && fragment_shader->Compiled()) { + if (fragment_shader && fragment_shader->GetShaderType() == ShaderType::Fragment && fragment_shader->Compiled()) { VkPipelineShaderStageCreateInfo fragment_shader_stage_info{}; fragment_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; fragment_shader_stage_info.stage = VK_SHADER_STAGE_FRAGMENT_BIT; - fragment_shader_stage_info.module = fragment_shader->shader_module_->GetVkShaderModule(); + fragment_shader_stage_info.module = fragment_shader->GetShaderModule()->GetVkShaderModule(); fragment_shader_stage_info.pName = "main"; shader_stages.emplace_back(fragment_shader_stage_info); } @@ -151,31 +152,31 @@ void GraphicsPipeline::PreparePipeline() { depth_stencil.depthBoundsTestEnable = VK_FALSE; depth_stencil.stencilTestEnable = VK_FALSE; std::vector dynamic_states = {VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR, - - VK_DYNAMIC_STATE_DEPTH_CLAMP_ENABLE_EXT, - VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE, - VK_DYNAMIC_STATE_POLYGON_MODE_EXT, - VK_DYNAMIC_STATE_CULL_MODE, - VK_DYNAMIC_STATE_FRONT_FACE, - VK_DYNAMIC_STATE_DEPTH_BIAS_ENABLE, - VK_DYNAMIC_STATE_DEPTH_BIAS, - VK_DYNAMIC_STATE_LINE_WIDTH, - - VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE, - VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE, - VK_DYNAMIC_STATE_DEPTH_COMPARE_OP, - VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE, - VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE, - VK_DYNAMIC_STATE_STENCIL_OP, - VK_DYNAMIC_STATE_DEPTH_BOUNDS, - - VK_DYNAMIC_STATE_LOGIC_OP_ENABLE_EXT, - VK_DYNAMIC_STATE_LOGIC_OP_EXT, - VK_DYNAMIC_STATE_COLOR_BLEND_ENABLE_EXT, - VK_DYNAMIC_STATE_COLOR_BLEND_EQUATION_EXT, - VK_DYNAMIC_STATE_COLOR_WRITE_MASK_EXT, - VK_DYNAMIC_STATE_BLEND_CONSTANTS}; + VK_DYNAMIC_STATE_SCISSOR, + + VK_DYNAMIC_STATE_DEPTH_CLAMP_ENABLE_EXT, + VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE, + VK_DYNAMIC_STATE_POLYGON_MODE_EXT, + VK_DYNAMIC_STATE_CULL_MODE, + VK_DYNAMIC_STATE_FRONT_FACE, + VK_DYNAMIC_STATE_DEPTH_BIAS_ENABLE, + VK_DYNAMIC_STATE_DEPTH_BIAS, + VK_DYNAMIC_STATE_LINE_WIDTH, + + VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE, + VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE, + VK_DYNAMIC_STATE_DEPTH_COMPARE_OP, + VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE, + VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE, + VK_DYNAMIC_STATE_STENCIL_OP, + VK_DYNAMIC_STATE_DEPTH_BOUNDS, + + VK_DYNAMIC_STATE_LOGIC_OP_ENABLE_EXT, + VK_DYNAMIC_STATE_LOGIC_OP_EXT, + VK_DYNAMIC_STATE_COLOR_BLEND_ENABLE_EXT, + VK_DYNAMIC_STATE_COLOR_BLEND_EQUATION_EXT, + VK_DYNAMIC_STATE_COLOR_WRITE_MASK_EXT, + VK_DYNAMIC_STATE_BLEND_CONSTANTS}; VkPipelineDynamicStateCreateInfo dynamic_state{}; dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; dynamic_state.dynamicStateCount = static_cast(dynamic_states.size()); @@ -207,23 +208,23 @@ void GraphicsPipeline::PreparePipeline() { pipeline_info.layout = pipeline_layout_->GetVkPipelineLayout(); pipeline_info.pNext = &rendering_create_info; pipeline_info.basePipelineHandle = VK_NULL_HANDLE; - Graphics::CheckVk(vkCreateGraphicsPipelines(Graphics::GetVkDevice(), VK_NULL_HANDLE, 1, &pipeline_info, nullptr, + Platform::CheckVk(vkCreateGraphicsPipelines(Platform::GetVkDevice(), VK_NULL_HANDLE, 1, &pipeline_info, nullptr, &vk_graphics_pipeline_)); states.ResetAllStates(1); } -bool GraphicsPipeline::PipelineReady() const { +bool GraphicsPipeline::Initialized() const { return vk_graphics_pipeline_ != VK_NULL_HANDLE; } -void GraphicsPipeline::Bind(const VkCommandBuffer command_buffer) { - vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vk_graphics_pipeline_); - states.ApplyAllStates(command_buffer, true); +void GraphicsPipeline::Bind(const VkCommandBuffer vk_command_buffer) { + vkCmdBindPipeline(vk_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vk_graphics_pipeline_); + states.ApplyAllStates(vk_command_buffer, true); } -void GraphicsPipeline::BindDescriptorSet(const VkCommandBuffer command_buffer, const uint32_t first_set, +void GraphicsPipeline::BindDescriptorSet(const VkCommandBuffer vk_command_buffer, const uint32_t first_set, const VkDescriptorSet descriptor_set) const { - vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout_->GetVkPipelineLayout(), + vkCmdBindDescriptorSets(vk_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout_->GetVkPipelineLayout(), first_set, 1, &descriptor_set, 0, nullptr); } @@ -328,4 +329,11 @@ void PipelineDynamicState::Apply(const VkPipelineDynamicStateCreateInfo& vk_pipe IGraphicsResource::ApplyVector(dynamic_states, vk_pipeline_dynamic_state_create_info.dynamicStateCount, vk_pipeline_dynamic_state_create_info.pDynamicStates); } -#pragma endregion \ No newline at end of file + +GraphicsPipeline::~GraphicsPipeline() { + if (vk_graphics_pipeline_ != VK_NULL_HANDLE) { + vkDestroyPipeline(Platform::GetVkDevice(), vk_graphics_pipeline_, nullptr); + vk_graphics_pipeline_ = nullptr; + } +} +#pragma endregion diff --git a/EvoEngine_SDK/src/GraphicsPipelineStates.cpp b/EvoEngine_SDK/src/GraphicsPipelineStates.cpp index e3672c2..8fc198b 100644 --- a/EvoEngine_SDK/src/GraphicsPipelineStates.cpp +++ b/EvoEngine_SDK/src/GraphicsPipelineStates.cpp @@ -1,5 +1,7 @@ #include "GraphicsPipelineStates.hpp" +#include "GraphicsResources.hpp" + using namespace evo_engine; void GraphicsPipelineStates::ResetAllStates(const size_t color_attachment_size) { @@ -46,78 +48,78 @@ void GraphicsPipelineStates::ResetAllStates(const size_t color_attachment_size) blend_constants[3] = 0; } -void GraphicsPipelineStates::ApplyAllStates(const VkCommandBuffer command_buffer, const bool force_set) { +void GraphicsPipelineStates::ApplyAllStates(const VkCommandBuffer vk_command_buffer, const bool force_set) { if (force_set || view_port_applied_.x != view_port.x || view_port_applied_.y != view_port.y || view_port_applied_.width != view_port.width || view_port_applied_.height != view_port.height || view_port_applied_.maxDepth != view_port.maxDepth || view_port_applied_.minDepth != view_port.minDepth) { view_port_applied_ = view_port; view_port_applied_.width = view_port.width = glm::max(1.0f, view_port.width); view_port_applied_.height = view_port.height = glm::max(1.0f, view_port.height); - vkCmdSetViewport(command_buffer, 0, 1, &view_port_applied_); + vkCmdSetViewport(vk_command_buffer, 0, 1, &view_port_applied_); } if (force_set || scissor_applied_.extent.height != scissor.extent.height || scissor_applied_.extent.width != scissor.extent.width || scissor_applied_.offset.x != scissor.offset.x || scissor_applied_.offset.y != scissor.offset.y) { scissor_applied_ = scissor; - vkCmdSetScissor(command_buffer, 0, 1, &scissor_applied_); + vkCmdSetScissor(vk_command_buffer, 0, 1, &scissor_applied_); } if (force_set || depth_clamp_applied_ != depth_clamp) { depth_clamp_applied_ = depth_clamp; - vkCmdSetDepthClampEnableEXT(command_buffer, depth_clamp_applied_); + vkCmdSetDepthClampEnableEXT(vk_command_buffer, depth_clamp_applied_); } if (force_set || rasterizer_discard_applied_ != rasterizer_discard) { rasterizer_discard_applied_ = rasterizer_discard; - vkCmdSetRasterizerDiscardEnable(command_buffer, rasterizer_discard_applied_); + vkCmdSetRasterizerDiscardEnable(vk_command_buffer, rasterizer_discard_applied_); } if (force_set || polygon_mode_applied_ != polygon_mode) { polygon_mode_applied_ = polygon_mode; - vkCmdSetPolygonModeEXT(command_buffer, polygon_mode_applied_); + vkCmdSetPolygonModeEXT(vk_command_buffer, polygon_mode_applied_); } if (force_set || cull_mode_applied_ != cull_mode) { cull_mode_applied_ = cull_mode; - vkCmdSetCullModeEXT(command_buffer, cull_mode_applied_); + vkCmdSetCullModeEXT(vk_command_buffer, cull_mode_applied_); } if (force_set || front_face_applied_ != front_face) { front_face_applied_ = front_face; - vkCmdSetFrontFace(command_buffer, front_face_applied_); + vkCmdSetFrontFace(vk_command_buffer, front_face_applied_); } if (force_set || depth_bias_applied_ != depth_bias) { depth_bias_applied_ = depth_bias; - vkCmdSetDepthBiasEnable(command_buffer, depth_bias_applied_); + vkCmdSetDepthBiasEnable(vk_command_buffer, depth_bias_applied_); } if (force_set || depth_bias_constant_clamp_slope_applied_ != depth_bias_constant_clamp_slope) { depth_bias_constant_clamp_slope_applied_ = depth_bias_constant_clamp_slope; - vkCmdSetDepthBias(command_buffer, depth_bias_constant_clamp_slope_applied_.x, depth_bias_constant_clamp_slope_applied_.y, + vkCmdSetDepthBias(vk_command_buffer, depth_bias_constant_clamp_slope_applied_.x, depth_bias_constant_clamp_slope_applied_.y, depth_bias_constant_clamp_slope_applied_.z); } if (force_set || line_width_applied_ != line_width) { line_width_applied_ = line_width; - vkCmdSetLineWidth(command_buffer, line_width_applied_); + vkCmdSetLineWidth(vk_command_buffer, line_width_applied_); } if (force_set || depth_test_applied_ != depth_test) { depth_test_applied_ = depth_test; - vkCmdSetDepthTestEnableEXT(command_buffer, depth_test_applied_); + vkCmdSetDepthTestEnableEXT(vk_command_buffer, depth_test_applied_); } if (force_set || depth_write_applied_ != depth_write) { depth_write_applied_ = depth_write; - vkCmdSetDepthWriteEnableEXT(command_buffer, depth_write_applied_); + vkCmdSetDepthWriteEnableEXT(vk_command_buffer, depth_write_applied_); } if (force_set || depth_compare_applied_ != depth_compare) { depth_compare_applied_ = depth_compare; - vkCmdSetDepthCompareOpEXT(command_buffer, depth_compare_applied_); + vkCmdSetDepthCompareOpEXT(vk_command_buffer, depth_compare_applied_); } if (force_set || depth_bound_test_applied_ != depth_bound_test) { depth_bound_test_applied_ = depth_bound_test; - vkCmdSetDepthBoundsTestEnableEXT(command_buffer, depth_bound_test_applied_); + vkCmdSetDepthBoundsTestEnableEXT(vk_command_buffer, depth_bound_test_applied_); } if (force_set || min_max_depth_bound_applied_ != min_max_depth_bound) { min_max_depth_bound_applied_ = min_max_depth_bound; - vkCmdSetDepthBounds(command_buffer, min_max_depth_bound_applied_.x, min_max_depth_bound_applied_.y); + vkCmdSetDepthBounds(vk_command_buffer, min_max_depth_bound_applied_.x, min_max_depth_bound_applied_.y); } if (force_set || stencil_test_applied_ != stencil_test) { stencil_test_applied_ = stencil_test; - vkCmdSetStencilTestEnableEXT(command_buffer, stencil_test_applied_); + vkCmdSetStencilTestEnableEXT(vk_command_buffer, stencil_test_applied_); } if (force_set || front_face_applied_ != front_face || stencil_fail_op_applied_ != stencil_fail_op || stencil_pass_op_applied_ != stencil_pass_op || stencil_depth_fail_op_applied_ != stencil_depth_fail_op || @@ -127,16 +129,16 @@ void GraphicsPipelineStates::ApplyAllStates(const VkCommandBuffer command_buffer stencil_pass_op_applied_ = stencil_pass_op; stencil_depth_fail_op_applied_ = stencil_depth_fail_op; stencil_compare_op_applied_ = stencil_compare_op; - vkCmdSetStencilOpEXT(command_buffer, stencil_face_mask_applied_, stencil_fail_op_applied_, stencil_pass_op_applied_, + vkCmdSetStencilOpEXT(vk_command_buffer, stencil_face_mask_applied_, stencil_fail_op_applied_, stencil_pass_op_applied_, stencil_depth_fail_op_applied_, stencil_compare_op_applied_); } if (force_set || logic_op_enable_applied_ != logic_op_enable) { - vkCmdSetLogicOpEnableEXT(command_buffer, logic_op_enable_applied_); + vkCmdSetLogicOpEnableEXT(vk_command_buffer, logic_op_enable_applied_); } if (force_set || logic_op_applied_ != logic_op) { - vkCmdSetLogicOpEXT(command_buffer, logic_op_applied_); + vkCmdSetLogicOpEXT(vk_command_buffer, logic_op_applied_); } if (color_blend_attachment_states.empty()) { color_blend_attachment_states.emplace_back(); @@ -147,7 +149,7 @@ void GraphicsPipelineStates::ApplyAllStates(const VkCommandBuffer command_buffer color_write_masks.push_back(i.colorWriteMask); } if (!color_write_masks.empty()) - vkCmdSetColorWriteMaskEXT(command_buffer, 0, color_write_masks.size(), color_write_masks.data()); + vkCmdSetColorWriteMaskEXT(vk_command_buffer, 0, color_write_masks.size(), color_write_masks.data()); std::vector color_blend_enable = {}; color_blend_enable.reserve(color_blend_attachment_states.size()); @@ -155,7 +157,7 @@ void GraphicsPipelineStates::ApplyAllStates(const VkCommandBuffer command_buffer color_blend_enable.push_back(i.blendEnable); } if (!color_blend_enable.empty()) - vkCmdSetColorBlendEnableEXT(command_buffer, 0, color_blend_enable.size(), color_blend_enable.data()); + vkCmdSetColorBlendEnableEXT(vk_command_buffer, 0, color_blend_enable.size(), color_blend_enable.data()); std::vector equations{}; for (const auto& i : color_blend_attachment_states) { @@ -169,9 +171,9 @@ void GraphicsPipelineStates::ApplyAllStates(const VkCommandBuffer command_buffer equations.emplace_back(equation); } if (!equations.empty()) - vkCmdSetColorBlendEquationEXT(command_buffer, 0, equations.size(), equations.data()); + vkCmdSetColorBlendEquationEXT(vk_command_buffer, 0, equations.size(), equations.data()); else { int a = 0; } - vkCmdSetBlendConstants(command_buffer, blend_constants_applied_); + vkCmdSetBlendConstants(vk_command_buffer, blend_constants_applied_); } diff --git a/EvoEngine_SDK/src/GraphicsPipelinesRegistry.cpp b/EvoEngine_SDK/src/GraphicsPipelinesRegistry.cpp index 034416b..64df51b 100644 --- a/EvoEngine_SDK/src/GraphicsPipelinesRegistry.cpp +++ b/EvoEngine_SDK/src/GraphicsPipelinesRegistry.cpp @@ -1,6 +1,6 @@ #include "Application.hpp" #include "EditorLayer.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "PostProcessingStack.hpp" #include "RenderLayer.hpp" #include "Resources.hpp" @@ -9,7 +9,7 @@ #include "WindowLayer.hpp" using namespace evo_engine; -void Graphics::CreateGraphicsPipelines() const { +void Platform::CreateGraphicsPipelines() const { auto per_frame_layout = GetDescriptorSetLayout("PER_FRAME_LAYOUT"); auto camera_g_buffer_layout = GetDescriptorSetLayout("CAMERA_GBUFFER_LAYOUT"); auto lighting_layout = GetDescriptorSetLayout("LIGHTING_LAYOUT"); @@ -30,7 +30,7 @@ void Graphics::CreateGraphicsPipelines() const { render_texture_pass_through->color_attachment_formats = {1, swapchain_->GetImageFormat()}; - render_texture_pass_through->PreparePipeline(); + render_texture_pass_through->Initialize(); RegisterGraphicsPipeline("RENDER_TEXTURE_PRESENT", render_texture_pass_through); } @@ -52,7 +52,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - ssr_reflect->PreparePipeline(); + ssr_reflect->Initialize(); RegisterGraphicsPipeline("SSR_REFLECT", ssr_reflect); } @@ -73,7 +73,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - ssr_blur->PreparePipeline(); + ssr_blur->Initialize(); RegisterGraphicsPipeline("SSR_BLUR", ssr_blur); } @@ -93,7 +93,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.size = sizeof(SsrPushConstant); push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - ssr_combine->PreparePipeline(); + ssr_combine->Initialize(); RegisterGraphicsPipeline("SSR_COMBINE", ssr_combine); } @@ -115,7 +115,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - standard_deferred_prepass->PreparePipeline(); + standard_deferred_prepass->Initialize(); RegisterGraphicsPipeline("STANDARD_DEFERRED_PREPASS", standard_deferred_prepass); } if (Constants::enable_mesh_shader) { @@ -136,7 +136,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - standard_deferred_prepass->PreparePipeline(); + standard_deferred_prepass->Initialize(); RegisterGraphicsPipeline("STANDARD_DEFERRED_PREPASS_MESH", standard_deferred_prepass); } @@ -156,7 +156,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.size = sizeof(RenderInstancePushConstant); push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - standard_skinned_deferred_prepass->PreparePipeline(); + standard_skinned_deferred_prepass->Initialize(); RegisterGraphicsPipeline("STANDARD_SKINNED_DEFERRED_PREPASS", standard_skinned_deferred_prepass); } { @@ -175,7 +175,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.size = sizeof(RenderInstancePushConstant); push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - standard_instanced_deferred_prepass->PreparePipeline(); + standard_instanced_deferred_prepass->Initialize(); RegisterGraphicsPipeline("STANDARD_INSTANCED_DEFERRED_PREPASS", standard_instanced_deferred_prepass); } { @@ -201,7 +201,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.size = sizeof(RenderInstancePushConstant); push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - standard_strands_deferred_prepass->PreparePipeline(); + standard_strands_deferred_prepass->Initialize(); RegisterGraphicsPipeline("STANDARD_STRANDS_DEFERRED_PREPASS", standard_strands_deferred_prepass); } { @@ -223,7 +223,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - standard_deferred_lighting->PreparePipeline(); + standard_deferred_lighting->Initialize(); RegisterGraphicsPipeline("STANDARD_DEFERRED_LIGHTING", standard_deferred_lighting); } { @@ -245,7 +245,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.size = sizeof(RenderInstancePushConstant); push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - standard_deferred_lighting_scene_camera->PreparePipeline(); + standard_deferred_lighting_scene_camera->Initialize(); RegisterGraphicsPipeline("STANDARD_DEFERRED_LIGHTING_SCENE_CAMERA", standard_deferred_lighting_scene_camera); } { @@ -262,7 +262,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - directional_light_shadow_map->PreparePipeline(); + directional_light_shadow_map->Initialize(); RegisterGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP", directional_light_shadow_map); } if (Constants::enable_mesh_shader) { @@ -280,7 +280,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - directional_light_shadow_map->PreparePipeline(); + directional_light_shadow_map->Initialize(); RegisterGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP_MESH", directional_light_shadow_map); } { @@ -300,7 +300,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - directional_light_shadow_map_skinned->PreparePipeline(); + directional_light_shadow_map_skinned->Initialize(); RegisterGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP_SKINNED", directional_light_shadow_map_skinned); } { @@ -320,7 +320,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - directional_light_shadow_map_instanced->PreparePipeline(); + directional_light_shadow_map_instanced->Initialize(); RegisterGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP_INSTANCED", directional_light_shadow_map_instanced); } { @@ -347,7 +347,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - directional_light_shadow_map_strand->PreparePipeline(); + directional_light_shadow_map_strand->Initialize(); RegisterGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP_STRANDS", directional_light_shadow_map_strand); } { @@ -364,7 +364,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - point_light_shadow_map->PreparePipeline(); + point_light_shadow_map->Initialize(); RegisterGraphicsPipeline("POINT_LIGHT_SHADOW_MAP", point_light_shadow_map); } if (Constants::enable_mesh_shader) { @@ -384,7 +384,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - point_light_shadow_map->PreparePipeline(); + point_light_shadow_map->Initialize(); RegisterGraphicsPipeline("POINT_LIGHT_SHADOW_MAP_MESH", point_light_shadow_map); } { @@ -403,7 +403,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - point_light_shadow_map_skinned->PreparePipeline(); + point_light_shadow_map_skinned->Initialize(); RegisterGraphicsPipeline("POINT_LIGHT_SHADOW_MAP_SKINNED", point_light_shadow_map_skinned); } { @@ -422,7 +422,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - point_light_shadow_map_instanced->PreparePipeline(); + point_light_shadow_map_instanced->Initialize(); RegisterGraphicsPipeline("POINT_LIGHT_SHADOW_MAP_INSTANCED", point_light_shadow_map_instanced); } { @@ -449,7 +449,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - point_light_shadow_map_strand->PreparePipeline(); + point_light_shadow_map_strand->Initialize(); RegisterGraphicsPipeline("POINT_LIGHT_SHADOW_MAP_STRANDS", point_light_shadow_map_strand); } { @@ -466,7 +466,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - spot_light_shadow_map->PreparePipeline(); + spot_light_shadow_map->Initialize(); RegisterGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP", spot_light_shadow_map); } if (Constants::enable_mesh_shader) { @@ -486,7 +486,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - spot_light_shadow_map->PreparePipeline(); + spot_light_shadow_map->Initialize(); RegisterGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP_MESH", spot_light_shadow_map); } { @@ -504,7 +504,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - spot_light_shadow_map->PreparePipeline(); + spot_light_shadow_map->Initialize(); RegisterGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP_SKINNED", spot_light_shadow_map); } { @@ -522,7 +522,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - spot_light_shadow_map->PreparePipeline(); + spot_light_shadow_map->Initialize(); RegisterGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP_INSTANCED", spot_light_shadow_map); } { @@ -548,7 +548,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - spot_light_shadow_map_strand->PreparePipeline(); + spot_light_shadow_map_strand->Initialize(); RegisterGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP_STRANDS", spot_light_shadow_map_strand); } { @@ -561,7 +561,7 @@ void Graphics::CreateGraphicsPipelines() const { brdf_lut->stencil_attachment_format = VK_FORMAT_UNDEFINED; brdf_lut->color_attachment_formats = {1, VK_FORMAT_R16G16_SFLOAT}; - brdf_lut->PreparePipeline(); + brdf_lut->Initialize(); RegisterGraphicsPipeline("ENVIRONMENTAL_MAP_BRDF", brdf_lut); } { @@ -582,7 +582,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - equirectangular_to_cubemap->PreparePipeline(); + equirectangular_to_cubemap->Initialize(); RegisterGraphicsPipeline("EQUIRECTANGULAR_TO_CUBEMAP", equirectangular_to_cubemap); } { @@ -602,7 +602,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - irradiance_construct->PreparePipeline(); + irradiance_construct->Initialize(); RegisterGraphicsPipeline("IRRADIANCE_CONSTRUCT", irradiance_construct); } { @@ -622,7 +622,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - prefilter_construct->PreparePipeline(); + prefilter_construct->Initialize(); RegisterGraphicsPipeline("PREFILTER_CONSTRUCT", prefilter_construct); } { @@ -642,7 +642,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - gizmos->PreparePipeline(); + gizmos->Initialize(); RegisterGraphicsPipeline("GIZMOS", gizmos); } { @@ -667,7 +667,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - gizmos_strands->PreparePipeline(); + gizmos_strands->Initialize(); RegisterGraphicsPipeline("GIZMOS_STRANDS", gizmos_strands); } { @@ -689,7 +689,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - gizmos_normal_colored->PreparePipeline(); + gizmos_normal_colored->Initialize(); RegisterGraphicsPipeline("GIZMOS_NORMAL_COLORED", gizmos_normal_colored); } { @@ -716,7 +716,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - gizmos_strands_normal_colored->PreparePipeline(); + gizmos_strands_normal_colored->Initialize(); RegisterGraphicsPipeline("GIZMOS_STRANDS_NORMAL_COLORED", gizmos_strands_normal_colored); } { @@ -736,7 +736,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - gizmos_vertex_colored->PreparePipeline(); + gizmos_vertex_colored->Initialize(); RegisterGraphicsPipeline("GIZMOS_VERTEX_COLORED", gizmos_vertex_colored); } { @@ -765,7 +765,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - gizmos_strands_vertex_colored->PreparePipeline(); + gizmos_strands_vertex_colored->Initialize(); RegisterGraphicsPipeline("GIZMOS_STRANDS_VERTEX_COLORED", gizmos_strands_vertex_colored); } { @@ -786,7 +786,7 @@ void Graphics::CreateGraphicsPipelines() const { push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; - gizmos_instanced_colored->PreparePipeline(); + gizmos_instanced_colored->Initialize(); RegisterGraphicsPipeline("GIZMOS_INSTANCED_COLORED", gizmos_instanced_colored); } } diff --git a/EvoEngine_SDK/src/GraphicsResources.cpp b/EvoEngine_SDK/src/GraphicsResources.cpp index 39d5cc8..85f18b9 100644 --- a/EvoEngine_SDK/src/GraphicsResources.cpp +++ b/EvoEngine_SDK/src/GraphicsResources.cpp @@ -2,19 +2,19 @@ #include "Application.hpp" #include "Console.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "Utilities.hpp" using namespace evo_engine; Fence::Fence(const VkFenceCreateInfo& vk_fence_create_info) { - Graphics::CheckVk(vkCreateFence(Graphics::GetVkDevice(), &vk_fence_create_info, nullptr, &vk_fence_)); + Platform::CheckVk(vkCreateFence(Platform::GetVkDevice(), &vk_fence_create_info, nullptr, &vk_fence_)); flags_ = vk_fence_create_info.flags; } Fence::~Fence() { if (vk_fence_ != VK_NULL_HANDLE) { - vkDestroyFence(Graphics::GetVkDevice(), vk_fence_, nullptr); + vkDestroyFence(Platform::GetVkDevice(), vk_fence_, nullptr); vk_fence_ = nullptr; } } @@ -24,13 +24,13 @@ const VkFence& Fence::GetVkFence() const { } Semaphore::Semaphore(const VkSemaphoreCreateInfo& semaphore_create_info) { - Graphics::CheckVk(vkCreateSemaphore(Graphics::GetVkDevice(), &semaphore_create_info, nullptr, &vk_semaphore_)); + Platform::CheckVk(vkCreateSemaphore(Platform::GetVkDevice(), &semaphore_create_info, nullptr, &vk_semaphore_)); flags_ = semaphore_create_info.flags; } Semaphore::~Semaphore() { if (vk_semaphore_ != VK_NULL_HANDLE) { - vkDestroySemaphore(Graphics::GetVkDevice(), vk_semaphore_, nullptr); + vkDestroySemaphore(Platform::GetVkDevice(), vk_semaphore_, nullptr); vk_semaphore_ = VK_NULL_HANDLE; } } @@ -48,8 +48,8 @@ void* Semaphore::GetVkSemaphoreHandle(VkExternalSemaphoreHandleTypeFlagBitsKHR e vulkan_semaphore_get_win32_handle_info_khr.semaphore = vk_semaphore_; vulkan_semaphore_get_win32_handle_info_khr.handleType = external_semaphore_handle_type; auto func = - PFN_vkGetSemaphoreWin32HandleKHR(vkGetDeviceProcAddr(Graphics::GetVkDevice(), "vkGetSemaphoreWin32HandleKHR")); - func(Graphics::GetVkDevice(), &vulkan_semaphore_get_win32_handle_info_khr, &handle); + PFN_vkGetSemaphoreWin32HandleKHR(vkGetDeviceProcAddr(Platform::GetVkDevice(), "vkGetSemaphoreWin32HandleKHR")); + func(Platform::GetVkDevice(), &vulkan_semaphore_get_win32_handle_info_khr, &handle); return handle; } @@ -64,7 +64,7 @@ int Semaphore::GetVkSemaphoreHandle(VkExternalSemaphoreHandleTypeFlagBitsKHR ext vulkanSemaphoreGetFdInfoKHR.semaphore = vk_semaphore_; vulkanSemaphoreGetFdInfoKHR.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR; - vkGetSemaphoreFdKHR(Graphics::GetVkDevice(), &vulkanSemaphoreGetFdInfoKHR, &fd); + vkGetSemaphoreFdKHR(Platform::GetVkDevice(), &vulkanSemaphoreGetFdInfoKHR, &fd); return fd; } @@ -72,8 +72,8 @@ int Semaphore::GetVkSemaphoreHandle(VkExternalSemaphoreHandleTypeFlagBitsKHR ext } #endif Swapchain::Swapchain(const VkSwapchainCreateInfoKHR& swap_chain_create_info) { - const auto& device = Graphics::GetVkDevice(); - Graphics::CheckVk(vkCreateSwapchainKHR(Graphics::GetVkDevice(), &swap_chain_create_info, nullptr, &vk_swapchain_)); + const auto& device = Platform::GetVkDevice(); + Platform::CheckVk(vkCreateSwapchainKHR(Platform::GetVkDevice(), &swap_chain_create_info, nullptr, &vk_swapchain_)); uint32_t image_count = 0; vkGetSwapchainImagesKHR(device, vk_swapchain_, &image_count, nullptr); vk_images_.resize(image_count); @@ -117,7 +117,7 @@ Swapchain::Swapchain(const VkSwapchainCreateInfoKHR& swap_chain_create_info) { Swapchain::~Swapchain() { vk_image_views_.clear(); if (vk_swapchain_ != VK_NULL_HANDLE) { - vkDestroySwapchainKHR(Graphics::GetVkDevice(), vk_swapchain_, nullptr); + vkDestroySwapchainKHR(Platform::GetVkDevice(), vk_swapchain_, nullptr); vk_swapchain_ = VK_NULL_HANDLE; } } @@ -131,11 +131,11 @@ const std::vector& Swapchain::GetAllVkImages() const { } const VkImage& Swapchain::GetVkImage() const { - return vk_images_[Graphics::GetNextImageIndex()]; + return vk_images_[Platform::GetNextImageIndex()]; } const VkImageView& Swapchain::GetVkImageView() const { - return vk_image_views_[Graphics::GetNextImageIndex()]->vk_image_view_; + return vk_image_views_[Platform::GetNextImageIndex()]->vk_image_view_; } const std::vector>& Swapchain::GetAllImageViews() const { @@ -151,7 +151,7 @@ VkExtent2D Swapchain::GetImageExtent() const { } ImageView::ImageView(const VkImageViewCreateInfo& image_view_create_info) { - Graphics::CheckVk(vkCreateImageView(Graphics::GetVkDevice(), &image_view_create_info, nullptr, &vk_image_view_)); + Platform::CheckVk(vkCreateImageView(Platform::GetVkDevice(), &image_view_create_info, nullptr, &vk_image_view_)); image_ = nullptr; flags_ = image_view_create_info.flags; view_type_ = image_view_create_info.viewType; @@ -161,7 +161,7 @@ ImageView::ImageView(const VkImageViewCreateInfo& image_view_create_info) { } ImageView::ImageView(const VkImageViewCreateInfo& image_view_create_info, const std::shared_ptr& image) { - Graphics::CheckVk(vkCreateImageView(Graphics::GetVkDevice(), &image_view_create_info, nullptr, &vk_image_view_)); + Platform::CheckVk(vkCreateImageView(Platform::GetVkDevice(), &image_view_create_info, nullptr, &vk_image_view_)); image_ = image; flags_ = image_view_create_info.flags; view_type_ = image_view_create_info.viewType; @@ -172,7 +172,7 @@ ImageView::ImageView(const VkImageViewCreateInfo& image_view_create_info, const ImageView::~ImageView() { if (vk_image_view_ != VK_NULL_HANDLE) { - vkDestroyImageView(Graphics::GetVkDevice(), vk_image_view_, nullptr); + vkDestroyImageView(Platform::GetVkDevice(), vk_image_view_, nullptr); vk_image_view_ = VK_NULL_HANDLE; } } @@ -187,13 +187,13 @@ const std::shared_ptr& ImageView::GetImage() const { ShaderModule::~ShaderModule() { if (vk_shader_module_ != VK_NULL_HANDLE) { - vkDestroyShaderModule(Graphics::GetVkDevice(), vk_shader_module_, nullptr); + vkDestroyShaderModule(Platform::GetVkDevice(), vk_shader_module_, nullptr); vk_shader_module_ = VK_NULL_HANDLE; } } ShaderModule::ShaderModule(const VkShaderModuleCreateInfo& create_info) { - Graphics::CheckVk(vkCreateShaderModule(Graphics::GetVkDevice(), &create_info, nullptr, &vk_shader_module_)); + Platform::CheckVk(vkCreateShaderModule(Platform::GetVkDevice(), &create_info, nullptr, &vk_shader_module_)); } VkShaderModule ShaderModule::GetVkShaderModule() const { @@ -201,8 +201,8 @@ VkShaderModule ShaderModule::GetVkShaderModule() const { } PipelineLayout::PipelineLayout(const VkPipelineLayoutCreateInfo& pipeline_layout_create_info) { - Graphics::CheckVk( - vkCreatePipelineLayout(Graphics::GetVkDevice(), &pipeline_layout_create_info, nullptr, &vk_pipeline_layout_)); + Platform::CheckVk( + vkCreatePipelineLayout(Platform::GetVkDevice(), &pipeline_layout_create_info, nullptr, &vk_pipeline_layout_)); flags_ = pipeline_layout_create_info.flags; ApplyVector(set_layouts_, pipeline_layout_create_info.setLayoutCount, pipeline_layout_create_info.pSetLayouts); @@ -212,7 +212,7 @@ PipelineLayout::PipelineLayout(const VkPipelineLayoutCreateInfo& pipeline_layout PipelineLayout::~PipelineLayout() { if (vk_pipeline_layout_ != VK_NULL_HANDLE) { - vkDestroyPipelineLayout(Graphics::GetVkDevice(), vk_pipeline_layout_, nullptr); + vkDestroyPipelineLayout(Platform::GetVkDevice(), vk_pipeline_layout_, nullptr); vk_pipeline_layout_ = VK_NULL_HANDLE; } } @@ -222,13 +222,13 @@ VkPipelineLayout PipelineLayout::GetVkPipelineLayout() const { } CommandPool::CommandPool(const VkCommandPoolCreateInfo& command_pool_create_info) { - Graphics::CheckVk( - vkCreateCommandPool(Graphics::GetVkDevice(), &command_pool_create_info, nullptr, &vk_command_pool_)); + Platform::CheckVk( + vkCreateCommandPool(Platform::GetVkDevice(), &command_pool_create_info, nullptr, &vk_command_pool_)); } CommandPool::~CommandPool() { if (vk_command_pool_ != VK_NULL_HANDLE) { - vkDestroyCommandPool(Graphics::GetVkDevice(), vk_command_pool_, nullptr); + vkDestroyCommandPool(Platform::GetVkDevice(), vk_command_pool_, nullptr); vk_command_pool_ = VK_NULL_HANDLE; } } @@ -255,7 +255,7 @@ Image::Image(VkImageCreateInfo image_create_info) { VmaAllocationCreateInfo alloc_info = {}; alloc_info.usage = VMA_MEMORY_USAGE_AUTO; - if (vmaCreateImage(Graphics::GetVmaAllocator(), &image_create_info, &alloc_info, &vk_image_, &vma_allocation_, + if (vmaCreateImage(Platform::GetVmaAllocator(), &image_create_info, &alloc_info, &vk_image_, &vma_allocation_, &vma_allocation_info_)) { throw std::runtime_error("Failed to create image!"); } @@ -286,7 +286,7 @@ Image::Image(VkImageCreateInfo image_create_info, const VmaAllocationCreateInfo& image_create_info.pNext = &vk_external_mem_image_create_info; - if (vmaCreateImage(Graphics::GetVmaAllocator(), &image_create_info, &vma_allocation_create_info, &vk_image_, + if (vmaCreateImage(Platform::GetVmaAllocator(), &image_create_info, &vma_allocation_create_info, &vk_image_, &vma_allocation_, &vma_allocation_info_)) { throw std::runtime_error("Failed to create image!"); } @@ -309,7 +309,8 @@ bool Image::HasStencilComponent() const { return format_ == VK_FORMAT_D32_SFLOAT_S8_UINT || format_ == VK_FORMAT_D24_UNORM_S8_UINT; } -void Image::CopyFromBuffer(VkCommandBuffer command_buffer, const VkBuffer& src_buffer, VkDeviceSize src_offset) const { +void Image::CopyFromBuffer(const VkCommandBuffer vk_command_buffer, const VkBuffer& src_buffer, + VkDeviceSize src_offset) const { VkBufferImageCopy region{}; region.bufferOffset = src_offset; region.bufferRowLength = 0; @@ -320,10 +321,10 @@ void Image::CopyFromBuffer(VkCommandBuffer command_buffer, const VkBuffer& src_b region.imageSubresource.layerCount = 1; region.imageOffset = {0, 0, 0}; region.imageExtent = extent_; - vkCmdCopyBufferToImage(command_buffer, src_buffer, vk_image_, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); + vkCmdCopyBufferToImage(vk_command_buffer, src_buffer, vk_image_, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); } -void Image::GenerateMipmaps(const VkCommandBuffer command_buffer) { +void Image::GenerateMipmaps(const VkCommandBuffer vk_command_buffer) { VkImageMemoryBarrier barrier{}; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; barrier.image = vk_image_; @@ -344,8 +345,8 @@ void Image::GenerateMipmaps(const VkCommandBuffer command_buffer) { barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, - 0, nullptr, 1, &barrier); + vkCmdPipelineBarrier(vk_command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, + nullptr, 0, nullptr, 1, &barrier); VkImageBlit blit{}; blit.srcOffsets[0] = {0, 0, 0}; @@ -361,7 +362,7 @@ void Image::GenerateMipmaps(const VkCommandBuffer command_buffer) { blit.dstSubresource.baseArrayLayer = 0; blit.dstSubresource.layerCount = array_layers_; - vkCmdBlitImage(command_buffer, vk_image_, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, vk_image_, + vkCmdBlitImage(vk_command_buffer, vk_image_, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, vk_image_, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, VK_FILTER_LINEAR); barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; @@ -369,7 +370,7 @@ void Image::GenerateMipmaps(const VkCommandBuffer command_buffer) { barrier.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT; barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, + vkCmdPipelineBarrier(vk_command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrier); if (mip_width > 1) @@ -383,7 +384,7 @@ void Image::GenerateMipmaps(const VkCommandBuffer command_buffer) { barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, + vkCmdPipelineBarrier(vk_command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrier); layout_ = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; } @@ -410,16 +411,16 @@ VkImageLayout Image::GetLayout() const { Image::~Image() { if (vk_image_ != VK_NULL_HANDLE || vma_allocation_ != VK_NULL_HANDLE) { - vmaDestroyImage(Graphics::GetVmaAllocator(), vk_image_, vma_allocation_); + vmaDestroyImage(Platform::GetVmaAllocator(), vk_image_, vma_allocation_); vk_image_ = VK_NULL_HANDLE; vma_allocation_ = VK_NULL_HANDLE; vma_allocation_info_ = {}; } } -void Image::TransitImageLayout(const VkCommandBuffer command_buffer, const VkImageLayout new_layout) { +void Image::TransitImageLayout(VkCommandBuffer vk_command_buffer, const VkImageLayout new_layout) { // if (newLayout == layout_) return; - Graphics::TransitImageLayout(command_buffer, vk_image_, format_, array_layers_, layout_, new_layout, mip_levels_); + Platform::TransitImageLayout(vk_command_buffer, vk_image_, format_, array_layers_, layout_, new_layout, mip_levels_); layout_ = new_layout; } @@ -436,7 +437,7 @@ void* Image::GetVkImageMemHandle(VkExternalMemoryHandleTypeFlagsKHR external_mem vk_memory_get_win32_handle_info_khr.memory = vma_allocation_info_.deviceMemory; vk_memory_get_win32_handle_info_khr.handleType = static_cast(external_memory_handle_type); - vkGetMemoryWin32HandleKHR(Graphics::GetVkDevice(), &vk_memory_get_win32_handle_info_khr, &handle); + vkGetMemoryWin32HandleKHR(Platform::GetVkDevice(), &vk_memory_get_win32_handle_info_khr, &handle); return handle; } #else @@ -450,7 +451,7 @@ int Image::GetVkImageMemHandle(VkExternalMemoryHandleTypeFlagsKHR externalMemory vkMemoryGetFdInfoKHR.memory = vma_allocation_info_.deviceMemory; vkMemoryGetFdInfoKHR.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR; - vkGetMemoryFdKHR(Graphics::GetVkDevice(), &vkMemoryGetFdInfoKHR, &fd); + vkGetMemoryFdKHR(Platform::GetVkDevice(), &vkMemoryGetFdInfoKHR, &fd); return fd; } @@ -459,12 +460,12 @@ int Image::GetVkImageMemHandle(VkExternalMemoryHandleTypeFlagsKHR externalMemory #endif Sampler::Sampler(const VkSamplerCreateInfo& sampler_create_info) { - Graphics::CheckVk(vkCreateSampler(Graphics::GetVkDevice(), &sampler_create_info, nullptr, &vk_sampler_)); + Platform::CheckVk(vkCreateSampler(Platform::GetVkDevice(), &sampler_create_info, nullptr, &vk_sampler_)); } Sampler::~Sampler() { if (vk_sampler_ != VK_NULL_HANDLE) { - vkDestroySampler(Graphics::GetVkDevice(), vk_sampler_, nullptr); + vkDestroySampler(Platform::GetVkDevice(), vk_sampler_, nullptr); vk_sampler_ = VK_NULL_HANDLE; } } @@ -479,9 +480,9 @@ void Buffer::UploadData(const size_t size, const void* src) { if (vma_allocation_create_info_.flags & VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT || vma_allocation_create_info_.flags & VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT) { void* mapping; - vmaMapMemory(Graphics::GetVmaAllocator(), vma_allocation_, &mapping); + vmaMapMemory(Platform::GetVmaAllocator(), vma_allocation_, &mapping); memcpy(mapping, src, size); - vmaUnmapMemory(Graphics::GetVmaAllocator(), vma_allocation_); + vmaUnmapMemory(Platform::GetVmaAllocator(), vma_allocation_); } else { Buffer staging_buffer(size); staging_buffer.UploadData(size, src); @@ -495,9 +496,9 @@ void Buffer::DownloadData(const size_t size, void* dst) { if (vma_allocation_create_info_.flags & VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT || vma_allocation_create_info_.flags & VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT) { void* mapping; - vmaMapMemory(Graphics::GetVmaAllocator(), vma_allocation_, &mapping); + vmaMapMemory(Platform::GetVmaAllocator(), vma_allocation_, &mapping); memcpy(dst, mapping, size); - vmaUnmapMemory(Graphics::GetVmaAllocator(), vma_allocation_); + vmaUnmapMemory(Platform::GetVmaAllocator(), vma_allocation_); } else { Buffer staging_buffer(size); staging_buffer.CopyFromBuffer(*this, size, 0, 0); @@ -507,7 +508,7 @@ void Buffer::DownloadData(const size_t size, void* dst) { void Buffer::Allocate(VkBufferCreateInfo buffer_create_info, const VmaAllocationCreateInfo& vma_allocation_create_info) { - VkExternalMemoryBufferCreateInfo vk_external_mem_buffer_create_info = {}; + VkExternalMemoryBufferCreateInfo vk_external_mem_buffer_create_info; vk_external_mem_buffer_create_info.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO; vk_external_mem_buffer_create_info.pNext = NULL; #ifdef _WIN64 @@ -518,7 +519,7 @@ void Buffer::Allocate(VkBufferCreateInfo buffer_create_info, buffer_create_info.pNext = &vk_external_mem_buffer_create_info; - if (vmaCreateBuffer(Graphics::GetVmaAllocator(), &buffer_create_info, &vma_allocation_create_info, &vk_buffer_, + if (vmaCreateBuffer(Platform::GetVmaAllocator(), &buffer_create_info, &vma_allocation_create_info, &vk_buffer_, &vma_allocation_, &vma_allocation_info_)) { throw std::runtime_error("Failed to create buffer!"); } @@ -560,7 +561,7 @@ void Buffer::Resize(VkDeviceSize new_size) { if (new_size == size_) return; if (vk_buffer_ != VK_NULL_HANDLE || vma_allocation_ != VK_NULL_HANDLE) { - vmaDestroyBuffer(Graphics::GetVmaAllocator(), vk_buffer_, vma_allocation_); + vmaDestroyBuffer(Platform::GetVmaAllocator(), vk_buffer_, vma_allocation_); vk_buffer_ = VK_NULL_HANDLE; vma_allocation_ = VK_NULL_HANDLE; vma_allocation_info_ = {}; @@ -584,7 +585,7 @@ void Buffer::Resize(VkDeviceSize new_size) { #endif buffer_create_info.pNext = &vk_external_mem_buffer_create_info; - if (vmaCreateBuffer(Graphics::GetVmaAllocator(), &buffer_create_info, &vma_allocation_create_info_, &vk_buffer_, + if (vmaCreateBuffer(Platform::GetVmaAllocator(), &buffer_create_info, &vma_allocation_create_info_, &vk_buffer_, &vma_allocation_, &vma_allocation_info_)) { throw std::runtime_error("Failed to create buffer!"); } @@ -593,7 +594,7 @@ void Buffer::Resize(VkDeviceSize new_size) { Buffer::~Buffer() { if (vk_buffer_ != VK_NULL_HANDLE || vma_allocation_ != VK_NULL_HANDLE) { - vmaDestroyBuffer(Graphics::GetVmaAllocator(), vk_buffer_, vma_allocation_); + vmaDestroyBuffer(Platform::GetVmaAllocator(), vk_buffer_, vma_allocation_); vk_buffer_ = VK_NULL_HANDLE; vma_allocation_ = VK_NULL_HANDLE; vma_allocation_info_ = {}; @@ -603,22 +604,22 @@ Buffer::~Buffer() { void Buffer::CopyFromBuffer(const Buffer& src_buffer, const VkDeviceSize size, const VkDeviceSize src_offset, const VkDeviceSize dst_offset) { Resize(size); - Graphics::ImmediateSubmit([&](const VkCommandBuffer command_buffer) { + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { VkBufferCopy copy_region{}; copy_region.size = size; copy_region.srcOffset = src_offset; copy_region.dstOffset = dst_offset; - vkCmdCopyBuffer(command_buffer, src_buffer.GetVkBuffer(), vk_buffer_, 1, ©_region); + vkCmdCopyBuffer(vk_command_buffer, src_buffer.GetVkBuffer(), vk_buffer_, 1, ©_region); }); } void Buffer::CopyFromImage(Image& src_image, const VkBufferImageCopy& image_copy_info) const { - Graphics::ImmediateSubmit([&](const VkCommandBuffer command_buffer) { + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { const auto prev_layout = src_image.GetLayout(); - src_image.TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); - vkCmdCopyImageToBuffer(command_buffer, src_image.GetVkImage(), src_image.GetLayout(), vk_buffer_, 1, + src_image.TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + vkCmdCopyImageToBuffer(vk_command_buffer, src_image.GetVkImage(), src_image.GetLayout(), vk_buffer_, 1, &image_copy_info); - src_image.TransitImageLayout(command_buffer, prev_layout); + src_image.TransitImageLayout(vk_command_buffer, prev_layout); }); } @@ -654,7 +655,7 @@ const VmaAllocationInfo& Buffer::GetVmaAllocationInfo() const { DescriptorSetLayout::~DescriptorSetLayout() { if (vk_descriptor_set_layout_ != VK_NULL_HANDLE) { - vkDestroyDescriptorSetLayout(Graphics::GetVkDevice(), vk_descriptor_set_layout_, nullptr); + vkDestroyDescriptorSetLayout(Platform::GetVkDevice(), vk_descriptor_set_layout_, nullptr); vk_descriptor_set_layout_ = VK_NULL_HANDLE; } } @@ -676,7 +677,7 @@ void DescriptorSetLayout::PushDescriptorBinding(uint32_t binding_index, VkDescri void DescriptorSetLayout::Initialize() { if (vk_descriptor_set_layout_ != VK_NULL_HANDLE) { - vkDestroyDescriptorSetLayout(Graphics::GetVkDevice(), vk_descriptor_set_layout_, nullptr); + vkDestroyDescriptorSetLayout(Platform::GetVkDevice(), vk_descriptor_set_layout_, nullptr); vk_descriptor_set_layout_ = VK_NULL_HANDLE; } @@ -697,7 +698,7 @@ void DescriptorSetLayout::Initialize() { descriptor_set_layout_create_info.bindingCount = static_cast(list_of_bindings.size()); descriptor_set_layout_create_info.pBindings = list_of_bindings.data(); descriptor_set_layout_create_info.pNext = &extended_info; - Graphics::CheckVk(vkCreateDescriptorSetLayout(Graphics::GetVkDevice(), &descriptor_set_layout_create_info, nullptr, + Platform::CheckVk(vkCreateDescriptorSetLayout(Platform::GetVkDevice(), &descriptor_set_layout_create_info, nullptr, &vk_descriptor_set_layout_)); } @@ -707,8 +708,8 @@ const VkDescriptorSet& DescriptorSet::GetVkDescriptorSet() const { DescriptorSet::~DescriptorSet() { if (descriptor_set_ != VK_NULL_HANDLE) { - Graphics::CheckVk(vkFreeDescriptorSets(Graphics::GetVkDevice(), - Graphics::GetDescriptorPool()->GetVkDescriptorPool(), 1, &descriptor_set_)); + Platform::CheckVk(vkFreeDescriptorSets(Platform::GetVkDevice(), + Platform::GetDescriptorPool()->GetVkDescriptorPool(), 1, &descriptor_set_)); descriptor_set_ = VK_NULL_HANDLE; } } @@ -716,11 +717,11 @@ DescriptorSet::~DescriptorSet() { DescriptorSet::DescriptorSet(const std::shared_ptr& target_layout) { VkDescriptorSetAllocateInfo alloc_info{}; alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; - alloc_info.descriptorPool = Graphics::GetDescriptorPool()->GetVkDescriptorPool(); + alloc_info.descriptorPool = Platform::GetDescriptorPool()->GetVkDescriptorPool(); alloc_info.descriptorSetCount = 1; alloc_info.pSetLayouts = &target_layout->GetVkDescriptorSetLayout(); - if (vkAllocateDescriptorSets(Graphics::GetVkDevice(), &alloc_info, &descriptor_set_) != VK_SUCCESS) { + if (vkAllocateDescriptorSets(Platform::GetVkDevice(), &alloc_info, &descriptor_set_) != VK_SUCCESS) { throw std::runtime_error("failed to allocate descriptor sets!"); } descriptor_set_layout_ = target_layout; @@ -737,7 +738,7 @@ void DescriptorSet::UpdateImageDescriptorBinding(const uint32_t binding_index, c write_info.descriptorType = descriptor_binding.binding.descriptorType; write_info.descriptorCount = 1; write_info.pImageInfo = &image_info; - vkUpdateDescriptorSets(Graphics::GetVkDevice(), 1, &write_info, 0, nullptr); + vkUpdateDescriptorSets(Platform::GetVkDevice(), 1, &write_info, 0, nullptr); } void DescriptorSet::UpdateBufferDescriptorBinding(const uint32_t binding_index, @@ -752,7 +753,7 @@ void DescriptorSet::UpdateBufferDescriptorBinding(const uint32_t binding_index, write_info.descriptorType = descriptor_binding.binding.descriptorType; write_info.descriptorCount = 1; write_info.pBufferInfo = &buffer_info; - vkUpdateDescriptorSets(Graphics::GetVkDevice(), 1, &write_info, 0, nullptr); + vkUpdateDescriptorSets(Platform::GetVkDevice(), 1, &write_info, 0, nullptr); } const VkDescriptorSetLayout& DescriptorSetLayout::GetVkDescriptorSetLayout() const { @@ -760,13 +761,13 @@ const VkDescriptorSetLayout& DescriptorSetLayout::GetVkDescriptorSetLayout() con } DescriptorPool::DescriptorPool(const VkDescriptorPoolCreateInfo& descriptor_pool_create_info) { - Graphics::CheckVk( - vkCreateDescriptorPool(Graphics::GetVkDevice(), &descriptor_pool_create_info, nullptr, &vk_descriptor_pool_)); + Platform::CheckVk( + vkCreateDescriptorPool(Platform::GetVkDevice(), &descriptor_pool_create_info, nullptr, &vk_descriptor_pool_)); } DescriptorPool::~DescriptorPool() { if (vk_descriptor_pool_ != VK_NULL_HANDLE) { - vkDestroyDescriptorPool(Graphics::GetVkDevice(), vk_descriptor_pool_, nullptr); + vkDestroyDescriptorPool(Platform::GetVkDevice(), vk_descriptor_pool_, nullptr); vk_descriptor_pool_ = VK_NULL_HANDLE; } } @@ -776,7 +777,7 @@ VkDescriptorPool DescriptorPool::GetVkDescriptorPool() const { } ShaderExt::ShaderExt(const VkShaderCreateInfoEXT& shader_create_info_ext) { - Graphics::CheckVk(vkCreateShadersEXT(Graphics::GetVkDevice(), 1, &shader_create_info_ext, nullptr, &shader_ext_)); + Platform::CheckVk(vkCreateShadersEXT(Platform::GetVkDevice(), 1, &shader_create_info_ext, nullptr, &shader_ext_)); flags_ = shader_create_info_ext.flags; stage_ = shader_create_info_ext.stage; next_stage_ = shader_create_info_ext.nextStage; @@ -791,7 +792,7 @@ ShaderExt::ShaderExt(const VkShaderCreateInfoEXT& shader_create_info_ext) { ShaderExt::~ShaderExt() { if (shader_ext_ != VK_NULL_HANDLE) { - vkDestroyShaderEXT(Graphics::GetVkDevice(), shader_ext_, nullptr); + vkDestroyShaderEXT(Platform::GetVkDevice(), shader_ext_, nullptr); shader_ext_ = VK_NULL_HANDLE; } } @@ -804,20 +805,20 @@ CommandBufferStatus CommandBuffer::GetStatus() const { return status_; } -void CommandBuffer::Allocate(const VkQueueFlagBits& queue_type, const VkCommandBufferLevel& buffer_level) { +CommandBuffer::CommandBuffer(const VkCommandBufferLevel& buffer_level) { VkCommandBufferAllocateInfo command_buffer_allocate_info = {}; command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - command_buffer_allocate_info.commandPool = Graphics::GetVkCommandPool(); + command_buffer_allocate_info.commandPool = Platform::GetVkCommandPool(); command_buffer_allocate_info.level = buffer_level; command_buffer_allocate_info.commandBufferCount = 1; - Graphics::CheckVk( - vkAllocateCommandBuffers(Graphics::GetVkDevice(), &command_buffer_allocate_info, &vk_command_buffer_)); + Platform::CheckVk( + vkAllocateCommandBuffers(Platform::GetVkDevice(), &command_buffer_allocate_info, &vk_command_buffer_)); status_ = CommandBufferStatus::Ready; } -void CommandBuffer::Free() { +CommandBuffer::~CommandBuffer() { if (vk_command_buffer_ != VK_NULL_HANDLE) { - vkFreeCommandBuffers(Graphics::GetVkDevice(), Graphics::GetVkCommandPool(), 1, &vk_command_buffer_); + vkFreeCommandBuffers(Platform::GetVkDevice(), Platform::GetVkCommandPool(), 1, &vk_command_buffer_); vk_command_buffer_ = VK_NULL_HANDLE; } status_ = CommandBufferStatus::Invalid; @@ -839,7 +840,7 @@ void CommandBuffer::Begin(const VkCommandBufferUsageFlags& usage) { VkCommandBufferBeginInfo begin_info = {}; begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; begin_info.flags = usage; - Graphics::CheckVk(vkBeginCommandBuffer(vk_command_buffer_, &begin_info)); + Platform::CheckVk(vkBeginCommandBuffer(vk_command_buffer_, &begin_info)); status_ = CommandBufferStatus::Recording; } @@ -852,78 +853,134 @@ void CommandBuffer::End() { EVOENGINE_ERROR("Command buffer not recording!") return; } - Graphics::CheckVk(vkEndCommandBuffer(vk_command_buffer_)); + Platform::CheckVk(vkEndCommandBuffer(vk_command_buffer_)); status_ = CommandBufferStatus::Recorded; } -void CommandBuffer::SubmitIdle() { +void CommandBuffer::Record(const std::function& commands) { + Begin(); + commands(vk_command_buffer_); + End(); +} + +void CommandBuffer::Reset() { if (status_ == CommandBufferStatus::Invalid) { - EVOENGINE_ERROR("Command buffer invalid!") - return; - } - if (status_ == CommandBufferStatus::Recording) { - EVOENGINE_ERROR("Command buffer recording!") + EVOENGINE_ERROR("Command buffer invalid!"); return; } - VkSubmitInfo submit_info = {}; - submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - submit_info.commandBufferCount = 1; - submit_info.pCommandBuffers = &vk_command_buffer_; + Platform::CheckVk(vkResetCommandBuffer(vk_command_buffer_, 0)); + status_ = CommandBufferStatus::Ready; +} - VkFenceCreateInfo fence_create_info = {}; - fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; +void CommandQueue::Submit( + const std::vector>& command_buffers, + const std::vector, VkPipelineStageFlags>>& wait_semaphores, + const std::vector>& signal_semaphores, const std::shared_ptr& fence) const { + VkSubmitInfo submit_info{}; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + //=========== + submit_info.waitSemaphoreCount = wait_semaphores.size(); + std::vector wait_vk_semaphores(wait_semaphores.size()); + std::vector wait_vk_wait_stage_flags(wait_semaphores.size()); + for (uint32_t i = 0; i < wait_vk_semaphores.size(); i++) { + wait_vk_semaphores[i] = wait_semaphores[i].first->GetVkSemaphore(); + wait_vk_wait_stage_flags[i] = wait_semaphores[i].second; + } + submit_info.pWaitSemaphores = wait_vk_semaphores.data(); + submit_info.pWaitDstStageMask = wait_vk_wait_stage_flags.data(); - VkFence fence; - auto device = Graphics::GetVkDevice(); - if (vkCreateFence(device, &fence_create_info, nullptr, &fence)) - ; + //=========== + submit_info.signalSemaphoreCount = signal_semaphores.size(); + std::vector signal_vk_semaphores(signal_semaphores.size()); + for (uint32_t i = 0; i < signal_vk_semaphores.size(); i++) { + signal_vk_semaphores[i] = signal_semaphores[i]->GetVkSemaphore(); + } + submit_info.pSignalSemaphores = signal_vk_semaphores.data(); - Graphics::CheckVk(vkResetFences(device, 1, &fence)); + //=========== + submit_info.commandBufferCount = command_buffers.size(); + std::vector vk_command_buffers(command_buffers.size()); + for (uint32_t i = 0; i < command_buffers.size(); i++) { + vk_command_buffers[i] = command_buffers[i]->GetVkCommandBuffer(); + } + submit_info.pCommandBuffers = vk_command_buffers.data(); - Graphics::CheckVk(vkQueueSubmit(Graphics::GetGraphicsVkQueue(), 1, &submit_info, fence)); + if (vkQueueSubmit(vk_queue_, 1, &submit_info, fence->GetVkFence()) != VK_SUCCESS) { + throw std::runtime_error("Failed to submit command buffer!"); + } +} - Graphics::CheckVk(vkWaitForFences(device, 1, &fence, VK_TRUE, std::numeric_limits::max())); +void CommandQueue::Submit( + const std::vector>& command_buffers, + const std::vector, VkPipelineStageFlags>>& wait_semaphores, + const std::vector>& signal_semaphores) const { + VkSubmitInfo submit_info{}; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + //=========== + submit_info.waitSemaphoreCount = wait_semaphores.size(); + std::vector wait_vk_semaphores(wait_semaphores.size()); + std::vector wait_vk_wait_stage_flags(wait_semaphores.size()); + for (uint32_t i = 0; i < wait_vk_semaphores.size(); i++) { + wait_vk_semaphores[i] = wait_semaphores[i].first->GetVkSemaphore(); + wait_vk_wait_stage_flags[i] = wait_semaphores[i].second; + } + submit_info.pWaitSemaphores = wait_vk_semaphores.data(); + submit_info.pWaitDstStageMask = wait_vk_wait_stage_flags.data(); - vkDestroyFence(device, fence, nullptr); -} + //=========== + submit_info.signalSemaphoreCount = signal_semaphores.size(); + std::vector signal_vk_semaphores(signal_semaphores.size()); + for (uint32_t i = 0; i < signal_vk_semaphores.size(); i++) { + signal_vk_semaphores[i] = signal_semaphores[i]->GetVkSemaphore(); + } + submit_info.pSignalSemaphores = signal_vk_semaphores.data(); -void CommandBuffer::Submit(const VkSemaphore& wait_semaphore, const VkSemaphore& signal_semaphore, - const VkFence fence) const { - if (status_ == CommandBufferStatus::Invalid) { - EVOENGINE_ERROR("Command buffer invalid!"); - return; + //=========== + submit_info.commandBufferCount = command_buffers.size(); + std::vector vk_command_buffers(command_buffers.size()); + for (uint32_t i = 0; i < command_buffers.size(); i++) { + vk_command_buffers[i] = command_buffers[i]->GetVkCommandBuffer(); } - if (status_ == CommandBufferStatus::Recording) { - EVOENGINE_ERROR("Command buffer recording!"); - return; + submit_info.pCommandBuffers = vk_command_buffers.data(); + + if (vkQueueSubmit(vk_queue_, 1, &submit_info, VK_NULL_HANDLE) != VK_SUCCESS) { + throw std::runtime_error("Failed to submit command buffer!"); } - VkSubmitInfo submit_info = {}; - submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - submit_info.commandBufferCount = 1; - submit_info.pCommandBuffers = &vk_command_buffer_; +} - if (wait_semaphore != VK_NULL_HANDLE) { - // Pipeline stages used to wait at for graphics queue submissions. - static VkPipelineStageFlags submit_pipeline_stages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; +void CommandQueue::ImmediateSubmit( + const std::vector>& command_buffers, + const std::vector, VkPipelineStageFlags>>& wait_semaphores, + const std::vector>& signal_semaphores) const { + Submit(command_buffers, wait_semaphores, signal_semaphores); + WaitIdle(); +} - submit_info.pWaitDstStageMask = &submit_pipeline_stages; - submit_info.waitSemaphoreCount = 1; - submit_info.pWaitSemaphores = &wait_semaphore; +void CommandQueue::Present(const std::vector>& wait_semaphores, + const std::vector, uint32_t>>& targets) const { + VkPresentInfoKHR present_info{}; + present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + std::vector wait_vk_semaphores(wait_semaphores.size()); + for (uint32_t i = 0; i < wait_vk_semaphores.size(); i++) { + wait_vk_semaphores[i] = wait_semaphores[i]->GetVkSemaphore(); } + present_info.waitSemaphoreCount = wait_vk_semaphores.size(); + present_info.pWaitSemaphores = wait_vk_semaphores.data(); - if (signal_semaphore != VK_NULL_HANDLE) { - submit_info.signalSemaphoreCount = 1; - submit_info.pSignalSemaphores = &signal_semaphore; + //=========== + present_info.swapchainCount = targets.size(); + std::vector vk_swapchain_khrs(targets.size()); + std::vector image_indices(targets.size()); + for (uint32_t i = 0; i < targets.size(); i++) { + vk_swapchain_khrs[i] = targets[i].first->GetVkSwapchain(); + image_indices[i] = targets[i].second; } + present_info.pSwapchains = vk_swapchain_khrs.data(); + present_info.pImageIndices = image_indices.data(); - Graphics::CheckVk(vkQueueSubmit(Graphics::GetGraphicsVkQueue(), 1, &submit_info, fence)); + vkQueuePresentKHR(vk_queue_, &present_info); } -void CommandBuffer::Reset() { - if (status_ == CommandBufferStatus::Invalid) { - EVOENGINE_ERROR("Command buffer invalid!"); - return; - } - Graphics::CheckVk(vkResetCommandBuffer(vk_command_buffer_, 0)); - status_ = CommandBufferStatus::Ready; +void CommandQueue::WaitIdle() const { + vkQueueWaitIdle(vk_queue_); } diff --git a/EvoEngine_SDK/src/LightProbe.cpp b/EvoEngine_SDK/src/LightProbe.cpp index 322a394..e76da4b 100644 --- a/EvoEngine_SDK/src/LightProbe.cpp +++ b/EvoEngine_SDK/src/LightProbe.cpp @@ -8,8 +8,8 @@ using namespace evo_engine; void LightProbe::Initialize(const uint32_t resolution) { cubemap_ = ProjectManager::CreateTemporaryAsset(); cubemap_->Initialize(resolution); - Graphics::ImmediateSubmit([&](const VkCommandBuffer command_buffer) { - cubemap_->RefStorage().image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { + cubemap_->RefStorage().image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); }); } @@ -34,7 +34,7 @@ void LightProbe::ConstructFromCubemap(const std::shared_ptr& target_cub depth_image_info.extent.depth = 1; depth_image_info.mipLevels = 1; depth_image_info.arrayLayers = 1; - depth_image_info.format = Graphics::Constants::shadow_map; + depth_image_info.format = Platform::Constants::shadow_map; depth_image_info.tiling = VK_IMAGE_TILING_OPTIMAL; depth_image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; depth_image_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; @@ -42,15 +42,15 @@ void LightProbe::ConstructFromCubemap(const std::shared_ptr& target_cub depth_image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; const auto depth_image = std::make_shared(depth_image_info); - Graphics::ImmediateSubmit([&](const VkCommandBuffer command_buffer) { - depth_image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { + depth_image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); }); VkImageViewCreateInfo depth_view_info{}; depth_view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; depth_view_info.image = depth_image->GetVkImage(); depth_view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; - depth_view_info.format = Graphics::Constants::shadow_map; + depth_view_info.format = Platform::Constants::shadow_map; depth_view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; depth_view_info.subresourceRange.baseMipLevel = 0; depth_view_info.subresourceRange.levelCount = 1; @@ -60,7 +60,7 @@ void LightProbe::ConstructFromCubemap(const std::shared_ptr& target_cub #pragma endregion const std::unique_ptr temp_set = - std::make_unique(Graphics::GetDescriptorSetLayout("RENDER_TEXTURE_PRESENT_LAYOUT")); + std::make_unique(Platform::GetDescriptorSetLayout("RENDER_TEXTURE_PRESENT_LAYOUT")); VkDescriptorImageInfo descriptor_image_info{}; descriptor_image_info.imageView = target_cubemap->GetImageView()->GetVkImageView(); descriptor_image_info.imageLayout = target_cubemap->GetImage()->GetLayout(); @@ -77,9 +77,9 @@ void LightProbe::ConstructFromCubemap(const std::shared_ptr& target_cub glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f)), glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f))}; - const auto irradiance_construct = Graphics::GetGraphicsPipeline("IRRADIANCE_CONSTRUCT"); - Graphics::ImmediateSubmit([&](VkCommandBuffer command_buffer) { - cubemap_->RefStorage().image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + const auto irradiance_construct = Platform::GetGraphicsPipeline("IRRADIANCE_CONSTRUCT"); + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { + cubemap_->RefStorage().image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); #pragma region Viewport and scissor VkRect2D render_area; render_area.offset = {0, 0}; @@ -100,7 +100,7 @@ void LightProbe::ConstructFromCubemap(const std::shared_ptr& target_cub irradiance_construct->states.view_port = viewport; irradiance_construct->states.scissor = scissor; #pragma endregion - GeometryStorage::BindVertices(command_buffer); + GeometryStorage::BindVertices(vk_command_buffer); for (int i = 0; i < 6; i++) { #pragma region Lighting pass VkRenderingAttachmentInfo attachment{}; @@ -138,20 +138,20 @@ void LightProbe::ConstructFromCubemap(const std::shared_ptr& target_cub VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; i.blendEnable = VK_FALSE; } - vkCmdBeginRendering(command_buffer, &render_info); - irradiance_construct->Bind(command_buffer); - irradiance_construct->BindDescriptorSet(command_buffer, 0, temp_set->GetVkDescriptorSet()); + vkCmdBeginRendering(vk_command_buffer, &render_info); + irradiance_construct->Bind(vk_command_buffer); + irradiance_construct->BindDescriptorSet(vk_command_buffer, 0, temp_set->GetVkDescriptorSet()); const auto mesh = Resources::GetResource("PRIMITIVE_RENDERING_CUBE"); Cubemap::EquirectangularToCubemapConstant constant{}; constant.projection_view = capture_projection * capture_views[i]; - irradiance_construct->PushConstant(command_buffer, 0, constant); - mesh->DrawIndexed(command_buffer, irradiance_construct->states, 1); - vkCmdEndRendering(command_buffer); + irradiance_construct->PushConstant(vk_command_buffer, 0, constant); + mesh->DrawIndexed(vk_command_buffer, irradiance_construct->states, 1); + vkCmdEndRendering(vk_command_buffer); #pragma endregion - Graphics::EverythingBarrier(command_buffer); + Platform::EverythingBarrier(vk_command_buffer); } - cubemap_->RefStorage().image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + cubemap_->RefStorage().image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); }); } diff --git a/EvoEngine_SDK/src/Lights.cpp b/EvoEngine_SDK/src/Lights.cpp index 75070f3..7194a13 100644 --- a/EvoEngine_SDK/src/Lights.cpp +++ b/EvoEngine_SDK/src/Lights.cpp @@ -1,7 +1,7 @@ #include "Lights.hpp" #include "Application.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "RenderLayer.hpp" #include "Serialization.hpp" using namespace evo_engine; @@ -204,7 +204,7 @@ void Lighting::AllocateAtlas(uint32_t size, uint32_t max_resolution, std::vector } Lighting::Lighting() { - lighting_descriptor_set = std::make_shared(Graphics::GetDescriptorSetLayout("LIGHTING_LAYOUT")); + lighting_descriptor_set = std::make_shared(Platform::GetDescriptorSetLayout("LIGHTING_LAYOUT")); } void Lighting::Initialize() { @@ -216,12 +216,12 @@ void Lighting::Initialize() { VkImageCreateInfo image_info{}; image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; image_info.imageType = VK_IMAGE_TYPE_2D; - image_info.extent.width = Graphics::Settings::directional_light_shadow_map_resolution; - image_info.extent.height = Graphics::Settings::directional_light_shadow_map_resolution; + image_info.extent.width = Platform::Settings::directional_light_shadow_map_resolution; + image_info.extent.height = Platform::Settings::directional_light_shadow_map_resolution; image_info.extent.depth = 1; image_info.mipLevels = 1; image_info.arrayLayers = 4; - image_info.format = Graphics::Constants::shadow_map; + image_info.format = Platform::Constants::shadow_map; image_info.tiling = VK_IMAGE_TILING_OPTIMAL; image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; image_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; @@ -234,7 +234,7 @@ void Lighting::Initialize() { view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; view_info.image = directional_light_shadow_map_->GetVkImage(); view_info.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; - view_info.format = Graphics::Constants::shadow_map; + view_info.format = Platform::Constants::shadow_map; view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; view_info.subresourceRange.baseMipLevel = 0; view_info.subresourceRange.levelCount = 1; @@ -256,7 +256,7 @@ void Lighting::Initialize() { sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; sampler_info.anisotropyEnable = VK_TRUE; - sampler_info.maxAnisotropy = Graphics::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; + sampler_info.maxAnisotropy = Platform::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; sampler_info.unnormalizedCoordinates = VK_FALSE; sampler_info.compareEnable = VK_FALSE; @@ -275,12 +275,12 @@ void Lighting::Initialize() { VkImageCreateInfo image_info{}; image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; image_info.imageType = VK_IMAGE_TYPE_2D; - image_info.extent.width = Graphics::Settings::point_light_shadow_map_resolution; - image_info.extent.height = Graphics::Settings::point_light_shadow_map_resolution; + image_info.extent.width = Platform::Settings::point_light_shadow_map_resolution; + image_info.extent.height = Platform::Settings::point_light_shadow_map_resolution; image_info.extent.depth = 1; image_info.mipLevels = 1; image_info.arrayLayers = 6; - image_info.format = Graphics::Constants::shadow_map; + image_info.format = Platform::Constants::shadow_map; image_info.tiling = VK_IMAGE_TILING_OPTIMAL; image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; image_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; @@ -293,7 +293,7 @@ void Lighting::Initialize() { view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; view_info.image = point_light_shadow_map_->GetVkImage(); view_info.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; - view_info.format = Graphics::Constants::shadow_map; + view_info.format = Platform::Constants::shadow_map; view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; view_info.subresourceRange.baseMipLevel = 0; view_info.subresourceRange.levelCount = 1; @@ -316,7 +316,7 @@ void Lighting::Initialize() { sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; sampler_info.anisotropyEnable = VK_TRUE; - sampler_info.maxAnisotropy = Graphics::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; + sampler_info.maxAnisotropy = Platform::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; sampler_info.unnormalizedCoordinates = VK_FALSE; sampler_info.compareEnable = VK_FALSE; @@ -334,12 +334,12 @@ void Lighting::Initialize() { VkImageCreateInfo image_info{}; image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; image_info.imageType = VK_IMAGE_TYPE_2D; - image_info.extent.width = Graphics::Settings::spot_light_shadow_map_resolution; - image_info.extent.height = Graphics::Settings::spot_light_shadow_map_resolution; + image_info.extent.width = Platform::Settings::spot_light_shadow_map_resolution; + image_info.extent.height = Platform::Settings::spot_light_shadow_map_resolution; image_info.extent.depth = 1; image_info.mipLevels = 1; image_info.arrayLayers = 1; - image_info.format = Graphics::Constants::shadow_map; + image_info.format = Platform::Constants::shadow_map; image_info.tiling = VK_IMAGE_TILING_OPTIMAL; image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; image_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; @@ -352,7 +352,7 @@ void Lighting::Initialize() { view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; view_info.image = spot_light_shadow_map_->GetVkImage(); view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; - view_info.format = Graphics::Constants::shadow_map; + view_info.format = Platform::Constants::shadow_map; view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; view_info.subresourceRange.baseMipLevel = 0; view_info.subresourceRange.levelCount = 1; @@ -369,7 +369,7 @@ void Lighting::Initialize() { sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; sampler_info.anisotropyEnable = VK_TRUE; - sampler_info.maxAnisotropy = Graphics::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; + sampler_info.maxAnisotropy = Platform::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; sampler_info.unnormalizedCoordinates = VK_FALSE; sampler_info.compareEnable = VK_FALSE; diff --git a/EvoEngine_SDK/src/Mesh.cpp b/EvoEngine_SDK/src/Mesh.cpp index 1600343..21f036e 100644 --- a/EvoEngine_SDK/src/Mesh.cpp +++ b/EvoEngine_SDK/src/Mesh.cpp @@ -3,7 +3,7 @@ #include "ClassRegistry.hpp" #include "Console.hpp" #include "GeometryStorage.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "Jobs.hpp" #include "Utilities.hpp" using namespace evo_engine; @@ -126,7 +126,7 @@ Mesh::~Mesh() { meshlet_range_.reset(); } -void Mesh::DrawIndexed(const VkCommandBuffer vk_command_buffer, GraphicsPipelineStates& global_pipeline_state, +void Mesh::DrawIndexed(VkCommandBuffer vk_command_buffer, GraphicsPipelineStates& global_pipeline_state, const int instances_count) const { if (instances_count == 0) return; diff --git a/EvoEngine_SDK/src/Graphics.cpp b/EvoEngine_SDK/src/Platform.cpp similarity index 84% rename from EvoEngine_SDK/src/Graphics.cpp rename to EvoEngine_SDK/src/Platform.cpp index d894a46..fd113dc 100644 --- a/EvoEngine_SDK/src/Graphics.cpp +++ b/EvoEngine_SDK/src/Platform.cpp @@ -1,4 +1,4 @@ -#include "Graphics.hpp" +#include "Platform.hpp" #include "Application.hpp" #include "Console.hpp" #include "EditorLayer.hpp" @@ -12,6 +12,9 @@ #include "WindowLayer.hpp" #include "vk_mem_alloc.h" using namespace evo_engine; + +//#define GRAPHICS_VALIDATION + VkBool32 DebugCallback(const VkDebugUtilsMessageSeverityFlagBitsEXT message_severity, const VkDebugUtilsMessageTypeFlagsEXT message_type, const VkDebugUtilsMessengerCallbackDataEXT* p_callback_data, void* p_user_data) { @@ -53,7 +56,7 @@ VkBool32 DebugCallback(const VkDebugUtilsMessageSeverityFlagBitsEXT message_seve return VK_FALSE; } -uint32_t Graphics::FindMemoryType(const uint32_t type_filter, const VkMemoryPropertyFlags properties) { +uint32_t Platform::FindMemoryType(const uint32_t type_filter, const VkMemoryPropertyFlags properties) { const auto& graphics = GetInstance(); VkPhysicalDeviceMemoryProperties mem_properties; vkGetPhysicalDeviceMemoryProperties(graphics.vk_physical_device_, &mem_properties); @@ -104,12 +107,24 @@ void SelectStageFlagsAccessMask(const VkImageLayout image_layout, VkAccessFlags& } } -void Graphics::WaitForDeviceIdle() { +void Platform::RecordCommandsMainQueue(const std::function& action) { + auto& graphics = GetInstance(); + const unsigned vk_command_buffer_index = graphics.used_command_buffer_size_; + const auto current_frame_index = graphics.current_frame_index_; + if (vk_command_buffer_index >= graphics.command_buffer_pool_[current_frame_index].size()) { + graphics.command_buffer_pool_[current_frame_index].emplace_back(std::make_shared()); + } + const auto& vk_command_buffer = graphics.command_buffer_pool_[current_frame_index][vk_command_buffer_index]; + vk_command_buffer->Record(action); + graphics.used_command_buffer_size_++; +} + +void Platform::WaitForDeviceIdle() { const auto& graphics = GetInstance(); vkDeviceWaitIdle(graphics.vk_device_); } -void Graphics::RegisterGraphicsPipeline(const std::string& name, +void Platform::RegisterGraphicsPipeline(const std::string& name, const std::shared_ptr& graphics_pipeline) { auto& graphics = GetInstance(); if (graphics.graphics_pipelines_.find(name) != graphics.graphics_pipelines_.end()) { @@ -119,17 +134,27 @@ void Graphics::RegisterGraphicsPipeline(const std::string& name, graphics.graphics_pipelines_[name] = graphics_pipeline; } -const std::shared_ptr& Graphics::GetGraphicsPipeline(const std::string& name) { +void Platform::RegisterComputePipeline(const std::string& name, + const std::shared_ptr& compute_pipeline) { + auto& graphics = GetInstance(); + if (graphics.compute_pipelines_.find(name) != graphics.compute_pipelines_.end()) { + EVOENGINE_ERROR("ComputePipeline with same name exists!"); + return; + } + graphics.compute_pipelines_[name] = compute_pipeline; +} + +const std::shared_ptr& Platform::GetGraphicsPipeline(const std::string& name) { const auto& graphics = GetInstance(); return graphics.graphics_pipelines_.at(name); } -const std::shared_ptr& Graphics::GetDescriptorSetLayout(const std::string& name) { +const std::shared_ptr& Platform::GetDescriptorSetLayout(const std::string& name) { const auto& graphics = GetInstance(); return graphics.descriptor_set_layouts_.at(name); } -void Graphics::RegisterDescriptorSetLayout(const std::string& name, +void Platform::RegisterDescriptorSetLayout(const std::string& name, const std::shared_ptr& descriptor_set_layout) { auto& graphics = GetInstance(); if (graphics.descriptor_set_layouts_.find(name) != graphics.descriptor_set_layouts_.end()) { @@ -139,7 +164,7 @@ void Graphics::RegisterDescriptorSetLayout(const std::string& name, graphics.descriptor_set_layouts_[name] = descriptor_set_layout; } -void Graphics::TransitImageLayout(const VkCommandBuffer command_buffer, const VkImage target_image, +void Platform::TransitImageLayout(VkCommandBuffer vk_command_buffer, const VkImage target_image, const VkFormat image_format, const uint32_t layer_count, const VkImageLayout old_layout, const VkImageLayout new_layout, const uint32_t mip_levels) { @@ -174,130 +199,123 @@ void Graphics::TransitImageLayout(const VkCommandBuffer command_buffer, const Vk SelectStageFlagsAccessMask(old_layout, barrier.srcAccessMask, source_stage); SelectStageFlagsAccessMask(new_layout, barrier.dstAccessMask, destination_stage); - vkCmdPipelineBarrier(command_buffer, source_stage, destination_stage, 0, 0, nullptr, 0, nullptr, 1, &barrier); + vkCmdPipelineBarrier(vk_command_buffer, source_stage, destination_stage, 0, 0, nullptr, 0, nullptr, 1, &barrier); } -size_t Graphics::GetMaxBoneAmount() { +size_t Platform::GetMaxBoneAmount() { const auto& graphics = GetInstance(); return graphics.max_bone_amount_; } -size_t Graphics::GetMaxShadowCascadeAmount() { +size_t Platform::GetMaxShadowCascadeAmount() { const auto& graphics = GetInstance(); return graphics.max_shadow_cascade_amount_; } -void Graphics::ImmediateSubmit(const std::function& action) { +void Platform::ImmediateSubmit(const std::function& action) { const auto& graphics = GetInstance(); - VkCommandBufferAllocateInfo alloc_info{}; - alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; - alloc_info.commandPool = graphics.command_pool_->GetVkCommandPool(); - alloc_info.commandBufferCount = 1; - - VkCommandBuffer command_buffer; - vkAllocateCommandBuffers(graphics.vk_device_, &alloc_info, &command_buffer); - - VkCommandBufferBeginInfo begin_info{}; - begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; - - vkBeginCommandBuffer(command_buffer, &begin_info); - action(command_buffer); - vkEndCommandBuffer(command_buffer); + graphics.immediate_submit_command_buffer->Record(action); VkSubmitInfo submit_info{}; submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submit_info.commandBufferCount = 1; - submit_info.pCommandBuffers = &command_buffer; + submit_info.pCommandBuffers = &graphics.immediate_submit_command_buffer->GetVkCommandBuffer(); + + if (vkQueueSubmit(graphics.immediate_submit_queue_->vk_queue_, 1, &submit_info, VK_NULL_HANDLE) != VK_SUCCESS) { + throw std::runtime_error("Failed to submit command buffer to graphics queue!"); + } - vkQueueSubmit(graphics.vk_graphics_queue_, 1, &submit_info, VK_NULL_HANDLE); - vkQueueWaitIdle(graphics.vk_graphics_queue_); + vkQueueWaitIdle(graphics.immediate_submit_queue_->vk_queue_); - vkFreeCommandBuffers(graphics.vk_device_, graphics.command_pool_->GetVkCommandPool(), 1, &command_buffer); + graphics.immediate_submit_command_buffer->Reset(); } -QueueFamilyIndices Graphics::GetQueueFamilyIndices() { +QueueFamilyIndices Platform::GetQueueFamilyIndices() { const auto& graphics = GetInstance(); return graphics.queue_family_indices_; } -int Graphics::GetMaxFramesInFlight() { +int Platform::GetMaxFramesInFlight() { const auto& graphics = GetInstance(); return graphics.max_frame_in_flight_; } -void Graphics::NotifyRecreateSwapChain() { +void Platform::NotifyRecreateSwapChain() { auto& graphics = GetInstance(); graphics.recreate_swap_chain_ = true; } -VkInstance Graphics::GetVkInstance() { +VkInstance Platform::GetVkInstance() { const auto& graphics = GetInstance(); return graphics.vk_instance_; } -VkPhysicalDevice Graphics::GetVkPhysicalDevice() { +VkPhysicalDevice Platform::GetVkPhysicalDevice() { const auto& graphics = GetInstance(); return graphics.vk_physical_device_; } -VkDevice Graphics::GetVkDevice() { +VkDevice Platform::GetVkDevice() { const auto& graphics = GetInstance(); return graphics.vk_device_; } -uint32_t Graphics::GetCurrentFrameIndex() { +uint32_t Platform::GetCurrentFrameIndex() { const auto& graphics = GetInstance(); return graphics.current_frame_index_; } -uint32_t Graphics::GetNextImageIndex() { +uint32_t Platform::GetNextImageIndex() { const auto& graphics = GetInstance(); return graphics.next_image_index_; } -VkCommandPool Graphics::GetVkCommandPool() { +VkCommandPool Platform::GetVkCommandPool() { const auto& graphics = GetInstance(); return graphics.command_pool_->GetVkCommandPool(); } -VkQueue Graphics::GetGraphicsVkQueue() { +const std::unique_ptr& Platform::GetMainQueue() { const auto& graphics = GetInstance(); - return graphics.vk_graphics_queue_; + return graphics.main_queue_; } -VkQueue Graphics::GetPresentVkQueue() { +const std::unique_ptr& Platform::GetImmediateSubmitQueue() { const auto& graphics = GetInstance(); - return graphics.vk_present_queue_; + return graphics.immediate_submit_queue_; } -VmaAllocator Graphics::GetVmaAllocator() { +const std::unique_ptr& Platform::GetPresentQueue() { + const auto& graphics = GetInstance(); + return graphics.present_queue_; +} + +VmaAllocator Platform::GetVmaAllocator() { const auto& graphics = GetInstance(); return graphics.vma_allocator_; } -const std::unique_ptr& Graphics::GetSwapchain() { +const std::shared_ptr& Platform::GetSwapchain() { const auto& graphics = GetInstance(); return graphics.swapchain_; } -const std::unique_ptr& Graphics::GetDescriptorPool() { +const std::unique_ptr& Platform::GetDescriptorPool() { const auto& graphics = GetInstance(); return graphics.descriptor_pool_; } -unsigned Graphics::GetSwapchainVersion() { +unsigned Platform::GetSwapchainVersion() { const auto& graphics = GetInstance(); return graphics.swapchain_version_; } -VkSurfaceFormatKHR Graphics::GetVkSurfaceFormat() { +VkSurfaceFormatKHR Platform::GetVkSurfaceFormat() { const auto& graphics = GetInstance(); return graphics.vk_surface_format_; } -const VkPhysicalDeviceProperties& Graphics::GetVkPhysicalDeviceProperties() { +const VkPhysicalDeviceProperties& Platform::GetVkPhysicalDeviceProperties() { const auto& graphics = GetInstance(); return graphics.vk_physical_device_properties_; } @@ -350,7 +368,7 @@ bool CheckDeviceExtensionSupport(const VkPhysicalDevice physical_device, for (const auto& extension : available_extensions) { required_extensions.erase(extension.extensionName); } -#ifndef NDEBUG +#ifdef GRAPHICS_VALIDATION for (const auto& extension : required_extensions) { EVOENGINE_ERROR("Extension " + extension + " is not supported by this device!"); } @@ -358,7 +376,7 @@ bool CheckDeviceExtensionSupport(const VkPhysicalDevice physical_device, return required_extensions.empty(); } -QueueFamilyIndices Graphics::FindQueueFamilies(const VkPhysicalDevice physical_device) const { +QueueFamilyIndices Platform::FindQueueFamilies(const VkPhysicalDevice physical_device) const { const auto window_layer = Application::GetLayer(); QueueFamilyIndices indices; @@ -370,8 +388,8 @@ QueueFamilyIndices Graphics::FindQueueFamilies(const VkPhysicalDevice physical_d int i = 0; for (const auto& queue_family : queue_families) { - if (queue_family.queueFlags & VK_QUEUE_GRAPHICS_BIT) { - indices.graphics_family = i; + if ((queue_family.queueFlags & VK_QUEUE_GRAPHICS_BIT) && (queue_family.queueFlags & VK_QUEUE_COMPUTE_BIT)) { + indices.graphics_and_compute_family = i; } VkBool32 present_support = false; if (window_layer) { @@ -389,7 +407,7 @@ QueueFamilyIndices Graphics::FindQueueFamilies(const VkPhysicalDevice physical_d return indices; } -SwapChainSupportDetails Graphics::QuerySwapChainSupport(const VkPhysicalDevice physical_device) const { +SwapChainSupportDetails Platform::QuerySwapChainSupport(const VkPhysicalDevice physical_device) const { SwapChainSupportDetails details; vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, vk_surface_, &details.capabilities); @@ -414,7 +432,7 @@ SwapChainSupportDetails Graphics::QuerySwapChainSupport(const VkPhysicalDevice p return details; } -bool Graphics::IsDeviceSuitable(VkPhysicalDevice physical_device, +bool Platform::IsDeviceSuitable(VkPhysicalDevice physical_device, const std::vector& required_device_extensions) const { if (!CheckDeviceExtensionSupport(physical_device, required_device_extensions)) return false; @@ -430,7 +448,7 @@ bool Graphics::IsDeviceSuitable(VkPhysicalDevice physical_device, return true; } -void Graphics::CreateInstance() { +void Platform::CreateInstance() { auto application_info = Application::GetApplicationInfo(); const auto window_layer = Application::GetLayer(); const auto editor_layer = Application::GetLayer(); @@ -497,7 +515,7 @@ void Graphics::CreateInstance() { required_extensions.emplace_back(glfw_extensions[i]); } } -#ifndef NDEBUG +#ifdef GRAPHICS_VALIDATION required_extensions.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); #endif instance_create_info.enabledExtensionCount = static_cast(required_extensions.size()); @@ -509,7 +527,7 @@ void Graphics::CreateInstance() { vkEnumerateInstanceLayerProperties(&layer_count, nullptr); vk_layers_.resize(layer_count); vkEnumerateInstanceLayerProperties(&layer_count, vk_layers_.data()); -#ifndef NDEBUG +#ifdef GRAPHICS_VALIDATION if (!CheckLayerSupport("VK_LAYER_KHRONOS_validation")) { throw std::runtime_error("Validation layers requested, but not available!"); } @@ -532,7 +550,7 @@ void Graphics::CreateInstance() { #pragma endregion } -void Graphics::CreateSurface() { +void Platform::CreateSurface() { const auto window_layer = Application::GetLayer(); #pragma region Surface if (window_layer) { @@ -543,9 +561,9 @@ void Graphics::CreateSurface() { #pragma endregion } -void Graphics::CreateDebugMessenger() { +void Platform::CreateDebugMessenger() { #pragma region Debug Messenger -#ifndef NDEBUG +#ifdef GRAPHICS_VALIDATION VkDebugUtilsMessengerCreateInfoEXT debug_utils_messenger_create_info{}; PopulateDebugMessengerCreateInfo(debug_utils_messenger_create_info); if (CreateDebugUtilsMessengerExt(vk_instance_, &debug_utils_messenger_create_info, nullptr, &vk_debug_messenger_) != @@ -579,7 +597,7 @@ int RateDeviceSuitability(const VkPhysicalDevice physical_device) { return score; } -void Graphics::SelectPhysicalDevice() { +void Platform::SelectPhysicalDevice() { if (const auto window_layer = Application::GetLayer()) { required_device_extensions_.emplace_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); } @@ -662,7 +680,7 @@ void Graphics::SelectPhysicalDevice() { } } -void Graphics::CreateLogicalDevice() { +void Platform::CreateLogicalDevice() { std::vector c_required_device_extensions; c_required_device_extensions.reserve(required_device_extensions_.size()); for (const auto& i : required_device_extensions_) @@ -767,18 +785,33 @@ void Graphics::CreateLogicalDevice() { #pragma region Queues requirement queue_family_indices_ = FindQueueFamilies(vk_physical_device_); std::vector queue_create_infos; - std::set unique_queue_families; - if (queue_family_indices_.graphics_family.has_value()) - unique_queue_families.emplace(queue_family_indices_.graphics_family.value()); - if (queue_family_indices_.present_family.has_value()) - unique_queue_families.emplace(queue_family_indices_.present_family.value()); - float queue_priority = 1.0f; - for (uint32_t queue_family : unique_queue_families) { + std::map>> unique_queue_families; + if (queue_family_indices_.graphics_and_compute_family.has_value()) { + if (unique_queue_families.find(queue_family_indices_.graphics_and_compute_family.value()) == unique_queue_families.end()) { + unique_queue_families[queue_family_indices_.graphics_and_compute_family.value()] = + std::make_pair(0, std::vector()); + } + unique_queue_families[queue_family_indices_.graphics_and_compute_family.value()].first += 2; + unique_queue_families[queue_family_indices_.graphics_and_compute_family.value()].second.emplace_back(1.f); + unique_queue_families[queue_family_indices_.graphics_and_compute_family.value()].second.emplace_back(0.f); + + } + if (queue_family_indices_.present_family.has_value()) { + if (unique_queue_families.find(queue_family_indices_.present_family.value()) == + unique_queue_families.end()) { + unique_queue_families[queue_family_indices_.present_family.value()] = + std::make_pair(0, std::vector()); + } + unique_queue_families[queue_family_indices_.present_family.value()].first += 1; + unique_queue_families[queue_family_indices_.present_family.value()].second.emplace_back(0.f); + } + + for (auto& queue_family : unique_queue_families) { VkDeviceQueueCreateInfo queue_create_info{}; queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; - queue_create_info.queueFamilyIndex = queue_family; - queue_create_info.queueCount = 1; - queue_create_info.pQueuePriorities = &queue_priority; + queue_create_info.queueFamilyIndex = queue_family.first; + queue_create_info.queueCount = queue_family.second.first; + queue_create_info.pQueuePriorities = queue_family.second.second.data(); queue_create_infos.push_back(queue_create_info); } device_create_info.queueCreateInfoCount = static_cast(queue_create_infos.size()); @@ -796,15 +829,26 @@ void Graphics::CreateLogicalDevice() { if (vkCreateDevice(vk_physical_device_, &device_create_info, nullptr, &vk_device_) != VK_SUCCESS) { throw std::runtime_error("Failed to create logical device!"); } - if (queue_family_indices_.graphics_family.has_value()) - vkGetDeviceQueue(vk_device_, queue_family_indices_.graphics_family.value(), 0, &vk_graphics_queue_); - if (queue_family_indices_.present_family.has_value()) - vkGetDeviceQueue(vk_device_, queue_family_indices_.present_family.value(), 0, &vk_present_queue_); - + if (queue_family_indices_.graphics_and_compute_family.has_value()) { + main_queue_ = std::make_unique(); + immediate_submit_queue_ = std::make_unique(); + vkGetDeviceQueue(vk_device_, queue_family_indices_.graphics_and_compute_family.value(), 0, + &immediate_submit_queue_->vk_queue_); + vkGetDeviceQueue(vk_device_, queue_family_indices_.graphics_and_compute_family.value(), 1, + &main_queue_->vk_queue_); + } + if (queue_family_indices_.present_family.has_value()) { + present_queue_ = std::make_unique(); + if (queue_family_indices_.graphics_and_compute_family.value() != queue_family_indices_.present_family.value()) { + vkGetDeviceQueue(vk_device_, queue_family_indices_.present_family.value(), 0, &present_queue_->vk_queue_); + }else { + vkGetDeviceQueue(vk_device_, queue_family_indices_.present_family.value(), 2, &present_queue_->vk_queue_); + } + } #pragma endregion } -void Graphics::EverythingBarrier(VkCommandBuffer command_buffer) { +void Platform::EverythingBarrier(const VkCommandBuffer vk_command_buffer) { VkMemoryBarrier2 memory_barrier{}; memory_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER_2; memory_barrier.srcStageMask = memory_barrier.dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; @@ -814,10 +858,10 @@ void Graphics::EverythingBarrier(VkCommandBuffer command_buffer) { dependency_info.memoryBarrierCount = 1; dependency_info.pMemoryBarriers = &memory_barrier; - vkCmdPipelineBarrier2(command_buffer, &dependency_info); + vkCmdPipelineBarrier2(vk_command_buffer, &dependency_info); } -void Graphics::SetupVmaAllocator() { +void Platform::SetupVmaAllocator() { #pragma region VMA VmaVulkanFunctions vulkan_functions{}; vulkan_functions.vkGetInstanceProcAddr = vkGetInstanceProcAddr; @@ -847,7 +891,7 @@ void Graphics::SetupVmaAllocator() { #pragma endregion } -std::string Graphics::StringifyResultVk(const VkResult& result) { +std::string Platform::StringifyResultVk(const VkResult& result) { switch (result) { case VK_SUCCESS: return "Success"; @@ -902,7 +946,7 @@ std::string Graphics::StringifyResultVk(const VkResult& result) { } } -void Graphics::CheckVk(const VkResult& result) { +void Platform::CheckVk(const VkResult& result) { if (result >= 0) { return; } @@ -910,22 +954,7 @@ void Graphics::CheckVk(const VkResult& result) { throw std::runtime_error("Vulkan error: " + failure); } -void Graphics::AppendCommands(const std::function& action) { - auto& graphics = GetInstance(); - const unsigned command_buffer_index = graphics.used_command_buffer_size_; - if (command_buffer_index >= graphics.command_buffer_pool_[graphics.current_frame_index_].size()) { - graphics.command_buffer_pool_[graphics.current_frame_index_].emplace_back(); - graphics.command_buffer_pool_[graphics.current_frame_index_].back().Allocate(); - } - auto& command_buffer = graphics.command_buffer_pool_[graphics.current_frame_index_][command_buffer_index]; - command_buffer.Begin(); - GraphicsPipelineStates graphics_global_state{}; - action(command_buffer.GetVkCommandBuffer()); - command_buffer.End(); - graphics.used_command_buffer_size_++; -} - -void Graphics::CreateSwapChain() { +void Platform::CreateSwapChain() { auto application_info = Application::GetApplicationInfo(); auto window_layer = Application::GetLayer(); SwapChainSupportDetails swap_chain_support_details = QuerySwapChainSupport(vk_physical_device_); @@ -996,10 +1025,10 @@ void Graphics::CreateSwapChain() { */ swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; - uint32_t queue_family_indices[] = {queue_family_indices_.graphics_family.value(), + uint32_t queue_family_indices[] = {queue_family_indices_.graphics_and_compute_family.value(), queue_family_indices_.present_family.value()}; - if (queue_family_indices_.graphics_family != queue_family_indices_.present_family) { + if (queue_family_indices_.graphics_and_compute_family != queue_family_indices_.present_family) { swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; swapchain_create_info.queueFamilyIndexCount = 2; swapchain_create_info.pQueueFamilyIndices = queue_family_indices; @@ -1021,7 +1050,7 @@ void Graphics::CreateSwapChain() { if (extent.width == 0) { EVOENGINE_ERROR("WRONG") } - swapchain_ = std::make_unique(swapchain_create_info); + swapchain_ = std::make_shared(swapchain_create_info); VkSemaphoreCreateInfo semaphore_create_info{}; semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; @@ -1033,7 +1062,7 @@ void Graphics::CreateSwapChain() { swapchain_version_++; } -void Graphics::CreateSwapChainSyncObjects() { +void Platform::CreateSwapChainSyncObjects() { VkSemaphoreCreateInfo semaphore_create_info{}; semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; VkFenceCreateInfo fence_create_info{}; @@ -1047,12 +1076,12 @@ void Graphics::CreateSwapChainSyncObjects() { } } -void Graphics::RecreateSwapChain() { +void Platform::RecreateSwapChain() { vkDeviceWaitIdle(vk_device_); CreateSwapChain(); } -void Graphics::OnDestroy() { +void Platform::OnDestroy() { const auto& window_layer = Application::GetLayer(); if (const auto& editor_layer = Application::GetLayer(); window_layer && editor_layer) { ImGui_ImplVulkan_Shutdown(); @@ -1084,7 +1113,7 @@ void Graphics::OnDestroy() { #pragma endregion } -void Graphics::SwapChainSwapImage() { +void Platform::SwapChainSwapImage() { if (const auto& window_layer = Application::GetLayer(); window_layer->window_size_.x == 0 || window_layer->window_size_.y == 0) return; @@ -1111,55 +1140,35 @@ void Graphics::SwapChainSwapImage() { vkResetFences(vk_device_, 1, in_flight_fences); } -void Graphics::SubmitPresent() { +void Platform::SubmitPresent() { if (const auto& window_layer = Application::GetLayer(); window_layer->window_size_.x == 0 || window_layer->window_size_.y == 0) return; - VkSubmitInfo submit_info{}; - submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - - const VkSemaphore wait_semaphores[] = {image_available_semaphores_[current_frame_index_]->GetVkSemaphore()}; - constexpr VkPipelineStageFlags wait_stages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT}; - submit_info.waitSemaphoreCount = 1; - submit_info.pWaitSemaphores = wait_semaphores; - submit_info.pWaitDstStageMask = wait_stages; - std::vector command_buffers; + std::vector> command_buffers; command_buffers.reserve(used_command_buffer_size_); for (int i = 0; i < used_command_buffer_size_; i++) { - command_buffers.emplace_back(command_buffer_pool_[current_frame_index_][i].GetVkCommandBuffer()); - } - - submit_info.commandBufferCount = command_buffers.size(); - submit_info.pCommandBuffers = command_buffers.data(); - - const VkSemaphore signal_semaphores[] = {render_finished_semaphores_[current_frame_index_]->GetVkSemaphore()}; - submit_info.signalSemaphoreCount = 1; - submit_info.pSignalSemaphores = signal_semaphores; - if (vkQueueSubmit(vk_graphics_queue_, 1, &submit_info, in_flight_fences_[current_frame_index_]->GetVkFence()) != - VK_SUCCESS) { - throw std::runtime_error("failed to submit draw command buffer!"); + command_buffers.emplace_back(command_buffer_pool_[current_frame_index_][i]); } - VkPresentInfoKHR present_info{}; - present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; - - present_info.waitSemaphoreCount = 1; - present_info.pWaitSemaphores = signal_semaphores; + std::vector, VkPipelineStageFlags>> wait_semaphores; + std::vector> signal_semaphores; - const VkSwapchainKHR swap_chains[] = {swapchain_->GetVkSwapchain()}; - present_info.swapchainCount = 1; - present_info.pSwapchains = swap_chains; + wait_semaphores.emplace_back(image_available_semaphores_[current_frame_index_], + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT); + signal_semaphores.emplace_back(render_finished_semaphores_[current_frame_index_]); - present_info.pImageIndices = &next_image_index_; + main_queue_->Submit(command_buffers, wait_semaphores, signal_semaphores, in_flight_fences_[current_frame_index_]); - vkQueuePresentKHR(vk_present_queue_, &present_info); + std::vector, uint32_t>> targets; + targets.emplace_back(swapchain_, next_image_index_); + present_queue_->Present(signal_semaphores, targets); current_frame_index_ = (current_frame_index_ + 1) % max_frame_in_flight_; } -void Graphics::WaitForCommandsComplete() const { +void Platform::WaitForCommandsComplete() const { vkDeviceWaitIdle(vk_device_); GeometryStorage::DeviceSync(); TextureStorage::DeviceSync(); @@ -1168,43 +1177,27 @@ void Graphics::WaitForCommandsComplete() const { vkResetFences(vk_device_, 1, in_flight_fences); } -void Graphics::Submit() { - VkSubmitInfo submit_info{}; - submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - submit_info.waitSemaphoreCount = 0; - submit_info.pWaitSemaphores = nullptr; - submit_info.pWaitDstStageMask = nullptr; - - std::vector command_buffers; - +void Platform::Submit() { + std::vector> command_buffers; command_buffers.reserve(used_command_buffer_size_); for (int i = 0; i < used_command_buffer_size_; i++) { - command_buffers.emplace_back(command_buffer_pool_[current_frame_index_][i].GetVkCommandBuffer()); - } - - submit_info.commandBufferCount = command_buffers.size(); - submit_info.pCommandBuffers = command_buffers.data(); - - submit_info.signalSemaphoreCount = 0; - submit_info.pSignalSemaphores = nullptr; - if (vkQueueSubmit(vk_graphics_queue_, 1, &submit_info, in_flight_fences_[current_frame_index_]->GetVkFence()) != - VK_SUCCESS) { - throw std::runtime_error("failed to submit draw command buffer!"); + command_buffers.emplace_back(command_buffer_pool_[current_frame_index_][i]); } + main_queue_->Submit(command_buffers, {}, {}, in_flight_fences_[current_frame_index_]); current_frame_index_ = (current_frame_index_ + 1) % max_frame_in_flight_; } -void Graphics::ResetCommandBuffers() { +void Platform::ResetCommandBuffers() { used_command_buffer_size_ = 0; - for (auto& command_buffer : command_buffer_pool_[current_frame_index_]) { - if (command_buffer.status_ == CommandBufferStatus::Recorded) - command_buffer.Reset(); + for (const auto& command_buffer : command_buffer_pool_[current_frame_index_]) { + if (command_buffer->status_ == CommandBufferStatus::Recorded) + command_buffer->Reset(); } } #pragma endregion -void Graphics::Initialize() { +void Platform::Initialize() { auto& graphics = GetInstance(); #pragma region volk if (volkInitialize() != VK_SUCCESS) { @@ -1231,12 +1224,12 @@ void Graphics::Initialize() { } } } - if (graphics.queue_family_indices_.graphics_family.has_value()) { + if (graphics.queue_family_indices_.graphics_and_compute_family.has_value()) { #pragma region Command pool VkCommandPoolCreateInfo pool_info{}; pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; - pool_info.queueFamilyIndex = graphics.queue_family_indices_.graphics_family.value(); + pool_info.queueFamilyIndex = graphics.queue_family_indices_.graphics_and_compute_family.value(); graphics.command_pool_ = std::make_unique(pool_info); #pragma endregion graphics.used_command_buffer_size_ = 0; @@ -1292,8 +1285,8 @@ void Graphics::Initialize() { init_info.Instance = graphics.vk_instance_; init_info.PhysicalDevice = graphics.vk_physical_device_; init_info.Device = graphics.vk_device_; - init_info.QueueFamily = graphics.queue_family_indices_.graphics_family.value(); - init_info.Queue = graphics.vk_graphics_queue_; + init_info.QueueFamily = graphics.queue_family_indices_.graphics_and_compute_family.value(); + init_info.Queue = graphics.main_queue_->vk_queue_; init_info.PipelineCache = VK_NULL_HANDLE; init_info.DescriptorPool = graphics.descriptor_pool_->GetVkDescriptorPool(); init_info.MinImageCount = graphics.swapchain_->GetAllImageViews().size(); @@ -1308,9 +1301,12 @@ void Graphics::Initialize() { // init_info.ColorAttachmentFormat = graphics.swapchain_->GetImageFormat(); ImGui_ImplVulkan_LoadFunctions([](const char* function_name, void*) { - return vkGetInstanceProcAddr(Graphics::GetVkInstance(), function_name); + return vkGetInstanceProcAddr(GetVkInstance(), function_name); }); ImGui_ImplVulkan_Init(&init_info); + + + graphics.immediate_submit_command_buffer = std::make_shared(); } GeometryStorage::Initialize(); @@ -1321,18 +1317,18 @@ void Graphics::Initialize() { graphics.strands_segments.resize(graphics.max_frame_in_flight_); } -void Graphics::PostResourceLoadingInitialization() { +void Platform::PostResourceLoadingInitialization() { const auto& graphics = GetInstance(); graphics.PrepareDescriptorSetLayouts(); graphics.CreateGraphicsPipelines(); } -void Graphics::Destroy() { +void Platform::Destroy() { auto& graphics = GetInstance(); graphics.OnDestroy(); } -void Graphics::PreUpdate() { +void Platform::PreUpdate() { auto& graphics = GetInstance(); const auto window_layer = Application::GetLayer(); const auto render_layer = Application::GetLayer(); @@ -1361,7 +1357,7 @@ void Graphics::PreUpdate() { } } -void Graphics::LateUpdate() { +void Platform::LateUpdate() { auto& graphics = GetInstance(); if (const auto window_layer = Application::GetLayer()) { if (Application::GetLayer() && !Application::GetLayer()) { @@ -1369,10 +1365,11 @@ void Graphics::LateUpdate() { if (const auto main_camera = scene->main_camera.Get(); main_camera->IsEnabled() && main_camera->rendered_) { const auto& render_texture_present = graphics.graphics_pipelines_["RENDER_TEXTURE_PRESENT"]; - AppendCommands([&](const VkCommandBuffer command_buffer) { - EverythingBarrier(command_buffer); - TransitImageLayout(command_buffer, graphics.swapchain_->GetVkImage(), graphics.swapchain_->GetImageFormat(), - 1, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR); + RecordCommandsMainQueue([&](VkCommandBuffer vk_command_buffer) { + EverythingBarrier(vk_command_buffer); + TransitImageLayout(vk_command_buffer, graphics.swapchain_->GetVkImage(), + graphics.swapchain_->GetImageFormat(), 1, VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR); constexpr VkClearValue clear_color = {{{0.0f, 0.0f, 0.0f, 1.0f}}}; VkRect2D render_area; @@ -1417,18 +1414,19 @@ void Graphics::LateUpdate() { } render_texture_present->states.depth_test = VK_FALSE; render_texture_present->states.depth_write = VK_FALSE; - vkCmdBeginRendering(command_buffer, &render_info); + vkCmdBeginRendering(vk_command_buffer, &render_info); // From main camera to swap chain. - render_texture_present->Bind(command_buffer); + render_texture_present->Bind(vk_command_buffer); render_texture_present->BindDescriptorSet( - command_buffer, 0, main_camera->GetRenderTexture()->descriptor_set_->GetVkDescriptorSet()); + vk_command_buffer, 0, main_camera->GetRenderTexture()->descriptor_set_->GetVkDescriptorSet()); const auto mesh = Resources::GetResource("PRIMITIVE_TEX_PASS_THROUGH"); - GeometryStorage::BindVertices(command_buffer); - mesh->DrawIndexed(command_buffer, render_texture_present->states, 1); - vkCmdEndRendering(command_buffer); - TransitImageLayout(command_buffer, graphics.swapchain_->GetVkImage(), graphics.swapchain_->GetImageFormat(), - 1, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR); + GeometryStorage::BindVertices(vk_command_buffer); + mesh->DrawIndexed(vk_command_buffer, render_texture_present->states, 1); + vkCmdEndRendering(vk_command_buffer); + TransitImageLayout(vk_command_buffer, graphics.swapchain_->GetVkImage(), + graphics.swapchain_->GetImageFormat(), 1, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR, + VK_IMAGE_LAYOUT_PRESENT_SRC_KHR); }); } } @@ -1439,7 +1437,7 @@ void Graphics::LateUpdate() { } } -bool Graphics::CheckExtensionSupport(const std::string& extension_name) { +bool Platform::CheckExtensionSupport(const std::string& extension_name) { const auto& graphics = GetInstance(); for (const auto& layer_properties : graphics.vk_layers_) { @@ -1450,7 +1448,7 @@ bool Graphics::CheckExtensionSupport(const std::string& extension_name) { return false; } -bool Graphics::CheckLayerSupport(const std::string& layer_name) { +bool Platform::CheckLayerSupport(const std::string& layer_name) { const auto& graphics = GetInstance(); for (const auto& layer_properties : graphics.vk_layers_) { if (strcmp(layer_name.c_str(), layer_properties.layerName) == 0) { diff --git a/EvoEngine_SDK/src/PostProcessingStack.cpp b/EvoEngine_SDK/src/PostProcessingStack.cpp index 79ed8f9..980cded 100644 --- a/EvoEngine_SDK/src/PostProcessingStack.cpp +++ b/EvoEngine_SDK/src/PostProcessingStack.cpp @@ -3,7 +3,7 @@ #include "Application.hpp" #include "Camera.hpp" #include "GeometryStorage.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "Mesh.hpp" #include "RenderLayer.hpp" #include "Resources.hpp" @@ -26,12 +26,12 @@ void PostProcessingStack::OnCreate() { render_texture1_ = std::make_unique(render_texture_create_info); render_texture2_ = std::make_unique(render_texture_create_info); - ssr_reflect_descriptor_set_ = std::make_shared(Graphics::GetDescriptorSetLayout("SSR_REFLECT_LAYOUT")); + ssr_reflect_descriptor_set_ = std::make_shared(Platform::GetDescriptorSetLayout("SSR_REFLECT_LAYOUT")); ssr_blur_horizontal_descriptor_set_ = - std::make_shared(Graphics::GetDescriptorSetLayout("RENDER_TEXTURE_PRESENT_LAYOUT")); + std::make_shared(Platform::GetDescriptorSetLayout("RENDER_TEXTURE_PRESENT_LAYOUT")); ssr_blur_vertical_descriptor_set_ = - std::make_shared(Graphics::GetDescriptorSetLayout("RENDER_TEXTURE_PRESENT_LAYOUT")); - ssr_combine_descriptor_set_ = std::make_shared(Graphics::GetDescriptorSetLayout("SSR_COMBINE_LAYOUT")); + std::make_shared(Platform::GetDescriptorSetLayout("RENDER_TEXTURE_PRESENT_LAYOUT")); + ssr_combine_descriptor_set_ = std::make_shared(Platform::GetDescriptorSetLayout("SSR_COMBINE_LAYOUT")); } bool PostProcessingStack::OnInspect(const std::shared_ptr& editor_layer) { @@ -55,7 +55,7 @@ void PostProcessingStack::Process(const std::shared_ptr& target_camera) render_texture0_->Resize({size.x, size.y, 1}); render_texture1_->Resize({size.x, size.y, 1}); render_texture2_->Resize({size.x, size.y, 1}); - const auto current_frame_index = Graphics::GetCurrentFrameIndex(); + const auto current_frame_index = Platform::GetCurrentFrameIndex(); if (ssao) { } if (ssr) { @@ -100,7 +100,7 @@ void PostProcessingStack::Process(const std::shared_ptr& target_camera) ssr_combine_descriptor_set_->UpdateImageDescriptorBinding(1, image_info); } - Graphics::AppendCommands([&](VkCommandBuffer command_buffer) { + Platform::RecordCommandsMainQueue([&](const VkCommandBuffer vk_command_buffer) { #pragma region Viewport and scissor VkRect2D render_area; render_area.offset = {0, 0}; @@ -123,7 +123,7 @@ void PostProcessingStack::Process(const std::shared_ptr& target_camera) render_info.renderArea = render_area; render_info.layerCount = 1; #pragma endregion - GeometryStorage::BindVertices(command_buffer); + GeometryStorage::BindVertices(vk_command_buffer); { SsrPushConstant push_constant{}; push_constant.num_binary_search_steps = ssr_settings.num_binary_search_steps; @@ -139,14 +139,14 @@ void PostProcessingStack::Process(const std::shared_ptr& target_camera) render_info2.pDepthAttachment = VK_NULL_HANDLE; // Input texture - target_camera->TransitGBufferImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - target_camera->render_texture_->GetDepthImage()->TransitImageLayout(command_buffer, + target_camera->TransitGBufferImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + target_camera->render_texture_->GetDepthImage()->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - target_camera->render_texture_->GetColorImage()->TransitImageLayout(command_buffer, + target_camera->render_texture_->GetColorImage()->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); // Attachments - render_texture0_->GetColorImage()->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); - render_texture1_->GetColorImage()->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + render_texture0_->GetColorImage()->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + render_texture1_->GetColorImage()->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); render_texture0_->AppendColorAttachmentInfos(color_attachment_infos, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE); render_texture1_->AppendColorAttachmentInfos(color_attachment_infos, VK_ATTACHMENT_LOAD_OP_DONT_CARE, @@ -155,8 +155,8 @@ void PostProcessingStack::Process(const std::shared_ptr& target_camera) render_info2.pColorAttachments = color_attachment_infos.data(); { - const auto& ssr_reflect_pipeline = Graphics::GetGraphicsPipeline("SSR_REFLECT"); - vkCmdBeginRendering(command_buffer, &render_info2); + const auto& ssr_reflect_pipeline = Platform::GetGraphicsPipeline("SSR_REFLECT"); + vkCmdBeginRendering(vk_command_buffer, &render_info2); ssr_reflect_pipeline->states.depth_test = false; ssr_reflect_pipeline->states.color_blend_attachment_states.clear(); ssr_reflect_pipeline->states.color_blend_attachment_states.resize(color_attachment_infos.size()); @@ -165,29 +165,29 @@ void PostProcessingStack::Process(const std::shared_ptr& target_camera) VK_COLOR_COMPONENT_A_BIT; i.blendEnable = VK_FALSE; } - ssr_reflect_pipeline->Bind(command_buffer); + ssr_reflect_pipeline->Bind(vk_command_buffer); ssr_reflect_pipeline->BindDescriptorSet( - command_buffer, 0, render_layer->per_frame_descriptor_sets_[current_frame_index]->GetVkDescriptorSet()); - ssr_reflect_pipeline->BindDescriptorSet(command_buffer, 1, ssr_reflect_descriptor_set_->GetVkDescriptorSet()); + vk_command_buffer, 0, render_layer->per_frame_descriptor_sets_[current_frame_index]->GetVkDescriptorSet()); + ssr_reflect_pipeline->BindDescriptorSet(vk_command_buffer, 1, ssr_reflect_descriptor_set_->GetVkDescriptorSet()); ssr_reflect_pipeline->states.view_port = viewport; ssr_reflect_pipeline->states.scissor = scissor; - ssr_reflect_pipeline->PushConstant(command_buffer, 0, push_constant); - mesh->DrawIndexed(command_buffer, ssr_reflect_pipeline->states, 1); - vkCmdEndRendering(command_buffer); + ssr_reflect_pipeline->PushConstant(vk_command_buffer, 0, push_constant); + mesh->DrawIndexed(vk_command_buffer, ssr_reflect_pipeline->states, 1); + vkCmdEndRendering(vk_command_buffer); } // Input texture - render_texture1_->GetColorImage()->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + render_texture1_->GetColorImage()->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); // Attachments color_attachment_infos.clear(); - render_texture2_->GetColorImage()->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + render_texture2_->GetColorImage()->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); render_texture2_->AppendColorAttachmentInfos(color_attachment_infos, VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE); render_info2.colorAttachmentCount = color_attachment_infos.size(); render_info2.pColorAttachments = color_attachment_infos.data(); { - const auto& ssr_blur_pipeline = Graphics::GetGraphicsPipeline("SSR_BLUR"); - vkCmdBeginRendering(command_buffer, &render_info2); + const auto& ssr_blur_pipeline = Platform::GetGraphicsPipeline("SSR_BLUR"); + vkCmdBeginRendering(vk_command_buffer, &render_info2); ssr_blur_pipeline->states.depth_test = false; ssr_blur_pipeline->states.color_blend_attachment_states.clear(); ssr_blur_pipeline->states.color_blend_attachment_states.resize(color_attachment_infos.size()); @@ -196,28 +196,28 @@ void PostProcessingStack::Process(const std::shared_ptr& target_camera) VK_COLOR_COMPONENT_A_BIT; i.blendEnable = VK_FALSE; } - ssr_blur_pipeline->Bind(command_buffer); - ssr_blur_pipeline->BindDescriptorSet(command_buffer, 0, + ssr_blur_pipeline->Bind(vk_command_buffer); + ssr_blur_pipeline->BindDescriptorSet(vk_command_buffer, 0, ssr_blur_horizontal_descriptor_set_->GetVkDescriptorSet()); ssr_blur_pipeline->states.view_port = viewport; ssr_blur_pipeline->states.scissor = scissor; push_constant.horizontal = true; - ssr_blur_pipeline->PushConstant(command_buffer, 0, push_constant); - mesh->DrawIndexed(command_buffer, ssr_blur_pipeline->states, 1); - vkCmdEndRendering(command_buffer); + ssr_blur_pipeline->PushConstant(vk_command_buffer, 0, push_constant); + mesh->DrawIndexed(vk_command_buffer, ssr_blur_pipeline->states, 1); + vkCmdEndRendering(vk_command_buffer); } // Input texture - render_texture2_->GetColorImage()->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + render_texture2_->GetColorImage()->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); // Attachments color_attachment_infos.clear(); - render_texture1_->GetColorImage()->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + render_texture1_->GetColorImage()->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); render_texture1_->AppendColorAttachmentInfos(color_attachment_infos, VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE); render_info2.colorAttachmentCount = color_attachment_infos.size(); render_info2.pColorAttachments = color_attachment_infos.data(); { - const auto& ssr_blur_pipeline = Graphics::GetGraphicsPipeline("SSR_BLUR"); - vkCmdBeginRendering(command_buffer, &render_info2); + const auto& ssr_blur_pipeline = Platform::GetGraphicsPipeline("SSR_BLUR"); + vkCmdBeginRendering(vk_command_buffer, &render_info2); ssr_blur_pipeline->states.depth_test = false; ssr_blur_pipeline->states.color_blend_attachment_states.clear(); ssr_blur_pipeline->states.color_blend_attachment_states.resize(color_attachment_infos.size()); @@ -226,30 +226,30 @@ void PostProcessingStack::Process(const std::shared_ptr& target_camera) VK_COLOR_COMPONENT_A_BIT; i.blendEnable = VK_FALSE; } - ssr_blur_pipeline->Bind(command_buffer); - ssr_blur_pipeline->BindDescriptorSet(command_buffer, 0, + ssr_blur_pipeline->Bind(vk_command_buffer); + ssr_blur_pipeline->BindDescriptorSet(vk_command_buffer, 0, ssr_blur_vertical_descriptor_set_->GetVkDescriptorSet()); ssr_blur_pipeline->states.view_port = viewport; ssr_blur_pipeline->states.scissor = scissor; push_constant.horizontal = false; - ssr_blur_pipeline->PushConstant(command_buffer, 0, push_constant); - mesh->DrawIndexed(command_buffer, ssr_blur_pipeline->states, 1); - vkCmdEndRendering(command_buffer); + ssr_blur_pipeline->PushConstant(vk_command_buffer, 0, push_constant); + mesh->DrawIndexed(vk_command_buffer, ssr_blur_pipeline->states, 1); + vkCmdEndRendering(vk_command_buffer); } // Input texture - render_texture0_->GetColorImage()->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - render_texture1_->GetColorImage()->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + render_texture0_->GetColorImage()->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + render_texture1_->GetColorImage()->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); // Attachments color_attachment_infos.clear(); - target_camera->render_texture_->GetColorImage()->TransitImageLayout(command_buffer, + target_camera->render_texture_->GetColorImage()->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); target_camera->render_texture_->AppendColorAttachmentInfos( color_attachment_infos, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE); render_info2.colorAttachmentCount = color_attachment_infos.size(); render_info2.pColorAttachments = color_attachment_infos.data(); { - const auto& ssr_combine_pipeline = Graphics::GetGraphicsPipeline("SSR_COMBINE"); - vkCmdBeginRendering(command_buffer, &render_info2); + const auto& ssr_combine_pipeline = Platform::GetGraphicsPipeline("SSR_COMBINE"); + vkCmdBeginRendering(vk_command_buffer, &render_info2); ssr_combine_pipeline->states.depth_test = false; ssr_combine_pipeline->states.color_blend_attachment_states.clear(); ssr_combine_pipeline->states.color_blend_attachment_states.resize(color_attachment_infos.size()); @@ -258,13 +258,13 @@ void PostProcessingStack::Process(const std::shared_ptr& target_camera) VK_COLOR_COMPONENT_A_BIT; i.blendEnable = VK_FALSE; } - ssr_combine_pipeline->Bind(command_buffer); - ssr_combine_pipeline->BindDescriptorSet(command_buffer, 0, ssr_combine_descriptor_set_->GetVkDescriptorSet()); + ssr_combine_pipeline->Bind(vk_command_buffer); + ssr_combine_pipeline->BindDescriptorSet(vk_command_buffer, 0, ssr_combine_descriptor_set_->GetVkDescriptorSet()); ssr_combine_pipeline->states.view_port = viewport; ssr_combine_pipeline->states.scissor = scissor; - ssr_combine_pipeline->PushConstant(command_buffer, 0, push_constant); - mesh->DrawIndexed(command_buffer, ssr_combine_pipeline->states, 1); - vkCmdEndRendering(command_buffer); + ssr_combine_pipeline->PushConstant(vk_command_buffer, 0, push_constant); + mesh->DrawIndexed(vk_command_buffer, ssr_combine_pipeline->states, 1); + vkCmdEndRendering(vk_command_buffer); } } }); diff --git a/EvoEngine_SDK/src/ReflectionProbe.cpp b/EvoEngine_SDK/src/ReflectionProbe.cpp index 06bae88..69827de 100644 --- a/EvoEngine_SDK/src/ReflectionProbe.cpp +++ b/EvoEngine_SDK/src/ReflectionProbe.cpp @@ -15,10 +15,10 @@ void ReflectionProbe::Initialize(uint32_t resolution) { cubemap_->Initialize(resolution, mip_levels); - Graphics::ImmediateSubmit([&](const VkCommandBuffer command_buffer) { - cubemap_->RefStorage().image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); - cubemap_->RefStorage().image->GenerateMipmaps(command_buffer); - cubemap_->RefStorage().image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { + cubemap_->RefStorage().image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + cubemap_->RefStorage().image->GenerateMipmaps(vk_command_buffer); + cubemap_->RefStorage().image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); }); for (int i = 0; i < 6; i++) { @@ -28,7 +28,7 @@ void ReflectionProbe::Initialize(uint32_t resolution) { view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; view_info.image = cubemap_->RefStorage().image->GetVkImage(); view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; - view_info.format = Graphics::Constants::texture_2d; + view_info.format = Platform::Constants::texture_2d; view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; view_info.subresourceRange.baseMipLevel = mip; view_info.subresourceRange.levelCount = 1; @@ -61,7 +61,7 @@ void ReflectionProbe::ConstructFromCubemap(const std::shared_ptr& targe depth_image_info.extent.depth = 1; depth_image_info.mipLevels = 1; depth_image_info.arrayLayers = 1; - depth_image_info.format = Graphics::Constants::shadow_map; + depth_image_info.format = Platform::Constants::shadow_map; depth_image_info.tiling = VK_IMAGE_TILING_OPTIMAL; depth_image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; depth_image_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; @@ -69,15 +69,15 @@ void ReflectionProbe::ConstructFromCubemap(const std::shared_ptr& targe depth_image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; const auto depth_image = std::make_shared(depth_image_info); - Graphics::ImmediateSubmit([&](const VkCommandBuffer command_buffer) { - depth_image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { + depth_image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); }); VkImageViewCreateInfo depth_view_info{}; depth_view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; depth_view_info.image = depth_image->GetVkImage(); depth_view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; - depth_view_info.format = Graphics::Constants::shadow_map; + depth_view_info.format = Platform::Constants::shadow_map; depth_view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; depth_view_info.subresourceRange.baseMipLevel = 0; depth_view_info.subresourceRange.levelCount = 1; @@ -87,7 +87,7 @@ void ReflectionProbe::ConstructFromCubemap(const std::shared_ptr& targe #pragma endregion const std::unique_ptr temp_set = - std::make_unique(Graphics::GetDescriptorSetLayout("RENDER_TEXTURE_PRESENT_LAYOUT")); + std::make_unique(Platform::GetDescriptorSetLayout("RENDER_TEXTURE_PRESENT_LAYOUT")); VkDescriptorImageInfo descriptor_image_info; descriptor_image_info.imageView = target_cubemap->GetImageView()->GetVkImageView(); descriptor_image_info.imageLayout = target_cubemap->GetImage()->GetLayout(); @@ -105,9 +105,9 @@ void ReflectionProbe::ConstructFromCubemap(const std::shared_ptr& targe glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f))}; const auto max_mip_levels = cubemap_->RefStorage().image->GetMipLevels(); - const auto prefilter_construct = Graphics::GetGraphicsPipeline("PREFILTER_CONSTRUCT"); - Graphics::ImmediateSubmit([&](VkCommandBuffer command_buffer) { - cubemap_->RefStorage().image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + const auto prefilter_construct = Platform::GetGraphicsPipeline("PREFILTER_CONSTRUCT"); + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { + cubemap_->RefStorage().image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); for (uint32_t mip = 0; mip < max_mip_levels; ++mip) { unsigned int mip_width = cubemap_->RefStorage().image->GetExtent().width * std::pow(0.5, mip); @@ -132,7 +132,7 @@ void ReflectionProbe::ConstructFromCubemap(const std::shared_ptr& targe prefilter_construct->states.view_port = viewport; prefilter_construct->states.scissor = scissor; #pragma endregion - GeometryStorage::BindVertices(command_buffer); + GeometryStorage::BindVertices(vk_command_buffer); for (int i = 0; i < 6; i++) { #pragma region Lighting pass VkRenderingAttachmentInfo attachment{}; @@ -170,22 +170,22 @@ void ReflectionProbe::ConstructFromCubemap(const std::shared_ptr& targe VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; i.blendEnable = VK_FALSE; } - vkCmdBeginRendering(command_buffer, &render_info); - prefilter_construct->Bind(command_buffer); - prefilter_construct->BindDescriptorSet(command_buffer, 0, temp_set->GetVkDescriptorSet()); + vkCmdBeginRendering(vk_command_buffer, &render_info); + prefilter_construct->Bind(vk_command_buffer); + prefilter_construct->BindDescriptorSet(vk_command_buffer, 0, temp_set->GetVkDescriptorSet()); const auto mesh = Resources::GetResource("PRIMITIVE_RENDERING_CUBE"); EquirectangularToCubemapConstant constant{}; constant.projection_view = capture_projection * capture_views[i]; constant.m_preset = roughness; - prefilter_construct->PushConstant(command_buffer, 0, constant); - mesh->DrawIndexed(command_buffer, prefilter_construct->states, 1); - vkCmdEndRendering(command_buffer); + prefilter_construct->PushConstant(vk_command_buffer, 0, constant); + mesh->DrawIndexed(vk_command_buffer, prefilter_construct->states, 1); + vkCmdEndRendering(vk_command_buffer); #pragma endregion - Graphics::EverythingBarrier(command_buffer); + Platform::EverythingBarrier(vk_command_buffer); } } - cubemap_->RefStorage().image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + cubemap_->RefStorage().image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); }); } diff --git a/EvoEngine_SDK/src/RenderLayer.cpp b/EvoEngine_SDK/src/RenderLayer.cpp index eda8850..057aec2 100644 --- a/EvoEngine_SDK/src/RenderLayer.cpp +++ b/EvoEngine_SDK/src/RenderLayer.cpp @@ -2,7 +2,7 @@ #include "Application.hpp" #include "EditorLayer.hpp" #include "GeometryStorage.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "GraphicsPipeline.hpp" #include "Jobs.hpp" #include "LODGroup.hpp" @@ -49,14 +49,14 @@ void RenderLayer::OnCreate() { CreatePerFrameDescriptorSets(); std::vector kernels; - for (uint32_t i = 0; i < Graphics::Constants::max_kernel_amount; i++) { + for (uint32_t i = 0; i < Platform::Constants::max_kernel_amount; i++) { kernels.emplace_back(glm::ballRand(1.0f), 1.0f); } - for (uint32_t i = 0; i < Graphics::Constants::max_kernel_amount; i++) { + for (uint32_t i = 0; i < Platform::Constants::max_kernel_amount; i++) { kernels.emplace_back(glm::gaussRand(0.0f, 1.0f), glm::gaussRand(0.0f, 1.0f), glm::gaussRand(0.0f, 1.0f), glm::gaussRand(0.0f, 1.0f)); } - for (int i = 0; i < Graphics::GetMaxFramesInFlight(); i++) { + for (int i = 0; i < Platform::GetMaxFramesInFlight(); i++) { kernel_descriptor_buffers_[i]->UploadVector(kernels); } @@ -80,10 +80,10 @@ void RenderLayer::ClearAllCameras() { std::vector>> cameras; CollectCameras(cameras); - Graphics::AppendCommands([&](const VkCommandBuffer command_buffer) { + Platform::RecordCommandsMainQueue([&](VkCommandBuffer vk_command_buffer) { for (const auto& i : cameras) { if (const auto render_texture = i.second->GetRenderTexture()) - render_texture->Clear(command_buffer); + render_texture->Clear(vk_command_buffer); } }); } @@ -138,8 +138,8 @@ void RenderLayer::RenderAllCameras() { CollectPointLights(); CollectSpotLights(); - const auto current_frame_index = Graphics::GetCurrentFrameIndex(); - auto& graphics = Graphics::GetInstance(); + const auto current_frame_index = Platform::GetCurrentFrameIndex(); + auto& graphics = Platform::GetInstance(); graphics.triangles[current_frame_index] = 0; graphics.strands_segments[current_frame_index] = 0; graphics.draw_call[current_frame_index] = 0; @@ -243,36 +243,36 @@ void RenderLayer::RenderAllCameras() { return; } if (i.editor_camera_component && i.editor_camera_component->IsEnabled()) { - Graphics::AppendCommands([&](const VkCommandBuffer command_buffer) { + Platform::RecordCommandsMainQueue([&](VkCommandBuffer vk_command_buffer) { std::shared_ptr gizmos_pipeline; switch (i.gizmo_settings.color_mode) { case GizmoSettings::ColorMode::Default: { - gizmos_pipeline = Graphics::GetGraphicsPipeline("GIZMOS"); + gizmos_pipeline = Platform::GetGraphicsPipeline("GIZMOS"); } break; case GizmoSettings::ColorMode::VertexColor: { - gizmos_pipeline = Graphics::GetGraphicsPipeline("GIZMOS_VERTEX_COLORED"); + gizmos_pipeline = Platform::GetGraphicsPipeline("GIZMOS_VERTEX_COLORED"); } break; case GizmoSettings::ColorMode::NormalColor: { - gizmos_pipeline = Graphics::GetGraphicsPipeline("GIZMOS_NORMAL_COLORED"); + gizmos_pipeline = Platform::GetGraphicsPipeline("GIZMOS_NORMAL_COLORED"); } break; } i.editor_camera_component->GetRenderTexture()->ApplyGraphicsPipelineStates(gizmos_pipeline->states); i.gizmo_settings.ApplySettings(gizmos_pipeline->states); - gizmos_pipeline->Bind(command_buffer); - gizmos_pipeline->BindDescriptorSet(command_buffer, 0, GetPerFrameDescriptorSet()->GetVkDescriptorSet()); + gizmos_pipeline->Bind(vk_command_buffer); + gizmos_pipeline->BindDescriptorSet(vk_command_buffer, 0, GetPerFrameDescriptorSet()->GetVkDescriptorSet()); - i.editor_camera_component->GetRenderTexture()->BeginRendering(command_buffer, VK_ATTACHMENT_LOAD_OP_LOAD, + i.editor_camera_component->GetRenderTexture()->BeginRendering(vk_command_buffer, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE); GizmosPushConstant push_constant; push_constant.model = i.model; push_constant.color = i.color; push_constant.size = i.size; push_constant.camera_index = GetCameraIndex(i.editor_camera_component->GetHandle()); - gizmos_pipeline->PushConstant(command_buffer, 0, push_constant); - GeometryStorage::BindVertices(command_buffer); - i.mesh->DrawIndexed(command_buffer, gizmos_pipeline->states, 1); - i.editor_camera_component->GetRenderTexture()->EndRendering(command_buffer); + gizmos_pipeline->PushConstant(vk_command_buffer, 0, push_constant); + GeometryStorage::BindVertices(vk_command_buffer); + i.mesh->DrawIndexed(vk_command_buffer, gizmos_pipeline->states, 1); + i.editor_camera_component->GetRenderTexture()->EndRendering(vk_command_buffer); }); } } @@ -283,27 +283,28 @@ void RenderLayer::RenderAllCameras() { return; } if (i.editor_camera_component && i.editor_camera_component->IsEnabled()) { - Graphics::AppendCommands([&](const VkCommandBuffer command_buffer) { - const auto gizmos_pipeline = Graphics::GetGraphicsPipeline("GIZMOS_INSTANCED_COLORED"); + Platform::RecordCommandsMainQueue([&](VkCommandBuffer vk_command_buffer) { + const auto gizmos_pipeline = Platform::GetGraphicsPipeline("GIZMOS_INSTANCED_COLORED"); i.editor_camera_component->GetRenderTexture()->ApplyGraphicsPipelineStates(gizmos_pipeline->states); i.gizmo_settings.ApplySettings(gizmos_pipeline->states); - gizmos_pipeline->Bind(command_buffer); - gizmos_pipeline->BindDescriptorSet(command_buffer, 0, GetPerFrameDescriptorSet()->GetVkDescriptorSet()); - gizmos_pipeline->BindDescriptorSet(command_buffer, 1, + gizmos_pipeline->Bind(vk_command_buffer); + gizmos_pipeline->BindDescriptorSet(vk_command_buffer, 0, GetPerFrameDescriptorSet()->GetVkDescriptorSet()); + gizmos_pipeline->BindDescriptorSet(vk_command_buffer, 1, i.instanced_data->GetDescriptorSet()->GetVkDescriptorSet()); - i.editor_camera_component->GetRenderTexture()->BeginRendering(command_buffer, VK_ATTACHMENT_LOAD_OP_LOAD, + i.editor_camera_component->GetRenderTexture()->BeginRendering(vk_command_buffer, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE); GizmosPushConstant push_constant; push_constant.model = i.model; push_constant.color = glm::vec4(0.0f); push_constant.size = i.size; push_constant.camera_index = GetCameraIndex(i.editor_camera_component->GetHandle()); - gizmos_pipeline->PushConstant(command_buffer, 0, push_constant); - GeometryStorage::BindVertices(command_buffer); - i.mesh->DrawIndexed(command_buffer, gizmos_pipeline->states, i.instanced_data->PeekParticleInfoList().size()); - i.editor_camera_component->GetRenderTexture()->EndRendering(command_buffer); + gizmos_pipeline->PushConstant(vk_command_buffer, 0, push_constant); + GeometryStorage::BindVertices(vk_command_buffer); + i.mesh->DrawIndexed(vk_command_buffer, gizmos_pipeline->states, + i.instanced_data->PeekParticleInfoList().size()); + i.editor_camera_component->GetRenderTexture()->EndRendering(vk_command_buffer); }); } } @@ -314,36 +315,36 @@ void RenderLayer::RenderAllCameras() { return; } if (i.editor_camera_component && i.editor_camera_component->IsEnabled()) { - Graphics::AppendCommands([&](const VkCommandBuffer command_buffer) { + Platform::RecordCommandsMainQueue([&](VkCommandBuffer vk_command_buffer) { std::shared_ptr gizmos_pipeline; switch (i.gizmo_settings.color_mode) { case GizmoSettings::ColorMode::Default: { - gizmos_pipeline = Graphics::GetGraphicsPipeline("GIZMOS_STRANDS"); + gizmos_pipeline = Platform::GetGraphicsPipeline("GIZMOS_STRANDS"); } break; case GizmoSettings::ColorMode::VertexColor: { - gizmos_pipeline = Graphics::GetGraphicsPipeline("GIZMOS_STRANDS_VERTEX_COLORED"); + gizmos_pipeline = Platform::GetGraphicsPipeline("GIZMOS_STRANDS_VERTEX_COLORED"); } break; case GizmoSettings::ColorMode::NormalColor: { - gizmos_pipeline = Graphics::GetGraphicsPipeline("GIZMOS_STRANDS_NORMAL_COLORED"); + gizmos_pipeline = Platform::GetGraphicsPipeline("GIZMOS_STRANDS_NORMAL_COLORED"); } break; } i.editor_camera_component->GetRenderTexture()->ApplyGraphicsPipelineStates(gizmos_pipeline->states); i.gizmo_settings.ApplySettings(gizmos_pipeline->states); - gizmos_pipeline->Bind(command_buffer); - gizmos_pipeline->BindDescriptorSet(command_buffer, 0, GetPerFrameDescriptorSet()->GetVkDescriptorSet()); + gizmos_pipeline->Bind(vk_command_buffer); + gizmos_pipeline->BindDescriptorSet(vk_command_buffer, 0, GetPerFrameDescriptorSet()->GetVkDescriptorSet()); - i.editor_camera_component->GetRenderTexture()->BeginRendering(command_buffer, VK_ATTACHMENT_LOAD_OP_LOAD, + i.editor_camera_component->GetRenderTexture()->BeginRendering(vk_command_buffer, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE); GizmosPushConstant push_constant; push_constant.model = i.model; push_constant.color = i.color; push_constant.size = i.m_size; push_constant.camera_index = GetCameraIndex(i.editor_camera_component->GetHandle()); - gizmos_pipeline->PushConstant(command_buffer, 0, push_constant); - GeometryStorage::BindStrandPoints(command_buffer); - i.m_strands->DrawIndexed(command_buffer, gizmos_pipeline->states, 1); - i.editor_camera_component->GetRenderTexture()->EndRendering(command_buffer); + gizmos_pipeline->PushConstant(vk_command_buffer, 0, push_constant); + GeometryStorage::BindStrandPoints(vk_command_buffer); + i.m_strands->DrawIndexed(vk_command_buffer, gizmos_pipeline->states, 1); + i.editor_camera_component->GetRenderTexture()->EndRendering(vk_command_buffer); }); } } @@ -384,11 +385,11 @@ void RenderLayer::OnInspect(const std::shared_ptr& editor_layer) { ImGui::Checkbox("Count dc for shadows", &count_shadow_rendering_draw_calls); ImGui::Checkbox("Wireframe", &wire_frame); - if (Graphics::Constants::enable_mesh_shader) - ImGui::Checkbox("Meshlet", &Graphics::Settings::use_mesh_shader); - if (!Graphics::Settings::use_mesh_shader) + if (Platform::Constants::enable_mesh_shader) + ImGui::Checkbox("Meshlet", &Platform::Settings::use_mesh_shader); + if (!Platform::Settings::use_mesh_shader) ImGui::Checkbox("Indirect Rendering", &enable_indirect_rendering); - if (Graphics::Constants::enable_mesh_shader && Graphics::Settings::use_mesh_shader) { + if (Platform::Constants::enable_mesh_shader && Platform::Settings::use_mesh_shader) { ImGui::Checkbox("Show meshlets", &enable_debug_visualization); } else { ImGui::Checkbox("Show meshes", &enable_debug_visualization); @@ -542,7 +543,7 @@ void RenderLayer::CollectDirectionalLights( scene->UnsafeGetPrivateComponentOwnersList(); render_info_block.directional_light_size = 0; if (directional_light_entities && !directional_light_entities->empty()) { - directional_light_info_blocks_.resize(Graphics::Settings::max_directional_light_size * cameras.size()); + directional_light_info_blocks_.resize(Platform::Settings::max_directional_light_size * cameras.size()); for (const auto& light_entity : *directional_light_entities) { if (!scene->IsEntityEnabled(light_entity)) continue; @@ -553,11 +554,11 @@ void RenderLayer::CollectDirectionalLights( } std::vector viewport_results; Lighting::AllocateAtlas(render_info_block.directional_light_size, - Graphics::Settings::directional_light_shadow_map_resolution, viewport_results); + Platform::Settings::directional_light_shadow_map_resolution, viewport_results); for (const auto& [cameraGlobalTransform, camera] : cameras) { auto camera_index = GetCameraIndex(camera->GetHandle()); for (int i = 0; i < render_info_block.directional_light_size; i++) { - const auto block_index = camera_index * Graphics::Settings::max_directional_light_size + i; + const auto block_index = camera_index * Platform::Settings::max_directional_light_size + i; auto& viewport = directional_light_info_blocks_[block_index].viewport; viewport.x = viewport_results[i].x; viewport.y = viewport_results[i].y; @@ -582,7 +583,7 @@ void RenderLayer::CollectDirectionalLights( float plane_distance = 0; glm::vec3 center; const auto block_index = - camera_index * Graphics::Settings::max_directional_light_size + directional_light_index; + camera_index * Platform::Settings::max_directional_light_size + directional_light_index; directional_light_info_blocks_[block_index].direction = glm::vec4(light_dir, 0.0f); directional_light_info_blocks_[block_index].diffuse = glm::vec4(dlc->diffuse * dlc->diffuse_brightness, dlc->cast_shadow); @@ -754,7 +755,7 @@ void RenderLayer::CollectPointLights() { render_info_block.point_light_size++; } std::vector view_port_results; - Lighting::AllocateAtlas(render_info_block.point_light_size, Graphics::Settings::point_light_shadow_map_resolution, + Lighting::AllocateAtlas(render_info_block.point_light_size, Platform::Settings::point_light_shadow_map_resolution, view_port_results); int allocation_index = 0; for (const auto& point_light_index : sorted_point_light_indices) { @@ -821,7 +822,7 @@ void RenderLayer::CollectSpotLights() { render_info_block.spot_light_size++; } std::vector view_port_results; - Lighting::AllocateAtlas(render_info_block.spot_light_size, Graphics::Settings::spot_light_shadow_map_resolution, + Lighting::AllocateAtlas(render_info_block.spot_light_size, Platform::Settings::spot_light_shadow_map_resolution, view_port_results); int allocation_index = 0; for (const auto& spot_light_index : sorted_spot_light_indices) { @@ -873,28 +874,28 @@ void RenderLayer::ApplyAnimator() const { void RenderLayer::PreparePointAndSpotLightShadowMap() const { const bool count_draw_calls = count_shadow_rendering_draw_calls; - const bool use_mesh_shader = Graphics::Constants::enable_mesh_shader && Graphics::Settings::use_mesh_shader; - const auto current_frame_index = Graphics::GetCurrentFrameIndex(); + const bool use_mesh_shader = Platform::Constants::enable_mesh_shader && Platform::Settings::use_mesh_shader; + const auto current_frame_index = Platform::GetCurrentFrameIndex(); const auto& point_light_shadow_pipeline = use_mesh_shader - ? Graphics::GetGraphicsPipeline("POINT_LIGHT_SHADOW_MAP_MESH") - : Graphics::GetGraphicsPipeline("POINT_LIGHT_SHADOW_MAP"); - const auto& spot_light_shadow_pipeline = use_mesh_shader ? Graphics::GetGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP_MESH") - : Graphics::GetGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP"); + ? Platform::GetGraphicsPipeline("POINT_LIGHT_SHADOW_MAP_MESH") + : Platform::GetGraphicsPipeline("POINT_LIGHT_SHADOW_MAP"); + const auto& spot_light_shadow_pipeline = use_mesh_shader ? Platform::GetGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP_MESH") + : Platform::GetGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP"); - const auto& point_light_shadow_skinned_pipeline = Graphics::GetGraphicsPipeline("POINT_LIGHT_SHADOW_MAP_SKINNED"); - const auto& spot_light_shadow_skinned_pipeline = Graphics::GetGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP_SKINNED"); + const auto& point_light_shadow_skinned_pipeline = Platform::GetGraphicsPipeline("POINT_LIGHT_SHADOW_MAP_SKINNED"); + const auto& spot_light_shadow_skinned_pipeline = Platform::GetGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP_SKINNED"); - const auto& point_light_shadow_instanced_pipeline = Graphics::GetGraphicsPipeline("POINT_LIGHT_SHADOW_MAP_INSTANCED"); - const auto& spot_light_shadow_instanced_pipeline = Graphics::GetGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP_INSTANCED"); + const auto& point_light_shadow_instanced_pipeline = Platform::GetGraphicsPipeline("POINT_LIGHT_SHADOW_MAP_INSTANCED"); + const auto& spot_light_shadow_instanced_pipeline = Platform::GetGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP_INSTANCED"); - const auto& point_light_shadow_strands_pipeline = Graphics::GetGraphicsPipeline("POINT_LIGHT_SHADOW_MAP_STRANDS"); - const auto& spot_light_shadow_strands_pipeline = Graphics::GetGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP_STRANDS"); - auto& graphics = Graphics::GetInstance(); + const auto& point_light_shadow_strands_pipeline = Platform::GetGraphicsPipeline("POINT_LIGHT_SHADOW_MAP_STRANDS"); + const auto& spot_light_shadow_strands_pipeline = Platform::GetGraphicsPipeline("SPOT_LIGHT_SHADOW_MAP_STRANDS"); + auto& graphics = Platform::GetInstance(); const uint32_t task_work_group_invocations = graphics.mesh_shader_properties_ext_.maxPreferredTaskWorkGroupInvocations; - Graphics::AppendCommands([&](VkCommandBuffer command_buffer) { + Platform::RecordCommandsMainQueue([&](VkCommandBuffer vk_command_buffer) { #pragma region Viewport and scissor VkRect2D render_area; render_area.offset = {0, 0}; @@ -915,10 +916,10 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { scissor.extent.height = render_area.extent.height; #pragma endregion - lighting_->point_light_shadow_map_->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + lighting_->point_light_shadow_map_->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); for (int face = 0; face < 6; face++) { - GeometryStorage::BindVertices(command_buffer); + GeometryStorage::BindVertices(vk_command_buffer); { VkRenderingInfo render_info{}; auto depth_attachment = lighting_->GetLayeredPointLightDepthAttachmentInfo(face, VK_ATTACHMENT_LOAD_OP_CLEAR, @@ -933,10 +934,10 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { point_light_shadow_pipeline->states.view_port = viewport; point_light_shadow_pipeline->states.scissor = scissor; - vkCmdBeginRendering(command_buffer, &render_info); - point_light_shadow_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + point_light_shadow_pipeline->Bind(vk_command_buffer); point_light_shadow_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); for (int i = 0; i < point_light_info_blocks_.size(); i++) { const auto& point_light_info_block = point_light_info_blocks_[i]; viewport.x = point_light_info_block.viewport.x; @@ -953,14 +954,14 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { push_constant.camera_index = i; push_constant.light_split_index = face; push_constant.instance_index = 0; - point_light_shadow_pipeline->PushConstant(command_buffer, 0, push_constant); - point_light_shadow_pipeline->states.ApplyAllStates(command_buffer); + point_light_shadow_pipeline->PushConstant(vk_command_buffer, 0, push_constant); + point_light_shadow_pipeline->states.ApplyAllStates(vk_command_buffer); if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.triangles[current_frame_index] += total_mesh_triangles_; vkCmdDrawIndexedIndirect( - command_buffer, mesh_draw_indexed_indirect_commands_buffers_[current_frame_index]->GetVkBuffer(), 0, + vk_command_buffer, mesh_draw_indexed_indirect_commands_buffers_[current_frame_index]->GetVkBuffer(), 0, mesh_draw_indexed_indirect_commands_.size(), sizeof(VkDrawIndexedIndirectCommand)); } else { deferred_render_instances_.Dispatch([&](const RenderInstance& render_command) { @@ -970,7 +971,7 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { push_constant.camera_index = i; push_constant.light_split_index = face; push_constant.instance_index = render_command.instance_index; - point_light_shadow_pipeline->PushConstant(command_buffer, 0, push_constant); + point_light_shadow_pipeline->PushConstant(vk_command_buffer, 0, push_constant); if (use_mesh_shader) { if (count_draw_calls) graphics.draw_call[current_frame_index]++; @@ -979,19 +980,19 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { const uint32_t count = (render_command.meshlet_size + task_work_group_invocations - 1) / task_work_group_invocations; - vkCmdDrawMeshTasksEXT(command_buffer, count, 1, 1); + vkCmdDrawMeshTasksEXT(vk_command_buffer, count, 1, 1); } else { const auto mesh = render_command.m_mesh; if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.triangles[current_frame_index] += render_command.m_mesh->triangles_.size(); - mesh->DrawIndexed(command_buffer, point_light_shadow_pipeline->states, 1); + mesh->DrawIndexed(vk_command_buffer, point_light_shadow_pipeline->states, 1); } }); } } - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } { VkRenderingInfo render_info{}; @@ -1006,10 +1007,10 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { point_light_shadow_instanced_pipeline->states.ResetAllStates(0); point_light_shadow_instanced_pipeline->states.view_port = viewport; point_light_shadow_instanced_pipeline->states.scissor = scissor; - vkCmdBeginRendering(command_buffer, &render_info); - point_light_shadow_instanced_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + point_light_shadow_instanced_pipeline->Bind(vk_command_buffer); point_light_shadow_instanced_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); for (int i = 0; i < point_light_info_blocks_.size(); i++) { const auto& point_light_info_block = point_light_info_blocks_[i]; viewport.x = point_light_info_block.viewport.x; @@ -1024,25 +1025,25 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { if (!render_command.cast_shadow) return; point_light_shadow_instanced_pipeline->BindDescriptorSet( - command_buffer, 1, render_command.particle_infos->GetDescriptorSet()->GetVkDescriptorSet()); + vk_command_buffer, 1, render_command.particle_infos->GetDescriptorSet()->GetVkDescriptorSet()); RenderInstancePushConstant push_constant; push_constant.camera_index = i; push_constant.light_split_index = face; push_constant.instance_index = render_command.instance_index; - point_light_shadow_instanced_pipeline->PushConstant(command_buffer, 0, push_constant); + point_light_shadow_instanced_pipeline->PushConstant(vk_command_buffer, 0, push_constant); const auto mesh = render_command.mesh; if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.triangles[current_frame_index] += render_command.mesh->triangles_.size() * render_command.particle_infos->PeekParticleInfoList().size(); - mesh->DrawIndexed(command_buffer, point_light_shadow_instanced_pipeline->states, + mesh->DrawIndexed(vk_command_buffer, point_light_shadow_instanced_pipeline->states, render_command.particle_infos->PeekParticleInfoList().size()); }); } - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } - GeometryStorage::BindSkinnedVertices(command_buffer); + GeometryStorage::BindSkinnedVertices(vk_command_buffer); { VkRenderingInfo render_info{}; auto depth_attachment = lighting_->GetLayeredPointLightDepthAttachmentInfo(face, VK_ATTACHMENT_LOAD_OP_LOAD, @@ -1056,10 +1057,10 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { point_light_shadow_skinned_pipeline->states.ResetAllStates(0); point_light_shadow_skinned_pipeline->states.view_port = viewport; point_light_shadow_skinned_pipeline->states.scissor = scissor; - vkCmdBeginRendering(command_buffer, &render_info); - point_light_shadow_skinned_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + point_light_shadow_skinned_pipeline->Bind(vk_command_buffer); point_light_shadow_skinned_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); for (int i = 0; i < point_light_info_blocks_.size(); i++) { const auto& point_light_info_block = point_light_info_blocks_[i]; viewport.x = point_light_info_block.viewport.x; @@ -1074,23 +1075,23 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { if (!render_command.cast_shadow) return; point_light_shadow_skinned_pipeline->BindDescriptorSet( - command_buffer, 1, render_command.bone_matrices->GetDescriptorSet()->GetVkDescriptorSet()); + vk_command_buffer, 1, render_command.bone_matrices->GetDescriptorSet()->GetVkDescriptorSet()); RenderInstancePushConstant push_constant; push_constant.camera_index = i; push_constant.light_split_index = face; push_constant.instance_index = render_command.instance_index; - point_light_shadow_skinned_pipeline->PushConstant(command_buffer, 0, push_constant); + point_light_shadow_skinned_pipeline->PushConstant(vk_command_buffer, 0, push_constant); const auto skinned_mesh = render_command.skinned_mesh; if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.triangles[current_frame_index] += render_command.skinned_mesh->skinned_triangles_.size(); - skinned_mesh->DrawIndexed(command_buffer, point_light_shadow_skinned_pipeline->states, 1); + skinned_mesh->DrawIndexed(vk_command_buffer, point_light_shadow_skinned_pipeline->states, 1); }); } - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } - GeometryStorage::BindStrandPoints(command_buffer); + GeometryStorage::BindStrandPoints(vk_command_buffer); { VkRenderingInfo render_info{}; auto depth_attachment = lighting_->GetLayeredPointLightDepthAttachmentInfo(face, VK_ATTACHMENT_LOAD_OP_LOAD, @@ -1104,10 +1105,10 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { point_light_shadow_strands_pipeline->states.ResetAllStates(0); point_light_shadow_strands_pipeline->states.view_port = viewport; point_light_shadow_strands_pipeline->states.scissor = scissor; - vkCmdBeginRendering(command_buffer, &render_info); - point_light_shadow_strands_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + point_light_shadow_strands_pipeline->Bind(vk_command_buffer); point_light_shadow_strands_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); for (int i = 0; i < point_light_info_blocks_.size(); i++) { const auto& point_light_info_block = point_light_info_blocks_[i]; viewport.x = point_light_info_block.viewport.x; @@ -1125,16 +1126,16 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { push_constant.camera_index = i; push_constant.light_split_index = face; push_constant.instance_index = render_command.instance_index; - point_light_shadow_strands_pipeline->PushConstant(command_buffer, 0, push_constant); + point_light_shadow_strands_pipeline->PushConstant(vk_command_buffer, 0, push_constant); const auto strands = render_command.m_strands; if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.strands_segments[current_frame_index] += render_command.m_strands->segments_.size(); - strands->DrawIndexed(command_buffer, point_light_shadow_strands_pipeline->states, 1); + strands->DrawIndexed(vk_command_buffer, point_light_shadow_strands_pipeline->states, 1); }); } - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } } #pragma region Viewport and scissor @@ -1155,8 +1156,8 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { scissor.extent.height = render_area.extent.height; #pragma endregion - lighting_->spot_light_shadow_map_->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); - GeometryStorage::BindVertices(command_buffer); + lighting_->spot_light_shadow_map_->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + GeometryStorage::BindVertices(vk_command_buffer); { VkRenderingInfo render_info{}; auto depth_attachment = @@ -1170,10 +1171,10 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { spot_light_shadow_pipeline->states.ResetAllStates(0); spot_light_shadow_pipeline->states.view_port = viewport; spot_light_shadow_pipeline->states.scissor = scissor; - vkCmdBeginRendering(command_buffer, &render_info); - spot_light_shadow_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + spot_light_shadow_pipeline->Bind(vk_command_buffer); spot_light_shadow_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); for (int i = 0; i < spot_light_info_blocks_.size(); i++) { const auto& spot_light_info_block = spot_light_info_blocks_[i]; viewport.x = spot_light_info_block.viewport.x; @@ -1189,13 +1190,13 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { push_constant.camera_index = i; push_constant.light_split_index = 0; push_constant.instance_index = 0; - spot_light_shadow_pipeline->PushConstant(command_buffer, 0, push_constant); - spot_light_shadow_pipeline->states.ApplyAllStates(command_buffer); + spot_light_shadow_pipeline->PushConstant(vk_command_buffer, 0, push_constant); + spot_light_shadow_pipeline->states.ApplyAllStates(vk_command_buffer); if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.triangles[current_frame_index] += total_mesh_triangles_; - vkCmdDrawIndexedIndirect(command_buffer, + vkCmdDrawIndexedIndirect(vk_command_buffer, mesh_draw_indexed_indirect_commands_buffers_[current_frame_index]->GetVkBuffer(), 0, mesh_draw_indexed_indirect_commands_.size(), sizeof(VkDrawIndexedIndirectCommand)); } else { @@ -1206,7 +1207,7 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { push_constant.camera_index = i; push_constant.light_split_index = 0; push_constant.instance_index = render_command.instance_index; - spot_light_shadow_pipeline->PushConstant(command_buffer, 0, push_constant); + spot_light_shadow_pipeline->PushConstant(vk_command_buffer, 0, push_constant); if (use_mesh_shader) { if (count_draw_calls) graphics.draw_call[current_frame_index]++; @@ -1214,19 +1215,19 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { graphics.triangles[current_frame_index] += render_command.m_mesh->triangles_.size(); const uint32_t count = (render_command.meshlet_size + task_work_group_invocations - 1) / task_work_group_invocations; - vkCmdDrawMeshTasksEXT(command_buffer, count, 1, 1); + vkCmdDrawMeshTasksEXT(vk_command_buffer, count, 1, 1); } else { const auto mesh = render_command.m_mesh; if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.triangles[current_frame_index] += render_command.m_mesh->triangles_.size(); - mesh->DrawIndexed(command_buffer, spot_light_shadow_pipeline->states, 1); + mesh->DrawIndexed(vk_command_buffer, spot_light_shadow_pipeline->states, 1); } }); } } - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } { VkRenderingInfo render_info{}; @@ -1241,10 +1242,10 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { spot_light_shadow_instanced_pipeline->states.ResetAllStates(0); spot_light_shadow_instanced_pipeline->states.view_port = viewport; spot_light_shadow_instanced_pipeline->states.scissor = scissor; - vkCmdBeginRendering(command_buffer, &render_info); - spot_light_shadow_instanced_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + spot_light_shadow_instanced_pipeline->Bind(vk_command_buffer); spot_light_shadow_instanced_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); for (int i = 0; i < spot_light_info_blocks_.size(); i++) { const auto& spot_light_info_block = spot_light_info_blocks_[i]; viewport.x = spot_light_info_block.viewport.x; @@ -1257,25 +1258,25 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { if (!render_command.cast_shadow) return; spot_light_shadow_instanced_pipeline->BindDescriptorSet( - command_buffer, 1, render_command.particle_infos->GetDescriptorSet()->GetVkDescriptorSet()); + vk_command_buffer, 1, render_command.particle_infos->GetDescriptorSet()->GetVkDescriptorSet()); RenderInstancePushConstant push_constant; push_constant.camera_index = i; push_constant.light_split_index = 0; push_constant.instance_index = render_command.instance_index; - spot_light_shadow_instanced_pipeline->PushConstant(command_buffer, 0, push_constant); + spot_light_shadow_instanced_pipeline->PushConstant(vk_command_buffer, 0, push_constant); const auto mesh = render_command.mesh; if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.triangles[current_frame_index] += render_command.mesh->triangles_.size() * render_command.particle_infos->PeekParticleInfoList().size(); - mesh->DrawIndexed(command_buffer, spot_light_shadow_instanced_pipeline->states, + mesh->DrawIndexed(vk_command_buffer, spot_light_shadow_instanced_pipeline->states, render_command.particle_infos->PeekParticleInfoList().size()); }); } - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } - GeometryStorage::BindSkinnedVertices(command_buffer); + GeometryStorage::BindSkinnedVertices(vk_command_buffer); { VkRenderingInfo render_info{}; auto depth_attachment = @@ -1289,10 +1290,10 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { spot_light_shadow_skinned_pipeline->states.ResetAllStates(0); spot_light_shadow_skinned_pipeline->states.view_port = viewport; spot_light_shadow_skinned_pipeline->states.scissor = scissor; - vkCmdBeginRendering(command_buffer, &render_info); - spot_light_shadow_skinned_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + spot_light_shadow_skinned_pipeline->Bind(vk_command_buffer); spot_light_shadow_skinned_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); for (int i = 0; i < spot_light_info_blocks_.size(); i++) { const auto& spot_light_info_block = spot_light_info_blocks_[i]; viewport.x = spot_light_info_block.viewport.x; @@ -1305,23 +1306,23 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { if (!render_command.cast_shadow) return; spot_light_shadow_skinned_pipeline->BindDescriptorSet( - command_buffer, 1, render_command.bone_matrices->GetDescriptorSet()->GetVkDescriptorSet()); + vk_command_buffer, 1, render_command.bone_matrices->GetDescriptorSet()->GetVkDescriptorSet()); RenderInstancePushConstant push_constant; push_constant.camera_index = i; push_constant.light_split_index = 0; push_constant.instance_index = render_command.instance_index; - spot_light_shadow_skinned_pipeline->PushConstant(command_buffer, 0, push_constant); + spot_light_shadow_skinned_pipeline->PushConstant(vk_command_buffer, 0, push_constant); const auto skinned_mesh = render_command.skinned_mesh; if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.triangles[current_frame_index] += render_command.skinned_mesh->skinned_triangles_.size(); - skinned_mesh->DrawIndexed(command_buffer, spot_light_shadow_skinned_pipeline->states, 1); + skinned_mesh->DrawIndexed(vk_command_buffer, spot_light_shadow_skinned_pipeline->states, 1); }); } - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } - GeometryStorage::BindStrandPoints(command_buffer); + GeometryStorage::BindStrandPoints(vk_command_buffer); { VkRenderingInfo render_info{}; auto depth_attachment = @@ -1335,10 +1336,10 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { spot_light_shadow_strands_pipeline->states.ResetAllStates(0); spot_light_shadow_strands_pipeline->states.view_port = viewport; spot_light_shadow_strands_pipeline->states.scissor = scissor; - vkCmdBeginRendering(command_buffer, &render_info); - spot_light_shadow_strands_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + spot_light_shadow_strands_pipeline->Bind(vk_command_buffer); spot_light_shadow_strands_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); for (int i = 0; i < spot_light_info_blocks_.size(); i++) { const auto& spot_light_info_block = spot_light_info_blocks_[i]; viewport.x = spot_light_info_block.viewport.x; @@ -1354,19 +1355,19 @@ void RenderLayer::PreparePointAndSpotLightShadowMap() const { push_constant.camera_index = i; push_constant.light_split_index = 0; push_constant.instance_index = render_command.instance_index; - spot_light_shadow_strands_pipeline->PushConstant(command_buffer, 0, push_constant); + spot_light_shadow_strands_pipeline->PushConstant(vk_command_buffer, 0, push_constant); const auto strands = render_command.m_strands; if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.strands_segments[current_frame_index] += render_command.m_strands->segments_.size(); - strands->DrawIndexed(command_buffer, spot_light_shadow_strands_pipeline->states, 1); + strands->DrawIndexed(vk_command_buffer, spot_light_shadow_strands_pipeline->states, 1); }); } - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } - lighting_->point_light_shadow_map_->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - lighting_->spot_light_shadow_map_->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + lighting_->point_light_shadow_map_->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + lighting_->spot_light_shadow_map_->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); }); } @@ -1532,7 +1533,7 @@ void RenderLayer::CreateStandardDescriptorBuffers() { buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; VmaAllocationCreateInfo buffer_vma_allocation_create_info{}; buffer_vma_allocation_create_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE; - const auto max_frame_in_flight = Graphics::GetMaxFramesInFlight(); + const auto max_frame_in_flight = Platform::GetMaxFramesInFlight(); for (size_t i = 0; i < max_frame_in_flight; i++) { buffer_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; buffer_create_info.size = sizeof(RenderInfoBlock); @@ -1542,37 +1543,37 @@ void RenderLayer::CreateStandardDescriptorBuffers() { environment_info_descriptor_buffers_.emplace_back( std::make_unique(buffer_create_info, buffer_vma_allocation_create_info)); buffer_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; - buffer_create_info.size = sizeof(CameraInfoBlock) * Graphics::Constants::initial_camera_size; + buffer_create_info.size = sizeof(CameraInfoBlock) * Platform::Constants::initial_camera_size; camera_info_descriptor_buffers_.emplace_back( std::make_unique(buffer_create_info, buffer_vma_allocation_create_info)); - buffer_create_info.size = sizeof(MaterialInfoBlock) * Graphics::Constants::initial_material_size; + buffer_create_info.size = sizeof(MaterialInfoBlock) * Platform::Constants::initial_material_size; material_info_descriptor_buffers_.emplace_back( std::make_unique(buffer_create_info, buffer_vma_allocation_create_info)); - buffer_create_info.size = sizeof(InstanceInfoBlock) * Graphics::Constants::initial_instance_size; + buffer_create_info.size = sizeof(InstanceInfoBlock) * Platform::Constants::initial_instance_size; instance_info_descriptor_buffers_.emplace_back( std::make_unique(buffer_create_info, buffer_vma_allocation_create_info)); buffer_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; - buffer_create_info.size = sizeof(glm::vec4) * Graphics::Constants::max_kernel_amount * 2; + buffer_create_info.size = sizeof(glm::vec4) * Platform::Constants::max_kernel_amount * 2; kernel_descriptor_buffers_.emplace_back( std::make_unique(buffer_create_info, buffer_vma_allocation_create_info)); buffer_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; - buffer_create_info.size = sizeof(DirectionalLightInfo) * Graphics::Settings::max_directional_light_size * - Graphics::Constants::initial_camera_size; + buffer_create_info.size = sizeof(DirectionalLightInfo) * Platform::Settings::max_directional_light_size * + Platform::Constants::initial_camera_size; directional_light_info_descriptor_buffers_.emplace_back( std::make_unique(buffer_create_info, buffer_vma_allocation_create_info)); - buffer_create_info.size = sizeof(PointLightInfo) * Graphics::Settings::max_point_light_size; + buffer_create_info.size = sizeof(PointLightInfo) * Platform::Settings::max_point_light_size; point_light_info_descriptor_buffers_.emplace_back( std::make_unique(buffer_create_info, buffer_vma_allocation_create_info)); - buffer_create_info.size = sizeof(SpotLightInfo) * Graphics::Settings::max_spot_light_size; + buffer_create_info.size = sizeof(SpotLightInfo) * Platform::Settings::max_spot_light_size; spot_light_info_descriptor_buffers_.emplace_back( std::make_unique(buffer_create_info, buffer_vma_allocation_create_info)); buffer_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT; - buffer_create_info.size = sizeof(VkDrawMeshTasksIndirectCommandEXT) * Graphics::Constants::initial_render_task_size; + buffer_create_info.size = sizeof(VkDrawMeshTasksIndirectCommandEXT) * Platform::Constants::initial_render_task_size; mesh_draw_mesh_tasks_indirect_commands_buffers_.emplace_back( std::make_unique(buffer_create_info, buffer_vma_allocation_create_info)); - buffer_create_info.size = sizeof(VkDrawIndexedIndirectCommand) * Graphics::Constants::initial_render_task_size; + buffer_create_info.size = sizeof(VkDrawIndexedIndirectCommand) * Platform::Constants::initial_render_task_size; mesh_draw_indexed_indirect_commands_buffers_.emplace_back( std::make_unique(buffer_create_info, buffer_vma_allocation_create_info)); } @@ -1580,11 +1581,11 @@ void RenderLayer::CreateStandardDescriptorBuffers() { } void RenderLayer::CreatePerFrameDescriptorSets() { - const auto max_frames_in_flight = Graphics::GetMaxFramesInFlight(); + const auto max_frames_in_flight = Platform::GetMaxFramesInFlight(); per_frame_descriptor_sets_.clear(); for (size_t i = 0; i < max_frames_in_flight; i++) { - auto descriptor_set = std::make_shared(Graphics::GetDescriptorSetLayout("PER_FRAME_LAYOUT")); + auto descriptor_set = std::make_shared(Platform::GetDescriptorSetLayout("PER_FRAME_LAYOUT")); per_frame_descriptor_sets_.emplace_back(descriptor_set); } } @@ -1633,7 +1634,7 @@ void RenderLayer::PrepareEnvironmentalBrdfLut() { sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; sampler_info.anisotropyEnable = VK_TRUE; - sampler_info.maxAnisotropy = Graphics::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; + sampler_info.maxAnisotropy = Platform::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; sampler_info.unnormalizedCoordinates = VK_FALSE; sampler_info.compareEnable = VK_FALSE; @@ -1642,9 +1643,9 @@ void RenderLayer::PrepareEnvironmentalBrdfLut() { environmental_brdf_lut_texture_storage.sampler = std::make_unique(sampler_info); } - const auto environmental_brdf_pipeline = Graphics::GetGraphicsPipeline("ENVIRONMENTAL_MAP_BRDF"); - Graphics::ImmediateSubmit([&](const VkCommandBuffer command_buffer) { - environmental_brdf_lut_texture_storage.image->TransitImageLayout(command_buffer, + const auto environmental_brdf_pipeline = Platform::GetGraphicsPipeline("ENVIRONMENTAL_MAP_BRDF"); + Platform::ImmediateSubmit([&](VkCommandBuffer vk_command_buffer) { + environmental_brdf_lut_texture_storage.image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); #pragma region Viewport and scissor VkRect2D render_area; @@ -1691,15 +1692,15 @@ void RenderLayer::PrepareEnvironmentalBrdfLut() { i.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT; i.blendEnable = VK_FALSE; } - vkCmdBeginRendering(command_buffer, &render_info); - environmental_brdf_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + environmental_brdf_pipeline->Bind(vk_command_buffer); const auto mesh = Resources::GetResource("PRIMITIVE_TEX_PASS_THROUGH"); - GeometryStorage::BindVertices(command_buffer); - mesh->DrawIndexed(command_buffer, environmental_brdf_pipeline->states, 1); - vkCmdEndRendering(command_buffer); + GeometryStorage::BindVertices(vk_command_buffer); + mesh->DrawIndexed(vk_command_buffer, environmental_brdf_pipeline->states, 1); + vkCmdEndRendering(vk_command_buffer); #pragma endregion } - environmental_brdf_lut_texture_storage.image->TransitImageLayout(command_buffer, + environmental_brdf_lut_texture_storage.image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); }); } @@ -1707,24 +1708,24 @@ void RenderLayer::PrepareEnvironmentalBrdfLut() { void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, const std::shared_ptr& camera) { const bool count_draw_calls = count_shadow_rendering_draw_calls; - const bool use_mesh_shader = Graphics::Constants::enable_mesh_shader && Graphics::Settings::use_mesh_shader; - const auto current_frame_index = Graphics::GetCurrentFrameIndex(); + const bool use_mesh_shader = Platform::Constants::enable_mesh_shader && Platform::Settings::use_mesh_shader; + const auto current_frame_index = Platform::GetCurrentFrameIndex(); const int camera_index = GetCameraIndex(camera->GetHandle()); const auto scene = Application::GetActiveScene(); #pragma region Directional Light Shadows const auto& directional_light_shadow_pipeline = - use_mesh_shader ? Graphics::GetGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP_MESH") - : Graphics::GetGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP"); + use_mesh_shader ? Platform::GetGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP_MESH") + : Platform::GetGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP"); const auto& directional_light_shadow_pipeline_skinned = - Graphics::GetGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP_SKINNED"); + Platform::GetGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP_SKINNED"); const auto& directional_light_shadow_pipeline_instanced = - Graphics::GetGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP_INSTANCED"); + Platform::GetGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP_INSTANCED"); const auto& directional_light_shadow_pipeline_strands = - Graphics::GetGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP_STRANDS"); - auto& graphics = Graphics::GetInstance(); + Platform::GetGraphicsPipeline("DIRECTIONAL_LIGHT_SHADOW_MAP_STRANDS"); + auto& graphics = Platform::GetInstance(); const uint32_t task_work_group_invocations = graphics.mesh_shader_properties_ext_.maxPreferredTaskWorkGroupInvocations; - Graphics::AppendCommands([&](VkCommandBuffer command_buffer) { + Platform::RecordCommandsMainQueue([&](VkCommandBuffer vk_command_buffer) { #pragma region Viewport and scissor VkRect2D render_area; render_area.offset = {0, 0}; @@ -1745,7 +1746,7 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, scissor.extent.height = render_area.extent.height; #pragma endregion - lighting_->directional_light_shadow_map_->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + lighting_->directional_light_shadow_map_->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); for (int split = 0; split < 4; split++) { { @@ -1763,14 +1764,14 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, directional_light_shadow_pipeline->states.view_port = viewport; directional_light_shadow_pipeline->states.color_blend_attachment_states.clear(); - vkCmdBeginRendering(command_buffer, &render_info); - directional_light_shadow_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + directional_light_shadow_pipeline->Bind(vk_command_buffer); directional_light_shadow_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[current_frame_index]->GetVkDescriptorSet()); - GeometryStorage::BindVertices(command_buffer); + vk_command_buffer, 0, per_frame_descriptor_sets_[current_frame_index]->GetVkDescriptorSet()); + GeometryStorage::BindVertices(vk_command_buffer); for (int i = 0; i < render_info_block.directional_light_size; i++) { const auto& directional_light_info_block = - directional_light_info_blocks_[camera_index * Graphics::Settings::max_directional_light_size + i]; + directional_light_info_blocks_[camera_index * Platform::Settings::max_directional_light_size + i]; viewport.x = directional_light_info_block.viewport.x; viewport.y = directional_light_info_block.viewport.y; viewport.width = directional_light_info_block.viewport.z; @@ -1779,30 +1780,30 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, scissor.extent.height = directional_light_info_block.viewport.w; directional_light_shadow_pipeline->states.scissor = scissor; directional_light_shadow_pipeline->states.view_port = viewport; - directional_light_shadow_pipeline->states.ApplyAllStates(command_buffer); + directional_light_shadow_pipeline->states.ApplyAllStates(vk_command_buffer); if (enable_indirect_rendering && !use_mesh_shader) { RenderInstancePushConstant push_constant; - push_constant.camera_index = camera_index * Graphics::Settings::max_directional_light_size + i; + push_constant.camera_index = camera_index * Platform::Settings::max_directional_light_size + i; push_constant.light_split_index = split; push_constant.instance_index = 0; - directional_light_shadow_pipeline->PushConstant(command_buffer, 0, push_constant); - directional_light_shadow_pipeline->states.ApplyAllStates(command_buffer); + directional_light_shadow_pipeline->PushConstant(vk_command_buffer, 0, push_constant); + directional_light_shadow_pipeline->states.ApplyAllStates(vk_command_buffer); if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.triangles[current_frame_index] += total_mesh_triangles_; vkCmdDrawIndexedIndirect( - command_buffer, mesh_draw_indexed_indirect_commands_buffers_[current_frame_index]->GetVkBuffer(), 0, + vk_command_buffer, mesh_draw_indexed_indirect_commands_buffers_[current_frame_index]->GetVkBuffer(), 0, mesh_draw_indexed_indirect_commands_.size(), sizeof(VkDrawIndexedIndirectCommand)); } else { deferred_render_instances_.Dispatch([&](const RenderInstance& render_command) { if (!render_command.cast_shadow) return; RenderInstancePushConstant push_constant; - push_constant.camera_index = camera_index * Graphics::Settings::max_directional_light_size + i; + push_constant.camera_index = camera_index * Platform::Settings::max_directional_light_size + i; push_constant.light_split_index = split; push_constant.instance_index = render_command.instance_index; - directional_light_shadow_pipeline->PushConstant(command_buffer, 0, push_constant); + directional_light_shadow_pipeline->PushConstant(vk_command_buffer, 0, push_constant); if (use_mesh_shader) { if (count_draw_calls) graphics.draw_call[current_frame_index]++; @@ -1811,20 +1812,20 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, const uint32_t count = (render_command.meshlet_size + task_work_group_invocations - 1) / task_work_group_invocations; - vkCmdDrawMeshTasksEXT(command_buffer, count, 1, 1); + vkCmdDrawMeshTasksEXT(vk_command_buffer, count, 1, 1); } else { const auto mesh = render_command.m_mesh; - GeometryStorage::BindVertices(command_buffer); + GeometryStorage::BindVertices(vk_command_buffer); if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.triangles[current_frame_index] += render_command.m_mesh->triangles_.size(); - mesh->DrawIndexed(command_buffer, directional_light_shadow_pipeline->states, 1); + mesh->DrawIndexed(vk_command_buffer, directional_light_shadow_pipeline->states, 1); } }); } } - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } { const auto depth_attachment = lighting_->GetLayeredDirectionalLightDepthAttachmentInfo( @@ -1841,15 +1842,15 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, directional_light_shadow_pipeline_instanced->states.view_port = viewport; directional_light_shadow_pipeline_instanced->states.color_blend_attachment_states.clear(); - vkCmdBeginRendering(command_buffer, &render_info); - directional_light_shadow_pipeline_instanced->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + directional_light_shadow_pipeline_instanced->Bind(vk_command_buffer); directional_light_shadow_pipeline_instanced->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); directional_light_shadow_pipeline_instanced->states.cull_mode = VK_CULL_MODE_NONE; - GeometryStorage::BindVertices(command_buffer); + GeometryStorage::BindVertices(vk_command_buffer); for (int i = 0; i < render_info_block.directional_light_size; i++) { const auto& directional_light_info_block = - directional_light_info_blocks_[camera_index * Graphics::Settings::max_directional_light_size + i]; + directional_light_info_blocks_[camera_index * Platform::Settings::max_directional_light_size + i]; viewport.x = directional_light_info_block.viewport.x; viewport.y = directional_light_info_block.viewport.y; viewport.width = directional_light_info_block.viewport.z; @@ -1858,31 +1859,31 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, scissor.extent.height = directional_light_info_block.viewport.w; directional_light_shadow_pipeline_instanced->states.scissor = scissor; directional_light_shadow_pipeline_instanced->states.view_port = viewport; - directional_light_shadow_pipeline_instanced->states.ApplyAllStates(command_buffer); + directional_light_shadow_pipeline_instanced->states.ApplyAllStates(vk_command_buffer); deferred_instanced_render_instances_.Dispatch([&](const InstancedRenderInstance& render_command) { if (!render_command.cast_shadow) return; directional_light_shadow_pipeline_instanced->BindDescriptorSet( - command_buffer, 1, render_command.particle_infos->GetDescriptorSet()->GetVkDescriptorSet()); + vk_command_buffer, 1, render_command.particle_infos->GetDescriptorSet()->GetVkDescriptorSet()); RenderInstancePushConstant push_constant; - push_constant.camera_index = camera_index * Graphics::Settings::max_directional_light_size + i; + push_constant.camera_index = camera_index * Platform::Settings::max_directional_light_size + i; push_constant.light_split_index = split; push_constant.instance_index = render_command.instance_index; - directional_light_shadow_pipeline_instanced->PushConstant(command_buffer, 0, push_constant); + directional_light_shadow_pipeline_instanced->PushConstant(vk_command_buffer, 0, push_constant); const auto mesh = render_command.mesh; if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.triangles[current_frame_index] += render_command.mesh->triangles_.size() * render_command.particle_infos->PeekParticleInfoList().size(); - mesh->DrawIndexed(command_buffer, directional_light_shadow_pipeline_instanced->states, + mesh->DrawIndexed(vk_command_buffer, directional_light_shadow_pipeline_instanced->states, render_command.particle_infos->PeekParticleInfoList().size()); }); } - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } - GeometryStorage::BindSkinnedVertices(command_buffer); + GeometryStorage::BindSkinnedVertices(vk_command_buffer); { const auto depth_attachment = lighting_->GetLayeredDirectionalLightDepthAttachmentInfo( split, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE); @@ -1898,14 +1899,14 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, directional_light_shadow_pipeline_skinned->states.view_port = viewport; directional_light_shadow_pipeline_skinned->states.color_blend_attachment_states.clear(); - vkCmdBeginRendering(command_buffer, &render_info); - directional_light_shadow_pipeline_skinned->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + directional_light_shadow_pipeline_skinned->Bind(vk_command_buffer); directional_light_shadow_pipeline_skinned->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); directional_light_shadow_pipeline_skinned->states.cull_mode = VK_CULL_MODE_NONE; for (int i = 0; i < render_info_block.directional_light_size; i++) { const auto& directional_light_info_block = - directional_light_info_blocks_[camera_index * Graphics::Settings::max_directional_light_size + i]; + directional_light_info_blocks_[camera_index * Platform::Settings::max_directional_light_size + i]; viewport.x = directional_light_info_block.viewport.x; viewport.y = directional_light_info_block.viewport.y; viewport.width = directional_light_info_block.viewport.z; @@ -1914,29 +1915,29 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, scissor.extent.height = directional_light_info_block.viewport.w; directional_light_shadow_pipeline_skinned->states.scissor = scissor; directional_light_shadow_pipeline_skinned->states.view_port = viewport; - directional_light_shadow_pipeline_skinned->states.ApplyAllStates(command_buffer); + directional_light_shadow_pipeline_skinned->states.ApplyAllStates(vk_command_buffer); deferred_skinned_render_instances_.Dispatch([&](const SkinnedRenderInstance& render_command) { if (!render_command.cast_shadow) return; directional_light_shadow_pipeline_skinned->BindDescriptorSet( - command_buffer, 1, render_command.bone_matrices->GetDescriptorSet()->GetVkDescriptorSet()); + vk_command_buffer, 1, render_command.bone_matrices->GetDescriptorSet()->GetVkDescriptorSet()); RenderInstancePushConstant push_constant; - push_constant.camera_index = camera_index * Graphics::Settings::max_directional_light_size + i; + push_constant.camera_index = camera_index * Platform::Settings::max_directional_light_size + i; push_constant.light_split_index = split; push_constant.instance_index = render_command.instance_index; - directional_light_shadow_pipeline_skinned->PushConstant(command_buffer, 0, push_constant); + directional_light_shadow_pipeline_skinned->PushConstant(vk_command_buffer, 0, push_constant); const auto skinned_mesh = render_command.skinned_mesh; if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.triangles[current_frame_index] += render_command.skinned_mesh->skinned_triangles_.size(); - skinned_mesh->DrawIndexed(command_buffer, directional_light_shadow_pipeline_skinned->states, 1); + skinned_mesh->DrawIndexed(vk_command_buffer, directional_light_shadow_pipeline_skinned->states, 1); }); } - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } - GeometryStorage::BindStrandPoints(command_buffer); + GeometryStorage::BindStrandPoints(vk_command_buffer); { const auto depth_attachment = lighting_->GetLayeredDirectionalLightDepthAttachmentInfo( split, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE); @@ -1952,14 +1953,14 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, directional_light_shadow_pipeline_strands->states.view_port = viewport; directional_light_shadow_pipeline_strands->states.color_blend_attachment_states.clear(); - vkCmdBeginRendering(command_buffer, &render_info); - directional_light_shadow_pipeline_strands->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + directional_light_shadow_pipeline_strands->Bind(vk_command_buffer); directional_light_shadow_pipeline_strands->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); directional_light_shadow_pipeline_strands->states.cull_mode = VK_CULL_MODE_NONE; for (int i = 0; i < render_info_block.directional_light_size; i++) { const auto& directional_light_info_block = - directional_light_info_blocks_[camera_index * Graphics::Settings::max_directional_light_size + i]; + directional_light_info_blocks_[camera_index * Platform::Settings::max_directional_light_size + i]; viewport.x = directional_light_info_block.viewport.x; viewport.y = directional_light_info_block.viewport.y; viewport.width = directional_light_info_block.viewport.z; @@ -1968,25 +1969,25 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, scissor.extent.height = directional_light_info_block.viewport.w; directional_light_shadow_pipeline_strands->states.scissor = scissor; directional_light_shadow_pipeline_strands->states.view_port = viewport; - directional_light_shadow_pipeline_strands->states.ApplyAllStates(command_buffer); + directional_light_shadow_pipeline_strands->states.ApplyAllStates(vk_command_buffer); deferred_strands_render_instances_.Dispatch([&](const StrandsRenderInstance& render_command) { if (!render_command.cast_shadow) return; RenderInstancePushConstant push_constant; - push_constant.camera_index = camera_index * Graphics::Settings::max_directional_light_size + i; + push_constant.camera_index = camera_index * Platform::Settings::max_directional_light_size + i; push_constant.light_split_index = split; push_constant.instance_index = render_command.instance_index; - directional_light_shadow_pipeline_strands->PushConstant(command_buffer, 0, push_constant); + directional_light_shadow_pipeline_strands->PushConstant(vk_command_buffer, 0, push_constant); const auto strands = render_command.m_strands; if (count_draw_calls) graphics.draw_call[current_frame_index]++; if (count_draw_calls) graphics.strands_segments[current_frame_index] += render_command.m_strands->segments_.size(); - strands->DrawIndexed(command_buffer, directional_light_shadow_pipeline_strands->states, 1); + strands->DrawIndexed(vk_command_buffer, directional_light_shadow_pipeline_strands->states, 1); }); } - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } } }); @@ -2003,7 +2004,7 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, } #pragma region Deferred Rendering - Graphics::AppendCommands([&](VkCommandBuffer command_buffer) { + Platform::RecordCommandsMainQueue([&](VkCommandBuffer vk_command_buffer) { #pragma region Viewport and scissor VkRect2D render_area; render_area.offset = {0, 0}; @@ -2022,8 +2023,8 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, scissor.extent.width = camera->GetSize().x; scissor.extent.height = camera->GetSize().y; - camera->TransitGBufferImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); - camera->render_texture_->GetDepthImage()->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + camera->TransitGBufferImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + camera->render_texture_->GetDepthImage()->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); VkRenderingInfo render_info{}; render_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO; @@ -2031,7 +2032,7 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, render_info.layerCount = 1; #pragma endregion #pragma region Geometry pass - GeometryStorage::BindVertices(command_buffer); + GeometryStorage::BindVertices(vk_command_buffer); { const auto depth_attachment = camera->render_texture_->GetDepthAttachmentInfo(VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE); @@ -2043,26 +2044,26 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, render_info.pColorAttachments = color_attachment_infos.data(); const auto& deferred_prepass_pipeline = use_mesh_shader - ? Graphics::GetGraphicsPipeline("STANDARD_DEFERRED_PREPASS_MESH") - : Graphics::GetGraphicsPipeline("STANDARD_DEFERRED_PREPASS"); + ? Platform::GetGraphicsPipeline("STANDARD_DEFERRED_PREPASS_MESH") + : Platform::GetGraphicsPipeline("STANDARD_DEFERRED_PREPASS"); deferred_prepass_pipeline->states.ResetAllStates(color_attachment_infos.size()); deferred_prepass_pipeline->states.view_port = viewport; deferred_prepass_pipeline->states.scissor = scissor; deferred_prepass_pipeline->states.polygon_mode = wire_frame ? VK_POLYGON_MODE_LINE : VK_POLYGON_MODE_FILL; - vkCmdBeginRendering(command_buffer, &render_info); - deferred_prepass_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + deferred_prepass_pipeline->Bind(vk_command_buffer); deferred_prepass_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); if (enable_indirect_rendering && !use_mesh_shader) { if (!deferred_render_instances_.render_commands.empty()) { RenderInstancePushConstant push_constant; push_constant.camera_index = camera_index; push_constant.instance_index = 0; - deferred_prepass_pipeline->PushConstant(command_buffer, 0, push_constant); - GeometryStorage::BindVertices(command_buffer); + deferred_prepass_pipeline->PushConstant(vk_command_buffer, 0, push_constant); + GeometryStorage::BindVertices(vk_command_buffer); graphics.draw_call[current_frame_index]++; graphics.triangles[current_frame_index] += total_mesh_triangles_; - vkCmdDrawIndexedIndirect(command_buffer, + vkCmdDrawIndexedIndirect(vk_command_buffer, mesh_draw_indexed_indirect_commands_buffers_[current_frame_index]->GetVkBuffer(), 0, mesh_draw_indexed_indirect_commands_.size(), sizeof(VkDrawIndexedIndirectCommand)); } @@ -2075,25 +2076,25 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, wire_frame ? VK_POLYGON_MODE_LINE : render_command.polygon_mode; deferred_prepass_pipeline->states.cull_mode = render_command.cull_mode; deferred_prepass_pipeline->states.line_width = render_command.line_width; - deferred_prepass_pipeline->states.ApplyAllStates(command_buffer); - deferred_prepass_pipeline->PushConstant(command_buffer, 0, push_constant); + deferred_prepass_pipeline->states.ApplyAllStates(vk_command_buffer); + deferred_prepass_pipeline->PushConstant(vk_command_buffer, 0, push_constant); if (use_mesh_shader) { graphics.draw_call[current_frame_index]++; graphics.triangles[current_frame_index] += render_command.m_mesh->triangles_.size(); const uint32_t count = (render_command.meshlet_size + task_work_group_invocations - 1) / task_work_group_invocations; - vkCmdDrawMeshTasksEXT(command_buffer, count, 1, 1); + vkCmdDrawMeshTasksEXT(vk_command_buffer, count, 1, 1); } else { const auto mesh = render_command.m_mesh; graphics.draw_call[current_frame_index]++; graphics.triangles[current_frame_index] += render_command.m_mesh->triangles_.size(); - mesh->DrawIndexed(command_buffer, deferred_prepass_pipeline->states, 1); + mesh->DrawIndexed(vk_command_buffer, deferred_prepass_pipeline->states, 1); } }); } - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } { const auto depth_attachment = @@ -2106,17 +2107,17 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, render_info.pColorAttachments = color_attachment_infos.data(); const auto& deferred_instanced_prepass_pipeline = - Graphics::GetGraphicsPipeline("STANDARD_INSTANCED_DEFERRED_PREPASS"); + Platform::GetGraphicsPipeline("STANDARD_INSTANCED_DEFERRED_PREPASS"); deferred_instanced_prepass_pipeline->states.ResetAllStates(color_attachment_infos.size()); deferred_instanced_prepass_pipeline->states.view_port = viewport; deferred_instanced_prepass_pipeline->states.scissor = scissor; - vkCmdBeginRendering(command_buffer, &render_info); - deferred_instanced_prepass_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + deferred_instanced_prepass_pipeline->Bind(vk_command_buffer); deferred_instanced_prepass_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); deferred_instanced_render_instances_.Dispatch([&](const InstancedRenderInstance& render_command) { deferred_instanced_prepass_pipeline->BindDescriptorSet( - command_buffer, 1, render_command.particle_infos->GetDescriptorSet()->GetVkDescriptorSet()); + vk_command_buffer, 1, render_command.particle_infos->GetDescriptorSet()->GetVkDescriptorSet()); RenderInstancePushConstant push_constant; push_constant.camera_index = camera_index; push_constant.instance_index = render_command.instance_index; @@ -2124,19 +2125,19 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, wire_frame ? VK_POLYGON_MODE_LINE : render_command.polygon_mode; deferred_instanced_prepass_pipeline->states.cull_mode = render_command.cull_mode; deferred_instanced_prepass_pipeline->states.line_width = render_command.line_width; - deferred_instanced_prepass_pipeline->states.ApplyAllStates(command_buffer); - deferred_instanced_prepass_pipeline->PushConstant(command_buffer, 0, push_constant); + deferred_instanced_prepass_pipeline->states.ApplyAllStates(vk_command_buffer); + deferred_instanced_prepass_pipeline->PushConstant(vk_command_buffer, 0, push_constant); const auto mesh = render_command.mesh; graphics.draw_call[current_frame_index]++; graphics.triangles[current_frame_index] += render_command.mesh->triangles_.size() * render_command.particle_infos->PeekParticleInfoList().size(); - mesh->DrawIndexed(command_buffer, deferred_instanced_prepass_pipeline->states, + mesh->DrawIndexed(vk_command_buffer, deferred_instanced_prepass_pipeline->states, render_command.particle_infos->PeekParticleInfoList().size()); }); - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } - GeometryStorage::BindSkinnedVertices(command_buffer); + GeometryStorage::BindSkinnedVertices(vk_command_buffer); { const auto depth_attachment = camera->render_texture_->GetDepthAttachmentInfo(VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE); @@ -2148,18 +2149,18 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, render_info.pColorAttachments = color_attachment_infos.data(); const auto& deferred_skinned_prepass_pipeline = - Graphics::GetGraphicsPipeline("STANDARD_SKINNED_DEFERRED_PREPASS"); + Platform::GetGraphicsPipeline("STANDARD_SKINNED_DEFERRED_PREPASS"); deferred_skinned_prepass_pipeline->states.ResetAllStates(color_attachment_infos.size()); deferred_skinned_prepass_pipeline->states.view_port = viewport; deferred_skinned_prepass_pipeline->states.scissor = scissor; - vkCmdBeginRendering(command_buffer, &render_info); - deferred_skinned_prepass_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + deferred_skinned_prepass_pipeline->Bind(vk_command_buffer); deferred_skinned_prepass_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); deferred_skinned_render_instances_.Dispatch([&](const SkinnedRenderInstance& render_command) { deferred_skinned_prepass_pipeline->BindDescriptorSet( - command_buffer, 1, render_command.bone_matrices->GetDescriptorSet()->GetVkDescriptorSet()); + vk_command_buffer, 1, render_command.bone_matrices->GetDescriptorSet()->GetVkDescriptorSet()); RenderInstancePushConstant push_constant; push_constant.camera_index = camera_index; push_constant.instance_index = render_command.instance_index; @@ -2167,17 +2168,17 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, wire_frame ? VK_POLYGON_MODE_LINE : render_command.polygon_mode; deferred_skinned_prepass_pipeline->states.cull_mode = render_command.cull_mode; deferred_skinned_prepass_pipeline->states.line_width = render_command.line_width; - deferred_skinned_prepass_pipeline->states.ApplyAllStates(command_buffer); - deferred_skinned_prepass_pipeline->PushConstant(command_buffer, 0, push_constant); + deferred_skinned_prepass_pipeline->states.ApplyAllStates(vk_command_buffer); + deferred_skinned_prepass_pipeline->PushConstant(vk_command_buffer, 0, push_constant); const auto skinned_mesh = render_command.skinned_mesh; graphics.draw_call[current_frame_index]++; graphics.triangles[current_frame_index] += render_command.skinned_mesh->skinned_triangles_.size(); - skinned_mesh->DrawIndexed(command_buffer, deferred_skinned_prepass_pipeline->states, 1); + skinned_mesh->DrawIndexed(vk_command_buffer, deferred_skinned_prepass_pipeline->states, 1); }); - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } - GeometryStorage::BindStrandPoints(command_buffer); + GeometryStorage::BindStrandPoints(vk_command_buffer); { const auto depth_attachment = camera->render_texture_->GetDepthAttachmentInfo(VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE); @@ -2189,15 +2190,15 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, render_info.pColorAttachments = color_attachment_infos.data(); const auto& deferred_strands_prepass_pipeline = - Graphics::GetGraphicsPipeline("STANDARD_STRANDS_DEFERRED_PREPASS"); + Platform::GetGraphicsPipeline("STANDARD_STRANDS_DEFERRED_PREPASS"); deferred_strands_prepass_pipeline->states.ResetAllStates(color_attachment_infos.size()); deferred_strands_prepass_pipeline->states.view_port = viewport; deferred_strands_prepass_pipeline->states.scissor = scissor; - vkCmdBeginRendering(command_buffer, &render_info); - deferred_strands_prepass_pipeline->Bind(command_buffer); + vkCmdBeginRendering(vk_command_buffer, &render_info); + deferred_strands_prepass_pipeline->Bind(vk_command_buffer); deferred_strands_prepass_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); deferred_strands_render_instances_.Dispatch([&](const StrandsRenderInstance& render_command) { RenderInstancePushConstant push_constant; push_constant.camera_index = camera_index; @@ -2206,22 +2207,22 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, wire_frame ? VK_POLYGON_MODE_LINE : render_command.polygon_mode; deferred_strands_prepass_pipeline->states.cull_mode = render_command.cull_mode; deferred_strands_prepass_pipeline->states.line_width = render_command.line_width; - deferred_strands_prepass_pipeline->PushConstant(command_buffer, 0, push_constant); + deferred_strands_prepass_pipeline->PushConstant(vk_command_buffer, 0, push_constant); const auto strands = render_command.m_strands; graphics.draw_call[current_frame_index]++; graphics.strands_segments[current_frame_index] += render_command.m_strands->segments_.size(); - strands->DrawIndexed(command_buffer, deferred_strands_prepass_pipeline->states, 1); + strands->DrawIndexed(vk_command_buffer, deferred_strands_prepass_pipeline->states, 1); }); - vkCmdEndRendering(command_buffer); + vkCmdEndRendering(vk_command_buffer); } #pragma endregion #pragma region Lighting pass - GeometryStorage::BindVertices(command_buffer); + GeometryStorage::BindVertices(vk_command_buffer); { - camera->TransitGBufferImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - camera->render_texture_->GetDepthImage()->TransitImageLayout(command_buffer, + camera->TransitGBufferImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + camera->render_texture_->GetDepthImage()->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); std::vector color_attachment_infos; camera->GetRenderTexture()->AppendColorAttachmentInfos(color_attachment_infos, VK_ATTACHMENT_LOAD_OP_CLEAR, @@ -2233,21 +2234,21 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, render_info.colorAttachmentCount = color_attachment_infos.size(); render_info.pColorAttachments = color_attachment_infos.data(); render_info.pDepthAttachment = VK_NULL_HANDLE; - lighting_->directional_light_shadow_map_->TransitImageLayout(command_buffer, + lighting_->directional_light_shadow_map_->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); const auto& deferred_lighting_pipeline = - is_scene_camera ? Graphics::GetGraphicsPipeline("STANDARD_DEFERRED_LIGHTING_SCENE_CAMERA") - : Graphics::GetGraphicsPipeline("STANDARD_DEFERRED_LIGHTING"); - vkCmdBeginRendering(command_buffer, &render_info); + is_scene_camera ? Platform::GetGraphicsPipeline("STANDARD_DEFERRED_LIGHTING_SCENE_CAMERA") + : Platform::GetGraphicsPipeline("STANDARD_DEFERRED_LIGHTING"); + vkCmdBeginRendering(vk_command_buffer, &render_info); deferred_lighting_pipeline->states.ResetAllStates(color_attachment_infos.size()); deferred_lighting_pipeline->states.depth_test = false; - deferred_lighting_pipeline->Bind(command_buffer); + deferred_lighting_pipeline->Bind(vk_command_buffer); deferred_lighting_pipeline->BindDescriptorSet( - command_buffer, 0, per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]->GetVkDescriptorSet()); - deferred_lighting_pipeline->BindDescriptorSet(command_buffer, 1, + vk_command_buffer, 0, per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]->GetVkDescriptorSet()); + deferred_lighting_pipeline->BindDescriptorSet(vk_command_buffer, 1, camera->g_buffer_descriptor_set_->GetVkDescriptorSet()); - deferred_lighting_pipeline->BindDescriptorSet(command_buffer, 2, + deferred_lighting_pipeline->BindDescriptorSet(vk_command_buffer, 2, lighting_->lighting_descriptor_set->GetVkDescriptorSet()); deferred_lighting_pipeline->states.view_port = viewport; deferred_lighting_pipeline->states.scissor = scissor; @@ -2255,11 +2256,11 @@ void RenderLayer::RenderToCamera(const GlobalTransform& camera_global_transform, push_constant.camera_index = camera_index; push_constant.light_split_index = need_fade ? glm::max(128, 256 - editor_layer->selection_alpha_) : 256; push_constant.instance_index = need_fade ? 1 : 0; - deferred_lighting_pipeline->PushConstant(command_buffer, 0, push_constant); + deferred_lighting_pipeline->PushConstant(vk_command_buffer, 0, push_constant); const auto mesh = Resources::GetResource("PRIMITIVE_TEX_PASS_THROUGH"); - mesh->DrawIndexed(command_buffer, deferred_lighting_pipeline->states, 1); - vkCmdEndRendering(command_buffer); + mesh->DrawIndexed(vk_command_buffer, deferred_lighting_pipeline->states, 1); + vkCmdEndRendering(vk_command_buffer); } #pragma endregion }); @@ -2516,7 +2517,7 @@ void RenderLayer::DrawMesh(const std::shared_ptr& mesh, const std::shared_ } const std::shared_ptr& RenderLayer::GetPerFrameDescriptorSet() const { - return per_frame_descriptor_sets_[Graphics::GetCurrentFrameIndex()]; + return per_frame_descriptor_sets_[Platform::GetCurrentFrameIndex()]; } bool RenderLayer::TryRegisterRenderer(const std::shared_ptr& scene, const Entity& owner, diff --git a/EvoEngine_SDK/src/RenderTexture.cpp b/EvoEngine_SDK/src/RenderTexture.cpp index 63f90e0..bc855a8 100644 --- a/EvoEngine_SDK/src/RenderTexture.cpp +++ b/EvoEngine_SDK/src/RenderTexture.cpp @@ -2,7 +2,7 @@ #include "Console.hpp" #include "EditorLayer.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" using namespace evo_engine; @@ -48,7 +48,7 @@ void RenderTexture::Initialize(const RenderTextureCreateInfo& render_texture_cre image_info.extent = render_texture_create_info.extent; image_info.mipLevels = 1; image_info.arrayLayers = layer_count; - image_info.format = Graphics::Constants::render_texture_color; + image_info.format = Platform::Constants::render_texture_color; image_info.tiling = VK_IMAGE_TILING_OPTIMAL; image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; image_info.usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | @@ -57,15 +57,15 @@ void RenderTexture::Initialize(const RenderTextureCreateInfo& render_texture_cre image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; color_image_ = std::make_shared(image_info); - Graphics::ImmediateSubmit([&](const VkCommandBuffer command_buffer) { - color_image_->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { + color_image_->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); }); VkImageViewCreateInfo view_info{}; view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; view_info.image = color_image_->GetVkImage(); view_info.viewType = render_texture_create_info.image_view_type; - view_info.format = Graphics::Constants::render_texture_color; + view_info.format = Platform::Constants::render_texture_color; view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; view_info.subresourceRange.baseMipLevel = 0; view_info.subresourceRange.levelCount = 1; @@ -82,7 +82,7 @@ void RenderTexture::Initialize(const RenderTextureCreateInfo& render_texture_cre sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; sampler_info.anisotropyEnable = VK_TRUE; - sampler_info.maxAnisotropy = Graphics::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; + sampler_info.maxAnisotropy = Platform::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; sampler_info.unnormalizedCoordinates = VK_FALSE; sampler_info.compareEnable = VK_FALSE; @@ -102,7 +102,7 @@ void RenderTexture::Initialize(const RenderTextureCreateInfo& render_texture_cre depth_info.extent = render_texture_create_info.extent; depth_info.mipLevels = 1; depth_info.arrayLayers = layer_count; - depth_info.format = Graphics::Constants::render_texture_depth; + depth_info.format = Platform::Constants::render_texture_depth; depth_info.tiling = VK_IMAGE_TILING_OPTIMAL; depth_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; depth_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | @@ -111,15 +111,15 @@ void RenderTexture::Initialize(const RenderTextureCreateInfo& render_texture_cre depth_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; depth_image_ = std::make_shared(depth_info); - Graphics::ImmediateSubmit([&](const VkCommandBuffer command_buffer) { - depth_image_->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { + depth_image_->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); }); VkImageViewCreateInfo depth_view_info{}; depth_view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; depth_view_info.image = depth_image_->GetVkImage(); depth_view_info.viewType = render_texture_create_info.image_view_type; - depth_view_info.format = Graphics::Constants::render_texture_depth; + depth_view_info.format = Platform::Constants::render_texture_depth; depth_view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; depth_view_info.subresourceRange.baseMipLevel = 0; depth_view_info.subresourceRange.levelCount = 1; @@ -136,7 +136,7 @@ void RenderTexture::Initialize(const RenderTextureCreateInfo& render_texture_cre depth_sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; depth_sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; depth_sampler_info.anisotropyEnable = VK_TRUE; - depth_sampler_info.maxAnisotropy = Graphics::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; + depth_sampler_info.maxAnisotropy = Platform::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; depth_sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; depth_sampler_info.unnormalizedCoordinates = VK_FALSE; depth_sampler_info.compareEnable = VK_FALSE; @@ -150,7 +150,7 @@ void RenderTexture::Initialize(const RenderTextureCreateInfo& render_texture_cre if (color_) { descriptor_set_ = - std::make_shared(Graphics::GetDescriptorSetLayout("RENDER_TEXTURE_PRESENT_LAYOUT")); + std::make_shared(Platform::GetDescriptorSetLayout("RENDER_TEXTURE_PRESENT_LAYOUT")); VkDescriptorImageInfo descriptor_image_info; descriptor_image_info.imageLayout = color_image_->GetLayout(); descriptor_image_info.imageView = color_image_view_->GetVkImageView(); @@ -159,10 +159,10 @@ void RenderTexture::Initialize(const RenderTextureCreateInfo& render_texture_cre } } -void RenderTexture::Clear(const VkCommandBuffer command_buffer) const { +void RenderTexture::Clear(VkCommandBuffer vk_command_buffer) const { if (depth_) { const auto prev_depth_layout = depth_image_->GetLayout(); - depth_image_->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + depth_image_->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); VkImageSubresourceRange depth_subresource_range{}; depth_subresource_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; depth_subresource_range.baseMipLevel = 0; @@ -171,13 +171,13 @@ void RenderTexture::Clear(const VkCommandBuffer command_buffer) const { depth_subresource_range.layerCount = 1; VkClearDepthStencilValue depth_stencil_value{}; depth_stencil_value = {1, 0}; - vkCmdClearDepthStencilImage(command_buffer, depth_image_->GetVkImage(), depth_image_->GetLayout(), + vkCmdClearDepthStencilImage(vk_command_buffer, depth_image_->GetVkImage(), depth_image_->GetLayout(), &depth_stencil_value, 1, &depth_subresource_range); - depth_image_->TransitImageLayout(command_buffer, prev_depth_layout); + depth_image_->TransitImageLayout(vk_command_buffer, prev_depth_layout); } if (color_) { const auto prev_color_layout = color_image_->GetLayout(); - color_image_->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + color_image_->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); VkImageSubresourceRange color_subresource_range{}; color_subresource_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; color_subresource_range.baseMipLevel = 0; @@ -186,9 +186,9 @@ void RenderTexture::Clear(const VkCommandBuffer command_buffer) const { color_subresource_range.layerCount = 1; VkClearColorValue color_value{}; color_value = {0, 0, 0, 1}; - vkCmdClearColorImage(command_buffer, color_image_->GetVkImage(), color_image_->GetLayout(), &color_value, 1, + vkCmdClearColorImage(vk_command_buffer, color_image_->GetVkImage(), color_image_->GetLayout(), &color_value, 1, &color_subresource_range); - color_image_->TransitImageLayout(command_buffer, prev_color_layout); + color_image_->TransitImageLayout(vk_command_buffer, prev_color_layout); } } @@ -275,12 +275,12 @@ const std::shared_ptr& RenderTexture::GetDepthImageView() { return depth_image_view_; } -void RenderTexture::BeginRendering(const VkCommandBuffer command_buffer, const VkAttachmentLoadOp load_op, +void RenderTexture::BeginRendering(const VkCommandBuffer vk_command_buffer, const VkAttachmentLoadOp load_op, const VkAttachmentStoreOp store_op) const { if (depth_) - depth_image_->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + depth_image_->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); if (color_) - color_image_->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); + color_image_->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL); VkRect2D render_area; render_area.offset = {0, 0}; render_area.extent.width = extent_.width; @@ -305,11 +305,11 @@ void RenderTexture::BeginRendering(const VkCommandBuffer command_buffer, const V render_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO; render_info.renderArea = render_area; render_info.layerCount = 1; - vkCmdBeginRendering(command_buffer, &render_info); + vkCmdBeginRendering(vk_command_buffer, &render_info); } -void RenderTexture::EndRendering(const VkCommandBuffer command_buffer) const { - vkCmdEndRendering(command_buffer); +void RenderTexture::EndRendering(VkCommandBuffer vk_command_buffer) const { + vkCmdEndRendering(vk_command_buffer); } ImTextureID RenderTexture::GetColorImTextureId() const { diff --git a/EvoEngine_SDK/src/Resources.cpp b/EvoEngine_SDK/src/Resources.cpp index 04eb64d..f7a7b56 100644 --- a/EvoEngine_SDK/src/Resources.cpp +++ b/EvoEngine_SDK/src/Resources.cpp @@ -14,29 +14,29 @@ void Resources::LoadShaders() { #pragma region Shader Includes std::string add; uint32_t mesh_work_group_invocations = - Graphics::GetInstance().mesh_shader_properties_ext_.maxPreferredMeshWorkGroupInvocations; + Platform::GetInstance().mesh_shader_properties_ext_.maxPreferredMeshWorkGroupInvocations; uint32_t task_work_group_invocations = - Graphics::GetInstance().mesh_shader_properties_ext_.maxPreferredTaskWorkGroupInvocations; + Platform::GetInstance().mesh_shader_properties_ext_.maxPreferredTaskWorkGroupInvocations; - uint32_t mesh_subgroup_size = Graphics::GetInstance().vk_physical_device_vulkan11_properties_.subgroupSize; - uint32_t mesh_subgroup_count = (std::min(std::max(Graphics::Constants::meshlet_max_vertices_size, - Graphics::Constants::meshlet_max_triangles_size), + uint32_t mesh_subgroup_size = Platform::GetInstance().vk_physical_device_vulkan11_properties_.subgroupSize; + uint32_t mesh_subgroup_count = (std::min(std::max(Platform::Constants::meshlet_max_vertices_size, + Platform::Constants::meshlet_max_triangles_size), mesh_work_group_invocations) + mesh_subgroup_size - 1) / mesh_subgroup_size; - uint32_t task_subgroup_size = Graphics::GetInstance().vk_physical_device_vulkan11_properties_.subgroupSize; + uint32_t task_subgroup_size = Platform::GetInstance().vk_physical_device_vulkan11_properties_.subgroupSize; uint32_t task_subgroup_count = (task_work_group_invocations + task_subgroup_size - 1) / task_subgroup_size; task_subgroup_size = glm::max(task_subgroup_size, 1u); mesh_subgroup_size = glm::max(mesh_subgroup_size, 1u); task_subgroup_count = glm::max(task_subgroup_count, 1u); mesh_subgroup_count = glm::max(mesh_subgroup_count, 1u); - add += "\n#define MAX_DIRECTIONAL_LIGHT_SIZE " + std::to_string(Graphics::Settings::max_directional_light_size) + - "\n#define MAX_KERNEL_AMOUNT " + std::to_string(Graphics::Constants::max_kernel_amount) + - "\n#define MESHLET_MAX_VERTICES_SIZE " + std::to_string(Graphics::Constants::meshlet_max_vertices_size) + - "\n#define MESHLET_MAX_TRIANGLES_SIZE " + std::to_string(Graphics::Constants::meshlet_max_triangles_size) + - "\n#define MESHLET_MAX_INDICES_SIZE " + std::to_string(Graphics::Constants::meshlet_max_triangles_size * 3) + add += "\n#define MAX_DIRECTIONAL_LIGHT_SIZE " + std::to_string(Platform::Settings::max_directional_light_size) + + "\n#define MAX_KERNEL_AMOUNT " + std::to_string(Platform::Constants::max_kernel_amount) + + "\n#define MESHLET_MAX_VERTICES_SIZE " + std::to_string(Platform::Constants::meshlet_max_vertices_size) + + "\n#define MESHLET_MAX_TRIANGLES_SIZE " + std::to_string(Platform::Constants::meshlet_max_triangles_size) + + "\n#define MESHLET_MAX_INDICES_SIZE " + std::to_string(Platform::Constants::meshlet_max_triangles_size * 3) + "\n#define EXT_TASK_SUBGROUP_SIZE " + std::to_string(task_subgroup_size) + "\n#define EXT_MESH_SUBGROUP_SIZE " + std::to_string(mesh_subgroup_size) + @@ -47,17 +47,17 @@ void Resources::LoadShaders() { + "\n"; - Graphics::GetInstance().shader_basic_ = + Platform::GetInstance().shader_basic_ = add + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Include/Basic.glsl"); - Graphics::GetInstance().shader_basic_constants_ = + Platform::GetInstance().shader_basic_constants_ = add + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Include/BasicConstants.glsl"); - Graphics::GetInstance().shader_gizmos_constants_ = + Platform::GetInstance().shader_gizmos_constants_ = add + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Include/GizmosConstants.glsl"); - Graphics::GetInstance().shader_lighting_ = + Platform::GetInstance().shader_lighting_ = FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Include/Lighting.glsl"); - Graphics::GetInstance().shader_ssr_constants_ = + Platform::GetInstance().shader_ssr_constants_ = add + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Include/SSRConstants.glsl"); @@ -65,78 +65,78 @@ void Resources::LoadShaders() { #pragma region Standard Shader { - auto vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Standard/Standard.vert"); auto standard_vert = CreateResource("STANDARD_VERT"); standard_vert->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Standard/StandardSkinned.vert"); standard_vert = CreateResource("STANDARD_SKINNED_VERT"); standard_vert->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Standard/StandardInstanced.vert"); standard_vert = CreateResource("STANDARD_INSTANCED_VERT"); standard_vert->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Standard/StandardStrands.vert"); standard_vert = CreateResource("STANDARD_STRANDS_VERT"); standard_vert->Set(ShaderType::Vertex, vert_shader_code); - auto tesc_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto tesc_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/TessellationControl/Standard/StandardStrands.tesc"); auto standard_tesc = CreateResource("STANDARD_STRANDS_TESC"); standard_tesc->Set(ShaderType::TessellationControl, tesc_shader_code); - auto tese_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto tese_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/TessellationEvaluation/Standard/StandardStrands.tese"); auto standard_tese = CreateResource("STANDARD_STRANDS_TESE"); standard_tese->Set(ShaderType::TessellationEvaluation, tese_shader_code); - auto geom_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto geom_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Geometry/Standard/StandardStrands.geom"); auto standard_geom = CreateResource("STANDARD_STRANDS_GEOM"); standard_geom->Set(ShaderType::Geometry, geom_shader_code); - auto task_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto task_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Task/Standard/Standard.task"); auto standard_task = CreateResource("STANDARD_TASK"); standard_task->Set(ShaderType::Task, task_shader_code); - auto mesh_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto mesh_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Mesh/Standard/Standard.mesh"); auto standard_mesh = CreateResource("STANDARD_MESH"); standard_mesh->Set(ShaderType::Mesh, mesh_shader_code); - mesh_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + mesh_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Mesh/Standard/StandardMeshletColored.mesh"); standard_mesh = CreateResource("STANDARD_MESHLET_COLORED_MESH"); @@ -158,24 +158,24 @@ void Resources::LoadShaders() { #pragma region GBuffer { - auto frag_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + - Graphics::GetInstance().shader_basic_ + "\n" + "\n" + - Graphics::GetInstance().shader_lighting_ + "\n" + + auto frag_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + + Platform::GetInstance().shader_basic_ + "\n" + "\n" + + Platform::GetInstance().shader_lighting_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Fragment/Standard/StandardDeferredLighting.frag"); auto frag_shader = CreateResource("STANDARD_DEFERRED_LIGHTING_FRAG"); frag_shader->Set(ShaderType::Fragment, frag_shader_code); frag_shader_code = - std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + - Graphics::GetInstance().shader_basic_ + "\n" + "\n" + Graphics::GetInstance().shader_lighting_ + "\n" + + std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + + Platform::GetInstance().shader_basic_ + "\n" + "\n" + Platform::GetInstance().shader_lighting_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Fragment/Standard/StandardDeferredLightingSceneCamera.frag"); frag_shader = CreateResource("STANDARD_DEFERRED_LIGHTING_SCENE_CAMERA_FRAG"); frag_shader->Set(ShaderType::Fragment, frag_shader_code); - frag_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + frag_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Fragment/Standard/StandardDeferred.frag"); frag_shader = CreateResource("STANDARD_DEFERRED_FRAG"); @@ -185,20 +185,20 @@ void Resources::LoadShaders() { #pragma region PostProcessing { - auto frag_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_ssr_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto frag_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_ssr_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Fragment/PostProcessing/SSRReflect.frag"); auto frag_shader = CreateResource("SSR_REFLECT_FRAG"); frag_shader->Set(ShaderType::Fragment, frag_shader_code); - frag_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_ssr_constants_ + "\n" + + frag_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_ssr_constants_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Fragment/PostProcessing/SSRBlur.frag"); frag_shader = CreateResource("SSR_BLUR_FRAG"); frag_shader->Set(ShaderType::Fragment, frag_shader_code); - frag_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_ssr_constants_ + "\n" + + frag_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_ssr_constants_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Fragment/PostProcessing/SSRCombine.frag"); frag_shader = CreateResource("SSR_COMBINE_FRAG"); @@ -207,104 +207,104 @@ void Resources::LoadShaders() { #pragma endregion #pragma region Shadow Maps { - auto vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Lighting/DirectionalLightShadowMap.vert"); auto vert_shader = CreateResource("DIRECTIONAL_LIGHT_SHADOW_MAP_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Lighting/DirectionalLightShadowMapSkinned.vert"); vert_shader = CreateResource("DIRECTIONAL_LIGHT_SHADOW_MAP_SKINNED_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Lighting/DirectionalLightShadowMapInstanced.vert"); vert_shader = CreateResource("DIRECTIONAL_LIGHT_SHADOW_MAP_INSTANCED_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Lighting/DirectionalLightShadowMapStrands.vert"); vert_shader = CreateResource("DIRECTIONAL_LIGHT_SHADOW_MAP_STRANDS_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Lighting/PointLightShadowMap.vert"); vert_shader = CreateResource("POINT_LIGHT_SHADOW_MAP_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Lighting/PointLightShadowMapSkinned.vert"); vert_shader = CreateResource("POINT_LIGHT_SHADOW_MAP_SKINNED_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Lighting/PointLightShadowMapInstanced.vert"); vert_shader = CreateResource("POINT_LIGHT_SHADOW_MAP_INSTANCED_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Lighting/PointLightShadowMapStrands.vert"); vert_shader = CreateResource("POINT_LIGHT_SHADOW_MAP_STRANDS_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Lighting/SpotLightShadowMap.vert"); vert_shader = CreateResource("SPOT_LIGHT_SHADOW_MAP_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Lighting/SpotLightShadowMapSkinned.vert"); vert_shader = CreateResource("SPOT_LIGHT_SHADOW_MAP_SKINNED_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Lighting/SpotLightShadowMapInstanced.vert"); vert_shader = CreateResource("SPOT_LIGHT_SHADOW_MAP_INSTANCED_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Lighting/SpotLightShadowMapStrands.vert"); vert_shader = CreateResource("SPOT_LIGHT_SHADOW_MAP_STRANDS_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - auto tesc_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto tesc_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/TessellationControl/Lighting/ShadowMapStrands.tesc"); @@ -312,8 +312,8 @@ void Resources::LoadShaders() { tesc_shader->Set(ShaderType::TessellationControl, tesc_shader_code); auto tese_shader_code = - std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/TessellationEvaluation/Lighting/ShadowMapStrands.tese"); @@ -321,72 +321,72 @@ void Resources::LoadShaders() { tese_shader->Set(ShaderType::TessellationEvaluation, tese_shader_code); auto geom_shader_code = - std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Geometry/Lighting/DirectionalLightShadowMapStrands.geom"); auto geom_shader = CreateResource("DIRECTIONAL_LIGHT_SHADOW_MAP_STRANDS_GEOM"); geom_shader->Set(ShaderType::Geometry, geom_shader_code); - geom_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + geom_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Geometry/Lighting/PointLightShadowMapStrands.geom"); geom_shader = CreateResource("POINT_LIGHT_SHADOW_MAP_STRANDS_GEOM"); geom_shader->Set(ShaderType::Geometry, geom_shader_code); - geom_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + geom_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Geometry/Lighting/SpotLightShadowMapStrands.geom"); geom_shader = CreateResource("SPOT_LIGHT_SHADOW_MAP_STRANDS_GEOM"); geom_shader->Set(ShaderType::Geometry, geom_shader_code); - auto task_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto task_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Task/Lighting/DirectionalLightShadowMap.task"); auto task_shader = CreateResource("DIRECTIONAL_LIGHT_SHADOW_MAP_TASK"); task_shader->Set(ShaderType::Task, task_shader_code); - task_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + task_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Task/Lighting/PointLightShadowMap.task"); task_shader = CreateResource("POINT_LIGHT_SHADOW_MAP_TASK"); task_shader->Set(ShaderType::Task, task_shader_code); - task_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + task_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Task/Lighting/SpotLightShadowMap.task"); task_shader = CreateResource("SPOT_LIGHT_SHADOW_MAP_TASK"); task_shader->Set(ShaderType::Task, task_shader_code); - auto mesh_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto mesh_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Mesh/Lighting/DirectionalLightShadowMap.mesh"); auto mesh_shader = CreateResource("DIRECTIONAL_LIGHT_SHADOW_MAP_MESH"); mesh_shader->Set(ShaderType::Mesh, mesh_shader_code); - mesh_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + mesh_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Mesh/Lighting/PointLightShadowMap.mesh"); mesh_shader = CreateResource("POINT_LIGHT_SHADOW_MAP_MESH"); mesh_shader->Set(ShaderType::Mesh, mesh_shader_code); - mesh_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + mesh_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Mesh/Lighting/SpotLightShadowMap.mesh"); @@ -394,14 +394,14 @@ void Resources::LoadShaders() { mesh_shader->Set(ShaderType::Mesh, mesh_shader_code); auto frag_shader_code = - std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Fragment/Empty.frag"); auto frag_shader = CreateResource("EMPTY_FRAG"); frag_shader->Set(ShaderType::Fragment, frag_shader_code); - frag_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_basic_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + frag_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_basic_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Fragment/ShadowMapPassThrough.frag"); frag_shader = CreateResource("SHADOW_MAP_PASS_THROUGH_FRAG"); @@ -446,105 +446,105 @@ void Resources::LoadShaders() { #pragma region Gizmos { auto vert_shader_code = - std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Gizmos/Gizmos.vert"); auto vert_shader = CreateResource("GIZMOS_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Gizmos/GizmosStrands.vert"); vert_shader = CreateResource("GIZMOS_STRANDS_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Gizmos/GizmosInstancedColored.vert"); vert_shader = CreateResource("GIZMOS_INSTANCED_COLORED_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Gizmos/GizmosNormalColored.vert"); vert_shader = CreateResource("GIZMOS_NORMAL_COLORED_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Gizmos/GizmosStrandsNormalColored.vert"); vert_shader = CreateResource("GIZMOS_STRANDS_NORMAL_COLORED_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Gizmos/GizmosVertexColored.vert"); vert_shader = CreateResource("GIZMOS_VERTEX_COLORED_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - std::string tesc_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + - "\n" + Graphics::GetInstance().shader_basic_ + "\n" + + std::string tesc_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + + "\n" + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/TessellationControl/Gizmos/GizmosStrands.tesc"); auto tesc_shader = CreateResource("GIZMOS_STRANDS_TESC"); tesc_shader->Set(ShaderType::TessellationControl, tesc_shader_code); - tesc_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + tesc_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/TessellationControl/Gizmos/GizmosStrandsColored.tesc"); tesc_shader = CreateResource("GIZMOS_STRANDS_COLORED_TESC"); tesc_shader->Set(ShaderType::TessellationControl, tesc_shader_code); - auto tese_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto tese_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/TessellationEvaluation/Gizmos/GizmosStrands.tese"); auto tese_shader = CreateResource("GIZMOS_STRANDS_TESE"); tese_shader->Set(ShaderType::TessellationEvaluation, tese_shader_code); - tese_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + tese_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/TessellationEvaluation/Gizmos/GizmosStrandsColored.tese"); tese_shader = CreateResource("GIZMOS_STRANDS_COLORED_TESE"); tese_shader->Set(ShaderType::TessellationEvaluation, tese_shader_code); - auto geom_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto geom_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Geometry/Gizmos/GizmosStrands.geom"); auto geom_shader = CreateResource("GIZMOS_STRANDS_GEOM"); geom_shader->Set(ShaderType::Geometry, geom_shader_code); - geom_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + geom_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Geometry/Gizmos/GizmosStrandsColored.geom"); geom_shader = CreateResource("GIZMOS_STRANDS_COLORED_GEOM"); geom_shader->Set(ShaderType::Geometry, geom_shader_code); - vert_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + vert_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Vertex/Gizmos/GizmosStrandsVertexColored.vert"); vert_shader = CreateResource("GIZMOS_STRANDS_VERTEX_COLORED_VERT"); vert_shader->Set(ShaderType::Vertex, vert_shader_code); - auto frag_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + auto frag_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Fragment/Gizmos/Gizmos.frag"); auto frag_shader = CreateResource("GIZMOS_FRAG"); frag_shader->Set(ShaderType::Fragment, frag_shader_code); - frag_shader_code = std::string("#version 460\n") + Graphics::GetInstance().shader_gizmos_constants_ + "\n" + - Graphics::GetInstance().shader_basic_ + "\n" + + frag_shader_code = std::string("#version 460\n") + Platform::GetInstance().shader_gizmos_constants_ + "\n" + + Platform::GetInstance().shader_basic_ + "\n" + FileUtils::LoadFileAsString(std::filesystem::path("./DefaultResources") / "Shaders/Fragment/Gizmos/GizmosColored.frag"); frag_shader = CreateResource("GIZMOS_COLORED_FRAG"); diff --git a/EvoEngine_SDK/src/Shader.cpp b/EvoEngine_SDK/src/Shader.cpp index b8c1d74..43e0a4e 100644 --- a/EvoEngine_SDK/src/Shader.cpp +++ b/EvoEngine_SDK/src/Shader.cpp @@ -18,4 +18,8 @@ void Shader::Set(const ShaderType shader_type, const std::string& shader_code) { } const std::unique_ptr& Shader::GetShaderModule() const { return shader_module_; -} \ No newline at end of file +} + +ShaderType Shader::GetShaderType() const { + return shader_type_; +} diff --git a/EvoEngine_SDK/src/SkinnedMesh.cpp b/EvoEngine_SDK/src/SkinnedMesh.cpp index 0fe3b66..79f3bc1 100644 --- a/EvoEngine_SDK/src/SkinnedMesh.cpp +++ b/EvoEngine_SDK/src/SkinnedMesh.cpp @@ -23,7 +23,7 @@ void SkinnedVertexAttributes::Deserialize(const YAML::Node& in) { } const std::shared_ptr& BoneMatrices::GetDescriptorSet() const { - const auto current_frame_index = Graphics::GetCurrentFrameIndex(); + const auto current_frame_index = Platform::GetCurrentFrameIndex(); return descriptor_set_[current_frame_index]; } @@ -35,11 +35,11 @@ BoneMatrices::BoneMatrices() { bone_matrices_crate_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; VmaAllocationCreateInfo allocation_create_info{}; allocation_create_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE; - const auto max_frames_in_flight = Graphics::GetMaxFramesInFlight(); + const auto max_frames_in_flight = Platform::GetMaxFramesInFlight(); for (int i = 0; i < max_frames_in_flight; i++) { bone_matrices_buffer_.emplace_back(std::make_unique(bone_matrices_crate_info, allocation_create_info)); descriptor_set_.emplace_back( - std::make_shared(Graphics::GetDescriptorSetLayout("BONE_MATRICES_LAYOUT"))); + std::make_shared(Platform::GetDescriptorSetLayout("BONE_MATRICES_LAYOUT"))); } } @@ -49,7 +49,7 @@ size_t& BoneMatrices::GetVersion() { void BoneMatrices::UploadData() { version_++; - const auto current_frame_index = Graphics::GetCurrentFrameIndex(); + const auto current_frame_index = Platform::GetCurrentFrameIndex(); if (!value.empty()) bone_matrices_buffer_[current_frame_index]->UploadVector(value); VkDescriptorBufferInfo buffer_info; diff --git a/EvoEngine_SDK/src/Texture2D.cpp b/EvoEngine_SDK/src/Texture2D.cpp index 5fe39e7..10ab736 100644 --- a/EvoEngine_SDK/src/Texture2D.cpp +++ b/EvoEngine_SDK/src/Texture2D.cpp @@ -4,7 +4,7 @@ #include "ClassRegistry.hpp" #include "Console.hpp" #include "EditorLayer.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "Jobs.hpp" #include "TextureStorage.hpp" diff --git a/EvoEngine_SDK/src/TextureStorage.cpp b/EvoEngine_SDK/src/TextureStorage.cpp index 9766b1f..68edac2 100644 --- a/EvoEngine_SDK/src/TextureStorage.cpp +++ b/EvoEngine_SDK/src/TextureStorage.cpp @@ -15,7 +15,7 @@ void CubemapStorage::Initialize(uint32_t resolution, uint32_t mip_levels) { image_info.extent.depth = 1; image_info.mipLevels = mip_levels; image_info.arrayLayers = 6; - image_info.format = Graphics::Constants::texture_2d; + image_info.format = Platform::Constants::texture_2d; image_info.tiling = VK_IMAGE_TILING_OPTIMAL; image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; image_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | @@ -29,7 +29,7 @@ void CubemapStorage::Initialize(uint32_t resolution, uint32_t mip_levels) { view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; view_info.image = image->GetVkImage(); view_info.viewType = VK_IMAGE_VIEW_TYPE_CUBE; - view_info.format = Graphics::Constants::texture_2d; + view_info.format = Platform::Constants::texture_2d; view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; view_info.subresourceRange.baseMipLevel = 0; view_info.subresourceRange.levelCount = mip_levels; @@ -46,7 +46,7 @@ void CubemapStorage::Initialize(uint32_t resolution, uint32_t mip_levels) { sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; sampler_info.anisotropyEnable = VK_TRUE; - sampler_info.maxAnisotropy = Graphics::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; + sampler_info.maxAnisotropy = Platform::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; sampler_info.unnormalizedCoordinates = VK_FALSE; sampler_info.compareEnable = VK_FALSE; @@ -58,8 +58,8 @@ void CubemapStorage::Initialize(uint32_t resolution, uint32_t mip_levels) { } sampler = std::make_shared(sampler_info); - Graphics::ImmediateSubmit([&](const VkCommandBuffer command_buffer) { - image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { + image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); }); for (int i = 0; i < 6; i++) { @@ -67,7 +67,7 @@ void CubemapStorage::Initialize(uint32_t resolution, uint32_t mip_levels) { face_view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; face_view_info.image = image->GetVkImage(); face_view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; - face_view_info.format = Graphics::Constants::texture_2d; + face_view_info.format = Platform::Constants::texture_2d; face_view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; face_view_info.subresourceRange.baseMipLevel = 0; face_view_info.subresourceRange.levelCount = 1; @@ -150,7 +150,7 @@ void Texture2DStorage::Initialize(const glm::uvec2& resolution) { image_info.extent.depth = 1; image_info.mipLevels = mip_levels; image_info.arrayLayers = 1; - image_info.format = Graphics::Constants::texture_2d; + image_info.format = Platform::Constants::texture_2d; image_info.tiling = VK_IMAGE_TILING_OPTIMAL; image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; image_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | @@ -163,7 +163,7 @@ void Texture2DStorage::Initialize(const glm::uvec2& resolution) { view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; view_info.image = image->GetVkImage(); view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; - view_info.format = Graphics::Constants::texture_2d; + view_info.format = Platform::Constants::texture_2d; view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; view_info.subresourceRange.baseMipLevel = 0; view_info.subresourceRange.levelCount = image_info.mipLevels; @@ -180,7 +180,7 @@ void Texture2DStorage::Initialize(const glm::uvec2& resolution) { sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; sampler_info.anisotropyEnable = VK_TRUE; - sampler_info.maxAnisotropy = Graphics::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; + sampler_info.maxAnisotropy = Platform::GetVkPhysicalDeviceProperties().limits.maxSamplerAnisotropy; sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; sampler_info.unnormalizedCoordinates = VK_FALSE; sampler_info.compareEnable = VK_FALSE; @@ -212,15 +212,15 @@ void Texture2DStorage::UploadData(const std::vector& data, const glm: const Buffer staging_buffer{staging_buffer_create_info, staging_buffer_vma_allocation_create_info}; void* device_data = nullptr; - vmaMapMemory(Graphics::GetVmaAllocator(), staging_buffer.GetVmaAllocation(), &device_data); + vmaMapMemory(Platform::GetVmaAllocator(), staging_buffer.GetVmaAllocation(), &device_data); memcpy(device_data, data.data(), image_size); - vmaUnmapMemory(Graphics::GetVmaAllocator(), staging_buffer.GetVmaAllocation()); + vmaUnmapMemory(Platform::GetVmaAllocator(), staging_buffer.GetVmaAllocation()); - Graphics::ImmediateSubmit([&](const VkCommandBuffer command_buffer) { - image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); - image->CopyFromBuffer(command_buffer, staging_buffer.GetVkBuffer()); - image->GenerateMipmaps(command_buffer); - image->TransitImageLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + Platform::ImmediateSubmit([&](const VkCommandBuffer vk_command_buffer) { + image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + image->CopyFromBuffer(vk_command_buffer, staging_buffer.GetVkBuffer()); + image->GenerateMipmaps(vk_command_buffer); + image->TransitImageLayout(vk_command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); }); EditorLayer::UpdateTextureId(im_texture_id, sampler->GetVkSampler(), image_view->GetVkImageView(), @@ -260,7 +260,7 @@ void Texture2DStorage::UploadDataImmediately() { void TextureStorage::DeviceSync() { auto& storage = GetInstance(); - const auto current_frame_index = Graphics::GetCurrentFrameIndex(); + const auto current_frame_index = Platform::GetCurrentFrameIndex(); const auto render_layer = Application::GetLayer(); diff --git a/EvoEngine_SDK/src/WindowLayer.cpp b/EvoEngine_SDK/src/WindowLayer.cpp index 21d361d..ca42e0b 100644 --- a/EvoEngine_SDK/src/WindowLayer.cpp +++ b/EvoEngine_SDK/src/WindowLayer.cpp @@ -1,6 +1,6 @@ #include "WindowLayer.hpp" #include "Application.hpp" -#include "Graphics.hpp" +#include "Platform.hpp" #include "ProjectManager.hpp" using namespace evo_engine; @@ -9,7 +9,7 @@ void WindowLayer::FramebufferSizeCallback(GLFWwindow* window, int width, int hei if (const auto window_layer = Application::GetLayer(); window_layer->window_ == window) { window_layer->window_size_ = {width, height}; } - if (const auto& graphics_layer = Application::GetLayer()) { + if (const auto& graphics_layer = Application::GetLayer()) { graphics_layer->NotifyRecreateSwapChain(); } } diff --git a/Extern/3rdParty/CMakeLists.txt b/Extern/3rdParty/CMakeLists.txt index a55554d..c25675f 100644 --- a/Extern/3rdParty/CMakeLists.txt +++ b/Extern/3rdParty/CMakeLists.txt @@ -85,7 +85,6 @@ foreach(target ${all_targets}) endif() endforeach() - set(3RDPARTY_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${3RDPARTY_INCLUDES} diff --git a/Extern/3rdParty/zlib/CMakeLists.txt b/Extern/3rdParty/zlib/CMakeLists.txt index 7224298..4138be3 100644 --- a/Extern/3rdParty/zlib/CMakeLists.txt +++ b/Extern/3rdParty/zlib/CMakeLists.txt @@ -30,9 +30,13 @@ set(3RDPARTY_INCLUDES ${3RDPARTY_INCLUDES} ${ZLIB_INCLUDE_DIR} PARENT_SCOPE) set(3RDPARTY_DLLS ${3RDPARTY_DLLS} ${CMAKE_CURRENT_BINARY_DIR}/zlib/zlib1.dll ${CMAKE_CURRENT_BINARY_DIR}/zlib/$/zlib1.dll + ${CMAKE_CURRENT_BINARY_DIR}/zlib/zlibd1.dll + ${CMAKE_CURRENT_BINARY_DIR}/zlib/$/zlibd1.dll PARENT_SCOPE) set(3RDPARTY_PDBS ${3RDPARTY_PDBS} ${CMAKE_CURRENT_BINARY_DIR}/zlib/zlib.pdb ${CMAKE_CURRENT_BINARY_DIR}/zlib/$/zlib.pdb + ${CMAKE_CURRENT_BINARY_DIR}/zlib/zlibd.pdb + ${CMAKE_CURRENT_BINARY_DIR}/zlib/$/zlibd.pdb PARENT_SCOPE) \ No newline at end of file diff --git a/Resources/EcoSysLabProject/SoilLayers/Basic.nsld.evefilemeta b/Resources/EcoSysLabProject/SoilLayers/Basic.nsld.evefilemeta index 4769060..197384d 100644 --- a/Resources/EcoSysLabProject/SoilLayers/Basic.nsld.evefilemeta +++ b/Resources/EcoSysLabProject/SoilLayers/Basic.nsld.evefilemeta @@ -1,4 +1,4 @@ asset_extension_: .nsld asset_file_name_: Basic asset_type_name_: Binary -asset_handle_: 13276103344296017010 \ No newline at end of file +asset_handle_: 927991688091439202 \ No newline at end of file