Function signature for __attribute__(kernel) function and usage of "OutAllocation"

StackOverflow https://stackoverflow.com/questions/20475311

  •  30-08-2022
  •  | 
  •  

質問

I intend to process RGB data through RenderScript.

For this I've created Allocations in Java and passing them to RS Kernel function as below:

uchar3 __attribute__((kernel)) invert(uchar3 v_in, uint32_t v_out) {
v_in.r = ...;
v_in.g = ...;
v_in.b = ...;
}

However ideally I would like to work on v_out in similar way i.e. setting values for v_out.r, v_out.g and v_out.b. Currently I can not do this with uint32_t v_out.

Now if I define the above RS kernel as:

uchar3 __attribute__((kernel)) invert(uchar3 v_in, uchar3 v_out) {
...
}

I get below compile time error: error: Unexpected kernel invert() parameter 'v_out' of type 'uchar3 *'

Please suggest how to resolve this.

Compile time:

error: Unexpected kernel invert() parameter 'v_out' of type 'uchar3 *'
役に立ちましたか?

解決

you should be defining this as

uchar3 __attribute__((kernel)) invert(uchar3 in);

that function will then be reflected as ScriptC_.forEach_invert(Allocation in, Allocation out). each element in in will be passed to invert, and each value returned from invert will be written to the corresponding location in out.

他のヒント

Define your own local variable of uchar3 type and then populate it before returning it:

uchar3 __attribute__((kernel)) invert(uchar3 in) {
    uchar3 out;
    out.r = ...
    out.g = ...
    out.b = ...
    return out;
}

The compiler is clever enough to notice what you are doing, so there won't be additional copies made of the output items.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top