2
3
4
5
13
14
21 RendererPassBuilder{
"BassPass",
this }
23 .AddColorAttachment(
"Albedo", TextureType::Texture2D, [](
bool& isEnableBlend, VkAttachmentDescription& description) {
24 description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
25 description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
26 description.format = VK_FORMAT_R16G16B16A16_SFLOAT;
28 .AddColorAttachment(
"Normal", TextureType::Texture2D, [](
bool& isEnableBlend, VkAttachmentDescription& description) {
29 description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
30 description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
31 description.format = VK_FORMAT_R16G16B16A16_SFLOAT;
33 .AddColorAttachment(
"Roughness", TextureType::Texture2D, [](
bool& isEnableBlend, VkAttachmentDescription& description) {
34 description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
35 description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
36 description.format = VK_FORMAT_R16G16B16A16_SFLOAT;
38 .AddColorAttachment(
"Metallic", TextureType::Texture2D, [](
bool& isEnableBlend, VkAttachmentDescription& description) {
39 description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
40 description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
41 description.format = VK_FORMAT_R16G16B16A16_SFLOAT;
43 .AddColorAttachment(
"Position", TextureType::Texture2D, [](
bool& isEnableBlend, VkAttachmentDescription& description) {
44 description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
45 description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
46 description.format = VK_FORMAT_R32G32B32A32_SFLOAT;
48 .AddColorAttachment(
"EntityID", TextureType::Texture2D, [](
bool& isEnableBlend, VkAttachmentDescription& description) {
49 description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
50 description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
51 description.format = VK_FORMAT_R32_SFLOAT;
53 .AddColorAttachment(
"TriangleID", TextureType::Texture2D, [](
bool& isEnableBlend, VkAttachmentDescription& description) {
54 description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
55 description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
56 description.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
58 .AddColorAttachment(
"MeshletID", TextureType::Texture2D, [](
bool& isEnableBlend, VkAttachmentDescription& description) {
59 description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
60 description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
61 description.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
63 .AddDepthAttachment(
"Depth", TextureType::Texture2D, [](VkAttachmentDescription& description) {
64 description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
65 description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
67 .AddSelfDependency(VK_ACCESS_COMMAND_PREPROCESS_WRITE_BIT_NV,VK_ACCESS_INDIRECT_COMMAND_READ_BIT,VK_PIPELINE_STAGE_COMMAND_PREPROCESS_BIT_NV,VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT)
69 .AddSubPass(
"SkyBox", Querier::None)
70 .AddColorAttachment(
"Albedo", TextureType::Texture2D, [](
bool& isEnableBlend, VkAttachmentDescription& description) {
71 description.format = VK_FORMAT_R16G16B16A16_SFLOAT;
73 .AddColorAttachment(
"Position", TextureType::Texture2D, [](
bool& isEnableBlend, VkAttachmentDescription& description) {
74 description.format = VK_FORMAT_R32G32B32A32_SFLOAT;
76 .AddColorAttachment(
"EntityID", TextureType::Texture2D, [](
bool& isEnableBlend, VkAttachmentDescription& description) {
77 description.format = VK_FORMAT_R32_SFLOAT;
79 .AddColorAttachment(
"TriangleID", TextureType::Texture2D, [](
bool& isEnableBlend, VkAttachmentDescription& description) {
81 .AddColorAttachment(
"MeshletID", TextureType::Texture2D, [](
bool& isEnableBlend, VkAttachmentDescription& description) {
83 .AddDepthAttachment(
"Depth", TextureType::Texture2D, [](VkAttachmentDescription& description) {})
92 DescriptorSetBuilder{
"Mesh",
this }
96 DescriptorSetBuilder{
"SkyBox",
this }
105 DGCLayoutBuilder{
"Mesh",
this }
122 const auto dgcInstance = FillIndirectRenderData<MeshComponent>(
"Mesh", view);
127 m_DGCData[
"Mesh"] = dgcInstance;
135 std::shared_ptr<
Material> material ,
136 VkPipelineLayout& layout ,
142 PipelineBuilder{ subPass, material,
this }
146 .SetPipelineLayout(layout)
147 .SetCullMode(VK_CULL_MODE_NONE)
148 .SetColorAttachments()
153 const std::string& pipelineName ,
154 const std::string& materialName ,
155 VkPipelineLayout& layout ,
162 PipelineBuilder{ subPass,
nullptr,
this }
166 .SetPipelineLayout(layout)
167 .SetCullMode(VK_CULL_MODE_NONE)
168 .SetColorAttachments()
169 .BuildDeviceGeneratedCommand(pipelineName, materialName, indirectPtr);
184 builder
.Await([&](
const VkCommandBuffer& cmdBuffer) {
186 builder.SetViewPort(cmdBuffer);
188 builder.BindDescriptorSet(DescriptorSetManager::GetByName(
"PreRenderer"), cmdBuffer);
190 builder.BindDescriptorSet(DescriptorSetManager::GetByName({ m_Pass->GetName(),
"Mesh" }), cmdBuffer);
192 builder.RunDGC(cmdBuffer);
198 const size_t nThreads = ThreadModel::Get()->GetRHIThreadPool()->GetThreadsCount();
199 const size_t nTask = m_View ? (m_View->size() > 40 ? nThreads : 1) : 0;
200 const size_t nCount = m_View ? m_View->size() / nTask : 0;
202 std::vector<std::future<VkCommandBuffer>> futureCmdBuffers;
203 for(size_t i = 0; i < nTask; i++)
205 futureCmdBuffers.push_back(
207 builder.Async([&, i](
const VkCommandBuffer& cmdBuffer) {
209 builder.SetViewPort(cmdBuffer);
211 builder.BindDescriptorSet(DescriptorSetManager::GetByName(
"PreRenderer"), cmdBuffer);
213 builder.BindDescriptorSet(DescriptorSetManager::GetByName({ m_Pass->GetName(),
"Mesh" }), cmdBuffer);
215 IterWorldCompWithRange<MeshComponent>(frameInfo, *m_View, i * nCount, std::min((i + 1) * nCount, m_View->size() - 1), [&](
int entityId, TransformComponent& transComp, MeshComponent& meshComp) {
217 meshComp.GetMesh()->DrawMeshTasks(cmdBuffer, [&](
const uint32_t& meshpackId,
const auto& meshPack) {
219 builder.BindPipeline(meshPack->GetMaterial()->GetName(), cmdBuffer);
221 builder.UpdatePushConstant<uint64_t>([&](
auto& push) {
222 push = meshPack->GetMeshDesc().GetBufferAddress();
232 builder.Wait(futureCmdBuffers);
238 builder.SetViewPort();
240 builder.BindDescriptorSet(DescriptorSetManager::GetByName(
"PreRenderer"));
242 builder.BindDescriptorSet(DescriptorSetManager::GetByName({ m_Pass->GetName(),
"SkyBox" }));
246 skyboxComp.GetMesh()->DrawMeshTasks(
m_VulkanState.m_GraphicCommandBuffer[frameInfo
.m_FrameIndex], [&](
const uint32_t& meshPackId,
const auto& meshPack) {
248 builder.BindPipeline(meshPack->GetMaterial()->GetName());
250 builder.UpdatePushConstant<uint64_t>([&](
auto& push) {
251 push = meshPack->GetMeshDesc().GetBufferAddress();
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
virtual void CreatePipeline(std::shared_ptr< Material > material, VkPipelineLayout &layout, std::shared_ptr< RendererSubPass > subPass) override
The interface is inherited from Renderer. Create Material Specific Pipeline.
virtual void CreateRendererPass() override
The interface is inherited from Renderer. Create Specific Renderer pass.
virtual void CreateDescriptorSet() override
The interface is inherited from Renderer. Create specific descriptor set for sub pass.
virtual void CreateDeviceGeneratedCommandsPipeline(const std::string &pipelineName, const std::string &materialName, VkPipelineLayout &layout, std::shared_ptr< RendererSubPass > subPass, VulkanDeviceGeneratedCommandsNV *indirectPtr) override
Create device generated command Pipeline.
virtual void CreateDeviceGeneratedCommandsLayout() override
This interface is called during OnSystemInitialize(). Create Device Generated Commands Layout.
virtual void OnMeshAddedWorld() override
virtual void Render(TimeStep &ts, FrameInfo &frameInfo) override
The interface is inherited from Renderer.
BasePassRenderer Class. This class defines the base pass render behaves.
uint32_t m_FrameIndex
FrameIndex, varying during 0 - (MaxFrameInFlight - 1). Used almost anywhere.
static FrameInfo & Get()
Get FrameInfo.
RendererType m_RendererType
The renderer type of current world.
uint32_t m_ImageIndex
ImageIndex, varying during 0 - (MaxFrameInFlight - 1). Used in swapchain index and framebuffer index.
FrameInfo Class. This class defines the FrameInfo data.
Material Class. This class contains a branch of parameter and shader, also descriptor.
MeshComponent Class. This class defines the specific behaves of MeshComponent.
This Class Combines some data relative to sub pass. Usually as a member variable of RendererPass.
DGCLayoutBuilder & AddDrawMeshTaskInput()
Add Draw Mesh Task Command to Input.
DGCLayoutBuilder & AddShaderGroupInput()
Add Binding Shader Group Command to Input.
void Build() const
Create GDC Layout.
DGCLayoutBuilder & AddPushConstantInput()
Add Binding PushConstant Command to Input.
DescriptorSetBuilder & AddPushConstant(uint32_t size)
Set VkPushConstantRange by a specific push constant struct.
virtual void BeginNextSubPass(const std::string &subPassName)
End a preview sub pass and stat next sub pass.
void Await(std::function< void(const VkCommandBuffer &cmdBuffer)> func) const
Await Async Commands.
void BeginRenderPassAsync()
Begin this Renderer's RenderPass Async.
virtual void EndRenderPass()
End this Renderer's RenderPass.
This class helps to bind pipeline and bind buffer. Only instanced during Render().
virtual void OnMeshAddedWorld()
VulkanState & m_VulkanState
This variable is passed while renderer instanced.
Renderer Class. This class defines the basic behaves of renderer. When we add an new Renderer,...
SkyBoxComponent Class. This class defines the specific behaves of SkyBoxComponent.
This Class handles our engine time step during frames. Global Unique.
VulkanDeviceGeneratedCommandsNV Class. This class defines the VulkanDeviceGeneratedCommandsNV behaves...
constexpr bool m_IsUseDGC
Use DGC or not.