Red: draw-side writes to an 8-bit sRGB texture, the conformance case and the runtime's test

fpv_srgb_draw_storage's companions (regen-air-fixtures on the Mac, job m3-max-82169). The
conformance case srgb-storage-fragment-writes is the fragment twin of srgb-storage-writes: the same
values, formats, texture and layout, written by fpv_srgb_fragment_write and its half form behind
one triangle over a 256 by 2 RGBA8Unorm attachment. The runtime's test draws the fragment writers
and the vertex writer (rasterization off) onto RGBA8Unorm_sRGB and BGRA8Unorm_sRGB textures with
their twins' storage views, and expects the draw to run through the render state's sRGB variant:
the encode in the bytes, one make at encode, and the state's DevicePackConversion note. At
development's tip the draw is Gap::StorageElement, so the test is red; the Metal recording and the
lavapipe run follow.
This commit is contained in:
Anees Iqbal committed 2026-12-02 22:21:37 -08:00
1 parent 8a735791c4
commit ea5b786eb4
7 files changed
+747 -16

No files matched your search

@@ -185,6 +185,7 @@ pub mod sparse_heaps;
pub mod sparse_mappings;
pub mod sparse_tiles;
pub mod srgb_fetch;
pub mod srgb_storage_fragment_writes;
pub mod srgb_storage_writes;
pub mod stage_in_regions;
pub mod stage_in_unread;
@@ -617,6 +618,9 @@ pub fn all() -> Vec<Box<dyn Case>> {
cases.push(Box::new(case));
}
cases.push(Box::new(srgb_storage_writes::SrgbStorageWrites));
cases.push(Box::new(
srgb_storage_fragment_writes::SrgbStorageFragmentWrites,
));
cases.extend(norm_storage_writes::NormStorageWrites::all());
cases.extend(texel_swizzles::all());
for case in swizzled_storage::all() {
@@ -0,0 +1,185 @@
//! `srgb-storage-fragment-writes`: what a fragment function's `access::write` stores into an 8-bit
//! sRGB texture, the fragment twin of [`srgb_storage_writes`](super::srgb_storage_writes).
//!
//! The promise is that case's: Metal writes `RGBA8Unorm_sRGB` and `BGRA8Unorm_sRGB` on every Metal
//! 3 device, and the Metal Shading Language specification (8.7.7) encodes the write from linear to
//! sRGB, alpha linear. `read_write` access is not promised for either format, so this case writes
//! only.
//!
//! The functions are the owned fixture `fpv_srgb_draw_storage`'s `fpv_srgb_fragment_write` and
//! `fpv_srgb_fragment_write_half`, drawn behind `fpv_srgb_cover`, one triangle over the whole of
//! a [`WIDTH`] by [`HEIGHT`] `RGBA8Unorm` attachment: each pixel's fragment writes buffer 0's
//! `float4` or `half4` of its pixel, element `y * WIDTH + x`, at its own texel of the texture at
//! fragment texture slot 0. The values, the formats, the texture and the layout its bytes are read
//! under are the kernel case's, so the two cases' stored bytes compare one to one: the case
//! records the texture's bytes by `getBytes:`, one code a channel.
//!
//! One pass a sweep, one fragment a texel, no loop and no sampling: nothing here can fault a GPU.
use super::srgb_storage_writes::{
request, stored_layout, values, width_bytes, FORMATS, HEIGHT, WIDTH,
};
use crate::case::{call, made, Abort, Case, Failure, Input, MetalSource, Side};
use crate::fixture::{Fixture, METAL_TEXT, RUNTIME_TEXT};
use crate::recording::ShaderRef;
use crate::render::{
ColorState, PassColor, RenderPass, RenderPipelineSpec, RenderStep, RenderWork, TargetSpec,
};
use crate::transcript::{Digest, Node, Observed, Sites, Value};
use metal2vulkan::metal::{PixelFormat, PrimitiveType};
/// The fixture the functions live in.
const FIXTURE: &str = "fpv_srgb_draw_storage";
/// The vertex function: one triangle over the whole viewport.
const COVER: &str = "fpv_srgb_cover";
/// The fragment functions the case draws: a `float4` write and a `half4` write.
const FRAGMENTS: [&str; 2] = ["fpv_srgb_fragment_write", "fpv_srgb_fragment_write_half"];
/// The attachment's format, which the fragments' returned colour lands in and nothing reads.
const ATTACHMENT: PixelFormat = PixelFormat::RGBA8Unorm;
/// The one colour attachment every pipeline carries.
const COLORS: [Option<ColorState>; 1] = [Some(ColorState::new(ATTACHMENT))];
/// The attachment: [`WIDTH`] by [`HEIGHT`], so a fragment is a texel of the written texture.
fn attachment() -> TargetSpec {
TargetSpec::read(ATTACHMENT, [WIDTH, HEIGHT])
}
/// The case.
pub struct SrgbStorageFragmentWrites;
impl Case for SrgbStorageFragmentWrites {
fn name(&self) -> &'static str {
"srgb-storage-fragment-writes"
}
fn metal_source(&self) -> MetalSource {
MetalSource::Run
}
fn shaders(&self) -> Result<Vec<ShaderRef>, String> {
let fixture = Fixture::new(FIXTURE);
let mut shaders = Vec::new();
for fragment in FRAGMENTS {
for extension in [RUNTIME_TEXT, METAL_TEXT] {
shaders.push(ShaderRef {
fixture: format!("{FIXTURE}{extension}"),
entry: format!("{COVER}+{fragment}"),
source_sha256: crate::sha256_hex(fixture.text(extension)?.as_bytes()),
});
}
}
Ok(shaders)
}
fn inputs(&self) -> Result<Vec<Input>, String> {
let fixture = Fixture::new(FIXTURE);
let mut inputs = vec![
Input {
name: "air".to_owned(),
digest: Digest::sha256(fixture.text(RUNTIME_TEXT)?.as_bytes()),
},
Input {
name: "air-typed".to_owned(),
digest: Digest::sha256(fixture.text(METAL_TEXT)?.as_bytes()),
},
Input::bytes("buffer:1", &width_bytes()),
Input::bytes("attachment", &attachment().words()),
];
for fragment in FRAGMENTS {
let pipeline = RenderPipelineSpec::new(COVER, fragment, &COLORS);
inputs.push(Input::bytes(
format!("{fragment}/pipeline"),
&pipeline.words(),
));
inputs.push(Input::bytes(
format!("{fragment}/buffer:0"),
&values(fragment),
));
}
for format in FORMATS {
inputs.push(Input::bytes(format.name(), &request(format).words()));
}
Ok(inputs)
}
fn run(&self, side: &mut dyn Side, sites: &mut Sites) -> Result<(), Abort> {
let loaded = Fixture::new(FIXTURE).loaded().map_err(|why| Abort {
at: "library".to_owned(),
failure: Failure::named("FixtureNotRead", why),
})?;
let library = made(sites, "library", side.library(&loaded.source()))?;
let shape = made(sites, "buffer/width", side.buffer(&width_bytes()))?;
for fragment in FRAGMENTS {
let pipeline = made(
sites,
&format!("{fragment}/pipeline"),
side.render_pipeline(library, &RenderPipelineSpec::new(COVER, fragment, &COLORS)),
)?;
let values = made(
sites,
&format!("{fragment}/buffer/0"),
side.buffer(&values(fragment)),
)?;
for format in FORMATS {
let at = |site: &str| format!("{}/{fragment}/{site}", format.name());
let texture = made(sites, &at("texture"), side.texture(&request(format)))?;
let into = made(sites, &at("attachment"), side.target(&attachment()))?;
let steps = vec![
RenderStep::Pipeline(pipeline),
RenderStep::FragmentTexture { texture, index: 0 },
RenderStep::FragmentBuffer {
buffer: values,
offset: 0,
index: 0,
},
RenderStep::FragmentBuffer {
buffer: shape,
offset: 0,
index: 1,
},
RenderStep::Draw {
primitive: PrimitiveType::Triangle,
first: 0,
count: 3,
instances: 1,
},
];
let pass = RenderWork::Pass(
RenderPass::clearing(vec![PassColor::cleared(into, [0.0; 4])]).drawing(steps),
);
let outcome = call(sites, &at("draw"), side.render(&[pass]), |outcome| {
outcome.status.clone()
})?;
let refused = outcome.refused.first().and_then(Option::as_ref);
sites.push(Node::leaf(
at("pass"),
Observed::value(match refused {
Some(failure) => failure.recorded(),
None => Value::ok(Value::Absent),
}),
));
if let Some(failure) = refused {
return Err(Abort {
at: at("pass"),
failure: failure.clone(),
});
}
let stored = call(
sites,
&at("texels"),
side.read_texture(texture, [WIDTH, HEIGHT], WIDTH * 4),
|_| Value::Absent,
)?;
sites.push(Node::leaf(
at("stored"),
Observed::bytes(stored, stored_layout()),
));
}
}
Ok(())
}
}
@@ -35,8 +35,9 @@ const FIXTURE: &str = "fpv_srgb_storage";
/// The kernels the case runs: a `float4` write and a `half4` write.
const KERNELS: [&str; 2] = ["fpv_srgb_write", "fpv_srgb_write_half"];
/// The formats the case writes.
const FORMATS: [PixelFormat; 2] = [PixelFormat::RGBA8UnormSRGB, PixelFormat::BGRA8UnormSRGB];
/// The formats the case, and its fragment twin, write.
pub(crate) const FORMATS: [PixelFormat; 2] =
[PixelFormat::RGBA8UnormSRGB, PixelFormat::BGRA8UnormSRGB];
/// The texture's width, which buffer 1 holds.
pub const WIDTH: u32 = 256;
@@ -86,9 +87,11 @@ pub fn texels() -> Vec<[f32; 4]> {
out
}
/// Buffer 0's bytes for `kernel`: each texel's `float4`, or its `half4`.
fn values(kernel: &str) -> Vec<u8> {
let half = kernel.ends_with("_half");
/// Buffer 0's bytes for `function`, a kernel here or a fragment function of the fragment twin
/// (`srgb-storage-fragment-writes`): each texel's `float4`, or its `half4` where the name ends in
/// `_half`.
pub(crate) fn values(function: &str) -> Vec<u8> {
let half = function.ends_with("_half");
let mut bytes = Vec::new();
for value in texels().into_iter().flatten() {
match half {
@@ -100,17 +103,17 @@ fn values(kernel: &str) -> Vec<u8> {
}
/// Buffer 1's bytes: the row's width, as the kernels' `constant uint &width`.
fn width_bytes() -> Vec<u8> {
pub(crate) fn width_bytes() -> Vec<u8> {
WIDTH.to_le_bytes().to_vec()
}
/// The texture a sweep writes: shared storage, written by shaders alone.
fn request(format: PixelFormat) -> TextureRequest<'static> {
pub(crate) fn request(format: PixelFormat) -> TextureRequest<'static> {
TextureRequest::read_2d(format.as_raw(), WIDTH, HEIGHT).used(TextureUsage::SHADER_WRITE)
}
/// The layout the stored bytes are read under: one row a texel row, one code a channel.
fn stored_layout() -> ByteLayout {
pub(crate) fn stored_layout() -> ByteLayout {
let pitch = WIDTH * 4;
ByteLayout {
region: Region::Texture {
@@ -17,7 +17,18 @@
//! texture, lowers nothing; filled past a cap of 2, the map holds 2, and a variant it forgot
//! is lowered again at its kernel's next dispatch onto a twin (on a device whose textures have
//! their twins' storage views). It prints the translation time of the float kernel's state and
//! of its variant.
//! of its variant;
//! - a draw whose vertex or fragment function writes such a texture at a slot it does not read
//! runs the render state's sRGB variant: through the owned fixture `fpv_srgb_draw_storage`'s
//! `fpv_srgb_fragment_write` and `fpv_srgb_fragment_write_half` behind `fpv_srgb_cover`'s one
//! triangle over a [`WIDTH`] by 1 `RGBA8Unorm` attachment, and its `fpv_srgb_vertex_write` of
//! [`WIDTH`] points with rasterization off, each state's notes hold
//! `PrecisionNote::DevicePackConversion` from its creation, the texture's bytes hold the encode
//! as a kernel's do, and the variant is lowered once, at the state's first draw onto a twin
//! (`Metrics::translations_at_encode` rises by one), the draw onto the other format's twin and
//! one onto an `RGBA8Unorm` texture lowering nothing; where the texture has no twin's storage
//! view the draw is `Gap::StorageElement` of slot 0, `StorageElementCase::Absent`. It prints,
//! per device and function, the variant's make and the largest distance from the MSL encode.
//!
//! `llvm-as` assembles the fixture; without it the tests skip visibly.
@@ -27,10 +38,11 @@ mod on_device {
use crate::tests::draw::on_device::Buffers;
use crate::texture::TextureObject;
use crate::{
Buffer, ComputePipelineDescriptor, ComputePipelineState, Device, DispatchType, Error,
FunctionDescriptor, Gap, IndexClass, Library, PixelFormat, PrecisionNote, Region,
StageSource, StorageElementCase, StorageMode, Texture, TextureDescriptor, TextureType,
TextureUsage,
Buffer, ColorAttachmentDescriptor, ComputePipelineDescriptor, ComputePipelineState, Device,
DispatchType, Error, FunctionDescriptor, Gap, IndexClass, Library, LoadAction, PixelFormat,
PrecisionNote, PrimitiveType, Region, RenderPassDescriptor, RenderPipelineDescriptor,
RenderPipelineState, StageSource, StorageElementCase, StorageMode, Texture,
TextureDescriptor, TextureType, TextureUsage,
};
use ash::vk;
use metal2vulkan_devtools::{engine_dir, llvm_assemble, AssembleError};
@@ -53,15 +65,20 @@ mod on_device {
),
];
/// The fixture's library, or None where `llvm-as` is missing.
/// The kernels' fixture's library, or None where `llvm-as` is missing.
fn library() -> Option<Library> {
match llvm_assemble(&engine_dir().join("fpv_srgb_storage.ll")) {
fixture("fpv_srgb_storage")
}
/// The library of the owned fixture `name`, or None where `llvm-as` is missing.
fn fixture(name: &str) -> Option<Library> {
match llvm_assemble(&engine_dir().join(format!("{name}.ll"))) {
Ok(bitcode) => Some(Library::from_air(&bitcode).expect("the library")),
Err(AssembleError::Missing(why)) => {
eprintln!("SKIPPED: {why}");
None
}
Err(error) => panic!("fpv_srgb_storage.ll: {error:?}"),
Err(error) => panic!("{name}.ll: {error:?}"),
}
}
@@ -342,4 +359,191 @@ mod on_device {
);
});
}
/// The draw fixture's functions: each fragment writer drawn behind the cover, and the vertex
/// writer alone with rasterization off.
const DRAWN: [(&str, Option<&str>); 3] = [
("fpv_srgb_cover", Some("fpv_srgb_fragment_write")),
("fpv_srgb_cover", Some("fpv_srgb_fragment_write_half")),
("fpv_srgb_vertex_write", None),
];
/// The state of `vertex` with `fragment`, or with rasterization off where there is none, over
/// one `RGBA8Unorm` colour attachment.
fn render_state(
name: &str,
device: &Device,
library: &Library,
(vertex, fragment): (&str, Option<&str>),
) -> RenderPipelineState {
let function = |entry| {
StageSource::Function(FunctionDescriptor::new(
library.function(entry).expect("the function"),
))
};
let mut d = RenderPipelineDescriptor::new(function(vertex));
d.fragment = fragment.map(function);
d.rasterization_enabled = fragment.is_some();
d.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm));
(device.new_render_pipeline_state(&d, crate::tests::no_constexpr_samplers))
.unwrap_or_else(|error| panic!("{name}: {vertex} + {fragment:?}: {error}"))
}
/// One draw of `state` into a [`WIDTH`] by 1 `RGBA8Unorm` attachment, with `texture` at slot
/// 0, `values` at buffer 0 and `width` at buffer 1 of the function that writes (the fragment
/// function where `fragment`, else the vertex function): the cover's triangle, or [`WIDTH`]
/// points; committed and finished, the encoder's answer.
fn draw(
device: &Device,
(state, fragment): (&RenderPipelineState, bool),
texture: &Texture,
values: &Buffer,
width: &Buffer,
) -> Result<(), Error> {
let mut td = TextureDescriptor::new(TextureType::Type2D, PixelFormat::RGBA8Unorm, WIDTH, 1);
td.usage = TextureUsage::RENDER_TARGET;
td.storage_mode = StorageMode::Private;
let attachment = (device.new_texture_for_views(&td)).expect("an attachment");
let mut d = RenderPassDescriptor::default();
let c = &mut d.color_attachments[0];
c.texture = Some(attachment);
c.load_action = LoadAction::Clear;
let queue = device.new_command_queue(1).expect("a queue");
let command_buffer = queue.command_buffer().expect("a command buffer");
let mut encoder = (command_buffer.render_command_encoder(&d)).expect("an encoder");
encoder.set_render_pipeline_state(state).expect("the state");
let drawn = match fragment {
true => {
encoder
.set_fragment_texture(Some(texture), 0)
.expect("a texture");
encoder
.set_fragment_buffer(Some(values), 0, 0)
.expect("a buffer");
encoder
.set_fragment_buffer(Some(width), 0, 1)
.expect("a buffer");
encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0)
}
false => {
encoder
.set_vertex_texture(Some(texture), 0)
.expect("a texture");
encoder
.set_vertex_buffer(Some(values), 0, 0)
.expect("a buffer");
encoder
.set_vertex_buffer(Some(width), 0, 1)
.expect("a buffer");
encoder.draw_primitives(PrimitiveType::Point, 0, WIDTH, 1, 0)
}
};
encoder.end_encoding();
command_buffer.commit().expect("a commit");
finished("sRGB draws", &command_buffer);
assert_eq!(command_buffer.error(), None);
drawn
}
#[test]
fn every_device_draws_an_8_bit_srgb_texture_through_its_unorm_twin_encoded() {
let Some(library) = fixture("fpv_srgb_draw_storage") else {
return;
};
each_device("sRGB draws", |name, _, device| {
let _grant = (device.grant_indices(IndexClass::Texture, 1, 3))
.unwrap_or_else(|error| panic!("{name}: {error}"));
let textures: Vec<Texture> = (FORMATS.iter().enumerate())
.map(|(at, &(format, ..))| texture(name, &device, format, 1 + at as u32))
.collect();
let unorm = texture(name, &device, PixelFormat::RGBA8Unorm, 3);
let counters = device.counters();
let at_encode = || counters.metrics().translations_at_encode;
let mut buffers = Buffers::new(&device);
let width = buffers.of(&device, &WIDTH.to_le_bytes());
for functions in DRAWN {
let (vertex, fragment) = functions;
let writer = fragment.unwrap_or(vertex);
let state = render_state(name, &device, &library, functions);
let (bytes, taken) = written(writer);
let values = buffers.of(&device, &bytes);
let made = at_encode();
let mut off = 0.0f64;
let mut twins = 0;
for (texture, (format, _, order)) in textures.iter().zip(FORMATS) {
let drawn = draw(
&device,
(&state, fragment.is_some()),
texture,
&values,
&width,
);
match (texture.encodes(), drawn) {
(true, Ok(())) => twins += 1,
(
false,
Err(Error::Unsupported(Gap::StorageElement {
slot: Some(0),
pixel_format,
case: StorageElementCase::Absent,
..
})),
) if pixel_format == format => {
println!("{name}: {format:?}: {writer}: no twin, refused");
continue;
}
(encodes, other) => {
panic!("{name}: {format:?}: {writer}, a twin {encodes}: {other:?}")
}
}
let mut stored = vec![0; WIDTH as usize * 4];
let region = Region {
origin: [0; 3],
size: [WIDTH, 1, 1],
};
let pitch = u64::from(WIDTH) * 4;
(texture.get_bytes(&mut stored, pitch, pitch, region, 0, 0))
.unwrap_or_else(|error| panic!("{name}: {format:?}: {error}"));
for (i, value) in taken.iter().enumerate() {
for (channel, &byte) in order.iter().enumerate() {
let want = code(value[channel], channel == 3);
let got = f64::from(stored[i * 4 + byte]);
assert!(
(got - want).abs() <= 1.0,
"{name}: {format:?}: {writer}: texel {i} channel {channel}: \
{value:?} stored {got}, the encode {want}"
);
off = off.max((got - want).abs());
}
}
}
// The plain texture draws through the state's own content.
(draw(
&device,
(&state, fragment.is_some()),
&unorm,
&values,
&width,
))
.unwrap_or_else(|error| panic!("{name}: RGBA8Unorm: {writer}: {error}"));
assert!(
(state.precision_notes()).contains(&PrecisionNote::DevicePackConversion),
"{name}: {writer}: the note"
);
let makes = at_encode() - made;
assert_eq!(
makes,
u64::from(twins > 0),
"{name}: {writer}: one variant made at the first draw onto a twin, kept"
);
if twins > 0 {
println!(
"{name}: {writer}: drawn through the render state's sRGB variant onto \
{twins} twins ({makes} make at encode), every code within {off} of the \
MSL encode"
);
}
}
});
}
}
@@ -127,6 +127,7 @@ fixture fpc_frames: metal: Apple metal version 32023.921 (metalfe-32023.921.6);
fixture fpc_pointer_functions: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425)
fixture fpv_bfloat_textures: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425)
fixture fpv_rgbx_textures: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425)
fixture fpv_srgb_draw_storage: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118)
fixture fpv_srgb_storage: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425)
fixture fpv_swizzled_reads: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425)
fixture fragment_discard_counts: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425)
@@ -0,0 +1,168 @@
; Generated by scripts/regen-air-fixtures from fpv_srgb_draw_storage.metal (typed pointers; xcrun metal-as reassembles it). Do not edit.
; ModuleID = '-'
source_filename = "-"
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32"
target triple = "air64_v28-apple-macosx26.0.0"
%struct._texture_2d_t = type opaque
; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn
define <{ <4 x float> }> @fpv_srgb_cover(i32 noundef %0) local_unnamed_addr #0 {
%2 = shl i32 %0, 2
%3 = and i32 %2, 4
%4 = tail call fast float @air.convert.f.f32.u.i32(i32 %3) #4
%5 = insertelement <2 x float> undef, float %4, i64 0
%6 = shl i32 %0, 1
%7 = and i32 %6, 4
%8 = tail call fast float @air.convert.f.f32.u.i32(i32 %7) #4
%9 = insertelement <2 x float> %5, float %8, i64 1
%10 = fadd fast <2 x float> %9, <float -1.000000e+00, float -1.000000e+00>
%11 = shufflevector <2 x float> %10, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
%12 = shufflevector <4 x float> %11, <4 x float> <float poison, float poison, float 0.000000e+00, float 1.000000e+00>, <4 x i32> <i32 0, i32 1, i32 6, i32 7>
%13 = insertvalue <{ <4 x float> }> undef, <4 x float> %12, 0
ret <{ <4 x float> }> %13
}
; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn
declare float @air.convert.f.f32.u.i32(i32) local_unnamed_addr #1
; Function Attrs: mustprogress nounwind willreturn
define <4 x float> @fpv_srgb_fragment_write(<4 x float> %0, %struct._texture_2d_t addrspace(1)* %1, <4 x float> addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %2, i32 addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %3) local_unnamed_addr #2 {
%5 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> <i32 0, i32 1>
%6 = tail call <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float> %5) #4
%7 = extractelement <2 x i32> %6, i64 1
%8 = load i32, i32 addrspace(2)* %3, align 4, !tbaa !35, !alias.scope !39, !noalias !42
%9 = mul i32 %7, %8
%10 = extractelement <2 x i32> %6, i64 0
%11 = add i32 %9, %10
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %2, i64 %12
%14 = load <4 x float>, <4 x float> addrspace(1)* %13, align 16, !tbaa !45, !alias.scope !46, !noalias !47
tail call void @air.write_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture %1, <2 x i32> %6, <4 x float> %14, i32 0, i32 2) #5, !alias.scope !48, !noalias !49
ret <4 x float> zeroinitializer
}
; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn
declare <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float>) local_unnamed_addr #1
; Function Attrs: mustprogress nounwind willreturn
define <4 x float> @fpv_srgb_fragment_write_half(<4 x float> %0, %struct._texture_2d_t addrspace(1)* %1, <4 x half> addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %2, i32 addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %3) local_unnamed_addr #2 {
%5 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> <i32 0, i32 1>
%6 = tail call <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float> %5) #4
%7 = extractelement <2 x i32> %6, i64 1
%8 = load i32, i32 addrspace(2)* %3, align 4, !tbaa !35, !alias.scope !50, !noalias !53
%9 = mul i32 %7, %8
%10 = extractelement <2 x i32> %6, i64 0
%11 = add i32 %9, %10
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds <4 x half>, <4 x half> addrspace(1)* %2, i64 %12
%14 = load <4 x half>, <4 x half> addrspace(1)* %13, align 8, !tbaa !45, !alias.scope !56, !noalias !57
tail call void @air.write_texture_2d.v4f16(%struct._texture_2d_t addrspace(1)* nocapture %1, <2 x i32> %6, <4 x half> %14, i32 0, i32 2) #5, !alias.scope !58, !noalias !59
ret <4 x float> zeroinitializer
}
; Function Attrs: mustprogress nounwind willreturn
define void @fpv_srgb_vertex_write(i32 noundef %0, %struct._texture_2d_t addrspace(1)* %1, <4 x float> addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %2, i32 addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %3) local_unnamed_addr #2 {
%5 = zext i32 %0 to i64
%6 = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %2, i64 %5
%7 = load <4 x float>, <4 x float> addrspace(1)* %6, align 16, !tbaa !45, !alias.scope !60, !noalias !63
%8 = load i32, i32 addrspace(2)* %3, align 4, !tbaa !35, !alias.scope !66, !noalias !67
%9 = urem i32 %0, %8
%10 = insertelement <2 x i32> undef, i32 %9, i64 0
%11 = udiv i32 %0, %8
%12 = insertelement <2 x i32> %10, i32 %11, i64 1
tail call void @air.write_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture %1, <2 x i32> %12, <4 x float> %7, i32 0, i32 2) #5, !alias.scope !68, !noalias !69
ret void
}
; Function Attrs: argmemonly mustprogress nounwind willreturn
declare void @air.write_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture, <2 x i32>, <4 x float>, i32, i32) local_unnamed_addr #3
; Function Attrs: argmemonly mustprogress nounwind willreturn
declare void @air.write_texture_2d.v4f16(%struct._texture_2d_t addrspace(1)* nocapture, <2 x i32>, <4 x half>, i32, i32) local_unnamed_addr #3
attributes #0 = { mustprogress nofree nosync nounwind readnone willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #1 = { mustprogress nofree nosync nounwind readnone willreturn }
attributes #2 = { mustprogress nounwind willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #3 = { argmemonly mustprogress nounwind willreturn }
attributes #4 = { nounwind readnone willreturn }
attributes #5 = { argmemonly nounwind willreturn }
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8}
!air.vertex = !{!9, !14}
!air.fragment = !{!20, !25}
!air.compile_options = !{!29, !30, !31}
!llvm.ident = !{!32}
!air.version = !{!33}
!air.language_version = !{!34}
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]}
!1 = !{i32 1, !"wchar_size", i32 4}
!2 = !{i32 7, !"frame-pointer", i32 2}
!3 = !{i32 7, !"air.max_device_buffers", i32 31}
!4 = !{i32 7, !"air.max_constant_buffers", i32 31}
!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31}
!6 = !{i32 7, !"air.max_textures", i32 128}
!7 = !{i32 7, !"air.max_read_write_textures", i32 8}
!8 = !{i32 7, !"air.max_samplers", i32 16}
!9 = !{<{ <4 x float> }> (i32)* @fpv_srgb_cover, !10, !12}
!10 = !{!11}
!11 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"}
!12 = !{!13}
!13 = !{i32 0, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"}
!14 = !{void (i32, %struct._texture_2d_t addrspace(1)*, <4 x float> addrspace(1)*, i32 addrspace(2)*)* @fpv_srgb_vertex_write, !15, !16}
!15 = !{}
!16 = !{!13, !17, !18, !19}
!17 = !{i32 1, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.write", !"air.arg_type_name", !"texture2d<float, write>", !"air.arg_name", !"t"}
!18 = !{i32 2, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"float4", !"air.arg_name", !"values"}
!19 = !{i32 3, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 1, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"width"}
!20 = !{<4 x float> (<4 x float>, %struct._texture_2d_t addrspace(1)*, <4 x float> addrspace(1)*, i32 addrspace(2)*)* @fpv_srgb_fragment_write, !21, !23}
!21 = !{!22}
!22 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"float4"}
!23 = !{!24, !17, !18, !19}
!24 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"}
!25 = !{<4 x float> (<4 x float>, %struct._texture_2d_t addrspace(1)*, <4 x half> addrspace(1)*, i32 addrspace(2)*)* @fpv_srgb_fragment_write_half, !21, !26}
!26 = !{!24, !27, !28, !19}
!27 = !{i32 1, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.write", !"air.arg_type_name", !"texture2d<half, write>", !"air.arg_name", !"t"}
!28 = !{i32 2, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 8, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"half4", !"air.arg_name", !"values"}
!29 = !{!"air.compile.denorms_disable"}
!30 = !{!"air.compile.fast_math_enable"}
!31 = !{!"air.compile.framebuffer_fetch_enable"}
!32 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"}
!33 = !{i32 2, i32 8, i32 0}
!34 = !{!"Metal", i32 4, i32 0, i32 0}
!35 = !{!36, !36, i64 0}
!36 = !{!"int", !37, i64 0}
!37 = !{!"omnipotent char", !38, i64 0}
!38 = !{!"Simple C++ TBAA"}
!39 = !{!40}
!40 = distinct !{!40, !41, !"air-alias-scope-arg(3)"}
!41 = distinct !{!41, !"air-alias-scopes(fpv_srgb_fragment_write)"}
!42 = !{!43, !44}
!43 = distinct !{!43, !41, !"air-alias-scope-textures"}
!44 = distinct !{!44, !41, !"air-alias-scope-arg(2)"}
!45 = !{!37, !37, i64 0}
!46 = !{!44}
!47 = !{!43, !40}
!48 = !{!43}
!49 = !{!44, !40}
!50 = !{!51}
!51 = distinct !{!51, !52, !"air-alias-scope-arg(3)"}
!52 = distinct !{!52, !"air-alias-scopes(fpv_srgb_fragment_write_half)"}
!53 = !{!54, !55}
!54 = distinct !{!54, !52, !"air-alias-scope-textures"}
!55 = distinct !{!55, !52, !"air-alias-scope-arg(2)"}
!56 = !{!55}
!57 = !{!54, !51}
!58 = !{!54}
!59 = !{!55, !51}
!60 = !{!61}
!61 = distinct !{!61, !62, !"air-alias-scope-arg(2)"}
!62 = distinct !{!62, !"air-alias-scopes(fpv_srgb_vertex_write)"}
!63 = !{!64, !65}
!64 = distinct !{!64, !62, !"air-alias-scope-textures"}
!65 = distinct !{!65, !62, !"air-alias-scope-arg(3)"}
!66 = !{!65}
!67 = !{!64, !61}
!68 = !{!64}
!69 = !{!61, !65}
@@ -0,0 +1,166 @@
; Generated by scripts/regen-air-fixtures from fpv_srgb_draw_storage.metal (llvm-dis of fpv_srgb_draw_storage.air). Do not edit.
; ModuleID = '<stdin>'
source_filename = "-"
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32"
target triple = "air64_v28-apple-macosx26.0.0"
; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
define <{ <4 x float> }> @fpv_srgb_cover(i32 noundef %0) local_unnamed_addr #0 {
%2 = shl i32 %0, 2
%3 = and i32 %2, 4
%4 = tail call fast float @air.convert.f.f32.u.i32(i32 %3) #4
%5 = insertelement <2 x float> undef, float %4, i64 0
%6 = shl i32 %0, 1
%7 = and i32 %6, 4
%8 = tail call fast float @air.convert.f.f32.u.i32(i32 %7) #4
%9 = insertelement <2 x float> %5, float %8, i64 1
%10 = fadd fast <2 x float> %9, splat (float -1.000000e+00)
%11 = shufflevector <2 x float> %10, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
%12 = shufflevector <4 x float> %11, <4 x float> <float poison, float poison, float 0.000000e+00, float 1.000000e+00>, <4 x i32> <i32 0, i32 1, i32 6, i32 7>
%13 = insertvalue <{ <4 x float> }> undef, <4 x float> %12, 0
ret <{ <4 x float> }> %13
}
; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare float @air.convert.f.f32.u.i32(i32) local_unnamed_addr #1
; Function Attrs: mustprogress nounwind willreturn
define <4 x float> @fpv_srgb_fragment_write(<4 x float> %0, ptr addrspace(1) %1, ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %2, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %3) local_unnamed_addr #2 {
%5 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> <i32 0, i32 1>
%6 = tail call <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float> %5) #4
%7 = extractelement <2 x i32> %6, i64 1
%8 = load i32, ptr addrspace(2) %3, align 4, !tbaa !35, !alias.scope !39, !noalias !42
%9 = mul i32 %7, %8
%10 = extractelement <2 x i32> %6, i64 0
%11 = add i32 %9, %10
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds <4 x float>, ptr addrspace(1) %2, i64 %12
%14 = load <4 x float>, ptr addrspace(1) %13, align 16, !tbaa !45, !alias.scope !46, !noalias !47
tail call void @air.write_texture_2d.v4f32(ptr addrspace(1) captures(none) %1, <2 x i32> %6, <4 x float> %14, i32 0, i32 2) #5, !alias.scope !48, !noalias !49
ret <4 x float> zeroinitializer
}
; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float>) local_unnamed_addr #1
; Function Attrs: mustprogress nounwind willreturn
define <4 x float> @fpv_srgb_fragment_write_half(<4 x float> %0, ptr addrspace(1) %1, ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %2, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %3) local_unnamed_addr #2 {
%5 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> <i32 0, i32 1>
%6 = tail call <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float> %5) #4
%7 = extractelement <2 x i32> %6, i64 1
%8 = load i32, ptr addrspace(2) %3, align 4, !tbaa !35, !alias.scope !50, !noalias !53
%9 = mul i32 %7, %8
%10 = extractelement <2 x i32> %6, i64 0
%11 = add i32 %9, %10
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds <4 x half>, ptr addrspace(1) %2, i64 %12
%14 = load <4 x half>, ptr addrspace(1) %13, align 8, !tbaa !45, !alias.scope !56, !noalias !57
tail call void @air.write_texture_2d.v4f16(ptr addrspace(1) captures(none) %1, <2 x i32> %6, <4 x half> %14, i32 0, i32 2) #5, !alias.scope !58, !noalias !59
ret <4 x float> zeroinitializer
}
; Function Attrs: mustprogress nounwind willreturn
define void @fpv_srgb_vertex_write(i32 noundef %0, ptr addrspace(1) %1, ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %2, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %3) local_unnamed_addr #2 {
%5 = zext i32 %0 to i64
%6 = getelementptr inbounds <4 x float>, ptr addrspace(1) %2, i64 %5
%7 = load <4 x float>, ptr addrspace(1) %6, align 16, !tbaa !45, !alias.scope !60, !noalias !63
%8 = load i32, ptr addrspace(2) %3, align 4, !tbaa !35, !alias.scope !66, !noalias !67
%9 = urem i32 %0, %8
%10 = insertelement <2 x i32> undef, i32 %9, i64 0
%11 = udiv i32 %0, %8
%12 = insertelement <2 x i32> %10, i32 %11, i64 1
tail call void @air.write_texture_2d.v4f32(ptr addrspace(1) captures(none) %1, <2 x i32> %12, <4 x float> %7, i32 0, i32 2) #5, !alias.scope !68, !noalias !69
ret void
}
; Function Attrs: mustprogress nounwind willreturn memory(argmem: readwrite)
declare void @air.write_texture_2d.v4f32(ptr addrspace(1) captures(none), <2 x i32>, <4 x float>, i32, i32) local_unnamed_addr #3
; Function Attrs: mustprogress nounwind willreturn memory(argmem: readwrite)
declare void @air.write_texture_2d.v4f16(ptr addrspace(1) captures(none), <2 x i32>, <4 x half>, i32, i32) local_unnamed_addr #3
attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(none) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #1 = { mustprogress nofree nosync nounwind willreturn memory(none) }
attributes #2 = { mustprogress nounwind willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #3 = { mustprogress nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind willreturn memory(none) }
attributes #5 = { nounwind willreturn memory(argmem: readwrite) }
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8}
!air.vertex = !{!9, !14}
!air.fragment = !{!20, !25}
!air.compile_options = !{!29, !30, !31}
!llvm.ident = !{!32}
!air.version = !{!33}
!air.language_version = !{!34}
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]}
!1 = !{i32 1, !"wchar_size", i32 4}
!2 = !{i32 7, !"frame-pointer", i32 2}
!3 = !{i32 7, !"air.max_device_buffers", i32 31}
!4 = !{i32 7, !"air.max_constant_buffers", i32 31}
!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31}
!6 = !{i32 7, !"air.max_textures", i32 128}
!7 = !{i32 7, !"air.max_read_write_textures", i32 8}
!8 = !{i32 7, !"air.max_samplers", i32 16}
!9 = !{ptr @fpv_srgb_cover, !10, !12}
!10 = !{!11}
!11 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"}
!12 = !{!13}
!13 = !{i32 0, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"}
!14 = !{ptr @fpv_srgb_vertex_write, !15, !16}
!15 = !{}
!16 = !{!13, !17, !18, !19}
!17 = !{i32 1, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.write", !"air.arg_type_name", !"texture2d<float, write>", !"air.arg_name", !"t"}
!18 = !{i32 2, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"float4", !"air.arg_name", !"values"}
!19 = !{i32 3, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 1, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"width"}
!20 = !{ptr @fpv_srgb_fragment_write, !21, !23}
!21 = !{!22}
!22 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"float4"}
!23 = !{!24, !17, !18, !19}
!24 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"}
!25 = !{ptr @fpv_srgb_fragment_write_half, !21, !26}
!26 = !{!24, !27, !28, !19}
!27 = !{i32 1, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.write", !"air.arg_type_name", !"texture2d<half, write>", !"air.arg_name", !"t"}
!28 = !{i32 2, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 8, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"half4", !"air.arg_name", !"values"}
!29 = !{!"air.compile.denorms_disable"}
!30 = !{!"air.compile.fast_math_enable"}
!31 = !{!"air.compile.framebuffer_fetch_enable"}
!32 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"}
!33 = !{i32 2, i32 8, i32 0}
!34 = !{!"Metal", i32 4, i32 0, i32 0}
!35 = !{!36, !36, i64 0}
!36 = !{!"int", !37, i64 0}
!37 = !{!"omnipotent char", !38, i64 0}
!38 = !{!"Simple C++ TBAA"}
!39 = !{!40}
!40 = distinct !{!40, !41, !"air-alias-scope-arg(3)"}
!41 = distinct !{!41, !"air-alias-scopes(fpv_srgb_fragment_write)"}
!42 = !{!43, !44}
!43 = distinct !{!43, !41, !"air-alias-scope-textures"}
!44 = distinct !{!44, !41, !"air-alias-scope-arg(2)"}
!45 = !{!37, !37, i64 0}
!46 = !{!44}
!47 = !{!43, !40}
!48 = !{!43}
!49 = !{!44, !40}
!50 = !{!51}
!51 = distinct !{!51, !52, !"air-alias-scope-arg(3)"}
!52 = distinct !{!52, !"air-alias-scopes(fpv_srgb_fragment_write_half)"}
!53 = !{!54, !55}
!54 = distinct !{!54, !52, !"air-alias-scope-textures"}
!55 = distinct !{!55, !52, !"air-alias-scope-arg(2)"}
!56 = !{!55}
!57 = !{!54, !51}
!58 = !{!54}
!59 = !{!55, !51}
!60 = !{!61}
!61 = distinct !{!61, !62, !"air-alias-scope-arg(2)"}
!62 = distinct !{!62, !"air-alias-scopes(fpv_srgb_vertex_write)"}
!63 = !{!64, !65}
!64 = distinct !{!64, !62, !"air-alias-scope-textures"}
!65 = distinct !{!65, !62, !"air-alias-scope-arg(3)"}
!66 = !{!65}
!67 = !{!64, !61}
!68 = !{!64}
!69 = !{!61, !65}