You will have to alter the generated glue class (ScriptC_mono
) and it's base (ScriptC
) at the very least.
<ExtremeHax>
The .bc
file is read and passed down to RenderScript's internals. So far as I can tell, that is done inside ScriptC.internalCreate()
, which is wired to read a raw resource. You need it to instead read your file from a location you control. Possibly you will only need to modify internalCreate()
but there will probably be complications requiring broader editing.
Once you implement RuntimeScriptC
, you should modify ScriptC_mono
to inherit from that base class instead of ScriptC
.
As you noted, you will be very limited in the changes you can make to the rs
code since you cannot modify the glue class at runtime. For example, you could not change the signature of a kernel. However you could take this hack a bit further: if you forgo the glue class, it is possible to make whatever changes you want.
Kernels are invoked in the glue class by index rather than by name, and type/element checks are done inside the glue class. Thus even if you changed the kernel's signature, so long as you knew its index and the types of its in and out allocations, you could still invoke it by using forEach()
directly.
public class ScriptC_mono extends ScriptC {
//...
public void forEach_root(Allocation ain, Allocation aout) {
// check ain
if (!ain.getType().getElement().isCompatible(__U8_4)) {
throw new RSRuntimeException("Type mismatch with U8_4!");
}
// check aout
if (!aout.getType().getElement().isCompatible(__U8_4)) {
throw new RSRuntimeException("Type mismatch with U8_4!");
// Verify dimensions
Type tIn = ain.getType();
Type tOut = aout.getType();
if ((tIn.getCount() != tOut.getCount()) ||
(tIn.getX() != tOut.getX()) ||
(tIn.getY() != tOut.getY()) ||
(tIn.getZ() != tOut.getZ()) ||
(tIn.hasFaces() != tOut.hasFaces()) ||
(tIn.hasMipmaps() != tOut.hasMipmaps())) {
throw new RSRuntimeException("Dimension mismatch between input and output parameters!");
}
forEach(mExportForEachIdx_root, ain, aout, null);
}
}
</ExtremeHax>