mirror of
https://github.com/ZDoom/qzdoom.git
synced 2025-01-18 23:21:41 +00:00
- present an empty back buffer while keeping vsync
This commit is contained in:
parent
75403ec744
commit
fc79cd1280
2 changed files with 68 additions and 38 deletions
|
@ -34,6 +34,7 @@
|
||||||
#include "vk_framebuffer.h"
|
#include "vk_framebuffer.h"
|
||||||
#include "vulkan/textures/vk_samplers.h"
|
#include "vulkan/textures/vk_samplers.h"
|
||||||
#include "vulkan/system/vk_builders.h"
|
#include "vulkan/system/vk_builders.h"
|
||||||
|
#include "vulkan/system/vk_swapchain.h"
|
||||||
#include "doomerrors.h"
|
#include "doomerrors.h"
|
||||||
|
|
||||||
#include <ShaderLang.h>
|
#include <ShaderLang.h>
|
||||||
|
@ -45,9 +46,20 @@ EXTERN_CVAR(Int, gl_tonemap)
|
||||||
VulkanFrameBuffer::VulkanFrameBuffer(void *hMonitor, bool fullscreen, VulkanDevice *dev) :
|
VulkanFrameBuffer::VulkanFrameBuffer(void *hMonitor, bool fullscreen, VulkanDevice *dev) :
|
||||||
Super(hMonitor, fullscreen)
|
Super(hMonitor, fullscreen)
|
||||||
{
|
{
|
||||||
ShInitialize();
|
device = dev;
|
||||||
|
SetViewportRects(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
//screen = this; // temporary hack to make the tutorial code work.
|
VulkanFrameBuffer::~VulkanFrameBuffer()
|
||||||
|
{
|
||||||
|
ShFinalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanFrameBuffer::InitializeState()
|
||||||
|
{
|
||||||
|
ShInitialize();
|
||||||
|
mSamplerManager.reset(new VkSamplerManager(device));
|
||||||
|
mGraphicsCommandPool.reset(new VulkanCommandPool(device, device->graphicsFamily));
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
{
|
{
|
||||||
|
@ -66,20 +78,6 @@ VulkanFrameBuffer::VulkanFrameBuffer(void *hMonitor, bool fullscreen, VulkanDevi
|
||||||
auto shader = builder.create(dev);
|
auto shader = builder.create(dev);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
device = dev;
|
|
||||||
mSamplerManager = new VkSamplerManager(device);
|
|
||||||
SetViewportRects(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
VulkanFrameBuffer::~VulkanFrameBuffer()
|
|
||||||
{
|
|
||||||
delete mSamplerManager;
|
|
||||||
ShFinalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
void VulkanFrameBuffer::InitializeState()
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanFrameBuffer::Update()
|
void VulkanFrameBuffer::Update()
|
||||||
|
@ -87,24 +85,57 @@ void VulkanFrameBuffer::Update()
|
||||||
twoD.Reset();
|
twoD.Reset();
|
||||||
Flush3D.Reset();
|
Flush3D.Reset();
|
||||||
|
|
||||||
DrawRateStuff();
|
|
||||||
Flush3D.Clock();
|
Flush3D.Clock();
|
||||||
//vulkantest_tick();
|
|
||||||
|
int newWidth = GetClientWidth();
|
||||||
|
int newHeight = GetClientHeight();
|
||||||
|
if (lastSwapWidth != newWidth || lastSwapHeight != newHeight)
|
||||||
|
{
|
||||||
|
device->windowResized();
|
||||||
|
lastSwapWidth = newWidth;
|
||||||
|
lastSwapHeight = newHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
device->beginFrame();
|
||||||
|
|
||||||
|
mPresentCommands = mGraphicsCommandPool->createBuffer();
|
||||||
|
mPresentCommands->begin();
|
||||||
|
|
||||||
|
Draw2D();
|
||||||
|
Clear2D();
|
||||||
|
//DrawPresentTexture(mOutputLetterbox, true);
|
||||||
|
|
||||||
|
mPresentCommands->end();
|
||||||
|
|
||||||
|
VkSemaphore waitSemaphores[] = { device->imageAvailableSemaphore };
|
||||||
|
VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
|
||||||
|
|
||||||
|
VkSubmitInfo submitInfo = {};
|
||||||
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
|
submitInfo.waitSemaphoreCount = 1;
|
||||||
|
submitInfo.pWaitSemaphores = waitSemaphores;
|
||||||
|
submitInfo.pWaitDstStageMask = waitStages;
|
||||||
|
submitInfo.commandBufferCount = 1;
|
||||||
|
submitInfo.pCommandBuffers = &mPresentCommands->buffer;
|
||||||
|
submitInfo.signalSemaphoreCount = 1;
|
||||||
|
submitInfo.pSignalSemaphores = &device->renderFinishedSemaphore;
|
||||||
|
VkResult result = vkQueueSubmit(device->graphicsQueue, 1, &submitInfo, device->renderFinishedFence);
|
||||||
|
if (result != VK_SUCCESS)
|
||||||
|
I_FatalError("Failed to submit command buffer!\n");
|
||||||
|
|
||||||
Flush3D.Unclock();
|
Flush3D.Unclock();
|
||||||
|
|
||||||
Swap();
|
Finish.Reset();
|
||||||
CheckBench();
|
Finish.Clock();
|
||||||
|
device->presentFrame();
|
||||||
|
device->waitPresent();
|
||||||
|
|
||||||
int initialWidth = GetClientWidth();
|
mPresentCommands.reset();
|
||||||
int initialHeight = GetClientHeight();
|
mUploadCommands.reset();
|
||||||
int clientWidth = ViewportScaledWidth(initialWidth, initialHeight);
|
|
||||||
int clientHeight = ViewportScaledHeight(initialWidth, initialHeight);
|
Finish.Unclock();
|
||||||
if (clientWidth > 0 && clientHeight > 0 && (GetWidth() != clientWidth || GetHeight() != clientHeight))
|
|
||||||
{
|
Super::Update();
|
||||||
SetVirtualSize(clientWidth, clientHeight);
|
|
||||||
V_OutputResized(clientWidth, clientHeight);
|
|
||||||
//GLRenderer->mVBO->OutputResized(clientWidth, clientHeight);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanFrameBuffer::WriteSavePic(player_t *player, FileWriter *file, int width, int height)
|
void VulkanFrameBuffer::WriteSavePic(player_t *player, FileWriter *file, int width, int height)
|
||||||
|
@ -135,11 +166,6 @@ uint32_t VulkanFrameBuffer::GetCaps()
|
||||||
return (uint32_t)FlagSet;
|
return (uint32_t)FlagSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanFrameBuffer::Swap()
|
|
||||||
{
|
|
||||||
//vulkantest_present();
|
|
||||||
}
|
|
||||||
|
|
||||||
void VulkanFrameBuffer::SetVSync(bool vsync)
|
void VulkanFrameBuffer::SetVSync(bool vsync)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,11 @@ class VulkanFrameBuffer : public SystemBaseFrameBuffer
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VulkanDevice *device;
|
VulkanDevice *device;
|
||||||
VkSamplerManager *mSamplerManager;
|
std::unique_ptr<VkSamplerManager> mSamplerManager;
|
||||||
|
std::unique_ptr<VulkanCommandPool> mGraphicsCommandPool;
|
||||||
|
std::unique_ptr<VulkanCommandBuffer> mUploadCommands;
|
||||||
|
std::unique_ptr<VulkanCommandBuffer> mPresentCommands;
|
||||||
|
|
||||||
explicit VulkanFrameBuffer() {}
|
|
||||||
VulkanFrameBuffer(void *hMonitor, bool fullscreen, VulkanDevice *dev);
|
VulkanFrameBuffer(void *hMonitor, bool fullscreen, VulkanDevice *dev);
|
||||||
~VulkanFrameBuffer();
|
~VulkanFrameBuffer();
|
||||||
|
|
||||||
|
@ -43,11 +45,13 @@ public:
|
||||||
void WipeCleanup();
|
void WipeCleanup();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Swap();
|
|
||||||
void SetVSync(bool vsync);
|
void SetVSync(bool vsync);
|
||||||
|
|
||||||
void Draw2D() override;
|
void Draw2D() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int camtexcount = 0;
|
int camtexcount = 0;
|
||||||
|
|
||||||
|
int lastSwapWidth = 0;
|
||||||
|
int lastSwapHeight = 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue