Move VkRSBuffers to new file

This commit is contained in:
Magnus Norddahl 2023-05-16 23:51:00 +02:00 committed by Christoph Oelckers
parent 0bb6b2c298
commit 9f62679684
10 changed files with 311 additions and 314 deletions

View file

@ -744,7 +744,7 @@ set (VULKAN_SOURCES
common/rendering/vulkan/vk_postprocess.cpp
common/rendering/vulkan/vk_pprenderstate.cpp
common/rendering/vulkan/commands/vk_commandbuffer.cpp
common/rendering/vulkan/buffers/vk_streambuffer.cpp
common/rendering/vulkan/buffers/vk_rsbuffers.cpp
common/rendering/vulkan/buffers/vk_hwbuffer.cpp
common/rendering/vulkan/buffers/vk_buffer.cpp
common/rendering/vulkan/samplers/vk_samplers.cpp

View file

@ -22,12 +22,11 @@
#include "vk_buffer.h"
#include "vk_hwbuffer.h"
#include "vk_streambuffer.h"
#include "vk_rsbuffers.h"
#include "vulkan/vk_renderdevice.h"
#include "vulkan/pipelines/vk_renderpass.h"
#include "vulkan/commands/vk_commandbuffer.h"
#include <zvulkan/vulkanbuilders.h>
#include "flatvertices.h"
#include "cmdlib.h"
VkBufferManager::VkBufferManager(VulkanRenderDevice* fb) : fb(fb)
@ -99,126 +98,3 @@ void VkBufferManager::CreateFanToTrisIndexBuffer()
FanToTrisIndexBuffer.reset(CreateIndexBuffer());
FanToTrisIndexBuffer->SetData(sizeof(uint32_t) * data.Size(), data.Data(), BufferUsageType::Static);
}
/////////////////////////////////////////////////////////////////////////////
VkRSBuffers::VkRSBuffers(VulkanRenderDevice* fb)
{
static const FVertexBufferAttribute format[] =
{
{ 0, VATTR_VERTEX, VFmt_Float3, (int)myoffsetof(FFlatVertex, x) },
{ 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(FFlatVertex, u) },
{ 0, VATTR_LIGHTMAP, VFmt_Float3, (int)myoffsetof(FFlatVertex, lu) },
};
Flatbuffer.VertexFormat = fb->GetRenderPassManager()->GetVertexFormat(1, 3, sizeof(FFlatVertex), format);
Flatbuffer.VertexBuffer = BufferBuilder()
.Usage(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT)
.MemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
.Size(Flatbuffer.BUFFER_SIZE * sizeof(FFlatVertex))
.DebugName("Flatbuffer.VertexBuffer")
.Create(fb->GetDevice());
Flatbuffer.Vertices = (FFlatVertex*)Flatbuffer.VertexBuffer->Map(0, Flatbuffer.VertexBuffer->size);
Flatbuffer.IndexBuffer = BufferBuilder()
.Usage(VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VMA_MEMORY_USAGE_GPU_ONLY)
.Size(16)
.DebugName("Flatbuffer.IndexBuffer")
.Create(fb->GetDevice());
MatrixBuffer = std::make_unique<VkStreamBuffer>(fb, sizeof(MatricesUBO), 50000);
StreamBuffer = std::make_unique<VkStreamBuffer>(fb, sizeof(StreamUBO), 300);
Viewpoint.BlockAlign = (sizeof(HWViewpointUniforms) + fb->uniformblockalignment - 1) / fb->uniformblockalignment * fb->uniformblockalignment;
Viewpoint.UBO = BufferBuilder()
.Usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT)
.MemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
.Size(Viewpoint.Count * Viewpoint.BlockAlign)
.DebugName("Viewpoint.UBO")
.Create(fb->GetDevice());
Viewpoint.Data = Viewpoint.UBO->Map(0, Viewpoint.UBO->size);
Lightbuffer.UBO = BufferBuilder()
.Usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT)
.MemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
.Size(Lightbuffer.Count * 4 * sizeof(FVector4))
.DebugName("Lightbuffer.UBO")
.Create(fb->GetDevice());
Lightbuffer.Data = Lightbuffer.UBO->Map(0, Lightbuffer.UBO->size);
Bonebuffer.SSO = BufferBuilder()
.Usage(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT)
.MemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
.Size(Bonebuffer.Count * sizeof(VSMatrix))
.DebugName("Bonebuffer.SSO")
.Create(fb->GetDevice());
Bonebuffer.Data = Bonebuffer.SSO->Map(0, Bonebuffer.SSO->size);
}
VkRSBuffers::~VkRSBuffers()
{
if (Flatbuffer.VertexBuffer)
Flatbuffer.VertexBuffer->Unmap();
Flatbuffer.VertexBuffer.reset();
Flatbuffer.IndexBuffer.reset();
if (Viewpoint.UBO)
Viewpoint.UBO->Unmap();
Viewpoint.UBO.reset();
if (Lightbuffer.UBO)
Lightbuffer.UBO->Unmap();
Lightbuffer.UBO.reset();
if (Bonebuffer.SSO)
Bonebuffer.SSO->Unmap();
Bonebuffer.SSO.reset();
}
/////////////////////////////////////////////////////////////////////////////
VkStreamBuffer::VkStreamBuffer(VulkanRenderDevice* fb, size_t structSize, size_t count)
{
mBlockSize = static_cast<uint32_t>((structSize + fb->uniformblockalignment - 1) / fb->uniformblockalignment * fb->uniformblockalignment);
UBO = BufferBuilder()
.Usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT)
.MemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
.Size(mBlockSize * count)
.DebugName("VkStreamBuffer")
.Create(fb->GetDevice());
Data = UBO->Map(0, UBO->size);
}
VkStreamBuffer::~VkStreamBuffer()
{
UBO->Unmap();
}
uint32_t VkStreamBuffer::NextStreamDataBlock()
{
mStreamDataOffset += mBlockSize;
if (mStreamDataOffset + (size_t)mBlockSize >= UBO->size)
{
mStreamDataOffset = 0;
return 0xffffffff;
}
return mStreamDataOffset;
}

