filterscript文档在哪里(我该如何使用它)?

ete*_*att 14 documentation android renderscript

当Jelly Bean 4.2在一个月前宣布时,Filterscript也宣布了.它似乎是一种语言,是Renderscript的下标,具有不同的文件扩展名.这就是我对语言的全部了解.

我已经阅读了整个互联网上存在的关于Filterscript的两个段落并创建了一个小.fs文件pragma rs_fp_relaxed,但ADT构建器并没有像普通.rs文件在同一位置那样获取它.

我的ADT是最新的公共版本(21.0.0),对于Filterscript来说似乎太低了. tools.android.com似乎有21.0.1预览版,但在发行说明中没有提到Filterscript(事实上它只是一个bug修复版本).在任何地方都没有文档!

我如何使用Filterscript?它的文件在哪里?

我尝试过的:

https://www.google.com/search?q=filterscript+site:android.com&tbs=li:1

http://developer.android.com/about/versions/android-4.2.html#Renderscript

http://developer.android.com/tools/sdk/eclipse-adt.html#notes

http://tools.android.com/recent/2101preview1

ore*_*che 17

我还没有找到任何文档,但也许我可以给你一些有关我迄今为止所调查的内容的有用信息:

  • 指针不可用
  • 内核函数需要该属性,__attribute__((kernel))否则编译器会发疯并且需要指针类型,这是非法的
  • 可以使用Renderscript API(至少我到目前为止所尝试的一切都在工作)
  • 在AndroidManifest.xml中必须将属性"Min SDK version"设置为"17" - >"使用Sdk"

在阅读llvm-rs-cc编译器源代码时,我发现了以下大部分信息.任何进一步的信息或指向Filtercript的真实文档的链接将不胜感激!

产出分配

在Filterscript中,您没有输出分配的参数.而是返回值以在当前位置写入(这是全局线程ID xy):

uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y)
Run Code Online (Sandbox Code Playgroud)

生成:

public void forEach_root(Allocation aout)
Run Code Online (Sandbox Code Playgroud)

输入分配

您可以选择将输入分配作为参数进行切换:

uchar4 __attribute__((kernel)) root(const uchar4 in, uint32_t x, uint32_t y)
Run Code Online (Sandbox Code Playgroud)

生成:

public void forEach_root(Allocation ain, Allocation aout)
Run Code Online (Sandbox Code Playgroud)

这在极少数情况下很有用(例如点运算符),因为您只能在当前位置访问输入分配.

全球分配

如果要在输入分配中进行随机访问,则需要进行全局分配.这是一个使用适合我的全局分配的窗口运算符的小例子.

blur.fs:

#pragma version(1)
#pragma rs java_package_name(com.example.myproject)

rs_allocation in;

uint32_t width;
uint32_t height;

uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
    uint4 sum = 0;
    uint count = 0;
    for (int yi = y-1; yi <= y+1; ++yi) {
        for (int xi = x-1; xi <= x+1; ++xi) {
            if (xi >= 0 && xi < width && yi >= 0 && yi < height) {
                sum += convert_uint4(rsGetElementAt_uchar4(in, xi, yi));
                ++count;
            }
        }
    }
    return convert_uchar4(sum/count);
}
Run Code Online (Sandbox Code Playgroud)

MainActivity.java:

...
mRS = RenderScript.create(this);

mInAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
                    Allocation.MipmapControl.MIPMAP_NONE,
                    Allocation.USAGE_SCRIPT);
mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());

mScript = new ScriptC_blur(mRS, getResources(), R.raw.blur);
mScript.set_in(mInAllocation);
mScript.set_width(mBitmapIn.getWidth());
mScript.set_height(mBitmapIn.getHeight());

mScript.forEach_root(mOutAllocation);

mOutAllocation.copyTo(mBitmapOut);
...
Run Code Online (Sandbox Code Playgroud)

  • 什么时候应该使用FilterScript?它看起来与Renderscript差不多。另外,我认为它甚至在同一文件夹中。 (2认同)

Tim*_*ray 10

在这里做几件事:

  • 是的,我们落后于文档.我们知道,我们一直很忙.这是我不久的将来的议程.

  • FS旨在作为RS的更具限制性的变体,为编译器后端提供额外的优化机会.我们今天的CPU后端中没有任何这些不能从等效的RS文件中获得,但OEM可能会提高其文件与FS文件和通用RS文件的性能.通常,它需要__attribute__((kernel)),没有指针,没有联合,文件类型暗示了fp_relaxed.

  • 主机端API完全相同; 唯一的区别在于我们实际传递的内核二进制文件.

对ofp答案的一些小修正:

  1. 您应该使用rsGetElementAt_(type).它比rsGetElementAt更清晰,因为你不需要进行转换或额外的解除引用或类似的东西.
  2. #pragma fp_relaxed隐含在.fs扩展名中,在FS文件中不是必需的.
  3. 您不必包含rs_allocation.rsh(它也隐含在所有RS/FS文件中).