Published The results of the experiment on organizing the launch of Linux inside the virtual 3D-space of the multiplayer online game vrchat that allows you to download 3D models with your shader. To implement a conceived idea, an RISC-V architecture emulator, executed on the GPU side as a pixel (fragment) shader (VRCHAT does not support computing shaders and UAV). The code of the emulator is published under the MIT license.
The emulator is based on the implementation in the C language, when creating which, in turn, are used The operation of a minimalist emulator risc-rust developed in the RUST language. The prepared C code is broadcast in pixel shader in the HLSL language suitable for download in Vrchat. The emulator provides full support for the RV32IMASU command set architecture, the SV32 memory control unit and the minimum set of peripheral devices (UART and timer). The prepared features are sufficient to load the kernel of Linux 5.13.5 and the basic environment of the busyBox command line, with which you can interact directly from VRCHAT virtual world.
The emulator is implemented in a shader in the form of its own dynamic texture (Unity Custom Render Texture), supplemented by VRCHAT, UDON scripts provided to control the emulator during its execution. The contents of the RAM and the state of the processor of the emulated system is saved in the form of texture, the size of 2048×2048 pixels. Emulated processor works with a frequency of 250 kHz.
In addition to Linux, the emulator can also be launched Micropython .
To organize constant data storage with read and write support, a trick is used associated with the use of the Camera object affected by the rectangular region generated by a shader, and the output direction of the drawn texture on the shader input. Thus, any pixel recorded in the process of performing a pixel shader. A feature of pixel shaders is that a separate instance of the shader is started in parallel with each pixel.
This feature complicates significantly complicates and requires separate coordination of the state of the entire emulated system and comparing the position of the pixel processed with the CPU coded state or the contents of the EMULABED system encoded (each pixel can encode 128 bits of information). The shader code at the same time requires the inclusion of a huge number of inspections, to simplify the implementation of which the Perl preprocessor perlpp