@@ -19,11 +19,11 @@ namespace nbl
19
19
namespace asset
20
20
{
21
21
22
- template <typename Swizzle>
23
- class CNormalMapToDerivativeFilterBase : public impl ::CSwizzleableAndDitherableFilterBase<false , false , Swizzle, IdentityDither >
22
+ template <typename Swizzle, typename Dither >
23
+ class CNormalMapToDerivativeFilterBase : public impl ::CSwizzleableAndDitherableFilterBase<false , false , Swizzle, Dither >
24
24
{
25
25
public:
26
- class CNormalMapToDerivativeStateBase : public impl ::CSwizzleableAndDitherableFilterBase<false , false , Swizzle, IdentityDither >::state_type
26
+ class CNormalMapToDerivativeStateBase : public impl ::CSwizzleableAndDitherableFilterBase<false , false , Swizzle, Dither >::state_type
27
27
{
28
28
public:
29
29
@@ -50,19 +50,13 @@ class CNormalMapToDerivativeFilterBase : public impl::CSwizzleableAndDitherableF
50
50
Layer ID is relative to outBaseLayer in state
51
51
*/
52
52
53
- enum E_SCALE_FACTOR
54
- {
55
- ESF_X,
56
- ESF_Y,
57
- ESF_COUNT
58
- };
59
-
60
- const float getAbsoluteLayerScaleValue (size_t layer, E_SCALE_FACTOR scaleFactor)
53
+ const core::vectorSIMDf getAbsoluteLayerScaleValues (size_t layer)
61
54
{
62
55
if (!scaleValuesPointer)
63
56
{
64
- auto offset = layer * forcedScratchChannelAmount + scaleFactor == ESF_X ? 0 : 1 ;
65
- return *(scaleValuesPointer + offset);
57
+ auto offset = layer * forcedScratchChannelAmount;
58
+ auto * data = scaleValuesPointer + offset;
59
+ return core::vectorSIMDf (*data, *(data + 1 ));
66
60
}
67
61
else
68
62
return 0 ; // or maybe assert?
@@ -90,7 +84,7 @@ class CNormalMapToDerivativeFilterBase : public impl::CSwizzleableAndDitherableF
90
84
if (state->scratchMemoryByteSize == 0 )
91
85
return false ;
92
86
93
- if (!impl::CSwizzleableAndDitherableFilterBase<false , false , Swizzle, IdentityDither >::validate (state))
87
+ if (!impl::CSwizzleableAndDitherableFilterBase<false , false , Swizzle, Dither >::validate (state))
94
88
return false ;
95
89
96
90
return true ;
@@ -102,13 +96,13 @@ class CNormalMapToDerivativeFilterBase : public impl::CSwizzleableAndDitherableF
102
96
103
97
*/
104
98
105
- template <typename Swizzle = DefaultSwizzle>
106
- class CNormalMapToDerivativeFilter : public CMatchedSizeInOutImageFilterCommon , public CNormalMapToDerivativeFilterBase <Swizzle>
99
+ template <typename Swizzle = DefaultSwizzle, typename Dither = IdentityDither >
100
+ class CNormalMapToDerivativeFilter : public CMatchedSizeInOutImageFilterCommon , public CNormalMapToDerivativeFilterBase <Swizzle, Dither >
107
101
{
108
102
public:
109
103
virtual ~CNormalMapToDerivativeFilter () {}
110
104
111
- class CStateBase : public CMatchedSizeInOutImageFilterCommon ::state_type, public CNormalMapToDerivativeFilterBase<Swizzle>::CNormalMapToDerivativeStateBase
105
+ class CStateBase : public CMatchedSizeInOutImageFilterCommon ::state_type, public CNormalMapToDerivativeFilterBase<Swizzle, Dither >::CNormalMapToDerivativeStateBase
112
106
{
113
107
public:
114
108
CStateBase () = default ;
@@ -135,7 +129,7 @@ class CNormalMapToDerivativeFilter : public CMatchedSizeInOutImageFilterCommon,
135
129
if (!CMatchedSizeInOutImageFilterCommon::validate (state))
136
130
return false ;
137
131
138
- if (!CNormalMapToDerivativeFilterBase<Swizzle>::validate (state))
132
+ if (!CNormalMapToDerivativeFilterBase<Swizzle, Dither >::validate (state))
139
133
return false ;
140
134
141
135
const ICPUImage::SCreationParams& inParams = state->inImage ->getCreationParameters ();
@@ -194,7 +188,7 @@ class CNormalMapToDerivativeFilter : public CMatchedSizeInOutImageFilterCommon,
194
188
195
189
for (uint16_t w = 0u ; w < copyLayerCount; ++w)
196
190
{
197
- float * decodeAbsValuesOffset = state->scaleValuesPointer + (w * CNormalMapToDerivativeFilterBase<Swizzle>::CNormalMapToDerivativeStateBase::forcedScratchChannelAmount);
191
+ float * decodeAbsValuesOffset = state->scaleValuesPointer + (w * CNormalMapToDerivativeFilterBase<Swizzle, Dither >::CNormalMapToDerivativeStateBase::forcedScratchChannelAmount);
198
192
199
193
auto & xMaxDecodeAbsValue = *decodeAbsValuesOffset;
200
194
auto & yMaxDecodeAbsValue = *(decodeAbsValuesOffset + 1 );
@@ -225,6 +219,15 @@ class CNormalMapToDerivativeFilter : public CMatchedSizeInOutImageFilterCommon,
225
219
226
220
*data = -xDecode / zDecode;
227
221
*(data + 1 ) = -yDecode / zDecode;
222
+
223
+ auto absoluteX = core::abs (*data);
224
+ auto absoluteY = core::abs (*(data + 1 ));
225
+
226
+ if (xMaxDecodeAbsValue < absoluteX)
227
+ xMaxDecodeAbsValue = absoluteX;
228
+
229
+ if (yMaxDecodeAbsValue < absoluteY)
230
+ yMaxDecodeAbsValue = absoluteY;
228
231
}
229
232
};
230
233
@@ -237,35 +240,12 @@ class CNormalMapToDerivativeFilter : public CMatchedSizeInOutImageFilterCommon,
237
240
}
238
241
239
242
{
240
- auto getScratchPixel = [&](core::vector4di32_SIMD readBlockPos) -> CNormalMapToDerivativeFilterBase<Swizzle>::CNormalMapToDerivativeStateBase::decodeType*
243
+ auto getScratchPixel = [&](core::vector4di32_SIMD readBlockPos) -> CNormalMapToDerivativeFilterBase<Swizzle, Dither >::CNormalMapToDerivativeStateBase::decodeType*
241
244
{
242
245
const size_t scratchOffset = asset::IImage::SBufferCopy::getLocalByteOffset (core::vector3du32_SIMD (readBlockPos.x , readBlockPos.y , readBlockPos.z , 0 ), scratchByteStrides); // TODO
243
- return reinterpret_cast <CNormalMapToDerivativeFilterBase<Swizzle>::CNormalMapToDerivativeStateBase::decodeType*>(reinterpret_cast <uint8_t *>(state->scratchMemory ) + scratchOffset);
244
- };
245
-
246
- auto computeMaxAbs = [&](core::vectorSIMDi32 readBlockPos) -> void
247
- {
248
- auto * current = getScratchPixel (readBlockPos);
249
- auto & [x, y] = std::make_tuple (*current, *(current + 1 ));
250
-
251
- auto absoluteX = core::abs (x);
252
- auto absoluteY = core::abs (y);
253
-
254
- if (xMaxDecodeAbsValue < absoluteX)
255
- xMaxDecodeAbsValue = absoluteX;
256
-
257
- if (yMaxDecodeAbsValue < absoluteY)
258
- yMaxDecodeAbsValue = absoluteY;
246
+ return reinterpret_cast <CNormalMapToDerivativeFilterBase<Swizzle, Dither>::CNormalMapToDerivativeStateBase::decodeType*>(reinterpret_cast <uint8_t *>(state->scratchMemory ) + scratchOffset);
259
247
};
260
248
261
- {
262
- core::vector3du32_SIMD localCoord;
263
- for (auto & z = localCoord[2 ] = 0u ; z < state->extent .depth ; ++z)
264
- for (auto & y = localCoord[1 ] = 0u ; y < state->extent .height ; ++y)
265
- for (auto & x = localCoord[0 ] = 0u ; x < state->extent .width ; ++x)
266
- computeMaxAbs (core::vectorSIMDu32 (x, y, z));
267
- }
268
-
269
249
auto normalizeScratch = [&](bool isSigned)
270
250
{
271
251
core::vector3du32_SIMD localCoord;
@@ -274,13 +254,13 @@ class CNormalMapToDerivativeFilter : public CMatchedSizeInOutImageFilterCommon,
274
254
for (auto & x = localCoord[0 ] = 0u ; x < state->extent .width ; ++x)
275
255
{
276
256
const size_t scratchOffset = asset::IImage::SBufferCopy::getLocalByteOffset (localCoord, scratchByteStrides);
277
- auto * entryScratchAdress = reinterpret_cast <CNormalMapToDerivativeFilterBase<Swizzle>::CNormalMapToDerivativeStateBase::decodeType*>(reinterpret_cast <uint8_t *>(state->scratchMemory ) + scratchOffset);
257
+ auto * entryScratchAdress = reinterpret_cast <CNormalMapToDerivativeFilterBase<Swizzle, Dither >::CNormalMapToDerivativeStateBase::decodeType*>(reinterpret_cast <uint8_t *>(state->scratchMemory ) + scratchOffset);
278
258
279
259
if (isSigned)
280
- for (uint8_t channel = 0 ; channel < CNormalMapToDerivativeFilterBase<Swizzle>::CNormalMapToDerivativeStateBase::forcedScratchChannelAmount; ++channel)
260
+ for (uint8_t channel = 0 ; channel < CNormalMapToDerivativeFilterBase<Swizzle, Dither >::CNormalMapToDerivativeStateBase::forcedScratchChannelAmount; ++channel)
281
261
entryScratchAdress[channel] = entryScratchAdress[channel] / decodeAbsValuesOffset[channel];
282
262
else
283
- for (uint8_t channel = 0 ; channel < CNormalMapToDerivativeFilterBase<Swizzle>::CNormalMapToDerivativeStateBase::forcedScratchChannelAmount; ++channel)
263
+ for (uint8_t channel = 0 ; channel < CNormalMapToDerivativeFilterBase<Swizzle, Dither >::CNormalMapToDerivativeStateBase::forcedScratchChannelAmount; ++channel)
284
264
entryScratchAdress[channel] = entryScratchAdress[channel] * 0 .5f / decodeAbsValuesOffset[channel] + 0 .5f ;
285
265
}
286
266
};
@@ -301,7 +281,7 @@ class CNormalMapToDerivativeFilter : public CMatchedSizeInOutImageFilterCommon,
301
281
const size_t offset = asset::IImage::SBufferCopy::getLocalByteOffset (localOutPos, scratchByteStrides);
302
282
auto * data = reinterpret_cast <uint8_t *>(state->scratchMemory ) + offset;
303
283
304
- impl::CSwizzleAndConvertImageFilterBase<false , false , Swizzle, IdentityDither>::onEncode (outFormat, state, outDataAdress, data, localOutPos, 0 , 0 , CNormalMapToDerivativeFilterBase<Swizzle>::CNormalMapToDerivativeStateBase::forcedScratchChannelAmount); // overrrides texels, so region-overlapping case is fine
284
+ impl::CSwizzleAndConvertImageFilterBase<false , false , Swizzle, IdentityDither>::onEncode (outFormat, state, outDataAdress, data, localOutPos, 0 , 0 , CNormalMapToDerivativeFilterBase<Swizzle, Dither >::CNormalMapToDerivativeStateBase::forcedScratchChannelAmount); // overrrides texels, so region-overlapping case is fine
305
285
};
306
286
307
287
IImage::SSubresourceLayers subresource = { static_cast <IImage::E_ASPECT_FLAGS>(0u ), state->outMipLevel , state->outBaseLayer , 1 };
0 commit comments