Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "stdafx.h"

#include "Headers/CommandBufferPool.h"

namespace Divide {
namespace GFX {

#define USE_MEMORY_POOL

namespace {
#if !defined(USE_MEMORY_POOL)
    static SharedLock s_mutex;
    static std::deque<CommandBuffer> s_pool;
    static std::vector<bool> s_freeList;
#endif
};

CommandBufferPool::CommandBufferPool()
    : _bufferCount(0)
{
}

CommandBufferPool::~CommandBufferPool()
{

}

CommandBuffer* CommandBufferPool::allocateBuffer() {
#if defined(USE_MEMORY_POOL)
    WriteLock lock(_mutex);
    return _pool.newElement(_bufferCount++);
#else
    WriteLock lock(s_mutex);
    for (size_t i = 0; i < s_freeList.size(); ++i) {
        if (s_freeList[i]) {
            s_freeList[i] = false;
            _bufferCount++;
            return &s_pool[i];
        }
    }

    s_freeList.push_back(false);
    s_pool.emplace_back(s_pool.size());
    s_bufferCount++;
    return &s_pool.back();
#endif
}

void CommandBufferPool::deallocateBuffer(CommandBuffer*& buffer) {
    if (buffer != nullptr) {
#if defined(USE_MEMORY_POOL)
        WriteLock lock(_mutex);
        _pool.deleteElement(buffer);
#else
        size_t index = buffer->_index;
        buffer->clear();

        WriteLock lock(s_mutex);
        s_freeList[index] = true;
#endif

        buffer = nullptr;
        _bufferCount--;
    }
}

ScopedCommandBuffer::ScopedCommandBuffer(bool useSecondaryBuffers)
    : _useSecondaryBuffers(useSecondaryBuffers),
      _buffer(allocateCommandBuffer(useSecondaryBuffers))
{
}

ScopedCommandBuffer::~ScopedCommandBuffer()
{
    deallocateCommandBuffer(_buffer, _useSecondaryBuffers);
}


ScopedCommandBuffer allocateScopedCommandBuffer(bool useSecondaryBuffers) {
    return ScopedCommandBuffer(useSecondaryBuffers);
}

CommandBuffer* allocateCommandBuffer(bool useSecondaryBuffers) {
    if (useSecondaryBuffers) {
        return s_secondaryCommandBufferPool.allocateBuffer();
    }
    return s_commandBufferPool.allocateBuffer();
}

void deallocateCommandBuffer(GFX::CommandBuffer*& buffer, bool useSecondaryBuffers) {
    if (useSecondaryBuffers) {
        return s_secondaryCommandBufferPool.deallocateBuffer(buffer);
    }

    s_commandBufferPool.deallocateBuffer(buffer);
}

}; //namespace GFX
}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/Platform/Video/CommandBufferPool.cpp

Diff revisions: vs.
Revision Author Commited Message
949 Diff Diff IonutCava picture IonutCava Thu 19 Oct, 2017 21:48:37 +0000

[Ionut]
- More command buffer refactoring

947 Diff Diff IonutCava picture IonutCava Sun 08 Oct, 2017 22:36:54 +0000

[Ionut]
- Refactor command buffer pooling
- Remove all static commands in an attempt to fix rendering issues. Profile and rework later.

943 Diff Diff IonutCava picture IonutCava Tue 12 Sep, 2017 11:38:52 +0000

[IonutCava]
- Rework ThreadPool/Task system for clearer parent<->child relationship between tasks
— Disable Prio pool since it doesn’t work properly with the newest boost libraries
— Modify the C++11 threadpool to remove the boost dependency
- Reduce memory usage by allocating command buffers on use instead of on creation

942 IonutCava picture IonutCava Wed 06 Sep, 2017 20:45:37 +0000

[Ionut]
- Add more DLLs required by CEGUI
- Move CommandBuffer allocation from GFXDevice to GFX namespace