Permalink
Browse files

Merge pull request #9905 from hrydgard/vulkan-vertex-cache

Implement vertex caching for Vulkan.
  • Loading branch information...
hrydgard committed Aug 17, 2017
2 parents cd43049 + 4573746 commit e50cb4f3954cb6cdddf3b4bdd1a4a3d2c679b98a
@@ -114,6 +114,14 @@ void VulkanPushBuffer::Defragment(VulkanContext *vulkan) {
assert(res);
}
size_t VulkanPushBuffer::GetTotalSize() const {
size_t sum = 0;
if (buffers_.size() > 1)
sum += size_ * (buffers_.size() - 1);
sum += offset_;
return sum;
}
VulkanDeviceAllocator::VulkanDeviceAllocator(VulkanContext *vulkan, size_t minSlabSize, size_t maxSlabSize)
: vulkan_(vulkan), lastSlab_(0), minSlabSize_(minSlabSize), maxSlabSize_(maxSlabSize), memoryTypeIndex_(UNDEFINED_MEMORY_TYPE), destroyed_(false) {
assert((minSlabSize_ & (SLAB_GRAIN_SIZE - 1)) == 0);
@@ -38,13 +38,18 @@ class VulkanPushBuffer {
Map();
}
void BeginNoReset() {
Map();
}
void End() {
Unmap();
}
void Map() {
assert(!writePtr_);
VkResult res = vkMapMemory(device_, buffers_[buf_].deviceMemory, offset_, size_, 0, (void **)(&writePtr_));
VkResult res = vkMapMemory(device_, buffers_[buf_].deviceMemory, 0, size_, 0, (void **)(&writePtr_));
assert(writePtr_);
assert(VK_SUCCESS == res);
}
@@ -105,6 +110,8 @@ class VulkanPushBuffer {
return writePtr_ + off;
}
size_t GetTotalSize() const;
private:
bool AddBuffer();
void NextBuffer(size_t minSize);
@@ -59,7 +59,7 @@ class IndexGenerator {
}
void SetIndex(int ind) { index_ = ind; }
int MaxIndex() const { return index_; }
int MaxIndex() const { return index_; } // Really NextIndex rather than MaxIndex, it's one more than the highest index generated
int VertexCount() const { return count_; }
bool Empty() const { return index_ == 0; }
int SeenPrims() const { return seenPrims_; }
@@ -72,7 +72,7 @@ class VertexArrayInfoD3D11 {
}
~VertexArrayInfoD3D11();
enum Status {
enum Status : uint8_t {
VAI_NEW,
VAI_HASHING,
VAI_RELIABLE, // cache, don't hash
@@ -82,15 +82,14 @@ class VertexArrayInfoD3D11 {
ReliableHashType hash;
u32 minihash;
Status status;
ID3D11Buffer *vbo;
ID3D11Buffer *ebo;
// Precalculated parameter for drawRangeElements
u16 numVerts;
u16 maxIndex;
s8 prim;
Status status;
// ID information
int numDraws;
@@ -71,7 +71,7 @@ class VertexArrayInfoDX9 {
}
~VertexArrayInfoDX9();
enum Status {
enum Status : uint8_t {
VAI_NEW,
VAI_HASHING,
VAI_RELIABLE, // cache, don't hash
@@ -81,15 +81,14 @@ class VertexArrayInfoDX9 {
ReliableHashType hash;
u32 minihash;
Status status;
LPDIRECT3DVERTEXBUFFER9 vbo;
LPDIRECT3DINDEXBUFFER9 ebo;
// Precalculated parameter for drawRangeElements
u16 numVerts;
u16 maxIndex;
s8 prim;
Status status;
// ID information
int numDraws;
@@ -71,7 +71,7 @@ class VertexArrayInfo {
flags = 0;
}
enum Status {
enum Status : uint8_t {
VAI_NEW,
VAI_HASHING,
VAI_RELIABLE, // cache, don't hash
@@ -81,15 +81,14 @@ class VertexArrayInfo {
ReliableHashType hash;
u32 minihash;
Status status;
u32 vbo;
u32 ebo;
// Precalculated parameter for drawRangeElements
u16 numVerts;
u16 maxIndex;
s8 prim;
Status status;
// ID information
int numDraws;
Oops, something went wrong.

0 comments on commit e50cb4f

Please sign in to comment.