Text Rendering works
This commit is contained in:
@@ -90,10 +90,9 @@ PSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
for (auto it : freeRanges)
|
||||
for (auto& [allocatedOffset, freeAllocation] : freeRanges)
|
||||
{
|
||||
PSubAllocation freeAllocation = it.value;
|
||||
VkDeviceSize allocatedOffset = freeAllocation->allocatedOffset;
|
||||
assert(allocatedOffset == freeAllocation->allocatedOffset);
|
||||
VkDeviceSize alignedOffset = align(allocatedOffset, alignment);
|
||||
VkDeviceSize alignmentAdjustment = alignedOffset - allocatedOffset;
|
||||
VkDeviceSize size = alignmentAdjustment + requestedSize;
|
||||
@@ -112,8 +111,8 @@ PSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
|
||||
freeAllocation->alignedOffset += size;
|
||||
PSubAllocation subAlloc = new SubAllocation(this, allocatedOffset, size, alignedOffset, size);
|
||||
activeAllocations[allocatedOffset] = subAlloc.getHandle();
|
||||
freeRanges.erase(allocatedOffset);
|
||||
freeRanges[freeAllocation->allocatedOffset] = freeAllocation;
|
||||
freeRanges.erase(allocatedOffset);
|
||||
bytesUsed += size;
|
||||
return subAlloc;
|
||||
}
|
||||
@@ -136,9 +135,8 @@ void Allocation::markFree(SubAllocation *allocation)
|
||||
{
|
||||
std::scoped_lock lck(lock);
|
||||
//Join lower bound
|
||||
for (auto freeRange : freeRanges)
|
||||
for (auto& [allocatedOffset, freeAlloc] : freeRanges)
|
||||
{
|
||||
PSubAllocation freeAlloc = freeRange.value;
|
||||
if (freeAlloc->allocatedOffset <= lowerBound
|
||||
&& freeAlloc->allocatedOffset + freeAlloc->allocatedSize >= upperBound)
|
||||
{
|
||||
@@ -157,24 +155,24 @@ void Allocation::markFree(SubAllocation *allocation)
|
||||
auto foundAlloc = freeRanges.find(upperBound);
|
||||
if (foundAlloc != freeRanges.end())
|
||||
{
|
||||
freeRangeToDelete = foundAlloc->value;
|
||||
freeRangeToDelete = foundAlloc->second;
|
||||
// There is a free allocation ending where the new free one ends
|
||||
if (allocHandle != nullptr)
|
||||
{
|
||||
// extend allocHandle by another foundAlloc->allocatedSize bytes
|
||||
allocHandle->allocatedSize += foundAlloc->value->allocatedSize;
|
||||
freeRanges.erase(foundAlloc->key);
|
||||
allocHandle->allocatedSize += foundAlloc->second->allocatedSize;
|
||||
freeRanges.erase(foundAlloc->first);
|
||||
}
|
||||
else
|
||||
{
|
||||
// set foundAlloc back by size amount
|
||||
allocHandle = foundAlloc->value;
|
||||
allocHandle = foundAlloc->second;
|
||||
allocHandle->allocatedOffset -= allocation->allocatedSize;
|
||||
allocHandle->alignedOffset -= allocation->allocatedSize;
|
||||
// place back at correct offset
|
||||
freeRanges[allocHandle->allocatedOffset] = allocHandle;
|
||||
// remove from offset map since key changes
|
||||
freeRanges.erase(foundAlloc->key);
|
||||
freeRanges.erase(foundAlloc->first);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +257,7 @@ void Allocator::free(Allocation *allocation)
|
||||
{
|
||||
if (heap.allocations[i] == allocation)
|
||||
{
|
||||
heap.allocations.remove(i, false);
|
||||
heap.allocations.removeAt(i, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +99,8 @@ private:
|
||||
VkDeviceSize bytesAllocated;
|
||||
VkDeviceSize bytesUsed;
|
||||
VkDeviceMemory allocatedMemory;
|
||||
Map<VkDeviceSize, SubAllocation *> activeAllocations;
|
||||
Map<VkDeviceSize, PSubAllocation> freeRanges;
|
||||
std::map<VkDeviceSize, SubAllocation *> activeAllocations;
|
||||
std::map<VkDeviceSize, PSubAllocation> freeRanges;
|
||||
std::mutex lock;
|
||||
void *mappedPointer;
|
||||
uint8 isDedicated : 1;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "VulkanGraphics.h"
|
||||
#include "VulkanCommandBuffer.h"
|
||||
#include "VulkanAllocator.h"
|
||||
#include "ThreadPool.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
@@ -65,11 +64,11 @@ ShaderBuffer::~ShaderBuffer()
|
||||
{
|
||||
PCmdBuffer cmdBuffer = graphics->getQueueCommands(owner)->getCommands();
|
||||
VkDevice device = graphics->getDevice();
|
||||
auto deletionLambda = [cmdBuffer, device](VkBuffer buffer) -> Job
|
||||
auto deletionLambda = [cmdBuffer, device](VkBuffer buffer) -> void
|
||||
{
|
||||
//co_await cmdBuffer->asyncWait();
|
||||
//vkDestroyBuffer(device, buffer, nullptr);
|
||||
co_return;
|
||||
//co_return;
|
||||
};
|
||||
for (uint32 i = 0; i < numBuffers; ++i)
|
||||
{
|
||||
@@ -355,7 +354,7 @@ VkAccessFlags UniformBuffer::getDestAccessMask()
|
||||
}
|
||||
|
||||
StructuredBuffer::StructuredBuffer(PGraphics graphics, const StructuredBufferCreateInfo &resourceData)
|
||||
: Gfx::StructuredBuffer(graphics->getFamilyMapping(), resourceData.resourceData)
|
||||
: Gfx::StructuredBuffer(graphics->getFamilyMapping(), resourceData.stride, resourceData.resourceData)
|
||||
, Vulkan::ShaderBuffer(graphics, resourceData.resourceData.size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, currentOwner, resourceData.bDynamic)
|
||||
{
|
||||
if (resourceData.resourceData.data != nullptr)
|
||||
|
||||
@@ -250,6 +250,7 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
|
||||
{
|
||||
assert(threadId == std::this_thread::get_id());
|
||||
auto descriptor = descriptorSet.cast<DescriptorSet>();
|
||||
assert(descriptor->writeDescriptors.size() == 0);
|
||||
boundDescriptors.add(descriptor.getHandle());
|
||||
descriptor->bind();
|
||||
|
||||
@@ -263,6 +264,7 @@ void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorS
|
||||
for(uint32 i = 0; i < descriptorSets.size(); ++i)
|
||||
{
|
||||
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
|
||||
assert(descriptorSet->writeDescriptors.size() == 0);
|
||||
descriptorSet->bind();
|
||||
|
||||
boundDescriptors.add(descriptorSet.getHandle());
|
||||
@@ -370,6 +372,7 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
|
||||
{
|
||||
assert(threadId == std::this_thread::get_id());
|
||||
auto descriptor = descriptorSet.cast<DescriptorSet>();
|
||||
assert(descriptor->writeDescriptors.size() == 0);
|
||||
boundDescriptors.add(descriptor.getHandle());
|
||||
descriptor->bind();
|
||||
|
||||
@@ -384,9 +387,11 @@ void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptor
|
||||
for(uint32 i = 0; i < descriptorSets.size(); ++i)
|
||||
{
|
||||
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
|
||||
boundDescriptors.add(descriptorSet.getHandle());
|
||||
assert(descriptorSet->writeDescriptors.size() == 0);
|
||||
descriptorSet->bind();
|
||||
|
||||
//std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl;
|
||||
boundDescriptors.add(descriptorSet.getHandle());
|
||||
sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle();
|
||||
}
|
||||
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, 0, nullptr);
|
||||
|
||||
@@ -139,9 +139,9 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu
|
||||
cachedData[binding] = new UniformBuffer(*vulkanBuffer.getHandle());
|
||||
}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PStructuredBuffer uniformBuffer)
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PStructuredBuffer structuredBuffer)
|
||||
{
|
||||
PStructuredBuffer vulkanBuffer = uniformBuffer.cast<StructuredBuffer>();
|
||||
PStructuredBuffer vulkanBuffer = structuredBuffer.cast<StructuredBuffer>();
|
||||
StructuredBuffer* cachedBuffer = reinterpret_cast<StructuredBuffer*>(cachedData[binding]);
|
||||
if(vulkanBuffer.getHandle() == cachedBuffer)
|
||||
{
|
||||
@@ -330,7 +330,7 @@ void DescriptorAllocator::allocateDescriptorSet(Gfx::PDescriptorSet &descriptorS
|
||||
uint32 counts = 0;
|
||||
for(const auto& binding : layout.bindings)
|
||||
{
|
||||
if(binding.binding & Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT)
|
||||
if(binding.descriptorCount > 0)
|
||||
{
|
||||
counts = binding.descriptorCount;
|
||||
}
|
||||
|
||||
@@ -119,6 +119,8 @@ private:
|
||||
bool currentlyInUse;
|
||||
friend class DescriptorAllocator;
|
||||
friend class CmdBuffer;
|
||||
friend class RenderCommand;
|
||||
friend class ComputeCommand;
|
||||
};
|
||||
DEFINE_REF(DescriptorSet)
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
thread_local PCommandBufferManager Seele::Vulkan::Graphics::graphicsCommands = nullptr;
|
||||
@@ -570,7 +571,7 @@ void Graphics::createDevice(GraphicsInitializer initializer)
|
||||
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV |
|
||||
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV |
|
||||
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV;
|
||||
deviceInfo.pNext = &crashDiagInfo;
|
||||
descriptorIndexing.pNext = &crashDiagInfo;
|
||||
#endif
|
||||
deviceInfo.enabledExtensionCount = (uint32)initializer.deviceExtensions.size();
|
||||
deviceInfo.ppEnabledExtensionNames = initializer.deviceExtensions.data();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "VulkanGraphicsEnums.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
using namespace Seele::Gfx;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ Semaphore::~Semaphore()
|
||||
|
||||
Fence::Fence(PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
, signaled("Fence")
|
||||
, signaled(false)
|
||||
{
|
||||
VkFenceCreateInfo info =
|
||||
init::FenceCreateInfo(0);
|
||||
@@ -45,8 +45,8 @@ bool Fence::isSignaled()
|
||||
switch (res)
|
||||
{
|
||||
case VK_SUCCESS:
|
||||
signaled.raise();
|
||||
return true;
|
||||
signaled = true;
|
||||
return signaled;
|
||||
case VK_NOT_READY:
|
||||
break;
|
||||
default:
|
||||
@@ -60,7 +60,7 @@ void Fence::reset()
|
||||
if (signaled)
|
||||
{
|
||||
vkResetFences(graphics->getDevice(), 1, &fence);
|
||||
signaled.reset();
|
||||
signaled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ void Fence::wait(uint32 timeout)
|
||||
switch (r)
|
||||
{
|
||||
case VK_SUCCESS:
|
||||
signaled.raise();
|
||||
signaled = true;
|
||||
break;
|
||||
case VK_TIMEOUT:
|
||||
break;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <functional>
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
#include "VulkanAllocator.h"
|
||||
#include "ThreadPool.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -43,10 +42,10 @@ public:
|
||||
return fence;
|
||||
}
|
||||
void wait(uint32 timeout);
|
||||
Event& operator co_await()
|
||||
/*Event& operator co_await()
|
||||
{
|
||||
return signaled;
|
||||
}
|
||||
}*/
|
||||
bool operator<(const Fence &other) const
|
||||
{
|
||||
return fence < other.fence;
|
||||
@@ -54,7 +53,7 @@ public:
|
||||
|
||||
private:
|
||||
PGraphics graphics;
|
||||
Event signaled;
|
||||
bool signaled;
|
||||
VkFence fence;
|
||||
};
|
||||
DEFINE_REF(Fence)
|
||||
@@ -357,6 +356,11 @@ public:
|
||||
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
|
||||
virtual void setCloseCallback(std::function<void()> callback);
|
||||
|
||||
VkFormat getPixelFormat() const
|
||||
{
|
||||
return cast(windowState.pixelFormat);
|
||||
}
|
||||
|
||||
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
|
||||
std::function<void(double, double)> mouseMoveCallback;
|
||||
std::function<void(MouseButton, InputAction, KeyModifier)> mouseButtonCallback;
|
||||
@@ -381,7 +385,6 @@ protected:
|
||||
VkInstance instance;
|
||||
VkSwapchainKHR swapchain;
|
||||
VkSampleCountFlags numSamples;
|
||||
VkFormat pixelFormat;
|
||||
VkPresentModeKHR presentMode;
|
||||
VkSurfaceKHR surface;
|
||||
VkSurfaceFormatKHR surfaceFormat;
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "VulkanGraphicsEnums.h"
|
||||
#include "VulkanAllocator.h"
|
||||
#include "VulkanCommandBuffer.h"
|
||||
#include "ThreadPool.h"
|
||||
#include <math.h>
|
||||
|
||||
using namespace Seele;
|
||||
@@ -162,21 +161,21 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType,
|
||||
|
||||
TextureHandle::~TextureHandle()
|
||||
{
|
||||
auto cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands();
|
||||
VkDevice device = graphics->getDevice();
|
||||
VkImageView view = defaultView;
|
||||
VkImage img = image;
|
||||
auto deletionLambda = [cmdBuffer, device, view, img]() -> Job
|
||||
{
|
||||
//vkDestroyImageView(device, view, nullptr);
|
||||
//vkDestroyImage(device, img, nullptr);
|
||||
co_return;
|
||||
};
|
||||
deletionLambda();
|
||||
//auto cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands();
|
||||
//VkDevice device = graphics->getDevice();
|
||||
//VkImageView view = defaultView;
|
||||
//VkImage img = image;
|
||||
//vkDestroyImageView(device, view, nullptr);
|
||||
//vkDestroyImage(device, img, nullptr);
|
||||
//co_return;
|
||||
}
|
||||
|
||||
TextureHandle* TextureBase::cast(Gfx::PTexture texture)
|
||||
{
|
||||
if(texture == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
if(texture->getTexture2D() != nullptr)
|
||||
{
|
||||
PTexture2D texture2D = texture.cast<Texture2D>();
|
||||
|
||||
@@ -50,7 +50,6 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
|
||||
, instance(graphics->getInstance())
|
||||
, swapchain(VK_NULL_HANDLE)
|
||||
, numSamples(createInfo.numSamples)
|
||||
, pixelFormat(cast(createInfo.pixelFormat))
|
||||
{
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
GLFWwindow *handle = glfwCreateWindow(createInfo.width, createInfo.height, createInfo.title, createInfo.bFullscreen ? glfwGetPrimaryMonitor() : nullptr, nullptr);
|
||||
@@ -194,11 +193,7 @@ void Window::advanceBackBuffer()
|
||||
void Window::recreateSwapchain(const WindowCreateInfo &windowInfo)
|
||||
{
|
||||
destroySwapchain();
|
||||
sizeX = windowInfo.width;
|
||||
sizeY = windowInfo.height;
|
||||
pixelFormat = cast(windowInfo.pixelFormat);
|
||||
bFullscreen = windowInfo.bFullscreen;
|
||||
|
||||
windowState = windowInfo;
|
||||
uint32_t numFormats;
|
||||
VK_CHECK(vkGetPhysicalDeviceSurfaceFormatsKHR(graphics->getPhysicalDevice(), surface, &numFormats, nullptr));
|
||||
Array<VkSurfaceFormatKHR> formats(numFormats);
|
||||
@@ -234,6 +229,10 @@ void Window::present()
|
||||
while (presentResult != VK_SUCCESS)
|
||||
{
|
||||
presentResult = vkQueuePresentKHR(graphics->getGraphicsCommands()->getQueue()->getHandle(), &info);
|
||||
if(presentResult == VK_ERROR_OUT_OF_DATE_KHR)
|
||||
{
|
||||
recreateSwapchain(windowState);
|
||||
}
|
||||
}
|
||||
Gfx::currentFrameIndex = (Gfx::currentFrameIndex + 1)%Gfx::numFramesBuffered;
|
||||
static double lastFrameTime = 0.f;
|
||||
@@ -259,8 +258,8 @@ void Window::createSwapchain()
|
||||
}
|
||||
|
||||
VkExtent2D extent;
|
||||
extent.width = sizeX;
|
||||
extent.height = sizeY;
|
||||
extent.width = getSizeX();
|
||||
extent.height = getSizeY();
|
||||
VkSwapchainCreateInfoKHR swapchainInfo =
|
||||
init::SwapchainCreateInfo(
|
||||
surface,
|
||||
@@ -283,8 +282,8 @@ void Window::createSwapchain()
|
||||
|
||||
|
||||
TextureCreateInfo backBufferCreateInfo;
|
||||
backBufferCreateInfo.width = sizeX;
|
||||
backBufferCreateInfo.height = sizeY;
|
||||
backBufferCreateInfo.width = getSizeX();
|
||||
backBufferCreateInfo.height = getSizeY();
|
||||
backBufferCreateInfo.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
backBufferCreateInfo.resourceData.owner = Gfx::QueueType::GRAPHICS;
|
||||
backBufferCreateInfo.format = cast(surfaceFormat.format);
|
||||
|
||||
Reference in New Issue
Block a user