Renderer is now using new buffer management system

This commit is contained in:
antopilo
2025-05-04 22:33:47 -04:00
parent f57393d354
commit 1417df96d1
7 changed files with 67 additions and 223 deletions

View File

@@ -92,7 +92,7 @@ void Descriptor::Bind(VkCommandBuffer cmd, VkPipelineLayout layout)
}
BindlessDescriptor::BindlessDescriptor(ResourceType type, BindlessInfo& info) :
Info(info),
Info(info),
Type(type)
{
// Create a buffer that holds for N frame in flights of data
@@ -119,7 +119,7 @@ BindlessDescriptor::BindlessDescriptor(ResourceType type, BindlessInfo& info) :
// Create buffer and map, CPU -> GPU since we will writing to it directly
// Size of buffer is: size_of(ResourceType) * FRAME_OVERLAP since 1 buffer will hold N Frames in flight
// TODO(antopilo): move mapped pointer inside buffer directly
const BufferUsage usage = BufferUsage::STORAGE_BUFFER | BufferUsage::TRANSFER_DST;
const BufferUsage usage = BufferUsage::STORAGE_BUFFER | BufferUsage::TRANSFER_DST | BufferUsage::TRANSFER_SRC;
const MemoryUsage memoryUsage = MemoryUsage::CPU_TO_GPU;
const size_t size = info.ResourceElementSize[type] * info.ResourceCount[type];
const size_t totalSize = size * FRAME_OVERLAP;
@@ -145,6 +145,7 @@ void BindlessDescriptor::WriteToBuffer(int32_t frameIndex, void* data, size_t si
const size_t offsetSize = Info.ResourceCount[Type] * Info.ResourceElementSize[Type];
size_t offset = currentFrame * offsetSize;
LastWriteSize = size;
memcpy(desc.DataPtr, data, size);
}
@@ -156,7 +157,7 @@ void BindlessDescriptor::Swap(int32_t frameIndex)
auto& nextDesc = Descriptors[nextFrame];
// memcpy from currentFrame to next frame
memcpy(desc.DataPtr, nextDesc.DataPtr, desc.Size);
//memcpy(nextDesc.DataPtr, desc.DataPtr, LastWriteSize);
}
void BindlessDescriptor::Bind(VkCommandBuffer cmd, int32_t frameIndex, VkPipelineLayout layout)
@@ -173,7 +174,7 @@ ResourceDescriptors::ResourceDescriptors(const ResourceDescriptorsLimits& limits
AddResourceDescriptors<ResourceType::Sampler, VkDescriptorImageInfo>(limits.MaxSampler, 2);
AddResourceDescriptors<ResourceType::Material, MaterialBufferStruct>(limits.MaxMaterial, 3);
AddResourceDescriptors<ResourceType::Texture, VkDescriptorImageInfo>(limits.MaxTexture, 4);
AddResourceDescriptors<ResourceType::Light, LightData>(limits.MaxLight, 4);
AddResourceDescriptors<ResourceType::Light, LightData>(limits.MaxLight, 5);
AddResourceDescriptors<ResourceType::View, CameraView>(limits.MaxView, 6);
}
@@ -195,4 +196,7 @@ void ResourceDescriptors::Bind(VkCommandBuffer cmd, int32_t frame, VkPipelineLay
*/
Descriptors[ResourceType::Transform].Bind(cmd, frame, layout);
Descriptors[ResourceType::Material].Bind(cmd, frame, layout);
Descriptors[ResourceType::Light].Bind(cmd, frame, layout);
Descriptors[ResourceType::View].Bind(cmd, frame, layout);
}

View File

