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
/*
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 _PUSH_CONSTANT_H_
#define _PUSH_CONSTANT_H_

#include "Platform/Headers/PlatformDataTypes.h"
#include "Platform/Headers/PlatformDefines.h"

namespace Divide {
namespace GFX {

    enum class PushConstantType : U8 {
        BOOL = 0,
        INT,
        UINT,
        FLOAT,
        DOUBLE,
        //BVEC2, use vec2<I32>(1/0, 1/0)
        //BVEC3, use vec3<I32>(1/0, 1/0, 1/0)
        //BVEC4, use vec4<I32>(1/0, 1/0, 1/0, 1/0)
        IVEC2,
        IVEC3,
        IVEC4,
        UVEC2,
        UVEC3,
        UVEC4,
        VEC2,
        VEC3,
        VEC4,
        DVEC2,
        DVEC3,
        DVEC4,
        IMAT2,
        IMAT3,
        IMAT4,
        UMAT2,
        UMAT3,
        UMAT4,
        MAT2,
        MAT3,
        MAT4,
        DMAT2,
        DMAT3,
        DMAT4,
        //MAT_N_x_M,
        COUNT
    };

    struct PushConstant {
        PushConstant() = default;

        template<typename T>
        PushConstant(const stringImplFast& binding,
                     PushConstantType type,
                     const vectorImpl<T>& values,
                     bool flag = false)
            : _binding(binding),
              _bindingHash(_ID_RT(binding.c_str())),
              _type(type),
              _flag(flag),
              _transpose(false)
        {
            _buffer.resize(values.size() * (sizeof(T)));
            if (!_buffer.empty()) {
                std::memcpy(_buffer.data(), values.data(), _buffer.size());
            }
        }

        template<>
        PushConstant(const stringImplFast& binding,
                     PushConstantType type,
                     const vectorImpl<bool>& values,
                     bool flag)
            : _binding(binding),
              _bindingHash(_ID_RT(binding.c_str())),
              _type(type),
              _flag(flag),
              _transpose(false)
        {
            _buffer.reserve(values.size());
            if (!_buffer.empty()) {
                std::transform(std::cbegin(values), std::cend(values),
                               std::back_inserter(_buffer),
                               [](bool e) {return to_byte(e ? 1 : 0);});
            }
        }

        template<typename T, size_t N>
        PushConstant(const stringImplFast& binding,
                     PushConstantType type,
                     const std::array<T, N>& values,
                     bool flag = false)
            : _binding(binding),
              _bindingHash(_ID_RT(binding.c_str())),
              _type(type),
              _flag(flag),
              _transpose(false)
        {
            _buffer.resize(values.size() * (sizeof(T)));
            if (!_buffer.empty()) {
                std::memcpy(_buffer.data(), values.data(), _buffer.size());
            }
        }

        template<size_t N>
        PushConstant(const stringImplFast& binding,
                     PushConstantType type,
                     const std::array<bool, N>& values,
                     bool flag)
            : _binding(binding),
              _bindingHash(_ID_RT(binding.c_str()))
              _type(type),
              _flag(flag),
              _transpose(false)
        {
            _buffer.reserve(N);
            if (!_buffer.empty()) {
                std::transform(std::cbegin(values), std::cend(values),
                               std::back_inserter(_buffer),
                               [](bool e) {return to_byte(e ? 1 : 0);});
            }
        }

        PushConstant(const PushConstant& other);
        PushConstant& operator=(const PushConstant& other);
        PushConstant& assign(const PushConstant& other);

        ~PushConstant();

        void clear();


        inline bool operator==(const PushConstant& rhs) const {
            return _bindingHash == rhs._bindingHash &&
                   _type == rhs._type &&
                   _flag == rhs._flag &&
                   _buffer == rhs._buffer;
        }

        inline bool operator!=(const PushConstant& rhs) const {
            return _bindingHash != rhs._bindingHash ||
                   _type != rhs._type ||
                   _flag != rhs._flag ||
                   _buffer != rhs._buffer;
        }

        U64              _bindingHash;
        stringImplFast   _binding;
        PushConstantType _type = PushConstantType::COUNT;
        vectorImpl<char> _buffer;
        union {
            bool _flag = false;
            bool _transpose;
        };
    };
}; //namespace GFX
}; //namespace Divide
#endif //_PUSH_CONSTANT_H_

Commits for Divide-Framework/trunk/Source Code/Platform/Video/Headers/PushConstant.h

Diff revisions: vs.
Revision Author Commited Message
1021 Diff Diff IonutCava picture IonutCava Sun 21 Jan, 2018 22:19:16 +0000

[Ionut]
- Performance optimizations

1020 Diff Diff IonutCava picture IonutCava Fri 19 Jan, 2018 17:51:19 +0000

[Ionut]
- Second attempt at improving PushConstant performance

1015 Diff Diff IonutCava picture IonutCava Tue 16 Jan, 2018 17:15:50 +0000

[Ionut]
- Update to the newest PhysX SDK
- Some more performance improvements

1014 IonutCava picture IonutCava Tue 16 Jan, 2018 01:18:31 +0000

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