Metal计算 – 像素依赖于其他像素的颜色

huangapple go评论93阅读模式
英文:

Metal compute- pixels dependent on other pixels colour

问题

我最近开始学习Metal框架,这样我就可以为我的Swift应用程序编写一些滤镜。
我即将编写一个Metal核心,根据误差扩散抖动来抖动图片。
每个像素都被赋予一种颜色,然后根据原始像素的颜色将值分配给相邻的像素。这些值在整个图像上分布,因为每个像素都是计算的,所以所有像素都彼此依赖。
示例将是Floyd Steinberg抖动。

由于Metal处理线程的方式,这种抖动方法不起作用。在抖动图像时,像素只能按顺序从第一个计算到最后一个。
是否可能有一个不涉及线程的核心,或者一种选择整个图像数组由单个线程计算的方法?

英文:

I have recently started to learn the metal framework so I can write some filters for my swift app.
I am about to write a metal kernel that dithers a picture based on error diffusion dithering.
Each pixel is given a Color and then values are distributed to neighbouring pixels based on the original pixels Color. The values are spread out over the whole image as each pixel is calculated so all the pixels are dependent on each other.
The example will be a Floyd stein berg dither.

With the way metal deals with threading this dithering method won’t work. When dithering an image the pixels can only be computed in order from first to last.
Is it possible to have a kernel that doesn’t involve threading, or a way to select the whole image array to be computed by a single thread?

答案1

得分: 0

No, GPU计算不能这样做,因为GPU方法隐式并行。这意味着一个结果不能依赖于所有其他结果。您可以尝试将计算分解成阶段,以便逐个阶段可以并行进行。不过这取决于您的计算逻辑。如果您只想在GPU上使用“一个线程”,那么直接在CPU上进行计算可能会更快。如果您有兴趣,我写了一种方法,您可能想阅读一下Rice解压缩与Metal。这种方法对解压缩任务进行块状分割。

英文:

In short No, you cannot do that with GPU computing as the GPU approach is implicitly parallel. That means one result cannot depend on all the other results. What you could try is breaking down the computation into stages, so that one stage at a time can be done in parallel. It depends on what you computation logic does though. If you only want to use "one thread" on the GPU then it would likely be faster to just do the computations on the CPU instead. If you are interested, I wrote up an approach that you might want to read about Rice decompression with Metal. This approach does block by block segmentation of a decompression task.

huangapple
  • 本文由 发表于 2020年1月3日 23:57:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/59581584.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定