diff --git a/Android/app/src/main/java/name/jinleili/wgpu/MainActivity.kt b/Android/app/src/main/java/name/jinleili/wgpu/MainActivity.kt index 0e44e9d..4c18daa 100644 --- a/Android/app/src/main/java/name/jinleili/wgpu/MainActivity.kt +++ b/Android/app/src/main/java/name/jinleili/wgpu/MainActivity.kt @@ -41,7 +41,7 @@ var surfaceView: WGPUSurfaceView? = null @Composable fun SurfaceCard() { var selected by remember { mutableStateOf("boids") } - val toggleValues = listOf("boids", "MSAA line", "cube", "water", "shadow") + val toggleValues = listOf("boids", "MSAA line", "cube", "water", "shadow", "HDR ASTC") val screenWidth = LocalConfiguration.current.screenWidthDp.dp Column(modifier = Modifier.fillMaxSize()) { Row( diff --git a/Cargo.lock b/Cargo.lock index e84d06b..fab8e39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1565,7 +1565,7 @@ dependencies = [ [[package]] name = "wgpu" version = "0.12.0" -source = "git+https://github.com/jinleili/wgpu?rev=92d7b257#92d7b257f1a8653455e7fafb04e8ae4adb39858c" +source = "git+https://github.com/jinleili/wgpu?rev=305eadb1#305eadb19b58272674363fbb3c0924e15d30212a" dependencies = [ "arrayvec", "js-sys", @@ -1585,7 +1585,7 @@ dependencies = [ [[package]] name = "wgpu-core" version = "0.12.0" -source = "git+https://github.com/jinleili/wgpu?rev=92d7b257#92d7b257f1a8653455e7fafb04e8ae4adb39858c" +source = "git+https://github.com/jinleili/wgpu?rev=305eadb1#305eadb19b58272674363fbb3c0924e15d30212a" dependencies = [ "arrayvec", "bitflags", @@ -1607,7 +1607,7 @@ dependencies = [ [[package]] name = "wgpu-hal" version = "0.12.0" -source = "git+https://github.com/jinleili/wgpu?rev=92d7b257#92d7b257f1a8653455e7fafb04e8ae4adb39858c" +source = "git+https://github.com/jinleili/wgpu?rev=305eadb1#305eadb19b58272674363fbb3c0924e15d30212a" dependencies = [ "arrayvec", "ash", @@ -1665,7 +1665,7 @@ dependencies = [ [[package]] name = "wgpu-types" version = "0.12.0" -source = "git+https://github.com/jinleili/wgpu?rev=92d7b257#92d7b257f1a8653455e7fafb04e8ae4adb39858c" +source = "git+https://github.com/jinleili/wgpu?rev=305eadb1#305eadb19b58272674363fbb3c0924e15d30212a" dependencies = [ "bitflags", ] diff --git a/Cargo.toml b/Cargo.toml index 47afce3..5ddffe7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["rlib", "staticlib", "cdylib"] [features] angle = ["wgpu/angle"] default = [] +vulkan-portability = ["wgpu/vulkan-portability"] [dependencies] app-surface = {path = "./app-surface"} @@ -20,7 +21,7 @@ noise = {version = "0.7", default-features = false} pollster = "0.2" rand = {version = "0.7.2"} # wgpu = {git = "https://github.com/gfx-rs/wgpu", rev = "6931e571"} -wgpu = {git = "https://github.com/jinleili/wgpu", rev = "92d7b257"} +wgpu = {git = "https://github.com/jinleili/wgpu", rev = "305eadb1"} # wgpu = {path = "../../forks/wgpu/wgpu"} [target.'cfg(any(not(target_os = "ios"), not(target_os = "android")))'.dependencies] diff --git a/README.MD b/README.MD index b345314..0321403 100644 --- a/README.MD +++ b/README.MD @@ -86,8 +86,11 @@ cp target/armv7-linux-androideabi/release/libwgpu_on_app.so android/app/libs/arm ```sh # Use Metal backend. cargo run -# Or, use GL backend, need `Angle` libs on your computer. +# Use GL backend, need `Angle` libs on your computer. # https://github.com/gfx-rs/wgpu/pull/2461 -WGPU_BACKEND=gl cargo run --features=angle +cargo run --features angle +# Use Vulkan backend +# https://github.com/gfx-rs/wgpu/pull/2488 +cargo run --features vulkan-portability # Then, press 0, 1, 2, 3, 4 keys change running example. ``` \ No newline at end of file diff --git a/android_debug.sh b/android_debug.sh index 5db14f7..9ee0239 100755 --- a/android_debug.sh +++ b/android_debug.sh @@ -1,6 +1,9 @@ # build to Android target -RUST_BACKTRACE=1 RUST_LOG=wgpu_hal=debug cargo so b --lib --target aarch64-linux-android -RUST_BACKTRACE=1 RUST_LOG=wgpu_hal=debug cargo so b --lib --target armv7-linux-androideabi +# RUST_LOG=wgpu_hal=debug WGPU_BACKEND=gl cargo so b --features=angle --lib --target aarch64-linux-android +# RUST_LOG=wgpu_hal=debug WGPU_BACKEND=gl cargo so b --features=angle --lib --target armv7-linux-androideabi +RUST_BACKTRACE=full RUST_LOG=wgpu_hal=debug cargo so b --lib --target aarch64-linux-android +RUST_BACKTRACE=full RUST_LOG=wgpu_hal=debug cargo so b --lib --target armv7-linux-androideabi + # copy .so files to jniLibs folder cp target/aarch64-linux-android/debug/libwgpu_on_app.so android/app/libs/arm64-v8a/libwgpu_on_app.so cp target/armv7-linux-androideabi/debug/libwgpu_on_app.so android/app/libs/armeabi-v7a/libwgpu_on_app.so diff --git a/app-surface/Cargo.toml b/app-surface/Cargo.toml index ce4ff4d..0e6fb57 100644 --- a/app-surface/Cargo.toml +++ b/app-surface/Cargo.toml @@ -14,13 +14,18 @@ default = [] log = "0.4" pollster = "0.2" # wgpu = {git = "https://github.com/gfx-rs/wgpu", rev = "6931e571"} -wgpu = {git = "https://github.com/jinleili/wgpu", rev = "92d7b257"} +wgpu = {git = "https://github.com/jinleili/wgpu", rev = "305eadb1"} # wgpu = {path = "../../../forks/wgpu/wgpu"} [target.'cfg(any(not(target_os = "ios"), not(target_os = "android")))'.dependencies] async-executor = "1.0" winit = "0.26" +[target.'cfg(target_os = "macos")'.dependencies] +libc = "*" +objc = "0.2.7" +raw-window-handle = "0.4" + [target.'cfg(target_os = "ios")'.dependencies] core-graphics = "*" env_logger = "0.9" diff --git a/app-surface/src/app_surface.rs b/app-surface/src/app_surface.rs index 17ffd4c..92cb6c2 100644 --- a/app-surface/src/app_surface.rs +++ b/app-surface/src/app_surface.rs @@ -12,8 +12,7 @@ pub struct AppSurface { impl AppSurface { pub fn new(view: winit::window::Window) -> Self { let scale_factor = view.scale_factor(); - let backend = - wgpu::util::backend_bits_from_env().unwrap_or_else(|| wgpu::Backends::PRIMARY); + let backend = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all); let instance = wgpu::Instance::new(backend); let (physical, surface) = unsafe { (view.inner_size(), instance.create_surface(&view)) }; let (_adapter, device, queue) = @@ -21,7 +20,9 @@ impl AppSurface { let config = wgpu::SurfaceConfiguration { usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - format: wgpu::TextureFormat::Bgra8UnormSrgb, + // format: wgpu::TextureFormat::Bgra8UnormSrgb, + format: wgpu::TextureFormat::Rgba16Float, + width: physical.width as u32, height: physical.height as u32, present_mode: wgpu::PresentMode::Fifo, diff --git a/app-surface/src/ios.rs b/app-surface/src/ios.rs index d1b58e0..90ae93f 100644 --- a/app-surface/src/ios.rs +++ b/app-surface/src/ios.rs @@ -33,7 +33,7 @@ impl AppSurface { (s.size.width as f32 * scale_factor) as u32, (s.size.height as f32 * scale_factor) as u32, ); - let backend = wgpu::util::backend_bits_from_env().unwrap_or_else(|| wgpu::Backends::METAL); + let backend = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all); let instance = wgpu::Instance::new(backend); let surface = unsafe { instance.create_surface_from_core_animation_layer(obj.metal_layer) }; let (_adapter, device, queue) = diff --git a/app-surface/src/lib.rs b/app-surface/src/lib.rs index 934e111..c9dabe6 100644 --- a/app-surface/src/lib.rs +++ b/app-surface/src/lib.rs @@ -95,6 +95,7 @@ async fn request_device( request_features |= f; } } + // request_features |= wgpu::Features::TEXTURE_COMPRESSION_ASTC_HDR; let res = adapter .request_device( @@ -108,6 +109,8 @@ async fn request_device( .await; match res { Err(err) => { + log::info!("hdr 1, {:?}", err); + panic!("request_device failed: {:?}", err); } Ok(tuple) => (adapter, tuple.0, tuple.1), diff --git a/iOS/wgpu_on_iOS.xcodeproj/project.xcworkspace/xcuserdata/LiJinlei.xcuserdatad/UserInterfaceState.xcuserstate b/iOS/wgpu_on_iOS.xcodeproj/project.xcworkspace/xcuserdata/LiJinlei.xcuserdatad/UserInterfaceState.xcuserstate index 9106250..3f7d022 100644 Binary files a/iOS/wgpu_on_iOS.xcodeproj/project.xcworkspace/xcuserdata/LiJinlei.xcuserdatad/UserInterfaceState.xcuserstate and b/iOS/wgpu_on_iOS.xcodeproj/project.xcworkspace/xcuserdata/LiJinlei.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/src/android.rs b/src/android.rs index dbd9636..009eba4 100644 --- a/src/android.rs +++ b/src/android.rs @@ -10,7 +10,7 @@ use log::{info, Level}; #[no_mangle] #[jni_fn("name.jinleili.wgpu.RustBridge")] pub unsafe fn createWgpuCanvas(env: *mut JNIEnv, _: JClass, surface: jobject, idx: jint) -> jlong { - android_logger::init_once(Config::default().with_min_level(Level::Info)); + android_logger::init_once(Config::default().with_min_level(Level::Trace)); let canvas = WgpuCanvas::new(AppSurface::new(env as *mut _, surface), idx as i32); info!("WgpuCanvas created!"); Box::into_raw(Box::new(canvas)) as jlong diff --git a/src/main.rs b/src/main.rs index f8dc7c4..e84b4c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ fn main() { .with_title("wgpu on Desktop"); let window = builder.build(&events_loop).unwrap(); - let mut canvas = WgpuCanvas::new(AppSurface::new(window), 2_i32); + let mut canvas = WgpuCanvas::new(AppSurface::new(window), 0_i32); let mut last_update_inst = Instant::now(); let target_frametime = Duration::from_secs_f64(1.0 / 60.0); diff --git a/src/wgpu_canvas.rs b/src/wgpu_canvas.rs index 6e92b71..53ac051 100644 --- a/src/wgpu_canvas.rs +++ b/src/wgpu_canvas.rs @@ -9,12 +9,14 @@ pub struct WgpuCanvas { #[allow(dead_code)] impl WgpuCanvas { pub fn new(app_surface: AppSurface, _idx: i32) -> Self { - let example = Box::new(Boids::new(&app_surface)); + let example = Box::new(Water::new(&app_surface)); + // let hdr_view = HDRImageView::new(&mutapp_surface); log::info!("example created"); - let instance = WgpuCanvas { + let mut instance = WgpuCanvas { app_surface, example, }; + // instance.change_example(5); if let Some(callback) = instance.app_surface.callback_to_app { callback(0); }