Skip to content

Commit

Permalink
Test MSAA on Android: gfx-rs/wgpu#3429
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili committed Jan 28, 2023
1 parent c5257b1 commit 8db09d7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ hal = { git = "https://github.com/gfx-rs/wgpu", package = "wgpu-hal", version =

# wgpu = { path = "../../forks/wgpu/wgpu" }
# hal = { package = "wgpu-hal", path = "../../forks/wgpu/wgpu-hal" }
# wgpu = { path = "../../forks/wgpu-i509VCB/wgpu" }
# hal = { package = "wgpu-hal", path = "../../forks/wgpu-i509VCB/wgpu-hal" }

async-executor = "1.0"
winit = "0.27.1"
Expand Down
1 change: 1 addition & 0 deletions wgpu-in-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ libc.workspace = true
android_logger.workspace = true
jni.workspace = true
jni_fn.workspace = true
log-panics = "*"


[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
23 changes: 21 additions & 2 deletions wgpu-in-app/src/examples/msaa_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,29 @@ pub struct MSAALine {
}

impl MSAALine {
pub fn new(app_surface: &AppSurface) -> Self {
pub fn new(app_surface: &mut AppSurface) -> Self {
// Only srgb format can show real MSAA effect on metal backend.
let msaa_format = app_surface.config.format.add_srgb_suffix();
app_surface.sdq.update_config_format(msaa_format);

let config = &app_surface.config;
let device = &app_surface.device;
let sample_count = 4;

let sample_flags = app_surface
.adapter
.get_texture_format_features(config.format)
.flags;
let sample_count = {
if sample_flags.contains(wgpu::TextureFormatFeatureFlags::MULTISAMPLE_X8) {
8
} else if sample_flags.contains(wgpu::TextureFormatFeatureFlags::MULTISAMPLE_X4) {
4
} else if sample_flags.contains(wgpu::TextureFormatFeatureFlags::MULTISAMPLE_X2) {
2
} else {
1
}
};

let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
Expand Down
1 change: 1 addition & 0 deletions wgpu-in-app/src/ffi/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use log::{info, Level};
#[no_mangle]
#[jni_fn("name.jinleili.wgpu.RustBridge")]
pub fn createWgpuCanvas(env: *mut JNIEnv, _: JClass, surface: jobject, idx: jint) -> jlong {
log_panics::init();
android_logger::init_once(Config::default().with_min_level(Level::Info));
let canvas = WgpuCanvas::new(AppSurface::new(env as *mut _, surface), idx as i32);
info!("WgpuCanvas created!");
Expand Down
2 changes: 1 addition & 1 deletion wgpu-in-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {
let window = builder.build(&events_loop).unwrap();

let app_view = pollster::block_on(AppSurface::new(window));
let mut canvas = WgpuCanvas::new(app_view, 3);
let mut canvas = WgpuCanvas::new(app_view, 0);

let mut last_update_inst = Instant::now();
let target_frametime = Duration::from_secs_f64(1.0 / 60.0);
Expand Down

0 comments on commit 8db09d7

Please sign in to comment.