mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 01:22:21 +02:00
GPU frame player and other fixes
This commit is contained in:
parent
1a2a401d3f
commit
968392f2b9
7 changed files with 37 additions and 26 deletions
|
@ -274,6 +274,7 @@ static AppNapDisabler appNapDisabler; // disabled, while in scope
|
|||
#endif
|
||||
|
||||
#include "graphics/RenderEventHandler.h"
|
||||
#include "display-plugins/VulkanDisplayPlugin.h"
|
||||
|
||||
Q_LOGGING_CATEGORY(trace_app_input_mouse, "trace.app.input.mouse")
|
||||
|
||||
|
@ -9013,7 +9014,11 @@ void Application::setDisplayPlugin(DisplayPluginPointer newDisplayPlugin) {
|
|||
}
|
||||
|
||||
RefreshRateManager& refreshRateManager = getRefreshRateManager();
|
||||
#ifdef USE_GL
|
||||
refreshRateManager.setRefreshRateOperator(OpenGLDisplayPlugin::getRefreshRateOperator());
|
||||
#else
|
||||
refreshRateManager.setRefreshRateOperator(VulkanDisplayPlugin::getRefreshRateOperator());
|
||||
#endif
|
||||
bool isHmd = newDisplayPlugin->isHmd();
|
||||
RefreshRateManager::UXMode uxMode = isHmd ? RefreshRateManager::UXMode::VR :
|
||||
RefreshRateManager::UXMode::DESKTOP;
|
||||
|
|
|
@ -612,7 +612,11 @@ void VKBackend::executeFrame(const FramePointer& frame) {
|
|||
cmdEndLabel(commandBuffer);
|
||||
}
|
||||
const auto& framebuffer = batch._framebuffers.get(batch._params[paramOffset]._uint);
|
||||
cmdBeginLabel(commandBuffer, "framebuffer:" + framebuffer->getName(), vec4{ 1, 0, 1, 1 });
|
||||
if (framebuffer) {
|
||||
cmdBeginLabel(commandBuffer, "framebuffer:" + framebuffer->getName(), vec4{ 1, 0, 1, 1 });
|
||||
} else {
|
||||
cmdBeginLabel(commandBuffer, "framebuffer: NULL", vec4{ 1, 0, 1, 1 });
|
||||
}
|
||||
renderpassActive = true;
|
||||
_cache.pipelineState.setFramebuffer(framebuffer);
|
||||
} break;
|
||||
|
|
|
@ -432,8 +432,8 @@ public:
|
|||
U t;
|
||||
return std::make_shared<gpu::Buffer>(usage, sizeof(U), (const gpu::Byte*)&t, sizeof(U));
|
||||
}
|
||||
~StructBuffer<T>(){};
|
||||
StructBuffer<T>() : gpu::BufferView(makeBuffer<T>()) {}
|
||||
~StructBuffer(){};
|
||||
StructBuffer() : gpu::BufferView(makeBuffer<T>()) {}
|
||||
|
||||
T& edit() { return BufferView::edit<T>(0); }
|
||||
const T& get() const { return BufferView::get<T>(0); }
|
||||
|
|
|
@ -430,10 +430,7 @@ void Context::buildDevice() {
|
|||
|
||||
VkCommandBuffer Context::createCommandBuffer(VkCommandBufferLevel level) const {
|
||||
VkCommandBuffer cmdBuffer;
|
||||
VkCommandBufferAllocateInfo cmdBufAllocateInfo;
|
||||
cmdBufAllocateInfo.commandPool = getCommandPool();
|
||||
cmdBufAllocateInfo.level = level;
|
||||
cmdBufAllocateInfo.commandBufferCount = 1;
|
||||
VkCommandBufferAllocateInfo cmdBufAllocateInfo = vks::initializers::commandBufferAllocateInfo(getCommandPool(), level, 1);
|
||||
VK_CHECK_RESULT(vkAllocateCommandBuffers(device->logicalDevice, &cmdBufAllocateInfo, &cmdBuffer));
|
||||
return cmdBuffer;
|
||||
}
|
||||
|
|
|
@ -131,6 +131,8 @@ namespace vks {
|
|||
device(device) {
|
||||
pipelineCreateInfo.layout = layout;
|
||||
pipelineCreateInfo.renderPass = renderPass;
|
||||
multisampleState.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
||||
multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -148,14 +150,14 @@ namespace vks {
|
|||
VkRenderPass& renderPass { pipelineCreateInfo.renderPass };
|
||||
VkPipelineLayout& layout { pipelineCreateInfo.layout };
|
||||
// TODO: these need to be initialized
|
||||
PipelineInputAssemblyStateCreateInfo inputAssemblyState {};
|
||||
PipelineRasterizationStateCreateInfo rasterizationState {};
|
||||
PipelineInputAssemblyStateCreateInfo inputAssemblyState;
|
||||
PipelineRasterizationStateCreateInfo rasterizationState;
|
||||
VkPipelineMultisampleStateCreateInfo multisampleState {};
|
||||
PipelineDepthStencilStateCreateInfo depthStencilState {};
|
||||
PipelineViewportStateCreateInfo viewportState {};
|
||||
PipelineDynamicStateCreateInfo dynamicState {};
|
||||
PipelineColorBlendStateCreateInfo colorBlendState {};
|
||||
PipelineVertexInputStateCreateInfo vertexInputState {};
|
||||
PipelineDepthStencilStateCreateInfo depthStencilState;
|
||||
PipelineViewportStateCreateInfo viewportState;
|
||||
PipelineDynamicStateCreateInfo dynamicState;
|
||||
PipelineColorBlendStateCreateInfo colorBlendState;
|
||||
PipelineVertexInputStateCreateInfo vertexInputState;
|
||||
std::vector<VkPipelineShaderStageCreateInfo> shaderStages {};
|
||||
|
||||
VkGraphicsPipelineCreateInfo pipelineCreateInfo{};
|
||||
|
|
|
@ -96,7 +96,7 @@ void RenderThread::initialize(QWindow* window) {
|
|||
setupRenderPass();
|
||||
setupFramebuffers();
|
||||
|
||||
VkSemaphoreCreateInfo semaphoreCI{};
|
||||
VkSemaphoreCreateInfo semaphoreCI = vks::initializers::semaphoreCreateInfo();
|
||||
VK_CHECK_RESULT(vkCreateSemaphore(_vkcontext.device->logicalDevice, &semaphoreCI, nullptr, &acquireComplete));
|
||||
VK_CHECK_RESULT(vkCreateSemaphore(_vkcontext.device->logicalDevice, &semaphoreCI, nullptr, &renderComplete));
|
||||
|
||||
|
@ -205,6 +205,9 @@ void RenderThread::renderFrame(gpu::FramePointer& frame) {
|
|||
#endif
|
||||
|
||||
//_gpuContext->enableStereo(true);
|
||||
auto vkBackend = std::dynamic_pointer_cast<gpu::vulkan::VKBackend>(_gpuContext->getBackend());
|
||||
vkBackend->setDrawCommandBuffer(commandBuffer);
|
||||
|
||||
if (frame && !frame->batches.empty()) {
|
||||
_gpuContext->executeFrame(frame);
|
||||
}
|
||||
|
@ -255,7 +258,7 @@ void RenderThread::renderFrame(gpu::FramePointer& frame) {
|
|||
submitInfo.commandBufferCount = 1;
|
||||
VkFenceCreateInfo fenceCI{};
|
||||
VkFence frameFence;
|
||||
vkCreateFence(_vkdevice, &fenceCI, nullptr, &frameFence);
|
||||
vkCreateFence(_vkcontext.device->logicalDevice, &fenceCI, nullptr, &frameFence);
|
||||
vkQueueSubmit(_vkcontext.queue, 1, &submitInfo, frameFence);
|
||||
_swapchain.queuePresent(_vkcontext.queue, swapchainIndex, renderComplete);
|
||||
_vkcontext.trashCommandBuffers({ commandBuffer });
|
||||
|
@ -303,7 +306,7 @@ void RenderThread::setupFramebuffers() {
|
|||
// Recreate the frame buffers
|
||||
_vkcontext.trashAll<VkFramebuffer>(_framebuffers, [this](const std::vector<VkFramebuffer>& framebuffers) {
|
||||
for (const auto& framebuffer : framebuffers) {
|
||||
vkDestroyFramebuffer(_vkdevice, framebuffer, nullptr);
|
||||
vkDestroyFramebuffer(_vkcontext.device->logicalDevice, framebuffer, nullptr);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -311,6 +314,7 @@ void RenderThread::setupFramebuffers() {
|
|||
attachments.resize(1);
|
||||
VkFramebufferCreateInfo framebufferCreateInfo{};
|
||||
framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||
framebufferCreateInfo.pNext = NULL;
|
||||
framebufferCreateInfo.renderPass = _renderPass;
|
||||
framebufferCreateInfo.attachmentCount = 1;
|
||||
framebufferCreateInfo.pAttachments = attachments.data();
|
||||
|
@ -322,7 +326,7 @@ void RenderThread::setupFramebuffers() {
|
|||
_framebuffers.resize(_swapchain.imageCount);
|
||||
for (uint32_t i = 0; i < _swapchain.imageCount; i++) {
|
||||
attachments[0] = _swapchain.buffers[i].view;
|
||||
VK_CHECK_RESULT(vkCreateFramebuffer(_vkdevice, &framebufferCreateInfo, nullptr, &_framebuffers[i]));
|
||||
VK_CHECK_RESULT(vkCreateFramebuffer(_vkcontext.device->logicalDevice, &framebufferCreateInfo, nullptr, &_framebuffers[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -331,23 +335,24 @@ void RenderThread::setupRenderPass() {
|
|||
vkDestroyRenderPass(_vkcontext.device->logicalDevice, _renderPass, nullptr);
|
||||
}
|
||||
|
||||
VkAttachmentDescription attachment;
|
||||
VkAttachmentDescription attachment{};
|
||||
// Color attachment
|
||||
attachment.format = _swapchain.colorFormat;
|
||||
attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
attachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||
attachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
|
||||
VkAttachmentReference colorAttachmentReference;
|
||||
VkAttachmentReference colorAttachmentReference{};
|
||||
colorAttachmentReference.attachment = 0;
|
||||
colorAttachmentReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
|
||||
VkSubpassDescription subpass;
|
||||
VkSubpassDescription subpass{};
|
||||
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
subpass.colorAttachmentCount = 1;
|
||||
subpass.pColorAttachments = &colorAttachmentReference;
|
||||
VkSubpassDependency subpassDependency;
|
||||
VkSubpassDependency subpassDependency{};
|
||||
subpassDependency.srcSubpass = 0;
|
||||
subpassDependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
subpassDependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
|
@ -355,7 +360,7 @@ void RenderThread::setupRenderPass() {
|
|||
subpassDependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
|
||||
subpassDependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
|
||||
VkRenderPassCreateInfo renderPassInfo;
|
||||
VkRenderPassCreateInfo renderPassInfo{};
|
||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||
renderPassInfo.attachmentCount = 1;
|
||||
renderPassInfo.pAttachments = &attachment;
|
||||
|
|
|
@ -32,8 +32,6 @@ public:
|
|||
QWindow* _window{ nullptr };
|
||||
|
||||
vks::Context& _vkcontext{ vks::Context::get() };
|
||||
// TODO: is the _vkcontext.device->logicalDevice created at the time?
|
||||
const VkDevice& _vkdevice{ _vkcontext.device->logicalDevice };
|
||||
vks::Buffer _vkstagingBuffer;
|
||||
|
||||
#ifdef USE_GL
|
||||
|
@ -41,7 +39,7 @@ public:
|
|||
#else
|
||||
|
||||
//VkSurfaceKHR _surface;
|
||||
VkRenderPass _renderPass;
|
||||
VkRenderPass _renderPass{VK_NULL_HANDLE};
|
||||
VulkanSwapChain _swapchain;
|
||||
VkSemaphore acquireComplete, renderComplete;
|
||||
std::vector<VkFramebuffer> _framebuffers;
|
||||
|
|
Loading…
Reference in a new issue