Skip to content

Commit c505493

Browse files
committed
Texture Bindless Test
1 parent 3bbc1b7 commit c505493

File tree

5 files changed

+294
-80
lines changed

5 files changed

+294
-80
lines changed

tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ctor.workspace = true
3434
futures-lite.workspace = true
3535
glam.workspace = true
3636
itertools.workspace = true
37+
image.workspace = true
3738
libtest-mimic.workspace = true
3839
log.workspace = true
3940
parking_lot.workspace = true

tests/tests/binding_array/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
mod partially_bounded_arrays;
2+
mod textures;
Lines changed: 80 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::num::NonZeroU32;
22

3-
use wgpu_test::{gpu_test, image::ReadbackBuffers, GpuTestConfiguration, TestParameters};
3+
use wgpu_test::{
4+
gpu_test, image::ReadbackBuffers, GpuTestConfiguration, TestParameters, TestingContext,
5+
};
46

57
#[gpu_test]
68
static PARTIALLY_BOUNDED_ARRAY: GpuTestConfiguration = GpuTestConfiguration::new()
@@ -14,90 +16,92 @@ static PARTIALLY_BOUNDED_ARRAY: GpuTestConfiguration = GpuTestConfiguration::new
1416
)
1517
.limits(wgpu::Limits::downlevel_defaults()),
1618
)
17-
.run_async(|ctx| async move {
18-
let device = &ctx.device;
19+
.run_async(partially_bounded_arrays);
1920

20-
let texture_extent = wgpu::Extent3d {
21-
width: 1,
22-
height: 1,
23-
depth_or_array_layers: 1,
24-
};
25-
let storage_texture = device.create_texture(&wgpu::TextureDescriptor {
26-
label: None,
27-
size: texture_extent,
28-
mip_level_count: 1,
29-
sample_count: 1,
30-
dimension: wgpu::TextureDimension::D2,
31-
format: wgpu::TextureFormat::Rgba32Float,
32-
usage: wgpu::TextureUsages::TEXTURE_BINDING
33-
| wgpu::TextureUsages::COPY_DST
34-
| wgpu::TextureUsages::STORAGE_BINDING
35-
| wgpu::TextureUsages::COPY_SRC,
36-
view_formats: &[],
37-
});
21+
async fn partially_bounded_arrays(ctx: TestingContext) {
22+
let device = &ctx.device;
3823

39-
let texture_view = storage_texture.create_view(&wgpu::TextureViewDescriptor::default());
24+
let texture_extent = wgpu::Extent3d {
25+
width: 1,
26+
height: 1,
27+
depth_or_array_layers: 1,
28+
};
29+
let storage_texture = device.create_texture(&wgpu::TextureDescriptor {
30+
label: None,
31+
size: texture_extent,
32+
mip_level_count: 1,
33+
sample_count: 1,
34+
dimension: wgpu::TextureDimension::D2,
35+
format: wgpu::TextureFormat::Rgba32Float,
36+
usage: wgpu::TextureUsages::TEXTURE_BINDING
37+
| wgpu::TextureUsages::COPY_DST
38+
| wgpu::TextureUsages::STORAGE_BINDING
39+
| wgpu::TextureUsages::COPY_SRC,
40+
view_formats: &[],
41+
});
4042

41-
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
42-
label: Some("bind group layout"),
43-
entries: &[wgpu::BindGroupLayoutEntry {
44-
binding: 0,
45-
visibility: wgpu::ShaderStages::COMPUTE,
46-
ty: wgpu::BindingType::StorageTexture {
47-
access: wgpu::StorageTextureAccess::WriteOnly,
48-
format: wgpu::TextureFormat::Rgba32Float,
49-
view_dimension: wgpu::TextureViewDimension::D2,
50-
},
43+
let texture_view = storage_texture.create_view(&wgpu::TextureViewDescriptor::default());
5144

52-
count: NonZeroU32::new(4),
53-
}],
54-
});
45+
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
46+
label: Some("bind group layout"),
47+
entries: &[wgpu::BindGroupLayoutEntry {
48+
binding: 0,
49+
visibility: wgpu::ShaderStages::COMPUTE,
50+
ty: wgpu::BindingType::StorageTexture {
51+
access: wgpu::StorageTextureAccess::WriteOnly,
52+
format: wgpu::TextureFormat::Rgba32Float,
53+
view_dimension: wgpu::TextureViewDimension::D2,
54+
},
5555

56-
let cs_module =
57-
device.create_shader_module(wgpu::include_wgsl!("partially_bounded_arrays.wgsl"));
56+
count: NonZeroU32::new(4),
57+
}],
58+
});
5859

