mod common;

use common::{extent_square, make_context};

const RENDER_COLOR_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm;
const RENDER_DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;

#[test]
fn msaa_x4_probe_matches_independent_color_and_depth_query() {
    let ctx = make_context(extent_square(16));
    let probed = ctx.gpu().capabilities().supports_msaa_x4();

    let instance =
        wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle_from_env());
    let Ok(adapter) = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
        power_preference: wgpu::PowerPreference::LowPower,
        force_fallback_adapter: false,
        compatible_surface: None,
    })) else {
        panic!("cross-check adapter request must match the offscreen adapter");
    };
    let color = adapter
        .get_texture_format_features(RENDER_COLOR_FORMAT)
        .flags;
    let depth = adapter
        .get_texture_format_features(RENDER_DEPTH_FORMAT)
        .flags;
    let expected = color.supported_sample_counts().contains(&4)
        && depth.supported_sample_counts().contains(&4);

    assert_eq!(
        probed, expected,
        "supports_msaa_x4 must AND msaa x4 across the color and depth render formats",
    );
}