@@ -72,6 +72,7 @@ namespace Nuake
VkDescriptorSetLayout DescriptorLayout;
BindlessInfo Info;
ResourceType Type;
size_t LastWriteSize = 0;
public:
// Delete copy
@@ -91,6 +92,12 @@ namespace Nuake
void Bind(VkCommandBuffer cmd, int32_t frameIndex, VkPipelineLayout layout);
};
struct ResourceDescriptorDef
{
size_t Size;
uint32_t Slot;
};
struct ResourceDescriptorsLimits
{
size_t MaxTransform;

View File

@@ -0,0 +1,23 @@
#pragma once
#include <volk/volk.h>
namespace Nuake
{
enum class SamplerType
{
Linear,
Nearest
};
class Sampler
{
private:
VkSampler vkSampler;
float maxAnisotropy;
public:
Sampler(SamplerType samplerType);
~Sampler();
};
}

View File

@@ -39,12 +39,8 @@ ShadowRenderPipeline::ShadowRenderPipeline()
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
Cmd& cmd = ctx.commandBuffer;
//cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
});
shadowPass.SetRender([&](PassRenderContext& ctx) {
auto& cmd = ctx.commandBuffer;
@@ -381,14 +377,11 @@ void SceneRenderPipeline::RecreatePipeline()
{
auto& layout = ctx.renderPass->PipelineLayout;
auto& res = GPUResources::Get();
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
Cmd& cmd = ctx.commandBuffer;
cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
});
gBufferPass.SetRender([&](PassRenderContext& ctx)
{
@@ -491,12 +484,9 @@ void SceneRenderPipeline::RecreatePipeline()
Cmd& cmd = ctx.commandBuffer;
auto& layout = ctx.renderPass->PipelineLayout;
auto& res = GPUResources::Get();
cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
// Bind noise kernel
cmd.BindDescriptorSet(layout, res.SSAOKernelDescriptor, 7);
@@ -533,12 +523,9 @@ void SceneRenderPipeline::RecreatePipeline()
Cmd& cmd = ctx.commandBuffer;
auto& layout = ctx.renderPass->PipelineLayout;
auto& res = GPUResources::Get();
cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
blurConstant.sourceTextureID = res.GetBindlessTextureID(SSAOOutput->GetID());
blurConstant.sourceSize = SSAOOutput->GetSize();
@@ -609,12 +596,9 @@ void SceneRenderPipeline::RecreatePipeline()
auto& res = GPUResources::Get();
// Bindless
cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
// Inputs
shadingConstant.AlbedoTextureID = res.GetBindlessTextureID(GBufferAlbedo->GetID());
@@ -665,12 +649,9 @@ void SceneRenderPipeline::RecreatePipeline()
auto& res = GPUResources::Get();
// Bindless
cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
// Inputs
tonemapConstant.Exposure = ctx.scene->GetEnvironment()->Exposure;
@@ -703,14 +684,9 @@ void SceneRenderPipeline::RecreatePipeline()
auto& layout = ctx.renderPass->PipelineLayout;
auto& res = GPUResources::Get();
//ctx.renderPass->SetClearColor({0, 0, 0, 0});
cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
});
volumetricPass.SetRender([&](PassRenderContext& ctx)
{
@@ -760,13 +736,9 @@ void SceneRenderPipeline::RecreatePipeline()
Cmd& cmd = ctx.commandBuffer;
auto& layout = ctx.renderPass->PipelineLayout;
auto& res = GPUResources::Get();
cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
});
volumetricBlurPass.SetRender([&](PassRenderContext& ctx)
{
@@ -793,13 +765,9 @@ void SceneRenderPipeline::RecreatePipeline()
Cmd& cmd = ctx.commandBuffer;
auto& layout = ctx.renderPass->PipelineLayout;
auto& res = GPUResources::Get();
cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
});
volumetricCombinePass.SetRender([&](PassRenderContext& ctx)
{
@@ -831,13 +799,9 @@ void SceneRenderPipeline::RecreatePipeline()
Cmd& cmd = ctx.commandBuffer;
auto& layout = ctx.renderPass->PipelineLayout;
auto& res = GPUResources::Get();
cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
});
gizmoPass.SetRender([&](PassRenderContext& ctx)
{
@@ -856,13 +820,9 @@ void SceneRenderPipeline::RecreatePipeline()
Cmd& cmd = ctx.commandBuffer;
auto& layout = ctx.renderPass->PipelineLayout;
auto& res = GPUResources::Get();
cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
});
gizmoCombinePass.SetRender([&](PassRenderContext& ctx)
{
@@ -892,13 +852,9 @@ void SceneRenderPipeline::RecreatePipeline()
auto& layout = ctx.renderPass->PipelineLayout;
auto& res = GPUResources::Get();
// Bindless
cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
});
outlinePass.SetRender([&](PassRenderContext& ctx)
{
@@ -933,12 +889,9 @@ void SceneRenderPipeline::RecreatePipeline()
auto& layout = ctx.renderPass->PipelineLayout;
auto& res = GPUResources::Get();
cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
});
linePass.SetRender([&](PassRenderContext& ctx)
{
@@ -958,12 +911,9 @@ void SceneRenderPipeline::RecreatePipeline()
auto& layout = ctx.renderPass->PipelineLayout;
auto& res = GPUResources::Get();
cmd.BindDescriptorSet(layout, res.ModelDescriptor, 0);
res.BindSceneData(ctx.commandBuffer.GetCmdBuffer(), layout);
cmd.BindDescriptorSet(layout, res.SamplerDescriptor, 2);
cmd.BindDescriptorSet(layout, res.MaterialDescriptor, 3);
cmd.BindDescriptorSet(layout, res.TexturesDescriptor, 4);
cmd.BindDescriptorSet(layout, res.LightsDescriptor, 5);
cmd.BindDescriptorSet(layout, res.CamerasDescriptor, 6);
});
lineCombinePass.SetRender([&](PassRenderContext& ctx)
{
@@ -980,7 +930,6 @@ void SceneRenderPipeline::RecreatePipeline()
cmd.DrawIndexed(6);
});
GBufferPipeline.Build();
}

