Skip to content

Commit 45f5b4f

Browse files
committed
Remove incorrect Vulkan-only restriction on SubpassData dimension
The C++ validator does not restrict SubpassData to Vulkan environments. Only the Arrayed==0 constraint is Vulkan-specific. Remove the blanket environment check and make the Arrayed check Vulkan-only to match.
1 parent 87a2783 commit 45f5b4f

3 files changed

Lines changed: 54 additions & 26 deletions

File tree

rust/spirv-tools-core/src/validation/error.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4159,16 +4159,8 @@ pub enum ValidationError {
41594159
/// Actual operand count.
41604160
actual: usize,
41614161
},
4162-
/// OpTypeImage with SubpassData dimension requires Vulkan environment.
4163-
#[error("OpTypeImage {type_id:?} with SubpassData dimension is only allowed in Vulkan, current environment is {env:?}")]
4164-
ImageTypeSubpassDataRequiresVulkan {
4165-
/// The image type ID.
4166-
type_id: Option<TypeId>,
4167-
/// The current target environment.
4168-
env: crate::target_env::TargetEnv,
4169-
},
4170-
/// OpTypeImage with SubpassData dimension must not be arrayed.
4171-
#[error("OpTypeImage {type_id:?} with SubpassData dimension must not be arrayed")]
4162+
/// OpTypeImage with SubpassData dimension must not be arrayed (Vulkan).
4163+
#[error("OpTypeImage {type_id:?} with SubpassData dimension must not be arrayed in Vulkan")]
41724164
ImageTypeSubpassDataMustNotBeArrayed {
41734165
/// The image type ID.
41744166
type_id: Option<TypeId>,

rust/spirv-tools-core/src/validation/rules/image.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,18 +293,10 @@ impl ValidationRule for ImageTypeRule {
293293
);
294294
}
295295

296-
// SubpassData requires Vulkan environment
297-
if dim == Dim::DimSubpassData && !ctx.env.is_vulkan() {
298-
return Err(ValidationError::ImageTypeSubpassDataRequiresVulkan {
299-
type_id,
300-
env: ctx.env,
301-
}
302-
.into());
303-
}
304-
305296
// SubpassData constraints
306297
if dim == Dim::DimSubpassData {
307-
if arrayed != 0 {
298+
// Arrayed must be 0 in Vulkan (VUID-StandaloneSpirv-SubpassData-06214)
299+
if ctx.env.is_vulkan() && arrayed != 0 {
308300
return Err(
309301
ValidationError::ImageTypeSubpassDataMustNotBeArrayed { type_id }.into(),
310302
);

rust/spirv-tools-core/src/validation/tests/misc.rs

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7272,7 +7272,7 @@ OpFunctionEnd
72727272
}
72737273

72747274
// ============================================================================
7275-
// SubpassData Vulkan-only restriction
7275+
// SubpassData validation
72767276
// ============================================================================
72777277

72787278
#[test]
@@ -7297,7 +7297,7 @@ OpFunctionEnd
72977297
}
72987298

72997299
#[test]
7300-
fn subpass_data_rejected_in_non_vulkan() {
7300+
fn subpass_data_accepted_in_universal() {
73017301
let text = r#"
73027302
OpCapability Shader
73037303
OpCapability InputAttachment
@@ -7313,13 +7313,57 @@ OpExecutionMode %main OriginUpperLeft
73137313
OpReturn
73147314
OpFunctionEnd
73157315
"#;
7316-
let err = assemble_and_validate_with_env(text, TargetEnv::Universal1_6)
7317-
.expect_err("SubpassData should be rejected in non-Vulkan");
7316+
assemble_and_validate_with_env(text, TargetEnv::Universal1_3)
7317+
.expect("SubpassData should be accepted in Universal environment");
7318+
}
7319+
7320+
#[test]
7321+
fn subpass_data_arrayed_rejected_in_vulkan() {
7322+
// In Vulkan, SubpassData Arrayed must be 0 (VUID-StandaloneSpirv-SubpassData-06214)
7323+
let text = r#"
7324+
OpCapability Shader
7325+
OpCapability InputAttachment
7326+
OpMemoryModel Logical GLSL450
7327+
OpEntryPoint Fragment %main "main"
7328+
OpExecutionMode %main OriginUpperLeft
7329+
%void = OpTypeVoid
7330+
%fn = OpTypeFunction %void
7331+
%f32 = OpTypeFloat 32
7332+
%img = OpTypeImage %f32 SubpassData 0 1 0 2 Unknown
7333+
%main = OpFunction %void None %fn
7334+
%entry = OpLabel
7335+
OpReturn
7336+
OpFunctionEnd
7337+
"#;
7338+
let err = assemble_and_validate_with_env(text, TargetEnv::Vulkan1_2)
7339+
.expect_err("SubpassData with Arrayed=1 should be rejected in Vulkan");
73187340
assert!(
73197341
matches!(
73207342
err,
7321-
ValidationError::ImageTypeSubpassDataRequiresVulkan { .. }
7343+
ValidationError::ImageTypeSubpassDataMustNotBeArrayed { .. }
73227344
),
7323-
"expected ImageTypeSubpassDataRequiresVulkan, got {err:?}"
7345+
"expected ImageTypeSubpassDataMustNotBeArrayed, got {err:?}"
73247346
);
73257347
}
7348+
7349+
#[test]
7350+
fn subpass_data_arrayed_accepted_in_universal() {
7351+
// Outside Vulkan, arrayed SubpassData is not restricted
7352+
let text = r#"
7353+
OpCapability Shader
7354+
OpCapability InputAttachment
7355+
OpMemoryModel Logical GLSL450
7356+
OpEntryPoint Fragment %main "main"
7357+
OpExecutionMode %main OriginUpperLeft
7358+
%void = OpTypeVoid
7359+
%fn = OpTypeFunction %void
7360+
%f32 = OpTypeFloat 32
7361+
%img = OpTypeImage %f32 SubpassData 0 1 0 2 Unknown
7362+
%main = OpFunction %void None %fn
7363+
%entry = OpLabel
7364+
OpReturn
7365+
OpFunctionEnd
7366+
"#;
7367+
assemble_and_validate_with_env(text, TargetEnv::Universal1_3)
7368+
.expect("SubpassData with Arrayed=1 should be accepted in Universal");
7369+
}

0 commit comments

Comments
 (0)