Skip to content

Commit 95ddbd4

Browse files
fix swizzles not working && add a very nice utility function to cut out on the verbosity
1 parent 388f8fa commit 95ddbd4

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

include/nbl/asset/filters/CBlitImageFilter.h

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,29 @@ class CBlitImageFilter : public CImageFilter<CBlitImageFilter<Swizzle,Dither,Nor
8787
private:
8888
using value_type = typename KernelX::value_type;
8989
using base_t = CBlitImageFilterBase<value_type,Swizzle,Dither,Normalization,Clamp>;
90+
//using this_t = CBlitImageFilter<Swizzle,Dither,Normalization,Clamp,KernelX,KernelX,KernelX,lut_value_type>;
9091

91-
_NBL_STATIC_INLINE_CONSTEXPR auto MaxChannels = blit_utils_t::MaxChannels;
92+
static inline constexpr auto MaxChannels = blit_utils_t::MaxChannels;
9293

9394
public:
9495
// we'll probably never remove this requirement
9596
static_assert(KernelX::is_separable&&KernelY::is_separable&&KernelZ::is_separable,"Alpha Handling requires high precision and multipass filtering!");
9697

9798
virtual ~CBlitImageFilter() {}
9899

100+
enum E_SCRATCH_USAGE
101+
{
102+
ESU_SCALED_KERNEL_PHASED_LUT = 0,
103+
ESU_DECODE_WRITE = 1,
104+
ESU_BLIT_X_AXIS_READ = ESU_DECODE_WRITE,
105+
ESU_BLIT_X_AXIS_WRITE = 2,
106+
ESU_BLIT_Y_AXIS_READ = ESU_BLIT_X_AXIS_WRITE,
107+
ESU_BLIT_Y_AXIS_WRITE = 3,
108+
ESU_BLIT_Z_AXIS_READ = ESU_BLIT_Y_AXIS_WRITE,
109+
ESU_BLIT_Z_AXIS_WRITE = 4,
110+
ESU_ALPHA_HISTOGRAM = 5,
111+
ESU_COUNT
112+
};
99113
class CState : public IImageFilter::IState, public base_t::CStateBase
100114
{
101115
public:
@@ -121,6 +135,17 @@ class CBlitImageFilter : public CImageFilter<CBlitImageFilter<Swizzle,Dither,Nor
121135
}
122136
virtual ~CState() {}
123137

138+
inline bool recomputeScaledKernelPhasedLUT()
139+
{
140+
if (!base_t::CStateBase::scratchMemory || !inImage)
141+
return false;
142+
const size_t offset = getScratchOffset(this,ESU_SCALED_KERNEL_PHASED_LUT);
143+
const auto inType = inImage->getCreationParameters().type;
144+
const size_t size = blit_utils_t::template getScaledKernelPhasedLUTSize<lut_value_type>(inExtentLayerCount,outExtentLayerCount,inType,kernelX,kernelY,kernelZ);
145+
auto* lut = base_t::CStateBase::scratchMemory+offset;
146+
return blit_utils_t::template computeScaledKernelPhasedLUT<lut_value_type>(lut,inExtentLayerCount,outExtentLayerCount,inType,kernelX,kernelY,kernelZ);
147+
}
148+
124149
union
125150
{
126151
core::vectorSIMDu32 inOffsetBaseLayer;
@@ -169,20 +194,6 @@ class CBlitImageFilter : public CImageFilter<CBlitImageFilter<Swizzle,Dither,Nor
169194
};
170195
using state_type = CState;
171196

172-
enum E_SCRATCH_USAGE
173-
{
174-
ESU_SCALED_KERNEL_PHASED_LUT = 0,
175-
ESU_DECODE_WRITE = 1,
176-
ESU_BLIT_X_AXIS_READ=ESU_DECODE_WRITE,
177-
ESU_BLIT_X_AXIS_WRITE=2,
178-
ESU_BLIT_Y_AXIS_READ = ESU_BLIT_X_AXIS_WRITE,
179-
ESU_BLIT_Y_AXIS_WRITE = 3,
180-
ESU_BLIT_Z_AXIS_READ = ESU_BLIT_Y_AXIS_WRITE,
181-
ESU_BLIT_Z_AXIS_WRITE = 4,
182-
ESU_ALPHA_HISTOGRAM = 5,
183-
ESU_COUNT
184-
};
185-
186197
//! Call `getScratchOffset(state, ESU_COUNT)` to get the total scratch size needed.
187198
static inline uint32_t getScratchOffset(const state_type* state, const E_SCRATCH_USAGE usage)
188199
{
@@ -541,10 +552,10 @@ class CBlitImageFilter : public CImageFilter<CBlitImageFilter<Swizzle,Dither,Nor
541552
continue;
542553

543554
auto sample = lineBuffer+i*MaxChannels;
544-
value_type swizzledSample[MaxChannels];
555+
value_type preSwizzleSample[MaxChannels];
545556

546557
// TODO: make sure there is no leak due to MaxChannels!
547-
base_t::template onDecode(inFormat, state, srcPix, sample, swizzledSample, inBlockCoord.x, inBlockCoord.y);
558+
base_t::template onDecode(inFormat, state, srcPix, preSwizzleSample, sample, inBlockCoord.x, inBlockCoord.y);
548559

549560
if (nonPremultBlendSemantic)
550561
{

0 commit comments

Comments
 (0)