1
0
Fork 0
This commit is contained in:
May B. 2020-10-17 22:50:52 +02:00
parent 623cbb8724
commit c7da6fbcc0
5 changed files with 21 additions and 22 deletions

View File

@ -1,7 +1,6 @@
#include "Allocator.hpp" #include "Allocator.hpp"
#include "PhysicalDeviceInfo.hpp" #include "PhysicalDeviceInfo.hpp"
#include <TracyVulkan.hpp>
#include <memory.h> #include <memory.h>
#include <cassert> #include <cassert>
@ -49,7 +48,6 @@ Allocator::Allocator(VkDevice device, const PhysicalDeviceInfo &info): physicalD
allocInfo.commandBufferCount = 1; allocInfo.commandBufferCount = 1;
vkAllocateCommandBuffers(device, &allocInfo, &transferBuffer); vkAllocateCommandBuffers(device, &allocInfo, &transferBuffer);
tracyCtx = TracyVkContext(info.device, device, transferQueue, transferBuffer);
} }
{ // Graphics { // Graphics
vkGetDeviceQueue(device, info.queueIndices.graphicsFamily.value(), 0, &graphicsQueue); vkGetDeviceQueue(device, info.queueIndices.graphicsFamily.value(), 0, &graphicsQueue);
@ -72,7 +70,6 @@ Allocator::Allocator(VkDevice device, const PhysicalDeviceInfo &info): physicalD
} }
} }
Allocator::~Allocator() { Allocator::~Allocator() {
TracyVkDestroy(tracyCtx);
vkFreeCommandBuffers(device, transferPool, 1, &transferBuffer); vkFreeCommandBuffers(device, transferPool, 1, &transferBuffer);
vkFreeCommandBuffers(device, graphicsPool, 1, &graphicsBuffer); vkFreeCommandBuffers(device, graphicsPool, 1, &graphicsBuffer);
@ -81,12 +78,6 @@ Allocator::~Allocator() {
//NOTE: all allocations are delete by ~vector //NOTE: all allocations are delete by ~vector
} }
void Allocator::setTracyZone(const char* name) {
TracyVkCollect(tracyCtx, transferBuffer);
TracyVkZone(tracyCtx, transferBuffer, name);
(void)name;
}
void Allocator::updateProperties() { void Allocator::updateProperties() {
if (hasBudget()) { if (hasBudget()) {
vkGetPhysicalDeviceMemoryProperties2(physicalDevice, &properties2); vkGetPhysicalDeviceMemoryProperties2(physicalDevice, &properties2);

View File

@ -7,10 +7,6 @@
#include <vector> #include <vector>
#include <optional> #include <optional>
namespace tracy {
class VkCtx;
}
typedef tracy::VkCtx* TracyVkCtx;
namespace render::vk { namespace render::vk {
struct Allocation { struct Allocation {
@ -40,8 +36,6 @@ public:
void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mipLevels, uint32_t arrayLayers); void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mipLevels, uint32_t arrayLayers);
void copyBufferToImage(VkBuffer src, VkImage dst, uint32_t width, uint32_t height, uint32_t mipLevels = 1, uint32_t arrayLayer = 0); void copyBufferToImage(VkBuffer src, VkImage dst, uint32_t width, uint32_t height, uint32_t mipLevels = 1, uint32_t arrayLayer = 0);
void setTracyZone(const char* name);
struct Capabilities { struct Capabilities {
std::optional<float> maxAnisotropy; std::optional<float> maxAnisotropy;
float maxLodBias; float maxLodBias;
@ -72,7 +66,6 @@ private:
VkQueue transferQueue; VkQueue transferQueue;
VkCommandPool transferPool; VkCommandPool transferPool;
VkCommandBuffer transferBuffer; // MAYBE: parallel upload VkCommandBuffer transferBuffer; // MAYBE: parallel upload
TracyVkCtx tracyCtx;
VkQueue graphicsQueue; VkQueue graphicsQueue;
VkCommandPool graphicsPool; VkCommandPool graphicsPool;
VkCommandBuffer graphicsBuffer; VkCommandBuffer graphicsBuffer;

View File

@ -3,6 +3,7 @@
#include "PhysicalDeviceInfo.hpp" #include "PhysicalDeviceInfo.hpp"
#include "Pipeline.hpp" #include "Pipeline.hpp"
#include "Renderer.hpp" #include "Renderer.hpp"
#include <TracyVulkan.hpp>
using namespace render::vk; using namespace render::vk;
@ -75,7 +76,7 @@ void CommandCenter::loadAtlases(const std::string& textures, int anisotropy, flo
} }
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
void CommandCenter::allocate(const std::vector<VkImageView>& views, const Pipeline& pipe, VkExtent2D extent) { void CommandCenter::allocate(const std::vector<VkImageView>& views, const Pipeline& pipe, VkPhysicalDevice physicalDevice, VkExtent2D extent) {
assert(freed); assert(freed);
if (colorSamples > 1) { if (colorSamples > 1) {
@ -230,12 +231,16 @@ void CommandCenter::allocate(const std::vector<VkImageView>& views, const Pipeli
if (vkAllocateCommandBuffers(device, &allocInfo, graphicsBuffers.data()) != VK_SUCCESS) { if (vkAllocateCommandBuffers(device, &allocInfo, graphicsBuffers.data()) != VK_SUCCESS) {
FATAL("Failed to allocate graphics buffers!"); FATAL("Failed to allocate graphics buffers!");
} }
(void)physicalDevice;
tracyCtx = TracyVkContext(physicalDevice, device, graphicsQueue, graphicsBuffers.front());
} }
freed = false; freed = false;
} }
void CommandCenter::free() { void CommandCenter::free() {
assert(!freed); assert(!freed);
TracyVkDestroy(tracyCtx);
vkFreeCommandBuffers(device, graphicsPool, static_cast<uint32_t>(graphicsBuffers.size()), graphicsBuffers.data()); vkFreeCommandBuffers(device, graphicsPool, static_cast<uint32_t>(graphicsBuffers.size()), graphicsBuffers.data());
vkDestroyDescriptorPool(device, voxelDescriptorPool, ALLOC); vkDestroyDescriptorPool(device, voxelDescriptorPool, ALLOC);
@ -258,6 +263,7 @@ void CommandCenter::free() {
void CommandCenter::startRecording(uint32_t idx, VkRenderPass renderPass, VkExtent2D extent, const VoxelUBO& ubo) { void CommandCenter::startRecording(uint32_t idx, VkRenderPass renderPass, VkExtent2D extent, const VoxelUBO& ubo) {
uniformBuffers.write(idx, data_view(&ubo, sizeof(ubo))); uniformBuffers.write(idx, data_view(&ubo, sizeof(ubo)));
VkCommandBufferBeginInfo beginInfo{}; VkCommandBufferBeginInfo beginInfo{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
@ -268,6 +274,10 @@ void CommandCenter::startRecording(uint32_t idx, VkRenderPass renderPass, VkExte
FATAL("Failed to begin recording command buffer!"); FATAL("Failed to begin recording command buffer!");
} }
if (!idx) {
TracyVkCollect(tracyCtx, graphicsBuffers[idx]);
}
TracyVkZone(tracyCtx, graphicsBuffers[idx], "Render");
VkRenderPassBeginInfo renderPassInfo{}; VkRenderPassBeginInfo renderPassInfo{};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassInfo.renderPass = renderPass; renderPassInfo.renderPass = renderPass;
@ -326,6 +336,7 @@ void CommandCenter::recordPostprocess(uint32_t idx, const Subpass& skyPass, bool
vkCmdDraw(graphicsBuffers[idx], skyCubeBuffer->size, 1, 0, 0); vkCmdDraw(graphicsBuffers[idx], skyCubeBuffer->size, 1, 0, 0);
} }
vkCmdEndRenderPass(graphicsBuffers[idx]); vkCmdEndRenderPass(graphicsBuffers[idx]);
TracyVkZone(tracyCtx, graphicsBuffers[idx], "Swap");
} }
void CommandCenter::submitGraphics(uint32_t idx, VkSemaphore waitSemaphore, VkSemaphore signalSemaphore, VkFence submittedFence) { void CommandCenter::submitGraphics(uint32_t idx, VkSemaphore waitSemaphore, VkSemaphore signalSemaphore, VkFence submittedFence) {

View File

@ -7,6 +7,11 @@
#include "api/Images.hpp" #include "api/Images.hpp"
#include "api/Models.hpp" #include "api/Models.hpp"
namespace tracy {
class VkCtx;
}
typedef tracy::VkCtx* TracyVkCtx;
namespace render::vk { namespace render::vk {
class SwapChain; class SwapChain;
class Pipeline; class Pipeline;
@ -26,7 +31,7 @@ public:
void recordPostprocess(uint32_t idx, const Subpass&, bool skybox); void recordPostprocess(uint32_t idx, const Subpass&, bool skybox);
void submitGraphics(uint32_t, VkSemaphore, VkSemaphore, VkFence); void submitGraphics(uint32_t, VkSemaphore, VkSemaphore, VkFence);
void allocate(const std::vector<VkImageView>&, const Pipeline&, VkExtent2D); void allocate(const std::vector<VkImageView>&, const Pipeline&, VkPhysicalDevice, VkExtent2D);
void free(); void free();
private: private:
@ -45,6 +50,7 @@ private:
VkQueue graphicsQueue; VkQueue graphicsQueue;
VkCommandPool graphicsPool; VkCommandPool graphicsPool;
std::vector<VkCommandBuffer> graphicsBuffers; std::vector<VkCommandBuffer> graphicsBuffers;
TracyVkCtx tracyCtx;
BufferGroup uniformBuffers; BufferGroup uniformBuffers;

View File

@ -52,7 +52,7 @@ Renderer::Renderer(VkInstance instance, VkDevice device, const PhysicalDeviceInf
swapChain = std::make_unique<SwapChain>(device, getInfos()); swapChain = std::make_unique<SwapChain>(device, getInfos());
pipeline = std::make_unique<Pipeline>(device, getInfos(), options); pipeline = std::make_unique<Pipeline>(device, getInfos(), options);
commandCenter = std::make_unique<CommandCenter>(device, getInfos(), options); commandCenter = std::make_unique<CommandCenter>(device, getInfos(), options);
commandCenter->allocate(swapChain->getImageViews(), *pipeline.get(), getInfos().swapDetails.capabilities.currentExtent); commandCenter->allocate(swapChain->getImageViews(), *pipeline.get(), getInfos().device, getInfos().swapDetails.capabilities.currentExtent);
{ {
imageAvailableSemaphores.resize(opt.inFlightFrames); imageAvailableSemaphores.resize(opt.inFlightFrames);
@ -110,7 +110,7 @@ void Renderer::recreateSwapChain() {
set_current_extent(physicalInfo->swapDetails.capabilities, physicalInfo->window); set_current_extent(physicalInfo->swapDetails.capabilities, physicalInfo->window);
swapChain = std::make_unique<SwapChain>(device, getInfos()); swapChain = std::make_unique<SwapChain>(device, getInfos());
pipeline = std::make_unique<Pipeline>(device, getInfos(), options); pipeline = std::make_unique<Pipeline>(device, getInfos(), options);
commandCenter->allocate(swapChain->getImageViews(), *pipeline.get(), getInfos().swapDetails.capabilities.currentExtent); commandCenter->allocate(swapChain->getImageViews(), *pipeline.get(), getInfos().device, getInfos().swapDetails.capabilities.currentExtent);
} }
void Renderer::destroySwapChain() { void Renderer::destroySwapChain() {
commandCenter->free(); commandCenter->free();
@ -422,7 +422,6 @@ void Renderer::beginFrame() {
ubo.lightInv = LightInvDir; ubo.lightInv = LightInvDir;
commandCenter->startRecording(currentImage, pipeline->getRenderPass(), commandCenter->startRecording(currentImage, pipeline->getRenderPass(),
getInfos().swapDetails.capabilities.currentExtent, ubo); getInfos().swapDetails.capabilities.currentExtent, ubo);
allocator->setTracyZone("Submit");
ShortIndexedVertexBuffer::ClearUnused(currentImage); ShortIndexedVertexBuffer::ClearUnused(currentImage);
} else { } else {
recreateSwapChain(); recreateSwapChain();
@ -483,7 +482,6 @@ void Renderer::swapBuffer(Window&) {
currentFrame = (currentFrame + 1) % renderFinishedSemaphores.size(); currentFrame = (currentFrame + 1) % renderFinishedSemaphores.size();
currentImage = UINT32_MAX; currentImage = UINT32_MAX;
allocator->setTracyZone("Swap");
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX); vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
} }