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
/*
Copyright (c) 2015 DIVIDE-Studio
Copyright (c) 2009 Ionut Cava

This file is part of DIVIDE Framework.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software
and associated documentation files (the "Software"), to deal in the Software
without restriction,
including without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#ifndef _GL_MEMORY_MANAGER_H_
#define _GL_MEMORY_MANAGER_H_

#include "Platform/Video/OpenGL/Headers/glResources.h"

namespace Divide {
namespace GLUtil {
    class VBO {
    public:
        // Allocate VBOs in 64K chunks. This will HIGHLY depend on actual data usage and requires testing.
        static const U32 MAX_VBO_CHUNK_SIZE_BYTES = 64 * 1024;
        // nVidia recommended (years ago) to use up to 4 megs per VBO. Use 4 MEGS VBOs :D
        static const U32  MAX_VBO_SIZE_BYTES = 4 * 1024 * 1024;
        // The total number of available chunks per VBO is easy to figure out
        static const U32 MAX_VBO_CHUNK_COUNT = MAX_VBO_SIZE_BYTES / MAX_VBO_CHUNK_SIZE_BYTES;

        //keep track of what chunks we are using
        //for each chunk, keep track how many next chunks are also part of the same allocation
        std::array<std::pair<bool, U32>, MAX_VBO_CHUNK_COUNT> _chunkUsageState;

        static U32 getChunkCountForSize(size_t sizeInBytes);

        VBO();
        ~VBO();

        void freeAll();
        U32 handle();
        bool checkChunksAvailability(U32 offset, U32 count);

        bool allocateChunks(U32 count, GLenum usage, U32& offsetOut);

        void releaseChunks(U32 offset);

        U32 getMemUsage();

    private:
        GLuint _handle;
        GLenum _usage;
    };

    struct AllocationHandle {
        explicit AllocationHandle()
            : _id(0),
            _offset(0)
        {
        }

        GLuint _id;
        U32 _offset;
    };

    bool commitVBO(U32 chunkCount, GLenum usage, GLuint& handleOut, U32& offsetOut);
    bool releaseVBO(GLuint& handle, U32& offset);
    U32 getVBOMemUsage(GLuint handle);
    U32 getVBOCount();

    void clearVBOs();

    void createAndAllocBuffer(GLsizeiptr bufferSize,
                              GLenum usageMask,
                              GLuint& bufferIdOut,
                              const bufferPtr data = NULL);

    bufferPtr allocPersistentBuffer(GLuint bufferId,
                                    GLsizeiptr bufferSize,
                                    BufferStorageMask storageMask,
                                    BufferAccessMask accessMask,
                                    const bufferPtr data = NULL);

    bufferPtr createAndAllocPersistentBuffer(GLsizeiptr bufferSize,
                                             BufferStorageMask storageMask,
                                             BufferAccessMask accessMask,
                                             GLuint& bufferIdOut,
                                             const bufferPtr data = NULL);

    void freeBuffer(GLuint &bufferId, bufferPtr mappedPtr = nullptr);

}; //namespace GLUtil
}; //namespace Divide

#endif //_GL_MEMORY_MANAGER_H_

Commits for Divide-Framework/trunk/Source Code/Platform/Video/OpenGL/Buffers/Headers/glMemoryManager.h

Diff revisions: vs.
Revision Author Commited Message
557 Diff Diff IonutCava picture IonutCava Tue 10 Nov, 2015 12:00:20 +0000

[IonutCava]
- Gather all rendering calls from glVertexArray and glGenericVertexData into a single function in glResources: submitRenderCommand.
— This allows both classes to interpret GenericDrawCommands in the same way
- Use unsigned ints for all hasehs instead of size_t to avoid negative number hashes (useful for debugging)

553 Diff Diff IonutCava picture IonutCava Sun 08 Nov, 2015 21:48:10 +0000

[IonutCava]
- Improve VBO allocation system
- Disable mipmap generation for blur FBO in CascadedShadowMaps
- Code cleanup

398 Diff Diff IonutCava picture IonutCava Mon 13 Apr, 2015 16:11:29 +0000

[Ionut]
- Migrated to a pure OpenGL 4.5 implementation
- Fixed a string bug in glsw’s path suffix and prefix strings
- Some profile-guided optimizations

395 Diff Diff IonutCava picture IonutCava Wed 01 Apr, 2015 16:06:28 +0000

[Ionut]
- Shader management improvements
- More singleton fixes
- Automatic core count detection and threadpool adjustment at startup
- Replaced most static C-arrays with std::array
- Replace most file manipulation code from C-style FILE based system to ifstream/ofstream

369 Diff Diff IonutCava picture IonutCava Fri 13 Mar, 2015 00:34:48 +0000

[Ionut]
- More updates to the DSA style OpenGL API implementation
- Remove 0-count draw commands from rendering queue before uploading to GPU memory

363 Diff Diff IonutCava picture IonutCava Thu 05 Mar, 2015 22:37:12 +0000

[Ionut]
- More work on OpenGL memory management

362 IonutCava picture IonutCava Thu 05 Mar, 2015 17:10:19 +0000

[Ionut]
- Initial part of OpenGL memory refactoring