From 40ee32a0ce8c2a109f27ad4f3150988272444fd1 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 17 Mar 2019 21:14:51 +0100 Subject: [PATCH] - minor adjustments --- src/gamedata/textures/textures.h | 1 + src/rendering/gl/renderer/gl_renderstate.cpp | 8 -------- src/rendering/gl/renderer/gl_renderstate.h | 3 --- .../hwrenderer/scene/hw_renderstate.cpp | 9 +++++++++ src/rendering/hwrenderer/scene/hw_renderstate.h | 4 ++++ src/rendering/vulkan/renderer/vk_renderstate.cpp | 16 ++++++++++++---- src/rendering/vulkan/renderer/vk_renderstate.h | 3 +++ src/rendering/vulkan/system/vk_framebuffer.cpp | 3 +-- 8 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/gamedata/textures/textures.h b/src/gamedata/textures/textures.h index 98e389462..bc9d4811d 100644 --- a/src/gamedata/textures/textures.h +++ b/src/gamedata/textures/textures.h @@ -293,6 +293,7 @@ class FTexture friend class FWarpTexture; friend class FMaterial; friend class OpenGLRenderer::FGLRenderState; // For now this needs access to some fields in ApplyMaterial. This should be rerouted through the Material class + friend class VkRenderState; friend struct FTexCoordInfo; friend class OpenGLRenderer::FHardwareTexture; friend class VkHardwareTexture; diff --git a/src/rendering/gl/renderer/gl_renderstate.cpp b/src/rendering/gl/renderer/gl_renderstate.cpp index a27e65140..da611f49a 100644 --- a/src/rendering/gl/renderer/gl_renderstate.cpp +++ b/src/rendering/gl/renderer/gl_renderstate.cpp @@ -583,12 +583,4 @@ bool FGLRenderState::SetDepthClamp(bool on) return res; } -void FGLRenderState::CheckTimer(uint64_t ShaderStartTime) -{ - // if firstFrame is not yet initialized, initialize it to current time - // if we're going to overflow a float (after ~4.6 hours, or 24 bits), re-init to regain precision - if ((firstFrame == 0) || (screen->FrameTime - firstFrame >= 1 << 24) || ShaderStartTime >= firstFrame) - firstFrame = screen->FrameTime; -} - } diff --git a/src/rendering/gl/renderer/gl_renderstate.h b/src/rendering/gl/renderer/gl_renderstate.h index c28d8963d..eda287634 100644 --- a/src/rendering/gl/renderer/gl_renderstate.h +++ b/src/rendering/gl/renderer/gl_renderstate.h @@ -42,8 +42,6 @@ struct GLSectorPlane; class FGLRenderState : public FRenderState { - uint64_t firstFrame = 0; - uint8_t mLastDepthClamp : 1; float mGlossiness, mSpecularLevel; @@ -95,7 +93,6 @@ public: void Apply(); void ApplyBuffers(); void ApplyBlendMode(); - void CheckTimer(uint64_t ShaderStartTime); void ResetVertexBuffer() { diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.cpp b/src/rendering/hwrenderer/scene/hw_renderstate.cpp index ec183e3fb..60fad5dbb 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.cpp +++ b/src/rendering/hwrenderer/scene/hw_renderstate.cpp @@ -156,3 +156,12 @@ void HWDrawInfo::SetFog(FRenderState &state, int lightlevel, int rellight, bool } } } + + +void FRenderState::CheckTimer(uint64_t ShaderStartTime) +{ + // if firstFrame is not yet initialized, initialize it to current time + // if we're going to overflow a float (after ~4.6 hours, or 24 bits), re-init to regain precision + if ((firstFrame == 0) || (screen->FrameTime - firstFrame >= 1 << 24) || ShaderStartTime >= firstFrame) + firstFrame = screen->FrameTime; +} diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.h b/src/rendering/hwrenderer/scene/hw_renderstate.h index c7d894fcf..f48235782 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.h +++ b/src/rendering/hwrenderer/scene/hw_renderstate.h @@ -172,6 +172,8 @@ protected: EPassType mPassType = NORMAL_PASS; + uint64_t firstFrame = 0; + public: VSMatrix mModelMatrix; VSMatrix mTextureMatrix; @@ -531,6 +533,8 @@ public: return mPassType; } + void CheckTimer(uint64_t ShaderStartTime); + // API-dependent render interface // Draw commands diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index e65daf23a..addde18f6 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -324,7 +324,7 @@ void VkRenderState::ApplyStreamData() mStreamData.uVertexColor = mColor.vec; mStreamData.uVertexNormal = mNormal.vec; - mStreamData.timer = 0.0f; // static_cast((double)(screen->FrameTime - firstFrame) * (double)mShaderTimer / 1000.); + mStreamData.timer = static_cast((double)(screen->FrameTime - firstFrame) * (double)mShaderTimer / 1000.); if (mGlowEnabled) { @@ -397,7 +397,7 @@ void VkRenderState::ApplyPushConstants() } int tempTM = TM_NORMAL; - if (mMaterial.mMaterial && mMaterial.mMaterial->tex->isHardwareCanvas()) + if (mMaterial.mMaterial && mMaterial.mMaterial->tex && mMaterial.mMaterial->tex->isHardwareCanvas()) tempTM = TM_OPAQUE; mPushConstants.uFogEnabled = fogset; @@ -409,8 +409,8 @@ void VkRenderState::ApplyPushConstants() mPushConstants.uAlphaThreshold = mAlphaThreshold; mPushConstants.uClipSplit = { mClipSplit[0], mClipSplit[1] }; - //if (mMaterial.mMaterial) - // mPushConstants.uSpecularMaterial = { mMaterial.mMaterial->tex->Glossiness, mMaterial.mMaterial->tex->SpecularLevel }; + if (mMaterial.mMaterial && mMaterial.mMaterial->tex) + mPushConstants.uSpecularMaterial = { mMaterial.mMaterial->tex->Glossiness, mMaterial.mMaterial->tex->SpecularLevel }; mPushConstants.uLightIndex = screen->mLights->BindUBO(mLightIndex); mPushConstants.uDataIndex = mDataIndex; @@ -502,6 +502,9 @@ void VkRenderState::ApplyMaterial() mCommandBuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, passManager->PipelineLayout.get(), 1, base->GetDescriptorSet(mMaterial)); } + if (mMaterial.mMaterial && mMaterial.mMaterial->tex) + mShaderTimer = mMaterial.mMaterial->tex->shaderspeed; + mMaterial.mChanged = false; } } @@ -537,6 +540,11 @@ void VkRenderState::Bind(int bindingpoint, uint32_t offset) } } +void VkRenderState::BeginFrame() +{ + mMaterial.Reset(); +} + void VkRenderState::EndRenderPass() { if (mCommandBuffer) diff --git a/src/rendering/vulkan/renderer/vk_renderstate.h b/src/rendering/vulkan/renderer/vk_renderstate.h index ba510ae4e..fd8d5c825 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.h +++ b/src/rendering/vulkan/renderer/vk_renderstate.h @@ -42,6 +42,7 @@ public: void EnableLineSmooth(bool on) override; void EnableDrawBuffers(int count) override; + void BeginFrame(); void SetRenderTarget(VulkanImageView *view, int width, int height, VkSampleCountFlagBits samples); void Bind(int bindingpoint, uint32_t offset); void EndRenderPass(); @@ -86,6 +87,8 @@ protected: int mColorMask = 15; int mCullMode = 0; + float mShaderTimer = 0.0f; + MatricesUBO mMatrices = {}; StreamData mStreamData = {}; PushConstants mPushConstants = {}; diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 20d538e52..585f86c09 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -366,9 +366,7 @@ sector_t *VulkanFrameBuffer::RenderView(player_t *player) NoInterpolateView = false; // Shader start time does not need to be handled per level. Just use the one from the camera to render from. -#if 0 GetRenderState()->CheckTimer(player->camera->Level->ShaderStartTime); -#endif // prepare all camera textures that have been used in the last frame. // This must be done for all levels, not just the primary one! for (auto Level : AllLevels()) @@ -763,6 +761,7 @@ void VulkanFrameBuffer::BeginFrame() mScreenBuffers->BeginFrame(screen->mScreenViewport.width, screen->mScreenViewport.height, screen->mSceneViewport.width, screen->mSceneViewport.height); mSaveBuffers->BeginFrame(SAVEPICWIDTH, SAVEPICHEIGHT, SAVEPICWIDTH, SAVEPICHEIGHT); mPostprocess->BeginFrame(); + mRenderState->BeginFrame(); mRenderPassManager->UpdateDynamicSet(); }