1
0
Fork 0
tmp
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 "PhysicalDeviceInfo.hpp"
#include <TracyVulkan.hpp>
#include <memory.h>
#include <cassert>
@ -49,7 +48,6 @@ Allocator::Allocator(VkDevice device, const PhysicalDeviceInfo &info): physicalD
allocInfo.commandBufferCount = 1;
vkAllocateCommandBuffers(device, &allocInfo, &transferBuffer);
tracyCtx = TracyVkContext(info.device, device, transferQueue, transferBuffer);
}
{ // Graphics
vkGetDeviceQueue(device, info.queueIndices.graphicsFamily.value(), 0, &graphicsQueue);
@ -72,7 +70,6 @@ Allocator::Allocator(VkDevice device, const PhysicalDeviceInfo &info): physicalD
}
}
Allocator::~Allocator() {
TracyVkDestroy(tracyCtx);
vkFreeCommandBuffers(device, transferPool, 1, &transferBuffer);
vkFreeCommandBuffers(device, graphicsPool, 1, &graphicsBuffer);
@ -81,12 +78,6 @@ Allocator::~Allocator() {
//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() {
if (hasBudget()) {
vkGetPhysicalDeviceMemoryProperties2(physicalDevice, &properties2);

View File

@ -7,10 +7,6 @@
#include <vector>
#include <optional>
namespace tracy {
class VkCtx;
}
typedef tracy::VkCtx* TracyVkCtx;
namespace render::vk {
struct Allocation {
@ -40,8 +36,6 @@ public:
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 setTracyZone(const char* name);
struct Capabilities {
std::optional<float> maxAnisotropy;
float maxLodBias;
@ -72,7 +66,6 @@ private:
VkQueue transferQueue;
VkCommandPool transferPool;
VkCommandBuffer transferBuffer; // MAYBE: parallel upload
TracyVkCtx tracyCtx;
VkQueue graphicsQueue;
VkCommandPool graphicsPool;
VkCommandBuffer graphicsBuffer;

View File

@ -3,6 +3,7 @@
#include "PhysicalDeviceInfo.hpp"
#include "Pipeline.hpp"
#include "Renderer.hpp"
#include <TracyVulkan.hpp>
using namespace render::vk;
@ -75,7 +76,7 @@ void CommandCenter::loadAtlases(const std::string& textures, int anisotropy, flo
}
#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);
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) {
FATAL("Failed to allocate graphics buffers!");
}
(void)physicalDevice;
tracyCtx = TracyVkContext(physicalDevice, device, graphicsQueue, graphicsBuffers.front());
}
freed = false;
}
void CommandCenter::free() {
assert(!freed);
TracyVkDestroy(tracyCtx);
vkFreeCommandBuffers(device, graphicsPool, static_cast<uint32_t>(graphicsBuffers.size()), graphicsBuffers.data());
vkDestroyDescriptorPool(device, voxelDescriptorPool, ALLOC);
@ -258,6 +263,7 @@ void CommandCenter::free() {
void CommandCenter::startRecording(uint32_t idx, VkRenderPass renderPass, VkExtent2D extent, const VoxelUBO& ubo) {
uniformBuffers.write(idx, data_view(&ubo, sizeof(ubo)));
VkCommandBufferBeginInfo beginInfo{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
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!");
}
if (!idx) {
TracyVkCollect(tracyCtx, graphicsBuffers[idx]);
}
TracyVkZone(tracyCtx, graphicsBuffers[idx], "Render");
VkRenderPassBeginInfo renderPassInfo{};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
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);
}
vkCmdEndRenderPass(graphicsBuffers[idx]);
TracyVkZone(tracyCtx, graphicsBuffers[idx], "Swap");
}
void CommandCenter::submitGraphics(uint32_t idx, VkSemaphore waitSemaphore, VkSemaphore signalSemaphore, VkFence submittedFence) {

View File

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

View File

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