Commit d84e9f89 authored by Lukas Tietze's avatar Lukas Tietze

Bugfixes

parent 7070d28f
......@@ -13,15 +13,18 @@ namespace lib
struct TextureCreateInfo
{
inline TextureCreateInfo(vk::Format format = vk::Format{},
inline TextureCreateInfo(std::vector<uint32_t> queueFamilyIndices = {},
vk::Format format = vk::Format{},
vk::ImageUsageFlags usage = vk::ImageUsageFlagBits{},
vk::ImageLayout layout = vk::ImageLayout{})
: format(format),
: queueFamilyIndices(queueFamilyIndices),
format(format),
usage(usage),
layout(layout)
{
}
std::vector<uint32_t> queueFamilyIndices;
vk::Format format;
vk::ImageUsageFlags usage;
vk::ImageLayout layout;
......
......@@ -204,7 +204,7 @@ void lib::CgContext::CreateRaytracingDescriptorSets()
vk::DescriptorBufferInfo camInfo;
camInfo.buffer = frame.ubo->GetDeviceBufferHandle();
camInfo.range = sizeof(SceneDescription);
camInfo.range = VK_WHOLE_SIZE;
vk::WriteDescriptorSet camWrite;
camWrite.dstSet = frame.descriptorSet;
......
......@@ -1048,31 +1048,54 @@ void lib::CgContext::DrawFrame(lib::time_diff_t delta)
void lib::CgContext::LoadDummyTexture()
{
this->dummyTexture.reset(new lib::Texture{this, 256, 256, [](uint32_t x, uint32_t y) {
auto rx = x / 255.f;
auto ry = y / 255.f;
auto r = static_cast<uint8_t>(rx * 255);
auto g = static_cast<uint8_t>(rx * 255);
auto b = static_cast<uint8_t>(rx * 255);
auto a = uint8_t{255};
return (uint32_t{r} << 24) |
(uint32_t{g} << 16) |
(uint32_t{b} << 8) |
(uint32_t{a} << 0);
},
lib::TextureCreateInfo{vk::Format::eR8G8B8A8Srgb, vk::ImageUsageFlagBits::eSampled, vk::ImageLayout::eShaderReadOnlyOptimal}});
lib::TextureCreateInfo createInfo{{
this->physicalDeviceInfo.GetGraphicsQueueFamily(),
this->physicalDeviceInfo.GetBufferStagingQueueFamily(),
this->physicalDeviceInfo.GetComputeQueueFamily(),
this->physicalDeviceInfo.GetPresentationQueueFamily(),
},
vk::Format::eR8G8B8A8Srgb,
vk::ImageUsageFlagBits::eSampled,
vk::ImageLayout::eShaderReadOnlyOptimal};
auto newTexture = new lib::Texture{this, 256, 256, [](uint32_t x, uint32_t y) {
auto rx = x / 255.f;
auto ry = y / 255.f;
auto r = static_cast<uint8_t>(rx * 255);
auto g = static_cast<uint8_t>(rx * 255);
auto b = static_cast<uint8_t>(rx * 255);
auto a = uint8_t{255};
return (uint32_t{r} << 24) |
(uint32_t{g} << 16) |
(uint32_t{b} << 8) |
(uint32_t{a} << 0);
},
createInfo};
this->dummyTexture.reset(newTexture);
for (auto &frame : this->frames)
{
frame.raytracingTexture.reset(new lib::Texture{this,
this->swapChainExtent.width,
this->swapChainExtent.height,
lib::TextureCreateInfo{
this->swapChainImageFormat,
vk::ImageUsageFlagBits::eStorage,
vk::ImageLayout::eGeneral}});
const lib::TextureCreateInfo textureCreateInfo{
{
this->physicalDeviceInfo.GetGraphicsQueueFamily(),
this->physicalDeviceInfo.GetBufferStagingQueueFamily(),
this->physicalDeviceInfo.GetComputeQueueFamily(),
this->physicalDeviceInfo.GetPresentationQueueFamily(),
},
this->swapChainImageFormat,
vk::ImageUsageFlagBits::eStorage | vk::ImageUsageFlagBits::eColorAttachment,
vk::ImageLayout::eGeneral};
auto newTexture = new lib::Texture{this,
this->swapChainExtent.width,
this->swapChainExtent.height,
textureCreateInfo};
frame.raytracingTexture.reset(newTexture);
vk::FramebufferCreateInfo createInfo;
createInfo.renderPass = this->rasterizationStep.renderPass;
createInfo.attachmentCount = 1;
......
......@@ -150,7 +150,7 @@ void lib::StagedBuffer::Allocate(vk::DeviceSize size)
deviceCreateInfo.sharingMode = this->sharingMode;
deviceCreateInfo.size = this->size;
this->deviceBuffer = this->parent->GetLogicalDevice().createBuffer(hostCreateInfo);
this->deviceBuffer = this->parent->GetLogicalDevice().createBuffer(deviceCreateInfo);
auto deviceMemoryRequirements = this->parent->GetLogicalDevice().getBufferMemoryRequirements(this->deviceBuffer);
auto deviceMemoryProperties = this->parent->GetPhysicalDeviceInfo().GetHandle().getMemoryProperties();
......
......@@ -2,6 +2,7 @@
#include "VkUtil/Texture.hpp"
#include "stb_image.h"
#include "VkUtil/VkUtil.hpp"
#include "Util/Utils.hpp"
lib::Texture::Texture(CgContext *parent, uint32_t width, uint32_t height, const TextureCreateInfo &createInfo)
: parent(parent)
......@@ -66,6 +67,9 @@ lib::Texture::~Texture()
void lib::Texture::LoadData(uint32_t width, uint32_t height, const void *data, uint8_t pixelByteCount, const TextureCreateInfo &createInfo)
{
auto queueFamilyIndices = createInfo.queueFamilyIndices;
lib::FilterUnique(queueFamilyIndices);
std::unique_ptr<lib::Buffer> stagingBuffer;
const auto loadInitialData = data && pixelByteCount;
......@@ -87,9 +91,11 @@ void lib::Texture::LoadData(uint32_t width, uint32_t height, const void *data, u
imageCreateInfo.format = createInfo.format;
imageCreateInfo.tiling = vk::ImageTiling::eOptimal;
imageCreateInfo.initialLayout = vk::ImageLayout::eUndefined;
imageCreateInfo.sharingMode = vk::SharingMode::eExclusive;
imageCreateInfo.sharingMode = queueFamilyIndices.size() > 1 ? vk::SharingMode::eConcurrent : vk::SharingMode::eExclusive;
imageCreateInfo.samples = vk::SampleCountFlagBits::e1;
imageCreateInfo.usage = createInfo.usage;
imageCreateInfo.queueFamilyIndexCount = static_cast<uint32_t>(queueFamilyIndices.size());
imageCreateInfo.pQueueFamilyIndices = queueFamilyIndices.data();
if (loadInitialData)
{
......@@ -113,7 +119,7 @@ void lib::Texture::LoadData(uint32_t width, uint32_t height, const void *data, u
device.bindImageMemory(this->image, this->memory, 0);
auto commandBuffer = this->parent->AllocateSingleUseStagingCommandBuffer();
auto commandBuffer = this->parent->AllocateSingleUseComputeCommandBuffer();
if (loadInitialData)
{
......
......@@ -33,6 +33,8 @@ void lib::TransitionImageLayout(vk::CommandBuffer commandBuffer,
barrier.newLayout = newLayout;
barrier.image = image;
barrier.subresourceRange = subresourceRange;
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
commandBuffer.pipelineBarrier(srcStage, dstStage, vk::DependencyFlagBits::eByRegion,
{}, {}, barrier);
......
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