- fix enough bugs to finally get some visuals

This commit is contained in:
Magnus Norddahl 2019-02-26 20:19:54 +01:00
parent e1d1358249
commit fe67a2c24f
13 changed files with 93 additions and 19 deletions

View file

@ -6,6 +6,7 @@
#include "vulkan/system/vk_buffers.h"
#include "hwrenderer/data/flatvertices.h"
#include "hwrenderer/scene/hw_viewpointuniforms.h"
#include "rendering/2d/v_2ddrawer.h"
VkRenderPassManager::VkRenderPassManager()
{
@ -123,7 +124,7 @@ VkRenderPassSetup::VkRenderPassSetup()
void VkRenderPassSetup::CreateRenderPass()
{
RenderPassBuilder builder;
builder.addRgba16fAttachment(false, VK_IMAGE_LAYOUT_GENERAL);
builder.addRgba16fAttachment(true, VK_IMAGE_LAYOUT_GENERAL);
builder.addSubpass();
builder.addSubpassColorAttachmentRef(0, VK_IMAGE_LAYOUT_GENERAL);
builder.addExternalSubpassDependency();
@ -136,14 +137,26 @@ void VkRenderPassSetup::CreatePipeline()
GraphicsPipelineBuilder builder;
builder.addVertexShader(fb->GetShaderManager()->vert.get());
builder.addFragmentShader(fb->GetShaderManager()->frag.get());
builder.addVertexBufferBinding(0, sizeof(FFlatVertex));
builder.addVertexBufferBinding(0, sizeof(F2DDrawer::TwoDVertex));
builder.addVertexAttribute(0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(F2DDrawer::TwoDVertex, x));
builder.addVertexAttribute(1, 0, VK_FORMAT_R32G32_SFLOAT, offsetof(F2DDrawer::TwoDVertex, u));
builder.addVertexAttribute(2, 0, VK_FORMAT_R8G8B8A8_UNORM, offsetof(F2DDrawer::TwoDVertex, color0));
builder.addVertexAttribute(3, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(F2DDrawer::TwoDVertex, x));
builder.addVertexAttribute(4, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(F2DDrawer::TwoDVertex, x));
builder.addVertexAttribute(5, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(F2DDrawer::TwoDVertex, x));
#if 0
builder.addVertexBufferBinding(0, sizeof(FFlatVertex));
builder.addVertexAttribute(0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(FFlatVertex, x));
builder.addVertexAttribute(1, 0, VK_FORMAT_R32G32_SFLOAT, offsetof(FFlatVertex, u));
// To do: not all vertex formats has all the data..
//builder.addVertexAttribute(2, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(FFlatVertex, x));
//builder.addVertexAttribute(3, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(FFlatVertex, x));
//builder.addVertexAttribute(4, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(FFlatVertex, x));
//builder.addVertexAttribute(5, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(FFlatVertex, x));
builder.addVertexAttribute(2, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(FFlatVertex, x));
builder.addVertexAttribute(3, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(FFlatVertex, x));
builder.addVertexAttribute(4, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(FFlatVertex, x));
builder.addVertexAttribute(5, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(FFlatVertex, x));
#endif
builder.setViewport(0.0f, 0.0f, (float)SCREENWIDTH, (float)SCREENHEIGHT);
builder.setScissor(0, 0, SCREENWIDTH, SCREENHEIGHT);
builder.setAlphaBlendMode();

View file

@ -18,6 +18,7 @@
VkRenderState::VkRenderState()
{
Reset();
}
void VkRenderState::ClearScreen()
@ -54,7 +55,8 @@ void VkRenderState::DrawIndexed(int dt, int index, int count, bool apply)
BindDescriptorSets();
drawcalls.Clock();
mCommandBuffer->drawIndexed(count, 1, 0, index * (int)sizeof(uint32_t), 0);
if (mMaterial.mMaterial)
mCommandBuffer->drawIndexed(count, 1, index, 0, 0);
drawcalls.Unclock();
}
@ -149,12 +151,24 @@ void VkRenderState::Apply(int dt)
beginInfo.setRenderPass(passSetup->RenderPass.get());
beginInfo.setRenderArea(0, 0, SCREENWIDTH, SCREENHEIGHT);
beginInfo.setFramebuffer(passSetup->Framebuffer.get());
beginInfo.addClearColor(0.0f, 0.0f, 0.0f, 1.0f);
beginInfo.addClearDepthStencil(0.0f, 0);
beginInfo.addClearColor(1.0f, 0.0f, 0.0f, 1.0f);
beginInfo.addClearDepthStencil(1.0f, 0);
mCommandBuffer->beginRenderPass(beginInfo);
mCommandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, passSetup->Pipeline.get());
}
mMatrices.ModelMatrix = mModelMatrix;
mMatrices.NormalModelMatrix.computeNormalMatrix(mModelMatrix);
mMatrices.TextureMatrix = mTextureMatrix;
memcpy(static_cast<uint8_t*>(fb->MatricesUBO->Memory()) + mMatricesOffset, &mMatrices, sizeof(MatricesUBO));
memcpy(static_cast<uint8_t*>(fb->ColorsUBO->Memory()) + mColorsOffset, &mColors, sizeof(ColorsUBO));
memcpy(static_cast<uint8_t*>(fb->GlowingWallsUBO->Memory()) + mGlowingWallsOffset, &mGlowingWalls, sizeof(GlowingWallsUBO));
mPushConstants.uTextureMode = 0;
mPushConstants.uLightLevel = 1.0f;
mPushConstants.uLightIndex = -1;
mCommandBuffer->pushConstants(passManager->PipelineLayout.get(), VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, (uint32_t)sizeof(PushConstants), &mPushConstants);
VkBuffer vertexBuffers[] = { static_cast<VKVertexBuffer*>(mVertexBuffer)->mBuffer->buffer };
@ -165,7 +179,8 @@ void VkRenderState::Apply(int dt)
BindDescriptorSets();
if (mMaterial.mChanged)
//if (mMaterial.mChanged)
if (mMaterial.mMaterial)
{
auto base = static_cast<VkHardwareTexture*>(mMaterial.mMaterial->GetLayer(0, mMaterial.mTranslation));
if (base)

View file

@ -47,9 +47,13 @@ private:
bool mLastDepthClamp = true;
VulkanCommandBuffer *mCommandBuffer = nullptr;
PushConstants mPushConstants;
bool mDescriptorsChanged = true;
MatricesUBO mMatrices = {};
ColorsUBO mColors = {};
GlowingWallsUBO mGlowingWalls = {};
PushConstants mPushConstants = {};
uint32_t mViewpointOffset = 0;
uint32_t mLightBufferOffset = 0;
uint32_t mMatricesOffset = 0;

View file

@ -122,6 +122,7 @@ static const char *shaderBindings = R"(
#endif
// #define SUPPORTS_SHADOWMAPS
#define VULKAN_COORDINATE_SYSTEM
)";
std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(const char *vert_lump, const char *defines)