View file

@ -7,58 +7,9 @@
class VulkanRenderDevice;
class VkHardwareBuffer;
class VkHardwareDataBuffer;
class VkStreamBuffer;
class IBuffer;
class VkRSBuffers;
struct FVertexBufferAttribute;
struct HWViewpointUniforms;
struct FFlatVertex;
class VkRSBuffers
{
public:
VkRSBuffers(VulkanRenderDevice* fb);
~VkRSBuffers();
struct
{
std::unique_ptr<VulkanBuffer> VertexBuffer;
int VertexFormat = 0;
FFlatVertex* Vertices = nullptr;
unsigned int ShadowDataSize = 0;
unsigned int CurIndex = 0;
static const unsigned int BUFFER_SIZE = 2000000;
static const unsigned int BUFFER_SIZE_TO_USE = BUFFER_SIZE - 500;
std::unique_ptr<VulkanBuffer> IndexBuffer;
} Flatbuffer;
struct
{
int UploadIndex = 0;
int BlockAlign = 0;
int Count = 1000;
std::unique_ptr<VulkanBuffer> UBO;
void* Data = nullptr;
} Viewpoint;
struct
{
int UploadIndex = 0;
int Count = 80000;
std::unique_ptr<VulkanBuffer> UBO;
void* Data = nullptr;
} Lightbuffer;
struct
{
int UploadIndex = 0;
int Count = 80000;
std::unique_ptr<VulkanBuffer> SSO;
void* Data = nullptr;
} Bonebuffer;
std::unique_ptr<VkStreamBuffer> MatrixBuffer;
std::unique_ptr<VkStreamBuffer> StreamBuffer;
};
class VkBufferManager
{
@ -94,20 +45,3 @@ private:
std::list<VkHardwareBuffer*> Buffers;
std::vector<std::unique_ptr<VkRSBuffers>> RSBuffers;
};
class VkStreamBuffer
{
public:
VkStreamBuffer(VulkanRenderDevice* fb, size_t structSize, size_t count);
~VkStreamBuffer();
uint32_t NextStreamDataBlock();
void Reset() { mStreamDataOffset = 0; }
std::unique_ptr<VulkanBuffer> UBO;
void* Data = nullptr;
private:
uint32_t mBlockSize = 0;
uint32_t mStreamDataOffset = 0;
};

View file