View File

@@ -27,7 +27,7 @@ AllocatedBuffer::AllocatedBuffer(size_t inSize, BufferUsage inFlags, MemoryUsage
VmaAllocationCreateInfo vmaallocInfo = {};
vmaallocInfo.usage = static_cast<VmaMemoryUsage>(inUsage);
vmaallocInfo.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT;
vmaallocInfo.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
MemUsage = inUsage;

View File

@@ -749,6 +749,7 @@ bool VkRenderer::Draw()
VK_CALL(vkWaitForFences(Device, 1, &GetCurrentFrame().RenderFence, true, 1000000000));
if (SurfaceSize != Window::Get()->GetSize())
{
RecreateSwapchain();
@@ -771,6 +772,8 @@ bool VkRenderer::Draw()
VK_CALL(vkResetFences(Device, 1, &GetCurrentFrame().RenderFence));
GPUResources::Get().Swap(FrameNumber);
// Note: this will be the meat of the engine that should be here.
VkCommandBuffer cmd = GetCurrentFrame().CommandBuffer;
VK_CALL(vkResetCommandBuffer(cmd, 0));
@@ -881,7 +884,6 @@ void VkRenderer::EndDraw()
// Increase the number of frames drawn
FrameNumber++;
//GPUResources::Get().Swap(FrameNumber);
}
void VkRenderer::DrawImgui(VkCommandBuffer cmd, VkImageView targetImageView)

View File

@@ -46,12 +46,12 @@ void GPUResources::Init()
ResourceDescriptorsLimits limits
{
.MaxTransform = 100,
.MaxView = 100,
.MaxMaterial = 100,
.MaxTexture = 100,
.MaxLight = 100,
.MaxSampler = 100,
.MaxTransform = 3000,
.MaxView = 1000,
.MaxMaterial = 1000,
.MaxTexture = 3000,
.MaxLight = 1000,
.MaxSampler = 2,
};
resourceDescriptors = CreateScope<ResourceDescriptors>(limits);
@@ -423,157 +423,16 @@ void GPUResources::RecreateBindlessCameras()
i++;
}
void* mappedData;
auto allocator = VulkanAllocator::Get().GetAllocator();
vmaMapMemory(allocator, (VkRenderer::Get().GetCurrentFrame().CamerasStagingBuffer->GetAllocation()), &mappedData);
memcpy(mappedData, Cameras.data(), sizeof(CameraView) * Cameras.size());
VkRenderer::Get().GetCurrentFrame().CamerasStagingBuffer->Update();
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd) {
VkBufferCopy copy{ 0 };
copy.dstOffset = 0;
copy.srcOffset = 0;
copy.size = sizeof(CameraView) * MAX_CAMERAS;
vkCmdCopyBuffer(cmd, VkRenderer::Get().GetCurrentFrame().CamerasStagingBuffer->GetBuffer(), CamerasBuffer->GetBuffer(), 1, &copy);
CamerasBuffer->Update();
});
vmaUnmapMemory(allocator, VkRenderer::Get().GetCurrentFrame().CamerasStagingBuffer->GetAllocation());
// Update descriptor set for camera
VkDescriptorBufferInfo transformBufferInfo{};
transformBufferInfo.buffer = CamerasBuffer->GetBuffer();
transformBufferInfo.offset = 0;
transformBufferInfo.range = VK_WHOLE_SIZE;
VkWriteDescriptorSet bufferWriteModel = {};
bufferWriteModel.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
bufferWriteModel.pNext = nullptr;
bufferWriteModel.dstBinding = 0;
bufferWriteModel.dstSet = CamerasDescriptor;
bufferWriteModel.descriptorCount = 1;
bufferWriteModel.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
bufferWriteModel.pBufferInfo = &transformBufferInfo;
vkUpdateDescriptorSets(VkRenderer::Get().GetDevice(), 1, &bufferWriteModel, 0, nullptr);
const auto frameIndex = VkRenderer::Get().FrameNumber;
resourceDescriptors->UpdateBuffer<ResourceType::View>(frameIndex, Cameras.data(), Cameras.size() * sizeof(CameraView));
}
void GPUResources::UpdateBuffers()
{
//resourceDescriptors->UpdateBuffer<ResourceType::Tranform>(VkRenderer::Get().FrameNumber, ModelTransforms.Data.data(), ModelTransforms.Data.size() * sizeof(Matrix4));
// Tranforms
{
void* mappedData;
vmaMapMemory(VulkanAllocator::Get().GetAllocator(), (VkRenderer::Get().GetCurrentFrame().ModelStagingBuffer->GetAllocation()), &mappedData);
memcpy(mappedData, &ModelTransforms, sizeof(TransformData));
VkRenderer::Get().GetCurrentFrame().ModelStagingBuffer->Update();
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd) {
VkBufferCopy copy{ 0 };
copy.dstOffset = 0;
copy.srcOffset = 0;
copy.size = sizeof(TransformData);
vkCmdCopyBuffer(cmd, VkRenderer::Get().GetCurrentFrame().ModelStagingBuffer->GetBuffer(), ModelBuffer->GetBuffer(), 1, &copy);
ModelBuffer->Update();
});
vmaUnmapMemory(VulkanAllocator::Get().GetAllocator(), VkRenderer::Get().GetCurrentFrame().ModelStagingBuffer->GetAllocation());
// Update descriptor set for camera
VkDescriptorBufferInfo transformBufferInfo{};
transformBufferInfo.buffer = ModelBuffer->GetBuffer();
transformBufferInfo.offset = 0;
transformBufferInfo.range = VK_WHOLE_SIZE;
VkWriteDescriptorSet bufferWriteModel = {};
bufferWriteModel.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
bufferWriteModel.pNext = nullptr;
bufferWriteModel.dstBinding = 0;
bufferWriteModel.dstSet = ModelDescriptor;
bufferWriteModel.descriptorCount = 1;
bufferWriteModel.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
bufferWriteModel.pBufferInfo = &transformBufferInfo;
vkUpdateDescriptorSets(VkRenderer::Get().GetDevice(), 1, &bufferWriteModel, 0, nullptr);
}
//resourceDescriptors->UpdateBuffer<ResourceType::Material>(0, MaterialDataContainer.Data.data(), MaterialDataContainer.Data.size());
// Update material buffer
{
void* mappedData;
vmaMapMemory(VulkanAllocator::Get().GetAllocator(), (VkRenderer::Get().GetCurrentFrame().MaterialStagingBuffer->GetAllocation()), &mappedData);
memcpy(mappedData, &MaterialDataContainer, sizeof(MaterialData));
VkRenderer::Get().GetCurrentFrame().MaterialStagingBuffer->Update();
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd) {
VkBufferCopy copy{ 0 };
copy.dstOffset = 0;
copy.srcOffset = 0;
copy.size = sizeof(MaterialData);
vkCmdCopyBuffer(cmd, VkRenderer::Get().GetCurrentFrame().MaterialStagingBuffer->GetBuffer(), MaterialBuffer->GetBuffer(), 1, &copy);
MaterialBuffer->Update();
});
vmaUnmapMemory(VulkanAllocator::Get().GetAllocator(), VkRenderer::Get().GetCurrentFrame().MaterialStagingBuffer->GetAllocation());
// Update descriptor set for camera
VkDescriptorBufferInfo bufferInfo{};
bufferInfo.buffer = MaterialBuffer->GetBuffer();
bufferInfo.offset = 0;
bufferInfo.range = VK_WHOLE_SIZE;
VkWriteDescriptorSet bufferWrite = {};
bufferWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
bufferWrite.pNext = nullptr;
bufferWrite.dstBinding = 0;
bufferWrite.dstSet = MaterialDescriptor;
bufferWrite.descriptorCount = 1;
bufferWrite.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
bufferWrite.pBufferInfo = &bufferInfo;
bufferWrite.pImageInfo = VK_NULL_HANDLE;
vkUpdateDescriptorSets(VkRenderer::Get().GetDevice(), 1, &bufferWrite, 0, nullptr);
}
//resourceDescriptors->UpdateBuffer<ResourceType::Light>(0, LightDataContainerArray.Data.data(), LightDataContainerArray.Data.size());
// Lights
{
void* mappedData;
vmaMapMemory(VulkanAllocator::Get().GetAllocator(), (VkRenderer::Get().GetCurrentFrame().LightStagingBuffer->GetAllocation()), &mappedData);
memcpy(mappedData, &LightDataContainerArray, sizeof(LightDataContainer));
VkRenderer::Get().GetCurrentFrame().LightStagingBuffer->Update();
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd) {
VkBufferCopy copy{ 0 };
copy.dstOffset = 0;
copy.srcOffset = 0;
copy.size = sizeof(LightDataContainer);
vkCmdCopyBuffer(cmd, VkRenderer::Get().GetCurrentFrame().LightStagingBuffer->GetBuffer(), LightBuffer->GetBuffer(), 1, &copy);
LightBuffer->Update();
});
vmaUnmapMemory(VulkanAllocator::Get().GetAllocator(), VkRenderer::Get().GetCurrentFrame().LightStagingBuffer->GetAllocation());
// Update descriptor set for camera
VkDescriptorBufferInfo bufferInfo{};
bufferInfo.buffer = LightBuffer->GetBuffer();
bufferInfo.offset = 0;
bufferInfo.range = VK_WHOLE_SIZE;
VkWriteDescriptorSet bufferWrite = {};
bufferWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
bufferWrite.pNext = nullptr;
bufferWrite.dstBinding = 0;
bufferWrite.dstSet = LightsDescriptor;
bufferWrite.descriptorCount = 1;
bufferWrite.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
bufferWrite.pBufferInfo = &bufferInfo;
bufferWrite.pImageInfo = VK_NULL_HANDLE;
vkUpdateDescriptorSets(VkRenderer::Get().GetDevice(), 1, &bufferWrite, 0, nullptr);
}
auto frameIndex = VkRenderer::Get().FrameNumber;
resourceDescriptors->UpdateBuffer<ResourceType::Transform>(frameIndex, ModelTransforms.Data.data(), ModelTransforms.Data.size() * sizeof(Matrix4));
resourceDescriptors->UpdateBuffer<ResourceType::Material>(frameIndex, MaterialDataContainer.Data.data(), MaterialDataContainer.Data.size() * sizeof(MaterialBufferStruct));
resourceDescriptors->UpdateBuffer<ResourceType::Light>(frameIndex, LightDataContainerArray.Data.data(), LightDataContainerArray.Data.size() * sizeof(LightData));
}
std::vector<VkDescriptorSetLayout> GPUResources::GetBindlessLayout()