59-
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
60-
label: Some("main"),
61-
bind_group_layouts: &[&bind_group_layout],
62-
push_constant_ranges: &[],
63-
});
60+
let cs_module =
61+
device.create_shader_module(wgpu::include_wgsl!("partially_bounded_arrays.wgsl"));
6462

65-
let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
66-
label: None,
67-
layout: Some(&pipeline_layout),
68-
module: &cs_module,
69-
entry_point: Some("main"),
70-
compilation_options: Default::default(),
71-
cache: None,
72-
});
63+
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
64+
label: Some("main"),
65+
bind_group_layouts: &[&bind_group_layout],
66+
push_constant_ranges: &[],
67+
});
7368

74-
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
75-
entries: &[wgpu::BindGroupEntry {
76-
binding: 0,
77-
resource: wgpu::BindingResource::TextureViewArray(&[&texture_view]),
78-
}],
79-
layout: &bind_group_layout,
80-
label: Some("bind group"),
81-
});
69+
let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
70+
label: None,
71+
layout: Some(&pipeline_layout),
72+
module: &cs_module,
73+
entry_point: Some("main"),
74+
compilation_options: Default::default(),
75+
cache: None,
76+
});
77+
78+
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
79+
entries: &[wgpu::BindGroupEntry {
80+
binding: 0,
81+
resource: wgpu::BindingResource::TextureViewArray(&[&texture_view]),
82+
}],
83+
layout: &bind_group_layout,
84+
label: Some("bind group"),
85+
});
8286

83-
let mut encoder =
84-
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
85-
{
86-
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
87-
label: None,
88-
timestamp_writes: None,
89-
});
90-
cpass.set_pipeline(&compute_pipeline);
91-
cpass.set_bind_group(0, &bind_group, &[]);
92-
cpass.dispatch_workgroups(1, 1, 1);
93-
}
87+
let mut encoder =
88+
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
89+
{
90+
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
91+
label: None,
92+
timestamp_writes: None,
93+
});
94+
cpass.set_pipeline(&compute_pipeline);
95+
cpass.set_bind_group(0, &bind_group, &[]);
96+
cpass.dispatch_workgroups(1, 1, 1);
97+
}
9498

95-
let readback_buffers = ReadbackBuffers::new(&ctx.device, &storage_texture);
96-
readback_buffers.copy_from(&ctx.device, &mut encoder, &storage_texture);
99+
let readback_buffers = ReadbackBuffers::new(&ctx.device, &storage_texture);
100+
readback_buffers.copy_from(&ctx.device, &mut encoder, &storage_texture);
97101

98-
ctx.queue.submit(Some(encoder.finish()));
102+
ctx.queue.submit(Some(encoder.finish()));
99103

100-
readback_buffers
101-
.assert_buffer_contents(&ctx, bytemuck::bytes_of(&[4.0f32, 3.0, 2.0, 1.0]))
102-
.await;
103-
});
104+
readback_buffers
105+
.assert_buffer_contents(&ctx, bytemuck::bytes_of(&[4.0f32, 3.0, 2.0, 1.0]))
106+
.await;
107+
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
@group(0)
22
@binding(0)
3-
var texture_array_storage: binding_array<texture_storage_2d<rgba32float,write>,1>;
3+
var texture_array_storage: binding_array<texture_storage_2d<rgba32float, write> >;
44

55
@compute
66
@workgroup_size(1)
77
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
8-
9-
textureStore(texture_array_storage[0],vec2<i32>(0,0), vec4<f32>(4.0,3.0,2.0,1.0));
10-
8+
textureStore(texture_array_storage[0],vec2<i32>(0,0), vec4<f32>(4.0,3.0,2.0,1.0));
119
}

0 commit comments

Comments
 (0)