Prepare FFlatVertexBuffer for removal

This commit is contained in:
Magnus Norddahl 2023-05-07 03:19:43 +02:00 committed by Christoph Oelckers
parent eb3878ad78
commit 8c4ddea735
13 changed files with 102 additions and 73 deletions

View file

@ -128,10 +128,3 @@ void FFlatVertexBuffer::Copy(int start, int count)
mVertexBuffer = old;
}
//==========================================================================
std::pair<FFlatVertex*, unsigned int> FRenderState::AllocVertices(unsigned int count)
{
return screen->mVertexData->AllocVertices(count);
}

View file

@ -22,6 +22,12 @@ MeshBuilder::MeshBuilder()
mVertices = screen->mVertexData->vbo_shadowdata;
}
void MeshBuilder::SetShadowData(const TArray<FFlatVertex>& vertices, const TArray<uint32_t>& indexes)
{
mVertices = vertices;
mIndexes = indexes;
}
void MeshBuilder::Draw(int dt, int index, int count, bool apply)
{
if (apply)

View file

@ -69,6 +69,8 @@ public:
// Vertices
std::pair<FFlatVertex*, unsigned int> AllocVertices(unsigned int count) override;
void SetShadowData(const TArray<FFlatVertex>& vertices, const TArray<uint32_t>& indexes) override;
void UpdateShadowData(unsigned int index, const FFlatVertex* vertices, unsigned int count) { }
// Buffers
int SetViewpoint(const HWViewpointUniforms& vp) override { return 0; }
@ -115,6 +117,7 @@ private:
DrawLists* mDrawLists = nullptr;
TArray<FFlatVertex> mVertices;
TArray<uint32_t> mIndexes;
int mDepthFunc = 0;
VSMatrix mTextureMatrix = VSMatrix::identity();

View file

@ -734,7 +734,9 @@ public:
// API-dependent render interface
// Vertices
virtual std::pair<FFlatVertex*, unsigned int> AllocVertices(unsigned int count);
virtual std::pair<FFlatVertex*, unsigned int> AllocVertices(unsigned int count) = 0;
virtual void SetShadowData(const TArray<FFlatVertex>& vertices, const TArray<uint32_t>& indexes) = 0;
virtual void UpdateShadowData(unsigned int index, const FFlatVertex* vertices, unsigned int count) = 0;
// Buffers
virtual int SetViewpoint(const HWViewpointUniforms& vp) = 0;

View file

@ -620,6 +620,30 @@ int VkRenderState::UploadBones(const TArray<VSMatrix>& bones)
}
}
std::pair<FFlatVertex*, unsigned int> VkRenderState::AllocVertices(unsigned int count)
{
return fb->mVertexData->AllocVertices(count);
}
void VkRenderState::SetShadowData(const TArray<FFlatVertex>& vertices, const TArray<uint32_t>& indexes)
{
FFlatVertexBuffer* fvb = fb->mVertexData;
fvb->vbo_shadowdata = vertices;
fvb->ibo_data = indexes;
fvb->mCurIndex = fvb->vbo_shadowdata.Size();
fvb->mIndex = fvb->vbo_shadowdata.Size();
fvb->Copy(0, fvb->mIndex);
fvb->mIndexBuffer->SetData(fvb->ibo_data.Size() * sizeof(uint32_t), &fvb->ibo_data[0], BufferUsageType::Static);
}
void VkRenderState::UpdateShadowData(unsigned int index, const FFlatVertex* vertices, unsigned int count)
{
FFlatVertexBuffer* fvb = fb->mVertexData;
FFlatVertex* mapvt = fvb->GetBuffer(index);
memcpy(mapvt, vertices, count * sizeof(FFlatVertex));
fvb->mVertexBuffer->Upload(index * sizeof(FFlatVertex), count * sizeof(FFlatVertex));
}
void VkRenderState::BeginFrame()
{
mMaterial.Reset();

View file

@ -55,6 +55,11 @@ public:
int UploadLights(const FDynLightData& lightdata) override;
int UploadBones(const TArray<VSMatrix>& bones) override;
// Vertices
std::pair<FFlatVertex*, unsigned int> AllocVertices(unsigned int count) override;
void SetShadowData(const TArray<FFlatVertex>& vertices, const TArray<uint32_t>& indexes) override;
void UpdateShadowData(unsigned int index, const FFlatVertex* vertices, unsigned int count) override;
protected:
void Apply(int dt);
void ApplyRenderPass(int dt);

View file

@ -706,7 +706,7 @@ struct sector_t
int vboindex[4]; // VBO indices of the 4 planes this sector uses during rendering. This is only needed for updating plane heights.
int iboindex[4]; // IBO indices of the 4 planes this sector uses during rendering
double vboheight[HW_MAX_PIPELINE_BUFFERS][2]; // Last calculated height for the 2 planes of this actual sector
double vboheight[2]; // Last calculated height for the 2 planes of this actual sector
int vbocount[2]; // Total count of vertices belonging to this sector's planes. This is used when a sector height changes and also contains all attached planes.
int ibocount; // number of indices per plane (identical for all planes.) If this is -1 the index buffer is not in use.

View file

@ -3243,7 +3243,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
InitRenderInfo(); // create hardware independent renderer resources for the level. This must be done BEFORE the PolyObj Spawn!!!
Level->ClearDynamic3DFloorData(); // CreateVBO must be run on the plain 3D floor data.
CreateVBO(screen->mVertexData, Level->sectors);
CreateVBO(*screen->RenderState(), Level->sectors);
meshcache.Clear();
screen->InitLightmap(Level->LMTextureSize, Level->LMTextureCount, Level->LMTextureData);

View file

@ -24,10 +24,14 @@
#include "g_levellocals.h"
#include "hw_vertexbuilder.h"
#include "hw_renderstate.h"
#include "flatvertices.h"
#include "earcut.hpp"
#include "v_video.h"
TArray<FFlatVertex> sector_vertices;
TArray<uint32_t> sector_indexes;
//=============================================================================
//
// Creates vertex meshes for sector planes
@ -210,12 +214,12 @@ static void SetFlatVertex(FFlatVertex& ffv, vertex_t* vt, const secplane_t& plan
//
//==========================================================================
static int CreateIndexedSectorVerticesLM(FFlatVertexBuffer* fvb, sector_t* sec, const secplane_t& plane, int floor, int h, int lightmapIndex)
static int CreateIndexedSectorVerticesLM(FRenderState& renderstate, sector_t* sec, const secplane_t& plane, int floor, int h, int lightmapIndex)
{
int i, pos;
float diff;
auto& ibo_data = fvb->ibo_data;
auto& ibo_data = sector_indexes;
int rt = ibo_data.Size();
if (sec->transdoor && floor) diff = -1.f;
@ -227,7 +231,7 @@ static int CreateIndexedSectorVerticesLM(FFlatVertexBuffer* fvb, sector_t* sec,
pos += sec->subsectors[i]->numlines;
}
auto& vbo_shadowdata = fvb->vbo_shadowdata;
auto& vbo_shadowdata = sector_vertices;
int vi = vbo_shadowdata.Reserve(pos);
int idx = ibo_data.Reserve((pos - 2 * sec->subsectorcount) * 3);
@ -276,12 +280,12 @@ static int CreateIndexedSectorVerticesLM(FFlatVertexBuffer* fvb, sector_t* sec,
return rt;
}
static int CreateIndexedSectorVertices(FFlatVertexBuffer* fvb, sector_t* sec, const secplane_t& plane, int floor, VertexContainer& verts, int h, int lightmapIndex)
static int CreateIndexedSectorVertices(FRenderState& renderstate, sector_t* sec, const secplane_t& plane, int floor, VertexContainer& verts, int h, int lightmapIndex)
{
if (sec->HasLightmaps && lightmapIndex != -1)
return CreateIndexedSectorVerticesLM(fvb, sec, plane, floor, h, lightmapIndex);
return CreateIndexedSectorVerticesLM(renderstate, sec, plane, floor, h, lightmapIndex);
auto& vbo_shadowdata = fvb->vbo_shadowdata;
auto& vbo_shadowdata = sector_vertices;
unsigned vi = vbo_shadowdata.Reserve(verts.vertices.Size());
float diff;
@ -294,7 +298,7 @@ static int CreateIndexedSectorVertices(FFlatVertexBuffer* fvb, sector_t* sec, co
vbo_shadowdata[vi + i].z += diff;
}
auto& ibo_data = fvb->ibo_data;
auto& ibo_data = sector_indexes;
unsigned rt = ibo_data.Reserve(verts.indices.Size());
for (unsigned i = 0; i < verts.indices.Size(); i++)
{
@ -309,22 +313,21 @@ static int CreateIndexedSectorVertices(FFlatVertexBuffer* fvb, sector_t* sec, co
//
//==========================================================================
static int CreateIndexedVertices(FFlatVertexBuffer* fvb, int h, sector_t* sec, const secplane_t& plane, int floor, VertexContainers& verts)
static int CreateIndexedVertices(FRenderState& renderstate, int h, sector_t* sec, const secplane_t& plane, int floor, VertexContainers& verts)
{
auto& vbo_shadowdata = fvb->vbo_shadowdata;
auto& vbo_shadowdata = sector_vertices;
sec->vboindex[h] = vbo_shadowdata.Size();
// First calculate the vertices for the sector itself
for (int n = 0; n < screen->mPipelineNbr; n++)
sec->vboheight[n][h] = sec->GetPlaneTexZ(h);
sec->vboheight[h] = sec->GetPlaneTexZ(h);
sec->ibocount = verts[sec->Index()].indices.Size();
sec->iboindex[h] = CreateIndexedSectorVertices(fvb, sec, plane, floor, verts[sec->Index()], h, 0);
sec->iboindex[h] = CreateIndexedSectorVertices(renderstate, sec, plane, floor, verts[sec->Index()], h, 0);
// Next are all sectors using this one as heightsec
TArray<sector_t*>& fakes = sec->e->FakeFloor.Sectors;
for (unsigned g = 0; g < fakes.Size(); g++)
{
sector_t* fsec = fakes[g];
fsec->iboindex[2 + h] = CreateIndexedSectorVertices(fvb, fsec, plane, false, verts[fsec->Index()], h, -1);
fsec->iboindex[2 + h] = CreateIndexedSectorVertices(renderstate, fsec, plane, false, verts[fsec->Index()], h, -1);
}
// and finally all attached 3D floors
@ -342,7 +345,7 @@ static int CreateIndexedVertices(FFlatVertexBuffer* fvb, int h, sector_t* sec, c
if (dotop || dobottom)
{
auto ndx = CreateIndexedSectorVertices(fvb, fsec, plane, false, verts[fsec->Index()], h, ffloorIndex + 1);
auto ndx = CreateIndexedSectorVertices(renderstate, fsec, plane, false, verts[fsec->Index()], h, ffloorIndex + 1);
if (dotop) ffloor->top.vindex = ndx;
if (dobottom) ffloor->bottom.vindex = ndx;
}
@ -359,7 +362,7 @@ static int CreateIndexedVertices(FFlatVertexBuffer* fvb, int h, sector_t* sec, c
//
//==========================================================================
static void CreateIndexedFlatVertices(FFlatVertexBuffer* fvb, TArray<sector_t>& sectors)
static void CreateIndexedFlatVertices(FRenderState& renderstate, TArray<sector_t>& sectors)
{
auto verts = BuildVertices(sectors);
@ -388,7 +391,7 @@ static void CreateIndexedFlatVertices(FFlatVertexBuffer* fvb, TArray<sector_t>&
{
for (auto& sec : sectors)
{
CreateIndexedVertices(fvb, h, &sec, sec.GetSecPlane(h), h == sector_t::floor, verts);
CreateIndexedVertices(renderstate, h, &sec, sec.GetSecPlane(h), h == sector_t::floor, verts);
}
}
@ -416,21 +419,19 @@ static void CreateIndexedFlatVertices(FFlatVertexBuffer* fvb, TArray<sector_t>&
//
//==========================================================================
static void UpdatePlaneVertices(FFlatVertexBuffer *fvb, sector_t* sec, int plane)
static void UpdatePlaneVertices(FRenderState& renderstate, sector_t* sec, int plane)
{
int startvt = sec->vboindex[plane];
int countvt = sec->vbocount[plane];
secplane_t& splane = sec->GetSecPlane(plane);
FFlatVertex* vt = &fvb->vbo_shadowdata[startvt];
FFlatVertex* mapvt = fvb->GetBuffer(startvt);
for (int i = 0; i < countvt; i++, vt++, mapvt++)
FFlatVertex* vt = &sector_vertices[startvt];
for (int i = 0; i < countvt; i++, vt++)
{
vt->z = (float)splane.ZatPoint(vt->x, vt->y);
if (plane == sector_t::floor && sec->transdoor) vt->z -= 1;
mapvt->z = vt->z;
}
fvb->mVertexBuffer->Upload(startvt * sizeof(FFlatVertex), countvt * sizeof(FFlatVertex));
renderstate.UpdateShadowData(startvt, &sector_vertices[startvt], countvt);
}
//==========================================================================
@ -439,10 +440,10 @@ static void UpdatePlaneVertices(FFlatVertexBuffer *fvb, sector_t* sec, int plane
//
//==========================================================================
static void CreateVertices(FFlatVertexBuffer* fvb, TArray<sector_t>& sectors)
static void CreateVertices(FRenderState& renderstate, TArray<sector_t>& sectors)
{
fvb->vbo_shadowdata.Clear();
CreateIndexedFlatVertices(fvb, sectors);
sector_vertices.Clear();
CreateIndexedFlatVertices(renderstate, sectors);
}
//==========================================================================
@ -451,17 +452,17 @@ static void CreateVertices(FFlatVertexBuffer* fvb, TArray<sector_t>& sectors)
//
//==========================================================================
static void CheckPlanes(FFlatVertexBuffer* fvb, sector_t* sector)
static void CheckPlanes(FRenderState& renderstate, sector_t* sector)
{
if (sector->GetPlaneTexZ(sector_t::ceiling) != sector->vboheight[screen->mVertexData->GetPipelinePos()][sector_t::ceiling])
if (sector->GetPlaneTexZ(sector_t::ceiling) != sector->vboheight[sector_t::ceiling])
{
UpdatePlaneVertices(fvb, sector, sector_t::ceiling);
sector->vboheight[screen->mVertexData->GetPipelinePos()][sector_t::ceiling] = sector->GetPlaneTexZ(sector_t::ceiling);
UpdatePlaneVertices(renderstate, sector, sector_t::ceiling);
sector->vboheight[sector_t::ceiling] = sector->GetPlaneTexZ(sector_t::ceiling);
}
if (sector->GetPlaneTexZ(sector_t::floor) != sector->vboheight[screen->mVertexData->GetPipelinePos()][sector_t::floor])
if (sector->GetPlaneTexZ(sector_t::floor) != sector->vboheight[sector_t::floor])
{
UpdatePlaneVertices(fvb, sector, sector_t::floor);
sector->vboheight[screen->mVertexData->GetPipelinePos()][sector_t::floor] = sector->GetPlaneTexZ(sector_t::floor);
UpdatePlaneVertices(renderstate, sector, sector_t::floor);
sector->vboheight[sector_t::floor] = sector->GetPlaneTexZ(sector_t::floor);
}
}
@ -472,13 +473,13 @@ static void CheckPlanes(FFlatVertexBuffer* fvb, sector_t* sector)
//
//==========================================================================
void CheckUpdate(FFlatVertexBuffer* fvb, sector_t* sector)
void CheckUpdate(FRenderState& renderstate, sector_t* sector)
{
CheckPlanes(fvb, sector);
CheckPlanes(renderstate, sector);
sector_t* hs = sector->GetHeightSec();
if (hs != NULL) CheckPlanes(fvb, hs);
if (hs != NULL) CheckPlanes(renderstate, hs);
for (unsigned i = 0; i < sector->e->XFloor.ffloors.Size(); i++)
CheckPlanes(fvb, sector->e->XFloor.ffloors[i]->model);
CheckPlanes(renderstate, sector->e->XFloor.ffloors[i]->model);
}
//==========================================================================
@ -487,11 +488,9 @@ void CheckUpdate(FFlatVertexBuffer* fvb, sector_t* sector)
//
//==========================================================================
void CreateVBO(FFlatVertexBuffer* fvb, TArray<sector_t>& sectors)
void CreateVBO(FRenderState& renderstate, TArray<sector_t>& sectors)
{
fvb->vbo_shadowdata.Clear();
CreateVertices(fvb, sectors);
fvb->mCurIndex = fvb->mIndex = fvb->vbo_shadowdata.Size();
fvb->Copy(0, fvb->mIndex);
fvb->mIndexBuffer->SetData(fvb->ibo_data.Size() * sizeof(uint32_t), &fvb->ibo_data[0], BufferUsageType::Static);
sector_vertices.Clear();
CreateVertices(renderstate, sectors);
renderstate.SetShadowData(sector_vertices, sector_indexes);
}

View file

@ -1,7 +1,9 @@
#pragma once
#include "tarray.h"
#include "r_defs.h"
struct vertex_t;
struct FFlatVertex;
struct FQualifiedVertex
{
@ -67,7 +69,9 @@ using VertexContainers = TArray<VertexContainer>;
VertexContainers BuildVertices(TArray<sector_t> &sectors);
class FFlatVertexBuffer;
void CheckUpdate(FFlatVertexBuffer* fvb, sector_t* sector);
void CreateVBO(FFlatVertexBuffer* fvb, TArray<sector_t>& sectors);
class FRenderState;
void CheckUpdate(FRenderState& renderstate, sector_t* sector);
void CreateVBO(FRenderState& renderstate, TArray<sector_t>& sectors);
extern TArray<FFlatVertex> sector_vertices;
extern TArray<uint32_t> sector_indexes;

View file

@ -664,7 +664,7 @@ void HWDrawInfo::DoSubsector(subsector_t * sub, FRenderState& state)
if (sector->validcount != validcount)
{
CheckUpdate(screen->mVertexData, sector);
CheckUpdate(state, sector);
}
// [RH] Add particles

View file

@ -266,8 +266,7 @@ sector_t * hw_FakeFlat(sector_t * sec, area_t in_area, bool back, sector_t *loca
dest->SetTexture(sector_t::floor, s->GetTexture(sector_t::floor), false);
dest->SetPlaneTexZQuick(sector_t::floor, s->GetPlaneTexZ(sector_t::floor));
dest->iboindex[sector_t::floor] = sec->iboindex[sector_t::vbo_fakefloor];
for (int n = 0; n < screen->mPipelineNbr; n++)
dest->vboheight[n][sector_t::floor] = s->vboheight[n][sector_t::floor];
dest->vboheight[sector_t::floor] = s->vboheight[sector_t::floor];
}
else if (s->MoreFlags & SECMF_FAKEFLOORONLY)
{
@ -293,8 +292,7 @@ sector_t * hw_FakeFlat(sector_t * sec, area_t in_area, bool back, sector_t *loca
dest->floorplane = s->floorplane;
dest->iboindex[sector_t::floor] = sec->iboindex[sector_t::vbo_fakefloor];
for (int n = 0; n < screen->mPipelineNbr; n++)
dest->vboheight[n][sector_t::floor] = s->vboheight[n][sector_t::floor];
dest->vboheight[sector_t::floor] = s->vboheight[sector_t::floor];
}
if (!(s->MoreFlags&SECMF_FAKEFLOORONLY))
@ -306,8 +304,7 @@ sector_t * hw_FakeFlat(sector_t * sec, area_t in_area, bool back, sector_t *loca
dest->SetTexture(sector_t::ceiling, s->GetTexture(sector_t::ceiling), false);
dest->SetPlaneTexZQuick(sector_t::ceiling, s->GetPlaneTexZ(sector_t::ceiling));
dest->iboindex[sector_t::ceiling] = sec->iboindex[sector_t::vbo_fakeceiling];
for (int n = 0; n < screen->mPipelineNbr; n++)
dest->vboheight[n][sector_t::ceiling] = s->vboheight[n][sector_t::ceiling];
dest->vboheight[sector_t::ceiling] = s->vboheight[sector_t::ceiling];
}
}
else
@ -315,8 +312,7 @@ sector_t * hw_FakeFlat(sector_t * sec, area_t in_area, bool back, sector_t *loca
dest->ceilingplane = s->ceilingplane;
dest->SetPlaneTexZQuick(sector_t::ceiling, s->GetPlaneTexZ(sector_t::ceiling));
dest->iboindex[sector_t::ceiling] = sec->iboindex[sector_t::vbo_fakeceiling];
for (int n = 0; n < screen->mPipelineNbr; n++)
dest->vboheight[n][sector_t::ceiling] = s->vboheight[n][sector_t::ceiling];
dest->vboheight[sector_t::ceiling] = s->vboheight[sector_t::ceiling];
}
}
@ -330,12 +326,10 @@ sector_t * hw_FakeFlat(sector_t * sec, area_t in_area, bool back, sector_t *loca
dest->ceilingplane.FlipVert();
dest->iboindex[sector_t::floor] = sec->iboindex[sector_t::floor];
for (int n = 0; n < screen->mPipelineNbr; n++)
dest->vboheight[n][sector_t::floor] = sec->vboheight[n][sector_t::floor];
dest->vboheight[sector_t::floor] = sec->vboheight[sector_t::floor];
dest->iboindex[sector_t::ceiling] = sec->iboindex[sector_t::vbo_fakefloor];
for (int n = 0; n < screen->mPipelineNbr; n++)
dest->vboheight[n][sector_t::ceiling] = s->vboheight[n][sector_t::floor];
dest->vboheight[sector_t::ceiling] = s->vboheight[sector_t::floor];
dest->ClearPortal(sector_t::ceiling);
@ -385,12 +379,10 @@ sector_t * hw_FakeFlat(sector_t * sec, area_t in_area, bool back, sector_t *loca
dest->floorplane.FlipVert();
dest->iboindex[sector_t::floor] = sec->iboindex[sector_t::vbo_fakeceiling];
for (int n = 0; n < screen->mPipelineNbr; n++)
dest->vboheight[n][sector_t::floor] = sec->vboheight[n][sector_t::ceiling];
dest->vboheight[sector_t::floor] = sec->vboheight[sector_t::ceiling];
dest->iboindex[sector_t::ceiling] = sec->iboindex[sector_t::ceiling];
for (int n = 0; n < screen->mPipelineNbr; n++)
dest->vboheight[n][sector_t::ceiling] = s->vboheight[n][sector_t::ceiling];
dest->vboheight[sector_t::ceiling] = s->vboheight[sector_t::ceiling];
dest->ClearPortal(sector_t::floor);

View file

@ -78,6 +78,7 @@ void HWMeshCache::Update(FRenderViewpoint& vp)
di->MeshBuilding = true;
MeshBuilder state;
state.SetShadowData(sector_vertices, sector_indexes);
// Add to the draw lists
@ -86,7 +87,7 @@ void HWMeshCache::Update(FRenderViewpoint& vp)
{
auto sector = &level->sectors[i];
CheckUpdate(screen->mVertexData, sector);
// CheckUpdate(state, sector);
std::unordered_set<FSection*> seenSections;
for (int i = 0, count = sector->subsectorcount; i < count; i++)
{