Enabling other passes

This commit is contained in:
Dynamitos
2023-11-10 22:26:47 +01:00
parent 9871fb921d
commit 91555fcec3
9 changed files with 54 additions and 50 deletions
+1
View File
@@ -11,6 +11,7 @@ struct LightCullingData
RWTexture2D<uint2> oLightGrid; RWTexture2D<uint2> oLightGrid;
RWTexture2D<uint2> tLightGrid; RWTexture2D<uint2> tLightGrid;
}; };
layout(set=5)
ParameterBlock<LightCullingData> pLightCullingData; ParameterBlock<LightCullingData> pLightCullingData;
[shader("pixel")] [shader("pixel")]
+1 -1
View File
@@ -68,5 +68,5 @@ struct LightEnv
StructuredBuffer<PointLight> pointLights; StructuredBuffer<PointLight> pointLights;
uint numPointLights; uint numPointLights;
}; };
layout(set=3)
ParameterBlock<LightEnv> pLightEnv; ParameterBlock<LightEnv> pLightEnv;
+1
View File
@@ -8,4 +8,5 @@ interface IMaterial
BRDF prepare(MaterialParameter input); BRDF prepare(MaterialParameter input);
}; };
layout(set=4)
ParameterBlock<IMaterial> pMaterial; ParameterBlock<IMaterial> pMaterial;
+19 -18
View File
@@ -74,39 +74,37 @@ void BasePass::render()
graphics->beginRenderPass(renderPass); graphics->beginRenderPass(renderPass);
Gfx::ShaderPermutation permutation; Gfx::ShaderPermutation permutation;
permutation.hasFragment = true; if (graphics->supportMeshShading())
if(graphics->supportMeshShading())
{ {
permutation.useMeshShading = true; permutation.setTaskFile("MeshletBasePass");
permutation.hasTaskShader = true; permutation.setMeshFile("MeshletBasePass");
std::memcpy(permutation.taskFile, "MeshletBasePass", sizeof("MeshletBasePass"));
std::memcpy(permutation.vertexMeshFile, "MeshletBasePass", sizeof("MeshletBasePass"));
} }
else else
{ {
permutation.useMeshShading = false; permutation.setVertexFile("LegacyBasePass");
std::memcpy(permutation.vertexMeshFile, "LegacyBasePass", sizeof("LegacyBasePass"));
} }
std::memcpy(permutation.fragmentFile, "BasePass", std::strlen("BasePass")); permutation.setFragmentFile("BasePass");
graphics->beginRenderPass(renderPass);
Array<Gfx::PRenderCommand> commands;
for (VertexData* vertexData : VertexData::getList()) 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(); const auto& materials = vertexData->getMaterialData();
for (const auto& [_, materialData] : materials) for (const auto& [_, materialData] : materials)
{ {
// Create Pipeline(Material, VertexData) // Create Pipeline(Material, VertexData)
// Descriptors: // Descriptors:
// ViewData => global, static // ViewData => global, static
// LightEnv => global, static
// LightCulling => global, static
// Material => per material
// VertexData => per meshtype // VertexData => per meshtype
// SceneData => per material instance // SceneData => per material instance
// LightEnv => provided by scene
std::memcpy(permutation.materialName, materialData.material->getName().c_str(), std::strlen(materialData.material->getName().c_str())); // Material => per material
// LightCulling => calculated by pass
permutation.setMaterial(materialData.material->getName());
Gfx::PermutationId id(permutation); Gfx::PermutationId id(permutation);
Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender"); Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender");
command->setViewport(viewport);
Gfx::OPipelineLayout layout = graphics->createPipelineLayout(basePassLayout); Gfx::OPipelineLayout layout = graphics->createPipelineLayout(basePassLayout);
layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout()); layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout());
layout->addDescriptorLayout(INDEX_VERTEX_DATA, vertexData->getVertexDataLayout()); layout->addDescriptorLayout(INDEX_VERTEX_DATA, vertexData->getVertexDataLayout());
@@ -115,7 +113,7 @@ void BasePass::render()
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id); const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
assert(collection != nullptr); assert(collection != nullptr);
if(graphics->supportMeshShading()) if (graphics->supportMeshShading())
{ {
Gfx::MeshPipelineCreateInfo pipelineInfo; Gfx::MeshPipelineCreateInfo pipelineInfo;
pipelineInfo.taskShader = collection->taskShader; pipelineInfo.taskShader = collection->taskShader;
@@ -146,14 +144,14 @@ void BasePass::render()
descriptorSets[INDEX_MATERIAL] = instance.materialInstance->getDescriptorSet(); descriptorSets[INDEX_MATERIAL] = instance.materialInstance->getDescriptorSet();
descriptorSets[INDEX_SCENE_DATA] = instance.descriptorSet; descriptorSets[INDEX_SCENE_DATA] = instance.descriptorSet;
command->bindDescriptor(descriptorSets); command->bindDescriptor(descriptorSets);
if(Gfx::useMeshShading) if (graphics->supportMeshShading())
{ {
command->dispatch(instance.numMeshes, 1, 1); command->dispatch(instance.numMeshes, 1, 1);
} }
else else
{ {
uint32 instanceOffset = 0; uint32 instanceOffset = 0;
for(const auto& mesh : instance.meshes) for (const auto& mesh : instance.meshes)
{ {
uint32 vertexOffset = vertexData->getMeshOffset(mesh.id); uint32 vertexOffset = vertexData->getMeshOffset(mesh.id);
if (mesh.indexBuffer != nullptr) if (mesh.indexBuffer != nullptr)
@@ -165,11 +163,14 @@ void BasePass::render()
{ {
command->draw(vertexData->getMeshVertexCount(mesh.id), 1, vertexOffset, instanceOffset); command->draw(vertexData->getMeshVertexCount(mesh.id), 1, vertexOffset, instanceOffset);
} }
instanceOffset += mesh.meshes;
} }
} }
} }
commands.add(command);
} }
} }
graphics->executeCommands(commands);
graphics->endRenderPass(); graphics->endRenderPass();
} }
+10 -10
View File
@@ -31,17 +31,17 @@ private:
Gfx::OPipelineLayout basePassLayout; Gfx::OPipelineLayout basePassLayout;
// Set 0: viewParameter, provided by renderpass // Set 0: viewParameter, provided by renderpass
static constexpr uint32 INDEX_VIEW_PARAMS = 0; static constexpr uint32 INDEX_VIEW_PARAMS = 0;
// Set 1: light environment, provided by lightenv // Set 1: vertex buffers, provided by vertexdata
static constexpr uint32 INDEX_LIGHT_ENV = 1; static constexpr uint32 INDEX_VERTEX_DATA = 1;
// Set 2: light culling data // Set 2: instance data, provided by vertexdata
static constexpr uint32 INDEX_LIGHT_CULLING = 2; 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; Gfx::ODescriptorLayout lightCullingLayout;
// Set 3: material data, generated from material static constexpr uint32 INDEX_LIGHT_CULLING = 5;
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;
}; };
DEFINE_REF(BasePass) DEFINE_REF(BasePass)
} // namespace Seele } // namespace Seele
@@ -125,7 +125,7 @@ void LightCullingPass::publishOutputs()
ShaderCreateInfo createInfo; ShaderCreateInfo createInfo;
createInfo.name = "Culling"; createInfo.name = "Culling";
createInfo.additionalModules.add("LightCulling");
createInfo.mainModule = "LightCulling"; createInfo.mainModule = "LightCulling";
createInfo.entryPoint = "cullLights"; createInfo.entryPoint = "cullLights";
cullingShader = graphics->createComputeShader(createInfo); cullingShader = graphics->createComputeShader(createInfo);
@@ -209,7 +209,7 @@ void LightCullingPass::setupFrustums()
frustumLayout->create(); frustumLayout->create();
ShaderCreateInfo createInfo; ShaderCreateInfo createInfo;
createInfo.name = "Frustum"; createInfo.name = "Frustum";
createInfo.additionalModules.add("ComputeFrustums");
createInfo.mainModule = "ComputeFrustums"; createInfo.mainModule = "ComputeFrustums";
createInfo.entryPoint = "computeFrustums"; createInfo.entryPoint = "computeFrustums";
frustumShader = graphics->createComputeShader(createInfo); frustumShader = graphics->createComputeShader(createInfo);
+12 -11
View File
@@ -32,21 +32,22 @@ void DescriptorLayout::create()
for (size_t i = 0; i < descriptorBindings.size(); ++i) for (size_t i = 0; i < descriptorBindings.size(); ++i)
{ {
VkDescriptorSetLayoutBinding &binding = bindings[i]; VkDescriptorSetLayoutBinding &binding = bindings[i];
const Gfx::DescriptorBinding &rhiBinding = descriptorBindings[i]; const Gfx::DescriptorBinding &gfxBinding = descriptorBindings[i];
binding.binding = rhiBinding.binding; binding.binding = gfxBinding.binding;
binding.descriptorCount = rhiBinding.descriptorCount; binding.descriptorCount = gfxBinding.descriptorCount;
binding.descriptorType = cast(rhiBinding.descriptorType); binding.descriptorType = cast(gfxBinding.descriptorType);
binding.stageFlags = rhiBinding.shaderStages; binding.stageFlags = gfxBinding.shaderStages;
binding.pImmutableSamplers = nullptr; binding.pImmutableSamplers = nullptr;
bindingFlags[i] = rhiBinding.bindingFlags; bindingFlags[i] = gfxBinding.bindingFlags;
} }
VkDescriptorSetLayoutCreateInfo createInfo = VkDescriptorSetLayoutCreateInfo createInfo =
init::DescriptorSetLayoutCreateInfo(bindings.data(), (uint32)bindings.size()); init::DescriptorSetLayoutCreateInfo(bindings.data(), (uint32)bindings.size());
VkDescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsInfo = {}; VkDescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsInfo = {
bindingFlagsInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO,
bindingFlagsInfo.pNext = nullptr; .pNext = nullptr,
bindingFlagsInfo.bindingCount = static_cast<uint32>(bindingFlags.size()); .bindingCount = static_cast<uint32>(bindingFlags.size()),
bindingFlagsInfo.pBindingFlags = bindingFlags.data(); .pBindingFlags = bindingFlags.data(),
};
createInfo.pNext = &bindingFlagsInfo; createInfo.pNext = &bindingFlagsInfo;
VK_CHECK(vkCreateDescriptorSetLayout(graphics->getDevice(), &createInfo, nullptr, &layoutHandle)); VK_CHECK(vkCreateDescriptorSetLayout(graphics->getDevice(), &createInfo, nullptr, &layoutHandle));
+4 -4
View File
@@ -15,10 +15,10 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
, scene(new Scene(graphics)) , scene(new Scene(graphics))
, gameInterface(dllPath) , gameInterface(dllPath)
, renderGraph(RenderGraphBuilder::build( , renderGraph(RenderGraphBuilder::build(
DepthPrepass(graphics, scene) DepthPrepass(graphics, scene),
//LightCullingPass(graphics, scene), LightCullingPass(graphics, scene),
//BasePass(graphics, scene), BasePass(graphics, scene),
//SkyboxRenderPass(graphics, scene) SkyboxRenderPass(graphics, scene)
)) ))
{ {
camera = new CameraActor(scene); camera = new CameraActor(scene);
+4 -4
View File
@@ -31,10 +31,10 @@ private:
OEntity camera; OEntity camera;
GameInterface gameInterface; GameInterface gameInterface;
RenderGraph< RenderGraph<
DepthPrepass DepthPrepass,
//LightCullingPass, LightCullingPass,
//BasePass, BasePass,
//SkyboxRenderPass SkyboxRenderPass
> renderGraph; > renderGraph;
PSystemGraph systemGraph; PSystemGraph systemGraph;