View file

@ -5,6 +5,16 @@
#include "vulkan/renderer/vk_renderstate.h"
#include "doomerrors.h"
VKBuffer::~VKBuffer()
{
if (map)
mBuffer->Unmap();
auto fb = GetVulkanFrameBuffer();
if (fb && mBuffer)
fb->mFrameDeleteList.push_back(std::move(mBuffer));
}
void VKBuffer::SetData(size_t size, const void *data, bool staticdata)
{
auto fb = GetVulkanFrameBuffer();
@ -37,6 +47,8 @@ void VKBuffer::SetData(size_t size, const void *data, bool staticdata)
if (mPersistent)
{
map = mBuffer->Map(0, size);
if (data)
memcpy(map, data, size);
}
else if (data)
{

View file

@ -12,7 +12,7 @@
class VKBuffer : virtual public IBuffer
{
public:
~VKBuffer() { if (map) Unmap(); }
~VKBuffer();
void SetData(size_t size, const void *data, bool staticdata) override;
void SetSubData(size_t offset, size_t size, const void *data) override;

View file

@ -162,7 +162,7 @@ std::unique_ptr<VulkanShader> ShaderBuilder::create(VulkanDevice *device)
glslang::SpvOptions spvOptions;
spvOptions.generateDebugInfo = false;
spvOptions.disableOptimizer = false;
spvOptions.optimizeSize = false;
spvOptions.optimizeSize = true;
std::vector<unsigned int> spirv;
spv::SpvBuildLogger logger;

View file

@ -390,6 +390,9 @@ void VulkanDevice::releaseResources()
renderFinishedFence.reset();
swapChain.reset();
if (allocator)
vmaDestroyAllocator(allocator);
if (device)
vkDestroyDevice(device, nullptr);
device = nullptr;

View file

@ -63,12 +63,22 @@ VulkanFrameBuffer::VulkanFrameBuffer(void *hMonitor, bool fullscreen, VulkanDevi
VulkanFrameBuffer::~VulkanFrameBuffer()
{
delete MatricesUBO;
delete ColorsUBO;
delete GlowingWallsUBO;
delete mVertexData;
delete mSkyData;
delete mViewpoints;
delete mLights;
for (auto tex : AllTextures)
tex->Reset();
}
void VulkanFrameBuffer::InitializeState()
{
gl_vendorstring = "Vulkan";
hwcaps = RFL_SHADER_STORAGE_BUFFER | RFL_BUFFER_STORAGE;
mUploadSemaphore.reset(new VulkanSemaphore(device));
mGraphicsCommandPool.reset(new VulkanCommandPool(device, device->graphicsFamily));
@ -81,9 +91,9 @@ void VulkanFrameBuffer::InitializeState()
MatricesUBO = (VKDataBuffer*)CreateDataBuffer(1234, false);
ColorsUBO = (VKDataBuffer*)CreateDataBuffer(1234, false);
GlowingWallsUBO = (VKDataBuffer*)CreateDataBuffer(1234, false);
MatricesUBO->SetData(sizeof(MatricesUBO) * 128, 0, false);
ColorsUBO->SetData(sizeof(ColorsUBO) * 128, 0, false);
GlowingWallsUBO->SetData(sizeof(GlowingWallsUBO) * 128, 0, false);
MatricesUBO->SetData(sizeof(MatricesUBO) * 128, nullptr, false);
ColorsUBO->SetData(sizeof(ColorsUBO) * 128, nullptr, false);
GlowingWallsUBO->SetData(sizeof(GlowingWallsUBO) * 128, nullptr, false);
mShaderManager.reset(new VkShaderManager(device));
mSamplerManager.reset(new VkSamplerManager(device));
@ -148,6 +158,8 @@ void VulkanFrameBuffer::Update()
if (mUploadCommands)
{
mUploadCommands->end();
// Submit upload commands immediately
VkSubmitInfo submitInfo = {};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
@ -201,6 +213,7 @@ void VulkanFrameBuffer::Update()
mPresentCommands.reset();
mUploadCommands.reset();
mFrameDeleteList.clear();
Finish.Unclock();

View file

@ -32,6 +32,8 @@ public:
VKDataBuffer *ColorsUBO = nullptr;
VKDataBuffer *GlowingWallsUBO = nullptr;
std::vector<std::unique_ptr<VulkanBuffer>> mFrameDeleteList;
VulkanFrameBuffer(void *hMonitor, bool fullscreen, VulkanDevice *dev);
~VulkanFrameBuffer();

View file

@ -60,8 +60,8 @@ VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &s
{
0xff0000ff, 0xff0000ff, 0xffff00ff, 0xffff00ff,
0xff0000ff, 0xff0000ff, 0xffff00ff, 0xffff00ff,
0xff0000ff, 0x00ffffff, 0x0000ffff, 0x0000ffff,
0xff0000ff, 0x00ffffff, 0x0000ffff, 0x0000ffff,
0xff00ff00, 0xff00ff00, 0x0000ffff, 0xff00ffff,
0xff00ff00, 0xff00ff00, 0x0000ffff, 0xff00ffff,
};
CreateTexture(4, 4, 4, VK_FORMAT_R8G8B8A8_UNORM, testpixels);
}

View file

@ -542,6 +542,9 @@ vec3 AmbientOcclusionColor()
void main()
{
FragColor = texture(tex, vTexCoord.st);
return;
Material material = ProcessMaterial();
vec4 frag = material.Base;

View file

@ -80,7 +80,12 @@ void main()
#endif
gl_Position = ProjectionMatrix * eyeCoordPos;
#ifdef VULKAN_COORDINATE_SYSTEM
gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;
gl_Position.y = -gl_Position.y;
#endif
if (uClipHeightDirection != 0.0) // clip planes used for reflective flats
{
gl_ClipDistance[0] = (worldcoord.y - uClipHeight) * uClipHeightDirection;
@ -98,4 +103,7 @@ void main()
gl_ClipDistance[1] = worldcoord.y - uClipSplit.x;
gl_ClipDistance[2] = uClipSplit.y - worldcoord.y;
gl_ClipDistance[0] = 1;
gl_ClipDistance[1] = 1;
gl_ClipDistance[2] = 1;
}