qzdoom/src/rendering/vulkan/renderer/vk_postprocess.h

155 lines
4.4 KiB
C
Raw Normal View History

#pragma once
#include <functional>
2019-03-05 18:49:06 +00:00
#include <map>
#include <array>
2019-03-05 18:49:06 +00:00
#include "hwrenderer/postprocessing/hw_postprocess.h"
#include "vulkan/system/vk_objects.h"
#include "vulkan/system/vk_builders.h"
class FString;
2019-03-05 18:49:06 +00:00
class VkPPShader;
class VkPPTexture;
class VkPPRenderPassSetup;
class PipelineBarrier;
class VkPPRenderPassKey
{
public:
VkPPShader *Shader;
int Uniforms;
int InputTextures;
PPBlendMode BlendMode;
VkFormat OutputFormat;
int SwapChain;
2019-03-15 06:54:34 +00:00
int ShadowMapBuffers;
int StencilTest;
2019-03-16 22:37:38 +00:00
VkSampleCountFlagBits Samples;
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
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;
};
class VkPostprocess
{
public:
VkPostprocess();
~VkPostprocess();
void RenderBuffersReset();
2019-03-07 17:05:12 +00:00
void SetActiveRenderTarget();
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);
private:
void NextEye(int eyeCount);
std::unique_ptr<VulkanDescriptorSet> AllocateDescriptorSet(VulkanDescriptorSetLayout *layout);
VulkanSampler *GetSampler(PPFilterMode filter, PPWrapMode wrap);
2019-03-05 18:49:06 +00:00
std::array<std::unique_ptr<VulkanSampler>, 4> mSamplers;
std::map<VkPPRenderPassKey, std::unique_ptr<VkPPRenderPassSetup>> mRenderPassSetup;
2019-03-06 18:42:02 +00:00
std::unique_ptr<VulkanDescriptorPool> mDescriptorPool;
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;
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;
private:
void CreateDescriptorLayout(const VkPPRenderPassKey &key);
void CreatePipelineLayout(const VkPPRenderPassKey &key);
void CreatePipeline(const VkPPRenderPassKey &key);
void CreateRenderPass(const VkPPRenderPassKey &key);
};
2019-03-15 22:24:31 +00:00
class VkPPRenderState : public PPRenderState
{
public:
void PushGroup(const FString &name) override;
void PopGroup() override;
2019-03-15 22:24:31 +00:00
void Draw() override;
private:
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);
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);
};