Skip to content

Commit

Permalink
Port to UEFI
Browse files Browse the repository at this point in the history
  • Loading branch information
TrAyZeN committed Jun 9, 2024
1 parent a461cc9 commit 277b75c
Show file tree
Hide file tree
Showing 34 changed files with 608 additions and 56 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ tags
# Results
/*.png
/*.jpg

# UEFI
*.fd
/esp
109 changes: 106 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ name = "crab-rt"
version = "0.1.0"
authors = ["TrAyZeN <[email protected]>"]
edition = "2021"
default-run = "crab-rt"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = []

[profile.dev]
opt-level = 2
debug-assertions = true
Expand All @@ -20,10 +18,24 @@ codegen-units = 1
debug-assertions = false
debug = 1 # For profiling

[[bin]]
name = "uefi"
test = false
bench = false
required-features = ["uefi"]

[features]
default = ["std"]
std = ["dep:image", "rand/default", "dep:core_affinity"]
uefi = ["dep:uefi", "dep:core_maths", "dep:log"]

[dependencies]
image = { version = "0.24.7", default-features = false, features = ["jpeg", "jpeg_rayon"] }
rand = { version = "0.8.5", features = ["small_rng"] }
core_affinity = "0.8.1"
image = { version = "0.24.7", default-features = false, features = ["jpeg", "jpeg_rayon"], optional = true }
rand = { version = "0.8.5", default-features = false, features = ["small_rng"] }
core_affinity = { version = "0.8.1", optional = true }
uefi = { version = "0.28.0", features = ["alloc", "global_allocator", "logger", "panic_handler"], optional = true }
core_maths = { version = "0.1.0", optional = true }
log = { version = "0.4.21", optional = true }

[dev-dependencies]
criterion = "0.4"
Expand Down
47 changes: 35 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@
> A toy raytracer written in Rust following
[The Ray Tracing in One Weekend series of books](https://raytracing.github.io/).

## To do
- Finish implementing *Ray Tracing The Next Week*
- SIMD

## Images
<div align="center">
<img src="assets/scene.png">
<img src="assets/rt_weekend.png">
<img src="assets/light.png">
<img src="assets/cornell_box.png">
</div>

## Usage
```sh
cargo run --release
Expand All @@ -27,3 +15,38 @@ cargo run --release
cargo run --release --example rt_weekend
cargo run --release --example rt_nextweek
```

## UEFI
crab-rt features a UEFI port in `src/bin/uefi.rs`. To build it run the following
command:
```sh
cargo build --target x86_64-unknown-uefi --no-default-features --features=uefi --release --bin uefi
```

To run it under QEMU:
```sh
mkdir -p esp/efi/boot
cp target/x86_64-unknown-uefi/release/uefi.efi esp/efi/boot/bootx64.efi

cp /usr/share/ovmf/x64/OVMF_CODE.fd .
cp /usr/share/ovmf/x64/OVMF_VARS.fd .

qemu-system-x86_64 --enable-kvm \
-nodefaults \
-device virtio-rng-pci \
-machine q35 \
-smp 4 \
-m 256M \
-vga std \
-drive if=pflash,format=raw,readonly=on,file=OVMF_CODE.fd \
-drive if=pflash,format=raw,readonly=on,file=OVMF_VARS.fd \
-drive format=raw,file=fat:rw:esp
```

## Image gallery
<div align="center">
<img src="assets/scene.png">
<img src="assets/rt_weekend.png">
<img src="assets/light.png">
<img src="assets/cornell_box.png">
</div>
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "nightly"
targets = ["x86_64-unknown-uefi"]
2 changes: 1 addition & 1 deletion src/aabb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::mem;
use core::mem;

use crate::ray::Ray;
use crate::vec::Vec3;
Expand Down
Loading

0 comments on commit 277b75c

Please sign in to comment.