From 3b3ff20a37af9ffdfd245a26dc6dc94aff89f47d Mon Sep 17 00:00:00 2001 From: jmorton06 Date: Wed, 23 Oct 2024 08:02:38 +0100 Subject: [PATCH 1/3] refactor descriptor sets + disable opengl --- Editor/premake5.lua | 6 - ExampleProject/AssetRegistry.lmar | 308 +---------- .../imgui/backends/imgui_impl_vulkan.cpp | 8 +- .../imgui/backends/imgui_impl_vulkan.h | 2 +- .../Lumos/Core/DataStructures/TDArray.h | 30 ++ Lumos/Source/Lumos/Core/JobSystem.cpp | 25 +- .../Animation/AnimationController.cpp | 2 +- Lumos/Source/Lumos/Graphics/Material.cpp | 22 +- .../Source/Lumos/Graphics/RHI/DescriptorSet.h | 13 + .../Lumos/Graphics/RHI/RHIDefinitions.h | 5 +- .../Lumos/Graphics/Renderers/GridRenderer.cpp | 9 +- .../Graphics/Renderers/SceneRenderer.cpp | 435 ++++++++-------- .../Source/Lumos/Platform/GLFW/GLFWWindow.cpp | 2 + .../Lumos/Platform/Vulkan/VKContext.cpp | 2 +- .../Lumos/Platform/Vulkan/VKDescriptorSet.cpp | 483 ++++++++++++------ .../Lumos/Platform/Vulkan/VKDescriptorSet.h | 52 +- .../Lumos/Platform/Vulkan/VKIMGUIRenderer.cpp | 10 +- .../Source/Lumos/Platform/Vulkan/VKShader.cpp | 18 +- Lumos/Source/Lumos/Scene/Scene.cpp | 8 +- .../SerialisationImplementation.h | 21 +- .../Source/Lumos/Scripting/Lua/LuaManager.cpp | 130 +++++ Lumos/Source/Lumos/Scripting/Lua/LuaManager.h | 1 + Lumos/premake5.lua | 13 +- Runtime/Runtime.cpp | 2 + Runtime/premake5.lua | 6 - 25 files changed, 873 insertions(+), 740 deletions(-) diff --git a/Editor/premake5.lua b/Editor/premake5.lua index 33625180..fba8a43e 100755 --- a/Editor/premake5.lua +++ b/Editor/premake5.lua @@ -20,7 +20,6 @@ project "LumosEditor" { "%{IncludeDir.entt}", "%{IncludeDir.GLFW}", - "%{IncludeDir.Glad}", "%{IncludeDir.lua}", "%{IncludeDir.stb}", "%{IncludeDir.ImGui}", @@ -73,7 +72,6 @@ project "LumosEditor" defines { "LUMOS_PLATFORM_WINDOWS", - "LUMOS_RENDER_API_OPENGL", "LUMOS_RENDER_API_VULKAN", "VK_USE_PLATFORM_WIN32_KHR", "WIN32_LEAN_AND_MEAN", @@ -91,7 +89,6 @@ project "LumosEditor" links { "glfw", - "OpenGL32", "OpenAL32" } @@ -129,7 +126,6 @@ project "LumosEditor" { "LUMOS_PLATFORM_MACOS", "LUMOS_PLATFORM_UNIX", - "LUMOS_RENDER_API_OPENGL", "LUMOS_RENDER_API_VULKAN", "VK_EXT_metal_surface", "LUMOS_IMGUI", @@ -138,7 +134,6 @@ project "LumosEditor" linkoptions { - "-framework OpenGL", "-framework Cocoa", "-framework IOKit", "-framework CoreVideo", @@ -275,7 +270,6 @@ project "LumosEditor" { "LUMOS_PLATFORM_LINUX", "LUMOS_PLATFORM_UNIX", - "LUMOS_RENDER_API_OPENGL", "LUMOS_RENDER_API_VULKAN", "VK_USE_PLATFORM_XCB_KHR", "LUMOS_IMGUI", diff --git a/ExampleProject/AssetRegistry.lmar b/ExampleProject/AssetRegistry.lmar index b9ec15a8..59913732 100644 --- a/ExampleProject/AssetRegistry.lmar +++ b/ExampleProject/AssetRegistry.lmar @@ -1,13 +1,10 @@ { "value0": { "Version": 2, - "Count": 265, + "Count": 163, "Name": "//Assets/Meshes/greenhouse/skPlantsFlowerYellowTex0.png", "UUID": 22592664930542702, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/16299174074766089871.jpg", - "UUID": 98043891877507985, - "AssetType": 1, "Name": "DepthPrePassAnim", "UUID": 220796699938349989, "AssetType": 6, @@ -26,9 +23,6 @@ "Name": "//Assets/Textures/texture.jpg", "UUID": 538415633353194237, "AssetType": 1, - "Name": "//Assets/Cache/Meshes/Spyro/ArtisansHub.obj_thumbnail.png", - "UUID": 574509055418579333, - "AssetType": 1, "Name": "Batch2D", "UUID": 813680964025412095, "AssetType": 6, @@ -38,39 +32,18 @@ "Name": "EnvironmentIrradiance", "UUID": 960524816459447479, "AssetType": 6, - "Name": "//Assets/Meshes/Sponza/8006627369776289000.png", - "UUID": 1014597301889436762, - "AssetType": 1, - "Name": "//Assets/Scenes/Cache/Sponza.png", - "UUID": 1092808811581182007, - "AssetType": 1, "Name": "SSAO", "UUID": 1095354547157039442, "AssetType": 6, - "Name": "//Assets/Cache/Meshes/capsule.glb_thumbnail.png", - "UUID": 1117909052832930046, - "AssetType": 1, "Name": "//Assets/Textures/particle_dust.png", "UUID": 1123372390369367885, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/2411100444841994089.jpg", - "UUID": 1130475611784785173, - "AssetType": 1, "Name": "//Assets/Textures/icon32.png", "UUID": 1169913861966067682, "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/Sky_BK.png", "UUID": 1174728750949576407, "AssetType": 1, - "Name": "//Assets/Cache/Meshes/gym.obj_thumbnail.png", - "UUID": 1229536781878886413, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/715093869573992647.jpg", - "UUID": 1290130847179135662, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/332936164838540657.jpg", - "UUID": 1368807874242567164, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/skForestFern4Tex0.png", "UUID": 1374507108360195902, "AssetType": 1, @@ -89,12 +62,6 @@ "Name": "EnvironmentMipFilter", "UUID": 1675502722393171918, "AssetType": 6, - "Name": "//Assets/Cache/Meshes/Sponza/Sponza.gltf_thumbnail.png", - "UUID": 1680779725720779975, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/8114461559286000061.jpg", - "UUID": 1773864723472139353, - "AssetType": 1, "Name": "Batch2DLine", "UUID": 2094088944344111971, "AssetType": 6, @@ -110,57 +77,33 @@ "Name": "BRDFLUT", "UUID": 2216550627408006547, "AssetType": 6, - "Name": "//Assets/Cache/Meshes/material_sphere/material_sphere.fbx_thumbnail.png", - "UUID": 2486009519825565172, - "AssetType": 1, "Name": "Debanding", "UUID": 2495998898540605538, "AssetType": 6, "Name": "//Assets/Meshes/DamagedHelmet/glTF/Default_metalRoughness.jpg", "UUID": 2500712325220424302, "AssetType": 1, - "Name": "//Assets/Scenes/Cache/MeshCollisionTest.png", - "UUID": 2546253203902220982, - "AssetType": 1, "Name": "//Assets/Textures/checkerboard.tga", "UUID": 2626531592178374404, "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/circlewindow.png", "UUID": 2650902651226494616, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/5823059166183034438.jpg", - "UUID": 2885037267360439351, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/8481240838833932244.jpg", - "UUID": 2914807766181672733, - "AssetType": 1, "Name": "//Assets/Meshes/material_sphere/material_sphere.fbx", "UUID": 2948647025781413142, "AssetType": 9, "Name": "//Assets/Textures/PreintegratedFG.tga", "UUID": 3011559381961549495, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/6772804448157695701.jpg", - "UUID": 3015511777157830972, - "AssetType": 1, "Name": "ForwardPBR", "UUID": 3031085133988255604, "AssetType": 6, - "Name": "//Assets/Meshes/Sponza/11474523244911310074.jpg", - "UUID": 3040184915685281629, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/6593109234861095314.jpg", - "UUID": 3056158552645787691, - "AssetType": 1, "Name": "ForwardPBRAnim", "UUID": 3175668397740860526, "AssetType": 6, "Name": "//Assets/Meshes/greenhouse/exteriorArch1A.png", "UUID": 3447614406999776187, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/9916269861720640319.jpg", - "UUID": 3459788155502725901, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/greenstoneFloor_Diff.png", "UUID": 3566627028576158015, "AssetType": 1, @@ -176,27 +119,12 @@ "Name": "//Assets/Meshes/Scene/scene.gltf", "UUID": 3853544921239423074, "AssetType": 9, - "Name": "//Assets/Meshes/Sponza/white.png", - "UUID": 3910422899472164735, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/6047387724914829168.jpg", - "UUID": 4039401209977963489, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/13196865903111448057.jpg", - "UUID": 4043297105255920395, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/15295713303328085182.jpg", - "UUID": 4046501193320037423, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/specialbeam_GH4.png", "UUID": 4347402336064998355, "AssetType": 1, "Name": "//Assets/Meshes/stormtrooper/stormtrooper.gltf", "UUID": 4378391369236188799, "AssetType": 9, - "Name": "//Assets/Meshes/Sponza/7441062115984513793.jpg", - "UUID": 4382739155512825190, - "AssetType": 1, "Name": "DepthPrePass", "UUID": 4415649574143950547, "AssetType": 6, @@ -206,42 +134,21 @@ "Name": "//Assets/Meshes/basket.glb", "UUID": 4500161985950185631, "AssetType": 0, - "Name": "//Assets/Meshes/Sponza/2299742237651021498.jpg", - "UUID": 4512582615374619531, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/15722799267630235092.jpg", - "UUID": 4609169353622061456, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/Quid_Sky_DN.png", "UUID": 4757980925201342159, "AssetType": 1, "Name": "//Assets/Meshes/gym.obj", "UUID": 4951225963790835797, "AssetType": 0, - "Name": "//Assets/Meshes/Sponza/6667038893015345571.jpg", - "UUID": 4964605092713413959, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/skShowerHeadTex0.png", "UUID": 4974850072488045174, "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/greenstoneFloor.png", "UUID": 5200015067037167424, "AssetType": 1, - "Name": "//Assets/Cache/Meshes/Scene/scene.gltf_thumbnail.png", - "UUID": 5357948409829461133, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/8503262930880235456.jpg", - "UUID": 5417088191633740685, - "AssetType": 1, "Name": "//Assets/Meshes/AnimatedMorphCube.glb", "UUID": 5543534150634670453, "AssetType": 9, - "Name": "//Assets/Cache/Meshes/DamagedHelmet/glTF/DamagedHelmet.gltf_thumbnail.png", - "UUID": 5554588689799643674, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/16275776544635328252.png", - "UUID": 5698093024760268905, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/skGnomeHomeTex0.png", "UUID": 5749842087445720401, "AssetType": 1, @@ -251,24 +158,12 @@ "Name": "//Assets/Meshes/greenhouse/Dfurnace.png", "UUID": 5953217185310301223, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/12501374198249454378.jpg", - "UUID": 6066560373137509260, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/10388182081421875623.jpg", - "UUID": 6155090306630358422, - "AssetType": 1, - "Name": "//Assets/Scenes/Cache/Platformer.png", - "UUID": 6194444174986539845, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/DefaultTexture.png", "UUID": 6225984050555498579, "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/HogFoundation_GH1.png", "UUID": 6280961174024816424, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/4871783166746854860.jpg", - "UUID": 6465736750029772252, - "AssetType": 1, "Name": "//Assets/Meshes/Spyro/ArtisansHub.obj", "UUID": 6538867603038803317, "AssetType": 9, @@ -278,39 +173,24 @@ "Name": "//Assets/Meshes/greenhouse/shingles.png", "UUID": 6609275634191990635, "AssetType": 1, - "Name": "//Assets/Scenes/Cache/ElasticTest.png", - "UUID": 6770401320685515586, - "AssetType": 1, "Name": "//Assets/Meshes/DamagedHelmet/glTF/Default_albedo.jpg", "UUID": 6793517729857818429, "AssetType": 1, - "Name": "//Assets/Cache/Materials/Material0##0.lmat_thumbnail.png", - "UUID": 6966254140477458242, - "AssetType": 1, "Name": "//Assets/Meshes/lowpoly_bonfire/scene.gltf", "UUID": 7027018599794543603, "AssetType": 9, - "Name": "//Assets/Meshes/Sponza/14650633544276105767.jpg", - "UUID": 7191417769818910883, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/skToolsWateringCanTex0.png", "UUID": 7201228779077066790, "AssetType": 1, "Name": "ChromaticAberation", "UUID": 7375714513771862660, "AssetType": 6, - "Name": "//Assets/Meshes/Sponza/3371964815757888145.jpg", - "UUID": 7455977591346813500, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/leafdesign_GH4.png", "UUID": 7612302876869615578, "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/ExWallBorder_GH4.png", "UUID": 7755834373603763581, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/5061699253647017043.png", - "UUID": 7781615148054800833, - "AssetType": 1, "Name": "//Assets/Textures/particle_dust_copy.png", "UUID": 7834188427659250029, "AssetType": 1, @@ -320,45 +200,21 @@ "Name": "//Assets/Meshes/greenhouse/HHut_Inside_Floor_GH4.png", "UUID": 7921666898532392208, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/8747919177698443163.jpg", - "UUID": 7983540564144083672, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/1219024358953944284.jpg", - "UUID": 8020769921885392567, - "AssetType": 1, - "Name": "//Assets/Cache/Meshes/sphere.obj_thumbnail.png", - "UUID": 8071842674810667482, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/7815564343179553343.jpg", - "UUID": 8132119746132615003, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/devilface_B.png", "UUID": 8295672923578575637, "AssetType": 1, "Name": "Shadow", "UUID": 8301062219737337799, "AssetType": 6, - "Name": "//Assets/Scenes/Cache/CollisionPyramidTest.png", - "UUID": 8377029983424632478, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/11490520546946913238.jpg", - "UUID": 8417509157257117499, - "AssetType": 1, "Name": "//Assets/Meshes/Fox.glb", "UUID": 8425291053532852983, "AssetType": 9, "Name": "//Assets/Meshes/greenhouse/HogBrickTrim_GH4.png", "UUID": 8466017017906191526, "AssetType": 1, - "Name": "//Assets/Cache/Meshes/material_sphere/material_sphere.glb_thumbnail.png", - "UUID": 8564452194664459013, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/WoodBeam_GH4.png", "UUID": 8684206229813379877, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/13982482287905699490.jpg", - "UUID": 9068205711881955648, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/GreenhouseWall2.png", "UUID": 9116119470097498382, "AssetType": 1, @@ -374,9 +230,6 @@ "Name": "Bloom", "UUID": 9292640677943495227, "AssetType": 6, - "Name": "//Assets/Meshes/Sponza/8750083169368950601.jpg", - "UUID": 9373390944974422671, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/skFootStoolTex0.png", "UUID": 9430157078387944291, "AssetType": 1, @@ -386,60 +239,36 @@ "Name": "DepthPrePassAlpha", "UUID": 9648507851302580497, "AssetType": 6, - "Name": "//Assets/Cache/Meshes/cube.obj_thumbnail.png", - "UUID": 9681443051825963827, - "AssetType": 1, "Name": "Sharpen", "UUID": 9688744856235066537, "AssetType": 6, "Name": "DepthPrePassAlphaAnim", "UUID": 9747255277593312948, "AssetType": 6, - "Name": "//Assets/Cache/Meshes/basketball/scene.gltf_thumbnail.png", - "UUID": 9908067908599896959, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/clearwindows_GH4.png", "UUID": 9932638187471414580, "AssetType": 1, - "Name": "//Assets/Cache/Meshes/Materials/Material0##0.lmat_thumbnail.png", - "UUID": 9955801483686293186, - "AssetType": 1, "Name": "Particle", "UUID": 10078180836416861066, "AssetType": 6, "Name": "//Assets/Meshes/greenhouse/WoodDungeonDoor.png", "UUID": 10093175237610798880, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/2969916736137545357.jpg", - "UUID": 10325223064981364649, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/skPlantsWindowBoxTex0.png", "UUID": 10331530903584006055, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/2185409758123873465.jpg", - "UUID": 10336628128976782605, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/HogBrick2_GH4.png", "UUID": 10362315839565976692, "AssetType": 1, "Name": "//Assets/Textures/icon.png", "UUID": 10374144327092108136, "AssetType": 1, - "Name": "//Assets/Cache/Meshes/material_sphere/material_sphere.obj_thumbnail.png", - "UUID": 10387484473150550112, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/7645212358685992005.jpg", - "UUID": 10517838985572401790, - "AssetType": 1, "Name": "//Assets/Meshes/Spyro/Low.png", "UUID": 10543428672904306405, "AssetType": 1, "Name": "DepthOfField", "UUID": 10557890345575391864, "AssetType": 6, - "Name": "//Assets/Meshes/Sponza/11968150294050148237.jpg", - "UUID": 10581766720067404949, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/PalegreyFl_GH4.png", "UUID": 10724666440079376789, "AssetType": 1, @@ -458,9 +287,6 @@ "Name": "//Assets/Meshes/greenhouse/LgWindow.png", "UUID": 11077811304147940396, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/14118779221266351425.jpg", - "UUID": 11125725866154499932, - "AssetType": 1, "Name": "//Assets/Textures/round_outline.png", "UUID": 11126978127519170907, "AssetType": 1, @@ -479,30 +305,15 @@ "Name": "//Assets/Meshes/greenhouse/woodmover_sk.png", "UUID": 11546689571810384605, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/759203620573749278.jpg", - "UUID": 11632626362579178205, - "AssetType": 1, "Name": "//Assets/Meshes/DamagedHelmet/glTF/Default_normal.jpg", "UUID": 11696113533973076960, "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/HogWindow1_GH1.png", "UUID": 11805970974342685887, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/466164707995436622.jpg", - "UUID": 11891175326145363048, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/2051777328469649772.jpg", - "UUID": 11934113162438817988, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/skDiffindoRope64Tex0.png", "UUID": 11981827742016789208, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/8773302468495022225.jpg", - "UUID": 12263650696633721287, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/16885566240357350108.jpg", - "UUID": 12288186569820185047, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/Tallpillar_GH4.png", "UUID": 12291039238526031868, "AssetType": 1, @@ -527,9 +338,6 @@ "Name": "//Assets/Meshes/greenhouse/MossyGreenFlagstone_GH4.png", "UUID": 12671691340944658913, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/4975155472559461469.jpg", - "UUID": 12716124099546830009, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/WallTorch_Gh4.png", "UUID": 12752526827353792098, "AssetType": 1, @@ -557,90 +365,39 @@ "Name": "//Assets/Meshes/greenhouse/HogBrickMold_GH4.png", "UUID": 13195144987342237169, "AssetType": 1, - "Name": "/Users/jmorton/Dev/Lumos/ExampleProject/Assets/Cache/Meshes/cube.obj_thumbnail.png", - "UUID": 13196367447802436546, - "AssetType": 1, - "Name": "//Assets/Cache/Materials/Material-Green.lmat_thumbnail.png", - "UUID": 13518974410328160047, - "AssetType": 1, "Name": "//Assets/Meshes/DamagedHelmet/glTF/DamagedHelmet.gltf", "UUID": 13579337366301463653, "AssetType": 9, - "Name": "//Assets/Meshes/Sponza/6151467286084645207.jpg", - "UUID": 13586315271515006503, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/7268504077753552595.jpg", - "UUID": 13652647086728268907, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/9288698199695299068.jpg", - "UUID": 13745938771577501408, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/HogFoundation_GH4.png", "UUID": 13796017636552425731, "AssetType": 1, "Name": "//Assets/Textures/fire.png", "UUID": 13831315025881660061, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/11872827283454512094.jpg", - "UUID": 13831699179923534725, - "AssetType": 1, "Name": "//Assets/Meshes/lowpoly_bonfire/textures/lambert1.002_metallicRoughness.png", "UUID": 13837274997362013530, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/2374361008830720677.jpg", - "UUID": 13854994827704966763, - "AssetType": 1, "Name": "SSAOBlur", "UUID": 13910922921860105132, "AssetType": 6, - "Name": "//Assets/Cache/Meshes/lowpoly_bonfire/scene.gltf_thumbnail.png", - "UUID": 13956919628896410871, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/skDiffindoWeb2Tex0.png", "UUID": 14000566495614954288, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/8051790464816141987.jpg", - "UUID": 14057995666735149327, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/10381718147657362067.jpg", - "UUID": 14073583180272832789, - "AssetType": 1, "Name": "FinalPass", "UUID": 14113443814160806123, "AssetType": 6, "Name": "//Assets/Meshes/greenhouse/ornamentwindow_GH4.png", "UUID": 14224867004745657940, "AssetType": 1, - "Name": "//Assets/Scenes/Cache/CapsuleTest.png", - "UUID": 14269581500391755498, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/3628158980083700836.jpg", - "UUID": 14334753069666248614, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/17556969131407844942.jpg", - "UUID": 14341758253079944201, - "AssetType": 1, - "Name": "//Assets/Scenes/Cache/2D.png", - "UUID": 14433233690600321844, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/IronArchTop_GH1.png", "UUID": 14582018251189374788, "AssetType": 1, "Name": "Batch2DPoint", "UUID": 14671482827884459882, "AssetType": 6, - "Name": "/Users/jmorton/Dev/Lumos/ExampleProject/Assets/Cache/Meshes/AnimatedMorphCube.glb_thumbnail.png", - "UUID": 14692638057968195791, - "AssetType": 1, - "Name": "//Assets/Scenes/Cache/2DTest.png", - "UUID": 14706732569522392733, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/CrankWheel_GH4.png", "UUID": 14754618334615449993, "AssetType": 1, - "Name": "//Assets/Cache/Meshes/AnimatedMorphCube.glb_thumbnail.png", - "UUID": 14851380438564335907, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/Frame_B_GH4.png", "UUID": 14909191611701836044, "AssetType": 1, @@ -650,21 +407,6 @@ "Name": "//Assets/Meshes/greenhouse/IvyTall2_GH4.png", "UUID": 14927263090769801705, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/755318871556304029.jpg", - "UUID": 14951603529344960874, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/14267839433702832875.jpg", - "UUID": 14968883023977719254, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/4910669866631290573.jpg", - "UUID": 15294549561331977269, - "AssetType": 1, - "Name": "//Assets/Cache/Meshes/greenhouse/Adv4Greenhouse.obj_thumbnail.png", - "UUID": 15316715895923119879, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/14170708867020035030.jpg", - "UUID": 15334241507007352352, - "AssetType": 1, "Name": "ToneMapping", "UUID": 15576366496581061081, "AssetType": 6, @@ -686,54 +428,24 @@ "Name": "//Assets/Meshes/greenhouse/StrGrate_GH4.png", "UUID": 16003769903633202712, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/4477655471536070370.jpg", - "UUID": 16012405407936891595, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/LowerTwistArch_GH4.png", "UUID": 16044667088453235702, "AssetType": 1, "Name": "ShadowAnim", "UUID": 16067132574532594367, "AssetType": 6, - "Name": "//Assets/Meshes/Sponza/17876391417123941155.jpg", - "UUID": 16097551380465138131, - "AssetType": 1, - "Name": "//Assets/Cache/Meshes/Fox.glb_thumbnail.png", - "UUID": 16179565767608334086, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/Sky_RT.png", "UUID": 16186919575036941129, "AssetType": 1, "Name": "//Assets/Meshes/basketball/scene.gltf", "UUID": 16301651375097263174, "AssetType": 0, - "Name": "/Users/jmorton/Dev/Lumos/ExampleProject/Assets/Cache/Meshes/pyramid.obj_thumbnail.png", - "UUID": 16463431812382909674, - "AssetType": 1, - "Name": "//Assets/Cache/Meshes/pyramid.obj_thumbnail.png", - "UUID": 16554280716107352421, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/4601176305987539675.jpg", - "UUID": 16670775855148515879, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/3827035219084910048.jpg", - "UUID": 16767180019371278740, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/13824894030729245199.jpg", - "UUID": 16785658059555628681, - "AssetType": 1, "Name": "//Assets/Textures/backgroundColorGrass.png", "UUID": 16838368057738779843, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/2775690330959970771.jpg", - "UUID": 16858304654623083456, - "AssetType": 1, "Name": "//Assets/Meshes/lowpoly_bonfire/textures/lambert1.002_normal.png", "UUID": 16935851122039710704, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/8783994986360286082.jpg", - "UUID": 16979890630243606762, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/skPlantsCactus1Tex0.png", "UUID": 17032178551709164156, "AssetType": 1, @@ -749,21 +461,12 @@ "Name": "Grid", "UUID": 17174639512606516617, "AssetType": 6, - "Name": "//Assets/Meshes/Sponza/4675343432951571524.jpg", - "UUID": 17175991898379740832, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/skMapleTreeFullTex1.png", "UUID": 17187225970241321334, "AssetType": 1, - "Name": "//Assets/Cache/Materials/MaterialBlue##0.lmat_thumbnail.png", - "UUID": 17191006140985245560, - "AssetType": 1, "Name": "//Assets/Meshes/material_sphere/material_sphere.obj", "UUID": 17455043737545044798, "AssetType": 9, - "Name": "//Assets/Scenes/Cache/Physics.png", - "UUID": 17456551984026861291, - "AssetType": 1, "Name": "//Assets/Meshes/Sponza/Sponza.gltf", "UUID": 17477631631750750130, "AssetType": 9, @@ -779,21 +482,12 @@ "Name": "//Assets/Meshes/greenhouse/Sky_DN.png", "UUID": 17783438993853067061, "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/5792855332885324923.jpg", - "UUID": 17904024027961317902, - "AssetType": 1, "Name": "//Assets/Meshes/greenhouse/skPlantsHangingPlant1Tex0.png", "UUID": 18048577803622114842, "AssetType": 1, "Name": "ShadowAlpha", "UUID": 18088774006192505129, "AssetType": 6, - "Name": "//Assets/Meshes/Sponza/3455394979645218238.jpg", - "UUID": 18224986816777564923, - "AssetType": 1, - "Name": "//Assets/Meshes/Sponza/7056944414013900257.jpg", - "UUID": 18261938858643575233, - "AssetType": 1, "Name": "//Assets/Meshes/capsule.glb", "UUID": 18324794523591720199, "AssetType": 9 diff --git a/Lumos/External/imgui/backends/imgui_impl_vulkan.cpp b/Lumos/External/imgui/backends/imgui_impl_vulkan.cpp index 83a5dbe6..15cae614 100644 --- a/Lumos/External/imgui/backends/imgui_impl_vulkan.cpp +++ b/Lumos/External/imgui/backends/imgui_impl_vulkan.cpp @@ -481,7 +481,7 @@ static void ImGui_ImplVulkan_SetupRenderState(ImDrawData* draw_data, VkPipeline } // Render function -void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline, uint32_t frameIndex) +void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline, uint32_t frameIndex, uint32_t bufferIndex) { // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x); @@ -507,7 +507,7 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm } IM_ASSERT(wrb->Count == v->ImageCount); //wrb->Index = (wrb->Index + 1) % wrb->Count; - wrb->Index = frameIndex; + wrb->Index = bufferIndex; ImGui_ImplVulkanH_FrameRenderBuffers* rb = &wrb->FrameRenderBuffers[wrb->Index]; if (draw_data->TotalVtxCount > 0) @@ -579,10 +579,10 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm static VkDescriptorSet lastSet = VK_NULL_HANDLE; VkDescriptorSet desc_set[1]; - if (pcmd->TextureId && (*g_DescriptorSets)[frameIndex].find(pcmd->TextureId) != (*g_DescriptorSets)[frameIndex].end()) + if (pcmd->TextureId && (*g_DescriptorSets)[bufferIndex].find(pcmd->TextureId) != (*g_DescriptorSets)[bufferIndex].end()) { uint32_t index = 0; - auto desc = (*g_DescriptorSets)[frameIndex][pcmd->TextureId]; + auto desc = (*g_DescriptorSets)[bufferIndex][pcmd->TextureId]; //if (lastSet != desc) { desc_set[0] = desc; diff --git a/Lumos/External/imgui/backends/imgui_impl_vulkan.h b/Lumos/External/imgui/backends/imgui_impl_vulkan.h index 85e5b385..d44ab0e1 100644 --- a/Lumos/External/imgui/backends/imgui_impl_vulkan.h +++ b/Lumos/External/imgui/backends/imgui_impl_vulkan.h @@ -75,7 +75,7 @@ IMGUI_IMPL_API void ImGui_ImplVulkan_CreateDescriptorSets(ImDrawData* draw_d IMGUI_IMPL_API bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass render_pass); IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown(); IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame(); -IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline = VK_NULL_HANDLE, uint32_t frameIndex = 0); +IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline = VK_NULL_HANDLE, uint32_t frameIndex = 0, uint32_t bufferIndex = 0); IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer); IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontUploadObjects(); IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated) diff --git a/Lumos/Source/Lumos/Core/DataStructures/TDArray.h b/Lumos/Source/Lumos/Core/DataStructures/TDArray.h index aa62410f..a49a7cee 100644 --- a/Lumos/Source/Lumos/Core/DataStructures/TDArray.h +++ b/Lumos/Source/Lumos/Core/DataStructures/TDArray.h @@ -100,6 +100,15 @@ namespace Lumos ConstIterator begin() const { return ConstIterator(m_Data); } ConstIterator end() const { return ConstIterator(m_Data + m_Size); } + template + struct EqualTo + { + constexpr bool operator()(const U& a, const U& b) { return a == b; } + }; + + template ::type>> + void Unique(CompareFunc compare = CompareFunc()); + T*& Data() { return m_Data; } const T* Data() const { return m_Data; } @@ -399,4 +408,25 @@ namespace Lumos } Resize(writeIndex); } + + template + template + void TDArray::Unique(CompareFunc compare) + { + if (m_Size < 2) + return; + + size_t writeIndex = 1; // Start writing from the second element + for (size_t readIndex = 1; readIndex < m_Size; ++readIndex) + { + // Compare with the last written element + if (!compare(m_Data[readIndex], m_Data[writeIndex - 1])) + { + m_Data[writeIndex] = std::move(m_Data[readIndex]); + ++writeIndex; + } + } + + Resize(writeIndex); // Resize the array to the new size + } } diff --git a/Lumos/Source/Lumos/Core/JobSystem.cpp b/Lumos/Source/Lumos/Core/JobSystem.cpp index 41a63661..dbabbccc 100644 --- a/Lumos/Source/Lumos/Core/JobSystem.cpp +++ b/Lumos/Source/Lumos/Core/JobSystem.cpp @@ -112,22 +112,37 @@ namespace Lumos ~InternalState() { LUMOS_PROFILE_FUNCTION_LOW(); + alive.store(false); // indicate that new jobs cannot be started from this point - bool wake_loop = true; + bool bWakeLoop = true; + + #ifdef LUMOS_PLATFORM_LINUX + for(auto& thread : threads) + { + if(thread.joinable()) + thread.join(); + } + bWakeLoop = false; + wakeCondition.notify_all(); + #else std::thread waker([&] - { - while (wake_loop) + { + while (bWakeLoop) { wakeCondition.notify_all(); // wakes up sleeping worker threads - } }); + } + }); + for(auto& thread : threads) { if(thread.joinable()) thread.join(); } - wake_loop = false; + bWakeLoop = false; if(waker.joinable()) waker.join(); + #endif + delete[] jobQueuePerThread; } }; diff --git a/Lumos/Source/Lumos/Graphics/Animation/AnimationController.cpp b/Lumos/Source/Lumos/Graphics/Animation/AnimationController.cpp index 512f1ecd..bf118b82 100644 --- a/Lumos/Source/Lumos/Graphics/Animation/AnimationController.cpp +++ b/Lumos/Source/Lumos/Graphics/Animation/AnimationController.cpp @@ -171,7 +171,7 @@ namespace Lumos } auto test = GetJointMatrices(); - m_Descriptor->SetUniform("BoneTransforms", "BoneTransforms", test.Data(), (uint32_t)(sizeof(Mat4) * test.Size())); + m_Descriptor->SetUniformBufferData(0, test.Data(), (uint32_t)(sizeof(Mat4) * test.Size())); m_Descriptor->Update(); return m_Descriptor; diff --git a/Lumos/Source/Lumos/Graphics/Material.cpp b/Lumos/Source/Lumos/Graphics/Material.cpp index c6a95881..abd67acc 100644 --- a/Lumos/Source/Lumos/Graphics/Material.cpp +++ b/Lumos/Source/Lumos/Graphics/Material.cpp @@ -135,7 +135,7 @@ namespace Lumos::Graphics if(!m_DescriptorSet) return; - m_DescriptorSet->SetUniformBufferData("UniformMaterialData", *&m_MaterialProperties); + m_DescriptorSet->SetUniformBufferData(6, *&m_MaterialProperties); m_DescriptorSet->Update(); } @@ -164,53 +164,53 @@ namespace Lumos::Graphics { if(m_PBRMaterialTextures.albedo != nullptr) { - m_DescriptorSet->SetTexture("u_AlbedoMap", m_PBRMaterialTextures.albedo.get()); + m_DescriptorSet->SetTexture(0, m_PBRMaterialTextures.albedo.get()); } else { - m_DescriptorSet->SetTexture("u_AlbedoMap", s_DefaultTexture.get()); + m_DescriptorSet->SetTexture(0, s_DefaultTexture.get()); m_MaterialProperties->albedoMapFactor = 0.0f; } // if(pbr) { - m_DescriptorSet->SetTexture("u_MetallicMap", m_PBRMaterialTextures.metallic ? m_PBRMaterialTextures.metallic.get() : s_DefaultTexture.get()); + m_DescriptorSet->SetTexture(1, m_PBRMaterialTextures.metallic ? m_PBRMaterialTextures.metallic.get() : s_DefaultTexture.get()); if(!m_PBRMaterialTextures.metallic) m_MaterialProperties->metallicMapFactor = 0.0f; - m_DescriptorSet->SetTexture("u_RoughnessMap", m_PBRMaterialTextures.roughness ? m_PBRMaterialTextures.roughness.get() : s_DefaultTexture.get()); + m_DescriptorSet->SetTexture(2, m_PBRMaterialTextures.roughness ? m_PBRMaterialTextures.roughness.get() : s_DefaultTexture.get()); if(!m_PBRMaterialTextures.roughness) m_MaterialProperties->roughnessMapFactor = 0.0f; if(m_PBRMaterialTextures.normal != nullptr) { - m_DescriptorSet->SetTexture("u_NormalMap", m_PBRMaterialTextures.normal.get()); + m_DescriptorSet->SetTexture(3, m_PBRMaterialTextures.normal.get()); } else { - m_DescriptorSet->SetTexture("u_NormalMap", s_DefaultTexture.get()); + m_DescriptorSet->SetTexture(3, s_DefaultTexture.get()); m_MaterialProperties->normalMapFactor = 0.0f; } if(m_PBRMaterialTextures.ao != nullptr) { - m_DescriptorSet->SetTexture("u_AOMap", m_PBRMaterialTextures.ao.get()); + m_DescriptorSet->SetTexture(4, m_PBRMaterialTextures.ao.get()); } else { - m_DescriptorSet->SetTexture("u_AOMap", s_DefaultTexture.get()); + m_DescriptorSet->SetTexture(4, s_DefaultTexture.get()); m_MaterialProperties->occlusionMapFactor = 0.0f; } if(m_PBRMaterialTextures.emissive != nullptr) { - m_DescriptorSet->SetTexture("u_EmissiveMap", m_PBRMaterialTextures.emissive.get()); + m_DescriptorSet->SetTexture(5, m_PBRMaterialTextures.emissive.get()); } else { - m_DescriptorSet->SetTexture("u_EmissiveMap", s_DefaultTexture.get()); + m_DescriptorSet->SetTexture(5, s_DefaultTexture.get()); m_MaterialProperties->emissiveMapFactor = 0.0f; } diff --git a/Lumos/Source/Lumos/Graphics/RHI/DescriptorSet.h b/Lumos/Source/Lumos/Graphics/RHI/DescriptorSet.h index 1a1bf9d9..23662b49 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/DescriptorSet.h +++ b/Lumos/Source/Lumos/Graphics/RHI/DescriptorSet.h @@ -22,10 +22,23 @@ namespace Lumos virtual void SetUniform(const std::string& bufferName, const std::string& uniformName, void* data) = 0; virtual void SetUniform(const std::string& bufferName, const std::string& uniformName, void* data, uint32_t size) = 0; virtual void SetUniformBufferData(const std::string& bufferName, void* data) = 0; + + virtual void SetTexture(u8 binding, Texture* texture, uint32_t mipIndex = 0, TextureType textureType = TextureType(0)) = 0; + virtual void SetTexture(u8 binding, Texture** texture, uint32_t textureCount, TextureType textureType = TextureType(0)) = 0; + virtual void SetBuffer(u8 binding, UniformBuffer* buffer) = 0; + virtual void SetUniform(u8 binding, const std::string& uniformName, void* data) = 0; + virtual void SetUniform(u8 binding, const std::string& uniformName, void* data, uint32_t size) = 0; + virtual void SetUniformBufferData(u8 binding, void* data) = 0; + virtual void SetUniformBufferData(u8 binding, void* data, float size) = 0; + virtual void TransitionImages(CommandBuffer* commandBuffer = nullptr) { } virtual void SetUniformDynamic(const std::string& bufferName, uint32_t size) { } virtual Buffer* GetUniformBufferLocalData(const std::string& name) { return nullptr; } + virtual Buffer* GetUniformBufferLocalData(u8 binding) { return nullptr; } + virtual Graphics::UniformBuffer* GetUniformBuffer(u8 binding) = 0; + + protected: static DescriptorSet* (*CreateFunc)(const DescriptorDesc&); }; diff --git a/Lumos/Source/Lumos/Graphics/RHI/RHIDefinitions.h b/Lumos/Source/Lumos/Graphics/RHI/RHIDefinitions.h index 974420a4..605e6a30 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/RHIDefinitions.h +++ b/Lumos/Source/Lumos/Graphics/RHI/RHIDefinitions.h @@ -35,6 +35,9 @@ namespace Lumos static constexpr uint16_t DESCRIPTOR_MAX_SAMPLERS = 1024; static constexpr uint16_t DESCRIPTOR_MAX_TEXTURES = 1024; + static constexpr uint8_t DESCRIPTOR_MAX_SETS = 8; + static constexpr uint8_t DESCRIPTOR_MAX_DESCRIPTORS = 16; + enum class CullMode : uint8_t { FRONT = 0, @@ -317,13 +320,13 @@ namespace Lumos uint32_t binding; uint32_t textureCount = 1; uint32_t mipLevel = 0; - std::string name; TextureType textureType; DescriptorType type = DescriptorType::IMAGE_SAMPLER; ShaderType shaderType; TDArray m_Members; + std::string name; }; enum class CubeFace : uint8_t diff --git a/Lumos/Source/Lumos/Graphics/Renderers/GridRenderer.cpp b/Lumos/Source/Lumos/Graphics/Renderers/GridRenderer.cpp index ccec516e..4e07bfb3 100644 --- a/Lumos/Source/Lumos/Graphics/Renderers/GridRenderer.cpp +++ b/Lumos/Source/Lumos/Graphics/Renderers/GridRenderer.cpp @@ -134,12 +134,9 @@ namespace Lumos test.maxDistance = m_MaxDistance; - auto invViewProj = proj * view; - m_DescriptorSet[0]->SetUniform("UBO", "u_MVP", &invViewProj); - m_DescriptorSet[0]->SetUniform("UBO", "view", &view); - m_DescriptorSet[0]->SetUniform("UBO", "proj", &proj); - - m_DescriptorSet[0]->SetUniformBufferData("UniformBuffer", &test); + Mat4 matrices[3] = { view, proj, proj * view }; + m_DescriptorSet[0]->SetUniformBufferData(0, matrices); + m_DescriptorSet[0]->SetUniformBufferData(1, &test); m_DescriptorSet[0]->Update(); } diff --git a/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp b/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp index 73e21886..c407c536 100644 --- a/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp +++ b/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp @@ -55,6 +55,8 @@ static const uint32_t MaxLineIndices = MaxLines * 2; static const uint32_t MAX_LINE_BATCH_DRAW_CALLS = 100; static const uint32_t RENDERER_LINE_SIZE = sizeof(Lumos::Graphics::LineVertexData) * 4; static const uint32_t RENDERER_LINE_BUFFER_SIZE = RENDERER_LINE_SIZE * MaxLineVertices; +static const uint32_t MAX_LIGHTS = 32; +static const uint32_t MAX_SHADOWMAPS = 4; namespace Lumos::Graphics { @@ -228,7 +230,7 @@ namespace Lumos::Graphics { boneTransforms[i] = Mat4(1.0f); } - m_ForwardData.m_DescriptorSet[3]->SetUniform("BoneTransforms", "BoneTransforms", boneTransforms, sizeof(Mat4) * 100); + m_ForwardData.m_DescriptorSet[3]->SetUniformBufferData(0, boneTransforms); m_ForwardData.m_DescriptorSet[3]->Update(); m_ForwardData.m_DefaultMaterial = new Material(m_ForwardData.m_Shader); @@ -785,7 +787,7 @@ namespace Lumos::Graphics if(renderSettings.Renderer3DEnabled) { - m_ForwardData.m_DescriptorSet[0]->SetUniform("UBO", "projView", &projView); + m_ForwardData.m_DescriptorSet[0]->SetUniformBufferData(0, &projView); m_ForwardData.m_DescriptorSet[0]->Update(); } @@ -832,15 +834,12 @@ namespace Lumos::Graphics } } - auto invProj = proj.Inverse(); - auto invView = view.Inverse(); - - m_SkyboxDescriptorSet->SetUniform("UBO", "invProjection", &invProj); - m_SkyboxDescriptorSet->SetUniform("UBO", "invView", &invView); + Mat4 matrices[2] = { proj.Inverse(), view.Inverse() }; + m_SkyboxDescriptorSet->SetUniformBufferData(0, matrices); } Light* directionaLight = nullptr; - static Light lights[256]; + static Light lights[MAX_LIGHTS]; uint32_t numLights = 0; m_ForwardData.m_Frustum = m_Camera->GetFrustum(view); @@ -852,35 +851,62 @@ namespace Lumos::Graphics emitter.Update((float)Engine::GetTimeStep().GetSeconds(), trans.GetWorldPosition()); } + + + m_ForwardData.m_CommandQueue.Clear(); + + struct UniformSceneData + { + Light lights[MAX_LIGHTS]; + Mat4 ShadowTransform[MAX_SHADOWMAPS]; + Mat4 ViewMatrix; + Mat4 LightView; + Mat4 BiasMatrix; + Vec4 cameraPosition; + Vec4 SplitDepths[MAX_SHADOWMAPS]; + float LightSize; + float MaxShadowDist; + float ShadowFade; + float CascadeFade; + int LightCount; + int ShadowCount; + int Mode; + int EnvMipCount; + float InitialBias; + float Width; + float Height; + int shadowEnabled; + }; + if(renderSettings.Renderer3DEnabled) { { LUMOS_PROFILE_SCOPE("Get Light"); auto group = registry.group(entt::get); - for(auto& lightEntity : group) + for (auto& lightEntity : group) { - if(!Entity(lightEntity, scene).Active()) + if (!Entity(lightEntity, scene).Active()) continue; - if(numLights >= 64) + if (numLights >= MAX_LIGHTS) break; const auto& [light, trans] = group.get(lightEntity); - light.Position = Vec4(trans.GetWorldPosition(), 1.0f); - Vec3 forward = Vec3(0.0f, 0.0f, 1.0f); - forward = trans.GetWorldOrientation() * forward; + light.Position = Vec4(trans.GetWorldPosition(), 1.0f); + Vec3 forward = Vec3(0.0f, 0.0f, 1.0f); + forward = trans.GetWorldOrientation() * forward; forward.Normalise(); light.Direction = Vec4(forward, 1.0f); - if(light.Type == (float)Graphics::LightType::DirectionalLight) + if (light.Type == (float)Graphics::LightType::DirectionalLight) directionaLight = &light; - if(light.Type != float(LightType::DirectionalLight)) + if (light.Type != float(LightType::DirectionalLight)) { auto inside = m_ForwardData.m_Frustum.IsInside(Maths::BoundingSphere(Vec3(light.Position), light.Radius * 100)); - if(inside == Maths::Intersection::OUTSIDE) + if (inside == Maths::Intersection::OUTSIDE) continue; } @@ -890,73 +916,54 @@ namespace Lumos::Graphics } } - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "lights", lights, sizeof(Graphics::Light) * numLights); - - Vec4 cameraPos = Vec4(m_CameraTransform->GetWorldPosition(), 1.0f); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "cameraPosition", &cameraPos); - } - - if(renderSettings.ShadowsEnabled) - { - for(uint32_t i = 0; i < m_ShadowData.m_ShadowMapNum; i++) - { - m_ShadowData.m_CascadeCommandQueue[i].Clear(); - } - - if(directionaLight) + if (renderSettings.ShadowsEnabled) { - UpdateCascades(scene, directionaLight); + for (uint32_t i = 0; i < m_ShadowData.m_ShadowMapNum; i++) + { + m_ShadowData.m_CascadeCommandQueue[i].Clear(); + } - for(uint32_t i = 0; i < m_ShadowData.m_ShadowMapNum; i++) + if (directionaLight) { - m_ShadowData.m_CascadeFrustums[i].Define(m_ShadowData.m_ShadowProjView[i]); + UpdateCascades(scene, directionaLight); + + for (uint32_t i = 0; i < m_ShadowData.m_ShadowMapNum; i++) + { + m_ShadowData.m_CascadeFrustums[i].Define(m_ShadowData.m_ShadowProjView[i]); + } } } - } - m_ForwardData.m_CommandQueue.Clear(); - - auto& shadowData = GetShadowData(); - Mat4* shadowTransforms = shadowData.m_ShadowProjView; - Vec4* uSplitDepth = shadowData.m_SplitDepth; - Mat4 LightView = shadowData.m_LightMatrix; - float bias = shadowData.m_InitialBias; - float MaxShadowDist = shadowData.m_MaxShadowDistance; - float LightSize = (float)shadowData.m_ShadowMapSize; - float transitionFade = shadowData.m_CascadeFade; - float ShadowFade = shadowData.m_ShadowFade; - float width = (float)m_MainTexture->GetWidth(); - float height = (float)m_MainTexture->GetHeight(); - - int shadowEnabled = renderSettings.ShadowsEnabled ? 1 : 0; - if(renderSettings.Renderer3DEnabled) - { - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "ViewMatrix", &view); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "LightView", &LightView); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "ShadowTransform", shadowTransforms); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "SplitDepths", uSplitDepth); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "BiasMatrix", &m_ForwardData.m_BiasMatrix); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "LightSize", &LightSize); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "ShadowFade", &ShadowFade); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "CascadeFade", &transitionFade); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "MaxShadowDist", &MaxShadowDist); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "InitialBias", &bias); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "Width", &width); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "Height", &height); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "shadowEnabled", &shadowEnabled); - - m_ForwardData.m_DescriptorSet[2]->SetTexture("uShadowMap", reinterpret_cast(shadowData.m_ShadowTex), 0, TextureType::DEPTHARRAY); - - int numShadows = shadowData.m_ShadowMapNum; - auto EnvMipCount = m_ForwardData.m_EnvironmentMap ? m_ForwardData.m_EnvironmentMap->GetMipMapLevels() : 0; - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "LightCount", &numLights); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "ShadowCount", &numShadows); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "Mode", &m_ForwardData.m_RenderMode); - m_ForwardData.m_DescriptorSet[2]->SetUniform("UniformSceneData", "EnvMipCount", &EnvMipCount); - m_ForwardData.m_DescriptorSet[2]->SetTexture("uBRDFLUT", m_ForwardData.m_BRDFLUT.get()); - m_ForwardData.m_DescriptorSet[2]->SetTexture("uSSAOMap", Application::Get().GetCurrentScene()->GetSettings().RenderSettings.SSAOEnabled ? m_SSAOTexture : Material::GetDefaultTexture().get()); - m_ForwardData.m_DescriptorSet[2]->SetTexture("uEnvMap", m_ForwardData.m_EnvironmentMap, 0, TextureType::CUBE); - m_ForwardData.m_DescriptorSet[2]->SetTexture("uIrrMap", m_ForwardData.m_IrradianceMap, 0, TextureType::CUBE); + UniformSceneData uniformSceneData; + auto& shadowData = GetShadowData(); + MemoryCopy(uniformSceneData.ShadowTransform, shadowData.m_ShadowProjView, sizeof(Mat4)* shadowData.m_ShadowMapNum); + MemoryCopy(uniformSceneData.SplitDepths, shadowData.m_SplitDepth, sizeof(Vec4)* shadowData.m_ShadowMapNum); + uniformSceneData.LightView = shadowData.m_LightMatrix; + uniformSceneData.InitialBias = shadowData.m_InitialBias; + uniformSceneData.LightSize = shadowData.m_ShadowMapSize; + uniformSceneData.ShadowFade = shadowData.m_ShadowFade; + uniformSceneData.CascadeFade = shadowData.m_CascadeFade; + uniformSceneData.MaxShadowDist = shadowData.m_MaxShadowDistance; + uniformSceneData.Width = (float)m_MainTexture->GetWidth(); + uniformSceneData.Height = (float)m_MainTexture->GetHeight(); + uniformSceneData.shadowEnabled = renderSettings.ShadowsEnabled ? 1 : 0; + uniformSceneData.ShadowCount = shadowData.m_ShadowMapNum; + uniformSceneData.EnvMipCount = m_ForwardData.m_EnvironmentMap ? m_ForwardData.m_EnvironmentMap->GetMipMapLevels() : 0; + uniformSceneData.ViewMatrix = view; + uniformSceneData.BiasMatrix = m_ForwardData.m_BiasMatrix; + uniformSceneData.Mode = m_ForwardData.m_RenderMode; + uniformSceneData.cameraPosition = Vec4(m_CameraTransform->GetWorldPosition(), 1.0f); + + MemoryCopy(uniformSceneData.lights, lights, sizeof(Graphics::Light)* numLights); + uniformSceneData.LightCount = numLights; + + m_ForwardData.m_DescriptorSet[2]->SetUniformBufferData(5, &uniformSceneData); + + m_ForwardData.m_DescriptorSet[2]->SetTexture(0, reinterpret_cast(shadowData.m_ShadowTex), 0, TextureType::DEPTHARRAY); + m_ForwardData.m_DescriptorSet[2]->SetTexture(3, m_ForwardData.m_BRDFLUT.get()); + m_ForwardData.m_DescriptorSet[2]->SetTexture(4, Application::Get().GetCurrentScene()->GetSettings().RenderSettings.SSAOEnabled ? m_SSAOTexture : Material::GetDefaultTexture().get()); + m_ForwardData.m_DescriptorSet[2]->SetTexture(1, m_ForwardData.m_EnvironmentMap, 0, TextureType::CUBE); + m_ForwardData.m_DescriptorSet[2]->SetTexture(2, m_ForwardData.m_IrradianceMap, 0, TextureType::CUBE); m_ForwardData.m_DescriptorSet[2]->Update(); Mat4 boneTransforms[100]; @@ -964,7 +971,7 @@ namespace Lumos::Graphics { boneTransforms[i] = Mat4(1.0f); } - m_ForwardData.m_DescriptorSet[3]->SetUniform("BoneTransforms", "BoneTransforms", boneTransforms, sizeof(Mat4) * 100); + m_ForwardData.m_DescriptorSet[3]->SetUniformBufferData(0, boneTransforms); m_ForwardData.m_DescriptorSet[3]->Update(); auto group = registry.group(entt::get); @@ -1607,10 +1614,10 @@ namespace Lumos::Graphics commandBuffer->UnBindPipeline(); commandBuffer->EndCurrentRenderPass(); - m_ShadowData.m_DescriptorSet[0]->SetUniform("ShadowData", "DirLightMatrices", m_ShadowData.m_ShadowProjView); + m_ShadowData.m_DescriptorSet[0]->SetUniformBufferData(1, m_ShadowData.m_ShadowProjView); m_ShadowData.m_DescriptorSet[0]->Update(); - m_ShadowData.m_DescriptorSet[1]->SetUniform("ShadowData", "DirLightMatrices", m_ShadowData.m_ShadowProjView); + m_ShadowData.m_DescriptorSet[1]->SetUniformBufferData(1, m_ShadowData.m_ShadowProjView); m_ShadowData.m_DescriptorSet[1]->Update(); Arena* frameArena = Application::Get().GetFrameArena(); @@ -1701,7 +1708,7 @@ namespace Lumos::Graphics auto& worldTransform = command.transform; auto& pushConstants = m_DepthPrePassShader->GetPushConstants()[0]; - pushConstants.SetValue("transform", (void*)&worldTransform); + pushConstants.SetData((void*)&worldTransform); m_DepthPrePassShader->BindPushConstants(commandBuffer, pipeline); Renderer::BindDescriptorSets(pipeline, commandBuffer, 0, sets, command.animated ? 4 : 3); @@ -1740,8 +1747,19 @@ namespace Lumos::Graphics float nearC = m_Camera->GetNear(); float farC = m_Camera->GetFar(); - static Vec4 samples[64]; static bool init = false; + struct SSAOUniformBufferData + { + Mat4 projection; + Mat4 invProj; + Mat4 view; + Vec4 samples[64]; + float ssaoRadius; + float Near; + float Far; + float strength; + }; + static SSAOUniformBufferData data; if(!init) { @@ -1752,27 +1770,24 @@ namespace Lumos::Graphics sample *= Random32::Rand(0.0f, 1.0f); // Space out linearly float scale = (float)i / (float)64; scale = Maths::Lerp(0.1f, 1.0f, scale * scale); // Bring distribution of samples closer to origin - samples[i] = Vec4(sample * scale, 0.0f); + data.samples[i] = Vec4(sample * scale, 0.0f); } init = true; } Scene::SceneRenderSettings& renderSettings = m_CurrentScene->GetSettings().RenderSettings; - - m_SSAOPassDescriptorSet->SetUniform("UniformBuffer", "invProj", &invProj); - m_SSAOPassDescriptorSet->SetUniform("UniformBuffer", "projection", &projection); - m_SSAOPassDescriptorSet->SetUniform("UniformBuffer", "view", &view); - - m_SSAOPassDescriptorSet->SetUniform("UniformBuffer", "samples", &samples); - m_SSAOPassDescriptorSet->SetUniform("UniformBuffer", "ssaoRadius", &renderSettings.SSAOSampleRadius); - - m_SSAOPassDescriptorSet->SetUniform("UniformBuffer", "near", &nearC); - m_SSAOPassDescriptorSet->SetUniform("UniformBuffer", "far", &farC); - m_SSAOPassDescriptorSet->SetUniform("UniformBuffer", "strength", &renderSettings.SSAOStrength); - - m_SSAOPassDescriptorSet->SetTexture("in_Depth", m_ForwardData.m_DepthTexture); - m_SSAOPassDescriptorSet->SetTexture("in_Noise", m_NoiseTexture); - m_SSAOPassDescriptorSet->SetTexture("in_Normal", m_NormalTexture); + data.invProj = invProj; + data.projection = projection; + data.view = view; + data.ssaoRadius = renderSettings.SSAOSampleRadius; + data.Near = nearC; + data.Far = farC; + data.strength = renderSettings.SSAOStrength; + + m_SSAOPassDescriptorSet->SetUniformBufferData(0, &data); + m_SSAOPassDescriptorSet->SetTexture(1, m_ForwardData.m_DepthTexture); + m_SSAOPassDescriptorSet->SetTexture(3, m_NoiseTexture); + m_SSAOPassDescriptorSet->SetTexture(2, m_NormalTexture); m_SSAOPassDescriptorSet->Update(); auto pipeline = Graphics::Pipeline::Get(pipelineDesc); @@ -1801,30 +1816,37 @@ namespace Lumos::Graphics if(m_MainTextureSamples > 1) pipelineDesc.resolveTexture = m_ResolveTexture; - Vec2 ssaoTexelOffset = Vec2(2.0f / m_SSAOTexture->GetWidth(), 0.0f); - Scene::SceneRenderSettings& renderSettings = m_CurrentScene->GetSettings().RenderSettings; auto view = m_CameraTransform->GetWorldMatrix().Inverse(); - m_SSAOBlurPassDescriptorSet->SetUniform("UniformBuffer", "view", &view); - m_SSAOBlurPassDescriptorSet->SetUniform("UniformBuffer", "ssaoTexelOffset", &ssaoTexelOffset); - m_SSAOBlurPassDescriptorSet->SetUniform("UniformBuffer", "ssaoBlurRadius", &renderSettings.SSAOBlurRadius); - - m_SSAOBlurPassDescriptorSet->SetTexture("in_Depth", m_ForwardData.m_DepthTexture); - m_SSAOBlurPassDescriptorSet->SetTexture("in_SSAO", m_SSAOTexture); - m_SSAOBlurPassDescriptorSet->SetTexture("in_Normal", m_NormalTexture); + struct SSAOUniformBufferData + { + Mat4 view; + float texelOffset[2]; + int blurRadius; + int pad; + }; + static SSAOUniformBufferData data; + data.view = view; + data.texelOffset[0] = 2.0f / m_SSAOTexture->GetWidth(); + data.texelOffset[1] = 0.0f; + + data.blurRadius = renderSettings.SSAOBlurRadius; + + m_SSAOBlurPassDescriptorSet->SetUniformBufferData(0, &data); + m_SSAOBlurPassDescriptorSet->SetTexture(1, m_ForwardData.m_DepthTexture); + m_SSAOBlurPassDescriptorSet->SetTexture(2, m_SSAOTexture); + m_SSAOBlurPassDescriptorSet->SetTexture(3, m_NormalTexture); m_SSAOBlurPassDescriptorSet->TransitionImages(commandBuffer); m_SSAOBlurPassDescriptorSet->Update(); - ssaoTexelOffset = Vec2(0.0f, 2.0f / m_SSAOTexture->GetHeight()); - - m_SSAOBlurPassDescriptorSet2->SetUniform("UniformBuffer", "view", &view); - m_SSAOBlurPassDescriptorSet2->SetUniform("UniformBuffer", "ssaoTexelOffset", &ssaoTexelOffset); - m_SSAOBlurPassDescriptorSet2->SetUniform("UniformBuffer", "ssaoBlurRadius", &renderSettings.SSAOBlurRadius); + data.texelOffset[1] = 2.0f / m_SSAOTexture->GetHeight(); + data.texelOffset[0] = 0.0f; - m_SSAOBlurPassDescriptorSet2->SetTexture("in_Depth", m_ForwardData.m_DepthTexture); - m_SSAOBlurPassDescriptorSet2->SetTexture("in_SSAO", m_SSAOTexture1); - m_SSAOBlurPassDescriptorSet2->SetTexture("in_Normal", m_NormalTexture); + m_SSAOBlurPassDescriptorSet2->SetUniformBufferData(0, &data); + m_SSAOBlurPassDescriptorSet2->SetTexture(1, m_ForwardData.m_DepthTexture); + m_SSAOBlurPassDescriptorSet2->SetTexture(2, m_SSAOTexture1); + m_SSAOBlurPassDescriptorSet2->SetTexture(3, m_NormalTexture); auto pipeline = Graphics::Pipeline::Get(pipelineDesc); commandBuffer->BindPipeline(pipeline); @@ -1896,13 +1918,19 @@ namespace Lumos::Graphics if(!m_Camera || !m_CameraTransform) return; - int mode = 0; - float exposure = m_Exposure * 120000.0f; - float blurLevel = m_CurrentScene->GetSettings().RenderSettings.SkyboxMipLevel; - m_SkyboxDescriptorSet->SetUniform("UniformBuffer", "Mode", &mode); - m_SkyboxDescriptorSet->SetUniform("UniformBuffer", "Exposure", &exposure); - m_SkyboxDescriptorSet->SetUniform("UniformBuffer", "BlurLevel", &blurLevel); - m_SkyboxDescriptorSet->SetTexture("u_CubeMap", m_CubeMap, 0, TextureType::CUBE); + struct SkyboxUniformData + { + float Exposure; + int Mode; //0 env map , 1 custom sky + float BlurLevel; + float p1; + }; + SkyboxUniformData data; + data.Mode = 0; + data.Exposure = m_Exposure * 120000.0f; + data.BlurLevel = m_CurrentScene->GetSettings().RenderSettings.SkyboxMipLevel; + m_SkyboxDescriptorSet->SetTexture(1, m_CubeMap, 0, TextureType::CUBE); + m_SkyboxDescriptorSet->SetUniformBufferData(2, &data); m_SkyboxDescriptorSet->Update(); Graphics::PipelineDesc pipelineDesc {}; @@ -1954,14 +1982,12 @@ namespace Lumos::Graphics // correct the handedness issue. if(depthLinearizeMul * depthLinearizeAdd < 0) depthLinearizeAdd = -depthLinearizeAdd; - Vec2 DepthConsts = { depthLinearizeMul, depthLinearizeAdd }; - Vec2 DOFParams = { renderSettings.DepthOfFieldDistance, renderSettings.DepthOfFieldStrength }; - m_DepthOfFieldPassDescriptorSet->SetUniform("UniformBuffer", "DOFParams", &DOFParams); - m_DepthOfFieldPassDescriptorSet->SetUniform("UniformBuffer", "DepthConsts", &DepthConsts); + Vec4 UniformData = { renderSettings.DepthOfFieldDistance, renderSettings.DepthOfFieldStrength , depthLinearizeMul, depthLinearizeAdd }; - m_DepthOfFieldPassDescriptorSet->SetTexture("u_Texture", m_LastRenderTarget); - m_DepthOfFieldPassDescriptorSet->SetTexture("u_DepthTexture", m_ForwardData.m_DepthTexture); + m_DepthOfFieldPassDescriptorSet->SetUniformBufferData(0, &UniformData); + m_DepthOfFieldPassDescriptorSet->SetTexture(1, m_LastRenderTarget); + m_DepthOfFieldPassDescriptorSet->SetTexture(2, m_ForwardData.m_DepthTexture); m_DepthOfFieldPassDescriptorSet->Update(); Graphics::PipelineDesc pipelineDesc {}; @@ -1992,7 +2018,7 @@ namespace Lumos::Graphics Scene::SceneRenderSettings& renderSettings = m_CurrentScene->GetSettings().RenderSettings; - m_SharpenPassDescriptorSet->SetTexture("u_Texture", m_LastRenderTarget); + m_SharpenPassDescriptorSet->SetTexture(1, m_LastRenderTarget); m_SharpenPassDescriptorSet->Update(); Graphics::PipelineDesc pipelineDesc {}; @@ -2416,19 +2442,28 @@ namespace Lumos::Graphics auto commandBuffer = Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(); commandBuffer->UnBindPipeline(); - float bloomIntensity = m_CurrentScene->GetSettings().RenderSettings.BloomEnabled ? m_CurrentScene->GetSettings().RenderSettings.m_BloomIntensity : 0.0f; - float Saturation = m_CurrentScene->GetSettings().RenderSettings.Saturation; - float Brightness = m_CurrentScene->GetSettings().RenderSettings.Brightness; - float Contrast = m_CurrentScene->GetSettings().RenderSettings.Contrast; - - m_ToneMappingPassDescriptorSet->SetUniform("UniformBuffer", "BloomIntensity", &bloomIntensity); - m_ToneMappingPassDescriptorSet->SetUniform("UniformBuffer", "ToneMapIndex", &m_ToneMapIndex); - m_ToneMappingPassDescriptorSet->SetUniform("UniformBuffer", "Brightness", &Brightness); - m_ToneMappingPassDescriptorSet->SetUniform("UniformBuffer", "Contrast", &Contrast); - m_ToneMappingPassDescriptorSet->SetUniform("UniformBuffer", "Saturation", &Saturation); - - m_ToneMappingPassDescriptorSet->SetTexture("u_Texture", m_LastRenderTarget); - m_ToneMappingPassDescriptorSet->SetTexture("u_BloomTexture", m_BloomTextureLastRenderered); + struct ToneMappingUniformData + { + float BloomIntensity; + int ToneMapIndex; + float Saturation; + float Contrast; + float Brightness; + float p0; + float p1; + float p2; + }; + + ToneMappingUniformData data; + data.BloomIntensity = m_CurrentScene->GetSettings().RenderSettings.BloomEnabled ? m_CurrentScene->GetSettings().RenderSettings.m_BloomIntensity : 0.0f; + data.Saturation = m_CurrentScene->GetSettings().RenderSettings.Saturation; + data.Brightness = m_CurrentScene->GetSettings().RenderSettings.Brightness; + data.Contrast = m_CurrentScene->GetSettings().RenderSettings.Contrast; + data.ToneMapIndex = m_ToneMapIndex; + + m_ToneMappingPassDescriptorSet->SetUniformBufferData(0, &data); + m_ToneMappingPassDescriptorSet->SetTexture(1, m_LastRenderTarget); + m_ToneMappingPassDescriptorSet->SetTexture(2, m_BloomTextureLastRenderered); m_ToneMappingPassDescriptorSet->Update(); Graphics::PipelineDesc pipelineDesc {}; @@ -2486,7 +2521,7 @@ namespace Lumos::Graphics break; } #endif - m_FinalPassDescriptorSet->SetTexture("u_Texture", finalPassTexture); + m_FinalPassDescriptorSet->SetTexture(1, finalPassTexture); m_FinalPassDescriptorSet->Update(); Graphics::PipelineDesc pipelineDesc {}; @@ -2566,12 +2601,12 @@ namespace Lumos::Graphics commandBuffer->UnBindPipeline(); - m_BloomDescriptorSets[0]->SetTexture("u_Texture", m_LastRenderTarget); - m_BloomDescriptorSets[0]->SetTexture("u_BloomTexture", m_LastRenderTarget); + m_BloomDescriptorSets[0]->SetTexture(1, m_LastRenderTarget); + m_BloomDescriptorSets[0]->SetTexture(2, m_LastRenderTarget); if(m_SupportCompute) { - m_BloomDescriptorSets[0]->SetTexture("o_Image", m_BloomTexture); + m_BloomDescriptorSets[0]->SetTexture(0, m_BloomTexture); m_BloomDescriptorSets[0]->TransitionImages(commandBuffer); } m_BloomDescriptorSets[0]->Update(); @@ -2625,13 +2660,13 @@ namespace Lumos::Graphics { if(i % 2 == 0) { - m_BloomDescriptorSets[i]->SetTexture("u_Texture", m_BloomTexture1); - m_BloomDescriptorSets[i]->SetTexture("u_BloomTexture", m_LastRenderTarget); + m_BloomDescriptorSets[i]->SetTexture(1, m_BloomTexture1); + m_BloomDescriptorSets[i]->SetTexture(2, m_LastRenderTarget); } else { - m_BloomDescriptorSets[i]->SetTexture("u_Texture", m_BloomTexture); - m_BloomDescriptorSets[i]->SetTexture("u_BloomTexture", m_LastRenderTarget); + m_BloomDescriptorSets[i]->SetTexture(1, m_BloomTexture); + m_BloomDescriptorSets[i]->SetTexture(2, m_LastRenderTarget); } m_BloomDescriptorSets[i]->Update(); @@ -2659,7 +2694,7 @@ namespace Lumos::Graphics if(m_SupportCompute) { - m_BloomDescriptorSets[passCount]->SetTexture("o_Image", m_BloomTexture1, i); + m_BloomDescriptorSets[passCount]->SetTexture(0, m_BloomTexture1, i); } m_BloomDescriptorSets[passCount]->TransitionImages(commandBuffer); @@ -2696,7 +2731,7 @@ namespace Lumos::Graphics if(m_SupportCompute) { - m_BloomDescriptorSets[passCount]->SetTexture("o_Image", m_BloomTexture, i); + m_BloomDescriptorSets[passCount]->SetTexture(0, m_BloomTexture, i); m_BloomDescriptorSets[passCount]->TransitionImages(commandBuffer); m_BloomDescriptorSets[passCount]->Update(); } @@ -2745,12 +2780,12 @@ namespace Lumos::Graphics auto commandBuffer = Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(); commandBuffer->UnBindPipeline(); - m_BloomDescriptorSets[passCount]->SetTexture("u_Texture", m_BloomTexture); - m_BloomDescriptorSets[passCount]->SetTexture("u_BloomTexture", m_LastRenderTarget); + m_BloomDescriptorSets[passCount]->SetTexture(1, m_BloomTexture); + m_BloomDescriptorSets[passCount]->SetTexture(2, m_LastRenderTarget); if(m_SupportCompute) { - m_BloomDescriptorSets[passCount]->SetTexture("o_Image", m_BloomTexture2, mips - 2); + m_BloomDescriptorSets[passCount]->SetTexture(0, m_BloomTexture2, mips - 2); } m_BloomDescriptorSets[passCount]->TransitionImages(commandBuffer); m_BloomDescriptorSets[passCount]->Update(); @@ -2796,13 +2831,13 @@ namespace Lumos::Graphics if(test % 2 == 0) { - m_BloomDescriptorSets[i]->SetTexture("u_Texture", m_BloomTexture); - m_BloomDescriptorSets[i]->SetTexture("u_BloomTexture", m_BloomTexture1); + m_BloomDescriptorSets[i]->SetTexture(1, m_BloomTexture); + m_BloomDescriptorSets[i]->SetTexture(2, m_BloomTexture1); } else { - m_BloomDescriptorSets[i]->SetTexture("u_Texture", m_BloomTexture); - m_BloomDescriptorSets[i]->SetTexture("u_BloomTexture", m_BloomTexture2); + m_BloomDescriptorSets[i]->SetTexture(1, m_BloomTexture); + m_BloomDescriptorSets[i]->SetTexture(2, m_BloomTexture2); } m_BloomDescriptorSets[i]->Update(); @@ -2831,7 +2866,7 @@ namespace Lumos::Graphics { if(m_SupportCompute) { - m_BloomDescriptorSets[passCount]->SetTexture("o_Image", m_BloomTexture1, mip); + m_BloomDescriptorSets[passCount]->SetTexture(0, m_BloomTexture1, mip); m_BloomDescriptorSets[passCount]->TransitionImages(commandBuffer); m_BloomDescriptorSets[passCount]->Update(); } @@ -2842,7 +2877,7 @@ namespace Lumos::Graphics { if(m_SupportCompute) { - m_BloomDescriptorSets[passCount]->SetTexture("o_Image", m_BloomTexture2, mip); + m_BloomDescriptorSets[passCount]->SetTexture(0, m_BloomTexture2, mip); m_BloomDescriptorSets[passCount]->TransitionImages(commandBuffer); m_BloomDescriptorSets[passCount]->Update(); } @@ -2892,13 +2927,16 @@ namespace Lumos::Graphics auto commandBuffer = Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(); commandBuffer->UnBindPipeline(); - m_FXAAPassDescriptorSet->SetTexture("u_Texture", m_LastRenderTarget); + m_FXAAPassDescriptorSet->SetTexture(1, m_LastRenderTarget); if(m_SupportCompute) { - m_FXAAPassDescriptorSet->SetTexture("o_Image", m_PostProcessTexture1); + m_FXAAPassDescriptorSet->SetTexture(1, m_PostProcessTexture1); + m_FXAAPassDescriptorSet->SetTexture(0, m_LastRenderTarget); m_FXAAPassDescriptorSet->TransitionImages(commandBuffer); } + else + m_FXAAPassDescriptorSet->SetTexture(1, m_LastRenderTarget); m_FXAAPassDescriptorSet->Update(); @@ -2944,7 +2982,7 @@ namespace Lumos::Graphics if(!m_LastRenderTarget || !m_DebandingShader->IsCompiled()) return; - m_DebandingPassDescriptorSet->SetTexture("u_Texture", m_LastRenderTarget); + m_DebandingPassDescriptorSet->SetTexture(1, m_LastRenderTarget); m_DebandingPassDescriptorSet->Update(); Graphics::PipelineDesc pipelineDesc {}; @@ -2975,7 +3013,7 @@ namespace Lumos::Graphics auto commandBuffer = Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(); commandBuffer->UnBindPipeline(); - m_FilmicGrainPassDescriptorSet->SetTexture("u_Texture", m_LastRenderTarget); + m_FilmicGrainPassDescriptorSet->SetTexture(1, m_LastRenderTarget); m_FilmicGrainPassDescriptorSet->Update(); Graphics::PipelineDesc pipelineDesc {}; @@ -3017,7 +3055,7 @@ namespace Lumos::Graphics auto commandBuffer = Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(); commandBuffer->UnBindPipeline(); - // m_OutlinePassDescriptorSet->SetTexture("u_Texture", m_LastRenderTarget); + // m_OutlinePassDescriptorSet->SetTexture(1, m_LastRenderTarget); // m_OutlinePassDescriptorSet->Update(); Graphics::PipelineDesc pipelineDesc {}; @@ -3046,12 +3084,9 @@ namespace Lumos::Graphics return; auto set = m_ChromaticAberationPassDescriptorSet.get(); - float cameraAperture = m_Camera->GetAperture(); - float intensity = 100.0f; - - set->SetTexture("u_Texture", m_LastRenderTarget); - set->SetUniform("UniformBuffer", "chromaticAberrationIntensity", &intensity); - set->SetUniform("UniformBuffer", "cameraAperture", &cameraAperture); + float data[4] = { 100.0f, m_Camera->GetAperture(), 0.0f, 0.0f }; + set->SetTexture(1, m_LastRenderTarget); + set->SetUniformBufferData(0, data); set->Update(); Graphics::PipelineDesc pipelineDesc {}; @@ -3132,7 +3167,7 @@ namespace Lumos::Graphics Renderer2DBeginBatch(); auto projView = m_Camera->GetProjectionMatrix() * m_CameraTransform->GetWorldMatrix().Inverse(); - m_Renderer2DData.m_DescriptorSet[0][0]->SetUniform("UBO", "projView", &projView); + m_Renderer2DData.m_DescriptorSet[0][0]->SetUniformBufferData(0, &projView); m_Renderer2DData.m_DescriptorSet[0][0]->Update(); for(auto& command : m_Renderer2DData.m_CommandQueue2D) @@ -3254,11 +3289,11 @@ namespace Lumos::Graphics m_Renderer2DData.m_TextureCount = 16; if(m_Renderer2DData.m_TextureCount > 1) - m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][1]->SetTexture("textures", m_Renderer2DData.m_Textures, m_Renderer2DData.m_TextureCount); + m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][1]->SetTexture(0, m_Renderer2DData.m_Textures, m_Renderer2DData.m_TextureCount); else if(m_Renderer2DData.m_TextureCount == 0) - m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][1]->SetTexture("textures", nullptr); + m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][1]->SetTexture(0, nullptr); else - m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][1]->SetTexture("textures", m_Renderer2DData.m_Textures[0]); + m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][1]->SetTexture(0, m_Renderer2DData.m_Textures[0]); m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][1]->Update(); @@ -3310,11 +3345,11 @@ namespace Lumos::Graphics textRenderData.m_TextureCount = 16; if(textRenderData.m_TextureCount > 1) - textRenderData.m_DescriptorSet[textRenderData.m_BatchDrawCallIndex][1]->SetTexture("textures", textRenderData.m_Textures, textRenderData.m_TextureCount); + textRenderData.m_DescriptorSet[textRenderData.m_BatchDrawCallIndex][1]->SetTexture(0, textRenderData.m_Textures, textRenderData.m_TextureCount); else if(textRenderData.m_TextureCount == 0) - textRenderData.m_DescriptorSet[textRenderData.m_BatchDrawCallIndex][1]->SetTexture("textures", Material::GetDefaultTexture()); + textRenderData.m_DescriptorSet[textRenderData.m_BatchDrawCallIndex][1]->SetTexture(0, Material::GetDefaultTexture()); else - textRenderData.m_DescriptorSet[textRenderData.m_BatchDrawCallIndex][1]->SetTexture("textures", textRenderData.m_Textures[0]); + textRenderData.m_DescriptorSet[textRenderData.m_BatchDrawCallIndex][1]->SetTexture(0, textRenderData.m_Textures[0]); textRenderData.m_DescriptorSet[textRenderData.m_BatchDrawCallIndex][1]->Update(); @@ -3400,7 +3435,7 @@ namespace Lumos::Graphics // m_TextBuffer = m_TextRendererData.m_VertexBuffers[currentFrame][m_TextRendererData.m_BatchDrawCallIndex]->GetPointer(); auto projView = m_Camera->GetProjectionMatrix() * m_CameraTransform->GetWorldMatrix().Inverse(); - m_TextRendererData.m_DescriptorSet[m_TextRendererData.m_BatchDrawCallIndex][0]->SetUniform("UBO", "projView", &projView); + m_TextRendererData.m_DescriptorSet[m_TextRendererData.m_BatchDrawCallIndex][0]->SetUniformBufferData(0, &projView); m_TextRendererData.m_DescriptorSet[m_TextRendererData.m_BatchDrawCallIndex][0]->Update(); m_TextRendererData.m_TextureCount = 0; @@ -3582,7 +3617,7 @@ namespace Lumos::Graphics m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0] = SharedPtr(Graphics::DescriptorSet::Create(descriptorDesc)); } - m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0]->SetUniform("UBO", "projView", &projView); + m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0]->SetUniformBufferData(0, &projView); m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0]->Update(); } @@ -3626,7 +3661,7 @@ namespace Lumos::Graphics float aspectRatio = (float)m_MainTexture->GetWidth() / (float)m_MainTexture->GetHeight(); // projView = Mat4::Orthographic(-aspectRatio * scale, aspectRatio * scale, 0.0f, scale, -10.0f, 10.0f); - m_TextRendererData.m_DescriptorSet[m_TextRendererData.m_BatchDrawCallIndex][0]->SetUniform("UBO", "projView", &projView); + m_TextRendererData.m_DescriptorSet[m_TextRendererData.m_BatchDrawCallIndex][0]->SetUniformBufferData(0, &projView); } m_TextRendererData.m_DescriptorSet[m_TextRendererData.m_BatchDrawCallIndex][0]->Update(); @@ -3664,7 +3699,7 @@ namespace Lumos::Graphics if(!lines.Empty()) { LUMOS_PROFILE_SCOPE("Debug Lines"); - m_DebugDrawData.m_LineDescriptorSet[0]->SetUniform("UBO", "projView", &projView); + m_DebugDrawData.m_LineDescriptorSet[0]->SetUniformBufferData(0, &projView); m_DebugDrawData.m_LineDescriptorSet[0]->Update(); Graphics::CommandBuffer* commandBuffer = Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(); @@ -3729,7 +3764,7 @@ namespace Lumos::Graphics { LUMOS_PROFILE_SCOPE("Debug Thick Lines"); - m_DebugDrawData.m_LineDescriptorSet[0]->SetUniform("UBO", "projView", &projView); + m_DebugDrawData.m_LineDescriptorSet[0]->SetUniformBufferData(0, &projView); m_DebugDrawData.m_LineDescriptorSet[0]->Update(); Graphics::CommandBuffer* commandBuffer = Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(); @@ -3788,7 +3823,7 @@ namespace Lumos::Graphics if(!points.Empty()) { LUMOS_PROFILE_SCOPE("Debug Points"); - m_DebugDrawData.m_PointDescriptorSet[0]->SetUniform("UBO", "projView", &projView); + m_DebugDrawData.m_PointDescriptorSet[0]->SetUniformBufferData(0, &projView); m_DebugDrawData.m_PointDescriptorSet[0]->Update(); Graphics::CommandBuffer* commandBuffer = Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(); @@ -3867,7 +3902,7 @@ namespace Lumos::Graphics { LUMOS_PROFILE_SCOPE("Triangles Lines"); - m_DebugDrawData.m_Renderer2DData.m_DescriptorSet[0][0]->SetUniform("UBO", "projView", &projView); + m_DebugDrawData.m_Renderer2DData.m_DescriptorSet[0][0]->SetUniformBufferData(0, &projView); m_DebugDrawData.m_Renderer2DData.m_DescriptorSet[0][0]->Update(); m_DebugDrawData.m_Renderer2DData.m_DescriptorSet[0][1]->Update(); @@ -3991,7 +4026,7 @@ namespace Lumos::Graphics DebugTextVertexBufferPtr = DebugTextVertexBufferBase[currentFrame]; auto projView = m_Camera->GetProjectionMatrix() * Mat4::Inverse(m_CameraTransform->GetWorldMatrix()); - m_DebugTextRendererData.m_DescriptorSet[m_DebugTextRendererData.m_BatchDrawCallIndex][0]->SetUniform("UBO", "projView", &projView); + m_DebugTextRendererData.m_DescriptorSet[m_DebugTextRendererData.m_BatchDrawCallIndex][0]->SetUniformBufferData(0, &projView); m_DebugTextRendererData.m_DescriptorSet[m_DebugTextRendererData.m_BatchDrawCallIndex][0]->Update(); m_DebugTextRendererData.m_TextureCount = 0; @@ -4159,7 +4194,7 @@ namespace Lumos::Graphics DebugRenderer::GetInstance()->SetProjView(projView); DebugRenderer::SortLists(); - m_DebugTextRendererData.m_DescriptorSet[m_DebugTextRendererData.m_BatchDrawCallIndex][0]->SetUniform("UBO", "projView", &projView); + m_DebugTextRendererData.m_DescriptorSet[m_DebugTextRendererData.m_BatchDrawCallIndex][0]->SetUniformBufferData(0, &projView); m_DebugTextRendererData.m_DescriptorSet[m_DebugTextRendererData.m_BatchDrawCallIndex][0]->Update(); m_DebugTextRendererData.m_TextureCount = 0; @@ -4334,7 +4369,7 @@ namespace Lumos::Graphics m_DebugTextRendererData.m_VertexBuffers[currentFrame][m_DebugTextRendererData.m_BatchDrawCallIndex]->Bind(Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(), m_DebugTextRendererData.m_Pipeline.get()); DebugTextVertexBufferPtr = DebugTextVertexBufferBase[currentFrame]; - m_DebugTextRendererData.m_DescriptorSet[m_DebugTextRendererData.m_BatchDrawCallIndex][0]->SetUniform("UBO", "projView", &projView); + m_DebugTextRendererData.m_DescriptorSet[m_DebugTextRendererData.m_BatchDrawCallIndex][0]->SetUniformBufferData(0, &projView); m_DebugTextRendererData.m_DescriptorSet[m_DebugTextRendererData.m_BatchDrawCallIndex][0]->Update(); m_DebugTextRendererData.m_TextureCount = 0; @@ -4563,14 +4598,14 @@ namespace Lumos::Graphics TextureDesc textureParams; textureParams.srgb = false; hdri = Texture2D::CreateFromFile("Environment", filePath, textureParams); - descriptorSet->SetTexture("u_Texture", hdri); + descriptorSet->SetTexture(0, hdri); } else { - descriptorSet->SetTexture("u_Texture", Material::GetDefaultTexture()); + descriptorSet->SetTexture(0, Material::GetDefaultTexture()); } - descriptorSet->SetUniform("UniformBuffer", "u_Parameters", (void*)¶ms); + descriptorSet->SetUniformBufferData(1, (void*)¶ms); descriptorSet->Update(commandBuffer); Graphics::PipelineDesc pipelineDesc {}; @@ -4613,7 +4648,7 @@ namespace Lumos::Graphics descriptorDesc.layoutIndex = 0; descriptorDesc.shader = shader.get(); auto descriptorSet = SharedPtr(Graphics::DescriptorSet::Create(descriptorDesc)); - descriptorSet->SetTexture("u_Texture", environmentMap); + descriptorSet->SetTexture(0, environmentMap); descriptorSet->Update(commandBuffer); const float deltaRoughness = 1.0f / Maths::Max((float)environmentMapFiltered->GetMipMapLevels() - 1.0f, 1.0f); @@ -4665,10 +4700,10 @@ namespace Lumos::Graphics descriptorDesc.shader = shader; auto descriptorSet = SharedPtr(Graphics::DescriptorSet::Create(descriptorDesc)); - descriptorSet->SetTexture("u_Texture", environmentMapFiltered); + descriptorSet->SetTexture(0, environmentMapFiltered); uint32_t samples = 512; - descriptorSet->SetUniform("UniformBuffer", "Samples", (void*)&samples); + descriptorSet->SetUniformBufferData(1, (void*)&samples); descriptorSet->Update(commandBuffer); Graphics::PipelineDesc pipelineDesc {}; @@ -4951,7 +4986,7 @@ namespace Lumos::Graphics auto projView = m_Camera->GetProjectionMatrix() * Mat4::Inverse(m_CameraTransform->GetWorldMatrix()); auto cameraPos = m_CameraTransform->GetWorldPosition(); - m_ParticleData.m_DescriptorSet[0][0]->SetUniform("UBO", "projView", &projView); + m_ParticleData.m_DescriptorSet[0][0]->SetUniformBufferData(0, &projView); m_ParticleData.m_DescriptorSet[0][0]->Update(); for(auto& emitterEntity : emitterGroup) @@ -5174,11 +5209,11 @@ namespace Lumos::Graphics } if(m_ParticleData.m_TextureCount > 1) - m_ParticleData.m_DescriptorSet[m_ParticleData.m_BatchDrawCallIndex][1]->SetTexture("textures", m_ParticleData.m_Textures, m_ParticleData.m_TextureCount); + m_ParticleData.m_DescriptorSet[m_ParticleData.m_BatchDrawCallIndex][1]->SetTexture(0, m_ParticleData.m_Textures, m_ParticleData.m_TextureCount); else if(m_ParticleData.m_TextureCount == 0) - m_ParticleData.m_DescriptorSet[m_ParticleData.m_BatchDrawCallIndex][1]->SetTexture("textures", nullptr); + m_ParticleData.m_DescriptorSet[m_ParticleData.m_BatchDrawCallIndex][1]->SetTexture(0, nullptr); else - m_ParticleData.m_DescriptorSet[m_ParticleData.m_BatchDrawCallIndex][1]->SetTexture("textures", m_ParticleData.m_Textures[0]); + m_ParticleData.m_DescriptorSet[m_ParticleData.m_BatchDrawCallIndex][1]->SetTexture(0, m_ParticleData.m_Textures[0]); m_ParticleData.m_DescriptorSet[m_ParticleData.m_BatchDrawCallIndex][1]->Update(); diff --git a/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.cpp b/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.cpp index 113d77a8..fd82526a 100644 --- a/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.cpp +++ b/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.cpp @@ -4,7 +4,9 @@ #define GLFW_EXPOSE_NATIVE_COCOA #endif +#ifdef LUMOS_RENDER_API_OPENGL #include "Platform/OpenGL/GL.h" +#endif #include "GLFWWindow.h" #include "Graphics/RHI/GraphicsContext.h" diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKContext.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKContext.cpp index c62b484b..b811203b 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKContext.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKContext.cpp @@ -21,7 +21,7 @@ #define VK_LAYER_LUNARG_ASSISTENT_LAYER_NAME "VK_LAYER_LUNARG_assistant_layer" #define VK_LAYER_LUNARG_VALIDATION_NAME "VK_LAYER_KHRONOS_validation" -const bool EnableValidationLayers = false; +const bool EnableValidationLayers = true; namespace Lumos { diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.cpp index 4f4d2c78..73c3d84f 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.cpp @@ -18,40 +18,44 @@ namespace Lumos LUMOS_PROFILE_FUNCTION(); m_FramesInFlight = uint32_t(VKRenderer::GetMainSwapChain()->GetSwapChainBufferCount()); - m_Shader = descriptorDesc.shader; - m_Descriptors = m_Shader->GetDescriptorInfo(descriptorDesc.layoutIndex); + m_Shader = descriptorDesc.shader; + DescriptorSetInfo descriptorSetInfo = m_Shader->GetDescriptorInfo(descriptorDesc.layoutIndex); - for(auto& descriptor : m_Descriptors.descriptors) + for (auto& descriptor : descriptorSetInfo.descriptors) { - if(descriptor.type == DescriptorType::UNIFORM_BUFFER) + DescriptorData info; + info.HasUpdated[0] = false; + info.HasUpdated[1] = false; + info.HasUpdated[2] = false; + info.Desc = descriptor; + info.Binding = descriptor.binding; + + if (descriptor.type == DescriptorType::UNIFORM_BUFFER) { - for(uint32_t frame = 0; frame < m_FramesInFlight; frame++) + for (uint32_t frame = 0; frame < m_FramesInFlight; frame++) { // Uniform Buffer per frame in flight auto buffer = SharedPtr(Graphics::UniformBuffer::Create()); buffer->Init(descriptor.size, nullptr); - m_UniformBuffers[frame][descriptor.name] = buffer; + m_UniformBuffers[frame][descriptor.binding] = buffer; } Buffer localStorage; localStorage.Allocate(descriptor.size); localStorage.InitialiseEmpty(); - - UniformBufferInfo info; - info.LocalStorage = localStorage; - info.HasUpdated[0] = false; - info.HasUpdated[1] = false; - info.HasUpdated[2] = false; - info.m_Members = descriptor.m_Members; - m_UniformBuffersData[descriptor.name] = info; + info.LocalStorage = localStorage; + } + info.valid = true; + m_DescriptorData[descriptor.binding] = info; + } - for(uint32_t frame = 0; frame < m_FramesInFlight; frame++) + for (uint32_t frame = 0; frame < m_FramesInFlight; frame++) { - m_DescriptorDirty[frame] = true; + m_DescriptorDirty[frame] = true; m_DescriptorUpdated[frame] = false; - m_DescriptorSet[frame] = nullptr; + m_DescriptorSet[frame] = nullptr; g_DescriptorSetCount++; auto layout = static_cast(descriptorDesc.shader)->GetDescriptorLayout(descriptorDesc.layoutIndex); VKRenderer::GetRenderer()->AllocateDescriptorSet(&m_DescriptorSet[frame], m_DescriptorPoolCreatedFrom[frame], *layout, descriptorDesc.count); @@ -60,25 +64,23 @@ namespace Lumos VKDescriptorSet::~VKDescriptorSet() { - for(uint32_t frame = 0; frame < m_FramesInFlight; frame++) + for (uint32_t frame = 0; frame < m_FramesInFlight; frame++) { - if(!m_DescriptorSet[frame]) + if (!m_DescriptorSet[frame]) continue; - auto descriptorSet = m_DescriptorSet[frame]; - auto pool = m_DescriptorPoolCreatedFrom[frame]; - auto device = VKDevice::GetHandle(); - std::map>& buffers = m_UniformBuffers[frame]; - buffers.clear(); + auto descriptorSet = m_DescriptorSet[frame]; + auto pool = m_DescriptorPoolCreatedFrom[frame]; + auto device = VKDevice::GetHandle(); DeletionQueue& deletionQueue = VKRenderer::GetCurrentDeletionQueue(); deletionQueue.PushFunction([descriptorSet, pool, device] - { vkFreeDescriptorSets(device, pool, 1, &descriptorSet); }); + { vkFreeDescriptorSets(device, pool, 1, &descriptorSet); }); } - for(auto it = m_UniformBuffersData.begin(); it != m_UniformBuffersData.end(); it++) + for (auto bufferData : m_DescriptorData) { - it->second.LocalStorage.Release(); + bufferData.LocalStorage.Release(); } g_DescriptorSetCount -= 3; @@ -96,29 +98,29 @@ namespace Lumos void TransitionImageToCorrectLayout(Texture* texture, CommandBuffer* cmdBuffer) { - if(!texture) + if (!texture) return; auto commandBuffer = cmdBuffer ? cmdBuffer : Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(); - if(texture->GetType() == TextureType::COLOUR) + if (texture->GetType() == TextureType::COLOUR) { - if(((VKTexture2D*)texture)->GetImageLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) + if (((VKTexture2D*)texture)->GetImageLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { ((VKTexture2D*)texture)->TransitionImage(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, (VKCommandBuffer*)commandBuffer); } } - else if(texture->GetType() == TextureType::CUBE) + else if (texture->GetType() == TextureType::CUBE) { - if(((VKTextureCube*)texture)->GetImageLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) + if (((VKTextureCube*)texture)->GetImageLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { ((VKTextureCube*)texture)->TransitionImage(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, (VKCommandBuffer*)commandBuffer); } } - else if(texture->GetType() == TextureType::DEPTH) + else if (texture->GetType() == TextureType::DEPTH) { ((VKTextureDepth*)texture)->TransitionImage(VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, (VKCommandBuffer*)commandBuffer); } - else if(texture->GetType() == TextureType::DEPTHARRAY) + else if (texture->GetType() == TextureType::DEPTHARRAY) { ((VKTextureDepthArray*)texture)->TransitionImage(VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, (VKCommandBuffer*)commandBuffer); } @@ -127,126 +129,125 @@ namespace Lumos void VKDescriptorSet::Update(CommandBuffer* cmdBuffer) { LUMOS_PROFILE_FUNCTION_LOW(); - m_Dynamic = false; + m_Dynamic = false; int descriptorWritesCount = 0; - uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); + uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); - for(auto& bufferInfo : m_UniformBuffersData) + for (auto& bufferInfo : m_DescriptorData) { - if(bufferInfo.second.HasUpdated[currentFrame]) + if (bufferInfo.valid && !bufferInfo.Desc.m_Members.Empty() && bufferInfo.HasUpdated[currentFrame]) { - m_UniformBuffers[currentFrame][bufferInfo.first]->SetData(bufferInfo.second.LocalStorage.Data); - bufferInfo.second.HasUpdated[currentFrame] = false; + m_UniformBuffers[currentFrame][bufferInfo.Binding]->SetData(bufferInfo.LocalStorage.Data); + bufferInfo.HasUpdated[currentFrame] = false; } } - if(m_DescriptorDirty[currentFrame] || !m_DescriptorUpdated[currentFrame]) + if (m_DescriptorDirty[currentFrame] || !m_DescriptorUpdated[currentFrame]) { m_DescriptorDirty[currentFrame] = false; - uint32_t imageIndex = 0; - uint32_t index = 0; + uint32_t imageIndex = 0; + uint32_t index = 0; - const uint32_t descriptorCount = (uint32_t)m_Descriptors.descriptors.Size(); - ArenaTemp scratch = ScratchBegin(nullptr, 0); - VkDescriptorBufferInfo* bufferInfos = PushArrayNoZero(scratch.arena, VkDescriptorBufferInfo, 32); - VkDescriptorImageInfo* imageInfos = PushArrayNoZero(scratch.arena, VkDescriptorImageInfo, 32); + ArenaTemp scratch = ScratchBegin(nullptr, 0); + VkDescriptorBufferInfo* bufferInfos = PushArrayNoZero(scratch.arena, VkDescriptorBufferInfo, 32); + VkDescriptorImageInfo* imageInfos = PushArrayNoZero(scratch.arena, VkDescriptorImageInfo, 32); VkWriteDescriptorSet* writeDescriptorSets = PushArrayNoZero(scratch.arena, VkWriteDescriptorSet, 32); - for(auto& imageInfo : m_Descriptors.descriptors) + for (auto& imageInfo : m_DescriptorData) { - if(imageInfo.type == DescriptorType::IMAGE_SAMPLER && (imageInfo.texture || imageInfo.textures)) + if (imageInfo.valid && imageInfo.Desc.type == DescriptorType::IMAGE_SAMPLER && (imageInfo.Desc.texture || imageInfo.Desc.textures)) { - if(imageInfo.textureCount == 1) + if (imageInfo.Desc.textureCount == 1) { - if(imageInfo.texture) + if (imageInfo.Desc.texture) { - TransitionImageToCorrectLayout(imageInfo.texture, cmdBuffer); + TransitionImageToCorrectLayout(imageInfo.Desc.texture, cmdBuffer); - VkDescriptorImageInfo& des = *static_cast(imageInfo.texture->GetDescriptorInfo()); + VkDescriptorImageInfo& des = *static_cast(imageInfo.Desc.texture->GetDescriptorInfo()); imageInfos[imageIndex].imageLayout = des.imageLayout; - imageInfos[imageIndex].imageView = des.imageView; - imageInfos[imageIndex].sampler = des.sampler; + imageInfos[imageIndex].imageView = des.imageView; + imageInfos[imageIndex].sampler = des.sampler; } } else { - if(imageInfo.textures) + if (imageInfo.Desc.textures) { - for(uint32_t i = 0; i < imageInfo.textureCount; i++) + for (uint32_t i = 0; i < imageInfo.Desc.textureCount; i++) { - TransitionImageToCorrectLayout(imageInfo.textures[i], cmdBuffer); + TransitionImageToCorrectLayout(imageInfo.Desc.textures[i], cmdBuffer); - VkDescriptorImageInfo& des = *static_cast(imageInfo.textures[i]->GetDescriptorInfo()); + VkDescriptorImageInfo& des = *static_cast(imageInfo.Desc.textures[i]->GetDescriptorInfo()); imageInfos[i + imageIndex].imageLayout = des.imageLayout; - imageInfos[i + imageIndex].imageView = des.imageView; - imageInfos[i + imageIndex].sampler = des.sampler; + imageInfos[i + imageIndex].imageView = des.imageView; + imageInfos[i + imageIndex].sampler = des.sampler; } } } VkWriteDescriptorSet writeDescriptorSet = {}; - writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - writeDescriptorSet.dstSet = m_DescriptorSet[currentFrame]; - writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - writeDescriptorSet.dstBinding = imageInfo.binding; - writeDescriptorSet.pImageInfo = &imageInfos[imageIndex]; - writeDescriptorSet.descriptorCount = imageInfo.textureCount; + writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + writeDescriptorSet.dstSet = m_DescriptorSet[currentFrame]; + writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + writeDescriptorSet.dstBinding = imageInfo.Desc.binding; + writeDescriptorSet.pImageInfo = &imageInfos[imageIndex]; + writeDescriptorSet.descriptorCount = imageInfo.Desc.textureCount; writeDescriptorSets[descriptorWritesCount] = writeDescriptorSet; imageIndex++; descriptorWritesCount++; } - else if(imageInfo.type == DescriptorType::IMAGE_STORAGE && imageInfo.texture) + else if (imageInfo.Desc.type == DescriptorType::IMAGE_STORAGE && imageInfo.Desc.texture) { - if(imageInfo.texture) + if (imageInfo.Desc.texture) { - ((VKTexture2D*)imageInfo.texture)->TransitionImage(VK_IMAGE_LAYOUT_GENERAL); + ((VKTexture2D*)imageInfo.Desc.texture)->TransitionImage(VK_IMAGE_LAYOUT_GENERAL); - VkDescriptorImageInfo& des = *static_cast(imageInfo.texture->GetDescriptorInfo()); + VkDescriptorImageInfo& des = *static_cast(imageInfo.Desc.texture->GetDescriptorInfo()); imageInfos[imageIndex].imageLayout = des.imageLayout; - imageInfos[imageIndex].imageView = imageInfo.mipLevel > 0 ? ((VKTexture2D*)imageInfo.texture)->GetMipImageView(imageInfo.mipLevel) : des.imageView; - imageInfos[imageIndex].sampler = des.sampler; + imageInfos[imageIndex].imageView = imageInfo.Desc.mipLevel > 0 ? ((VKTexture2D*)imageInfo.Desc.texture)->GetMipImageView(imageInfo.Desc.mipLevel) : des.imageView; + imageInfos[imageIndex].sampler = des.sampler; } VkWriteDescriptorSet writeDescriptorSet = {}; - writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - writeDescriptorSet.dstSet = m_DescriptorSet[currentFrame]; - writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; - writeDescriptorSet.dstBinding = imageInfo.binding; - writeDescriptorSet.pImageInfo = &imageInfos[imageIndex]; - writeDescriptorSet.descriptorCount = imageInfo.textureCount; + writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + writeDescriptorSet.dstSet = m_DescriptorSet[currentFrame]; + writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + writeDescriptorSet.dstBinding = imageInfo.Desc.binding; + writeDescriptorSet.pImageInfo = &imageInfos[imageIndex]; + writeDescriptorSet.descriptorCount = imageInfo.Desc.textureCount; writeDescriptorSets[descriptorWritesCount] = writeDescriptorSet; imageIndex++; descriptorWritesCount++; } - else if(imageInfo.type == DescriptorType::UNIFORM_BUFFER) + else if (imageInfo.Desc.type == DescriptorType::UNIFORM_BUFFER) { - VKUniformBuffer* vkUniformBuffer = m_UniformBuffers[currentFrame][imageInfo.name].As().get(); - bufferInfos[index].buffer = *vkUniformBuffer->GetBuffer(); - bufferInfos[index].offset = imageInfo.offset; - bufferInfos[index].range = imageInfo.size; + VKUniformBuffer* vkUniformBuffer = m_UniformBuffers[currentFrame][imageInfo.Desc.binding].As().get(); + bufferInfos[index].buffer = *vkUniformBuffer->GetBuffer(); + bufferInfos[index].offset = imageInfo.Desc.offset; + bufferInfos[index].range = imageInfo.Desc.size; VkWriteDescriptorSet writeDescriptorSet = {}; - writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - writeDescriptorSet.dstSet = m_DescriptorSet[currentFrame]; - writeDescriptorSet.descriptorType = VKUtilities::DescriptorTypeToVK(imageInfo.type); - writeDescriptorSet.dstBinding = imageInfo.binding; - writeDescriptorSet.pBufferInfo = &bufferInfos[index]; - writeDescriptorSet.descriptorCount = 1; + writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + writeDescriptorSet.dstSet = m_DescriptorSet[currentFrame]; + writeDescriptorSet.descriptorType = VKUtilities::DescriptorTypeToVK(imageInfo.Desc.type); + writeDescriptorSet.dstBinding = imageInfo.Desc.binding; + writeDescriptorSet.pBufferInfo = &bufferInfos[index]; + writeDescriptorSet.descriptorCount = 1; writeDescriptorSets[descriptorWritesCount] = writeDescriptorSet; index++; descriptorWritesCount++; - if(imageInfo.type == DescriptorType::UNIFORM_BUFFER_DYNAMIC) + if (imageInfo.Desc.type == DescriptorType::UNIFORM_BUFFER_DYNAMIC) m_Dynamic = true; } } vkUpdateDescriptorSets(VKDevice::Get().GetDevice(), descriptorWritesCount, - writeDescriptorSets, 0, nullptr); + writeDescriptorSets, 0, nullptr); ScratchEnd(scratch); m_DescriptorUpdated[currentFrame] = true; @@ -255,18 +256,18 @@ namespace Lumos void VKDescriptorSet::TransitionImages(CommandBuffer* commandBuffer) { - for(auto& imageInfo : m_Descriptors.descriptors) + for (auto& imageInfo : m_DescriptorData) { - if((imageInfo.type == DescriptorType::IMAGE_SAMPLER || imageInfo.type == DescriptorType::IMAGE_STORAGE) && (imageInfo.texture || imageInfo.textures)) + if (imageInfo.valid && (imageInfo.Desc.type == DescriptorType::IMAGE_SAMPLER || imageInfo.Desc.type == DescriptorType::IMAGE_STORAGE) && (imageInfo.Desc.texture || imageInfo.Desc.textures)) { - if(imageInfo.textureCount == 1) + if (imageInfo.Desc.textureCount == 1) { - if(imageInfo.texture) + if (imageInfo.Desc.texture) { - if(imageInfo.type == DescriptorType::IMAGE_STORAGE) - ((VKTexture2D*)imageInfo.texture)->TransitionImage(VK_IMAGE_LAYOUT_GENERAL, (VKCommandBuffer*)commandBuffer); + if (imageInfo.Desc.type == DescriptorType::IMAGE_STORAGE) + ((VKTexture2D*)imageInfo.Desc.texture)->TransitionImage(VK_IMAGE_LAYOUT_GENERAL, (VKCommandBuffer*)commandBuffer); else - TransitionImageToCorrectLayout(imageInfo.texture, commandBuffer); + TransitionImageToCorrectLayout(imageInfo.Desc.texture, commandBuffer); } } } @@ -277,14 +278,14 @@ namespace Lumos { LUMOS_PROFILE_FUNCTION(); - for(auto& descriptor : m_Descriptors.descriptors) + for (auto& descriptor : m_DescriptorData) { - if((descriptor.type == DescriptorType::IMAGE_SAMPLER || descriptor.type == DescriptorType::IMAGE_STORAGE) && descriptor.name == name) + if (descriptor.valid && (descriptor.Desc.type == DescriptorType::IMAGE_SAMPLER || descriptor.Desc.type == DescriptorType::IMAGE_STORAGE) && descriptor.Desc.name == name) { - descriptor.texture = texture; - descriptor.textureType = textureType; - descriptor.textureCount = texture ? 1 : 0; - descriptor.mipLevel = mipIndex; + descriptor.Desc.texture = texture; + descriptor.Desc.textureType = textureType; + descriptor.Desc.textureCount = texture ? 1 : 0; + descriptor.Desc.mipLevel = mipIndex; m_DescriptorDirty[0] = true; m_DescriptorDirty[1] = true; @@ -297,13 +298,13 @@ namespace Lumos { LUMOS_PROFILE_FUNCTION(); - for(auto& descriptor : m_Descriptors.descriptors) + for (auto& descriptor : m_DescriptorData) { - if((descriptor.type == DescriptorType::IMAGE_SAMPLER || descriptor.type == DescriptorType::IMAGE_STORAGE) && descriptor.name == name) + if (descriptor.valid && (descriptor.Desc.type == DescriptorType::IMAGE_SAMPLER || descriptor.Desc.type == DescriptorType::IMAGE_STORAGE) && descriptor.Desc.name == name) { - descriptor.textureCount = textureCount; - descriptor.textures = texture; - descriptor.textureType = textureType; + descriptor.Desc.textureCount = textureCount; + descriptor.Desc.textures = texture; + descriptor.Desc.textureType = textureType; m_DescriptorDirty[0] = true; m_DescriptorDirty[1] = true; @@ -317,9 +318,9 @@ namespace Lumos LUMOS_PROFILE_FUNCTION(); uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); #if 0 - for(auto& descriptor : m_Descriptors[currentFrame].descriptors) + for (auto& descriptor : m_Descriptors[currentFrame].descriptors) { - if(descriptor.type == DescriptorType::UNIFORM_BUFFER && descriptor.name == name) + if (descriptor.type == DescriptorType::UNIFORM_BUFFER && descriptor.name == name) { descriptor.buffer = buffer; } @@ -329,14 +330,23 @@ namespace Lumos Buffer* VKDescriptorSet::GetUniformBufferLocalData(const std::string& name) { - std::map::iterator itr = m_UniformBuffersData.find(name); - if(itr != m_UniformBuffersData.end()) + LUMOS_PROFILE_FUNCTION(); + + DescriptorData* lBufferInfo = nullptr; + for (u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) { - itr->second.HasUpdated[0] = true; - itr->second.HasUpdated[1] = true; - itr->second.HasUpdated[2] = true; + if (!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == name) + { + lBufferInfo = &m_DescriptorData[i]; + } + } + if (lBufferInfo) + { + lBufferInfo->HasUpdated[0] = true; + lBufferInfo->HasUpdated[1] = true; + lBufferInfo->HasUpdated[2] = true; - return &itr->second.LocalStorage; + return &lBufferInfo->LocalStorage; } return nullptr; @@ -362,18 +372,24 @@ namespace Lumos void VKDescriptorSet::SetUniform(const std::string& bufferName, const std::string& uniformName, void* data) { LUMOS_PROFILE_FUNCTION(); - std::map::iterator itr = m_UniformBuffersData.find(bufferName); - if(itr != m_UniformBuffersData.end()) + DescriptorData* lBufferInfo = nullptr; + for (u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) { - for(auto& member : itr->second.m_Members) + if (!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == bufferName) { - if(member.name == uniformName) + lBufferInfo = &m_DescriptorData[i]; + } + } + if (lBufferInfo) + { + for (auto& member : lBufferInfo->Desc.m_Members) + { + if (member.name == uniformName) { - itr->second.LocalStorage.Write(data, member.size, member.offset); - - itr->second.HasUpdated[0] = true; - itr->second.HasUpdated[1] = true; - itr->second.HasUpdated[2] = true; + lBufferInfo->LocalStorage.Write(data, member.size, member.offset); + lBufferInfo->HasUpdated[0] = true; + lBufferInfo->HasUpdated[1] = true; + lBufferInfo->HasUpdated[2] = true; return; } } @@ -386,17 +402,24 @@ namespace Lumos { LUMOS_PROFILE_FUNCTION(); - std::map::iterator itr = m_UniformBuffersData.find(bufferName); - if(itr != m_UniformBuffersData.end()) + DescriptorData* lBufferInfo = nullptr; + for (u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) { - for(auto& member : itr->second.m_Members) + if (!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == bufferName) { - if(member.name == uniformName) + lBufferInfo = &m_DescriptorData[i]; + } + } + if (lBufferInfo) + { + for (auto& member : lBufferInfo->Desc.m_Members) + { + if (member.name == uniformName) { - itr->second.LocalStorage.Write(data, size, member.offset); - itr->second.HasUpdated[0] = true; - itr->second.HasUpdated[1] = true; - itr->second.HasUpdated[2] = true; + lBufferInfo->LocalStorage.Write(data, size, member.offset); + lBufferInfo->HasUpdated[0] = true; + lBufferInfo->HasUpdated[1] = true; + lBufferInfo->HasUpdated[2] = true; return; } } @@ -409,13 +432,20 @@ namespace Lumos { LUMOS_PROFILE_FUNCTION(); - std::map::iterator itr = m_UniformBuffersData.find(bufferName); - if(itr != m_UniformBuffersData.end()) + DescriptorData* lBufferInfo = nullptr; + for (u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) + { + if (!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == bufferName) + { + lBufferInfo = &m_DescriptorData[i]; + } + } + if (lBufferInfo) { - itr->second.LocalStorage.Write(data, itr->second.LocalStorage.GetSize(), 0); - itr->second.HasUpdated[0] = true; - itr->second.HasUpdated[1] = true; - itr->second.HasUpdated[2] = true; + lBufferInfo->LocalStorage.Write(data, lBufferInfo->LocalStorage.GetSize(), 0); + lBufferInfo->HasUpdated[0] = true; + lBufferInfo->HasUpdated[1] = true; + lBufferInfo->HasUpdated[2] = true; return; } @@ -424,15 +454,178 @@ namespace Lumos void VKDescriptorSet::SetUniformDynamic(const std::string& bufferName, uint32_t size) { - std::map::iterator itr = m_UniformBuffersData.find(bufferName); - if(itr != m_UniformBuffersData.end()) + DescriptorData* lBufferInfo = nullptr; + for (u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) { - itr->second.LocalStorage.Allocate(size); - for(auto& member : itr->second.m_Members) + if (!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == bufferName) + { + lBufferInfo = &m_DescriptorData[i]; + } + } + + if (lBufferInfo) + { + lBufferInfo->LocalStorage.Allocate(size); + for (auto& member : lBufferInfo->Desc.m_Members) { member.size = size; } } } + + void VKDescriptorSet::SetTexture(u8 binding, Texture* texture, uint32_t mipIndex, TextureType textureType) + { + LUMOS_PROFILE_FUNCTION(); + auto& descriptor = m_DescriptorData[binding]; + if ((descriptor.Desc.type == DescriptorType::IMAGE_SAMPLER || descriptor.Desc.type == DescriptorType::IMAGE_STORAGE) && texture) + { + descriptor.Desc.texture = texture; + descriptor.Desc.textureType = textureType; + descriptor.Desc.textureCount = texture ? 1 : 0; + descriptor.Desc.mipLevel = mipIndex; + + m_DescriptorDirty[0] = true; + m_DescriptorDirty[1] = true; + m_DescriptorDirty[2] = true; + } + + } + + void VKDescriptorSet::SetTexture(u8 binding, Texture** texture, uint32_t textureCount, TextureType textureType) + { + LUMOS_PROFILE_FUNCTION(); + auto& descriptor = m_DescriptorData[binding]; + if ((descriptor.Desc.type == DescriptorType::IMAGE_SAMPLER || descriptor.Desc.type == DescriptorType::IMAGE_STORAGE) && texture) + { + descriptor.Desc.textureCount = textureCount; + descriptor.Desc.textures = texture; + descriptor.Desc.textureType = textureType; + + m_DescriptorDirty[0] = true; + m_DescriptorDirty[1] = true; + m_DescriptorDirty[2] = true; + } + } + + void VKDescriptorSet::SetBuffer(u8 binding, UniformBuffer* buffer) + { + LUMOS_PROFILE_FUNCTION(); + uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); + m_DescriptorData[binding].Desc.buffer = buffer; + LWARN("Check"); + } + + Buffer* VKDescriptorSet::GetUniformBufferLocalData(u8 binding) + { + LUMOS_PROFILE_FUNCTION(); + DescriptorData* lBufferInfo = &m_DescriptorData[binding]; + if (lBufferInfo) + { + lBufferInfo->HasUpdated[0] = true; + lBufferInfo->HasUpdated[1] = true; + lBufferInfo->HasUpdated[2] = true; + + return &lBufferInfo->LocalStorage; + } + + return nullptr; + } + + Graphics::UniformBuffer* VKDescriptorSet::GetUniformBuffer(u8 binding) + { + LUMOS_PROFILE_FUNCTION(); + uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); + + // for(auto& buffers : m_UniformBuffers[currentFrame]) + //{ + // if(descriptor.type == DescriptorType::UNIFORM_BUFFER && descriptor.name == name) + //{ + // return descriptor.buffer; + // } + // } + + LWARN("Buffer not found %d", int(binding)); + return nullptr; + } + + void VKDescriptorSet::SetUniform(u8 binding, const std::string& uniformName, void* data) + { + LUMOS_PROFILE_FUNCTION(); + DescriptorData* lBufferInfo = &m_DescriptorData[binding]; + if (lBufferInfo) + { + for (auto& member : lBufferInfo->Desc.m_Members) + { + if (member.name == uniformName) + { + lBufferInfo->LocalStorage.Write(data, member.size, member.offset); + lBufferInfo->HasUpdated[0] = true; + lBufferInfo->HasUpdated[1] = true; + lBufferInfo->HasUpdated[2] = true; + return; + } + } + } + + LWARN("Uniform not found %d.%s", int(binding), uniformName.c_str()); + } + + void VKDescriptorSet::SetUniform(u8 binding, const std::string& uniformName, void* data, uint32_t size) + { + LUMOS_PROFILE_FUNCTION(); + + DescriptorData* lBufferInfo = &m_DescriptorData[binding]; + if (lBufferInfo) + { + for (auto& member : lBufferInfo->Desc.m_Members) + { + if (member.name == uniformName) + { + lBufferInfo->LocalStorage.Write(data, size, member.offset); + lBufferInfo->HasUpdated[0] = true; + lBufferInfo->HasUpdated[1] = true; + lBufferInfo->HasUpdated[2] = true; + return; + } + } + } + + LWARN("Uniform not found %d.%s",int(binding), uniformName.c_str()); + } + + void VKDescriptorSet::SetUniformBufferData(u8 binding, void* data) + { + LUMOS_PROFILE_FUNCTION(); + + DescriptorData* lBufferInfo = &m_DescriptorData[binding]; + if (lBufferInfo) + { + lBufferInfo->LocalStorage.Write(data, lBufferInfo->LocalStorage.GetSize(), 0); + lBufferInfo->HasUpdated[0] = true; + lBufferInfo->HasUpdated[1] = true; + lBufferInfo->HasUpdated[2] = true; + return; + } + + LWARN("Uniform not found %d", int(binding)); + } + + void VKDescriptorSet::SetUniformBufferData(u8 binding, void* data, float size) + { + LUMOS_PROFILE_FUNCTION(); + + DescriptorData* lBufferInfo = &m_DescriptorData[binding]; + if (lBufferInfo) + { + ASSERT(size <= lBufferInfo->LocalStorage.GetSize()); + lBufferInfo->LocalStorage.Write(data, size, 0); + lBufferInfo->HasUpdated[0] = true; + lBufferInfo->HasUpdated[1] = true; + lBufferInfo->HasUpdated[2] = true; + return; + } + + LWARN("Uniform not found %d", int(binding)); + } } } diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.h b/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.h index 3b73be16..07a2a440 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.h +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.h @@ -11,15 +11,16 @@ namespace Lumos { class VKDescriptorSet : public DescriptorSet { - public: + public: VKDescriptorSet(const DescriptorDesc& descriptorDesc); ~VKDescriptorSet(); - + VkDescriptorSet GetDescriptorSet() { uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); return m_DescriptorSet[currentFrame]; } + //Slow void Update(CommandBuffer* cmdBuffer) override; void SetTexture(const std::string& name, Texture* texture, uint32_t mipIndex, TextureType textureType) override; void SetTexture(const std::string& name, Texture** texture, uint32_t textureCount, TextureType textureType) override; @@ -27,44 +28,57 @@ namespace Lumos void SetUniform(const std::string& bufferName, const std::string& uniformName, void* data) override; void SetUniform(const std::string& bufferName, const std::string& uniformName, void* data, uint32_t size) override; void SetUniformBufferData(const std::string& bufferName, void* data) override; - void TransitionImages(CommandBuffer* commandBuffer) override; + void SetTexture(u8 binding, Texture* texture, uint32_t mipIndex, TextureType textureType) override; + void SetTexture(u8 binding, Texture** texture, uint32_t textureCount, TextureType textureType) override; + void SetBuffer(u8 binding, UniformBuffer* buffer) override; + void SetUniform(u8 binding, const std::string& uniformName, void* data) override; + void SetUniform(u8 binding, const std::string& uniformName, void* data, uint32_t size) override; + void SetUniformBufferData(u8 binding, void* data) override; + void SetUniformBufferData(u8 binding, void* data, float size) override; + + void TransitionImages(CommandBuffer* commandBuffer) override; + Buffer* GetUniformBufferLocalData(const std::string& name) override; Graphics::UniformBuffer* GetUniformBuffer(const std::string& name) override; - bool GetIsDynamic() const { return m_Dynamic; } + Buffer* GetUniformBufferLocalData(u8 binding) override; + Graphics::UniformBuffer* GetUniformBuffer(u8 binding) override; + + bool GetIsDynamic() const { return m_Dynamic; } + void SetDynamicOffset(uint32_t offset) override { m_DynamicOffset = offset; } uint32_t GetDynamicOffset() const override { return m_DynamicOffset; } bool GetHasUpdated(uint32_t frame) { return m_DescriptorUpdated[frame]; } void SetUniformDynamic(const std::string& bufferName, uint32_t size) override; - + static void MakeDefault(); - - protected: + + protected: void UpdateInternal(TDArray* imageInfos); - + static DescriptorSet* CreateFuncVulkan(const DescriptorDesc&); - - private: + + private: uint32_t m_DynamicOffset = 0; Shader* m_Shader = nullptr; bool m_Dynamic = false; - + uint32_t m_FramesInFlight = 0; - - struct UniformBufferInfo + + struct DescriptorData { - TDArray m_Members; + Descriptor Desc; Buffer LocalStorage; - + u8 Binding; + bool valid = false; // Per frame in flight bool HasUpdated[MAX_FRAMES_FLIGHT]; }; + + DescriptorData m_DescriptorData[DESCRIPTOR_MAX_DESCRIPTORS]; + SharedPtr m_UniformBuffers[MAX_FRAMES_FLIGHT][DESCRIPTOR_MAX_DESCRIPTORS]; - DescriptorSetInfo m_Descriptors; - std::map m_UniformBuffersData; - - std::map> m_UniformBuffers[MAX_FRAMES_FLIGHT]; VkDescriptorSet m_DescriptorSet[MAX_FRAMES_FLIGHT]; VkDescriptorPool m_DescriptorPoolCreatedFrom[MAX_FRAMES_FLIGHT]; bool m_DescriptorDirty[MAX_FRAMES_FLIGHT]; diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.cpp index a9f8d74d..def77fc0 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.cpp @@ -189,8 +189,10 @@ namespace Lumos void VKIMGUIRenderer::NewFrame() { - vkResetDescriptorPool(VKDevice::Get().GetDevice(), g_DescriptorPool[Renderer::GetMainSwapChain()->GetCurrentImageIndex()], 0); - ImGui_ImplVulkan_ClearDescriptors(Renderer::GetMainSwapChain()->GetCurrentImageIndex()); + u32 currentImageIndex = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); + + vkResetDescriptorPool(VKDevice::Get().GetDevice(), g_DescriptorPool[currentImageIndex], 0); + ImGui_ImplVulkan_ClearDescriptors(currentImageIndex); m_CurrentTextureIDIndex = 0; } @@ -246,7 +248,7 @@ namespace Lumos } } - ImGui_ImplVulkan_CreateDescriptorSets(ImGui::GetDrawData(), wd->FrameIndex); + ImGui_ImplVulkan_CreateDescriptorSets(ImGui::GetDrawData(), VKRenderer::GetMainSwapChain()->GetCurrentBufferIndex()); float clearColour[4] = { 0.1f, 0.1f, 0.1f, 1.0f }; m_Renderpass->BeginRenderPass(currentCommandBuffer, clearColour, m_Framebuffers[wd->FrameIndex], Graphics::SubPassContents::INLINE, wd->Width, wd->Height); @@ -254,7 +256,7 @@ namespace Lumos { LUMOS_PROFILE_SCOPE("ImGui Vulkan RenderDrawData"); // Record Imgui Draw Data and draw funcs into command buffer - ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), currentCommandBuffer->GetHandle(), VK_NULL_HANDLE, wd->FrameIndex); + ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), currentCommandBuffer->GetHandle(), VK_NULL_HANDLE, wd->FrameIndex, VKRenderer::GetMainSwapChain()->GetCurrentBufferIndex()); } m_Renderpass->EndRenderPass(currentCommandBuffer); } diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKShader.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKShader.cpp index 1f7e0b72..44fb2e59 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKShader.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKShader.cpp @@ -14,6 +14,8 @@ #include "Utilities/StringUtilities.h" #include "Maths/Vector3.h" #include "Maths/IVector4.h" +#include "Core/Algorithms/Sort.h" + #include #define SHADER_LOG_ENABLED 0 @@ -665,7 +667,7 @@ namespace Lumos member.offset = offset; member.size = (uint32_t)size; - SHADER_LOG(LINFO("%s - Size %i, offset %i", uniformName, size, offset)); + SHADER_LOG(LINFO("%s - Size %i, offset %i", uniformName.c_str(), size, offset)); } } @@ -770,6 +772,20 @@ namespace Lumos m_Compiled = true; } + for (auto& infos : m_DescriptorInfos) + { + Algorithms::BubbleSort(infos.second.descriptors.begin(), infos.second.descriptors.end(), + [](Descriptor& a, Descriptor& b) + { + return a.binding < b.binding; + }); + + /* infos.second.descriptors.Unique([](Descriptor& a, Descriptor& b) + { + return a.binding == b.binding; + });*/ + } + VK_CHECK_RESULT(result); } diff --git a/Lumos/Source/Lumos/Scene/Scene.cpp b/Lumos/Source/Lumos/Scene/Scene.cpp index 7daad330..77f08f46 100644 --- a/Lumos/Source/Lumos/Scene/Scene.cpp +++ b/Lumos/Source/Lumos/Scene/Scene.cpp @@ -449,6 +449,8 @@ namespace Lumos input(*this); if(m_SceneSerialisationVersion == 0) LERROR("Invalid Scene Version"); + else if (m_SceneSerialisationVersion < MIN_SCENE_VERSION) + LERROR("Invalid Scene Version - Version too low %d. Minimum version supported %d", m_SceneSerialisationVersion, MIN_SCENE_VERSION); #if MIN_SCENE_VERSION <= 2 else if(m_SceneSerialisationVersion < 2) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input).orphans(); @@ -543,9 +545,11 @@ namespace Lumos input(*this); if(m_SceneSerialisationVersion == 0) - LERROR("Invalid Scene Version"); + LERROR("Invalid Scene Version - Invalid Scene Version"); + else if (m_SceneSerialisationVersion < MIN_SCENE_VERSION) + LERROR("Invalid Scene Version - Version too low %d. Minimum version supported %d", m_SceneSerialisationVersion, MIN_SCENE_VERSION); #if MIN_SCENE_VERSION <= 2 - if(m_SceneSerialisationVersion < 2) + else if(m_SceneSerialisationVersion < 2) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input).orphans(); #endif #if MIN_SCENE_VERSION <= 3 diff --git a/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.h b/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.h index 190f14a6..e6397418 100644 --- a/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.h +++ b/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.h @@ -209,16 +209,21 @@ namespace Lumos static const int AssetRegistrySerialisationVersion = 2; template void save(Archive& archive, const AssetRegistry& registry) - { - std::vector> elems(registry.m_NameMap.begin(), registry.m_NameMap.end()); - std::sort(elems.begin(), elems.end(), [](std::pair& a, std::pair& b) - { return a.second < b.second; }); + { + std::vector> elems(registry.m_NameMap.begin(), registry.m_NameMap.end()); + + elems.erase(std::remove_if(elems.begin(), elems.end(), [](std::pair& a) { + return StringUtilities::StringContains(a.first, std::string("Cache/")); + }), elems.end()); + + std::sort(elems.begin(), elems.end(), [](std::pair& a, std::pair& b) + { return a.second < b.second; }); - archive(cereal::make_nvp("Version", AssetRegistrySerialisationVersion)); - archive(cereal::make_nvp("Count", (int)elems.size())); + archive(cereal::make_nvp("Version", AssetRegistrySerialisationVersion)); + archive(cereal::make_nvp("Count", (int)elems.size())); - for(auto& entry : elems) - archive(cereal::make_nvp("Name", entry.first), cereal::make_nvp("UUID", (uint64_t)entry.second), cereal::make_nvp("AssetType", registry.Contains(entry.second) ? (uint16_t)registry.Get(entry.second).Type : 0)); + for(auto& entry : elems) + archive(cereal::make_nvp("Name", entry.first), cereal::make_nvp("UUID", (uint64_t)entry.second), cereal::make_nvp("AssetType", registry.Contains(entry.second) ? (uint16_t)registry.Get(entry.second).Type : 0)); } template diff --git a/Lumos/Source/Lumos/Scripting/Lua/LuaManager.cpp b/Lumos/Source/Lumos/Scripting/Lua/LuaManager.cpp index e76eca19..09535e9d 100644 --- a/Lumos/Source/Lumos/Scripting/Lua/LuaManager.cpp +++ b/Lumos/Source/Lumos/Scripting/Lua/LuaManager.cpp @@ -11,6 +11,7 @@ #include "LuaScriptComponent.h" #include "Scene/SceneGraph.h" #include "Graphics/Camera/ThirdPersonCamera.h" +#include "Graphics/UI.h" #include "Scene/Component/Components.h" #include "Graphics/Camera/Camera.h" @@ -232,6 +233,9 @@ namespace Lumos BindLogLua(*m_State); BindSceneLua(*m_State); BindPhysicsLua(*m_State); + BindUILua(*m_State); + + LINFO("Initialised Lua Manager"); } LuaManager::~LuaManager() @@ -761,4 +765,130 @@ namespace Lumos app_type.set_function("GetWindowSize", &Application::GetWindowSize); state.set_function("GetAppInstance", &Application::Get); } + + void LuaManager::BindUILua(sol::state& lua) + { + // Enums + lua.new_enum("WidgetFlags", + "Clickable", Lumos::WidgetFlags_Clickable, + "DrawText", Lumos::WidgetFlags_DrawText, + "DrawBorder", Lumos::WidgetFlags_DrawBorder, + "DrawBackground", Lumos::WidgetFlags_DrawBackground, + "Draggable", Lumos::WidgetFlags_Draggable, + "StackVertically", Lumos::WidgetFlags_StackVertically, + "StackHorizontally", Lumos::WidgetFlags_StackHorizontally, + "Floating_X", Lumos::WidgetFlags_Floating_X, + "Floating_Y", Lumos::WidgetFlags_Floating_Y, + "CentreX", Lumos::WidgetFlags_CentreX, + "CentreY", Lumos::WidgetFlags_CentreY + ); + + lua.new_enum("UITextAlignment", + "None", Lumos::UI_Text_Alignment_None, + "Center_X", Lumos::UI_Text_Alignment_Center_X, + "Center_Y", Lumos::UI_Text_Alignment_Center_Y + ); + + lua.new_enum("SizeKind", + "Pixels", Lumos::SizeKind_Pixels, + "TextContent", Lumos::SizeKind_TextContent, + "PercentOfParent", Lumos::SizeKind_PercentOfParent, + "ChildSum", Lumos::SizeKind_ChildSum, + "MaxChild", Lumos::SizeKind_MaxChild + ); + + lua.new_enum("UIAxis", + "X", Lumos::UIAxis_X, + "Y", Lumos::UIAxis_Y, + "Count", Lumos::UIAxis_Count + ); + + lua.new_enum("StyleVar", + "Padding", Lumos::StyleVar_Padding, + "Border", Lumos::StyleVar_Border, + "BorderColor", Lumos::StyleVar_BorderColor, + "BackgroundColor", Lumos::StyleVar_BackgroundColor, + "TextColor", Lumos::StyleVar_TextColor, + "HotBorderColor", Lumos::StyleVar_HotBorderColor, + "HotBackgroundColor", Lumos::StyleVar_HotBackgroundColor, + "HotTextColor", Lumos::StyleVar_HotTextColor, + "ActiveBorderColor", Lumos::StyleVar_ActiveBorderColor, + "ActiveBackgroundColor", Lumos::StyleVar_ActiveBackgroundColor, + "ActiveTextColor", Lumos::StyleVar_ActiveTextColor, + "FontSize", Lumos::StyleVar_FontSize, + "Count", Lumos::StyleVar_Count + ); + + // Structs + lua.new_usertype("UI_Size", + sol::constructors(), + "kind", &Lumos::UI_Size::kind, + "value", &Lumos::UI_Size::value + ); + + lua.new_usertype("UI_Widget", + "parent", &Lumos::UI_Widget::parent, + "first", &Lumos::UI_Widget::first, + "last", &Lumos::UI_Widget::last, + "next", &Lumos::UI_Widget::next, + "prev", &Lumos::UI_Widget::prev, + "style_vars", &Lumos::UI_Widget::style_vars, + "hash", &Lumos::UI_Widget::hash, + "flags", &Lumos::UI_Widget::flags, + "text", &Lumos::UI_Widget::text, + "texture", &Lumos::UI_Widget::texture, + "semantic_size", &Lumos::UI_Widget::semantic_size, + "LayoutingAxis", &Lumos::UI_Widget::LayoutingAxis, + "TextAlignment", &Lumos::UI_Widget::TextAlignment, + "cursor", &Lumos::UI_Widget::cursor, + "position", &Lumos::UI_Widget::position, + "relative_position", &Lumos::UI_Widget::relative_position, + "size", &Lumos::UI_Widget::size, + "clicked", &Lumos::UI_Widget::clicked, + "is_initial_dragging_position_set", &Lumos::UI_Widget::is_initial_dragging_position_set, + "dragging", &Lumos::UI_Widget::dragging, + "drag_constraint_x", &Lumos::UI_Widget::drag_constraint_x, + "drag_constraint_y", &Lumos::UI_Widget::drag_constraint_y, + "drag_offset", &Lumos::UI_Widget::drag_offset, + "drag_mouse_p", &Lumos::UI_Widget::drag_mouse_p, + "HotTransition", &Lumos::UI_Widget::HotTransition, + "ActiveTransition", &Lumos::UI_Widget::ActiveTransition, + "LastFrameIndexActive", &Lumos::UI_Widget::LastFrameIndexActive + ); + + lua.new_usertype("UI_Interaction", + "widget", &Lumos::UI_Interaction::widget, + "hovering", &Lumos::UI_Interaction::hovering, + "clicked", &Lumos::UI_Interaction::clicked, + "dragging", &Lumos::UI_Interaction::dragging + ); + + // Functions + lua["GetUIState"] = &Lumos::GetUIState; + lua["GetStringSize"] = &Lumos::GetStringSize; + lua["InitialiseUI"] = &Lumos::InitialiseUI; + lua["ShutDownUI"] = &Lumos::ShutDownUI; + lua["UIBeginFrame"] = &Lumos::UIBeginFrame; + lua["UIEndFrame"] = &Lumos::UIEndFrame; + lua["UIBeginPanel"] = sol::overload( + static_cast(&Lumos::UIBeginPanel), + static_cast(&Lumos::UIBeginPanel) + ); + lua["UIEndPanel"] = &Lumos::UIEndPanel; + lua["UIPushStyle"] = sol::overload( + static_cast(&Lumos::UIPushStyle), + static_cast(&Lumos::UIPushStyle), + static_cast(&Lumos::UIPushStyle), + static_cast(&Lumos::UIPushStyle) + ); + + lua["UIPopStyle"] = &Lumos::UIPopStyle; + lua["UILabel"] = &Lumos::UILabel; + lua["UIButton"] = &Lumos::UIButton; + lua["UIImage"] = &Lumos::UIImage; + lua["UISlider"] = &Lumos::UISlider; + lua["UIToggle"] = &Lumos::UIToggle; + lua["UILayoutRoot"] = &Lumos::UILayoutRoot; + } + } diff --git a/Lumos/Source/Lumos/Scripting/Lua/LuaManager.h b/Lumos/Source/Lumos/Scripting/Lua/LuaManager.h index f0dde9f2..151dbac1 100644 --- a/Lumos/Source/Lumos/Scripting/Lua/LuaManager.h +++ b/Lumos/Source/Lumos/Scripting/Lua/LuaManager.h @@ -33,6 +33,7 @@ namespace Lumos void BindInputLua(sol::state& state); void BindSceneLua(sol::state& state); void BindAppLua(sol::state& state); + void BindUILua(sol::state& lua); static TDArray& GetIdentifiers() { return s_Identifiers; } diff --git a/Lumos/premake5.lua b/Lumos/premake5.lua index efe7a8e2..c9cd865f 100644 --- a/Lumos/premake5.lua +++ b/Lumos/premake5.lua @@ -35,7 +35,6 @@ project "Lumos" { "%{IncludeDir.entt}", "%{IncludeDir.GLFW}", - "%{IncludeDir.Glad}", "%{IncludeDir.lua}", "%{IncludeDir.stb}", "%{IncludeDir.ImGui}", @@ -94,7 +93,6 @@ project "Lumos" defines { "LUMOS_PLATFORM_WINDOWS", - "LUMOS_RENDER_API_OPENGL", "LUMOS_RENDER_API_VULKAN", "VK_USE_PLATFORM_WIN32_KHR", "WIN32_LEAN_AND_MEAN", @@ -119,13 +117,8 @@ project "Lumos" "Source/Lumos/Platform/OpenAL/*.h", "Source/Lumos/Platform/OpenAL/*.cpp", - "Source/Lumos/Platform/OpenGL/*.h", - "Source/Lumos/Platform/OpenGL/*.cpp", - "Source/Lumos/Platform/Vulkan/*.h", - "Source/Lumos/Platform/Vulkan/*.cpp", - - "External/glad/src/glad_wgl.c" + "Source/Lumos/Platform/Vulkan/*.cpp" } links @@ -292,7 +285,6 @@ project "Lumos" { "LUMOS_PLATFORM_LINUX", "LUMOS_PLATFORM_UNIX", - "LUMOS_RENDER_API_OPENGL", "LUMOS_RENDER_API_VULKAN", "VK_USE_PLATFORM_XCB_KHR", "LUMOS_IMGUI", @@ -311,9 +303,6 @@ project "Lumos" "Source/Lumos/Platform/OpenAL/*.h", "Source/Lumos/Platform/OpenAL/*.cpp", - "Source/Lumos/Platform/OpenGL/*.h", - "Source/Lumos/Platform/OpenGL/*.cpp", - "Source/Lumos/Platform/Vulkan/*.h", "Source/Lumos/Platform/Vulkan/*.cpp" } diff --git a/Runtime/Runtime.cpp b/Runtime/Runtime.cpp index ffce3a56..82ce8237 100644 --- a/Runtime/Runtime.cpp +++ b/Runtime/Runtime.cpp @@ -13,6 +13,8 @@ #include +#include + using namespace Lumos; class Runtime : public Application diff --git a/Runtime/premake5.lua b/Runtime/premake5.lua index 0b1ef753..61f05089 100644 --- a/Runtime/premake5.lua +++ b/Runtime/premake5.lua @@ -13,7 +13,6 @@ project "Runtime" externalincludedirs { "%{IncludeDir.GLFW}", - "%{IncludeDir.Glad}", "%{IncludeDir.lua}", "%{IncludeDir.stb}", "%{IncludeDir.ImGui}", @@ -70,7 +69,6 @@ project "Runtime" defines { "LUMOS_PLATFORM_WINDOWS", - "LUMOS_RENDER_API_OPENGL", "LUMOS_RENDER_API_VULKAN", "VK_USE_PLATFORM_WIN32_KHR", "WIN32_LEAN_AND_MEAN", @@ -88,7 +86,6 @@ project "Runtime" links { "glfw", - "OpenGL32", "OpenAL32" } @@ -127,7 +124,6 @@ end { "LUMOS_PLATFORM_MACOS", "LUMOS_PLATFORM_UNIX", - "LUMOS_RENDER_API_OPENGL", "LUMOS_RENDER_API_VULKAN", "VK_EXT_metal_surface", "LUMOS_IMGUI", @@ -136,7 +132,6 @@ end linkoptions { - "-framework OpenGL", "-framework Cocoa", "-framework IOKit", "-framework CoreVideo", @@ -272,7 +267,6 @@ end { "LUMOS_PLATFORM_LINUX", "LUMOS_PLATFORM_UNIX", - "LUMOS_RENDER_API_OPENGL", "LUMOS_RENDER_API_VULKAN", "VK_USE_PLATFORM_XCB_KHR", "LUMOS_IMGUI", From 6b9d644bacb75e2cc12c96089d6244e339b95cc2 Mon Sep 17 00:00:00 2001 From: jmorton06 Date: Thu, 14 Nov 2024 08:42:26 +0000 Subject: [PATCH 2/3] Minor fixes --- Editor/Source/Editor.cpp | 10 +++++++++- Editor/Source/Editor.h | 2 +- Lumos/Source/Lumos/Core/Application.cpp | 1 + .../Lumos/Graphics/Renderers/SceneRenderer.cpp | 1 + .../Source/Lumos/Platform/Vulkan/VKCommandBuffer.cpp | 4 +++- Lumos/Source/Lumos/Platform/Vulkan/VKFence.cpp | 12 +++++++----- Lumos/Source/Lumos/Platform/Vulkan/VKFence.h | 2 +- Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.cpp | 3 +++ Runtime/Runtime.cpp | 4 +--- 9 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Editor/Source/Editor.cpp b/Editor/Source/Editor.cpp index 8c3c6d68..654b2735 100644 --- a/Editor/Source/Editor.cpp +++ b/Editor/Source/Editor.cpp @@ -989,7 +989,7 @@ namespace Lumos timer = 0.0; stats = Engine::Get().Statistics(); } - +#if 0 auto size = ImGui::CalcTextSize("%.2f ms (%.i FPS)"); float sizeOfGfxAPIDropDown = ImGui::GetFontSize() * 8; ImGui::SameLine(ImGui::GetWindowContentRegionMax().x - size.x - ImGui::GetStyle().ItemSpacing.x * 2.0f - sizeOfGfxAPIDropDown); @@ -1079,6 +1079,14 @@ namespace Lumos ImGui::PopStyleColor(2); ImGui::PopStyleVar(); +#else + auto size = ImGui::CalcTextSize("%.2f ms (%.i FPS)"); + ImGui::SameLine(ImGui::GetWindowContentRegionMax().x - size.x - ImGui::GetStyle().ItemSpacing.x * 2.0f); + + int fps = int(Maths::Round(1000.0 / stats.FrameTime)); + ImGui::Text("%.2f ms (%.i FPS)", stats.FrameTime, fps); + ImGui::PopStyleColor(); +#endif ImGui::EndMainMenuBar(); } diff --git a/Editor/Source/Editor.h b/Editor/Source/Editor.h index f95ad5b3..a80f1fd8 100644 --- a/Editor/Source/Editor.h +++ b/Editor/Source/Editor.h @@ -1,5 +1,5 @@ #pragma once - +#include #include #include #include diff --git a/Lumos/Source/Lumos/Core/Application.cpp b/Lumos/Source/Lumos/Core/Application.cpp index 99b3f867..57d831d2 100644 --- a/Lumos/Source/Lumos/Core/Application.cpp +++ b/Lumos/Source/Lumos/Core/Application.cpp @@ -280,6 +280,7 @@ namespace Lumos FileSystem::CreateFolderIfDoesntExist(m_ProjectSettings.m_ProjectRoot + "Assets/Prefabs"); FileSystem::CreateFolderIfDoesntExist(m_ProjectSettings.m_ProjectRoot + "Assets/Materials"); + Graphics::Renderer::GetGraphicsContext()->WaitIdle(); m_SceneManager = CreateUniquePtr(); Deserialise(); diff --git a/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp b/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp index c407c536..769752dd 100644 --- a/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp +++ b/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp @@ -3966,6 +3966,7 @@ namespace Lumos::Graphics } Graphics::CommandBuffer* commandBuffer = Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(); + commandBuffer->UnBindPipeline(); currentDescriptors[0] = m_DebugDrawData.m_Renderer2DData.m_DescriptorSet[0][0].get(); currentDescriptors[1] = m_DebugDrawData.m_Renderer2DData.m_DescriptorSet[0][1].get(); diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKCommandBuffer.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKCommandBuffer.cpp index bb711093..213685e4 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKCommandBuffer.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKCommandBuffer.cpp @@ -296,9 +296,11 @@ namespace Lumos LUMOS_PROFILE_FUNCTION_LOW(); ASSERT(m_State == CommandBufferState::Submitted); - m_Fence->WaitAndReset(); m_State = CommandBufferState::Idle; + if(!m_Fence->WaitAndReset()) + return false; + return true; } diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKFence.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKFence.cpp index 72f2114c..98d5ba65 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKFence.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKFence.cpp @@ -60,10 +60,10 @@ namespace Lumos if(result == VK_SUCCESS) { m_Signaled = true; - return false; + return true; } - return true; + return false; } void VKFence::Reset() @@ -75,13 +75,15 @@ namespace Lumos m_Signaled = false; } - void VKFence::WaitAndReset() + bool VKFence::WaitAndReset() { - LUMOS_PROFILE_FUNCTION(); + LUMOS_PROFILE_FUNCTION(); + bool succeeded = true; if(!IsSignaled()) - Wait(); + succeeded = Wait(); Reset(); + return succeeded; } } } diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKFence.h b/Lumos/Source/Lumos/Platform/Vulkan/VKFence.h index 2c429811..b8763a54 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKFence.h +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKFence.h @@ -17,7 +17,7 @@ namespace Lumos bool Wait(uint64_t timeoutNanoseconds = 1000000000); void Reset(); - void WaitAndReset(); + bool WaitAndReset(); private: VkFence m_Handle; diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.cpp index d4a89b54..30699653 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.cpp @@ -342,6 +342,9 @@ namespace Lumos { if(!commandBuffer->Wait()) { + //Exit app + LFATAL("Failed to submit command buffer"); + Application::Get().SetAppState(AppState::Closing); return; } } diff --git a/Runtime/Runtime.cpp b/Runtime/Runtime.cpp index 82ce8237..3ce74b00 100644 --- a/Runtime/Runtime.cpp +++ b/Runtime/Runtime.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -10,9 +11,6 @@ #include #include #include - -#include - #include using namespace Lumos; From 5e5c87df65767af2a4b06189e5eb7229ee6a0da2 Mon Sep 17 00:00:00 2001 From: jmorton06 Date: Fri, 15 Nov 2024 08:06:45 +0000 Subject: [PATCH 3/3] ios fix --- Lumos/Source/Lumos/Core/DataStructures/TDArray.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lumos/Source/Lumos/Core/DataStructures/TDArray.h b/Lumos/Source/Lumos/Core/DataStructures/TDArray.h index a49a7cee..338ef886 100644 --- a/Lumos/Source/Lumos/Core/DataStructures/TDArray.h +++ b/Lumos/Source/Lumos/Core/DataStructures/TDArray.h @@ -422,7 +422,7 @@ namespace Lumos // Compare with the last written element if (!compare(m_Data[readIndex], m_Data[writeIndex - 1])) { - m_Data[writeIndex] = std::move(m_Data[readIndex]); + m_Data[writeIndex] = Move(m_Data[readIndex]); ++writeIndex; } }