2019-03-05 03:59:17 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-03-05 08:21:39 +00:00
|
|
|
#include <functional>
|
2019-03-05 18:49:06 +00:00
|
|
|
#include <map>
|
2019-03-05 22:31:38 +00:00
|
|
|
#include <array>
|
2019-03-05 08:21:39 +00:00
|
|
|
|
2019-03-05 18:49:06 +00:00
|
|
|
#include "hwrenderer/postprocessing/hw_postprocess.h"
|
2019-03-05 03:59:17 +00:00
|
|
|
#include "vulkan/system/vk_objects.h"
|
2019-03-10 00:47:55 +00:00
|
|
|
#include "vulkan/system/vk_builders.h"
|
2019-03-05 03:59:17 +00:00
|
|
|
|
|
|
|
class FString;
|
|
|
|
|
2019-03-05 18:49:06 +00:00
|
|
|
class VkPPShader;
|
|
|
|
class VkPPTexture;
|
2019-03-05 22:31:38 +00:00
|
|
|
class VkPPRenderPassSetup;
|
2019-03-10 00:47:55 +00:00
|
|
|
class PipelineBarrier;
|
2019-03-05 22:31:38 +00:00
|
|
|
|
|
|
|
class VkPPRenderPassKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VkPPShader *Shader;
|
|
|
|
int Uniforms;
|
|
|
|
int InputTextures;
|
|
|
|
PPBlendMode BlendMode;
|
|
|
|
VkFormat OutputFormat;
|
2019-03-09 21:07:46 +00:00
|
|
|
int SwapChain;
|
2019-03-15 06:54:34 +00:00
|
|
|
int ShadowMapBuffers;
|
2019-05-13 20:06:17 +00:00
|
|
|
int StencilTest;
|
2019-03-16 22:37:38 +00:00
|
|
|
VkSampleCountFlagBits Samples;
|
2019-03-05 22:31:38 +00:00
|
|
|
|
|
|
|
bool operator<(const VkPPRenderPassKey &other) const { return memcmp(this, &other, sizeof(VkPPRenderPassKey)) < 0; }
|
|
|
|
bool operator==(const VkPPRenderPassKey &other) const { return memcmp(this, &other, sizeof(VkPPRenderPassKey)) == 0; }
|
|
|
|
bool operator!=(const VkPPRenderPassKey &other) const { return memcmp(this, &other, sizeof(VkPPRenderPassKey)) != 0; }
|
|
|
|
};
|
2019-03-05 18:49:06 +00:00
|
|
|
|
2019-03-10 00:47:55 +00:00
|
|
|
class VkPPImageTransition
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void addImage(VulkanImage *image, VkImageLayout *layout, VkImageLayout targetLayout, bool undefinedSrcLayout);
|
|
|
|
void execute(VulkanCommandBuffer *cmdbuffer);
|
|
|
|
|
|
|
|
private:
|
|
|
|
PipelineBarrier barrier;
|
|
|
|
VkPipelineStageFlags srcStageMask = 0;
|
|
|
|
VkPipelineStageFlags dstStageMask = 0;
|
|
|
|
bool needbarrier = false;
|
|
|
|
};
|
|
|
|
|
2019-03-05 03:59:17 +00:00
|
|
|
class VkPostprocess
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VkPostprocess();
|
|
|
|
~VkPostprocess();
|
|
|
|
|
|
|
|
void RenderBuffersReset();
|
|
|
|
|
2019-03-07 17:05:12 +00:00
|
|
|
void SetActiveRenderTarget();
|
2019-03-05 03:59:17 +00:00
|
|
|
void PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D);
|
|
|
|
|
|
|
|
void AmbientOccludeScene(float m5);
|
|
|
|
void BlurScene(float gameinfobluramount);
|
|
|
|
void ClearTonemapPalette();
|
|
|
|
|
2019-03-15 06:54:34 +00:00
|
|
|
void UpdateShadowMap();
|
|
|
|
|
2019-03-16 22:37:38 +00:00
|
|
|
void ImageTransitionScene(bool undefinedSrcLayout);
|
|
|
|
|
|
|
|
void BlitSceneToPostprocess();
|
2019-03-13 13:10:13 +00:00
|
|
|
void BlitCurrentToImage(VulkanImage *image, VkImageLayout *layout, VkImageLayout finallayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
2019-03-06 21:59:21 +00:00
|
|
|
void DrawPresentTexture(const IntRect &box, bool applyGamma, bool clearBorders);
|
|
|
|
|
2019-03-05 03:59:17 +00:00
|
|
|
private:
|
|
|
|
void NextEye(int eyeCount);
|
2019-03-05 22:31:38 +00:00
|
|
|
|
2019-05-10 00:16:26 +00:00
|
|
|
std::unique_ptr<VulkanDescriptorSet> AllocateDescriptorSet(VulkanDescriptorSetLayout *layout);
|
2019-03-05 22:31:38 +00:00
|
|
|
VulkanSampler *GetSampler(PPFilterMode filter, PPWrapMode wrap);
|
2019-03-05 18:49:06 +00:00
|
|
|
|
2019-04-20 17:19:34 +00:00
|
|
|
std::array<std::unique_ptr<VulkanSampler>, 4> mSamplers;
|
2019-03-05 22:31:38 +00:00
|
|
|
std::map<VkPPRenderPassKey, std::unique_ptr<VkPPRenderPassSetup>> mRenderPassSetup;
|
2019-03-06 18:42:02 +00:00
|
|
|
std::unique_ptr<VulkanDescriptorPool> mDescriptorPool;
|
2019-03-06 16:59:11 +00:00
|
|
|
int mCurrentPipelineImage = 0;
|
2019-03-15 22:24:31 +00:00
|
|
|
|
|
|
|
friend class VkPPRenderState;
|
2019-03-05 18:49:06 +00:00
|
|
|
};
|
|
|
|
|
2019-03-15 22:24:31 +00:00
|
|
|
class VkPPShader : public PPShaderBackend
|
2019-03-05 18:49:06 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-03-15 22:24:31 +00:00
|
|
|
VkPPShader(PPShader *shader);
|
|
|
|
|
2019-03-05 18:49:06 +00:00
|
|
|
std::unique_ptr<VulkanShader> VertexShader;
|
|
|
|
std::unique_ptr<VulkanShader> FragmentShader;
|
2019-03-15 22:24:31 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
FString LoadShaderCode(const FString &lumpname, const FString &defines, int version);
|
2019-03-05 18:49:06 +00:00
|
|
|
};
|
|
|
|
|
2019-03-15 22:24:31 +00:00
|
|
|
class VkPPTexture : public PPTextureBackend
|
2019-03-05 18:49:06 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-03-15 22:24:31 +00:00
|
|
|
VkPPTexture(PPTexture *texture);
|
|
|
|
|
2019-03-05 18:49:06 +00:00
|
|
|
std::unique_ptr<VulkanImage> Image;
|
|
|
|
std::unique_ptr<VulkanImageView> View;
|
2019-03-05 19:39:27 +00:00
|
|
|
std::unique_ptr<VulkanBuffer> Staging;
|
|
|
|
VkImageLayout Layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
2019-03-05 22:31:38 +00:00
|
|
|
VkFormat Format;
|
|
|
|
};
|
|
|
|
|
|
|
|
class VkPPRenderPassSetup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VkPPRenderPassSetup(const VkPPRenderPassKey &key);
|
|
|
|
|
|
|
|
std::unique_ptr<VulkanDescriptorSetLayout> DescriptorLayout;
|
|
|
|
std::unique_ptr<VulkanPipelineLayout> PipelineLayout;
|
|
|
|
std::unique_ptr<VulkanRenderPass> RenderPass;
|
|
|
|
std::unique_ptr<VulkanPipeline> Pipeline;
|
2019-03-06 21:59:21 +00:00
|
|
|
std::map<VkImageView, std::unique_ptr<VulkanFramebuffer>> Framebuffers;
|
2019-03-05 22:31:38 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void CreateDescriptorLayout(const VkPPRenderPassKey &key);
|
|
|
|
void CreatePipelineLayout(const VkPPRenderPassKey &key);
|
|
|
|
void CreatePipeline(const VkPPRenderPassKey &key);
|
|
|
|
void CreateRenderPass(const VkPPRenderPassKey &key);
|
2019-03-05 03:59:17 +00:00
|
|
|
};
|
2019-03-15 22:24:31 +00:00
|
|
|
|
|
|
|
class VkPPRenderState : public PPRenderState
|
|
|
|
{
|
|
|
|
public:
|
2019-04-30 20:55:35 +00:00
|
|
|
void PushGroup(const FString &name) override;
|
|
|
|
void PopGroup() override;
|
|
|
|
|
2019-03-15 22:24:31 +00:00
|
|
|
void Draw() override;
|
|
|
|
|
|
|
|
private:
|
2019-05-13 20:06:17 +00:00
|
|
|
void RenderScreenQuad(VkPPRenderPassSetup *passSetup, VulkanDescriptorSet *descriptorSet, VulkanFramebuffer *framebuffer, int framebufferWidth, int framebufferHeight, int x, int y, int width, int height, const void *pushConstants, uint32_t pushConstantsSize, bool stencilTest);
|
2019-03-15 22:24:31 +00:00
|
|
|
|
|
|
|
VulkanDescriptorSet *GetInput(VkPPRenderPassSetup *passSetup, const TArray<PPTextureInput> &textures, bool bindShadowMapBuffers);
|
2019-05-13 20:06:17 +00:00
|
|
|
VulkanFramebuffer *GetOutput(VkPPRenderPassSetup *passSetup, const PPOutput &output, bool stencilTest, int &framebufferWidth, int &framebufferHeight);
|
2019-03-15 22:24:31 +00:00
|
|
|
|
|
|
|
VkPPShader *GetVkShader(PPShader *shader);
|
|
|
|
VkPPTexture *GetVkTexture(PPTexture *texture);
|
|
|
|
|
|
|
|
struct TextureImage
|
|
|
|
{
|
|
|
|
VulkanImage *image;
|
|
|
|
VulkanImageView *view;
|
|
|
|
VkImageLayout *layout;
|
|
|
|
const char *debugname;
|
|
|
|
};
|
|
|
|
TextureImage GetTexture(const PPTextureType &type, PPTexture *tex);
|
|
|
|
};
|