Specialize runtime storage image formats

Accept runtime storage surface formats and host feature facts by Metal texture index, specialize image types before interface creation, and reflect the exact explicit or formatless contract. Track runtime origins through arrays and image aliases so every read, write, imageblock write, emulated fetch, and atomic operation checks the required capability or refuses honestly.\n\nWire authored validation resources into the same product options, bump the reflection and candidate executor contracts, document consumer use, and cover type splitting, dependent loads, exact formatless capabilities, atomics, incompatibility, missing bindings, imageblock writes, and pixel-gather storage reads.\n\nVerified with workspace clippy -D warnings, warnings-denied all-features Rustdoc, serial product and validation suites, both packaged AIR reproductions plus spirv-val Vulkan 1.3, and release measurements under 0.5 seconds / 23 MiB RSS.
This commit is contained in:
Anees Iqbal committed 2026-08-20 06:47:22 +03:00
1 parent e76b90d6fd
commit 547a59d99b
24 files changed
+1321 -27

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ use base64::Engine as _;
use metal2vulkan::reflect::ShaderReflection;
use std::path::Path;
pub const EXECUTOR_ABI: &str = "vulkan-literal-resources-v27";
pub const EXECUTOR_ABI: &str = "vulkan-literal-resources-v28";
pub fn execute_case(
root: &Path,
+94
View File
@@ -713,6 +713,43 @@ impl TextureFormat {
Self::Depth32Float => 4,
}
}
fn runtime_storage_specialization(
self,
) -> Result<metal2vulkan::reflect::RuntimeStorageImageState, String> {
use metal2vulkan::reflect::{
RuntimeStorageImageCapabilities, RuntimeStorageImageFormat, RuntimeStorageImageState,
};
let format = match self {
Self::R8Unorm => RuntimeStorageImageFormat::R8Unorm,
Self::Rgba8Unorm => RuntimeStorageImageFormat::Rgba8Unorm,
Self::Rgba8Uint => RuntimeStorageImageFormat::Rgba8Uint,
Self::Rgba8Sint => RuntimeStorageImageFormat::Rgba8Sint,
Self::R16Float => RuntimeStorageImageFormat::R16Float,
Self::R16Uint => RuntimeStorageImageFormat::R16Uint,
Self::Rg16Float => RuntimeStorageImageFormat::Rg16Float,
Self::Rgba16Float => RuntimeStorageImageFormat::Rgba16Float,
Self::Rgba16Uint => RuntimeStorageImageFormat::Rgba16Uint,
Self::R32Uint => RuntimeStorageImageFormat::R32Uint,
Self::R32Sint => RuntimeStorageImageFormat::R32Sint,
Self::R32Float => RuntimeStorageImageFormat::R32Float,
Self::Rgba32Uint => RuntimeStorageImageFormat::Rgba32Uint,
Self::Rgba32Sint => RuntimeStorageImageFormat::Rgba32Sint,
Self::Rgba32Float => RuntimeStorageImageFormat::Rgba32Float,
Self::Depth32Float => {
return Err("depth formats cannot specialize a storage image".into());
}
};
Ok(RuntimeStorageImageState {
format,
capabilities: RuntimeStorageImageCapabilities {
storage_image: true,
storage_image_atomic: matches!(self, Self::R32Uint | Self::R32Sint),
read_without_format: false,
write_without_format: false,
},
})
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
@@ -793,6 +830,22 @@ pub(crate) fn product_transform_options(
options =
options.with_runtime_sampler(sampler.binding, sampler.runtime_specialization())?;
}
for texture in &case.textures {
if texture.role != ResourceRole::Input {
options = options.with_runtime_storage_image(
texture.binding,
texture.format.runtime_storage_specialization()?,
)?;
}
}
for texture in &case.texture_arrays {
if texture.role != ResourceRole::Input {
options = options.with_runtime_storage_image(
texture.binding,
texture.format.runtime_storage_specialization()?,
)?;
}
}
Ok(options)
}
@@ -2797,6 +2850,47 @@ mod tests {
assert!(error.contains("mixed min/mag"), "{error}");
}
#[test]
fn authored_storage_texture_format_is_the_product_specialization_input() {
let mut case = example();
case.textures.push(TextureResource {
binding: 4,
role: ResourceRole::Output,
texture_type: TextureType::D2,
format: TextureFormat::Rgba8Unorm,
dimensions: [2, 2, 1],
sample_count: 1,
bytes_b64: None,
initial_bytes_b64: None,
});
case.texture_arrays.push(TextureArrayResource {
binding: 6,
role: ResourceRole::InOut,
texture_type: TextureType::D2,
format: TextureFormat::R32Uint,
sample_count: 1,
elements: vec![TextureArrayElement {
dimensions: [1, 1, 1],
bytes_b64: None,
initial_bytes_b64: Some("AAAAAA==".into()),
}],
});
let options = product_transform_options(&case).expect("authored storage specialization");
assert_eq!(
options.runtime_storage_image_states[4]
.expect("single storage texture")
.format,
metal2vulkan::reflect::RuntimeStorageImageFormat::Rgba8Unorm
);
let array = options.runtime_storage_image_states[6].expect("storage texture array");
assert_eq!(
array.format,
metal2vulkan::reflect::RuntimeStorageImageFormat::R32Uint
);
assert!(array.capabilities.storage_image_atomic);
}
#[test]
fn fragment_depth_stencil_attachment_has_exact_aspect_bytes_and_selection() {
let mut case = example();
+6
View File
@@ -917,10 +917,16 @@ fn validate_texture_shape(
}
let exact_storage_format = shape.storage_format.map(|format| match format {
ReflectedFormat::R8 => TextureFormat::R8Unorm,
ReflectedFormat::Rgba8 => TextureFormat::Rgba8Unorm,
ReflectedFormat::R16f => TextureFormat::R16Float,
ReflectedFormat::R16ui => TextureFormat::R16Uint,
ReflectedFormat::Rg16f => TextureFormat::Rg16Float,
ReflectedFormat::R32f => TextureFormat::R32Float,
ReflectedFormat::R32i => TextureFormat::R32Sint,
ReflectedFormat::R32ui => TextureFormat::R32Uint,
ReflectedFormat::Rgba32i => TextureFormat::Rgba32Sint,
ReflectedFormat::Rgba32ui => TextureFormat::Rgba32Uint,
ReflectedFormat::Rgba32f => TextureFormat::Rgba32Float,
ReflectedFormat::Rgba16f => TextureFormat::Rgba16Float,
ReflectedFormat::Rgba8ui => TextureFormat::Rgba8Uint,
+10 -1
View File
@@ -149,7 +149,16 @@ pub fn unsupported_reflection_requirements(
if shape.storage_format.is_some_and(|format| {
!matches!(
format,
ReflectedTextureFormat::R32f
ReflectedTextureFormat::R8
| ReflectedTextureFormat::Rgba8
| ReflectedTextureFormat::R16f
| ReflectedTextureFormat::R16ui
| ReflectedTextureFormat::Rg16f
| ReflectedTextureFormat::R32i
| ReflectedTextureFormat::R32f
| ReflectedTextureFormat::R32ui
| ReflectedTextureFormat::Rgba32i
| ReflectedTextureFormat::Rgba32ui
| ReflectedTextureFormat::Rgba32f
| ReflectedTextureFormat::Rgba16f
| ReflectedTextureFormat::Rgba8ui