From 2a0ca001e2fffcf216995a7fbf1724cc0520affe Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sat, 29 Jun 2019 12:39:28 +0900 Subject: [PATCH] Optimized ray stack task duplication with memcopy. --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/ray.rs | 13 ++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc8f7b6..7e4b4ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -100,6 +100,11 @@ dependencies = [ name = "color" version = "0.1.0" +[[package]] +name = "copy_in_place" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "crossbeam" version = "0.3.2" @@ -239,6 +244,7 @@ dependencies = [ "bvh_order 0.1.0", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "color 0.1.0", + "copy_in_place 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "float4 0.1.0", "half 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -557,6 +563,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum copy_in_place 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b792a46b1ef44bb5e9a04721d34e186522431be965a283437107843d62ddbaad" "checksum crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "24ce9782d4d5c53674646a6a4c1863a21a8fc0cb649b3c94dfc16e45071dea19" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" diff --git a/Cargo.toml b/Cargo.toml index 1e51807..14ee2ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ debug = true # Crates.io dependencies base64 = "0.9" clap = "2.30" +copy_in_place = "0.2.0" crossbeam = "0.3" half = "1.0" lazy_static = "1.0" diff --git a/src/ray.rs b/src/ray.rs index 97bdd39..9727522 100644 --- a/src/ray.rs +++ b/src/ray.rs @@ -279,11 +279,18 @@ impl RayStack { let start = task.start_idx; let end = self.lanes[l].end_len; - for i in start..end { - let idx = self.lanes[l].idxs[i]; - self.lanes[l].idxs.push(idx); + // Extend the indices vector + self.lanes[l].idxs.reserve(end - start); + let old_len = self.lanes[l].idxs.len(); + let new_len = old_len + end - start; + unsafe { + self.lanes[l].idxs.set_len(new_len); } + // Copy elements + copy_in_place::copy_in_place(&mut self.lanes[l].idxs, start..end, end); + + // Push the new task onto the stack self.tasks.push(RayTask { lane: l, start_idx: end,