Skip to content

Instantly share code, notes, and snippets.

@dnevera
Last active May 19, 2018 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnevera/4016b9f608e137b04ea43e0f47e6d4c3 to your computer and use it in GitHub Desktop.
Save dnevera/4016b9f608e137b04ea43e0f47e6d4c3 to your computer and use it in GitHub Desktop.
//
// Ядро чтения семплов текстуры с точностью до индекса и вычисление среднего значения цвета областей с центрами
// в пространстве RGB
//
kernel void get_patchColors(
// исходная текстура
metal::texture2d<float, metal::access::sample> source [[texture(0)]],
// список центров в которых нужно проситать семплы
device float2 *centers [[ buffer(0) ]],
// список усредненных цветов областей в которых мы прочитаем тектсуру
device float3 *colors [[ buffer(1) ]],
// размер квадратной области
constant float &regionSize [[ buffer(2) ]],
// позиция треда GPU в гриде == индекс центра области
uint2 tid [[thread_position_in_grid]]
)
{
uint width = source.get_width();
uint height = source.get_height();
float2 size = float2(width,height);
float2 point = centers[tid.x];
int rs = -regionSize/2;
int re = regionSize/2+1;
uint2 gid = uint2(float2(point.x,point.y) * size);
colors[tid.x] = avrgColor(rs, re, rs, re, gid, source);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment