Hi Everyone,
Does any one know how to deal alpha blending with opencl efficiently? I had ported the host code to opencl and cuda, but the performance come out too poor. does anybody has any advice?
Hi Everyone,
Following is the code of opencl kernel for alpha blending. Can anyone give me some suggestion or guide me to optimize the opencl kernel.
uint applyAlphaToPixel(uint uPixel, uint uAlpha)
{
uint uColor = uPixel;
uPixel &= 0x00FF00FF;
uPixel = uAlpha;
uPixel += 0x00800080;
uPixel &= 0xFF00FF00;
uPixel >>= 8;
uColor &= 0xFF00FF00;
uColor >>= 8;
uColor = uAlpha;
uColor += 0x00800080;
uColor &= 0xFF00FF00;
uColor |= uPixel;
return uColor;
}
__kernel void alphaBlend_kernel(__global uint pTarget, __global uint pSource, const uint width, const uint height)
{
uint gx = get_global_id(0);
uint gy = get_global_id(1);
if (gx >= width || gy >= height)
return;
uint id = gy * width + gx;
uint tc = pTarget[id];
uint sc = pSource[id];
uint sa = sc >> 24;
if (sa == 0x0) {
pTarget[id] = tc;
} else if (sa == 0xFF) {
pTarget[id] = sc;
} else {
sc = applyAlphaToPixel(sc, sa);
tc = applyAlphaToPixel(tc, (0xFF ^ sa));
pTarget[id] = sc + tc;
}
}