Commit 0db0041f authored by Lukas Tietze's avatar Lukas Tietze

Test f眉r Staged Buffer = Ok

parent 362950eb
......@@ -146,13 +146,12 @@ namespace lib
float, 4, vk::Format::eR32G32B32Sfloat,
float, 4, vk::Format::eR32G32B32Sfloat>;
using index_t = uint32_t;
std::vector<Buffer> uniformStagingBuffers;
std::vector<Buffer> uniformBuffers;
std::vector<Buffer> vertexBuffers;
std::vector<Buffer> indexBuffers;
std::unique_ptr<Buffer> materialsBuffer;
std::unique_ptr<Buffer> objectInstancesBuffer;
std::unique_ptr<Buffer> lightSourcesBuffer;
std::unique_ptr<StagedBuffer> lightSourcesBuffer;
std::unique_ptr<Texture> dummyTexture; // TODO: dummy
struct PushConstants
......
......@@ -91,7 +91,7 @@ namespace lib
void Destroy();
std::tuple<vk::Buffer, vk::DeviceMemory, vk::Buffer, vk::DeviceMemory> Disown();
void ScheduleTransfer(vk::CommandBuffer &commandBuffer) const;
void ScheduleTransfer(const vk::CommandBuffer &commandBuffer) const;
const vk::Buffer &GetDeviceBufferHandle() const;
const vk::DeviceMemory &GetDeviceMemoryHandle() const;
......
......@@ -1053,18 +1053,17 @@ bool lib::CgContext::TryLoadModel()
auto materialsStagingBuffer = this->CreateStagingSrcBuffer();
auto objectInstancesStagingBuffer = this->CreateStagingSrcBuffer();
auto lightSourcesStagingBuffer = this->CreateStagingSrcBuffer();
this->materialsBuffer = std::make_unique<Buffer>(this->CreateStagingDstBuffer(vk::BufferUsageFlagBits::eStorageBuffer));
this->objectInstancesBuffer = std::make_unique<Buffer>(this->CreateStagingDstBuffer(vk::BufferUsageFlagBits::eStorageBuffer));
this->lightSourcesBuffer = std::make_unique<Buffer>(this->CreateStagingDstBuffer(vk::BufferUsageFlagBits::eStorageBuffer));
this->lightSourcesBuffer = std::make_unique<StagedBuffer>(this->CreateStagedBuffer(vk::BufferUsageFlagBits::eStorageBuffer));
materialsStagingBuffer.BufferData(model.GetMaterials());
objectInstancesStagingBuffer.BufferData(instances);
lightSourcesStagingBuffer.BufferData(this->lightSources);
this->lightSourcesBuffer->BufferDataHostOnly(lightSources);
this->materialsBuffer->Allocate(materialsStagingBuffer.GetSize());
this->objectInstancesBuffer->Allocate(objectInstancesStagingBuffer.GetSize());
this->lightSourcesBuffer->Allocate(lightSourcesStagingBuffer.GetSize());
std::vector<Buffer> vertexStagingBuffers;
std::vector<Buffer> indexStagingBuffers;
......@@ -1099,7 +1098,7 @@ bool lib::CgContext::TryLoadModel()
materialsStagingBuffer.ScheduleCopyTo(commandBuffer, *this->materialsBuffer);
objectInstancesStagingBuffer.ScheduleCopyTo(commandBuffer, *this->objectInstancesBuffer);
lightSourcesStagingBuffer.ScheduleCopyTo(commandBuffer, *this->lightSourcesBuffer);
this->lightSourcesBuffer->ScheduleTransfer(commandBuffer);
commandBuffer.Run();
......@@ -1124,7 +1123,7 @@ bool lib::CgContext::TryLoadModel()
this->SetObjectName(this->objectInstancesBuffer->GetBufferHandle(), "instances");
this->SetObjectName(this->materialsBuffer->GetBufferHandle(), "materials");
this->SetObjectName(this->lightSourcesBuffer->GetBufferHandle(), "lights");
this->SetObjectName(this->lightSourcesBuffer->GetDeviceBufferHandle(), "lights");
for (size_t i = 0; i < this->vertexBuffers.size(); i++)
{
......@@ -1414,7 +1413,7 @@ void lib::CgContext::CreateDescriptorSets()
objectInstanceWrite.pBufferInfo = &objectInstanceInfo;
vk::DescriptorBufferInfo lightSourcesInfo;
lightSourcesInfo.buffer = this->lightSourcesBuffer->GetBufferHandle();
lightSourcesInfo.buffer = this->lightSourcesBuffer->GetDeviceBufferHandle();
lightSourcesInfo.range = VK_WHOLE_SIZE;
vk::WriteDescriptorSet lightSourcesWrite;
......
......@@ -160,10 +160,10 @@ void lib::StagedBuffer::Allocate(vk::DeviceSize size)
vk::MemoryPropertyFlagBits::eDeviceLocal);
this->deviceMemory = this->parent->GetLogicalDevice().allocateMemory(vk::MemoryAllocateInfo(deviceMemoryRequirements.size, deviceMemoryType));
this->parent->GetLogicalDevice().bindBufferMemory(this->hostBuffer, this->hostMemory, 0);
this->parent->GetLogicalDevice().bindBufferMemory(this->deviceBuffer, this->deviceMemory, 0);
}
void lib::StagedBuffer::ScheduleTransfer(vk::CommandBuffer &commandBuffer) const
void lib::StagedBuffer::ScheduleTransfer(const vk::CommandBuffer &commandBuffer) const
{
vk::BufferCopy copy;
copy.size = this->size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment