Compiling renderscript code at runtime

I was wondering if it is possible to write / modify renderscript code when an Android application is running. My main goal is to create an application in which users can learn to work with renderscript without any knowledge of Java. The basic layout of the application will consist of input and output images with the ability to enter code. The main functionality of this application is already working, and this is an image of the interface. App layout

It would be useful to check the renderscript code with direct feedback from the application.

I already did some research on the assembly process and came up with the following idea:

The main "template" of the renderscript file with the necessary global variables, such as inputs and outputs.

java- script Java script. .rs .

, .rs , llvm-rs-cc, . .bc .bc . , java-.

, , , .bc apk res/raw, . .bc .

( ) renderscript ?

: github. ,

+4
1

(ScriptC_mono) (ScriptC) .

<ExtremeHax>

.bc RenderScript. , ScriptC.internalCreate(), . , . , internalCreate(), , , , .

RuntimeScriptC, ScriptC_mono ScriptC.

, , rs, . , . : , , .

, , / . , , , , , forEach() .

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>

+2

Source: https://habr.com/ru/post/1533345/


All Articles