- implement VKBuffer::Resize

This commit is contained in:
Magnus Norddahl 2019-04-18 22:01:42 +02:00
parent e42d11cc34
commit faac0805f0
12 changed files with 49 additions and 18 deletions

View file

@ -955,7 +955,7 @@ void GLPPRenderState::Draw()
if (Uniforms.Data.Size() > 0) if (Uniforms.Data.Size() > 0)
{ {
if (!shader->Uniforms) if (!shader->Uniforms)
shader->Uniforms.reset(screen->CreateDataBuffer(POSTPROCESS_BINDINGPOINT, false)); shader->Uniforms.reset(screen->CreateDataBuffer(POSTPROCESS_BINDINGPOINT, false, false));
shader->Uniforms->SetData(Uniforms.Data.Size(), Uniforms.Data.Data()); shader->Uniforms->SetData(Uniforms.Data.Size(), Uniforms.Data.Data());
shader->Uniforms->BindBase(); shader->Uniforms->BindBase();
} }

View file

@ -339,7 +339,7 @@ IIndexBuffer *OpenGLFrameBuffer::CreateIndexBuffer()
return new GLIndexBuffer; return new GLIndexBuffer;
} }
IDataBuffer *OpenGLFrameBuffer::CreateDataBuffer(int bindingpoint, bool ssbo) IDataBuffer *OpenGLFrameBuffer::CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize)
{ {
return new GLDataBuffer(bindingpoint, ssbo); return new GLDataBuffer(bindingpoint, ssbo);
} }

View file

@ -39,7 +39,7 @@ public:
void BlurScene(float amount) override; void BlurScene(float amount) override;
IVertexBuffer *CreateVertexBuffer() override; IVertexBuffer *CreateVertexBuffer() override;
IIndexBuffer *CreateIndexBuffer() override; IIndexBuffer *CreateIndexBuffer() override;
IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo) override; IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) override;
// Retrieves a buffer containing image data for a screenshot. // Retrieves a buffer containing image data for a screenshot.
// Hint: Pitch can be negative for upside-down images, in which case buffer // Hint: Pitch can be negative for upside-down images, in which case buffer

View file

@ -38,7 +38,7 @@ GLViewpointBuffer::GLViewpointBuffer()
mBufferSize = INITIAL_BUFFER_SIZE; mBufferSize = INITIAL_BUFFER_SIZE;
mBlockAlign = ((sizeof(HWViewpointUniforms) / screen->uniformblockalignment) + 1) * screen->uniformblockalignment; mBlockAlign = ((sizeof(HWViewpointUniforms) / screen->uniformblockalignment) + 1) * screen->uniformblockalignment;
mByteSize = mBufferSize * mBlockAlign; mByteSize = mBufferSize * mBlockAlign;
mBuffer = screen->CreateDataBuffer(VIEWPOINT_BINDINGPOINT, false); mBuffer = screen->CreateDataBuffer(VIEWPOINT_BINDINGPOINT, false, true);
mBuffer->SetData(mByteSize, nullptr, false); mBuffer->SetData(mByteSize, nullptr, false);
Clear(); Clear();
mLastMappedIndex = UINT_MAX; mLastMappedIndex = UINT_MAX;

View file

@ -123,7 +123,7 @@ public:
void Init() void Init()
{ {
if (mBuffer == nullptr) if (mBuffer == nullptr)
mBuffer = screen->CreateDataBuffer(bindingpoint, false); mBuffer = screen->CreateDataBuffer(bindingpoint, false, false);
} }
void Set(bool bind = true) void Set(bool bind = true)

View file

@ -60,7 +60,7 @@ FLightBuffer::FLightBuffer()
mByteSize += screen->maxuniformblock; // to avoid mapping beyond the end of the buffer. mByteSize += screen->maxuniformblock; // to avoid mapping beyond the end of the buffer.
} }
mBuffer = screen->CreateDataBuffer(LIGHTBUF_BINDINGPOINT, mBufferType); mBuffer = screen->CreateDataBuffer(LIGHTBUF_BINDINGPOINT, mBufferType, false);
mBuffer->SetData(mByteSize, nullptr, false); mBuffer->SetData(mByteSize, nullptr, false);
Clear(); Clear();

