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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#include "stdafx.h"

#include "Headers/GFXDevice.h"

#include "Utility/Headers/Localization.h"

#include "Platform/Video/OpenGL/Buffers/RenderTarget/Headers/glFramebuffer.h"
#include "Platform/Video/Direct3D/Buffers/RenderTarget/Headers/d3dRenderTarget.h"

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

#include "Platform/Video/OpenGL/Buffers/VertexBuffer/Headers/glVertexArray.h"
#include "Platform/Video/Direct3D/Buffers/VertexBuffer/Headers/d3dVertexBuffer.h"

#include "Platform/Video/OpenGL/Buffers/PixelBuffer/Headers/glPixelBuffer.h"
#include "Platform/Video/Direct3D/Buffers/PixelBuffer/Headers/d3dPixelBuffer.h"

#include "Platform/Video/OpenGL/Buffers/VertexBuffer/Headers/glGenericVertexData.h"
#include "Platform/Video/Direct3D/Buffers/VertexBuffer/Headers/d3dGenericVertexData.h"

#include "Platform/Video/OpenGL/Textures/Headers/glTexture.h"
#include "Platform/Video/Direct3D/Textures/Headers/d3dTexture.h"

#include "Platform/Video/OpenGL/Shaders/Headers/glShaderProgram.h"
#include "Platform/Video/Direct3D/Shaders/Headers/d3dShaderProgram.h"

#include "Platform/Video/OpenGL/Buffers/ShaderBuffer/Headers/glUniformBuffer.h"
#include "Platform/Video/Direct3D/Buffers/ShaderBuffer/Headers/d3dConstantBuffer.h"

