Commit 362950eb authored by Lukas Tietze's avatar Lukas Tietze

Textur und Test f眉r StagedBuffer

parent c6fa53e5
......@@ -15,6 +15,7 @@
#include "Util/NameList.hpp"
#include "VkUtil/BottomLevelAccelerationStructure.hpp"
#include "VkUtil/Buffer.hpp"
#include "VkUtil/StagedBuffer.hpp"
#include "VkUtil/OneTimeCommandBuffer.hpp"
#include "VkUtil/Shader.hpp"
#include "VkUtil/TopLevelAccelerationStructure.hpp"
......@@ -181,6 +182,7 @@ namespace lib
const uint32_t lightSources = 5;
const uint32_t vertices = 6;
const uint32_t indices = 7;
const uint32_t dummyTexture = 8;
} const descriptorBindings;
struct
......@@ -276,6 +278,8 @@ namespace lib
const vk::SurfaceKHR &GetSurface() const;
void SetShowUi(bool show);
lib::StagedBuffer CreateStagedBuffer(vk::BufferUsageFlags usageFlags);
lib::Buffer CreateBuffer(vk::BufferUsageFlags usageFlags, vk::MemoryPropertyFlags memoryFlags);
lib::Buffer CreateHostBuffer(vk::BufferUsageFlags usageFlags);
lib::Buffer CreateDeviceBuffer(vk::BufferUsageFlags usageFlags);
......
......@@ -202,6 +202,18 @@ void lib::CgContext::ReloadModel()
this->swapChainDirty = true;
}
lib::StagedBuffer lib::CgContext::CreateStagedBuffer(vk::BufferUsageFlags usageFlags)
{
return lib::StagedBuffer{
this,
{this->physicalDeviceInfo.GetGraphicsQueueFamily(),
this->physicalDeviceInfo.GetBufferStagingQueueFamily(),
this->physicalDeviceInfo.GetComputeQueueFamily(),
this->physicalDeviceInfo.GetPresentationQueueFamily()},
usageFlags,
vk::MemoryPropertyFlagBits{}};
}
lib::Buffer lib::CgContext::CreateBuffer(vk::BufferUsageFlags usageFlags, vk::MemoryPropertyFlags memoryFlags)
{
return lib::Buffer(
......
......@@ -145,9 +145,9 @@ lib::CgContext::~CgContext()
this->CleanupSwapChain();
this->CleanupModel();
if (this->descriptorSetLayout)
if (this->dummyTexture)
{
this->logicalDevice.destroyDescriptorSetLayout(this->descriptorSetLayout);
this->dummyTexture.reset();
}
for (auto &uniformBuffer : this->uniformStagingBuffers)
......@@ -155,6 +155,11 @@ lib::CgContext::~CgContext()
uniformBuffer.Destroy();
}
if (this->descriptorSetLayout)
{
this->logicalDevice.destroyDescriptorSetLayout(this->descriptorSetLayout);
}
for (auto &uniformBuffer : this->uniformBuffers)
{
uniformBuffer.Destroy();
......@@ -718,6 +723,7 @@ void lib::CgContext::UpdateCommandBuffer(uint32_t imageIndex)
commandBuffer.copyBuffer(this->uniformStagingBuffers[imageIndex].GetBufferHandle(),
this->uniformBuffers[imageIndex].GetBufferHandle(),
vk::BufferCopy(0, 0, this->uniformBuffers[imageIndex].GetSize()));
// this->uniformBuffers[imageIndex].ScheduleTransfer(commandBuffer);
commandBuffer.pushConstants(this->pipelineLayout,
vk::ShaderStageFlagBits::eRaygenNV | vk::ShaderStageFlagBits::eClosestHitNV,
......@@ -904,10 +910,10 @@ vk::ShaderModule lib::CgContext::LoadShader(const ShaderInfo &info)
void lib::CgContext::UpdateUniformBuffers(uint32_t imageIndex, lib::time_diff_t delta)
{
this->camera.UpdateMatrices();
this->uniformStagingBuffers[imageIndex].BufferData(SceneDescription(
this->uniformStagingBuffers[imageIndex].BufferData(SceneDescription{
this->camera.GetModel(),
static_cast<uint32_t>(this->lightSources.size()),
this->clearColor));
this->clearColor});
}
void lib::CgContext::BeginFrame()
......@@ -1149,6 +1155,14 @@ void lib::CgContext::CreateUniformBuffers()
for (int i = 0; i < bufferCount; i++)
{
const auto name = "UBO" + std::to_string(i);
// this->uniformBuffers.emplace_back(std::move(this->CreateStagedBuffer(vk::BufferUsageFlagBits::eUniformBuffer)));
// this->uniformBuffers.back().AllocateFor<SceneDescription>();
// this->SetObjectName(this->uniformBuffers.back().GetHostBufferHandle(), name + "[Host]");
// this->SetObjectName(this->uniformBuffers.back().GetDeviceBufferHandle(), name + "[Device]");
// this->UpdateUniformBuffers(i, time_diff_t());
this->uniformStagingBuffers.emplace_back(std::move(this->CreateStagingSrcBuffer()));
this->uniformStagingBuffers.back().AllocateFor<SceneDescription>();
this->SetObjectName(this->uniformStagingBuffers[i].GetBufferHandle(), "Uniform staging buffer " + std::to_string(i));
......@@ -1247,6 +1261,11 @@ void lib::CgContext::CreateDescriptorSetLayout()
layoutBindings.back().stageFlags = vk::ShaderStageFlagBits::eClosestHitNV;
// dummy texture
layoutBindings.emplace_back();
layoutBindings.back().binding = this->descriptorBindings.dummyTexture;
layoutBindings.back().descriptorCount = 1;
layoutBindings.back().descriptorType = vk::DescriptorType::eCombinedImageSampler;
layoutBindings.back().stageFlags = vk::ShaderStageFlagBits::eClosestHitNV | vk::ShaderStageFlagBits::eRaygenNV;
vk::DescriptorSetLayoutCreateInfo createInfo;
createInfo.bindingCount = static_cast<uint32_t>(layoutBindings.size());
......@@ -1275,6 +1294,8 @@ void lib::CgContext::CreateDescriptorPool()
vk::DescriptorPoolSize(vk::DescriptorType::eStorageBuffer, count * static_cast<uint32_t>(this->vertexBuffers.size())),
// indices
vk::DescriptorPoolSize(vk::DescriptorType::eStorageBuffer, count * static_cast<uint32_t>(this->indexBuffers.size())),
// dummy texture
vk::DescriptorPoolSize(vk::DescriptorType::eCombinedImageSampler, count),
};
vk::DescriptorPoolCreateInfo createInfo;
......@@ -1404,16 +1425,29 @@ void lib::CgContext::CreateDescriptorSets()
lightSourcesWrite.descriptorCount = 1;
lightSourcesWrite.pBufferInfo = &lightSourcesInfo;
std::vector<vk::WriteDescriptorSet> writes = {accelerationStructureWrite.get<vk::WriteDescriptorSet>(),
outputImageWrite,
camWrite,
vertexBufferWrite,
indexBufferWrite,
materialBufferWrite,
objectInstanceWrite,
lightSourcesWrite};
this->logicalDevice.updateDescriptorSets(writes, {});
vk::DescriptorImageInfo dummyTextureInfo;
dummyTextureInfo.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal;
dummyTextureInfo.imageView = this->dummyTexture->GetView();
dummyTextureInfo.sampler = this->dummyTexture->GetSampler();
vk::WriteDescriptorSet dummyTextureWrite;
dummyTextureWrite.dstSet = this->descriptorSets[i];
dummyTextureWrite.dstBinding = this->descriptorBindings.dummyTexture;
dummyTextureWrite.dstArrayElement = 0;
dummyTextureWrite.descriptorType = vk::DescriptorType::eCombinedImageSampler;
dummyTextureWrite.descriptorCount = 1;
dummyTextureWrite.pImageInfo = &dummyTextureInfo;
this->logicalDevice.updateDescriptorSets({accelerationStructureWrite.get<vk::WriteDescriptorSet>(),
outputImageWrite,
camWrite,
vertexBufferWrite,
indexBufferWrite,
materialBufferWrite,
objectInstanceWrite,
lightSourcesWrite,
dummyTextureWrite},
{});
}
Log("Successfully created raytracing descriptor set!");
......
......@@ -11,12 +11,14 @@ lib::Buffer::Buffer(CgContext *parent,
: parent(parent),
familyIndices(familyIndices),
bufferUsageFlags(bufferUsageFlags),
memoryPropertyFlags(memoryPropertyFlags),
sharingMode(familyIndices.size() > 1
? vk::SharingMode::eConcurrent
: vk::SharingMode::eExclusive)
memoryPropertyFlags(memoryPropertyFlags)
{
lib::FilterUnique(this->familyIndices);
this->sharingMode = familyIndices.size() > 1
? vk::SharingMode::eConcurrent
: vk::SharingMode::eExclusive;
}
lib::Buffer::~Buffer()
......
......@@ -10,12 +10,13 @@ lib::StagedBuffer::StagedBuffer(CgContext *parent,
: parent(parent),
familyIndices(familyIndices),
bufferUsageFlags(bufferUsageFlags),
memoryPropertyFlags(memoryPropertyFlags),
sharingMode(familyIndices.size() > 1
? vk::SharingMode::eConcurrent
: vk::SharingMode::eExclusive)
memoryPropertyFlags(memoryPropertyFlags)
{
lib::FilterUnique(this->familyIndices);
this->sharingMode = familyIndices.size() > 1
? vk::SharingMode::eConcurrent
: vk::SharingMode::eExclusive;
}
lib::StagedBuffer::~StagedBuffer()
......
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