Giter Site home page Giter Site logo

pimaker / rvc Goto Github PK

View Code? Open in Web Editor NEW
709.0 12.0 22.0 74.91 MB

A 32-bit RISC-V emulator in a shader (and C)

Home Page: https://blog.pimaker.at/texts/rvc1/

License: MIT License

Makefile 62.47% Rust 0.77% C 11.39% Perl 0.81% Shell 5.73% C# 0.46% ShaderLab 0.31% HLSL 0.56% Pascal 0.37% OpenEdge ABL 0.01% Puppet 0.27% Assembly 0.05% Arc 0.06% Tcl 0.17% Batchfile 0.29% Forth 0.03% CSS 0.21% HTML 15.87% JavaScript 0.10% M4 0.05%
vrchat risc-v unity shader hlsl

rvc's Introduction

rvc - risc v in c / HLSL

An experimental 32-bit [0] RISC-V emulator written in plain C [1], with a focus on porting the result to a HLSL pixel shader.

The resulting HLSL (Unity CG) can be found in _Nix/, read on to learn more.

A version of this shader running in VRChat can be found in this world:
https://vrchat.com/home/world/wrld_8126d9ef-eba5-4d49-9867-9e3c4f0b290d

The C version was initially based on takahirox/riscv-rust (see for example instruction decoder generation using instructions.txt and parse_ins.pl), which is a great resource for learning about RISC-V in general, aside from the official specs of course.

Linux running in VRChat

[0] GPUs only really support 32-bit integer math (in the use-case I want to put this in anyway)
[1] The elf loader ('elfy') is written in Rust, because I was too lazy to do it myself in C (Rust uses the 'elf' crate) and it doesn't need porting anyway.

Cloning this repository

This repo makes heavy use of submodules, so make sure to use git clone --recursive on initial cloning (may take a long time) and run git submodule update --recursive after a new pull.

To build any of the code included, you will probably need the following:

  • A C compiler (gcc, clang)
  • A rust compiler
  • Perl 5
  • A device tree compiler (dtc)

C version specifics

Pay no mind to the somewhat weird style of C please, it is mostly because of the need to port to HLSL.

To build, remove the 'rvc' binary and 'src/main.o', then run 'make rvc' from the top level directory.

To run the riscv-tests, use test.sh. test.sh all --clean can be used to run the full supported test suite.

Shader specifics

The shader version is a direct port of the C one. It can be found as part of a Unity project in _Nix/.

This is not a drag-and-drop prefab by any means, it will require careful setup and integration into a world to be useful.

The biggest pitfall is probably the required Perl support. The shader code uses perlpp and a valid runtime environment (I recommend Strawberry Perl for Windows). See the file AutoImport.cs for more information, you will need to set a valid path in there. Technically, the already created *.h files can be used as-is, but you won't be able to meaningfully change any code without it.

The approach uses a Custom Render Texture and some (really messy) VRChat Udon scripts to manage the emulator during runtime. They will probably require fixing up for use in your own world.

The NixDebug.cs (Udon) script needs to be placed on a camera pointing at a camera loop reading in from the 'display' shader. This provides a translation layer between the 128bit-per-pixel integer texture used in the CRT and the Color(float, float, float, float) struct available in Unity/C#.

NixControl.cs is built with support for my Dial prefab in mind, but can be changed to support any other control input too of course.

Build instructions (for the various subprojects/payloads)

Toolchain/Initramfs

For both the target toolchain (riscv32-gnu-linux-) and the initramfs, buildroot is used - this is not a submodule, but an extracted and slightly modified version instead.

To build, run make buildroot-2022.02.1/build.marker in the top level directory. The toolchain will be made in buildroot-2022.02.1/output/host and the rootfs in buildroot-2022.02.1/output/images. This will take a long time.

Micropython

Enter the 'mprv' subdirectory. Run 'make'. Requires the toolchain to be built.

bare_metal_test

Enter the 'bare_metal_test' subdirectory. Run 'make'. Requires the toolchain to be built.

toimg

This tool is responsible for converting binary images (not ELF!) into texture files you can import into Unity, which can then be run by the shader version.

Enter the 'toimg' subdirectory. Run cargo build --release. Use ./target/release/toimg <binary> 2048 2048 to create an image file. The second '2048' specifies the height, which may be smaller than '2048'. On the first run, the program will display the optimal size to give for running a second time. This is not necessary, but will produce smaller images.

rust_payload

This is a test payload written in rust. It demonstrates the ability to run rust code natively on the emulator (both C and shader version). Build by running make rust_payload.bin in the top-level directory.

NOTE: This requires a custom rust toolchain, as the default one does not have a 'rv32ima' target, only 'rv32imac' which is not supported. A demonstrative patch for rustc can be found in rust-target-rv32ima.patch.

linux

To build the linux payload, run make linux_payload.bin in the top level directory. This requires the toolchain and initramfs to be built.

Note that this uses a custom fork of the linux kernel that includes some custom rvc-specific patches. See the forked repo: https://github.com/pimaker/linux-rvc

Why?

Because.

License

MIT. See LICENSE for more.

rvc's People

Contributors

pimaker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rvc's Issues

VRC world does not work in proton

VRChat freezes completely when running through proton as soon as the speed is changed or something is loaded

Make the shader work when converted to vulkan smh

Submodule failed to init - 'rust_raytrace/rust-raytracer-weekend'

>> git submodule
 0bd94b14f8b6b838bbd48e5c204e819df621e659 linux (v5.17-2542-g0bd94b14f8b6)
 44818d1a35315c4dde34050eb0aac98866f9eb15 mprv/micropython (v1.16-222-g44818d1a3)
 7aa6c9aa96049b741b754b7340ea96a37719de27 opensbi (v0.9-134-g7aa6c9a)
 7d1a0e3153c37cd180be9e95f331f32c225d9257 riscv-opcodes (remotes/origin/riscv-bitmanip-33-g7d1a0e3)
 8ee69d7a5dc7ef6d8b2bda96bf86d2923f2cf176 riscv-rust (0.2.2-70-g8ee69d7)
 1b2c3ea84a7f8d8a833fca4d2b9aebb7d1ba4269 riscv-tests (remotes/origin/hw_watchpoint-128-g1b2c3ea)
 85e04d1edb1e35d2e59a791f5246dfec33982305 riscv32_belugafatal: no submodule mapping found in .gitmodules for path 'rust_raytrace/rust-raytracer-weekend'
 (heads/master)

A submodule failed to recursive clone and also fails on recursive initialization. Is the submodule the repo below?:

https://github.com/mwcz/rust-raytracer-weekend

Buildroot

When I tried running make on buildroot after copying its config file, I was getting the following error:

cp: cannot stat 'riscv32_beluga/riscvbin/ar/libc.a'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.