namespace Divide {

namespace {
    GFXDevice& refThis(const GFXDevice* device) {
        return const_cast<GFXDevice&>(*device);
    }
};

RenderTarget* GFXDevice::newRT(const RenderTargetDescriptor& descriptor) const {
    bool locked = _gpuObjectArenaMutex.try_lock();

    RenderTarget* temp = nullptr;
    switch (_API_ID) {
        case RenderAPI::OpenGL:
        case RenderAPI::OpenGLES: {
            /// Create and return a new framebuffer.
            /// The callee is responsible for it's deletion!
            temp =  new (_gpuObjectArena) glFramebuffer(refThis(this), descriptor);
        } break;
        case RenderAPI::Direct3D: {
            temp = new (_gpuObjectArena) d3dRenderTarget(refThis(this), descriptor);
        } break;
        default: {
            DIVIDE_UNEXPECTED_CALL(Locale::get(_ID("ERROR_GFX_DEVICE_API")));
        } break;
    };

    if (temp != nullptr) {
        _gpuObjectArena.DTOR(temp);
    }

    if (locked) {
        _gpuObjectArenaMutex.unlock();
    }

    return temp;
}

IMPrimitive* GFXDevice::newIMP() const {
    bool locked = _gpuObjectArenaMutex.try_lock();

    IMPrimitive* temp = nullptr;
    switch (_API_ID) {
        case RenderAPI::OpenGL:
        case RenderAPI::OpenGLES: {
            /// Create and return a new IM emulation primitive. The callee is responsible
            /// for it's deletion!
            temp = new (_gpuObjectArena) glIMPrimitive(refThis(this));
        } break;
        default: {
            DIVIDE_UNEXPECTED_CALL(Locale::get(_ID("ERROR_GFX_DEVICE_API")));
        } break;
    };

    if (temp != nullptr) {
        _gpuObjectArena.DTOR(temp);
    }

    if (locked) {
        _gpuObjectArenaMutex.unlock();
    }

    return temp;
}

VertexBuffer* GFXDevice::newVB() const {
    bool locked = _gpuObjectArenaMutex.try_lock();

    VertexBuffer* temp = nullptr;
    switch (_API_ID) {
        case RenderAPI::OpenGL:
        case RenderAPI::OpenGLES: {
            /// Create and return a new vertex array (VAO + VB + IB).
            /// The callee is responsible for it's deletion!
            temp = new (_gpuObjectArena) glVertexArray(refThis(this));
        } break;
        case RenderAPI::Direct3D: {
            temp = new (_gpuObjectArena) d3dVertexBuffer(refThis(this));
        } break;
        default: {
            DIVIDE_UNEXPECTED_CALL(Locale::get(_ID("ERROR_GFX_DEVICE_API")));
        } break;
    };

    if (temp != nullptr) {
        _gpuObjectArena.DTOR(temp);
    }

    if (locked) {
        _gpuObjectArenaMutex.unlock();
    }

    return temp;
}

PixelBuffer* GFXDevice::newPB(PBType type) const {
    bool locked = _gpuObjectArenaMutex.try_lock();

    PixelBuffer* temp = nullptr;
    switch (_API_ID) {
        case RenderAPI::OpenGL:
        case RenderAPI::OpenGLES: {
            /// Create and return a new pixel buffer using the requested format.
            /// The callee is responsible for it's deletion!
            temp = new (_gpuObjectArena) glPixelBuffer(refThis(this), type);
        } break;
        case RenderAPI::Direct3D: {
            temp = new (_gpuObjectArena) d3dPixelBuffer(refThis(this), type);
        } break;
        default: {
            DIVIDE_UNEXPECTED_CALL(Locale::get(_ID("ERROR_GFX_DEVICE_API")));
        } break;
    };

    if (temp != nullptr) {
        _gpuObjectArena.DTOR(temp);
    }

    if (locked) {
        _gpuObjectArenaMutex.unlock();
    }

    return temp;
}

GenericVertexData* GFXDevice::newGVD(const U32 ringBufferLength) const {
    bool locked = _gpuObjectArenaMutex.try_lock();

    GenericVertexData* temp = nullptr;
    switch (_API_ID) {
        case RenderAPI::OpenGL:
        case RenderAPI::OpenGLES: {
            /// Create and return a new generic vertex data object
            /// The callee is responsible for it's deletion!
            temp = new (_gpuObjectArena) glGenericVertexData(refThis(this), ringBufferLength);
        } break;
        case RenderAPI::Direct3D: {
            temp = new (_gpuObjectArena) d3dGenericVertexData(refThis(this), ringBufferLength);
        } break;
        default: {
            DIVIDE_UNEXPECTED_CALL(Locale::get(_ID("ERROR_GFX_DEVICE_API")));
        } break;
    };

    if (temp != nullptr) {
        _gpuObjectArena.DTOR(temp);
    }

    if (locked) {
        _gpuObjectArenaMutex.unlock();
    }

    return temp;
}

Texture* GFXDevice::newTexture(size_t descriptorHash,
                               const stringImpl& name,
                               const stringImpl& resourceName,
                               const stringImpl& resourceLocation,
                               bool isFlipped,
                               bool asyncLoad,
                               const TextureDescriptor& texDescriptor) const {
    bool locked = _gpuObjectArenaMutex.try_lock();
    

    // Texture is a resource! Do not use object arena!
    Texture* temp = nullptr;
    switch (_API_ID) {
        case RenderAPI::OpenGL:
        case RenderAPI::OpenGLES: {
            /// Create and return a new texture. The callee is responsible for it's deletion!
            temp = new (_gpuObjectArena) glTexture(refThis(this), descriptorHash, name, resourceName, resourceLocation, isFlipped, asyncLoad, texDescriptor);
        } break;
        case RenderAPI::Direct3D: {
            temp = new (_gpuObjectArena) d3dTexture(refThis(this), descriptorHash, name, resourceName, resourceLocation, isFlipped, asyncLoad, texDescriptor);
        } break;
        default: {
            DIVIDE_UNEXPECTED_CALL(Locale::get(_ID("ERROR_GFX_DEVICE_API")));
        } break;
    };

    if (temp != nullptr) {
        _gpuObjectArena.DTOR(temp);
    }

    if (locked) {
        _gpuObjectArenaMutex.unlock();
    }

    return temp;
}

Pipeline& GFXDevice::newPipeline(const PipelineDescriptor& descriptor) const {
    size_t hash = descriptor.getHash();
    hashMapImpl<size_t, Pipeline>::iterator it = _pipelineCache.find(hash);

    if (it == std::cend(_pipelineCache)) {
        return hashAlg::insert(_pipelineCache, hash, Pipeline(descriptor)).first->second;
    }

    return it->second;
}

ShaderProgram* GFXDevice::newShaderProgram(size_t descriptorHash,
                                           const stringImpl& name,
                                           const stringImpl& resourceName,
                                           const stringImpl& resourceLocation,
                                           bool asyncLoad) const {
    bool locked = _gpuObjectArenaMutex.try_lock();

    // ShaderProgram is a resource! Do not use object arena!
    ShaderProgram* temp = nullptr;
    switch (_API_ID) {
        case RenderAPI::OpenGL:
        case RenderAPI::OpenGLES: {
            /// Create and return a new shader program.
            /// The callee is responsible for it's deletion!
            temp = new (_gpuObjectArena) glShaderProgram(refThis(this), descriptorHash, name, resourceName, resourceLocation, asyncLoad);
        } break;
        case RenderAPI::Direct3D: {
            temp = new (_gpuObjectArena) d3dShaderProgram(refThis(this), descriptorHash, name, resourceName, resourceLocation, asyncLoad);
        } break;
        default: {
            DIVIDE_UNEXPECTED_CALL(Locale::get(_ID("ERROR_GFX_DEVICE_API")));
        } break;
    };

    if (temp != nullptr) {
        _gpuObjectArena.DTOR(temp);
    }

    if (locked) {
        _gpuObjectArenaMutex.unlock();
    }

    return temp;
}

ShaderBuffer* GFXDevice::newSB(const ShaderBufferDescriptor& descriptor) const {
    bool locked = _gpuObjectArenaMutex.try_lock();

    ShaderBuffer* temp = nullptr;
    switch (_API_ID) {
        case RenderAPI::OpenGL:
        case RenderAPI::OpenGLES: {
            /// Create and return a new shader buffer. The callee is responsible for it's deletion!
            /// The OpenGL implementation creates either an 'Uniform Buffer Object' if unbound is false
            /// or a 'Shader Storage Block Object' otherwise
            /// The shader buffer can also be persistently mapped, if requested
            temp = new (_gpuObjectArena) glUniformBuffer(refThis(this), descriptor);
        } break;
        case RenderAPI::Direct3D: {
            temp = new (_gpuObjectArena) d3dConstantBuffer(refThis(this), descriptor);
        } break;
        default: {
            DIVIDE_UNEXPECTED_CALL(Locale::get(_ID("ERROR_GFX_DEVICE_API")));
        } break;
    };

    if (temp != nullptr) {
        _gpuObjectArena.DTOR(temp);
    }

    if (locked) {
        _gpuObjectArenaMutex.unlock();
    }

    return temp;
}

}; // namespace Divide

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