View file

@ -189,7 +189,7 @@ void IShadowMap::UploadLights()
CollectLights(); CollectLights();
if (mLightList == nullptr) if (mLightList == nullptr)
mLightList = screen->CreateDataBuffer(LIGHTLIST_BINDINGPOINT, true); mLightList = screen->CreateDataBuffer(LIGHTLIST_BINDINGPOINT, true, false);
mLightList->SetData(sizeof(float) * mLights.Size(), &mLights[0]); mLightList->SetData(sizeof(float) * mLights.Size(), &mLights[0]);
} }
@ -200,11 +200,11 @@ void IShadowMap::UploadAABBTree()
if (!ValidateAABBTree(&level)) if (!ValidateAABBTree(&level))
{ {
if (!mNodesBuffer) if (!mNodesBuffer)
mNodesBuffer = screen->CreateDataBuffer(LIGHTNODES_BINDINGPOINT, true); mNodesBuffer = screen->CreateDataBuffer(LIGHTNODES_BINDINGPOINT, true, false);
mNodesBuffer->SetData(mAABBTree->NodesSize(), mAABBTree->Nodes()); mNodesBuffer->SetData(mAABBTree->NodesSize(), mAABBTree->Nodes());
if (!mLinesBuffer) if (!mLinesBuffer)
mLinesBuffer = screen->CreateDataBuffer(LIGHTLINES_BINDINGPOINT, true); mLinesBuffer = screen->CreateDataBuffer(LIGHTLINES_BINDINGPOINT, true, false);
mLinesBuffer->SetData(mAABBTree->LinesSize(), mAABBTree->Lines()); mLinesBuffer->SetData(mAABBTree->LinesSize(), mAABBTree->Lines());
} }
else if (mAABBTree->Update()) else if (mAABBTree->Update())

View file

@ -111,7 +111,30 @@ void VKBuffer::SetSubData(size_t offset, size_t size, const void *data)
void VKBuffer::Resize(size_t newsize) void VKBuffer::Resize(size_t newsize)
{ {
I_FatalError("VKBuffer::Resize not implemented\n"); auto fb = GetVulkanFrameBuffer();
// Grab old buffer
size_t oldsize = buffersize;
std::unique_ptr<VulkanBuffer> oldBuffer = std::move(mBuffer);
oldBuffer->Unmap();
map = nullptr;
// Create new buffer
BufferBuilder builder;
builder.setUsage(mBufferType, VMA_MEMORY_USAGE_CPU_TO_GPU, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT);
builder.setSize(newsize);
mBuffer = builder.create(fb->device);
buffersize = newsize;
// Transfer data from old to new
fb->GetTransferCommands()->copyBuffer(oldBuffer.get(), mBuffer.get(), 0, 0, oldsize);
fb->SubmitCommands(false);
// Fetch pointer to new buffer
map = mBuffer->Map(0, newsize);
// Old buffer may be part of the dynamic set
fb->GetRenderPassManager()->UpdateDynamicSet();
} }
void VKBuffer::Map() void VKBuffer::Map()

View file

