-
Hey all. I'm trying to work on #169 but I'm having some issues reproing the issue. // lib.rs
#![allow(internal_features)]
#![feature(core_intrinsics)]
#![no_std]
use spirv_std::spirv;
#[spirv(compute(threads(1)))]
pub fn bsw() -> i32 {
let number: i32 = -12345678;
core::intrinsics::bswap(number)
} // main.rs
#![allow(internal_features)]
#![feature(core_intrinsics)]
// crate name for testing is bswap
use bswap::bsw;
fn main() {
let result = bsw();
println!("{:08x}", -12345678);
println!("{:08x}", result);
println!("{:08x}", std::intrinsics::bswap(-12345678)); // to see if the spirv version matches calling bswap directly
} Does this properly run the gpu code? The bsw() function has the spirv attribute so I assume that it would, but I'm not getting the issue which makes me think I'm running this code wrong. Are there steps I am missing here? I'm simply getting the output: Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s
Running `target/debug/bswap`
ff439eb2
b29e43ff
b29e43ff Any help would be appreciated, thank you! Though with all of this said, I think that I already know how to fix the issue [just match over (u64, bool) instead of u64 and flip bytes] and have nearly finished and am ready for a PR, but I'd love to be able to test it first. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Ah, I already put up a fix for this! #174. We must have crossed in flight. A couple of things:
|
Beta Was this translation helpful? Give feedback.
-
Ah got it, thanks! I wasn't sure if it still went through the spirv_codegen crate or whatnot when running on the CPU. |
Beta Was this translation helpful? Give feedback.
-
Yeah, so this is super confusing in general and I only really got a hang of it this month. What is happening is that your So your // lib.rs
#![allow(internal_features)]
#![feature(core_intrinsics)]
#![no_std]
pub fn bsw() -> i32 {
let number: i32 = -12345678;
core::intrinsics::bswap(number)
} That is just a standard Rust crate you could write without knowing anything about Rust GPU. When your compiled In order to have code run on the GPU, you have to use |
Beta Was this translation helpful? Give feedback.
Ah, I already put up a fix for this! #174. We must have crossed in flight.
A couple of things:
spirv
annotation goes away and it becomes a normal function. If there is a standardbswap
intrinsic in Rust (looks like there is: https://doc.rust-lang.org/std/intrinsics/fn.bswap.html), it is likely using that.println
in shaders, so if you are printing it is most likely running on CPU. There is adebug_printf!
macro that works on the GPU but that requires you to install the vulkan SDK and enable vulkan layers to see the output (I want to make it better and hook stuff up toprintln
because it sucks from a UX perspective to be non-standard and I refuse…