From 91555fcec36e0a0db3ab271f2e06965f6913b3bb Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Fri, 10 Nov 2023 22:26:47 +0100 Subject: [PATCH] Enabling other passes --- res/shaders/BasePass.slang | 1 + res/shaders/lib/LightEnv.slang | 2 +- res/shaders/lib/Material.slang | 1 + src/Engine/Graphics/RenderPass/BasePass.cpp | 37 ++++++++++--------- src/Engine/Graphics/RenderPass/BasePass.h | 20 +++++----- .../Graphics/RenderPass/LightCullingPass.cpp | 4 +- src/Engine/Graphics/Vulkan/DescriptorSets.cpp | 23 ++++++------ src/Engine/Window/GameView.cpp | 8 ++-- src/Engine/Window/GameView.h | 8 ++-- 9 files changed, 54 insertions(+), 50 deletions(-) diff --git a/res/shaders/BasePass.slang b/res/shaders/BasePass.slang index 042d149..063c25e 100644 --- a/res/shaders/BasePass.slang +++ b/res/shaders/BasePass.slang @@ -11,6 +11,7 @@ struct LightCullingData RWTexture2D oLightGrid; RWTexture2D tLightGrid; }; +layout(set=5) ParameterBlock pLightCullingData; [shader("pixel")] diff --git a/res/shaders/lib/LightEnv.slang b/res/shaders/lib/LightEnv.slang index f505322..31d0477 100644 --- a/res/shaders/lib/LightEnv.slang +++ b/res/shaders/lib/LightEnv.slang @@ -68,5 +68,5 @@ struct LightEnv StructuredBuffer pointLights; uint numPointLights; }; - +layout(set=3) ParameterBlock pLightEnv; diff --git a/res/shaders/lib/Material.slang b/res/shaders/lib/Material.slang index da0c53c..7c15a9c 100644 --- a/res/shaders/lib/Material.slang +++ b/res/shaders/lib/Material.slang @@ -8,4 +8,5 @@ interface IMaterial BRDF prepare(MaterialParameter input); }; +layout(set=4) ParameterBlock pMaterial; diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index ed34862..e33e48e 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -74,39 +74,37 @@ void BasePass::render() graphics->beginRenderPass(renderPass); Gfx::ShaderPermutation permutation; - permutation.hasFragment = true; - if(graphics->supportMeshShading()) + if (graphics->supportMeshShading()) { - permutation.useMeshShading = true; - permutation.hasTaskShader = true; - std::memcpy(permutation.taskFile, "MeshletBasePass", sizeof("MeshletBasePass")); - std::memcpy(permutation.vertexMeshFile, "MeshletBasePass", sizeof("MeshletBasePass")); + permutation.setTaskFile("MeshletBasePass"); + permutation.setMeshFile("MeshletBasePass"); } else { - permutation.useMeshShading = false; - std::memcpy(permutation.vertexMeshFile, "LegacyBasePass", sizeof("LegacyBasePass")); + permutation.setVertexFile("LegacyBasePass"); } - std::memcpy(permutation.fragmentFile, "BasePass", std::strlen("BasePass")); + permutation.setFragmentFile("BasePass"); + graphics->beginRenderPass(renderPass); + Array commands; for (VertexData* vertexData : VertexData::getList()) { - std::memcpy(permutation.vertexDataName, vertexData->getTypeName().c_str(), std::strlen(vertexData->getTypeName().c_str())); + permutation.setVertexData(vertexData->getTypeName()); const auto& materials = vertexData->getMaterialData(); for (const auto& [_, materialData] : materials) { // Create Pipeline(Material, VertexData) // Descriptors: // ViewData => global, static - // LightEnv => global, static - // LightCulling => global, static - // Material => per material // VertexData => per meshtype // SceneData => per material instance - - std::memcpy(permutation.materialName, materialData.material->getName().c_str(), std::strlen(materialData.material->getName().c_str())); + // LightEnv => provided by scene + // Material => per material + // LightCulling => calculated by pass + permutation.setMaterial(materialData.material->getName()); Gfx::PermutationId id(permutation); Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender"); + command->setViewport(viewport); Gfx::OPipelineLayout layout = graphics->createPipelineLayout(basePassLayout); layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout()); layout->addDescriptorLayout(INDEX_VERTEX_DATA, vertexData->getVertexDataLayout()); @@ -115,7 +113,7 @@ void BasePass::render() const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id); assert(collection != nullptr); - if(graphics->supportMeshShading()) + if (graphics->supportMeshShading()) { Gfx::MeshPipelineCreateInfo pipelineInfo; pipelineInfo.taskShader = collection->taskShader; @@ -146,14 +144,14 @@ void BasePass::render() descriptorSets[INDEX_MATERIAL] = instance.materialInstance->getDescriptorSet(); descriptorSets[INDEX_SCENE_DATA] = instance.descriptorSet; command->bindDescriptor(descriptorSets); - if(Gfx::useMeshShading) + if (graphics->supportMeshShading()) { command->dispatch(instance.numMeshes, 1, 1); } else { uint32 instanceOffset = 0; - for(const auto& mesh : instance.meshes) + for (const auto& mesh : instance.meshes) { uint32 vertexOffset = vertexData->getMeshOffset(mesh.id); if (mesh.indexBuffer != nullptr) @@ -165,11 +163,14 @@ void BasePass::render() { command->draw(vertexData->getMeshVertexCount(mesh.id), 1, vertexOffset, instanceOffset); } + instanceOffset += mesh.meshes; } } } + commands.add(command); } } + graphics->executeCommands(commands); graphics->endRenderPass(); } diff --git a/src/Engine/Graphics/RenderPass/BasePass.h b/src/Engine/Graphics/RenderPass/BasePass.h index 34affe5..9d8b589 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.h +++ b/src/Engine/Graphics/RenderPass/BasePass.h @@ -31,17 +31,17 @@ private: Gfx::OPipelineLayout basePassLayout; // Set 0: viewParameter, provided by renderpass static constexpr uint32 INDEX_VIEW_PARAMS = 0; - // Set 1: light environment, provided by lightenv - static constexpr uint32 INDEX_LIGHT_ENV = 1; - // Set 2: light culling data - static constexpr uint32 INDEX_LIGHT_CULLING = 2; + // Set 1: vertex buffers, provided by vertexdata + static constexpr uint32 INDEX_VERTEX_DATA = 1; + // Set 2: instance data, provided by vertexdata + static constexpr uint32 INDEX_SCENE_DATA = 2; + // Set 3: light environment, provided by lightenv + static constexpr uint32 INDEX_LIGHT_ENV = 3; + // Set 4: material data, generated from material + static constexpr uint32 INDEX_MATERIAL = 4; + // Set 5: light culling data Gfx::ODescriptorLayout lightCullingLayout; - // Set 3: material data, generated from material - static constexpr uint32 INDEX_MATERIAL = 3; - // Set 4: vertex buffers, provided by vertexdata - static constexpr uint32 INDEX_VERTEX_DATA = 4; - // Set 5: instance data, provided by vertexdata - static constexpr uint32 INDEX_SCENE_DATA = 5; + static constexpr uint32 INDEX_LIGHT_CULLING = 5; }; DEFINE_REF(BasePass) } // namespace Seele diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index 95750c0..5f0f47d 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -125,7 +125,7 @@ void LightCullingPass::publishOutputs() ShaderCreateInfo createInfo; createInfo.name = "Culling"; - + createInfo.additionalModules.add("LightCulling"); createInfo.mainModule = "LightCulling"; createInfo.entryPoint = "cullLights"; cullingShader = graphics->createComputeShader(createInfo); @@ -209,7 +209,7 @@ void LightCullingPass::setupFrustums() frustumLayout->create(); ShaderCreateInfo createInfo; createInfo.name = "Frustum"; - + createInfo.additionalModules.add("ComputeFrustums"); createInfo.mainModule = "ComputeFrustums"; createInfo.entryPoint = "computeFrustums"; frustumShader = graphics->createComputeShader(createInfo); diff --git a/src/Engine/Graphics/Vulkan/DescriptorSets.cpp b/src/Engine/Graphics/Vulkan/DescriptorSets.cpp index fa85344..1541ff8 100644 --- a/src/Engine/Graphics/Vulkan/DescriptorSets.cpp +++ b/src/Engine/Graphics/Vulkan/DescriptorSets.cpp @@ -32,21 +32,22 @@ void DescriptorLayout::create() for (size_t i = 0; i < descriptorBindings.size(); ++i) { VkDescriptorSetLayoutBinding &binding = bindings[i]; - const Gfx::DescriptorBinding &rhiBinding = descriptorBindings[i]; - binding.binding = rhiBinding.binding; - binding.descriptorCount = rhiBinding.descriptorCount; - binding.descriptorType = cast(rhiBinding.descriptorType); - binding.stageFlags = rhiBinding.shaderStages; + const Gfx::DescriptorBinding &gfxBinding = descriptorBindings[i]; + binding.binding = gfxBinding.binding; + binding.descriptorCount = gfxBinding.descriptorCount; + binding.descriptorType = cast(gfxBinding.descriptorType); + binding.stageFlags = gfxBinding.shaderStages; binding.pImmutableSamplers = nullptr; - bindingFlags[i] = rhiBinding.bindingFlags; + bindingFlags[i] = gfxBinding.bindingFlags; } VkDescriptorSetLayoutCreateInfo createInfo = init::DescriptorSetLayoutCreateInfo(bindings.data(), (uint32)bindings.size()); - VkDescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsInfo = {}; - bindingFlagsInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO; - bindingFlagsInfo.pNext = nullptr; - bindingFlagsInfo.bindingCount = static_cast(bindingFlags.size()); - bindingFlagsInfo.pBindingFlags = bindingFlags.data(); + VkDescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsInfo = { + .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO, + .pNext = nullptr, + .bindingCount = static_cast(bindingFlags.size()), + .pBindingFlags = bindingFlags.data(), + }; createInfo.pNext = &bindingFlagsInfo; VK_CHECK(vkCreateDescriptorSetLayout(graphics->getDevice(), &createInfo, nullptr, &layoutHandle)); diff --git a/src/Engine/Window/GameView.cpp b/src/Engine/Window/GameView.cpp index 55c98c6..ea42ddb 100644 --- a/src/Engine/Window/GameView.cpp +++ b/src/Engine/Window/GameView.cpp @@ -15,10 +15,10 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate , scene(new Scene(graphics)) , gameInterface(dllPath) , renderGraph(RenderGraphBuilder::build( - DepthPrepass(graphics, scene) - //LightCullingPass(graphics, scene), - //BasePass(graphics, scene), - //SkyboxRenderPass(graphics, scene) + DepthPrepass(graphics, scene), + LightCullingPass(graphics, scene), + BasePass(graphics, scene), + SkyboxRenderPass(graphics, scene) )) { camera = new CameraActor(scene); diff --git a/src/Engine/Window/GameView.h b/src/Engine/Window/GameView.h index 9afba9e..798d40c 100644 --- a/src/Engine/Window/GameView.h +++ b/src/Engine/Window/GameView.h @@ -31,10 +31,10 @@ private: OEntity camera; GameInterface gameInterface; RenderGraph< - DepthPrepass - //LightCullingPass, - //BasePass, - //SkyboxRenderPass + DepthPrepass, + LightCullingPass, + BasePass, + SkyboxRenderPass > renderGraph; PSystemGraph systemGraph;