Merge remote-tracking branch 'origin/master' into polybackend

This commit is contained in:
Magnus Norddahl 2019-06-23 20:29:04 +02:00
commit 706bc0b7c6
41 changed files with 199 additions and 86 deletions

View file

@ -68,18 +68,10 @@ void FGLRenderer::PostProcessScene(int fixedcm, const std::function<void()> &aft
GLPPRenderState renderstate(mBuffers);
hw_postprocess.exposure.Render(&renderstate, sceneWidth, sceneHeight);
hw_postprocess.customShaders.Run(&renderstate, "beforebloom");
hw_postprocess.bloom.RenderBloom(&renderstate, sceneWidth, sceneHeight, fixedcm);
hw_postprocess.Pass1(&renderstate, fixedcm, sceneWidth, sceneHeight);
mBuffers->BindCurrentFB();
afterBloomDrawEndScene2D();
hw_postprocess.tonemap.Render(&renderstate);
hw_postprocess.colormap.Render(&renderstate, fixedcm);
hw_postprocess.lens.Render(&renderstate);
hw_postprocess.fxaa.Render(&renderstate);
hw_postprocess.customShaders.Run(&renderstate, "scene");
hw_postprocess.Pass2(&renderstate, fixedcm, sceneWidth, sceneHeight);
}
//-----------------------------------------------------------------------------

View file

@ -78,7 +78,7 @@ void HWViewpointBuffer::Set2D(FRenderState &di, int width, int height)
if (width != m2DWidth || height != m2DHeight)
{
HWViewpointUniforms matrices;
matrices.SetDefaults();
matrices.SetDefaults(nullptr);
matrices.mProjectionMatrix.ortho(0, (float)width, (float)height, 0, -1.0f, 1.0f);
matrices.CalcDependencies();
mBuffer->Map();

View file

@ -1081,3 +1081,20 @@ void PPCustomShaderInstance::AddUniformField(size_t &offset, const FString &name
offset += alignment - fieldsize;
}
}
void Postprocess::Pass1(PPRenderState* state, int fixedcm, int sceneWidth, int sceneHeight)
{
exposure.Render(state, sceneWidth, sceneHeight);
customShaders.Run(state, "beforebloom");
bloom.RenderBloom(state, sceneWidth, sceneHeight, fixedcm);
}
void Postprocess::Pass2(PPRenderState* state, int fixedcm, int sceneWidth, int sceneHeight)
{
tonemap.Render(state);
colormap.Render(state, fixedcm);
lens.Render(state);
fxaa.Render(state);
customShaders.Run(state, "scene");
}

View file

@ -834,6 +834,10 @@ public:
PPPresent present;
PPShadowMap shadowmap;
PPCustomShaders customShaders;
void Pass1(PPRenderState *state, int fixedcm, int sceneWidth, int sceneHeight);
void Pass2(PPRenderState* state, int fixedcm, int sceneWidth, int sceneHeight);
};
extern Postprocess hw_postprocess;

View file

@ -135,7 +135,7 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni
VPUniforms.mClipLine.X = -1000001.f;
VPUniforms.mClipHeight = 0;
}
else VPUniforms.SetDefaults();
else VPUniforms.SetDefaults(this);
mClipper->SetViewpoint(Viewpoint);
ClearBuffers();
@ -387,14 +387,15 @@ HWPortal * HWDrawInfo::FindPortal(const void * src)
//
//-----------------------------------------------------------------------------
void HWViewpointUniforms::SetDefaults()
void HWViewpointUniforms::SetDefaults(HWDrawInfo *drawInfo)
{
mProjectionMatrix.loadIdentity();
mViewMatrix.loadIdentity();
mNormalViewMatrix.loadIdentity();
mViewHeight = viewheight;
mGlobVis = (float)R_GetGlobVis(r_viewwindow, r_visibility) / 32.f;
mPalLightLevels = static_cast<int>(gl_bandedswlight) | (static_cast<int>(gl_fogmode) << 8) | (static_cast<int>(gl_lightmode) << 16);
const int lightMode = drawInfo == nullptr ? static_cast<int>(*gl_lightmode) : static_cast<int>(drawInfo->lightmode);
mPalLightLevels = static_cast<int>(gl_bandedswlight) | (static_cast<int>(gl_fogmode) << 8) | (lightMode << 16);
mClipLine.X = -10000000.0f;
mShadowmapFilter = gl_shadowmap_filter;

View file

@ -3,6 +3,8 @@
#include "r_data/matrix.h"
#include "r_utility.h"
struct HWDrawInfo;
struct HWViewpointUniforms
{
VSMatrix mProjectionMatrix;
@ -23,7 +25,7 @@ struct HWViewpointUniforms
mNormalViewMatrix.computeNormalMatrix(mViewMatrix);
}
void SetDefaults();
void SetDefaults(HWDrawInfo *drawInfo);
};

