- implement wipe screen copy

This commit is contained in:
Magnus Norddahl 2019-03-13 02:23:33 +01:00
parent a585a90d81
commit d78cb959a7
7 changed files with 98 additions and 7 deletions

View file

@ -119,6 +119,46 @@ void VkPostprocess::BlitSceneToTexture()
imageTransition1.execute(fb->GetDrawCommands());
}
void VkPostprocess::BlitCurrentToImage(VulkanImage *dstimage, VkImageLayout *dstlayout)
{
auto fb = GetVulkanFrameBuffer();
fb->GetRenderState()->EndRenderPass();
auto srcimage = fb->GetBuffers()->PipelineImage[mCurrentPipelineImage].get();
auto srclayout = &fb->GetBuffers()->PipelineLayout[mCurrentPipelineImage];
auto cmdbuffer = fb->GetDrawCommands();
*dstlayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; // needed by VkPPImageTransition.addImage. Actual layout is undefined.
VkPPImageTransition imageTransition0;
imageTransition0.addImage(srcimage, srclayout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, false);
imageTransition0.addImage(dstimage, dstlayout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, true);
imageTransition0.execute(fb->GetDrawCommands());
VkImageBlit blit = {};
blit.srcOffsets[0] = { 0, 0, 0 };
blit.srcOffsets[1] = { srcimage->width, srcimage->height, 1 };
blit.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
blit.srcSubresource.mipLevel = 0;
blit.srcSubresource.baseArrayLayer = 0;
blit.srcSubresource.layerCount = 1;
blit.dstOffsets[0] = { 0, 0, 0 };
blit.dstOffsets[1] = { dstimage->width, dstimage->height, 1 };
blit.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
blit.dstSubresource.mipLevel = 0;
blit.dstSubresource.baseArrayLayer = 0;
blit.dstSubresource.layerCount = 1;
cmdbuffer->blitImage(
srcimage->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
dstimage->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1, &blit, VK_FILTER_NEAREST);
VkPPImageTransition imageTransition1;
imageTransition1.addImage(dstimage, dstlayout, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, false);
imageTransition1.execute(fb->GetDrawCommands());
}
void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool clearBorders)
{
auto fb = GetVulkanFrameBuffer();

View file

@ -61,6 +61,7 @@ public:
void ClearTonemapPalette();
void BlitSceneToTexture();
void BlitCurrentToImage(VulkanImage *image, VkImageLayout *layout);
void DrawPresentTexture(const IntRect &box, bool applyGamma, bool clearBorders);
private:

View file

@ -78,7 +78,7 @@ void VkRenderBuffers::CreatePipeline(int width, int height)
ImageBuilder builder;
builder.setSize(width, height);
builder.setFormat(VK_FORMAT_R16G16B16A16_SFLOAT);
builder.setUsage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
builder.setUsage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
PipelineImage[i] = builder.create(fb->device);
PipelineImage[i]->SetDebugName("VkRenderBuffers.PipelineImage");

View file

@ -546,6 +546,32 @@ void VulkanFrameBuffer::UpdatePalette()
mPostprocess->ClearTonemapPalette();
}
FTexture *VulkanFrameBuffer::WipeStartScreen()
{
const auto &viewport = screen->mScreenViewport;
auto tex = new FWrapperTexture(viewport.width, viewport.height, 1);
auto systex = static_cast<VkHardwareTexture*>(tex->GetSystemTexture());
systex->CreateWipeTexture(viewport.width, viewport.height, "WipeStartScreen");
return tex;
}
FTexture *VulkanFrameBuffer::WipeEndScreen()
{
GetPostprocess()->SetActiveRenderTarget();
Draw2D();
Clear2D();
const auto &viewport = screen->mScreenViewport;
auto tex = new FWrapperTexture(viewport.width, viewport.height, 1);
auto systex = static_cast<VkHardwareTexture*>(tex->GetSystemTexture());
systex->CreateWipeTexture(viewport.width, viewport.height, "WipeEndScreen");
return tex;
}
void VulkanFrameBuffer::BeginFrame()
{
SetViewportRects(nullptr);

View file

@ -71,12 +71,8 @@ public:
IIndexBuffer *CreateIndexBuffer() override;
IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo) override;
/*
bool WipeStartScreen(int type);
void WipeEndScreen();
bool WipeDo(int ticks);
void WipeCleanup();
*/
FTexture *WipeStartScreen() override;
FTexture *WipeEndScreen() override;
void SetVSync(bool vsync);

View file

@ -35,6 +35,7 @@
#include "vulkan/system/vk_framebuffer.h"
#include "vulkan/textures/vk_samplers.h"
#include "vulkan/renderer/vk_renderpass.h"
#include "vulkan/renderer/vk_postprocess.h"
#include "vk_hwtexture.h"
VkHardwareTexture *VkHardwareTexture::First = nullptr;
@ -282,6 +283,30 @@ unsigned int VkHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
return 0;
}
void VkHardwareTexture::CreateWipeTexture(int w, int h, const char *name)
{
auto fb = GetVulkanFrameBuffer();
VkFormat format = VK_FORMAT_B8G8R8A8_UNORM;
ImageBuilder imgbuilder;
imgbuilder.setFormat(format);
imgbuilder.setSize(w, h);
imgbuilder.setUsage(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, VMA_MEMORY_USAGE_GPU_ONLY);
mImage = imgbuilder.create(fb->device);
mImage->SetDebugName(name);
mImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
mTexelsize = 4;
ImageViewBuilder viewbuilder;
viewbuilder.setImage(mImage.get(), format);
mImageView = viewbuilder.create(fb->device);
mImageView->SetDebugName(name);
fb->GetPostprocess()->BlitCurrentToImage(mImage.get(), &mImageLayout);
}
#if 0
//===========================================================================

View file

@ -32,6 +32,9 @@ public:
uint8_t *MapBuffer() override;
unsigned int CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, int translation, const char *name) override;
// Wipe screen
void CreateWipeTexture(int w, int h, const char *name);
static VkHardwareTexture *First;
VkHardwareTexture *Prev = nullptr;
VkHardwareTexture *Next = nullptr;