|
| 1 | +use super::*; |
| 2 | + |
| 3 | +// ============================================================================ |
| 4 | +// Int64ImageEXT capability tests |
| 5 | +// ============================================================================ |
| 6 | + |
| 7 | +#[test] |
| 8 | +fn image_type_64bit_int_sampled_type_requires_int64image_capability() { |
| 9 | + // The grammar-level capability validation catches this before our check: |
| 10 | + // R64ui format requires Int64ImageEXT capability at the operand level. |
| 11 | + let text = [ |
| 12 | + "OpCapability Shader", |
| 13 | + "OpCapability Int64", |
| 14 | + "OpCapability StorageImageExtendedFormats", |
| 15 | + "OpMemoryModel Logical GLSL450", |
| 16 | + "%u64 = OpTypeInt 64 0", |
| 17 | + "%img = OpTypeImage %u64 2D 0 0 0 2 R64ui", |
| 18 | + ] |
| 19 | + .join("\n"); |
| 20 | + let binary = assemble_text(&text).expect("assemble"); |
| 21 | + let err = validate_module(&binary, TargetEnv::Universal1_3) |
| 22 | + .expect_err("64-bit int image without Int64ImageEXT should fail"); |
| 23 | + // May fail with grammar-level MissingOperandCapability or our ImageTypeRequiresInt64ImageCapability |
| 24 | + let is_capability_error = matches!( |
| 25 | + err, |
| 26 | + ValidationError::ImageTypeRequiresInt64ImageCapability |
| 27 | + | ValidationError::MissingOperandCapability { .. } |
| 28 | + ); |
| 29 | + assert!( |
| 30 | + is_capability_error, |
| 31 | + "Expected capability error, got: {err:?}" |
| 32 | + ); |
| 33 | +} |
| 34 | + |
| 35 | +#[test] |
| 36 | +fn image_type_64bit_int_sampled_type_passes_with_int64image_capability() { |
| 37 | + let text = [ |
| 38 | + "OpCapability Shader", |
| 39 | + "OpCapability Int64", |
| 40 | + "OpCapability Int64ImageEXT", |
| 41 | + "OpCapability StorageImageExtendedFormats", |
| 42 | + "OpExtension \"SPV_EXT_shader_image_int64\"", |
| 43 | + "OpMemoryModel Logical GLSL450", |
| 44 | + "%u64 = OpTypeInt 64 0", |
| 45 | + "%img = OpTypeImage %u64 2D 0 0 0 2 R64ui", |
| 46 | + ] |
| 47 | + .join("\n"); |
| 48 | + let binary = assemble_text(&text).expect("assemble"); |
| 49 | + validate_module(&binary, TargetEnv::Universal1_3) |
| 50 | + .expect("64-bit int image with Int64ImageEXT should pass"); |
| 51 | +} |
| 52 | + |
| 53 | +#[test] |
| 54 | +fn image_type_32bit_int_sampled_type_does_not_require_int64image() { |
| 55 | + let text = [ |
| 56 | + "OpCapability Shader", |
| 57 | + "OpMemoryModel Logical GLSL450", |
| 58 | + "%u32 = OpTypeInt 32 0", |
| 59 | + "%img = OpTypeImage %u32 2D 0 0 0 2 R32ui", |
| 60 | + ] |
| 61 | + .join("\n"); |
| 62 | + let binary = assemble_text(&text).expect("assemble"); |
| 63 | + validate_module(&binary, TargetEnv::Universal1_3) |
| 64 | + .expect("32-bit int image should not require Int64ImageEXT"); |
| 65 | +} |
| 66 | + |
| 67 | +// ============================================================================ |
| 68 | +// StorageImageMultisample capability tests |
| 69 | +// ============================================================================ |
| 70 | + |
| 71 | +#[test] |
| 72 | +fn image_type_multisampled_storage_requires_storage_image_multisample() { |
| 73 | + let text = [ |
| 74 | + "OpCapability Shader", |
| 75 | + "OpMemoryModel Logical GLSL450", |
| 76 | + "%f32 = OpTypeFloat 32", |
| 77 | + // MS=1, Sampled=2 (storage image) -> requires StorageImageMultisample |
| 78 | + "%img = OpTypeImage %f32 2D 0 0 1 2 Rgba32f", |
| 79 | + ] |
| 80 | + .join("\n"); |
| 81 | + let binary = assemble_text(&text).expect("assemble"); |
| 82 | + let err = validate_module(&binary, TargetEnv::Universal1_3) |
| 83 | + .expect_err("multisampled storage image without StorageImageMultisample should fail"); |
| 84 | + assert!( |
| 85 | + matches!( |
| 86 | + err, |
| 87 | + ValidationError::ImageTypeRequiresStorageImageMultisampleCapability |
| 88 | + ), |
| 89 | + "Expected ImageTypeRequiresStorageImageMultisampleCapability, got: {err:?}" |
| 90 | + ); |
| 91 | +} |
| 92 | + |
| 93 | +#[test] |
| 94 | +fn image_type_multisampled_storage_passes_with_capability() { |
| 95 | + let text = [ |
| 96 | + "OpCapability Shader", |
| 97 | + "OpCapability StorageImageMultisample", |
| 98 | + "OpMemoryModel Logical GLSL450", |
| 99 | + "%f32 = OpTypeFloat 32", |
| 100 | + "%img = OpTypeImage %f32 2D 0 0 1 2 Rgba32f", |
| 101 | + ] |
| 102 | + .join("\n"); |
| 103 | + let binary = assemble_text(&text).expect("assemble"); |
| 104 | + validate_module(&binary, TargetEnv::Universal1_3) |
| 105 | + .expect("multisampled storage image with StorageImageMultisample should pass"); |
| 106 | +} |
| 107 | + |
| 108 | +#[test] |
| 109 | +fn image_type_multisampled_sampling_image_does_not_require_storage_multisample() { |
| 110 | + let text = [ |
| 111 | + "OpCapability Shader", |
| 112 | + "OpMemoryModel Logical GLSL450", |
| 113 | + "%f32 = OpTypeFloat 32", |
| 114 | + // MS=1, Sampled=1 (sampling image, not storage) -> no capability needed |
| 115 | + "%img = OpTypeImage %f32 2D 0 0 1 1 Unknown", |
| 116 | + ] |
| 117 | + .join("\n"); |
| 118 | + let binary = assemble_text(&text).expect("assemble"); |
| 119 | + validate_module(&binary, TargetEnv::Universal1_3) |
| 120 | + .expect("multisampled sampling image should not require StorageImageMultisample"); |
| 121 | +} |
| 122 | + |
| 123 | +#[test] |
| 124 | +fn image_type_non_multisampled_storage_does_not_require_storage_multisample() { |
| 125 | + let text = [ |
| 126 | + "OpCapability Shader", |
| 127 | + "OpMemoryModel Logical GLSL450", |
| 128 | + "%f32 = OpTypeFloat 32", |
| 129 | + // MS=0, Sampled=2 (non-multisampled storage image) -> no capability needed |
| 130 | + "%img = OpTypeImage %f32 2D 0 0 0 2 Rgba32f", |
| 131 | + ] |
| 132 | + .join("\n"); |
| 133 | + let binary = assemble_text(&text).expect("assemble"); |
| 134 | + validate_module(&binary, TargetEnv::Universal1_3) |
| 135 | + .expect("non-multisampled storage image should not require StorageImageMultisample"); |
| 136 | +} |
| 137 | + |
| 138 | +// ============================================================================ |
| 139 | +// ImageQueryFormat / ImageQueryOrder tests |
| 140 | +// ============================================================================ |
| 141 | + |
| 142 | +#[test] |
| 143 | +fn image_query_format_valid_kernel() { |
| 144 | + // OpImageQueryFormat requires Kernel capability |
| 145 | + let text = [ |
| 146 | + "OpCapability Kernel", |
| 147 | + "OpCapability Addresses", |
| 148 | + |
| 149 | + "OpMemoryModel Physical64 OpenCL", |
| 150 | + "OpEntryPoint Kernel %main \"main\"", |
| 151 | + "%void = OpTypeVoid", |
| 152 | + "%int = OpTypeInt 32 0", |
| 153 | + "%float = OpTypeFloat 32", |
| 154 | + "%fn = OpTypeFunction %void", |
| 155 | + "%img_ty = OpTypeImage %float 2D 0 0 0 0 Unknown", |
| 156 | + "%ptr_img = OpTypePointer CrossWorkgroup %img_ty", |
| 157 | + "%var = OpVariable %ptr_img CrossWorkgroup", |
| 158 | + "%main = OpFunction %void None %fn", |
| 159 | + "%entry = OpLabel", |
| 160 | + "%img = OpLoad %img_ty %var", |
| 161 | + "%fmt = OpImageQueryFormat %int %img", |
| 162 | + "OpReturn", |
| 163 | + "OpFunctionEnd", |
| 164 | + ] |
| 165 | + .join("\n"); |
| 166 | + let binary = assemble_text(&text).expect("assemble"); |
| 167 | + validate_module(&binary, TargetEnv::Universal1_3) |
| 168 | + .expect("valid OpImageQueryFormat in Kernel should pass"); |
| 169 | +} |
| 170 | + |
| 171 | +#[test] |
| 172 | +fn image_query_order_valid_kernel() { |
| 173 | + // OpImageQueryOrder requires Kernel capability |
| 174 | + let text = [ |
| 175 | + "OpCapability Kernel", |
| 176 | + "OpCapability Addresses", |
| 177 | + |
| 178 | + "OpMemoryModel Physical64 OpenCL", |
| 179 | + "OpEntryPoint Kernel %main \"main\"", |
| 180 | + "%void = OpTypeVoid", |
| 181 | + "%int = OpTypeInt 32 0", |
| 182 | + "%float = OpTypeFloat 32", |
| 183 | + "%fn = OpTypeFunction %void", |
| 184 | + "%img_ty = OpTypeImage %float 2D 0 0 0 0 Unknown", |
| 185 | + "%ptr_img = OpTypePointer CrossWorkgroup %img_ty", |
| 186 | + "%var = OpVariable %ptr_img CrossWorkgroup", |
| 187 | + "%main = OpFunction %void None %fn", |
| 188 | + "%entry = OpLabel", |
| 189 | + "%img = OpLoad %img_ty %var", |
| 190 | + "%ord = OpImageQueryOrder %int %img", |
| 191 | + "OpReturn", |
| 192 | + "OpFunctionEnd", |
| 193 | + ] |
| 194 | + .join("\n"); |
| 195 | + let binary = assemble_text(&text).expect("assemble"); |
| 196 | + validate_module(&binary, TargetEnv::Universal1_3) |
| 197 | + .expect("valid OpImageQueryOrder in Kernel should pass"); |
| 198 | +} |
| 199 | + |
| 200 | +#[test] |
| 201 | +fn image_query_format_requires_int_scalar_result_kernel() { |
| 202 | + // OpImageQueryFormat result type must be int scalar |
| 203 | + let text = [ |
| 204 | + "OpCapability Kernel", |
| 205 | + "OpCapability Addresses", |
| 206 | + |
| 207 | + "OpMemoryModel Physical64 OpenCL", |
| 208 | + "OpEntryPoint Kernel %main \"main\"", |
| 209 | + "%void = OpTypeVoid", |
| 210 | + "%float = OpTypeFloat 32", |
| 211 | + "%fn = OpTypeFunction %void", |
| 212 | + "%img_ty = OpTypeImage %float 2D 0 0 0 0 Unknown", |
| 213 | + "%ptr_img = OpTypePointer CrossWorkgroup %img_ty", |
| 214 | + "%var = OpVariable %ptr_img CrossWorkgroup", |
| 215 | + "%main = OpFunction %void None %fn", |
| 216 | + "%entry = OpLabel", |
| 217 | + "%img = OpLoad %img_ty %var", |
| 218 | + // Using float result type instead of int - should fail |
| 219 | + "%fmt = OpImageQueryFormat %float %img", |
| 220 | + "OpReturn", |
| 221 | + "OpFunctionEnd", |
| 222 | + ] |
| 223 | + .join("\n"); |
| 224 | + let binary = assemble_text(&text).expect("assemble"); |
| 225 | + let err = validate_module(&binary, TargetEnv::Universal1_3) |
| 226 | + .expect_err("OpImageQueryFormat with float result should fail"); |
| 227 | + assert!( |
| 228 | + matches!( |
| 229 | + err, |
| 230 | + ValidationError::ImageQueryResultTypeInvalid { .. } |
| 231 | + ), |
| 232 | + "Expected ImageQueryResultTypeInvalid, got: {err:?}" |
| 233 | + ); |
| 234 | +} |
0 commit comments