@ -0,0 +1,201 @@
/*
** Vulkan backend
** Copyright (c) 2016-2020 Magnus Norddahl
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any damages
** arising from the use of this software.
**
** Permission is granted to anyone to use this software for any purpose,
** including commercial applications, and to alter it and redistribute it
** freely, subject to the following restrictions:
**
** 1. The origin of this software must not be misrepresented; you must not
** claim that you wrote the original software. If you use this software
** in a product, an acknowledgment in the product documentation would be
** appreciated but is not required.
** 2. Altered source versions must be plainly marked as such, and must not be
** misrepresented as being the original software.
** 3. This notice may not be removed or altered from any source distribution.
**
*/
#include "vk_rsbuffers.h"
#include "vulkan/vk_renderstate.h"
#include "vulkan/vk_renderdevice.h"
#include "vulkan/buffers/vk_buffer.h"
#include <zvulkan/vulkanbuilders.h>
#include "flatvertices.h"
#include "cmdlib.h"
VkRSBuffers::VkRSBuffers(VulkanRenderDevice* fb)
{
static const FVertexBufferAttribute format[] =
{
{ 0, VATTR_VERTEX, VFmt_Float3, (int)myoffsetof(FFlatVertex, x) },
{ 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(FFlatVertex, u) },
{ 0, VATTR_LIGHTMAP, VFmt_Float3, (int)myoffsetof(FFlatVertex, lu) },
};
Flatbuffer.VertexFormat = fb->GetRenderPassManager()->GetVertexFormat(1, 3, sizeof(FFlatVertex), format);
Flatbuffer.VertexBuffer = BufferBuilder()
.Usage(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT)
.MemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
.Size(Flatbuffer.BUFFER_SIZE * sizeof(FFlatVertex))
.DebugName("Flatbuffer.VertexBuffer")
.Create(fb->GetDevice());
Flatbuffer.Vertices = (FFlatVertex*)Flatbuffer.VertexBuffer->Map(0, Flatbuffer.VertexBuffer->size);
Flatbuffer.IndexBuffer = BufferBuilder()
.Usage(VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VMA_MEMORY_USAGE_GPU_ONLY)
.Size(16)
.DebugName("Flatbuffer.IndexBuffer")
.Create(fb->GetDevice());
MatrixBuffer = std::make_unique<VkStreamBuffer>(fb, sizeof(MatricesUBO), 50000);
StreamBuffer = std::make_unique<VkStreamBuffer>(fb, sizeof(StreamUBO), 300);
Viewpoint.BlockAlign = (sizeof(HWViewpointUniforms) + fb->uniformblockalignment - 1) / fb->uniformblockalignment * fb->uniformblockalignment;
Viewpoint.UBO = BufferBuilder()
.Usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT)
.MemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
.Size(Viewpoint.Count * Viewpoint.BlockAlign)
.DebugName("Viewpoint.UBO")
.Create(fb->GetDevice());
Viewpoint.Data = Viewpoint.UBO->Map(0, Viewpoint.UBO->size);
Lightbuffer.UBO = BufferBuilder()
.Usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT)
.MemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
.Size(Lightbuffer.Count * 4 * sizeof(FVector4))
.DebugName("Lightbuffer.UBO")
.Create(fb->GetDevice());
Lightbuffer.Data = Lightbuffer.UBO->Map(0, Lightbuffer.UBO->size);
Bonebuffer.SSO = BufferBuilder()
.Usage(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT)
.MemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
.Size(Bonebuffer.Count * sizeof(VSMatrix))
.DebugName("Bonebuffer.SSO")
.Create(fb->GetDevice());
Bonebuffer.Data = Bonebuffer.SSO->Map(0, Bonebuffer.SSO->size);
}
VkRSBuffers::~VkRSBuffers()
{
if (Flatbuffer.VertexBuffer)
Flatbuffer.VertexBuffer->Unmap();
Flatbuffer.VertexBuffer.reset();
Flatbuffer.IndexBuffer.reset();
if (Viewpoint.UBO)
Viewpoint.UBO->Unmap();
Viewpoint.UBO.reset();
if (Lightbuffer.UBO)
Lightbuffer.UBO->Unmap();
Lightbuffer.UBO.reset();
if (Bonebuffer.SSO)
Bonebuffer.SSO->Unmap();
Bonebuffer.SSO.reset();
}
/////////////////////////////////////////////////////////////////////////////
VkStreamBuffer::VkStreamBuffer(VulkanRenderDevice* fb, size_t structSize, size_t count)
{
mBlockSize = static_cast<uint32_t>((structSize + fb->uniformblockalignment - 1) / fb->uniformblockalignment * fb->uniformblockalignment);
UBO = BufferBuilder()
.Usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT)
.MemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
.Size(mBlockSize * count)
.DebugName("VkStreamBuffer")
.Create(fb->GetDevice());
Data = UBO->Map(0, UBO->size);
}
VkStreamBuffer::~VkStreamBuffer()
{
UBO->Unmap();
}
uint32_t VkStreamBuffer::NextStreamDataBlock()
{
mStreamDataOffset += mBlockSize;
if (mStreamDataOffset + (size_t)mBlockSize >= UBO->size)
{
mStreamDataOffset = 0;
return 0xffffffff;
}
return mStreamDataOffset;
}
VkStreamBufferWriter::VkStreamBufferWriter(VkRSBuffers* rsbuffers)
{
mBuffer = rsbuffers->StreamBuffer.get();
}
bool VkStreamBufferWriter::Write(const StreamData& data)
{
mDataIndex++;
if (mDataIndex == MAX_STREAM_DATA)
{
mDataIndex = 0;
mStreamDataOffset = mBuffer->NextStreamDataBlock();
if (mStreamDataOffset == 0xffffffff)
return false;
}
uint8_t* ptr = (uint8_t*)mBuffer->Data;
memcpy(ptr + mStreamDataOffset + sizeof(StreamData) * mDataIndex, &data, sizeof(StreamData));
return true;
}
void VkStreamBufferWriter::Reset()
{
mDataIndex = MAX_STREAM_DATA - 1;
mStreamDataOffset = 0;
mBuffer->Reset();
}
/////////////////////////////////////////////////////////////////////////////
VkMatrixBufferWriter::VkMatrixBufferWriter(VkRSBuffers* rsbuffers)
{
mBuffer = rsbuffers->MatrixBuffer.get();
}
bool VkMatrixBufferWriter::Write(const MatricesUBO& matrices)
{
mOffset = mBuffer->NextStreamDataBlock();
if (mOffset == 0xffffffff)
return false;
uint8_t* ptr = (uint8_t*)mBuffer->Data;
memcpy(ptr + mOffset, &matrices, sizeof(MatricesUBO));
return true;
}
void VkMatrixBufferWriter::Reset()
{
mOffset = 0;
mBuffer->Reset();
}

