2019-02-21 21:49:00 +00:00
|
|
|
|
|
|
|
#include "vk_renderstate.h"
|
|
|
|
#include "vulkan/system/vk_framebuffer.h"
|
2019-02-26 10:27:29 +00:00
|
|
|
#include "vulkan/system/vk_builders.h"
|
|
|
|
#include "vulkan/renderer/vk_renderpass.h"
|
2019-02-26 14:29:08 +00:00
|
|
|
#include "vulkan/textures/vk_hwtexture.h"
|
2019-02-21 21:49:00 +00:00
|
|
|
#include "templates.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "r_data/colormaps.h"
|
|
|
|
#include "hwrenderer/scene/hw_skydome.h"
|
2019-02-26 10:27:29 +00:00
|
|
|
#include "hwrenderer/scene/hw_viewpointuniforms.h"
|
2019-02-21 21:49:00 +00:00
|
|
|
#include "hwrenderer/dynlights/hw_lightbuffer.h"
|
|
|
|
#include "hwrenderer/utility/hw_cvars.h"
|
|
|
|
#include "hwrenderer/utility/hw_clock.h"
|
|
|
|
#include "hwrenderer/data/flatvertices.h"
|
|
|
|
#include "hwrenderer/data/hw_viewpointbuffer.h"
|
2019-02-26 10:27:29 +00:00
|
|
|
#include "hwrenderer/data/shaderuniforms.h"
|
|
|
|
|
|
|
|
VkRenderState::VkRenderState()
|
|
|
|
{
|
|
|
|
}
|
2019-02-21 21:49:00 +00:00
|
|
|
|
|
|
|
void VkRenderState::ClearScreen()
|
|
|
|
{
|
|
|
|
screen->mViewpoints->Set2D(*this, SCREENWIDTH, SCREENHEIGHT);
|
|
|
|
SetColor(0, 0, 0);
|
|
|
|
Apply(DT_TriangleStrip);
|
|
|
|
|
|
|
|
/*
|
|
|
|
glDisable(GL_MULTISAMPLE);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
mCommandBuffer->draw(4, 1, FFlatVertexBuffer::FULLSCREEN_INDEX, 0);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::Draw(int dt, int index, int count, bool apply)
|
|
|
|
{
|
|
|
|
if (apply)
|
|
|
|
Apply(dt);
|
2019-02-26 10:27:29 +00:00
|
|
|
else if (mDescriptorsChanged)
|
|
|
|
BindDescriptorSets();
|
|
|
|
|
2019-02-21 21:49:00 +00:00
|
|
|
drawcalls.Clock();
|
2019-02-26 15:50:54 +00:00
|
|
|
mCommandBuffer->draw(count, 1, index, 0);
|
2019-02-21 21:49:00 +00:00
|
|
|
drawcalls.Unclock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::DrawIndexed(int dt, int index, int count, bool apply)
|
|
|
|
{
|
|
|
|
if (apply)
|
|
|
|
Apply(dt);
|
2019-02-26 10:27:29 +00:00
|
|
|
else if (mDescriptorsChanged)
|
|
|
|
BindDescriptorSets();
|
|
|
|
|
2019-02-21 21:49:00 +00:00
|
|
|
drawcalls.Clock();
|
2019-02-26 15:50:54 +00:00
|
|
|
mCommandBuffer->drawIndexed(count, 1, 0, index * (int)sizeof(uint32_t), 0);
|
2019-02-21 21:49:00 +00:00
|
|
|
drawcalls.Unclock();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VkRenderState::SetDepthClamp(bool on)
|
|
|
|
{
|
|
|
|
bool lastValue = mLastDepthClamp;
|
|
|
|
mLastDepthClamp = on;
|
|
|
|
return lastValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::SetDepthMask(bool on)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::SetDepthFunc(int func)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::SetDepthRange(float min, float max)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::SetColorMask(bool r, bool g, bool b, bool a)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::EnableDrawBufferAttachments(bool on)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::SetStencil(int offs, int op, int flags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::SetCulling(int mode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::EnableClipDistance(int num, bool state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::Clear(int targets)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::EnableStencil(bool on)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::SetScissor(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::SetViewport(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::EnableDepthTest(bool on)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::EnableMultisampling(bool on)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::EnableLineSmooth(bool on)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::Apply(int dt)
|
|
|
|
{
|
|
|
|
auto fb = GetVulkanFrameBuffer();
|
2019-02-26 10:27:29 +00:00
|
|
|
auto passManager = fb->GetRenderPassManager();
|
|
|
|
auto passSetup = passManager->RenderPassSetup.get();
|
2019-02-21 21:49:00 +00:00
|
|
|
|
|
|
|
bool changingRenderPass = false; // To do: decide if the state matches current bound renderpass
|
|
|
|
|
|
|
|
if (!mCommandBuffer)
|
|
|
|
{
|
|
|
|
mCommandBuffer = fb->GetDrawCommands();
|
|
|
|
changingRenderPass = true;
|
|
|
|
}
|
|
|
|
else if (changingRenderPass)
|
|
|
|
{
|
|
|
|
mCommandBuffer->endRenderPass();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changingRenderPass)
|
|
|
|
{
|
|
|
|
RenderPassBegin beginInfo;
|
2019-02-26 10:27:29 +00:00
|
|
|
beginInfo.setRenderPass(passSetup->RenderPass.get());
|
2019-02-21 21:49:00 +00:00
|
|
|
beginInfo.setRenderArea(0, 0, SCREENWIDTH, SCREENHEIGHT);
|
2019-02-26 10:27:29 +00:00
|
|
|
beginInfo.setFramebuffer(passSetup->Framebuffer.get());
|
2019-02-21 21:49:00 +00:00
|
|
|
beginInfo.addClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
beginInfo.addClearDepthStencil(0.0f, 0);
|
|
|
|
mCommandBuffer->beginRenderPass(beginInfo);
|
2019-02-26 10:27:29 +00:00
|
|
|
mCommandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, passSetup->Pipeline.get());
|
2019-02-21 21:49:00 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 15:50:54 +00:00
|
|
|
mCommandBuffer->pushConstants(passManager->PipelineLayout.get(), VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, (uint32_t)sizeof(PushConstants), &mPushConstants);
|
2019-02-26 10:27:29 +00:00
|
|
|
|
|
|
|
VkBuffer vertexBuffers[] = { static_cast<VKVertexBuffer*>(mVertexBuffer)->mBuffer->buffer };
|
|
|
|
VkDeviceSize offsets[] = { 0 };
|
|
|
|
mCommandBuffer->bindVertexBuffers(0, 1, vertexBuffers, offsets);
|
|
|
|
|
|
|
|
mCommandBuffer->bindIndexBuffer(static_cast<VKIndexBuffer*>(mIndexBuffer)->mBuffer->buffer, 0, VK_INDEX_TYPE_UINT32);
|
|
|
|
|
|
|
|
BindDescriptorSets();
|
2019-02-26 14:29:08 +00:00
|
|
|
|
|
|
|
if (mMaterial.mChanged)
|
|
|
|
{
|
|
|
|
auto base = static_cast<VkHardwareTexture*>(mMaterial.mMaterial->GetLayer(0, mMaterial.mTranslation));
|
|
|
|
if (base)
|
|
|
|
mCommandBuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, passManager->PipelineLayout.get(), 1, base->GetDescriptorSet(mMaterial));
|
|
|
|
|
|
|
|
mMaterial.mChanged = false;
|
|
|
|
}
|
2019-02-26 10:27:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::Bind(int bindingpoint, uint32_t offset)
|
|
|
|
{
|
|
|
|
if (bindingpoint == VIEWPOINT_BINDINGPOINT)
|
|
|
|
{
|
|
|
|
mViewpointOffset = offset;
|
|
|
|
}
|
|
|
|
else if (bindingpoint == LIGHTBUF_BINDINGPOINT)
|
|
|
|
{
|
|
|
|
mLightBufferOffset = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDescriptorsChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::BindDescriptorSets()
|
|
|
|
{
|
|
|
|
auto fb = GetVulkanFrameBuffer();
|
|
|
|
auto passManager = fb->GetRenderPassManager();
|
|
|
|
|
2019-02-26 15:50:54 +00:00
|
|
|
uint32_t offsets[5] = { mViewpointOffset, mLightBufferOffset, mMatricesOffset, mColorsOffset, mGlowingWallsOffset };
|
|
|
|
mCommandBuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, passManager->PipelineLayout.get(), 0, passManager->DynamicSet.get(), 5, offsets);
|
2019-02-26 10:27:29 +00:00
|
|
|
mDescriptorsChanged = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VkRenderState::EndRenderPass()
|
|
|
|
{
|
|
|
|
if (mCommandBuffer)
|
|
|
|
{
|
|
|
|
mCommandBuffer->endRenderPass();
|
|
|
|
mCommandBuffer = nullptr;
|
|
|
|
}
|
2019-02-21 21:49:00 +00:00
|
|
|
}
|