mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-24 00:11:11 +01:00
[spv-out] be smarter about deriving capabilities, auto derive them for tests
This commit is contained in:
1 parent
93d93bb46b
commit
8b71234fb4
15 files changed
+51
-42
No files matched your search
@@ -2232,8 +2232,8 @@ fn test_stack_size() {
|
||||
}
|
||||
let stack_size = addresses.end - addresses.start;
|
||||
// check the size (in debug only)
|
||||
// last observed macOS value: 21760
|
||||
if stack_size < 21000 || stack_size > 23000 {
|
||||
// last observed macOS value: 17664
|
||||
if stack_size < 14000 || stack_size > 23000 {
|
||||
panic!("`put_expression` stack size {} has changed!", stack_size);
|
||||
}
|
||||
}
|
||||
@@ -2247,8 +2247,8 @@ fn test_stack_size() {
|
||||
}
|
||||
let stack_size = addresses.end - addresses.start;
|
||||
// check the size (in debug only)
|
||||
// last observed macOS value: 12736
|
||||
if stack_size < 12000 || stack_size > 13500 {
|
||||
// last observed macOS value: 13600
|
||||
if stack_size < 10000 || stack_size > 14500 {
|
||||
panic!("`put_block` stack size {} has changed!", stack_size);
|
||||
}
|
||||
}
|
||||
|
||||
+40
-25
@@ -284,7 +284,7 @@ pub struct Writer {
|
||||
logical_layout: LogicalLayout,
|
||||
id_gen: IdGenerator,
|
||||
capabilities: crate::FastHashSet<spirv::Capability>,
|
||||
strict_capabilities: bool,
|
||||
forbidden_caps: Option<&'static [spirv::Capability]>,
|
||||
debugs: Vec<Instruction>,
|
||||
annotations: Vec<Instruction>,
|
||||
flags: WriterFlags,
|
||||
@@ -314,19 +314,22 @@ impl Writer {
|
||||
let gl450_ext_inst_id = id_gen.next();
|
||||
let void_type = id_gen.next();
|
||||
|
||||
let (capabilities, forbidden_caps) = match options.capabilities {
|
||||
Some(ref caps) => (caps.clone(), None),
|
||||
None => {
|
||||
let mut caps = crate::FastHashSet::default();
|
||||
caps.insert(spirv::Capability::Shader);
|
||||
let forbidden: &[_] = &[spirv::Capability::Kernel];
|
||||
(caps, Some(forbidden))
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Writer {
|
||||
physical_layout: PhysicalLayout::new(raw_version),
|
||||
logical_layout: LogicalLayout::default(),
|
||||
id_gen,
|
||||
capabilities: match options.capabilities {
|
||||
Some(ref caps) => caps.clone(),
|
||||
None => {
|
||||
let mut caps = crate::FastHashSet::default();
|
||||
caps.insert(spirv::Capability::Shader);
|
||||
caps
|
||||
}
|
||||
},
|
||||
strict_capabilities: options.capabilities.is_some(),
|
||||
capabilities,
|
||||
forbidden_caps,
|
||||
debugs: vec![],
|
||||
annotations: vec![],
|
||||
flags: options.flags,
|
||||
@@ -345,20 +348,21 @@ impl Writer {
|
||||
}
|
||||
|
||||
fn check(&mut self, capabilities: &[spirv::Capability]) -> Result<(), Error> {
|
||||
if self.strict_capabilities {
|
||||
if capabilities.is_empty()
|
||||
|| capabilities
|
||||
.iter()
|
||||
.any(|cap| self.capabilities.contains(cap))
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::MissingCapabilities(capabilities.to_vec()))
|
||||
}
|
||||
} else {
|
||||
self.capabilities.extend(capabilities);
|
||||
Ok(())
|
||||
if capabilities.is_empty()
|
||||
|| capabilities
|
||||
.iter()
|
||||
.any(|cap| self.capabilities.contains(cap))
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(forbidden) = self.forbidden_caps {
|
||||
// take the first allowed capability, blindly
|
||||
if let Some(&cap) = capabilities.iter().find(|cap| !forbidden.contains(cap)) {
|
||||
self.capabilities.insert(cap);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Err(Error::MissingCapabilities(capabilities.to_vec()))
|
||||
}
|
||||
|
||||
fn get_type_id(
|
||||
@@ -900,7 +904,15 @@ impl Writer {
|
||||
let kind = match class {
|
||||
crate::ImageClass::Sampled { kind, multi: _ } => kind,
|
||||
crate::ImageClass::Depth => crate::ScalarKind::Float,
|
||||
crate::ImageClass::Storage(format) => format.into(),
|
||||
crate::ImageClass::Storage(format) => {
|
||||
let required_caps: &[_] = match dim {
|
||||
crate::ImageDimension::D1 => &[spirv::Capability::Image1D],
|
||||
crate::ImageDimension::Cube => &[spirv::Capability::ImageCubeArray],
|
||||
_ => &[],
|
||||
};
|
||||
self.check(required_caps)?;
|
||||
format.into()
|
||||
}
|
||||
};
|
||||
let local_type = LocalType::Value {
|
||||
vector_size: None,
|
||||
@@ -908,9 +920,9 @@ impl Writer {
|
||||
width: 4,
|
||||
pointer_class: None,
|
||||
};
|
||||
let type_id = self.get_type_id(arena, LookupType::Local(local_type))?;
|
||||
let dim = map_dim(dim);
|
||||
self.check(dim.required_capabilities())?;
|
||||
let type_id = self.get_type_id(arena, LookupType::Local(local_type))?;
|
||||
Instruction::type_image(id, type_id, dim, arrayed, class)
|
||||
}
|
||||
crate::TypeInner::Sampler { comparison: _ } => Instruction::type_sampler(id),
|
||||
@@ -2213,6 +2225,8 @@ impl Writer {
|
||||
}
|
||||
};
|
||||
|
||||
self.check(&[spirv::Capability::ImageQuery])?;
|
||||
|
||||
match query {
|
||||
Iq::Size { level } => {
|
||||
let dim_coords = match dim {
|
||||
@@ -2249,6 +2263,7 @@ impl Writer {
|
||||
(spirv::Op::ImageQuerySizeLod, Some(level_id))
|
||||
}
|
||||
};
|
||||
|
||||
// The ID of the vector returned by SPIR-V, which contains the dimensions
|
||||
// as well as the layer count.
|
||||
let id_extended = self.id_gen.next();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(
|
||||
spv_version: (1, 1),
|
||||
spv_capabilities: [ Shader, Image1D, Sampled1D ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: false,
|
||||
msl_custom: false,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
(
|
||||
spv_flow_dump_prefix: "",
|
||||
spv_version: (1, 0),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: false,
|
||||
msl_custom: true,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
(
|
||||
spv_flow_dump_prefix: "",
|
||||
spv_version: (1, 0),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: false,
|
||||
msl_custom: false,
|
||||
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -1,6 +1,5 @@
|
||||
(
|
||||
spv_version: (1, 1),
|
||||
spv_capabilities: [ Shader, ImageQuery, Image1D, Sampled1D ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: false,
|
||||
msl_custom: false,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(
|
||||
spv_version: (1, 0),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: true,
|
||||
msl_custom: false,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(
|
||||
spv_version: (1, 0),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: true,
|
||||
msl_custom: false,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
(
|
||||
spv_flow_dump_prefix: "",
|
||||
spv_version: (1, 2),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: true,
|
||||
msl_custom: false,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
(
|
||||
spv_flow_dump_prefix: "",
|
||||
spv_version: (1, 0),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: false,
|
||||
spv_adjust_coordinate_space: false,
|
||||
msl_custom: true,
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
; Version: 1.1
|
||||
; Generator: rspirv
|
||||
; Bound: 31
|
||||
OpCapability Image1D
|
||||
OpCapability Shader
|
||||
OpCapability Sampled1D
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Vertex %19 "foo" %14 %17
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
; Version: 1.1
|
||||
; Generator: rspirv
|
||||
; Bound: 127
|
||||
OpCapability ImageQuery
|
||||
OpCapability Image1D
|
||||
OpCapability Shader
|
||||
OpCapability Sampled1D
|
||||
OpCapability ImageQuery
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %43 "main" %40
|
||||
|
||||
+6
-1
@@ -24,6 +24,7 @@ struct Parameters {
|
||||
#[cfg_attr(not(feature = "spv-out"), allow(dead_code))]
|
||||
spv_version: (u8, u8),
|
||||
#[cfg_attr(not(feature = "spv-out"), allow(dead_code))]
|
||||
#[serde(default)]
|
||||
spv_capabilities: naga::FastHashSet<spirv::Capability>,
|
||||
#[cfg_attr(not(feature = "spv-out"), allow(dead_code))]
|
||||
spv_debug: bool,
|
||||
@@ -127,7 +128,11 @@ fn check_output_spv(
|
||||
let options = spv::Options {
|
||||
lang_version: params.spv_version,
|
||||
flags,
|
||||
capabilities: Some(params.spv_capabilities.clone()),
|
||||
capabilities: if params.spv_capabilities.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(params.spv_capabilities.clone())
|
||||
},
|
||||
};
|
||||
|
||||
let spv = spv::write_vec(module, info, &options).unwrap();
|
||||
|
||||
Reference in new issue
Block a user