mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-04-23 08:09:40 +00:00
Added pipeline to FFlatVertexBuffer
This commit is contained in:
parent
99ab1e3317
commit
9405a08d0b
14 changed files with 135 additions and 35 deletions
|
@ -63,6 +63,7 @@ PROC zd_wglGetProcAddress(LPCSTR name);
|
|||
|
||||
EXTERN_CVAR(Int, vid_adapter)
|
||||
EXTERN_CVAR(Bool, vid_hdr)
|
||||
EXTERN_CVAR(Int, gl_pipeline_depth);
|
||||
|
||||
CUSTOM_CVAR(Bool, gl_debug, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
|
||||
{
|
||||
|
@ -106,6 +107,8 @@ DFrameBuffer *Win32GLVideo::CreateFrameBuffer()
|
|||
SystemGLFrameBuffer *fb;
|
||||
|
||||
fb = new OpenGLRenderer::OpenGLFrameBuffer(m_hMonitor, vid_fullscreen);
|
||||
|
||||
fb->mPipelineNbr = gl_pipeline_depth;
|
||||
return fb;
|
||||
}
|
||||
|
||||
|
|
|
@ -170,6 +170,29 @@ void GLBuffer::Resize(size_t newsize)
|
|||
}
|
||||
}
|
||||
|
||||
void GLBuffer::GPUDropSync()
|
||||
{
|
||||
if (mGLSync != NULL)
|
||||
{
|
||||
glDeleteSync(mGLSync);
|
||||
}
|
||||
|
||||
mGLSync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
}
|
||||
|
||||
void GLBuffer::GPUWaitSync()
|
||||
{
|
||||
GLenum status = glClientWaitSync(mGLSync, GL_SYNC_FLUSH_COMMANDS_BIT, 1000 * 1000 * 50); // Wait for a max of 50ms...
|
||||
|
||||
if (status != GL_ALREADY_SIGNALED && status != GL_CONDITION_SATISFIED)
|
||||
{
|
||||
//Printf("Error on glClientWaitSync: %d\n", status);
|
||||
}
|
||||
|
||||
glDeleteSync(mGLSync);
|
||||
|
||||
mGLSync = NULL;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
|
|
|
@ -19,6 +19,7 @@ protected:
|
|||
int mAllocationSize = 0;
|
||||
bool mPersistent = false;
|
||||
bool nomap = true;
|
||||
GLsync mGLSync = 0;
|
||||
|
||||
GLBuffer(int usetype);
|
||||
~GLBuffer();
|
||||
|
@ -29,6 +30,9 @@ protected:
|
|||
void Resize(size_t newsize) override;
|
||||
void *Lock(unsigned int size) override;
|
||||
void Unlock() override;
|
||||
|
||||
void GPUDropSync();
|
||||
void GPUWaitSync();
|
||||
public:
|
||||
void Bind();
|
||||
};
|
||||
|
|
|
@ -164,7 +164,7 @@ void OpenGLFrameBuffer::InitializeState()
|
|||
|
||||
SetViewportRects(nullptr);
|
||||
|
||||
mVertexData = new FFlatVertexBuffer(GetWidth(), GetHeight());
|
||||
mVertexData = new FFlatVertexBuffer(GetWidth(), GetHeight(), screen->mPipelineNbr);
|
||||
mSkyData = new FSkyVertexBuffer;
|
||||
mViewpoints = new HWViewpointBuffer;
|
||||
mLights = new FLightBuffer();
|
||||
|
@ -256,10 +256,15 @@ void OpenGLFrameBuffer::Swap()
|
|||
bool swapbefore = gl_finishbeforeswap && camtexcount == 0;
|
||||
Finish.Reset();
|
||||
Finish.Clock();
|
||||
if (swapbefore) glFinish();
|
||||
//if (swapbefore) glFinish();
|
||||
screen->mVertexData->DropSync();
|
||||
|
||||
FPSLimit();
|
||||
SwapBuffers();
|
||||
if (!swapbefore) glFinish();
|
||||
|
||||
screen->mVertexData->WaitSync();
|
||||
|
||||
//if (!swapbefore) glFinish();
|
||||
Finish.Unclock();
|
||||
camtexcount = 0;
|
||||
FHardwareTexture::UnbindAll();
|
||||
|
|
|
@ -58,6 +58,8 @@ public:
|
|||
virtual void Unmap() {}
|
||||
void *Memory() { return map; }
|
||||
size_t Size() { return buffersize; }
|
||||
virtual void GPUDropSync() {}
|
||||
virtual void GPUWaitSync() {}
|
||||
};
|
||||
|
||||
class IVertexBuffer : virtual public IBuffer
|
||||
|
|
|
@ -45,7 +45,8 @@
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
FFlatVertexBuffer::FFlatVertexBuffer(int width, int height)
|
||||
FFlatVertexBuffer::FFlatVertexBuffer(int width, int height, int pipelineNbr):
|
||||
mPipelineNbr(pipelineNbr)
|
||||
{
|
||||
vbo_shadowdata.Resize(NUM_RESERVED);
|
||||
|
||||
|
@ -78,17 +79,25 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height)
|
|||
vbo_shadowdata[18].Set(32767.0f, -32767.0f, 32767.0f, 0, 0);
|
||||
vbo_shadowdata[19].Set(32767.0f, -32767.0f, -32767.0f, 0, 0);
|
||||
|
||||
mVertexBuffer = screen->CreateVertexBuffer();
|
||||
mIndexBuffer = screen->CreateIndexBuffer();
|
||||
|
||||
unsigned int bytesize = BUFFER_SIZE * sizeof(FFlatVertex);
|
||||
mVertexBuffer->SetData(bytesize, nullptr, false);
|
||||
|
||||
static const FVertexBufferAttribute format[] = {
|
||||
{ 0, VATTR_VERTEX, VFmt_Float3, (int)myoffsetof(FFlatVertex, x) },
|
||||
{ 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(FFlatVertex, u) }
|
||||
};
|
||||
mVertexBuffer->SetFormat(1, 2, sizeof(FFlatVertex), format);
|
||||
for (int n = 0; n < mPipelineNbr; n++)
|
||||
{
|
||||
mVertexBufferPipeline[n] = screen->CreateVertexBuffer();
|
||||
|
||||
unsigned int bytesize = BUFFER_SIZE * sizeof(FFlatVertex);
|
||||
mVertexBufferPipeline[n]->SetData(bytesize, nullptr, false);
|
||||
|
||||
static const FVertexBufferAttribute format[] = {
|
||||
{ 0, VATTR_VERTEX, VFmt_Float3, (int)myoffsetof(FFlatVertex, x) },
|
||||
{ 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(FFlatVertex, u) }
|
||||
};
|
||||
|
||||
mVertexBufferPipeline[n]->SetFormat(1, 2, sizeof(FFlatVertex), format);
|
||||
}
|
||||
|
||||
mVertexBuffer = mVertexBufferPipeline[mPipelinePos];
|
||||
|
||||
mIndex = mCurIndex = NUM_RESERVED;
|
||||
mNumReserved = NUM_RESERVED;
|
||||
|
@ -103,8 +112,12 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height)
|
|||
|
||||
FFlatVertexBuffer::~FFlatVertexBuffer()
|
||||
{
|
||||
for (int n = 0; n < mPipelineNbr; n++)
|
||||
{
|
||||
delete mVertexBufferPipeline[n];
|
||||
}
|
||||
|
||||
delete mIndexBuffer;
|
||||
delete mVertexBuffer;
|
||||
mIndexBuffer = nullptr;
|
||||
mVertexBuffer = nullptr;
|
||||
}
|
||||
|
@ -151,8 +164,16 @@ std::pair<FFlatVertex *, unsigned int> FFlatVertexBuffer::AllocVertices(unsigned
|
|||
|
||||
void FFlatVertexBuffer::Copy(int start, int count)
|
||||
{
|
||||
Map();
|
||||
memcpy(GetBuffer(start), &vbo_shadowdata[0], count * sizeof(FFlatVertex));
|
||||
Unmap();
|
||||
IVertexBuffer* old = mVertexBuffer;
|
||||
|
||||
for (int n = 0; n < mPipelineNbr; n++)
|
||||
{
|
||||
mVertexBuffer = mVertexBufferPipeline[n];
|
||||
Map();
|
||||
memcpy(GetBuffer(start), &vbo_shadowdata[0], count * sizeof(FFlatVertex));
|
||||
Unmap();
|
||||
}
|
||||
|
||||
mVertexBuffer = old;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#ifndef _HW__VERTEXBUFFER_H
|
||||
#define _HW__VERTEXBUFFER_H
|
||||
|
||||
#include "doomdef.h"
|
||||
#include "tarray.h"
|
||||
#include "hwrenderer/data/buffers.h"
|
||||
#include <atomic>
|
||||
|
@ -46,9 +47,15 @@ public:
|
|||
TArray<FFlatVertex> vbo_shadowdata;
|
||||
TArray<uint32_t> ibo_data;
|
||||
|
||||
IVertexBuffer *mVertexBuffer;
|
||||
int mPipelineNbr;
|
||||
int mPipelinePos = 0;
|
||||
|
||||
IVertexBuffer* mVertexBuffer;
|
||||
IVertexBuffer *mVertexBufferPipeline[MAX_PIPELINE_BUFFERS];
|
||||
IIndexBuffer *mIndexBuffer;
|
||||
|
||||
|
||||
|
||||
unsigned int mIndex;
|
||||
std::atomic<unsigned int> mCurIndex;
|
||||
unsigned int mNumReserved;
|
||||
|
@ -69,7 +76,7 @@ public:
|
|||
NUM_RESERVED = 20
|
||||
};
|
||||
|
||||
FFlatVertexBuffer(int width, int height);
|
||||
FFlatVertexBuffer(int width, int height, int pipelineNbr = 1);
|
||||
~FFlatVertexBuffer();
|
||||
|
||||
void OutputResized(int width, int height);
|
||||
|
@ -96,6 +103,11 @@ public:
|
|||
void Reset()
|
||||
{
|
||||
mCurIndex = mIndex;
|
||||
|
||||
mPipelinePos++;
|
||||
mPipelinePos %= mPipelineNbr;
|
||||
|
||||
mVertexBuffer = mVertexBufferPipeline[mPipelinePos];
|
||||
}
|
||||
|
||||
void Map()
|
||||
|
@ -108,6 +120,20 @@ public:
|
|||
mVertexBuffer->Unmap();
|
||||
}
|
||||
|
||||
void DropSync()
|
||||
{
|
||||
mVertexBuffer->GPUDropSync();
|
||||
}
|
||||
|
||||
void WaitSync()
|
||||
{
|
||||
mVertexBuffer->GPUWaitSync();
|
||||
}
|
||||
|
||||
int GetPipelinePos()
|
||||
{
|
||||
return mPipelinePos;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -72,6 +72,8 @@ CVAR(Int, win_w, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
|||
CVAR(Int, win_h, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
CVAR(Bool, win_maximized, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
|
||||
|
||||
CVAR(Int, gl_pipeline_depth, 4, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
|
||||
|
||||
CUSTOM_CVAR(Int, vid_maxfps, 200, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
if (self < GameTicRate && self != 0)
|
||||
|
|
|
@ -149,6 +149,7 @@ public:
|
|||
IntRect mOutputLetterbox;
|
||||
float mSceneClearColor[4];
|
||||
|
||||
int mPipelineNbr = 1; // Number of HW buffers to pipeline
|
||||
public:
|
||||
DFrameBuffer (int width=1, int height=1);
|
||||
virtual ~DFrameBuffer();
|
||||
|
|
|
@ -255,4 +255,6 @@ enum
|
|||
|
||||
#define BLINKTHRESHOLD (4*32)
|
||||
|
||||
#define MAX_PIPELINE_BUFFERS 8
|
||||
|
||||
#endif // __DOOMDEF_H__
|
||||
|
|
|
@ -698,7 +698,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[2]; // Last calculated height for the 2 planes of this actual sector
|
||||
double vboheight[MAX_PIPELINE_BUFFERS][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.
|
||||
|
||||
|
|
|
@ -256,8 +256,8 @@ void WriteSavePic(player_t* player, FileWriter* file, int width, int height)
|
|||
screen->ImageTransitionScene(true);
|
||||
|
||||
hw_ClearFakeFlat();
|
||||
RenderState.SetVertexBuffer(screen->mVertexData);
|
||||
screen->mVertexData->Reset();
|
||||
RenderState.SetVertexBuffer(screen->mVertexData);
|
||||
screen->mLights->Clear();
|
||||
screen->mViewpoints->Clear();
|
||||
|
||||
|
@ -298,8 +298,10 @@ static void CheckTimer(FRenderState &state, uint64_t ShaderStartTime)
|
|||
sector_t* RenderView(player_t* player)
|
||||
{
|
||||
auto RenderState = screen->RenderState();
|
||||
RenderState->SetVertexBuffer(screen->mVertexData);
|
||||
|
||||
// Reset BEFORE SetVertexBuffer so it sets the correct buffer
|
||||
screen->mVertexData->Reset();
|
||||
RenderState->SetVertexBuffer(screen->mVertexData);
|
||||
|
||||
sector_t* retsec;
|
||||
if (!V_IsHardwareRenderer())
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "hw_vertexbuilder.h"
|
||||
#include "flatvertices.h"
|
||||
#include "earcut.hpp"
|
||||
|
||||
#include "v_video.h"
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
|
@ -222,7 +222,8 @@ static int CreateIndexedVertices(FFlatVertexBuffer* fvb, int h, sector_t* sec, c
|
|||
auto& vbo_shadowdata = fvb->vbo_shadowdata;
|
||||
sec->vboindex[h] = vbo_shadowdata.Size();
|
||||
// First calculate the vertices for the sector itself
|
||||
sec->vboheight[h] = sec->GetPlaneTexZ(h);
|
||||
for (int n = 0; n < screen->mPipelineNbr; n++)
|
||||
sec->vboheight[n][h] = sec->GetPlaneTexZ(h);
|
||||
sec->ibocount = verts[sec->Index()].indices.Size();
|
||||
sec->iboindex[h] = CreateIndexedSectorVertices(fvb, sec, plane, floor, verts[sec->Index()]);
|
||||
|
||||
|
@ -357,15 +358,15 @@ static void CreateVertices(FFlatVertexBuffer* fvb, TArray<sector_t>& sectors)
|
|||
|
||||
static void CheckPlanes(FFlatVertexBuffer* fvb, sector_t* sector)
|
||||
{
|
||||
if (sector->GetPlaneTexZ(sector_t::ceiling) != sector->vboheight[sector_t::ceiling])
|
||||
if (sector->GetPlaneTexZ(sector_t::ceiling) != sector->vboheight[screen->mVertexData->GetPipelinePos()][sector_t::ceiling])
|
||||
{
|
||||
UpdatePlaneVertices(fvb, sector, sector_t::ceiling);
|
||||
sector->vboheight[sector_t::ceiling] = sector->GetPlaneTexZ(sector_t::ceiling);
|
||||
sector->vboheight[screen->mVertexData->GetPipelinePos()][sector_t::ceiling] = sector->GetPlaneTexZ(sector_t::ceiling);
|
||||
}
|
||||
if (sector->GetPlaneTexZ(sector_t::floor) != sector->vboheight[sector_t::floor])
|
||||
if (sector->GetPlaneTexZ(sector_t::floor) != sector->vboheight[screen->mVertexData->GetPipelinePos()][sector_t::floor])
|
||||
{
|
||||
UpdatePlaneVertices(fvb, sector, sector_t::floor);
|
||||
sector->vboheight[sector_t::floor] = sector->GetPlaneTexZ(sector_t::floor);
|
||||
sector->vboheight[screen->mVertexData->GetPipelinePos()][sector_t::floor] = sector->GetPlaneTexZ(sector_t::floor);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -266,7 +266,8 @@ 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];
|
||||
dest->vboheight[sector_t::floor] = s->vboheight[sector_t::floor];
|
||||
for (int n = 0; n < screen->mPipelineNbr; n++)
|
||||
dest->vboheight[n][sector_t::floor] = s->vboheight[n][sector_t::floor];
|
||||
}
|
||||
else if (s->MoreFlags & SECMF_FAKEFLOORONLY)
|
||||
{
|
||||
|
@ -292,7 +293,8 @@ 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];
|
||||
dest->vboheight[sector_t::floor] = s->vboheight[sector_t::floor];
|
||||
for (int n = 0; n < screen->mPipelineNbr; n++)
|
||||
dest->vboheight[n][sector_t::floor] = s->vboheight[n][sector_t::floor];
|
||||
}
|
||||
|
||||
if (!(s->MoreFlags&SECMF_FAKEFLOORONLY))
|
||||
|
@ -304,7 +306,8 @@ 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];
|
||||
dest->vboheight[sector_t::ceiling] = s->vboheight[sector_t::ceiling];
|
||||
for (int n = 0; n < screen->mPipelineNbr; n++)
|
||||
dest->vboheight[n][sector_t::ceiling] = s->vboheight[n][sector_t::ceiling];
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -312,7 +315,8 @@ 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];
|
||||
dest->vboheight[sector_t::ceiling] = s->vboheight[sector_t::ceiling];
|
||||
for (int n = 0; n < screen->mPipelineNbr; n++)
|
||||
dest->vboheight[n][sector_t::ceiling] = s->vboheight[n][sector_t::ceiling];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -326,10 +330,12 @@ 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];
|
||||
dest->vboheight[sector_t::floor] = sec->vboheight[sector_t::floor];
|
||||
for (int n = 0; n < screen->mPipelineNbr; n++)
|
||||
dest->vboheight[n][sector_t::floor] = sec->vboheight[n][sector_t::floor];
|
||||
|
||||
dest->iboindex[sector_t::ceiling] = sec->iboindex[sector_t::vbo_fakefloor];
|
||||
dest->vboheight[sector_t::ceiling] = s->vboheight[sector_t::floor];
|
||||
for (int n = 0; n < screen->mPipelineNbr; n++)
|
||||
dest->vboheight[n][sector_t::ceiling] = s->vboheight[n][sector_t::floor];
|
||||
|
||||
dest->ClearPortal(sector_t::ceiling);
|
||||
|
||||
|
@ -379,10 +385,12 @@ 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];
|
||||
dest->vboheight[sector_t::floor] = s->vboheight[sector_t::ceiling];
|
||||
for (int n = 0; n < screen->mPipelineNbr; n++)
|
||||
dest->vboheight[n][sector_t::floor] = sec->vboheight[n][sector_t::floor];
|
||||
|
||||
dest->iboindex[sector_t::ceiling] = sec->iboindex[sector_t::ceiling];
|
||||
dest->vboheight[sector_t::ceiling] = sec->vboheight[sector_t::ceiling];
|
||||
for (int n = 0; n < screen->mPipelineNbr; n++)
|
||||
dest->vboheight[n][sector_t::ceiling] = s->vboheight[n][sector_t::floor];
|
||||
|
||||
dest->ClearPortal(sector_t::floor);
|
||||
|
||||
|
|
Loading…
Reference in a new issue