View file

@ -0,0 +1,104 @@
#pragma once
#include "vulkan/buffers/vk_hwbuffer.h"
#include "vulkan/shaders/vk_shader.h"
class VkStreamBuffer;
struct FFlatVertex;
class VkRSBuffers
{
public:
VkRSBuffers(VulkanRenderDevice* fb);
~VkRSBuffers();
struct
{
std::unique_ptr<VulkanBuffer> VertexBuffer;
int VertexFormat = 0;
FFlatVertex* Vertices = nullptr;
unsigned int ShadowDataSize = 0;
unsigned int CurIndex = 0;
static const unsigned int BUFFER_SIZE = 2000000;
static const unsigned int BUFFER_SIZE_TO_USE = BUFFER_SIZE - 500;
std::unique_ptr<VulkanBuffer> IndexBuffer;
} Flatbuffer;
struct
{
int UploadIndex = 0;
int BlockAlign = 0;
int Count = 1000;
std::unique_ptr<VulkanBuffer> UBO;
void* Data = nullptr;
} Viewpoint;
struct
{
int UploadIndex = 0;
int Count = 80000;
std::unique_ptr<VulkanBuffer> UBO;
void* Data = nullptr;
} Lightbuffer;
struct
{
int UploadIndex = 0;
int Count = 80000;
std::unique_ptr<VulkanBuffer> SSO;
void* Data = nullptr;
} Bonebuffer;
std::unique_ptr<VkStreamBuffer> MatrixBuffer;
std::unique_ptr<VkStreamBuffer> StreamBuffer;
};
class VkStreamBuffer
{
public:
VkStreamBuffer(VulkanRenderDevice* fb, size_t structSize, size_t count);
~VkStreamBuffer();
uint32_t NextStreamDataBlock();
void Reset() { mStreamDataOffset = 0; }
std::unique_ptr<VulkanBuffer> UBO;
void* Data = nullptr;
private:
uint32_t mBlockSize = 0;
uint32_t mStreamDataOffset = 0;
};
class VkStreamBufferWriter
{
public:
VkStreamBufferWriter(VkRSBuffers* rsbuffers);
bool Write(const StreamData& data);
void Reset();
uint32_t DataIndex() const { return mDataIndex; }
uint32_t StreamDataOffset() const { return mStreamDataOffset; }
private:
VkStreamBuffer* mBuffer;
uint32_t mDataIndex = MAX_STREAM_DATA - 1;
uint32_t mStreamDataOffset = 0;
};
class VkMatrixBufferWriter
{
public:
VkMatrixBufferWriter(VkRSBuffers* rsbuffers);
bool Write(const MatricesUBO& matrices);
void Reset();
uint32_t Offset() const { return mOffset; }
private:
VkStreamBuffer* mBuffer;
uint32_t mOffset = 0;
};

View file

