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
/* Copyright (c) 2017 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 _PLATFORM_VIDEO_OPENGLS_PROGRAM_INL_
#define _PLATFORM_VIDEO_OPENGLS_PROGRAM_INL_

#include "Core/Headers/Console.h"

namespace Divide {
    namespace {
        bool compare(GFX::PushConstantType type, const vectorImpl<AnyParam>& lhsVec, const vectorImpl<AnyParam>& rhsVec) {
            for (vectorAlg::vecSize i = 0; i < lhsVec.size(); ++i) {
                const AnyParam& lhs = lhsVec[i];
                const AnyParam& rhs = rhsVec[i];

                switch (type) {
                    case GFX::PushConstantType::BOOL:  return lhs.constant_cast<bool>() == rhs.constant_cast<bool>();
                    case GFX::PushConstantType::INT:   return lhs.constant_cast<I32>() == rhs.constant_cast<I32>();
                    case GFX::PushConstantType::UINT:  return lhs.constant_cast<U32>() == rhs.constant_cast<U32>();
                    case GFX::PushConstantType::DOUBLE:return lhs.constant_cast<D64>() == rhs.constant_cast<D64>();
                    case GFX::PushConstantType::FLOAT: return lhs.constant_cast<F32>() == rhs.constant_cast<F32>();
                    case GFX::PushConstantType::IVEC2: return lhs.constant_cast<vec2<I32>>() == rhs.constant_cast<vec2<I32>>();
                    case GFX::PushConstantType::IVEC3: return lhs.constant_cast<vec3<I32>>() == rhs.constant_cast<vec3<I32>>();
                    case GFX::PushConstantType::IVEC4: return lhs.constant_cast<vec4<I32>>() == rhs.constant_cast<vec4<I32>>();
                    case GFX::PushConstantType::UVEC2: return lhs.constant_cast<vec2<U32>>() == rhs.constant_cast<vec2<U32>>();
                    case GFX::PushConstantType::UVEC3: return lhs.constant_cast<vec3<U32>>() == rhs.constant_cast<vec3<U32>>();
                    case GFX::PushConstantType::UVEC4: return lhs.constant_cast<vec4<U32>>() == rhs.constant_cast<vec4<U32>>();
                    case GFX::PushConstantType::DVEC2: return lhs.constant_cast<vec2<D64>>() == rhs.constant_cast<vec2<D64>>();
                    case GFX::PushConstantType::VEC2:  return lhs.constant_cast<vec2<F32>>() == rhs.constant_cast<vec2<F32>>();
                    case GFX::PushConstantType::DVEC3: return lhs.constant_cast<vec3<D64>>() == rhs.constant_cast<vec3<D64>>();
                    case GFX::PushConstantType::VEC3:  return lhs.constant_cast<vec3<F32>>() == rhs.constant_cast<vec3<F32>>();
                    case GFX::PushConstantType::DVEC4: return lhs.constant_cast<vec4<D64>>() == rhs.constant_cast<vec4<D64>>();
                    case GFX::PushConstantType::VEC4:  return lhs.constant_cast<vec4<F32>>() == rhs.constant_cast<vec4<F32>>();
                    case GFX::PushConstantType::IMAT2: return lhs.constant_cast<mat2<I32>>() == rhs.constant_cast<mat2<I32>>();
                    case GFX::PushConstantType::IMAT3: return lhs.constant_cast<mat3<I32>>() == rhs.constant_cast<mat3<I32>>();
                    case GFX::PushConstantType::IMAT4: return lhs.constant_cast<mat4<I32>>() == rhs.constant_cast<mat4<I32>>();
                    case GFX::PushConstantType::UMAT2: return lhs.constant_cast<mat2<U32>>() == rhs.constant_cast<mat2<U32>>();
                    case GFX::PushConstantType::UMAT3: return lhs.constant_cast<mat3<U32>>() == rhs.constant_cast<mat3<U32>>();
                    case GFX::PushConstantType::UMAT4: return lhs.constant_cast<mat4<U32>>() == rhs.constant_cast<mat4<U32>>();
                    case GFX::PushConstantType::MAT2:  return lhs.constant_cast<mat2<F32>>() == rhs.constant_cast<mat2<F32>>();
                    case GFX::PushConstantType::MAT3:  return lhs.constant_cast<mat3<F32>>() == rhs.constant_cast<mat3<F32>>();
                    case GFX::PushConstantType::MAT4:  return lhs.constant_cast<mat4<F32>>() == rhs.constant_cast<mat4<F32>>();
                    case GFX::PushConstantType::DMAT2: return lhs.constant_cast<mat2<D64>>() == rhs.constant_cast<mat2<D64>>();
                    case GFX::PushConstantType::DMAT3: return lhs.constant_cast<mat3<D64>>() == rhs.constant_cast<mat3<D64>>();
                    case GFX::PushConstantType::DMAT4: return lhs.constant_cast<mat4<D64>>() == rhs.constant_cast<mat4<D64>>();
                };
            }

            return false;
        }

        template<typename T>
        typename std::enable_if<!std::is_same<T, bool>::value, void>::type
        convert(const vectorImpl<AnyParam>& valuesIn, vectorImpl<T>& valuesOut) {
            std::transform(std::cbegin(valuesIn), std::cend(valuesIn), std::begin(valuesOut), [](const AnyParam& val)
            {
                return val.constant_cast<T>();
            });
        }

        template<typename T>
        typename std::enable_if<std::is_same<T, bool>::value, void>::type
        convert(const vectorImpl<AnyParam>& valuesIn, vectorImpl<T>& valuesOut) {
            std::transform(std::cbegin(valuesIn), std::cend(valuesIn), std::begin(valuesOut), [](const AnyParam& val)
            {
                return val.constant_cast<bool>() ? 1 : 0;
            });
        }

        //ToDo: REALLY SLOW! Find a faster way of handling this! -Ionut
        template<typename T_out, typename T_in>
        struct castData {
            castData(const vectorImpl<AnyParam>& values)
                : _convertedData(values.size()),
                  _values(values)
            {
                convert(_values, _convertedData);
            }

            T_out* operator()() {
                return (T_out*)(_convertedData.data());
            }

            using vectorType = typename std::conditional<std::is_same<T_in, bool>::value, I32, T_in>::type;
            vectorImpl<vectorType> _convertedData;

            const vectorImpl<AnyParam>& _values;
        };
    };

    inline bool glShaderProgram::comparePushConstants(const GFX::PushConstant& lhs, const GFX::PushConstant& rhs) const {
        if (lhs._type == rhs._type) {
            if (lhs._binding == rhs._binding) {
                if (lhs._flag == rhs._flag) {
                    return compare(lhs._type, lhs._values, rhs._values);
                }
            }
        }

        return false;
    }

    void glShaderProgram::Uniform(I32 binding, GFX::PushConstantType type, const vectorImpl<AnyParam>& values, bool flag) const {
        GLsizei count = (GLsizei)values.size();
        switch (type) {
            case GFX::PushConstantType::BOOL:
                glProgramUniform1iv(_shaderProgramID, binding, count, castData<GLint, bool>(values)());
                break;
            case GFX::PushConstantType::INT:
                glProgramUniform1iv(_shaderProgramID, binding, count, castData<GLint, I32>(values)());
                break;
            case GFX::PushConstantType::UINT:
                glProgramUniform1uiv(_shaderProgramID, binding, count, castData<GLuint, U32>(values)());
                break;
            case GFX::PushConstantType::DOUBLE:           // Warning! Downcasting to float -Ionut
                glProgramUniform1fv(_shaderProgramID, binding, count, castData<GLfloat, D64>(values)());
                break;
            case GFX::PushConstantType::FLOAT:
                glProgramUniform1fv(_shaderProgramID, binding, count, castData<GLfloat, F32>(values)());
                break;
            case GFX::PushConstantType::IVEC2:
                glProgramUniform2iv(_shaderProgramID, binding, count, castData<GLint, vec2<I32>>(values)());
                break;
            case GFX::PushConstantType::IVEC3:
                glProgramUniform3iv(_shaderProgramID, binding, count, castData<GLint, vec3<I32>>(values)());
                break;
            case GFX::PushConstantType::IVEC4:
                glProgramUniform4iv(_shaderProgramID, binding, count, castData<GLint, vec4<I32>>(values)());
                break;
            case GFX::PushConstantType::UVEC2:
                glProgramUniform2uiv(_shaderProgramID, binding, count, castData<GLuint, vec2<U32>>(values)());
                break;
            case GFX::PushConstantType::UVEC3:
                glProgramUniform3uiv(_shaderProgramID, binding, count, castData<GLuint, vec3<U32>>(values)());
                break;
            case GFX::PushConstantType::UVEC4:
                glProgramUniform4uiv(_shaderProgramID, binding, count, castData<GLuint, vec4<U32>>(values)());
                break;
            case GFX::PushConstantType::DVEC2:            // Warning! Downcasting to float -Ionut
                glProgramUniform2fv(_shaderProgramID, binding, count, castData<GLfloat, vec2<D64>>(values)());
                break;
            case GFX::PushConstantType::VEC2:
                glProgramUniform2fv(_shaderProgramID, binding, count, castData<GLfloat, vec2<F32>>(values)());
                break;
            case GFX::PushConstantType::DVEC3:            // Warning! Downcasting to float -Ionut
                glProgramUniform3fv(_shaderProgramID, binding, count, castData<GLfloat, vec3<D64>>(values)());
                break;
            case GFX::PushConstantType::VEC3:
                glProgramUniform3fv(_shaderProgramID, binding, count, castData<GLfloat, vec3<F32>>(values)());
                break;
            case GFX::PushConstantType::DVEC4:            // Warning! Downcasting to float -Ionut
                glProgramUniform4fv(_shaderProgramID, binding, count, castData<GLfloat, vec4<D64>>(values)());
                break;
            case GFX::PushConstantType::VEC4:
                glProgramUniform4fv(_shaderProgramID, binding, count, castData<GLfloat, vec4<F32>>(values)());
                break;
            case GFX::PushConstantType::IMAT2:
                glProgramUniformMatrix2fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat2<I32>>(values)());
                break;
            case GFX::PushConstantType::IMAT3:
                glProgramUniformMatrix3fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat3<I32>>(values)());
                break;
            case GFX::PushConstantType::IMAT4:
                glProgramUniformMatrix4fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat4<I32>>(values)());
                break;
            case GFX::PushConstantType::UMAT2:
                glProgramUniformMatrix2fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat2<U32>>(values)());
                break;
            case GFX::PushConstantType::UMAT3:
                glProgramUniformMatrix3fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat3<U32>>(values)());
                break;
            case GFX::PushConstantType::UMAT4:
                glProgramUniformMatrix4fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat4<U32>>(values)());
                break;
            case GFX::PushConstantType::MAT2:
                glProgramUniformMatrix2fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat2<F32>>(values)());
                break;
            case GFX::PushConstantType::MAT3:
                glProgramUniformMatrix3fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat3<F32>>(values)());
                break;
            case GFX::PushConstantType::MAT4: {
                glProgramUniformMatrix4fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat4<F32>>(values)());
            }break;
            case GFX::PushConstantType::DMAT2:
                glProgramUniformMatrix2fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat2<D64>>(values)());
                break;
            case GFX::PushConstantType::DMAT3:
                glProgramUniformMatrix3fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat3<D64>>(values)());
                break;
            case GFX::PushConstantType::DMAT4:
                glProgramUniformMatrix4fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat4<D64>>(values)());
                break;
            default:
                DIVIDE_ASSERT(false, "glShaderProgram::Uniform error: Unhandled data type!");
        }
    }

    inline void glShaderProgram::UploadPushConstant(const GFX::PushConstant& constant) {
        I32 binding = cachedValueUpdate(constant);

        if (binding != -1) {
            Uniform(binding, constant._type, constant._values, constant._flag);
        }
    }

    inline void glShaderProgram::UploadPushConstants(const PushConstants& constants) {
        for (auto& constant : constants.data()) {
            if (!constant.second->_binding.empty() && constant.second->_type != GFX::PushConstantType::COUNT) {
                UploadPushConstant(*constant.second);
            }
        }
    }
}; //namespace Divide

#endif //_PLATFORM_VIDEO_OPENGLS_PROGRAM_INL_

Commits for Divide-Framework/trunk/Source Code/Platform/Video/OpenGL/Shaders/Headers/glShaderProgram.inl

Diff revisions: vs.
Revision Author Commited Message
1014 Diff Diff IonutCava picture IonutCava Tue 16 Jan, 2018 01:18:31 +0000

[Ionut]
- Attempt to pool PushConstants
— ToDo: Fix cleanup crash / heap corruption

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

931 Diff Diff IonutCava picture IonutCava Sun 13 Aug, 2017 23:09:33 +0000

[Ionut]
- More work on PushConstants to Uniforms conversion

930 Diff Diff IonutCava picture IonutCava Sun 13 Aug, 2017 20:33:31 +0000

[Ionut]
- Fix a bug with Push Constant to Uniform conversion
- Add more push constant types
- Fix RENDER_INDIRECT param for draw commands
- Cleanup Sky, Terrain and Vegetation a bit

929 Diff Diff IonutCava picture IonutCava Sat 12 Aug, 2017 17:34:44 +0000

[Ionut]
- More work on finishing up new PushConstant / Command buffer rendering system:
— Everything compiles and runs but with graphical and performance issues

928 Diff Diff IonutCava picture IonutCava Fri 11 Aug, 2017 16:20:37 +0000

[Ionut]
- Started porting Shader uniforms to more generic PushConstants (Part 1/2: does not compile yet)
— Implemented in OpenGL via Uniform emulation

923 Diff Diff IonutCava picture IonutCava Tue 01 Aug, 2017 22:23:24 +0000

[Ionut]
- Add (hack) new GL 4.6 KHR_NO_ERROR flag for non-GPU validated builds
- Disable GPU debug messages by default. Re-enabled only via a command line argument: “--enableGPUMessageGroups”.
- Cleanup GL texture and sampler binding
- Rework hash map insert and emplace
- Update SDL to 2.0.5

912 Diff Diff IonutCava picture IonutCava Sun 02 Jul, 2017 23:42:39 +0000

[Ionut]
- Add experimental Weighted Blended Order Independed Transparency (ref: http://casual-effects.blogspot.co.uk/2015/03/implemented-weighted-blended-order.html)
— Add per drawbuffer blend
— All translucent renderbin items go via the new OIT 2-step rendering: accumulation and composition
- Make sure we have proper blend enabled for text rendering
- Add a primitive form of PushConstants (unused yet. Emulated via Uniform calls)
- Fix bug with XMLParser not using case insensitive key lookups

892 Diff Diff IonutCava picture IonutCava Mon 15 May, 2017 20:43:39 +0000

[Ionut]
- Miscellaneous bug fixes

889 IonutCava picture IonutCava Tue 04 Apr, 2017 16:01:34 +0000

[IonutCava]
- Rework uniform passing/caching to better work with shader recompilation
- Cleanup shaders a bit for better performance