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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "Headers/glBufferImpl.h"
#include "Headers/glMemoryManager.h"
#include "Headers/glBufferLockManager.h"

namespace Divide {
namespace {

    const size_t g_persistentMapSizeThreshold = 512 * 1024; //512Kb

    typedef std::array<vec3<size_t>, to_const_uint(ShaderBufferLocation::COUNT)> BindConfig;
    BindConfig g_currentBindConfig;

    bool setIfDifferentBindRange(U32 UBOid,
                                 U32 bindIndex,
                                 size_t offset,
                                 size_t range) {

        vec3<size_t>& crtConfig = g_currentBindConfig[bindIndex];

        if (crtConfig.x != static_cast<size_t>(UBOid) ||
            crtConfig.y != offset ||
            crtConfig.z != range ||
            true) {
            crtConfig.set(static_cast<size_t>(UBOid), offset, range);
            return true;
        }

        return false;
    }
};

glBufferImpl::glBufferImpl(const BufferImplParams& params)
    : _target(params._target),
      _handle(0),
      _alignedSize(params._dataSizeInBytes),
      _updateFrequency(params._frequency),
      _mappedBuffer(nullptr),
      _lockManager(MemoryManager_NEW glBufferLockManager())
{

    _usage = _target == GL_TRANSFORM_FEEDBACK
                        ? _updateFrequency == BufferUpdateFrequency::ONCE
                                            ? GL_STATIC_COPY
                                            : _updateFrequency == BufferUpdateFrequency::OCASSIONAL
                                                                ? GL_DYNAMIC_COPY
                                                                : GL_STREAM_COPY
                        : _updateFrequency == BufferUpdateFrequency::ONCE
                                            ? GL_STATIC_DRAW
                                            : _updateFrequency == BufferUpdateFrequency::OCASSIONAL
                                                                ? GL_DYNAMIC_DRAW
                                                                : GL_STREAM_DRAW;

    bool usePersistentMapping = !Config::Profile::DISABLE_PERSISTENT_BUFFER && 
                                _alignedSize > g_persistentMapSizeThreshold;

    if (!usePersistentMapping) {
        GLUtil::createAndAllocBuffer(_alignedSize, _usage, _handle, params._initialData, params._name);
    } else {
        gl::BufferStorageMask storageMask = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT;
        if (_updateFrequency != BufferUpdateFrequency::ONCE) {
            //storageMask |= GL_DYNAMIC_STORAGE_BIT;
        }

        gl::BufferAccessMask accessMask = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT;

        _mappedBuffer = GLUtil::createAndAllocPersistentBuffer(_alignedSize, storageMask, accessMask, _handle, params._initialData, params._name);

        assert(_mappedBuffer != nullptr && "PersistentBuffer::Create error: Can't mapped persistent buffer!");
    }
}

glBufferImpl::~glBufferImpl()
{
    if (_handle > 0) {
        waitRange(0, _alignedSize, false);
        if (_mappedBuffer == nullptr) {
            glInvalidateBufferData(_handle);
        }

        GLUtil::freeBuffer(_handle, _mappedBuffer);
    }

    MemoryManager::DELETE(_lockManager);
}

void glBufferImpl::waitRange(size_t offset, size_t range, bool blockClient) {
    _lockManager->WaitForLockedRange(offset, range, blockClient);
}

void glBufferImpl::lockRange(size_t offset, size_t range) {
    _lockManager->LockRange(offset, range);
}

GLuint glBufferImpl::bufferID() const {
    return _handle;
}

bool glBufferImpl::bindRange(GLuint bindIndex, size_t offset, size_t range) {
    assert(_handle != 0 && "BufferImpl error: Tried to bind an uninitialized UBO");

    bool success = false;
    if (setIfDifferentBindRange(_handle, bindIndex, offset, range))
    {
        glBindBufferRange(_target, bindIndex, _handle, offset, range);
        success = true;
    }
    if (_mappedBuffer) {
        lockRange(offset, range);
    }

    return success;
}

void glBufferImpl::updateData(size_t offset, size_t range, const bufferPtr data)
{
    if (_mappedBuffer) {
        waitRange(offset, range, true);
        assert(_mappedBuffer != nullptr && "PersistentBuffer::UpdateData error: was called for an unmapped buffer!");
        if (data) {
            memcpy(((U8*)_mappedBuffer) + offset, data, range);
        } else {
            memset(((U8*)_mappedBuffer) + offset, 0, range);
        }
    } else {
        if (offset == 0 && range == _alignedSize) {
            glInvalidateBufferData(_handle);
            glNamedBufferData(_handle, _alignedSize, data, _usage);
        } else {
            glInvalidateBufferSubData(_handle, offset, range);
            glNamedBufferSubData(_handle, offset, range, data);
        }
    }
}

void glBufferImpl::readData(size_t offset, size_t range, const bufferPtr data)
{
    if (_mappedBuffer) {
        memcpy(data, ((U8*)(_mappedBuffer)+offset), range);
    } else {
        glGetNamedBufferSubData(_handle, offset, range, data);
    }
}

}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/Platform/Video/OpenGL/Buffers/glBufferImpl.cpp

