I have three Renderscript functions (in three separate RS files) that used to work great on Adroid 4.1.x phones. However, after I upgraded to ADK 18, they started having runtime errors, crashing on the same phones. The errors are like this:
V/RenderScript( 3644): rsContextCreate dev=0x5a2f0fc0
V/RenderScript( 3644): 0x40051010 Launching thread(s), CPUs 0
V/ScriptC ( 3644): Create script for resource = levels
E/bcc ( 3644): CPU is krait2
E/bcc ( 3644): Cache dependency levels sha1 mismatch:
E/bcc ( 3644): given: 4144ab455aa71df31932ff5baf15583cf1775d72
E/bcc ( 3644): cached: d2ab2c2b568810d8ca0c39d730cb2494cae89106
V/ScriptC ( 3644): Create script for resource = sepia
E/bcc ( 3644): Cache dependency sepia sha1 mismatch:
E/bcc ( 3644): given: 6b15396c900dd23c700b8c13e7d5019fb72fcb0e
E/bcc ( 3644): cached: 8d011a42147f8d3895db549e0b3fe4a43ed49fe2
V/ScriptC ( 3644): Create script for resource = flip
E/bcinfo ( 3644): Could not parse bitcode file
E/bcinfo ( 3644): Invalid SWITCH record
E/RenderScript( 3644): bcinfo: failed to read script metadata
W/dalvikvm( 3644): threadid=1: thread exiting with uncaught exception (group=0x410f4498)
E/AndroidRuntime( 3644): FATAL EXCEPTION: main
It is worth noting that on 4.2.x and newer devices, the Renderscript functions still work.
In the "project.properties" file, I tried sdk.buildtools = 17.0.0, 18.0.1, 18.1.0, 18.1.1, and 19.0.0. None of them worked on 4.1.x phones, though the error message changed slightly with 19.0.0. I googled the error message "failed to read script metadata". Apparently it was added by Stephen Hines. I don't really understand Stephen's changes, so I'd like to ask the following questions:
The flip.rs that's causing the crash is listed below. Suggestions and comments are welcome. Thanks!
#pragma version(1)
#pragma rs java_package_name(com.xxxx.yyyy.zzzz)
#include "rs_time.rsh"
rs_script flipScript;
rs_allocation gIn;
rs_allocation gOut;
int width;
int height;
int direction = 0;
void root(const uchar4 *v_in, uchar4 *v_out, const void *usrData, uint32_t x, uint32_t y) {
if(direction == 0) { // flip horizontally
const uchar4 *element = rsGetElementAt(gIn, width - x, y);
float4 color = rsUnpackColor8888(*element);
float4 output = {color.r, color.g, color.b};
*v_out = rsPackColorTo8888(output);
}
else if(direction == 1) { // flip vertically
const uchar4 *element = rsGetElementAt(gIn, x, height - y);
float4 color = rsUnpackColor8888(*element);
float4 output = {color.r, color.g, color.b};
*v_out = rsPackColorTo8888(output);
}
else if(direction == 2) { // rotate left
const uchar4 *element = rsGetElementAt(gIn, width - y, x);
float4 color = rsUnpackColor8888(*element);
float4 output = {color.r, color.g, color.b};
*v_out = rsPackColorTo8888(output);
}
else if(direction == 3) { // rotate right
const uchar4 *element = rsGetElementAt(gIn, y, height - x);
float4 color = rsUnpackColor8888(*element);
float4 output = {color.r, color.g, color.b};
*v_out = rsPackColorTo8888(output);
}
}
void flip(int testIdx) {
int64_t t0, t1;
int64_t t;
t0 = rsUptimeNanos();
rsForEach(flipScript, gIn, gOut);
t1 = rsUptimeNanos();
t = t1 - t0;
rsDebug(" flip: timer on RS side: ", t);
timeNanoSec[testIdx] = (float)t;
}
What target API are you compiling for? Can you send me an apk or at least the 3 failing .bc files?
This looks like a bitcode encoding issue for only v16 (JellyBean) devices. It has nothing to do with the changelist you mentioned, but actually has to do with coalescing of ranged values in a switch statement. It is a bug in the compiler frontend, llvm-rs-cc. Libbcc (the on-device compiler) is rightfully rejecting the bad bitcode that a v16 device can't read (namely, the coalesced case ranges). I will file a bug to fix this internally and hopefully get it released in a future SDK update. In the meantime, I suggest you make use of the RenderScript support library, which would bypass this particular bug (since it won't generate v16 bitcode).