Diff revisions: vs.
Revision Author Commited Message
1012 Diff Diff IonutCava picture IonutCava Mon 15 Jan, 2018 17:21:32 +0000

[Ionut]
- Update boost to v1.66
- Performance optimizations

996 Diff Diff IonutCava picture IonutCava Tue 12 Dec, 2017 17:16:54 +0000

[Ionut]
- Update and improve SGN creation and destruction
- Fix cleanup issues
- Fix GPU object memory leaks
- Fix duplicate GUID values being generated
- Misc cleanups and optimizations

953 Diff Diff IonutCava picture IonutCava Sat 28 Oct, 2017 21:57:10 +0000

[Ionut]
- Fix blinking issue by caching and hashing pipelines to that we don’t overwrite pipelines used by other elements

945 Diff Diff IonutCava picture IonutCava Wed 13 Sep, 2017 11:50:59 +0000

[Ionut]
- Rework Task <-> TaskPool work status signalling
- Add UniqueLock typedef

911 Diff Diff IonutCava picture IonutCava Fri 30 Jun, 2017 21:08:09 +0000

[Ionut]
- Use RTAttachmentDescriptor and RenderTargetDescriptor to initialise render targets.
— All formats and attachments need to be specified upfront!

909 Diff Diff IonutCava picture IonutCava Thu 29 Jun, 2017 23:57:18 +0000

[Ionut]
- Rework RenderTarget class
— RTAttachment now deal with textures directly
— RT size needs to be specified upfront
- Application class is no longer a Singleton but passed around in the PlatformContext

907 Diff Diff IonutCava picture IonutCava Wed 28 Jun, 2017 23:16:40 +0000

[Ionut]
- Rework texture loading, mip map generation, sampler usage, etc
- ResourceDescriptor for textures now ONLY takes a TextureDescriptor as a property descriptor. Sampler must be assigned to the tex descriptor:
— ToDo: Separate samplers completely from textures and assign them from a pool to textures at bind time

895 Diff Diff IonutCava picture IonutCava Wed 21 Jun, 2017 21:10:26 +0000

[IonutCava]
- Reorder and cleanup OpenGL backend a bit.
- Small code cleanup
- Some small profile-guided optimizations

893 Diff Diff IonutCava picture IonutCava Sun 18 Jun, 2017 17:33:07 +0000

[Ionut]
- Initial implementation of a PipelineStateObject (holds shader program, rasterizer state, etc)
- Rework PCH implementation a bit because VS2017 no longer has a /ZM option

890 IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation