GPGPU
..
573:536
07/04/23 18:28:24
あー、載せるの忘れてた。CPU版のソースはこんな感じ。これをGPUのサンプルのtransform()と入れ替えて辻褄合わせた。
#でも、CUDAではgetData()相当で単純に整数化しないでニアレストネイバーか何かでサンプリングしているのでその分更に差が開く……
static float getData(float * data, float x, float y, int width, int height)
{
int ix = static_cast<int>((x + 1) * width + 0.5f);
int iy = static_cast<int>((y + 1) * height + 0.5f);
ix %= width;
iy %= height;
return data[iy * width + ix];
}
void transform(float * rdata, float* g_odata, int width, int height, float theta)
{
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
float u = x / (float) width;
float v = y / (float) height;
u -= 0.5f;
v -= 0.5f;
float tu = u*cosf(theta) - v*sinf(theta) + 0.5f;
float tv = v*cosf(theta) + u*sinf(theta) + 0.5f;
rdata[y*width + x] = getData(g_odata, tu, tv, width, height);
}
}
}
このコード、Celeron1.2GHzでは109msだった。
次ページ続きを表示1を表示最新レス表示スレッドの検索類似スレ一覧話題のニュースおまかせリスト▼オプションを表示暇つぶし2ch
4962日前に更新/200 KB
担当:undef