Diff revisions: vs.
Revision Author Commited Message
827 Diff Diff IonutCava picture IonutCava Sun 22 Jan, 2017 21:59:36 +0000

[IonutCava]
- ShaderBuffers now decide heuristically if they get persistently mapped or not (depends on size. Current limit is 512Kb for subData calls.
- Separate visible node command generation into 2 steps: onRender and getDrawPackage. onRender allows the creation of parallel tasks that should finish by the time the second call, getDrawPackage reaches the same node
- Update ParticleEmitter to take into account multiple players and increase parallelism at the cost of memory consumption and complexity.
- Add a default bounding box for Players (add extents to SceneTransform nodes)
- All buffers (ShaderBuffer, d3dConstantBuffer, glUniformBuffer, glBufferImpl, glGenericBuffer, etc) use BufferParams for creation.
— Constructor and create calls have been merged together

826 Diff Diff IonutCava picture IonutCava Fri 20 Jan, 2017 17:11:41 +0000

[IonutCava]
- Persistent buffer optimisations

819 Diff Diff IonutCava picture IonutCava Mon 16 Jan, 2017 21:30:53 +0000

[IonutCava]
- More threading updates to the LightPool class

807 Diff Diff IonutCava picture IonutCava Mon 09 Jan, 2017 17:06:26 +0000

[IonutCava]
- Split PlatformDefines.h into 2. Move data type defines to PlatformDataTypes.h
- Continue to improve velocity map calculation
- Remove “destroy()” calls from most classes. Attempt to move as many classes to the RAII system.

780 Diff Diff IonutCava picture IonutCava Tue 11 Oct, 2016 16:15:24 +0000

[IonutCava]
- AtomicCounter in glUniformBuffer is now based on a glGenericBuffer implementation
- GFXDevice <-> Camera relation cleaned up a bit
- Added a readback system for glGenericBuffer
- Fixed a bug with Z_PRE_PASS stage culling

743 Diff Diff IonutCava picture IonutCava Tue 28 Jun, 2016 15:55:50 +0000

[IonutCava]
- More performance tuning:
— Move billboarding related camera variable calculation to shaders instead of CPU
— Replace some DIVIDE_ASSERT calls with regular assert calls in really low level code.
— Some cleanup of the GenericDrawCommand class
— glRegularBuffer does an invalidation call before updating
— Misc changes

738 Diff Diff IonutCava picture IonutCava Fri 24 Jun, 2016 16:06:04 +0000

[IonutCava]
- Performance improvement: Create linear list of ordered SGNs for update and split update step in two to allow parallel tasks in the first step to finish before moving to second step
- Performance improvement: Remove glFlush calls for lock manager. Drivers should be up to the task now
- Performance improvement: Re-enabled round robin buffer system for ParticleEmitter

736 Diff Diff IonutCava picture IonutCava Wed 22 Jun, 2016 20:55:11 +0000

[IonutCava]
- Trying to fix rendering issues with the Particle system in regards to the usage of the Generic Vertex Data object and its buffers

735 Diff Diff IonutCava picture IonutCava Wed 22 Jun, 2016 16:11:34 +0000

[IonutCava]
- Cleanup GenericVertexData class

713 IonutCava picture IonutCava Wed 25 May, 2016 15:43:38 +0000

[IonutCava]
- Removed all unique_ptr’s from the code with classic new/delete pairs. They were seriously not needed.
- Added the concept of SceneComponent to scene specific classes: aiManager, lightPool, sceneGraph, physicsInterface etc
— This allowed the removal of the global GET_ACTIVE_SCENEGRAPH call;