@ -1,78 +0,0 @@
/*
** Vulkan backend
** Copyright (c) 2016-2020 Magnus Norddahl
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any damages
** arising from the use of this software.
**
** Permission is granted to anyone to use this software for any purpose,
** including commercial applications, and to alter it and redistribute it
** freely, subject to the following restrictions:
**
** 1. The origin of this software must not be misrepresented; you must not
** claim that you wrote the original software. If you use this software
** in a product, an acknowledgment in the product documentation would be
** appreciated but is not required.
** 2. Altered source versions must be plainly marked as such, and must not be
** misrepresented as being the original software.
** 3. This notice may not be removed or altered from any source distribution.
**
*/
#include "vk_streambuffer.h"
#include "vulkan/vk_renderstate.h"
#include "vulkan/vk_renderdevice.h"
#include "vulkan/buffers/vk_buffer.h"
#include <zvulkan/vulkanbuilders.h>
VkStreamBufferWriter::VkStreamBufferWriter(VkRSBuffers* rsbuffers)
{
mBuffer = rsbuffers->StreamBuffer.get();
}
bool VkStreamBufferWriter::Write(const StreamData& data)
{
mDataIndex++;
if (mDataIndex == MAX_STREAM_DATA)
{
mDataIndex = 0;
mStreamDataOffset = mBuffer->NextStreamDataBlock();
if (mStreamDataOffset == 0xffffffff)
return false;
}
uint8_t* ptr = (uint8_t*)mBuffer->Data;
memcpy(ptr + mStreamDataOffset + sizeof(StreamData) * mDataIndex, &data, sizeof(StreamData));
return true;
}
void VkStreamBufferWriter::Reset()
{
mDataIndex = MAX_STREAM_DATA - 1;
mStreamDataOffset = 0;
mBuffer->Reset();
}
/////////////////////////////////////////////////////////////////////////////
VkMatrixBufferWriter::VkMatrixBufferWriter(VkRSBuffers* rsbuffers)
{
mBuffer = rsbuffers->MatrixBuffer.get();
}
bool VkMatrixBufferWriter::Write(const MatricesUBO& matrices)
{
mOffset = mBuffer->NextStreamDataBlock();
if (mOffset == 0xffffffff)
return false;
uint8_t* ptr = (uint8_t*)mBuffer->Data;
memcpy(ptr + mOffset, &matrices, sizeof(MatricesUBO));
return true;
}
void VkMatrixBufferWriter::Reset()
{
mOffset = 0;
mBuffer->Reset();
}

View file

@ -1,40 +0,0 @@
#pragma once
#include "vulkan/buffers/vk_hwbuffer.h"
#include "vulkan/shaders/vk_shader.h"
class VkStreamBuffer;
class VkRSBuffers;
class VkStreamBufferWriter
{
public:
VkStreamBufferWriter(VkRSBuffers* rsbuffers);
bool Write(const StreamData& data);
void Reset();
uint32_t DataIndex() const { return mDataIndex; }
uint32_t StreamDataOffset() const { return mStreamDataOffset; }
private:
VkStreamBuffer* mBuffer;
uint32_t mDataIndex = MAX_STREAM_DATA - 1;
uint32_t mStreamDataOffset = 0;
};
class VkMatrixBufferWriter
{
public:
VkMatrixBufferWriter(VkRSBuffers* rsbuffers);
bool Write(const MatricesUBO& matrices);
void Reset();
uint32_t Offset() const { return mOffset; }
private:
VkStreamBuffer* mBuffer;
uint32_t mOffset = 0;
};

View file

@ -30,7 +30,7 @@
#include "vulkan/textures/vk_texture.h"
#include "vulkan/buffers/vk_hwbuffer.h"
#include "vulkan/buffers/vk_buffer.h"
#include "vulkan/buffers/vk_streambuffer.h"
#include "vulkan/buffers/vk_rsbuffers.h"
#include "vulkan/commands/vk_commandbuffer.h"
#include "vulkan/pipelines/vk_pprenderpass.h"
#include <zvulkan/vulkanbuilders.h>

View file

@ -54,7 +54,7 @@
#include "vulkan/commands/vk_commandbuffer.h"
#include "vulkan/buffers/vk_hwbuffer.h"
#include "vulkan/buffers/vk_buffer.h"
#include "vulkan/buffers/vk_streambuffer.h"
#include "vulkan/buffers/vk_rsbuffers.h"
#include <zvulkan/vulkanswapchain.h>
#include <zvulkan/vulkanbuilders.h>
#include <zvulkan/vulkansurface.h>

View file

@ -2,7 +2,7 @@
#pragma once
#include "vulkan/buffers/vk_hwbuffer.h"
#include "vulkan/buffers/vk_streambuffer.h"
#include "vulkan/buffers/vk_rsbuffers.h"
#include "vulkan/shaders/vk_shader.h"
#include "vulkan/pipelines/vk_renderpass.h"