diff --git a/src/rendering/vulkan/renderer/vk_renderpass.cpp b/src/rendering/vulkan/renderer/vk_renderpass.cpp index 091cd06e5..cb6b80a4a 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.cpp +++ b/src/rendering/vulkan/renderer/vk_renderpass.cpp @@ -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(); diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 584ec4c3e..f3da36940 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -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(fb->MatricesUBO->Memory()) + mMatricesOffset, &mMatrices, sizeof(MatricesUBO)); + memcpy(static_cast(fb->ColorsUBO->Memory()) + mColorsOffset, &mColors, sizeof(ColorsUBO)); + memcpy(static_cast(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(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(mMaterial.mMaterial->GetLayer(0, mMaterial.mTranslation)); if (base) diff --git a/src/rendering/vulkan/renderer/vk_renderstate.h b/src/rendering/vulkan/renderer/vk_renderstate.h index 48def555a..24ab0ab03 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.h +++ b/src/rendering/vulkan/renderer/vk_renderstate.h @@ -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; diff --git a/src/rendering/vulkan/shaders/vk_shader.cpp b/src/rendering/vulkan/shaders/vk_shader.cpp index ce4568ec6..76aea3c7e 100644 --- a/src/rendering/vulkan/shaders/vk_shader.cpp +++ b/src/rendering/vulkan/shaders/vk_shader.cpp @@ -122,6 +122,7 @@ static const char *shaderBindings = R"( #endif // #define SUPPORTS_SHADOWMAPS + #define VULKAN_COORDINATE_SYSTEM )"; std::unique_ptr VkShaderManager::LoadVertShader(const char *vert_lump, const char *defines) diff --git a/src/rendering/vulkan/system/vk_buffers.cpp b/src/rendering/vulkan/system/vk_buffers.cpp index ef5cc9348..a25551509 100644 --- a/src/rendering/vulkan/system/vk_buffers.cpp +++ b/src/rendering/vulkan/system/vk_buffers.cpp @@ -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) { diff --git a/src/rendering/vulkan/system/vk_buffers.h b/src/rendering/vulkan/system/vk_buffers.h index 276b8f6b0..72ea6a46a 100644 --- a/src/rendering/vulkan/system/vk_buffers.h +++ b/src/rendering/vulkan/system/vk_buffers.h @@ -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; diff --git a/src/rendering/vulkan/system/vk_builders.cpp b/src/rendering/vulkan/system/vk_builders.cpp index 839b1b356..f4a961f65 100644 --- a/src/rendering/vulkan/system/vk_builders.cpp +++ b/src/rendering/vulkan/system/vk_builders.cpp @@ -162,7 +162,7 @@ std::unique_ptr ShaderBuilder::create(VulkanDevice *device) glslang::SpvOptions spvOptions; spvOptions.generateDebugInfo = false; spvOptions.disableOptimizer = false; - spvOptions.optimizeSize = false; + spvOptions.optimizeSize = true; std::vector spirv; spv::SpvBuildLogger logger; diff --git a/src/rendering/vulkan/system/vk_device.cpp b/src/rendering/vulkan/system/vk_device.cpp index 0364c1b8c..cbed3b5dc 100644 --- a/src/rendering/vulkan/system/vk_device.cpp +++ b/src/rendering/vulkan/system/vk_device.cpp @@ -390,6 +390,9 @@ void VulkanDevice::releaseResources() renderFinishedFence.reset(); swapChain.reset(); + if (allocator) + vmaDestroyAllocator(allocator); + if (device) vkDestroyDevice(device, nullptr); device = nullptr; diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 5d186ced4..c75b4592c 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -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(); diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index ff0187d5a..8e9bf18d2 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -32,6 +32,8 @@ public: VKDataBuffer *ColorsUBO = nullptr; VKDataBuffer *GlowingWallsUBO = nullptr; + std::vector> mFrameDeleteList; + VulkanFrameBuffer(void *hMonitor, bool fullscreen, VulkanDevice *dev); ~VulkanFrameBuffer(); diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index 8c498bece..e1226ea63 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -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); } diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index d952e2b7b..d4839f9ac 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -542,6 +542,9 @@ vec3 AmbientOcclusionColor() void main() { +FragColor = texture(tex, vTexCoord.st); +return; + Material material = ProcessMaterial(); vec4 frag = material.Base; diff --git a/wadsrc/static/shaders/glsl/main.vp b/wadsrc/static/shaders/glsl/main.vp index 0335c9354..e9ba4def5 100644 --- a/wadsrc/static/shaders/glsl/main.vp +++ b/wadsrc/static/shaders/glsl/main.vp @@ -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; }