Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BGL Deduplication Index Test #4914

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 58 additions & 18 deletions tests/tests/bind_group_layout_dedup.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
use wgpu_test::{gpu_test, GpuTestConfiguration};
use wgpu_test::{gpu_test, GpuTestConfiguration, TestingContext};

#[gpu_test]
static BIND_GROUP_LAYOUT_DEDUPLICATION: GpuTestConfiguration = GpuTestConfiguration::new()
.run_sync(|ctx| {
let entries_1 = &[];

let entries_2 = &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStages::VERTEX,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: None,
},
count: None,
}];

static BIND_GROUP_LAYOUT_DEDUPLICATION: GpuTestConfiguration =
GpuTestConfiguration::new().run_sync(bgl_dedupe);

fn bgl_dedupe(ctx: TestingContext) {
let entries_1 = &[];

let entries_2 = &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStages::VERTEX,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: None,
},
count: None,
}];

// Block so we can force all resource to die.
{
let bgl_1a = ctx
.device
.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
entries: entries_1,
});

let _bgl_2 = ctx
let bgl_2 = ctx
.device
.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
Expand Down Expand Up @@ -135,7 +139,43 @@ static BIND_GROUP_LAYOUT_DEDUPLICATION: GpuTestConfiguration = GpuTestConfigurat
}

ctx.queue.submit(Some(encoder.finish()));
});

// Abuse the fact that global_id is really just the bitpacked ids when targeting wgpu-core.
if ctx.adapter_info.backend != wgt::Backend::BrowserWebGpu {
let bgl_1a_idx = bgl_1a.global_id().inner() & 0xFFFF_FFFF;
assert_eq!(bgl_1a_idx, 0);
let bgl_2_idx = bgl_2.global_id().inner() & 0xFFFF_FFFF;
assert_eq!(bgl_2_idx, 1);
let bgl_1b_idx = bgl_1b.global_id().inner() & 0xFFFF_FFFF;
assert_eq!(bgl_1b_idx, 2);
}
}

ctx.device.poll(wgpu::Maintain::Wait);

if ctx.adapter_info.backend != wgt::Backend::BrowserWebGpu {
// Now all of the BGL ids should be dead, so we should get the same ids again.
for i in 0..=2 {
let test_bgl = ctx
.device
.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
entries: entries_1,
});

let test_bgl_idx = test_bgl.global_id().inner() & 0xFFFF_FFFF;

// https://github.com/gfx-rs/wgpu/issues/4912
//
// ID 2 is the deduplicated ID, which is never properly recycled.
if i == 2 {
assert_eq!(test_bgl_idx, 3);
} else {
assert_eq!(test_bgl_idx, i);
}
}
}
}

const SHADER_SRC: &str = "
@vertex fn vs_main() -> @builtin(position) vec4<f32> { return vec4<f32>(1.0); }
Expand Down
Loading