Skip to content

Commit 27b9ee6

Browse files
committed
Allow tests to set max_sets
1 parent 5f16b8d commit 27b9ee6

File tree

4 files changed

+54
-13
lines changed

4 files changed

+54
-13
lines changed

tests/difftests/lib/src/scaffold/compute/ash.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ use anyhow::{Context, Result, bail};
33
use ash::vk;
44
use std::ffi::{CStr, CString};
55

6+
/// Configuration for the Ash backend
7+
#[derive(Clone)]
8+
pub struct AshConfig {
9+
/// Maximum number of descriptor sets
10+
pub max_descriptor_sets: u32,
11+
}
12+
13+
impl Default for AshConfig {
14+
fn default() -> Self {
15+
Self {
16+
max_descriptor_sets: 16,
17+
}
18+
}
19+
}
20+
621
pub struct AshBackend {
722
instance: ash::Instance,
823
device: ash::Device,
@@ -90,8 +105,8 @@ impl AshBackend {
90105
}
91106
}
92107

93-
impl ComputeBackend for AshBackend {
94-
fn init() -> Result<Self> {
108+
impl AshBackend {
109+
pub fn new(config: AshConfig) -> Result<Self> {
95110
unsafe {
96111
let entry = ash::Entry::load().context("Failed to load Vulkan entry")?;
97112

@@ -174,7 +189,7 @@ impl ComputeBackend for AshBackend {
174189

175190
let descriptor_pool_create_info = vk::DescriptorPoolCreateInfo::default()
176191
.pool_sizes(&descriptor_pool_sizes)
177-
.max_sets(16);
192+
.max_sets(config.max_descriptor_sets);
178193

179194
let descriptor_pool = device
180195
.create_descriptor_pool(&descriptor_pool_create_info, None)
@@ -191,7 +206,15 @@ impl ComputeBackend for AshBackend {
191206
})
192207
}
193208
}
209+
}
210+
211+
impl Default for AshBackend {
212+
fn default() -> Self {
213+
Self::new(AshConfig::default()).expect("Failed to create AshBackend with default config")
214+
}
215+
}
194216

217+
impl ComputeBackend for AshBackend {
195218
fn run_compute(
196219
&self,
197220
spirv_bytes: &[u8],

tests/difftests/lib/src/scaffold/compute/backend.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ pub enum BufferUsage {
1919

2020
/// A generic trait for compute backends
2121
pub trait ComputeBackend: Sized {
22-
/// Initialize the backend
23-
fn init() -> Result<Self>;
24-
2522
/// Create and run a compute shader with multiple buffers
2623
fn run_compute(
2724
&self,
@@ -42,14 +39,32 @@ pub struct ComputeTest<B: ComputeBackend> {
4239
}
4340

4441
impl<B: ComputeBackend> ComputeTest<B> {
42+
pub fn new_with_backend(
43+
backend: B,
44+
spirv_bytes: Vec<u8>,
45+
entry_point: String,
46+
dispatch: [u32; 3],
47+
buffers: Vec<BufferConfig>,
48+
) -> Result<Self> {
49+
Ok(Self {
50+
backend,
51+
spirv_bytes,
52+
entry_point,
53+
dispatch,
54+
buffers,
55+
})
56+
}
57+
}
58+
59+
impl<B: ComputeBackend + Default> ComputeTest<B> {
4560
pub fn new(
4661
spirv_bytes: Vec<u8>,
4762
entry_point: String,
4863
dispatch: [u32; 3],
4964
buffers: Vec<BufferConfig>,
5065
) -> Result<Self> {
5166
Ok(Self {
52-
backend: B::init()?,
67+
backend: B::default(),
5368
spirv_bytes,
5469
entry_point,
5570
dispatch,

tests/difftests/lib/src/scaffold/compute/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod ash;
22
mod backend;
33
mod wgpu;
44

5-
pub use ash::AshBackend;
5+
pub use ash::{AshBackend, AshConfig};
66
pub use backend::{BufferConfig, BufferUsage, ComputeBackend, ComputeTest};
77
pub use wgpu::{
88
RustComputeShader, WgpuBackend, WgpuComputeTest, WgpuComputeTestMultiBuffer,

tests/difftests/lib/src/scaffold/compute/wgpu.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,18 @@ pub struct WgpuBackend {
336336
queue: Arc<wgpu::Queue>,
337337
}
338338

339-
impl ComputeBackend for WgpuBackend {
340-
fn init() -> anyhow::Result<Self> {
341-
let (device, queue) = WgpuComputeTest::<RustComputeShader>::init()?;
342-
Ok(Self {
339+
impl Default for WgpuBackend {
340+
fn default() -> Self {
341+
let (device, queue) = WgpuComputeTest::<RustComputeShader>::init()
342+
.expect("Failed to create WgpuBackend with default config");
343+
Self {
343344
device: Arc::new(device),
344345
queue: Arc::new(queue),
345-
})
346+
}
346347
}
348+
}
347349

350+
impl ComputeBackend for WgpuBackend {
348351
fn run_compute(
349352
&self,
350353
spirv_bytes: &[u8],

0 commit comments

Comments
 (0)