diff --git a/crates/metal2vulkan-conformance/known-gaps-rt.tsv b/crates/metal2vulkan-conformance/known-gaps-rt.tsv index 18f27f149..a549e0beb 100644 --- a/crates/metal2vulkan-conformance/known-gaps-rt.tsv +++ b/crates/metal2vulkan-conformance/known-gaps-rt.tsv @@ -7676,7 +7676,7 @@ texture-pairs-usage-crossings * divergent case/MTLPixelFormatRGBA8Unorm/Type2D/6 texture-pairs-usage-crossings * divergent case/MTLPixelFormatRGBA8Unorm/Type2D/64x64x1/levels-7/samples-1/slices-1/usage-0x8/private/texture/usage Metal 0 (0x0), ours 8 (0x8) rt has no usage getter; the site reads descriptor().usage, the descriptor as given; rt takes no bits as every usage wherever it acts. texture-pairs-usage-crossings * divergent case/MTLPixelFormatRGBA8Unorm/Type3D/64x64x8/levels-1/samples-1/slices-1/usage-0x0/private/texture/usage Metal 23 (0x17), ours 0 (0x0) rt has no usage getter; the site reads descriptor().usage, the descriptor as given; rt takes no bits as every usage wherever it acts. texture-pairs-usage-crossings * divergent case/MTLPixelFormatRGBA8Unorm/Type3D/64x64x8/levels-1/samples-1/slices-1/usage-0x8/private/texture/usage Metal 0 (0x0), ours 8 (0x8) rt has no usage getter; the site reads descriptor().usage, the descriptor as given; rt takes no bits as every usage wherever it acts. -bicubic-texel-classes * refused case/rgba8unorm-srgb/dispatch Err(Error::Unsupported("texture slot 0, which a kernel samples through a bicubic filter, bound to a RGBA8UnormSRGB texture, whose bicubic sample is not built")) Known gap (the rt README, Known gaps of textures): a kernel's bicubic constexpr sample of a texture of 8-bit sRGB codes is `Gap::BicubicTexels`, naming the slot and the format. Metal sums the decoded taps; the runtime holds the texture as an sRGB image and builds no bicubic sample of it. The fix belongs in the bicubic routine's sRGB arm (`lower::sampler::bicubic`), built when a stream binds one. +bicubic-texel-classes * refused case/rgba8unorm-srgb/dispatch Err(Error::Unsupported("texture slot 0, which a function samples through a bicubic filter, bound to a RGBA8UnormSRGB texture, whose bicubic sample is not built")) Known gap (the rt README, Known gaps of textures): a function's bicubic constexpr sample of a texture of 8-bit sRGB codes is `Gap::BicubicTexels`, naming the slot and the format. Metal sums the decoded taps; the runtime holds the texture as an sRGB image and builds no bicubic sample of it. The fix belongs in the bicubic routine's sRGB arm (`lower::sampler::bicubic`), built when a stream binds one. bicubic-texel-classes llvmpipe (LLVM 23.1.1, 256 bits) divergent case/mixed/sampled 470 elements differ (F32), the largest difference 0.00040435791015625 The device's arithmetic under the static note `bicubic-filter-arithmetic` (rule 1), within its stated bound. Metal's results lie on the format's grid: a sixteenth of a code for the 8-bit classes, a whole code for `RGBA16Unorm`, an exact `half` for `RGBA16Float`; at the six `RGBA16Float` samples where the sum is exactly halfway between two halves, Metal rounds away from zero. Ours is the unrounded `f32` sum of the sixteen decoded taps (the 2D routine, `lower::sampler::bicubic::routines`, `Plane`), and a `half` result is the device's narrowing of it. Every class takes Metal's arm, which the case's own tests hold in Metal's recording: `R32Float` the inner bilinear taps, which compare exactly; the clamp into [0, 1] of the unsigned normalized formats and into [-1, 1] of `RGBA8Snorm`; no clamp of `RGBA16Float`. Open: nothing; the difference is within Metal's precision, which rule 1 leaves to the note. bicubic-texel-classes llvmpipe (LLVM 23.1.1, 256 bits) divergent case/r8unorm/sampled 70 elements differ (F32), the largest difference 0.000152587890625 The device's arithmetic under the static note `bicubic-filter-arithmetic` (rule 1), within its stated bound. Metal's results lie on the format's grid: a sixteenth of a code for the 8-bit classes, a whole code for `RGBA16Unorm`, an exact `half` for `RGBA16Float`; at the six `RGBA16Float` samples where the sum is exactly halfway between two halves, Metal rounds away from zero. Ours is the unrounded `f32` sum of the sixteen decoded taps (the 2D routine, `lower::sampler::bicubic::routines`, `Plane`), and a `half` result is the device's narrowing of it. Every class takes Metal's arm, which the case's own tests hold in Metal's recording: `R32Float` the inner bilinear taps, which compare exactly; the clamp into [0, 1] of the unsigned normalized formats and into [-1, 1] of `RGBA8Snorm`; no clamp of `RGBA16Float`. Open: nothing; the difference is within Metal's precision, which rule 1 leaves to the note. bicubic-texel-classes llvmpipe (LLVM 23.1.1, 256 bits) divergent case/rgba16float/sampled 610 elements differ (F32), the largest difference 0.00037384033203125 The device's arithmetic under the static note `bicubic-filter-arithmetic` (rule 1), within its stated bound. Metal's results lie on the format's grid: a sixteenth of a code for the 8-bit classes, a whole code for `RGBA16Unorm`, an exact `half` for `RGBA16Float`; at the six `RGBA16Float` samples where the sum is exactly halfway between two halves, Metal rounds away from zero. Ours is the unrounded `f32` sum of the sixteen decoded taps (the 2D routine, `lower::sampler::bicubic::routines`, `Plane`), and a `half` result is the device's narrowing of it. Every class takes Metal's arm, which the case's own tests hold in Metal's recording: `R32Float` the inner bilinear taps, which compare exactly; the clamp into [0, 1] of the unsigned normalized formats and into [-1, 1] of `RGBA8Snorm`; no clamp of `RGBA16Float`. Open: nothing; the difference is within Metal's precision, which rule 1 leaves to the note. diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index d75479a82..93943c519 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -1474,13 +1474,21 @@ made, with no lock, and never rewritten for layouts. changes: its read would answer the texel unswizzled, where Metal reads it through the swizzle. A texture's own descriptor takes a swizzle only without shader-write and render-target usage (`Refusal::TextureSwizzleWithWrites`), so this reaches views alone. -- A kernel samples a 2D texture slot through a bicubic constexpr sampler at normalized - coordinates by the arm its slot's pushed word selects, which the runtime writes from the bound - texture's format and swizzle (`metal2vulkan::metal::format::bicubic_texels_word`). A dispatch - whose slot holds a texture of a format with no such word (a compressed, YUV, stencil, integer - or extended-range format, or one of 8-bit sRGB codes such as `RGBA8Unorm_sRGB`, whose taps - Metal filters decoded) is `Gap::BicubicTexels`, naming the slot and the format, found when the - pipeline state or a binding changes: each such format's arm is built when a guest binds one. +- A kernel, a vertex function or a fragment function samples a 2D texture slot through a bicubic + constexpr sampler at normalized coordinates by the arm its slot's pushed word selects, which the + runtime writes from the bound texture's format and swizzle + (`metal2vulkan::metal::format::bicubic_texels_word`), the same word for a dispatch and for a draw. + A dispatch or a draw whose slot holds a texture of a format with no such word (a compressed, YUV, + stencil, integer or extended-range format, or one of 8-bit sRGB codes such as `RGBA8Unorm_sRGB`, + whose taps Metal filters decoded) is `Gap::BicubicTexels`, naming the slot and the format, found + when the pipeline state or a binding changes: each such format's arm is built when a guest binds + one. A bicubic sample at pixel coordinates or of a 1D texture is refused at creation in every + stage (the identity domains' forms, below). Only a render state whose functions sample through a + bicubic sampler lists a slot to check and fill; a draw of any other state does neither. Basis: + this is NOT documented Metal. The MSL spec lists only nearest and linear filters, and 'bicubic' + appears nowhere in the spec or the feature-set tables. It is built because a guest already uses + the bicubic constexpr sampler in kernels, which is why the kernel half exists. Filling the field + for a draw completes that one form and adds none. - An opaque-black border sampled through a view whose component mapping is not the identity (a swizzle, or the mapping a pixel format takes: `A8Unorm` is held in `R8_UNORM` read through `(0, 0, 0, r)` on every device, as rt uses Vulkan 1.3 and does not enable diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 169cba633..8604aae3d 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -1209,19 +1209,19 @@ pub enum Gap { /// The texture's pixel format. pixel_format: PixelFormat, }, - /// A dispatch whose kernel samples texture slot `slot` through a constexpr sampler with - /// Metal's bicubic filter (`filter::bicubic`), where the texture bound there is of a pixel - /// format whose treatment under that filter the runtime does not establish: a format of no - /// family Metal's bicubic filter was measured on (compressed, YUV, stencil, integer and - /// extended-range formats), or of 8-bit sRGB codes, whose taps the filter sums decoded. The - /// function reads how the filter treats the bound format's texels (its inner taps, its clamp - /// and its border texels) from a field the runtime writes from the bound texture - /// (`metal2vulkan::metal::format::bicubic_texels_word`). Found when the pipeline state or a - /// binding changes. + /// A dispatch or a draw whose function samples texture slot `slot` through a constexpr + /// sampler with Metal's bicubic filter (`filter::bicubic`), where the texture bound there is + /// of a pixel format whose treatment under that filter the runtime does not establish: a + /// format of no family Metal's bicubic filter was measured on (compressed, YUV, stencil, + /// integer and extended-range formats), or of 8-bit sRGB codes, whose taps the filter sums + /// decoded. The function reads how the filter treats the bound format's texels (its inner + /// taps, its clamp and its border texels) from a field the runtime writes from the bound + /// texture (`metal2vulkan::metal::format::bicubic_texels_word`). Found when the pipeline + /// state or a binding changes. /// /// Basis: ours (each refused format's treatment is built when a guest binds one). BicubicTexels { - /// The kernel's texture slot. + /// The function's texture slot. slot: u32, /// The bound texture's pixel format. pixel_format: PixelFormat, @@ -2328,8 +2328,8 @@ impl fmt::Display for Gap { ), Gap::BicubicTexels { slot, pixel_format } => write!( f, - "texture slot {slot}, which a kernel samples through a bicubic filter, bound to a \ - {pixel_format:?} texture, whose bicubic sample is not built" + "texture slot {slot}, which a function samples through a bicubic filter, bound to \ + a {pixel_format:?} texture, whose bicubic sample is not built" ), Gap::RenderPipeline { kind } => { write!(f, "a render pipeline state with {kind:?} is not built") diff --git a/crates/metal2vulkan-runtime/src/pipeline.rs b/crates/metal2vulkan-runtime/src/pipeline.rs index 9c85b3197..7162358c2 100644 --- a/crates/metal2vulkan-runtime/src/pipeline.rs +++ b/crates/metal2vulkan-runtime/src/pipeline.rs @@ -704,7 +704,7 @@ pub(crate) enum FieldValue { /// A `u32`: how Metal's bicubic filter treats the texels of the texture bound at the slot /// (`metal::format::bicubic_texels_word`, under the swizzle it is sampled through), /// `metal::format::BICUBIC_TEXELS_UNBOUND` where none is; a texture of a format with no - /// such treatment is refused at the dispatch ([`Gap::BicubicTexels`]). + /// such treatment is refused at the dispatch or the draw ([`Gap::BicubicTexels`]). BicubicTexels(u32), /// A `u32`: the sampler index the consumer gave the constexpr sampler at this place of the /// state's numbered samplers (a render state's: the vertex function's, then the fragment diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index cf47a3bb4..742b8e3f9 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -139,6 +139,11 @@ pub(crate) struct Draws { /// attachment read of the pass through its texture's second element, ordered after every /// earlier draw of the pass (`crate::render_encoder`). pub(crate) fetched: Vec, + /// Each texture slot a function samples through a bicubic constexpr sampler, with its + /// function: the slots whose `PushField::BicubicTexels` a draw writes from the bound texture, + /// and whose texture a draw's checks refuse where the filter's treatment of its format is not + /// established (`Gap::BicubicTexels`). Empty for every other content. + pub(crate) bicubic: Vec<(usize, u32)>, /// Each fixed-function vertex binding: its binding and the vertex buffer index it reads. pub(crate) bindings: Vec<(u32, u32)>, /// Whether a function reads through an address that is not one of its slots. @@ -528,6 +533,7 @@ fn draws( let mut constexprs = Vec::new(); let mut fields = Vec::new(); let mut fetched = Vec::new(); + let mut bicubic = Vec::new(); let mut push_len = 0; let mut blocks = [None; 2]; for placement in &translated.push { @@ -579,6 +585,18 @@ fn draws( fields.push((offset, table(stage)?, FieldValue::IntegerChannels(index))); continue; } + // How Metal's bicubic filter treats the bound texture's texels, the word a + // dispatch writes for its kernel's slot (`FieldValue::BicubicTexels`). + PushField::BicubicTexels(SlotRef { + stage, + class: SlotClass::Texture, + index, + }) => { + let of = table(stage)?; + fields.push((offset, of, FieldValue::BicubicTexels(index))); + bicubic.push((of, index)); + continue; + } PushField::ConstexprSampler(sampler) => { let SamplerRef::Constexpr(words) = sampler.sampler else { return Err(draw_input()); @@ -659,6 +677,7 @@ fn draws( storage_reads, own_pixel, fetched, + bicubic, bindings, reads_unbound: translated.reads_unbound_resources, writes_unbound: translated.writes_unbound_resources, diff --git a/crates/metal2vulkan-runtime/src/render_encoder.rs b/crates/metal2vulkan-runtime/src/render_encoder.rs index 74e381bfc..20aef5054 100644 --- a/crates/metal2vulkan-runtime/src/render_encoder.rs +++ b/crates/metal2vulkan-runtime/src/render_encoder.rs @@ -96,7 +96,7 @@ use crate::shadow::{self, Area, Held}; use crate::texture::{Texture, TextureInner, TextureObject}; use ash::vk; use metal2vulkan::bind::alpha_test_code; -use metal2vulkan::metal::format::integer_channels_word; +use metal2vulkan::metal::format::{integer_channels_word, BICUBIC_TEXELS_UNBOUND}; use metal2vulkan::metal::state::{input_assembly, DepthStencilDescriptor}; use metal2vulkan::metal::{ CullMode, DepthClipMode, IndexType, PrimitiveType, TriangleFillMode, Winding, @@ -257,7 +257,7 @@ impl Facts { /// /// Err: [`Refusal::VertexBufferOffset`]; [`Refusal::NoBufferAtIndex`] for a vertex buffer the /// vertex descriptor reads that is not bound; [`Gap::SwizzledReadWrite`]; - /// [`Gap::StorageElement`]. + /// [`Gap::BicubicTexels`]; [`Gap::StorageElement`]. fn find(&mut self, draws: &Draws, tables: &[Tables; 2], pass: &Pass) -> Result<(), Error> { self.vertex.clear(); for &(binding, index) in &draws.bindings { @@ -285,6 +285,18 @@ impl Facts { return Err(Error::Unsupported(Gap::SwizzledReadWrite { slot })); } } + // A bicubic sample's texture, of a format the filter's treatment is known for; a content + // with no bicubic slot has none to look at. + for &(table, slot) in &draws.bicubic { + if let Some(texture) = tables[table].texture(slot) { + if texture.bicubic_texels().is_none() { + return Err(Error::Unsupported(Gap::BicubicTexels { + slot, + pixel_format: texture.descriptor().pixel_format, + })); + } + } + } for &(table, slot, access) in &draws.textures { let read = draws.storage_reads.contains(&(table, slot)); let stored = access != Access::Read || read; @@ -2539,6 +2551,15 @@ impl Drop for RenderCommandEncoder { } } +#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] +impl RenderCommandEncoder { + /// The push bytes the encoder's last draw filled, which `tests::bicubic` reads its fields' + /// words from. + pub(crate) fn pushed(&self) -> &[u8] { + &self.push + } +} + /// The topology of a draw of `primitive_type`, and whether it restarts strips. fn primitives(primitive_type: PrimitiveType) -> (vk::PrimitiveTopology, bool) { let (topology, restart) = input_assembly(primitive_type); @@ -2606,6 +2627,13 @@ fn fill_push( .map_or(0, |t| integer_channels_word(t.descriptor().pixel_format)); bytes[at..at + 4].copy_from_slice(&word.to_le_bytes()); } + // A texture of no bicubic treatment was refused at the draw's checks. + FieldValue::BicubicTexels(slot) => { + let word = (tables.texture(slot)).map_or(BICUBIC_TEXELS_UNBOUND, |t| { + t.bicubic_texels().unwrap_or(BICUBIC_TEXELS_UNBOUND) + }); + bytes[at..at + 4].copy_from_slice(&word.to_le_bytes()); + } FieldValue::ConstexprSampler(place) => { let index = ids.get(place).copied().unwrap_or(0); bytes[at..at + 4].copy_from_slice(&index.to_le_bytes()); @@ -2625,11 +2653,8 @@ fn fill_push( .map_or(0, |target| target.texture.second_resource_id().index); bytes[at..at + 4].copy_from_slice(&index.to_le_bytes()); } - // A render content has no dispatch or stage-in region, and no bicubic slot's field - // (`render::draws`). - FieldValue::DispatchRegion - | FieldValue::StageInRegion - | FieldValue::BicubicTexels(_) => {} + // A render content has no dispatch or stage-in region (`render::draws`). + FieldValue::DispatchRegion | FieldValue::StageInRegion => {} } } } diff --git a/crates/metal2vulkan-runtime/src/tests/bicubic_draw.rs b/crates/metal2vulkan-runtime/src/tests/bicubic_draw.rs new file mode 100644 index 000000000..4f470b187 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/bicubic_draw.rs @@ -0,0 +1,241 @@ +//! A draw whose function samples a 2D texture through a bicubic constexpr sampler at normalized +//! coordinates, in each stage: the fragment function of the owned fixture `engine/bcu_fragment` +//! (drawn by `colored_vertex`) and the vertex function of `engine/bcu_vertex`, under a device cfg +//! on every device of the cfg's kind. Each draw pushes, for the function's slot, the word a +//! dispatch pushes for a kernel's (`tests::bicubic`): how Metal's bicubic filter treats the format +//! bound there, for each of six formats, and the unbound word for a slot that holds no texture. A +//! draw of an `RGBA8Unorm` texture whose texels are all one value renders that value at every +//! pixel, as the filter's weights sum to one; a draw whose slot holds an `RGBA8Unorm_sRGB` +//! texture is refused, naming the slot and the format. A content with no bicubic slot has none +//! listed. +//! +//! `llvm-as` assembles the functions; without it the test skips visibly. + +#[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod on_device { + use crate::pipeline::FieldValue; + use crate::render::{DrawPlace, FRAGMENT, VERTEX}; + use crate::tests::command::on_device::each_device; + use crate::tests::draw::on_device::{ + descriptor, examples, floats, library, pass, read, run, target, Buffers, SIDE, + }; + use crate::{ + ColorAttachmentDescriptor, Device, Error, FunctionDescriptor, Gap, HostBytes, IndexClass, + NumberedSampler, PixelFormat, PrimitiveType, Region, RenderCommandEncoder, + RenderPipelineDescriptor, RenderPipelineState, StageSource, Texture, TextureDescriptor, + TextureType, TextureUsage, + }; + use metal2vulkan::metal::format::{bicubic_texels_word, BICUBIC_TEXELS_UNBOUND}; + use metal2vulkan::metal::TextureSwizzleChannels; + use metal2vulkan_devtools::engine_dir; + + /// The constexpr sampler's index the test gives the functions. + const CONSTEXPR: u32 = 1; + /// The first texture index the test grants. + const FIRST: u32 = 1; + /// Each format the test binds, as `tests::bicubic` does. + const FORMATS: [PixelFormat; 6] = [ + PixelFormat::R32Float, + PixelFormat::RGBA8Unorm, + PixelFormat::RGBA8Snorm, + PixelFormat::RGBA16Float, + PixelFormat::RGBA16Unorm, + PixelFormat::R8Unorm, + ]; + /// The texel of the drawn texture: codes whose `RGBA8Unorm` value a sum within a few ULPs of + /// it rounds back to. + const TEXEL: [u8; 4] = [64, 128, 192, 255]; + + /// A 2D texture of `format`, 4 texels a side, of shader-read usage at `index`. + fn texture(name: &str, device: &Device, format: PixelFormat, index: u32) -> Texture { + let mut d = TextureDescriptor::new(TextureType::Type2D, format, 4, 4); + d.usage = TextureUsage::SHADER_READ; + (device.new_texture(&d, Some(index))).unwrap_or_else(|error| panic!("{name}: {error}")) + } + + /// The state of `d`, whose functions sample through the one constexpr sampler. + fn state(name: &str, device: &Device, d: &RenderPipelineDescriptor) -> RenderPipelineState { + (device.new_render_pipeline_state(d, |samplers| { + assert!( + matches!(samplers, [NumberedSampler::Constexpr(_)]), + "{name}: {samplers:?}" + ); + Ok(vec![CONSTEXPR]) + })) + .unwrap_or_else(|error| panic!("{name}: {error}")) + } + + /// One stage's draw: its descriptor, which of the draw's tables samples (`VERTEX` or + /// `FRAGMENT`), and how a draw binds its texture and its coordinates' bytes. + struct Form { + stage: &'static str, + descriptor: RenderPipelineDescriptor, + table: usize, + bind: fn(&mut RenderCommandEncoder, Option<&Texture>) -> Result<(), Error>, + coordinates: Vec, + } + + #[test] + fn every_device_draws_a_bicubic_sample_in_each_stage() { + let (Some(examples), Some(fragments), Some(vertices)) = ( + examples(), + library(&engine_dir().join("bcu_fragment.ll")), + library(&engine_dir().join("bcu_vertex.ll")), + ) else { + return; + }; + let function = |library: &crate::Library, name| { + StageSource::Function(FunctionDescriptor::new( + library.function(name).expect("the function"), + )) + }; + let mut fragment = descriptor(&examples, "colored_fragment", PixelFormat::RGBA8Unorm); + fragment.fragment = Some(function(&fragments, "bcu_fragment")); + let mut vertex = RenderPipelineDescriptor::new(function(&vertices, "bcu_vertex")); + vertex.fragment = Some(function(&vertices, "bcu_vertex_color")); + vertex.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm)); + let forms = [ + Form { + stage: "fragment", + descriptor: fragment, + table: FRAGMENT, + bind: |encoder, texture| encoder.set_fragment_texture(texture, 0), + // `pos.xy * p.xy + p.zw`: the target's pixels at a sixteenth of a unit each. + coordinates: vec![1.0 / 16.0, 1.0 / 16.0, 0.0, 0.0], + }, + Form { + stage: "vertex", + descriptor: vertex, + table: VERTEX, + bind: |encoder, texture| encoder.set_vertex_texture(texture, 0), + // `p[vid]`, one coordinate a vertex. + coordinates: vec![0.25, 0.25, 0.5, 0.75, 0.875, 0.125], + }, + ]; + each_device("bicubic_draw", |name, _, device| { + let _grants = [ + (IndexClass::Texture, FIRST, FORMATS.len() as u32 + 2), + (IndexClass::Sampler, CONSTEXPR, 1), + ] + .map(|(class, first, count)| { + (device.grant_indices(class, first, count)) + .unwrap_or_else(|error| panic!("{name}: {error}")) + }); + let textures: Vec = (FORMATS.iter().zip(FIRST..)) + .map(|(&format, index)| texture(name, &device, format, index)) + .collect(); + let next = FIRST + FORMATS.len() as u32; + let srgb = texture(name, &device, PixelFormat::RGBA8UnormSRGB, next); + let drawn = texture(name, &device, PixelFormat::RGBA8Unorm, next + 1); + let bytes: Vec = TEXEL.repeat(16); + let whole = Region { + origin: [0; 3], + size: [4, 4, 1], + }; + (drawn.replace_region(whole, 0, 0, HostBytes::from(&bytes[..]), 16, 64)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let mut buffers = Buffers::new(&device); + // `colored_vertex`'s attributes: a triangle that covers the target, and its colours. + let positions = buffers.of(&device, &floats(&[-1.0, -1.0, 3.0, -1.0, -1.0, 3.0])); + let colors = buffers.of(&device, &floats(&[0.0; 12])); + let queue = device.new_command_queue(4).expect("a queue"); + for form in &forms { + let name = &format!("{name}: {}", form.stage); + let state = state(name, &device, &form.descriptor); + // The content lists its one bicubic slot, and its field is in the push range. + let draws = &state.inner.compiled.draws; + assert_eq!(draws.bicubic, [(form.table, 0)], "{name}"); + let at = (draws.fields.iter()) + .find_map(|&(place, table, value)| match (place, value) { + (DrawPlace::Push(offset), FieldValue::BicubicTexels(0)) + if table == form.table => + { + Some(offset as usize) + } + _ => None, + }) + .unwrap_or_else(|| panic!("{name}: no pushed field of the slot")); + let call = |result: Result<(), Error>| { + result.unwrap_or_else(|error| panic!("{name}: {error}")) + }; + let bytes = floats(&form.coordinates); + let begin = |command_buffer: &crate::CommandBuffer, color: &Texture| { + let mut encoder = (command_buffer.render_command_encoder(&pass(color, None))) + .unwrap_or_else(|error| panic!("{name}: {error}")); + call(encoder.set_render_pipeline_state(&state)); + call(encoder.set_vertex_buffer(Some(&positions), 0, 0)); + call(encoder.set_vertex_buffer(Some(&colors), 0, 1)); + call(match form.table { + FRAGMENT => encoder.set_fragment_bytes(&bytes, 0), + _ => encoder.set_vertex_bytes(&bytes, 0), + }); + encoder + }; + // Each format's word and the unbound word, from draws never committed. + let rgba8 = || { + target( + &device, + PixelFormat::RGBA8Unorm, + TextureUsage::RENDER_TARGET, + ) + }; + let words = queue.command_buffer().expect("a command buffer"); + let mut encoder = begin(&words, &rgba8()); + let word = |encoder: &RenderCommandEncoder| { + u32::from_le_bytes(encoder.pushed()[at..at + 4].try_into().unwrap()) + }; + call((form.bind)(&mut encoder, None)); + call(encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0)); + assert_eq!(word(&encoder), BICUBIC_TEXELS_UNBOUND, "{name}: unbound"); + for (texture, &format) in textures.iter().zip(&FORMATS) { + call((form.bind)(&mut encoder, Some(texture))); + call(encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0)); + let want = bicubic_texels_word(format, TextureSwizzleChannels::DEFAULT); + assert_eq!(Some(word(&encoder)), want, "{name}: {format:?}"); + } + // An sRGB texture is refused, the slot and the format named. + call((form.bind)(&mut encoder, Some(&srgb))); + let refused = encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0); + let Err(Error::Unsupported(gap)) = refused else { + panic!("{name}: an sRGB texture's bicubic sample: {refused:?}"); + }; + assert_eq!( + gap, + Gap::BicubicTexels { + slot: 0, + pixel_format: PixelFormat::RGBA8UnormSRGB + }, + "{name}" + ); + let text = gap.to_string(); + assert!( + text.contains("texture slot 0") && text.contains("RGBA8UnormSRGB"), + "{name}: {text}" + ); + encoder.end_encoding(); + // A texture of one texel value renders it at every pixel. + let color = rgba8(); + let command_buffer = queue.command_buffer().expect("a command buffer"); + let mut encoder = begin(&command_buffer, &color); + call((form.bind)(&mut encoder, Some(&drawn))); + call(encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0)); + encoder.end_encoding(); + run(name, &command_buffer); + let texels = read(&color, 4); + for (i, texel) in texels.as_chunks::<4>().0.iter().enumerate() { + let [x, y] = [i as u32 % SIDE, i as u32 / SIDE]; + assert_eq!(*texel, TEXEL, "{name}: pixel [{x}, {y}]"); + } + println!( + "bicubic_draw: {name}: each format's word pushed, sRGB refused, {} pixels \ + read the texel", + texels.len() / 4 + ); + } + // A content with no bicubic slot lists none. + let plain = descriptor(&examples, "colored_fragment", PixelFormat::RGBA8Unorm); + let plain = crate::tests::draw::on_device::state(name, &device, &plain); + assert!(plain.inner.compiled.draws.bicubic.is_empty(), "{name}"); + }); + } +} diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index aa78e2d9f..f269f09fb 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -5,6 +5,7 @@ mod argument_sampling; mod argument_tier; mod arrays; mod bicubic; +mod bicubic_draw; mod blit; mod border; mod cache; diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/README.md b/crates/metal2vulkan-validation/fixtures/public/engine/README.md index d7e468a2c..1c2eb76a8 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/README.md +++ b/crates/metal2vulkan-validation/fixtures/public/engine/README.md @@ -166,6 +166,7 @@ threadgroup's threads); an authored case that executes a loop declares it | `bcu_address` | `bcu_address` | bicubic samplers that clamp to the edge, to zero, and to an opaque white border, repeat, and mirror-repeat, normalized, and clamp to the edge and to zero with pixel coordinates, at footprints across each edge (translated since SEMANTICS 1075 by the Apple M3 Max's mirrored-repeat rule) | where an out-of-range tap's weight goes per address mode (cases `bicubic-address-modes-at-the-edges-of-a--`) | | `bcu_edges` | `bcu_edges` | `bcu_address` without its mirror-repeat sampler (edge, zero, opaque white border, and repeat, normalized; edge and zero with pixel coordinates), so that the Vulkan candidates run every sampler | Metal's sums of random texels at footprints across each edge (cases `bicubic-edges-of-random-texels-in-a--`) | | `bcu_fragment` | `bcu_fragment` | a fragment function's implicit bicubic sample at a coordinate `pos.xy * p.xy + p.zw` (derivative level of detail) | the impulse weights' products, magnifying and minifying (cases `fragment-bicubic-magnifying-...`, `fragment-bicubic-minifying-...`) | +| `bcu_vertex` | `bcu_vertex`, `bcu_vertex_color` | a vertex function's implicit bicubic sample (clamp-to-edge, normalized; outside a fragment function, the base level) at `p[vid]`, which the fragment function writes | no corpus case: the runtime's device test `every_device_draws_a_bicubic_sample_in_each_stage` reads a texture whose texels are all one value back from every pixel, and the slot's pushed word for each format | | `bcx_table` | `bcx_table` | `filter::bicubic` (clamp-to-edge, pixel coordinates) of two textures at one coordinate, the second at its swapped axes, so that a case binding the second to the first's transpose reads each tap on both axes | the weight of each tap at every 1/256 fraction of each axis (case `bicubic-weight-table-at-every-fraction-on-rgba16-unorm`) | | `bcx_rules` | `bcx_rules` | `filter::bicubic` (clamp-to-edge, pixel coordinates) of eight 2D `float`, four 2D `half`, three 1D `float`, and one 1D `half` texture slots, which the cases bind to different formats | how each format's sum is rounded and clamped: random texels (cases `bicubic-rounding-of-random-normalized-texels`, `bicubic-rounding-of-random-float-and-srgb-texels`) and designed sums (cases `bicubic-designed-ties-clamps-and-extremes`, `bicubic-designed-float-footprints`, `bicubic-16-bit-normalized-sums-near-the-rounding-tie`, `bicubic-8-bit-normalized-and-srgb-sums-near-the-rounding-tie`, `bicubic-float-cancellation-ties-and-non-finite-texels`) | | `bcx_half_read` | `bcx_half_read` | four 2D `half` textures, each read at a texel, sampled through a nearest and a linear sampler (clamp-to-edge, pixel coordinates), outside the bicubic filter; the cases bind wider formats | how Metal converts wider texels to `half` (cases `half-conversion-of-wider-texels-by-read-and-sample` and `half-conversion-of-half-float-and-signed-normalized-texels`) | diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN b/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN index fb22bd36c..c70d7414e 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN +++ b/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN @@ -31,6 +31,7 @@ fixture air_2_9_front_end: metal: Apple metal version 32023.921 (metalfe-32023.9 fixture alv_levels: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture ani_cube_grad: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture bary_weights: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) +fixture bcu_vertex: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture bcx_half_read: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture bcx_rules: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture bcx_table: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/bcu_vertex.air.ll b/crates/metal2vulkan-validation/fixtures/public/engine/bcu_vertex.air.ll new file mode 100644 index 000000000..31604e13c --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/bcu_vertex.air.ll @@ -0,0 +1,89 @@ +; Generated by scripts/regen-air-fixtures from bcu_vertex.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 +%struct._sampler_t = type opaque + +@__air_sampler_state = internal addrspace(2) constant [2 x i64] [i64 34901797601023049, i64 0], align 8 + +; Function Attrs: convergent mustprogress nofree nounwind readonly willreturn +define <{ <4 x float>, <4 x float> }> @bcu_vertex(i32 noundef %0, %struct._texture_2d_t addrspace(1)* %1, <2 x float> addrspace(2)* nocapture noundef readonly "air-buffer-no-alias" %2) local_unnamed_addr #0 { + %4 = icmp eq i32 %0, 1 + %5 = select fast i1 %4, float 3.000000e+00, float -1.000000e+00 + %6 = icmp eq i32 %0, 2 + %7 = select fast i1 %6, float 3.000000e+00, float -1.000000e+00 + %8 = insertelement <4 x float> , float %5, i64 0 + %9 = insertelement <4 x float> %8, float %7, i64 1 + %10 = zext i32 %0 to i64 + %11 = getelementptr inbounds <2 x float>, <2 x float> addrspace(2)* %2, i64 %10 + %12 = load <2 x float>, <2 x float> addrspace(2)* %11, align 8, !tbaa !30, !alias.scope !33, !noalias !36 + %13 = tail call { <4 x float>, i8 } @air.sample_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %1, %struct._sampler_t addrspace(2)* nocapture readonly bitcast ([2 x i64] addrspace(2)* @__air_sampler_state to %struct._sampler_t addrspace(2)*), <2 x float> %12, i1 true, <2 x i32> zeroinitializer, i1 false, float 0.000000e+00, float 0.000000e+00, i32 0) #3 + %14 = extractvalue { <4 x float>, i8 } %13, 0 + %15 = insertvalue <{ <4 x float>, <4 x float> }> undef, <4 x float> %9, 0 + %16 = insertvalue <{ <4 x float>, <4 x float> }> %15, <4 x float> %14, 1 + ret <{ <4 x float>, <4 x float> }> %16 +} + +; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone willreturn +define <4 x float> @bcu_vertex_color(<4 x float> %0, <4 x float> returned %1) local_unnamed_addr #1 { + ret <4 x float> %1 +} + +; Function Attrs: argmemonly convergent mustprogress nofree nounwind readonly willreturn +declare { <4 x float>, i8 } @air.sample_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly, %struct._sampler_t addrspace(2)* nocapture readonly, <2 x float>, i1, <2 x i32>, i1, float, float, i32) local_unnamed_addr #2 + +attributes #0 = { convergent mustprogress nofree nounwind readonly 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 #1 = { mustprogress nofree norecurse nosync nounwind readnone 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 #2 = { argmemonly convergent mustprogress nofree nounwind readonly willreturn } +attributes #3 = { argmemonly convergent nounwind readonly willreturn } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} +!air.vertex = !{!9} +!air.fragment = !{!17} +!air.compile_options = !{!23, !24, !25} +!air.sampler_states = !{!26} +!llvm.ident = !{!27} +!air.version = !{!28} +!air.language_version = !{!29} + +!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>, <4 x float> }> (i32, %struct._texture_2d_t addrspace(1)*, <2 x float> addrspace(2)*)* @bcu_vertex, !10, !13} +!10 = !{!11, !12} +!11 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"} +!12 = !{!"air.vertex_output", !"generated(5colorDv4_f)", !"air.arg_type_name", !"float4", !"air.arg_name", !"color"} +!13 = !{!14, !15, !16} +!14 = !{i32 0, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"} +!15 = !{i32 1, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.sample", !"air.arg_type_name", !"texture2d", !"air.arg_name", !"t"} +!16 = !{i32 2, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 8, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"float2", !"air.arg_name", !"p"} +!17 = !{<4 x float> (<4 x float>, <4 x float>)* @bcu_vertex_color, !18, !20} +!18 = !{!19} +!19 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"float4"} +!20 = !{!21, !22} +!21 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position", !"air.arg_unused"} +!22 = !{i32 1, !"air.fragment_input", !"generated(5colorDv4_f)", !"air.center", !"air.perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"color"} +!23 = !{!"air.compile.denorms_disable"} +!24 = !{!"air.compile.fast_math_enable"} +!25 = !{!"air.compile.framebuffer_fetch_enable"} +!26 = !{!"air.sampler_state", [2 x i64] addrspace(2)* @__air_sampler_state} +!27 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!28 = !{i32 2, i32 8, i32 0} +!29 = !{!"Metal", i32 4, i32 0, i32 0} +!30 = !{!31, !31, i64 0} +!31 = !{!"omnipotent char", !32, i64 0} +!32 = !{!"Simple C++ TBAA"} +!33 = !{!34} +!34 = distinct !{!34, !35, !"air-alias-scope-arg(2)"} +!35 = distinct !{!35, !"air-alias-scopes(bcu_vertex)"} +!36 = !{!37} +!37 = distinct !{!37, !35, !"air-alias-scope-textures"} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/bcu_vertex.ll b/crates/metal2vulkan-validation/fixtures/public/engine/bcu_vertex.ll new file mode 100644 index 000000000..547a0d841 --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/bcu_vertex.ll @@ -0,0 +1,86 @@ +; Generated by scripts/regen-air-fixtures from bcu_vertex.metal (llvm-dis of bcu_vertex.air). 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" + +@__air_sampler_state = internal addrspace(2) constant [2 x i64] [i64 34901797601023049, i64 0], align 8 + +; Function Attrs: convergent mustprogress nofree nounwind willreturn memory(read) +define <{ <4 x float>, <4 x float> }> @bcu_vertex(i32 noundef %0, ptr addrspace(1) %1, ptr addrspace(2) noundef readonly captures(none) "air-buffer-no-alias" %2) local_unnamed_addr #0 { + %4 = icmp eq i32 %0, 1 + %5 = select fast i1 %4, float 3.000000e+00, float -1.000000e+00 + %6 = icmp eq i32 %0, 2 + %7 = select fast i1 %6, float 3.000000e+00, float -1.000000e+00 + %8 = insertelement <4 x float> , float %5, i64 0 + %9 = insertelement <4 x float> %8, float %7, i64 1 + %10 = zext i32 %0 to i64 + %11 = getelementptr inbounds <2 x float>, ptr addrspace(2) %2, i64 %10 + %12 = load <2 x float>, ptr addrspace(2) %11, align 8, !tbaa !30, !alias.scope !33, !noalias !36 + %13 = tail call { <4 x float>, i8 } @air.sample_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %1, ptr addrspace(2) readonly captures(none) @__air_sampler_state, <2 x float> %12, i1 true, <2 x i32> zeroinitializer, i1 false, float 0.000000e+00, float 0.000000e+00, i32 0) #3 + %14 = extractvalue { <4 x float>, i8 } %13, 0 + %15 = insertvalue <{ <4 x float>, <4 x float> }> undef, <4 x float> %9, 0 + %16 = insertvalue <{ <4 x float>, <4 x float> }> %15, <4 x float> %14, 1 + ret <{ <4 x float>, <4 x float> }> %16 +} + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) +define <4 x float> @bcu_vertex_color(<4 x float> %0, <4 x float> returned %1) local_unnamed_addr #1 { + ret <4 x float> %1 +} + +; Function Attrs: convergent mustprogress nofree nounwind willreturn memory(argmem: read) +declare { <4 x float>, i8 } @air.sample_texture_2d.v4f32(ptr addrspace(1) readonly captures(none), ptr addrspace(2) readonly captures(none), <2 x float>, i1, <2 x i32>, i1, float, float, i32) local_unnamed_addr #2 + +attributes #0 = { convergent mustprogress nofree nounwind willreturn memory(read) "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 #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) "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 #2 = { convergent mustprogress nofree nounwind willreturn memory(argmem: read) } +attributes #3 = { convergent nounwind willreturn memory(argmem: read) } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} +!air.vertex = !{!9} +!air.fragment = !{!17} +!air.compile_options = !{!23, !24, !25} +!air.sampler_states = !{!26} +!llvm.ident = !{!27} +!air.version = !{!28} +!air.language_version = !{!29} + +!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 @bcu_vertex, !10, !13} +!10 = !{!11, !12} +!11 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"} +!12 = !{!"air.vertex_output", !"generated(5colorDv4_f)", !"air.arg_type_name", !"float4", !"air.arg_name", !"color"} +!13 = !{!14, !15, !16} +!14 = !{i32 0, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"} +!15 = !{i32 1, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.sample", !"air.arg_type_name", !"texture2d", !"air.arg_name", !"t"} +!16 = !{i32 2, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 8, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"float2", !"air.arg_name", !"p"} +!17 = !{ptr @bcu_vertex_color, !18, !20} +!18 = !{!19} +!19 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"float4"} +!20 = !{!21, !22} +!21 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position", !"air.arg_unused"} +!22 = !{i32 1, !"air.fragment_input", !"generated(5colorDv4_f)", !"air.center", !"air.perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"color"} +!23 = !{!"air.compile.denorms_disable"} +!24 = !{!"air.compile.fast_math_enable"} +!25 = !{!"air.compile.framebuffer_fetch_enable"} +!26 = !{!"air.sampler_state", ptr addrspace(2) @__air_sampler_state} +!27 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!28 = !{i32 2, i32 8, i32 0} +!29 = !{!"Metal", i32 4, i32 0, i32 0} +!30 = !{!31, !31, i64 0} +!31 = !{!"omnipotent char", !32, i64 0} +!32 = !{!"Simple C++ TBAA"} +!33 = !{!34} +!34 = distinct !{!34, !35, !"air-alias-scope-arg(2)"} +!35 = distinct !{!35, !"air-alias-scopes(bcu_vertex)"} +!36 = !{!37} +!37 = distinct !{!37, !35, !"air-alias-scope-textures"} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/bcu_vertex.metal b/crates/metal2vulkan-validation/fixtures/public/engine/bcu_vertex.metal new file mode 100644 index 000000000..bdd90fef7 --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/bcu_vertex.metal @@ -0,0 +1,29 @@ +// Owned fixture: Metal's bicubic filter in a vertex function, the vertex half of a draw's +// bicubic sample (`bcu_fragment` is the fragment half). Vertex `vid` of one triangle that covers +// the target samples the texture at `p[vid]` through a clamp-to-edge bicubic sampler at +// normalized coordinates, in the implicit form (outside a fragment function, the base level), and +// passes the sample on; `bcu_vertex_color` writes the interpolated sample. Loop-free. +#include +using namespace metal; + +constant sampler bicubic_edge(filter::bicubic, address::clamp_to_edge, coord::normalized); + +struct BcuVertexOut { + float4 position [[position]]; + float4 color; +}; + +vertex BcuVertexOut bcu_vertex(uint vid [[vertex_id]], + texture2d t [[texture(0)]], + constant float2 *p [[buffer(0)]]) +{ + BcuVertexOut o; + o.position = float4(vid == 1 ? 3.0 : -1.0, vid == 2 ? 3.0 : -1.0, 0.0, 1.0); + o.color = t.sample(bicubic_edge, p[vid]); + return o; +} + +fragment float4 bcu_vertex_color(BcuVertexOut in [[stage_in]]) +{ + return in.color; +} diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index af3d40c1a..f37199667 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 574; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 2547; +pub const RUNTIME_VERSION: u32 = 2548; /// Writes a digest as lowercase hex. pub(crate) fn write_hex(f: &mut fmt::Formatter<'_>, name: &str, hash: &Hash256) -> fmt::Result { diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index b25bc4254..a5d59f601 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -384,7 +384,7 @@ Columns: | `RenderPipeline` | A render pipeline state of something the runtime does not build yet | every device (a public call's own check of its arguments) | `ours`: the replay streams' render pipelines draw into colour, depth and stencil attachments of one sample, with no tessellation and no framebuffer fetch; each other kind is built when a replay stream makes one | 5: `crates/metal2vulkan-runtime/src/render.rs (draw_input)`, `crates/metal2vulkan-runtime/src/render.rs (of, 3 sites)` (+1) | `-` | | `SwizzledReadWrite` | A draw or dispatch whose function declares `access::read_write` at texture slot `slot` and reads it, where the texture bound there has a swizzle... | every device (a public call's own check of its arguments) | `ours`: built when a replay stream counts one | 2: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (find)` | `-` | | `StorageElement` | A draw or dispatch whose function writes a texture slot, or reads one through its storage image (`access::read_write`), bound to a texture made... | every device (a public call's own check of its arguments) | `ours`: the storage element through a view of the nearest format whose storage Vulkan requires of every device, with the translator's conversion, is the form to build | 3: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch, 2 sites)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (find)` | `-` | -| `BicubicTexels` | A dispatch whose kernel samples texture slot `slot` through a constexpr sampler with Metal's bicubic filter (`filter::bicubic`), where the texture... | every device (a public call's own check of its arguments) | `ours`: each refused format's treatment is built when a guest binds one | 1: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)` | `-` | +| `BicubicTexels` | A dispatch or a draw whose function samples texture slot `slot` through a constexpr sampler with Metal's bicubic filter (`filter::bicubic`), where... | every device (a public call's own check of its arguments) | `ours`: each refused format's treatment is built when a guest binds one | 2: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (find)` | `-` | | `TextureView` | `Texture::new_texture_view` of a kind Metal makes and the runtime does not build | every device (a public call's own check of its arguments) | `ours`: the replay streams' views that compute binds are same-format views of every slice, 2D views of one slice of a 2D array, and level subranges, swizzled or not; each other kind is built when a replay stream binds one | 1: `crates/metal2vulkan-runtime/src/texture.rs (view)` | `-` | | `RenderPass` | A render pass of something the runtime does not build yet (`CommandBuffer::render_command_encoder`) | every device (a public call's own check of its arguments) | `ours`: the replay streams' passes render into one to two color attachments and a stencil or a depth attachment, each a level of a 2D texture of one sample, with no resolve and a clear depth of 1, none naming two textures for its depth and stencil; each other kind is built when a replay stream makes one; `DepthStencilViews` and `ClearDepth` are what Vulkan's rendering under the floor takes no form of | 6: `crates/metal2vulkan-runtime/src/pass.rs (check)`, `crates/metal2vulkan-runtime/src/pass.rs (ops)` (+4) | `-` | | `Draw` | A draw or render encoder state the runtime does not build yet (`RenderCommandEncoder`) | every device (a public call's own check of its arguments) | `ours`: the replay streams draw lines and triangles through one viewport Vulkan's is, with pipeline states of their pass's formats, under depth biases with no clamp, filled and clipped; each other kind is built when a replay stream draws one), and device for [`DrawKind::DividedBaseInstance`] (a device that does not report `supportsNonZeroFirstInstance` | 12: `crates/metal2vulkan-runtime/src/render_encoder.rs (attachment_reads, 2 sites)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)` (+9) | `-` | @@ -669,7 +669,7 @@ Each refusal's sites, with the function that builds it. - `rt:Gap::RenderPipeline`: `crates/metal2vulkan-runtime/src/render.rs (draw_input)`; `crates/metal2vulkan-runtime/src/render.rs (of, 3 sites)`; `crates/metal2vulkan-runtime/src/render.rs (refuse)` - `rt:Gap::SwizzledReadWrite`: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (find)` - `rt:Gap::StorageElement`: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch, 2 sites)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (find)` -- `rt:Gap::BicubicTexels`: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)` +- `rt:Gap::BicubicTexels`: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (find)` - `rt:Gap::TextureView`: `crates/metal2vulkan-runtime/src/texture.rs (view)` - `rt:Gap::RenderPass`: `crates/metal2vulkan-runtime/src/pass.rs (check)`; `crates/metal2vulkan-runtime/src/pass.rs (ops)`; `crates/metal2vulkan-runtime/src/pass.rs (resolve)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (later_store)`; `crates/metal2vulkan-runtime/src/texture.rs (attachment_view)`; `crates/metal2vulkan-runtime/src/texture.rs (resolve_attachment)` - `rt:Gap::Draw`: `crates/metal2vulkan-runtime/src/render_encoder.rs (attachment_reads, 2 sites)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (draw_patches)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_depth_bias)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_depth_clip_mode)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_scissor_rects)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_triangle_fill_mode)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_viewport)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_viewports)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_visibility_result_mode)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (shadow_copies)`