View file

@ -46,18 +46,10 @@ void VkPostprocess::PostProcessScene(int fixedcm, const std::function<void()> &a
VkPPRenderState renderstate;
hw_postprocess.exposure.Render(&renderstate, sceneWidth, sceneHeight);
hw_postprocess.customShaders.Run(&renderstate, "beforebloom");
hw_postprocess.bloom.RenderBloom(&renderstate, sceneWidth, sceneHeight, fixedcm);
hw_postprocess.Pass1(&renderstate, fixedcm, sceneWidth, sceneHeight);
SetActiveRenderTarget();
afterBloomDrawEndScene2D();
hw_postprocess.tonemap.Render(&renderstate);
hw_postprocess.colormap.Render(&renderstate, fixedcm);
hw_postprocess.lens.Render(&renderstate);
hw_postprocess.fxaa.Render(&renderstate);
hw_postprocess.customShaders.Run(&renderstate, "scene");
hw_postprocess.Pass2(&renderstate, fixedcm, sceneWidth, sceneHeight);
}
void VkPostprocess::BlitSceneToPostprocess()

View file

@ -168,13 +168,13 @@ void VkRenderState::Apply(int dt)
mApplyCount = 0;
}
ApplyStreamData();
ApplyMatrices();
ApplyRenderPass(dt);
ApplyScissor();
ApplyViewport();
ApplyStencilRef();
ApplyDepthBias();
ApplyStreamData();
ApplyMatrices();
ApplyPushConstants();
ApplyVertexBuffers();
ApplyDynamicSet();
@ -327,6 +327,9 @@ void VkRenderState::ApplyStreamData()
{
mDataIndex = 0;
mStreamDataOffset += sizeof(StreamUBO);
if (mStreamDataOffset + sizeof(StreamUBO) >= fb->StreamUBO->Size())
WaitForStreamBuffers();
}
uint8_t *ptr = (uint8_t*)fb->StreamUBO->Memory();
memcpy(ptr + mStreamDataOffset + sizeof(StreamData) * mDataIndex, &mStreamData, sizeof(StreamData));
@ -420,11 +423,11 @@ void VkRenderState::ApplyMatrices()
{
auto fb = GetVulkanFrameBuffer();
if (mMatricesOffset + (fb->UniformBufferAlignedSize<MatricesUBO>() << 1) < fb->MatricesUBO->Size())
{
mMatricesOffset += fb->UniformBufferAlignedSize<MatricesUBO>();
memcpy(static_cast<uint8_t*>(fb->MatricesUBO->Memory()) + mMatricesOffset, &mMatrices, sizeof(MatricesUBO));
}
if (mMatricesOffset + (fb->UniformBufferAlignedSize<MatricesUBO>() << 1) >= fb->MatricesUBO->Size())
WaitForStreamBuffers();
mMatricesOffset += fb->UniformBufferAlignedSize<MatricesUBO>();
memcpy(static_cast<uint8_t*>(fb->MatricesUBO->Memory()) + mMatricesOffset, &mMatrices, sizeof(MatricesUBO));
}
}
@ -481,6 +484,16 @@ void VkRenderState::ApplyDynamicSet()
}
}
void VkRenderState::WaitForStreamBuffers()
{
EndRenderPass();
GetVulkanFrameBuffer()->WaitForCommands(false);
mApplyCount = 0;
mStreamDataOffset = 0;
mDataIndex = 0;
mMatricesOffset = 0;
}
void VkRenderState::Bind(int bindingpoint, uint32_t offset)
{
if (bindingpoint == VIEWPOINT_BINDINGPOINT)

View file

@ -63,6 +63,7 @@ protected:
void ApplyVertexBuffers();
void ApplyMaterial();
void WaitForStreamBuffers();
void BeginRenderPass(VulkanCommandBuffer *cmdbuffer);
bool mDepthClamp = true;

View file

@ -12,6 +12,8 @@ public:
{
AspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Layout = VK_IMAGE_LAYOUT_UNDEFINED;
PPFramebuffer.reset();
RSFramebuffers.clear();
DepthOnlyView.reset();
View.reset();
Image.reset();