Renderscript,什么是'in`参数? [英] Renderscript, what is the `in` parameter?

查看:112
本文介绍了Renderscript,什么是'in`参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解Renderscript。可能有人来看看这个code,让我知道了什么参数是什么?它不是一个分配对象,所以它是Ele​​ment?为什么是一个数组呢?

I am trying to understand Renderscript. Could somebody have a look at this code, and let me know what the in parameter is ? It is not an Allocation object, so it is an Element? Why is it an array then?

(我从这里code和修改了它,的 http://www.jayway.com/2014/02/11/renderscript-on-android-basics/

(I got the code from here, and modified it, http://www.jayway.com/2014/02/11/renderscript-on-android-basics/)

#pragma version(1)
#pragma rs java_package_name(foo.bar)

rs_allocation inPixels;
int height;
int width;

void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
    float3 pixel = convert_float4(in[0]).rgb;

    pixel.r = (pixel.r + pixel.g + pixel.b)/3;
    pixel.g = (pixel.r + pixel.g + pixel.b)/3;
    pixel.b = (pixel.r + pixel.g + pixel.b)/3;

    int topRight
    //float4 f4 = rsUnpackColor8888(*(uchar*)rsGetElementAt(inPixels, x+1, y+1));

    out->xyz = convert_uchar3(pixel);
}

这是什么行 convert_float4(在[0])吗?
该指数0点什么呢?第一像素?所以,如果我想进入下一个像素,我应该增加一个?

What does this line convert_float4(in[0]) do? The index 0 point to what ? The first pixel? So if I want to access the next pixel I should increase that by one?

推荐答案

uchar4 FLOAT3 的类型有着本质和你一样OpenCL中找到。它们是含4和3的组件,分别矢量值。在 convert_float4() convert_uchar3()函数由Renderscript提供做不同类型之间的正确,快速的转换。

The uchar4 and float3 types are essentially the same as what you find in OpenCL. They are vector values containing 4 and 3 components, respectively. The convert_float4() and convert_uchar3() functions are provided by Renderscript to do correct, fast conversion between the different types.

参数本质上是一个指向该内核运行当前元素。在 X 值告诉你到底是哪元素中你的分配对应。你不应该尝试使用它作为一个数组和直接访问其他元素。如果你这样做,你可能在你的进程无法访问触摸存储器。 Renderscript是并行处理的数据集,其可以在不同的线程或不同的处理器(GPU)来完成。这取决于硬件实现

The in parameter is essentially a pointer to the current element in which your kernel is operating. The x and y values tell you exactly which Element within your Allocation the in corresponds. You should not attempt to use it as an array and directly access other elements. If you do, you risk touching memory in which your process does not have access. Renderscript is processing your dataset in parallel, which may be done on different threads or a different processor (GPU). It depends on the hardware implementation.

这篇关于Renderscript,什么是'in`参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