1
- // Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O.
1
+ // Copyright (C) 2018-2023 - DevSH Graphics Programming Sp. z O.O.
2
2
// This file is part of the "Nabla Engine".
3
3
// For conditions of distribution and use, see copyright notice in nabla.h
4
-
5
4
#ifndef _NBL_ASSET_NORMALIZATION_STATES_H_INCLUDED_
6
5
#define _NBL_ASSET_NORMALIZATION_STATES_H_INCLUDED_
7
6
@@ -40,7 +39,7 @@ class CGlobalNormalizationState
40
39
void prepass (Tenc* encodeBuffer, const core::vectorSIMDu32& position, uint32_t blockX, uint32_t blockY, uint8_t channels)
41
40
{
42
41
static_assert (std::is_floating_point_v<Tenc>, " Integer decode not supported yet!" );
43
- for (uint8_t channel=0u ; channel<4u ; ++channel)
42
+ for (uint8_t channel=0u ; channel<channels ; ++channel)
44
43
{
45
44
const auto val = encodeBuffer[channel];
46
45
if constexpr (std::is_floating_point_v<Tenc>)
@@ -112,6 +111,23 @@ namespace impl
112
111
113
112
class CDerivativeMapNormalizationStateBase
114
113
{
114
+ protected:
115
+ // we only care about R and G
116
+ static inline constexpr uint32_t kChannels = 2 ;
117
+
118
+ template <bool isSignedFormat, typename Tenc>
119
+ void impl (Tenc* encodeBuffer, const core::vectorSIMDu32& position, uint32_t blockX, uint32_t blockY, uint8_t channels) const
120
+ {
121
+ static_assert (std::is_floating_point_v<Tenc>, " Encode types must be double or float!" );
122
+
123
+ if constexpr (isSignedFormat)
124
+ for (uint8_t channel = 0 ; channel < kChannels ; ++channel)
125
+ encodeBuffer[channel] = encodeBuffer[channel]/maxAbsPerChannel[channel];
126
+ else
127
+ for (uint8_t channel = 0 ; channel < kChannels ; ++channel)
128
+ encodeBuffer[channel] = encodeBuffer[channel]*0 .5f /maxAbsPerChannel[channel]+0 .5f ;
129
+ }
130
+
115
131
public:
116
132
inline bool validate () const {return true ;}
117
133
@@ -120,15 +136,15 @@ class CDerivativeMapNormalizationStateBase
120
136
inline void initialize ()
121
137
{
122
138
static_assert (std::is_floating_point_v<Tenc>, " Integer encode not supported yet!" );
123
- std::fill_n (maxAbsPerChannel,4 ,0 .f );
139
+ std::fill_n (maxAbsPerChannel,kChannels ,0 .f );
124
140
}
125
141
126
142
//
127
143
template <typename Tenc>
128
144
void prepass (Tenc* encodeBuffer, const core::vectorSIMDu32& position, uint32_t blockX, uint32_t blockY, uint8_t channels)
129
145
{
130
146
static_assert (std::is_floating_point_v<Tenc>, " Integer encode not supported yet!" );
131
- for (uint8_t channel=0u ; channel<4u ; ++channel)
147
+ for (uint8_t channel=0u ; channel<kChannels ; ++channel)
132
148
core::atomic_fetch_max (maxAbsPerChannel+channel,core::abs (encodeBuffer[channel]));
133
149
}
134
150
@@ -144,6 +160,7 @@ class CDerivativeMapNormalizationStateBase
144
160
template <typename Tenc>
145
161
void operator ()(E_FORMAT format, Tenc* encodeBuffer, const core::vectorSIMDu32& position, uint32_t blockX, uint32_t blockY, uint8_t channels) const
146
162
{
163
+ assert (channels>=kChannels );
147
164
#ifdef _NBL_DEBUG
148
165
bool status = isFloatingPointFormat (format)||isNormalizedFormat (format);
149
166
assert (status);
@@ -155,20 +172,7 @@ class CDerivativeMapNormalizationStateBase
155
172
impl<false ,Tenc>(encodeBuffer,position,blockX,blockY,channels);
156
173
}
157
174
158
- core::atomic<float > maxAbsPerChannel[4 ];
159
- protected:
160
- template <bool isSignedFormat, typename Tenc>
161
- void impl (Tenc* encodeBuffer, const core::vectorSIMDu32& position, uint32_t blockX, uint32_t blockY, uint8_t channels) const
162
- {
163
- static_assert (std::is_floating_point_v<Tenc>, " Encode types must be double or float!" );
164
-
165
- if constexpr (isSignedFormat)
166
- for (uint8_t channel = 0 ; channel < channels; ++channel)
167
- encodeBuffer[channel] = encodeBuffer[channel]/maxAbsPerChannel[channel];
168
- else
169
- for (uint8_t channel = 0 ; channel < channels; ++channel)
170
- encodeBuffer[channel] = encodeBuffer[channel]*0 .5f /maxAbsPerChannel[channel]+0 .5f ;
171
- }
175
+ core::atomic<float > maxAbsPerChannel[kChannels ];
172
176
};
173
177
174
178
}
@@ -183,8 +187,8 @@ class CDerivativeMapNormalizationState : public impl::CDerivativeMapNormalizatio
183
187
static_assert (std::is_floating_point_v<Tenc>, " Integer encode types not supported yet!" );
184
188
if constexpr (isotropic)
185
189
{
186
- const float isotropicMax = core::max ( core::max ( maxAbsPerChannel[0 ],maxAbsPerChannel[1 ]), core::max (maxAbsPerChannel[ 2 ],maxAbsPerChannel[ 3 ]) );
187
- for (auto i=0u ; i<4u ; i++)
190
+ const float isotropicMax = core::max< float >( maxAbsPerChannel[0 ],maxAbsPerChannel[1 ]);
191
+ for (auto i=0u ; i<kChannels ; i++)
188
192
maxAbsPerChannel[i] = isotropicMax;
189
193
}
190
194
}
0 commit comments