- compile the effect shaders

This commit is contained in:
Magnus Norddahl 2019-03-05 19:49:06 +01:00
parent b313f91ab0
commit a07e4601e7
3 changed files with 65 additions and 0 deletions

View file

@ -12,6 +12,7 @@
#include "hwrenderer/utility/hw_vrmodes.h"
#include "hwrenderer/data/flatvertices.h"
#include "r_videoscale.h"
#include "w_wad.h"
VkPostprocess::VkPostprocess()
{
@ -101,6 +102,44 @@ void VkPostprocess::UpdateEffectTextures()
void VkPostprocess::CompileEffectShaders()
{
auto fb = GetVulkanFrameBuffer();
TMap<FString, PPShader>::Iterator it(hw_postprocess.Shaders);
TMap<FString, PPShader>::Pair *pair;
while (it.NextPair(pair))
{
const auto &desc = pair->Value;
auto &vkshader = mShaders[pair->Key];
if (!vkshader)
{
FString prolog;
if (!desc.Uniforms.empty())
prolog = UniformBlockDecl::Create("Uniforms", desc.Uniforms, uniformbindingpoint);
prolog += desc.Defines;
ShaderBuilder vertbuilder;
vertbuilder.setVertexShader(LoadShaderCode(desc.VertexShader, "", desc.Version));
vkshader->VertexShader = vertbuilder.create(fb->device);
ShaderBuilder fragbuilder;
fragbuilder.setFragmentShader(LoadShaderCode(desc.FragmentShader, prolog, desc.Version));
vkshader->FragmentShader = fragbuilder.create(fb->device);
}
}
}
FString VkPostprocess::LoadShaderCode(const FString &lumpName, const FString &defines, int version)
{
int lump = Wads.CheckNumForFullName(lumpName, 0);
if (lump == -1) I_FatalError("Unable to load '%s'", lumpName);
FString code = Wads.ReadLump(lump).GetString().GetChars();
FString patchedCode;
patchedCode.AppendFormat("#version %d\n", 450);
patchedCode << defines;
patchedCode << "#line 1\n";
patchedCode << code;
return patchedCode;
}
void VkPostprocess::RenderEffect(const FString &name)

View file

@ -2,11 +2,16 @@
#pragma once
#include <functional>
#include <map>
#include "hwrenderer/postprocessing/hw_postprocess.h"
#include "vulkan/system/vk_objects.h"
class FString;
class VkPPShader;
class VkPPTexture;
class VkPostprocess
{
public:
@ -24,7 +29,27 @@ public:
private:
void UpdateEffectTextures();
void CompileEffectShaders();
FString LoadShaderCode(const FString &lumpname, const FString &defines, int version);
void RenderEffect(const FString &name);
void NextEye(int eyeCount);
void RenderScreenQuad();
std::map<PPTextureName, std::unique_ptr<VkPPTexture>> mTextures;
std::map<PPShaderName, std::unique_ptr<VkPPShader>> mShaders;
const static int uniformbindingpoint = 7;
};
class VkPPShader
{
public:
std::unique_ptr<VulkanShader> VertexShader;
std::unique_ptr<VulkanShader> FragmentShader;
};
class VkPPTexture
{
public:
std::unique_ptr<VulkanImage> Image;
std::unique_ptr<VulkanImageView> View;
};

View file

@ -102,6 +102,7 @@ void VulkanFrameBuffer::InitializeState()
gl_vendorstring = "Vulkan";
hwcaps = RFL_SHADER_STORAGE_BUFFER | RFL_BUFFER_STORAGE;
glslversion = 4.50f;
uniformblockalignment = (unsigned int)device->deviceProperties.limits.minUniformBufferOffsetAlignment;
maxuniformblock = device->deviceProperties.limits.maxUniformBufferRange;