@ -57,7 +57,14 @@ public:
class VKDataBuffer : public IDataBuffer, public VKBuffer class VKDataBuffer : public IDataBuffer, public VKBuffer
{ {
public: public:
VKDataBuffer(int bindingpoint, bool ssbo) : bindingpoint(bindingpoint) { mBufferType = ssbo ? VK_BUFFER_USAGE_STORAGE_BUFFER_BIT : VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; } VKDataBuffer(int bindingpoint, bool ssbo, bool needresize) : bindingpoint(bindingpoint)
{
mBufferType = ssbo ? VK_BUFFER_USAGE_STORAGE_BUFFER_BIT : VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
if (needresize)
{
mBufferType |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
}
}
void BindRange(size_t start, size_t length) override; void BindRange(size_t start, size_t length) override;
void BindBase() override; void BindBase() override;

View file

@ -138,8 +138,8 @@ void VulkanFrameBuffer::InitializeState()
CreateFanToTrisIndexBuffer(); CreateFanToTrisIndexBuffer();
// To do: move this to HW renderer interface maybe? // To do: move this to HW renderer interface maybe?
MatricesUBO = (VKDataBuffer*)CreateDataBuffer(-1, false); MatricesUBO = (VKDataBuffer*)CreateDataBuffer(-1, false, false);
StreamUBO = (VKDataBuffer*)CreateDataBuffer(-1, false); StreamUBO = (VKDataBuffer*)CreateDataBuffer(-1, false, false);
MatricesUBO->SetData(UniformBufferAlignedSize<::MatricesUBO>() * 50000, nullptr, false); MatricesUBO->SetData(UniformBufferAlignedSize<::MatricesUBO>() * 50000, nullptr, false);
StreamUBO->SetData(UniformBufferAlignedSize<::StreamUBO>() * 200, nullptr, false); StreamUBO->SetData(UniformBufferAlignedSize<::StreamUBO>() * 200, nullptr, false);
@ -590,9 +590,9 @@ IIndexBuffer *VulkanFrameBuffer::CreateIndexBuffer()
return new VKIndexBuffer(); return new VKIndexBuffer();
} }
IDataBuffer *VulkanFrameBuffer::CreateDataBuffer(int bindingpoint, bool ssbo) IDataBuffer *VulkanFrameBuffer::CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize)
{ {
auto buffer = new VKDataBuffer(bindingpoint, ssbo); auto buffer = new VKDataBuffer(bindingpoint, ssbo, needsresize);
auto fb = GetVulkanFrameBuffer(); auto fb = GetVulkanFrameBuffer();
switch (bindingpoint) switch (bindingpoint)

View file

@ -86,7 +86,7 @@ public:
FModelRenderer *CreateModelRenderer(int mli) override; FModelRenderer *CreateModelRenderer(int mli) override;
IVertexBuffer *CreateVertexBuffer() override; IVertexBuffer *CreateVertexBuffer() override;
IIndexBuffer *CreateIndexBuffer() override; IIndexBuffer *CreateIndexBuffer() override;
IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo) override; IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) override;
FTexture *WipeStartScreen() override; FTexture *WipeStartScreen() override;
FTexture *WipeEndScreen() override; FTexture *WipeEndScreen() override;
@ -97,13 +97,14 @@ public:
void Draw2D() override; void Draw2D() override;
void SubmitCommands(bool finish);
private: private:
sector_t *RenderViewpoint(FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); sector_t *RenderViewpoint(FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen);
void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV);
void DrawScene(HWDrawInfo *di, int drawmode); void DrawScene(HWDrawInfo *di, int drawmode);
void PrintStartupLog(); void PrintStartupLog();
void CreateFanToTrisIndexBuffer(); void CreateFanToTrisIndexBuffer();
void SubmitCommands(bool finish);
void CopyScreenToBuffer(int w, int h, void *data); void CopyScreenToBuffer(int w, int h, void *data);
void UpdateShadowMap(); void UpdateShadowMap();
void DeleteFrameObjects(); void DeleteFrameObjects();

View file

@ -448,7 +448,7 @@ public:
// Interface to hardware rendering resources // Interface to hardware rendering resources
virtual IVertexBuffer *CreateVertexBuffer() { return nullptr; } virtual IVertexBuffer *CreateVertexBuffer() { return nullptr; }
virtual IIndexBuffer *CreateIndexBuffer() { return nullptr; } virtual IIndexBuffer *CreateIndexBuffer() { return nullptr; }
virtual IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo) { return nullptr; } virtual IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) { return nullptr; }
bool BuffersArePersistent() { return !!(hwcaps & RFL_BUFFER_STORAGE); } bool BuffersArePersistent() { return !!(hwcaps & RFL_BUFFER_STORAGE); }
// Begin/End 2D drawing operations. // Begin/End 2D drawing operations.