From c43cef96d1e0ac5a61a515d81bd4e42f50f3b4bc Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 7 May 2023 00:49:54 +0200 Subject: [PATCH] Remove the reserved vbo_shadowdata so only hw_vertexbuffer still needs it --- .../hwrenderer/data/flatvertices.cpp | 52 +------------------ .../rendering/hwrenderer/data/flatvertices.h | 13 ----- src/common/rendering/v_framebuffer.cpp | 1 - .../vulkan/pipelines/vk_renderpass.cpp | 3 -- .../rendering/vulkan/vk_pprenderstate.cpp | 6 +-- .../rendering/vulkan/vk_renderstate.cpp | 15 +++++- src/rendering/hwrenderer/hw_vertexbuilder.cpp | 4 +- wadsrc/static/shaders/pp/screenquad.vp | 18 +++++-- 8 files changed, 32 insertions(+), 80 deletions(-) diff --git a/src/common/rendering/hwrenderer/data/flatvertices.cpp b/src/common/rendering/hwrenderer/data/flatvertices.cpp index 2ba92f55af..4f7dadd647 100644 --- a/src/common/rendering/hwrenderer/data/flatvertices.cpp +++ b/src/common/rendering/hwrenderer/data/flatvertices.cpp @@ -48,37 +48,6 @@ FFlatVertexBuffer::FFlatVertexBuffer(DFrameBuffer* fb, int width, int height, int pipelineNbr) : fb(fb), mPipelineNbr(pipelineNbr) { - vbo_shadowdata.Resize(NUM_RESERVED); - - // the first quad is reserved for handling coordinates through uniforms. - vbo_shadowdata[0].Set(0, 0, 0, 0, 0); - vbo_shadowdata[1].Set(1, 0, 0, 0, 0); - vbo_shadowdata[2].Set(2, 0, 0, 0, 0); - vbo_shadowdata[3].Set(3, 0, 0, 0, 0); - - // and the second one for the fullscreen quad used for blend overlays. - vbo_shadowdata[4].Set(0, 0, 0, 0, 0); - vbo_shadowdata[5].Set(0, (float)height, 0, 0, 1); - vbo_shadowdata[6].Set((float)width, 0, 0, 1, 0); - vbo_shadowdata[7].Set((float)width, (float)height, 0, 1, 1); - - // and this is for the postprocessing copy operation - vbo_shadowdata[8].Set(-1.0f, -1.0f, 0, 0.0f, 0.0f); - vbo_shadowdata[9].Set(3.0f, -1.0f, 0, 2.f, 0.0f); - vbo_shadowdata[10].Set(-1.0f, 3.0f, 0, 0.0f, 2.f); - vbo_shadowdata[11].Set(3.0f, 3.0f, 0, 2.f, 2.f); // Note: not used anymore - - // The next two are the stencil caps. - vbo_shadowdata[12].Set(-32767.0f, 32767.0f, -32767.0f, 0, 0); - vbo_shadowdata[13].Set(-32767.0f, 32767.0f, 32767.0f, 0, 0); - vbo_shadowdata[14].Set(32767.0f, 32767.0f, 32767.0f, 0, 0); - vbo_shadowdata[15].Set(32767.0f, 32767.0f, -32767.0f, 0, 0); - - vbo_shadowdata[16].Set(-32767.0f, -32767.0f, -32767.0f, 0, 0); - vbo_shadowdata[17].Set(-32767.0f, -32767.0f, 32767.0f, 0, 0); - vbo_shadowdata[18].Set(32767.0f, -32767.0f, 32767.0f, 0, 0); - vbo_shadowdata[19].Set(32767.0f, -32767.0f, -32767.0f, 0, 0); - mIndexBuffer = fb->CreateIndexBuffer(); int data[4] = {}; mIndexBuffer->SetData(4, data, BufferUsageType::Static); // On Vulkan this may not be empty, so set some dummy defaults to avoid crashes. @@ -99,9 +68,7 @@ FFlatVertexBuffer::FFlatVertexBuffer(DFrameBuffer* fb, int width, int height, in mVertexBuffer = mVertexBufferPipeline[mPipelinePos]; - mIndex = mCurIndex = NUM_RESERVED; - mNumReserved = NUM_RESERVED; - Copy(0, NUM_RESERVED); + mIndex = mCurIndex = 0; } //========================================================================== @@ -128,21 +95,6 @@ FFlatVertexBuffer::~FFlatVertexBuffer() // //========================================================================== -void FFlatVertexBuffer::OutputResized(int width, int height) -{ - vbo_shadowdata[4].Set(0, 0, 0, 0, 0); - vbo_shadowdata[5].Set(0, (float)height, 0, 0, 1); - vbo_shadowdata[6].Set((float)width, 0, 0, 1, 0); - vbo_shadowdata[7].Set((float)width, (float)height, 0, 1, 1); - Copy(4, 4); -} - -//========================================================================== -// -// -// -//========================================================================== - std::pair FFlatVertexBuffer::AllocVertices(unsigned int count) { FFlatVertex *p = GetBuffer(); @@ -169,7 +121,7 @@ void FFlatVertexBuffer::Copy(int start, int count) { mVertexBuffer = mVertexBufferPipeline[n]; Map(); - memcpy(GetBuffer(start), &vbo_shadowdata[0], count * sizeof(FFlatVertex)); + memcpy(GetBuffer(start), vbo_shadowdata.Data(), count * sizeof(FFlatVertex)); Unmap(); mVertexBuffer->Upload(start * sizeof(FFlatVertex), count * sizeof(FFlatVertex)); } diff --git a/src/common/rendering/hwrenderer/data/flatvertices.h b/src/common/rendering/hwrenderer/data/flatvertices.h index 2642715c8c..fd3c772cb8 100644 --- a/src/common/rendering/hwrenderer/data/flatvertices.h +++ b/src/common/rendering/hwrenderer/data/flatvertices.h @@ -73,7 +73,6 @@ public: unsigned int mIndex; std::atomic mCurIndex; - unsigned int mNumReserved; unsigned int mMapStart; @@ -81,21 +80,9 @@ public: static const unsigned int BUFFER_SIZE_TO_USE = BUFFER_SIZE-500; public: - enum - { - QUAD_INDEX = 0, - FULLSCREEN_INDEX = 4, - PRESENT_INDEX = 8, - STENCILTOP_INDEX = 12, - STENCILBOTTOM_INDEX = 16, - - NUM_RESERVED = 20 - }; - FFlatVertexBuffer(DFrameBuffer* fb, int width, int height, int pipelineNbr = 1); ~FFlatVertexBuffer(); - void OutputResized(int width, int height); std::pair GetBufferObjects() const { return std::make_pair(mVertexBuffer, mIndexBuffer); diff --git a/src/common/rendering/v_framebuffer.cpp b/src/common/rendering/v_framebuffer.cpp index 271348bc16..b24e9bcb5c 100644 --- a/src/common/rendering/v_framebuffer.cpp +++ b/src/common/rendering/v_framebuffer.cpp @@ -103,7 +103,6 @@ void DFrameBuffer::Update() { SetVirtualSize(clientWidth, clientHeight); V_OutputResized(clientWidth, clientHeight); - mVertexData->OutputResized(clientWidth, clientHeight); } } diff --git a/src/common/rendering/vulkan/pipelines/vk_renderpass.cpp b/src/common/rendering/vulkan/pipelines/vk_renderpass.cpp index 4204981d6b..3bc4af996e 100644 --- a/src/common/rendering/vulkan/pipelines/vk_renderpass.cpp +++ b/src/common/rendering/vulkan/pipelines/vk_renderpass.cpp @@ -366,9 +366,6 @@ void VkPPRenderPassSetup::CreatePipeline(const VkPPRenderPassKey& key) builder.AddVertexShader(key.Shader->VertexShader.get()); builder.AddFragmentShader(key.Shader->FragmentShader.get()); - 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)); builder.AddDynamicState(VK_DYNAMIC_STATE_VIEWPORT); builder.AddDynamicState(VK_DYNAMIC_STATE_SCISSOR); // Note: the actual values are ignored since we use dynamic viewport+scissor states diff --git a/src/common/rendering/vulkan/vk_pprenderstate.cpp b/src/common/rendering/vulkan/vk_pprenderstate.cpp index 129c5c909e..c30cef74bb 100644 --- a/src/common/rendering/vulkan/vk_pprenderstate.cpp +++ b/src/common/rendering/vulkan/vk_pprenderstate.cpp @@ -122,18 +122,14 @@ void VkPPRenderState::RenderScreenQuad(VkPPRenderPassSetup *passSetup, VulkanDes .AddClearColor(0.0f, 0.0f, 0.0f, 1.0f) .Execute(cmdbuffer); - VkBuffer vertexBuffers[] = { static_cast(screen->mVertexData->GetBufferObjects().first)->mBuffer->buffer }; - VkDeviceSize offsets[] = { 0 }; - cmdbuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, passSetup->Pipeline.get()); cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, passSetup->PipelineLayout.get(), 0, descriptorSet); - cmdbuffer->bindVertexBuffers(0, 1, vertexBuffers, offsets); cmdbuffer->setViewport(0, 1, &viewport); cmdbuffer->setScissor(0, 1, &scissor); if (stencilTest) cmdbuffer->setStencilReference(VK_STENCIL_FRONT_AND_BACK, screen->stencilValue); if (pushConstantsSize > 0) cmdbuffer->pushConstants(passSetup->PipelineLayout.get(), VK_SHADER_STAGE_FRAGMENT_BIT, 0, pushConstantsSize, pushConstants); - cmdbuffer->draw(3, 1, FFlatVertexBuffer::PRESENT_INDEX, 0); + cmdbuffer->draw(3, 1, 0, 0); cmdbuffer->endRenderPass(); } diff --git a/src/common/rendering/vulkan/vk_renderstate.cpp b/src/common/rendering/vulkan/vk_renderstate.cpp index 430ec51585..eb5b332688 100644 --- a/src/common/rendering/vulkan/vk_renderstate.cpp +++ b/src/common/rendering/vulkan/vk_renderstate.cpp @@ -51,10 +51,21 @@ VkRenderState::VkRenderState(VulkanRenderDevice* fb) : fb(fb), mStreamBufferWrit void VkRenderState::ClearScreen() { - Set2DViewpoint(SCREENWIDTH, SCREENHEIGHT); + int width = fb->GetWidth(); + int height = fb->GetHeight(); + + auto vertices = AllocVertices(4); + FFlatVertex* v = vertices.first; + v[0].Set(0, 0, 0, 0, 0); + v[1].Set(0, (float)height, 0, 0, 1); + v[2].Set((float)width, 0, 0, 1, 0); + v[3].Set((float)width, (float)height, 0, 1, 1); + + Set2DViewpoint(width, height); SetColor(0, 0, 0); Apply(DT_TriangleStrip); - mCommandBuffer->draw(4, 1, FFlatVertexBuffer::FULLSCREEN_INDEX, 0); + + mCommandBuffer->draw(4, 1, vertices.second, 0); } void VkRenderState::Draw(int dt, int index, int count, bool apply) diff --git a/src/rendering/hwrenderer/hw_vertexbuilder.cpp b/src/rendering/hwrenderer/hw_vertexbuilder.cpp index 718528afe1..c044175dd6 100644 --- a/src/rendering/hwrenderer/hw_vertexbuilder.cpp +++ b/src/rendering/hwrenderer/hw_vertexbuilder.cpp @@ -441,7 +441,7 @@ static void UpdatePlaneVertices(FFlatVertexBuffer *fvb, sector_t* sec, int plane static void CreateVertices(FFlatVertexBuffer* fvb, TArray& sectors) { - fvb->vbo_shadowdata.Resize(FFlatVertexBuffer::NUM_RESERVED); + fvb->vbo_shadowdata.Clear(); CreateIndexedFlatVertices(fvb, sectors); } @@ -489,7 +489,7 @@ void CheckUpdate(FFlatVertexBuffer* fvb, sector_t* sector) void CreateVBO(FFlatVertexBuffer* fvb, TArray& sectors) { - fvb->vbo_shadowdata.Resize(fvb->mNumReserved); + fvb->vbo_shadowdata.Clear(); CreateVertices(fvb, sectors); fvb->mCurIndex = fvb->mIndex = fvb->vbo_shadowdata.Size(); fvb->Copy(0, fvb->mIndex); diff --git a/wadsrc/static/shaders/pp/screenquad.vp b/wadsrc/static/shaders/pp/screenquad.vp index e5e10660f9..ce33270f1b 100644 --- a/wadsrc/static/shaders/pp/screenquad.vp +++ b/wadsrc/static/shaders/pp/screenquad.vp @@ -1,10 +1,20 @@ -layout(location = 0) in vec4 PositionInProjection; -layout(location = 1) in vec2 UV; layout(location = 0) out vec2 TexCoord; +vec2 positions[3] = vec2[]( + vec2(-1.0, -1.0), + vec2( 3.0, -1.0), + vec2(-1.0, 3.0) +); + +vec2 uvs[3] = vec2[]( + vec2(0.0, 0.0), + vec2(2.0, 0.0), + vec2(0.0, 2.0) +); + void main() { - gl_Position = PositionInProjection; - TexCoord = UV; + gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); + TexCoord = uvs[gl_VertexIndex]; }