Skip to content

Commit

Permalink
Update for gfx-rs/wgpu#2496
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili committed Feb 20, 2022
1 parent f215500 commit 4adf819
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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]
Expand Down
7 changes: 5 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```
7 changes: 5 additions & 2 deletions android_debug.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion app-surface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions app-surface/src/app_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ 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) =
pollster::block_on(crate::request_device(&instance, backend, &surface));

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,
Expand Down
2 changes: 1 addition & 1 deletion app-surface/src/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
3 changes: 3 additions & 0 deletions app-surface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ async fn request_device(
request_features |= f;
}
}
// request_features |= wgpu::Features::TEXTURE_COMPRESSION_ASTC_HDR;

let res = adapter
.request_device(
Expand All @@ -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),
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/wgpu_canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 4adf819

Please sign in to comment.