Texture buffers: a read-write one is words where its format's own view reads none without a format

A texture buffer's form (rule 2's texture buffer formats, metal::format::texel_buffer_form) asked
three accesses of a format's own view: a uniform texel buffer, a storage texel buffer, and a storage
texel buffer written without a format. A function that reads a texture buffer through
access::read_write reads its storage element without a format, which Vulkan asks of the view's
format (VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT, VUID-vkCmdDispatch-OpTypeImage-07030),
so on a device whose own view of a format lacks that bit the runtime refused the draw or dispatch
(Gap::StorageElement, ReadWithoutFormat). ANV on the Iris Xe (RPL-P) lacks it for BGRA8Unorm,
B5G6R5Unorm, BGR5A1Unorm and BGR10A2Unorm (jobs m3-max-81883, m3-max-82116); its committed profile
(intel-irisxe-rplp-anv) answers the same for RG11B10Float, RGB10A2Unorm and RGB10A2Uint, and so do
intel-irisxe-anv and intel-uhd770-rpls-anv for all seven (job m3-max-82025). Holding those formats
as words for every texture buffer would cost one made to be read 31.6% and 31.7% on that Iris
(texel_buffer_bgra8_read and texel_buffer_b5g6r5_read, job m3-max-82136).

The form now asks a fourth access, the storage read without a format, only of a texture buffer
whose usage, fixed at its making, holds both MTLTextureUsageShaderRead and
MTLTextureUsageShaderWrite, or is MTLTextureUsageUnknown (metal::format::texel_buffer_read_write):
Metal lets a function reach a texture buffer through access::read_write only where its usage holds
both. texel_buffer_form(pf, usage, profile) is one answer per format and usage per device; one made
to be read or written alone keeps the three-access answer. On the three ANV profiles the seven
formats move to words for such a texture buffer and nowhere else. AGENTS.md's rule 2 says so in
the same commit: the three accesses, plus the storage read without a format for a texture buffer
made with both usages, one answer per format and usage per device; it is still one query-chosen
form, and the count of fourteen is unchanged.

The word says the usage, as it says the format, so a shader that meets a texture buffer through a
handle, as one at a slot, tells which answer holds: bit 11 of a texture buffer word of a format
with a word layout, TextureWord::TEXEL_BUFFER_READ_WRITE, is set where it was made both to be read
and to be written. It lies within the 14 low bits an argument buffer's handle carries
(HANDLE_WORD), and the word stays the same on every device. The translator holds the codes a
profile holds as words per usage (WordCodes: alone, read_write); the words twin's held test tests
bit 11 beside the code only where some format is words for the one usage and not the other
(read_write & !alone), and where the two sets are equal the test and the module are what they
were. The runtime asks texel_form of the texture's usage at its making, and
Device::minimum_texture_buffer_alignment, Metal's query of a format alone, answers the larger of
the two forms' alignments: on the three ANV profiles (uniform offset alignment 1, storage 16, a
single texel enough for both) B5G6R5Unorm and BGR5A1Unorm go from 2 to 4 bytes (a word against a
2-byte texel), and BGRA8Unorm, BGR10A2Unorm, RG11B10Float, RGB10A2Unorm and RGB10A2Uint stay 4;
every other profile's two forms are equal, so its answer is unchanged (computed from the committed
profiles' limits, not measured apart).

Public contract, in this commit: TextureWord::of_texture_buffer(pixel_format, width, usage),
texel_buffer_form(pf, usage, profile), the new texel_buffer_read_write and
TextureWord::TEXEL_BUFFER_READ_WRITE (api_surface, api_signatures.tsv); docs/RESOURCE-ID.md's bit 11
row, its texture buffer word section and its test vectors: tests/resource_words.tsv gains a usage
column, each format with a word at read (1) and read-write (3) usage with its widths, and at write
(2) and unknown (0) at width 1. Consumer search: reims-vgpu at 4f46e27e3b (main's) and at its
current e447795571 (mine): no guest computation of words; of_texture_buffer, texel_buffer_form,
TEXEL_BUFFER_ and resource_words have no hit, and TextureWord's one hit is link-order.txt, a symbol
order list naming TextureWord::of. The runtime README's known gap now says the read is served for a
texture buffer made with both usages, and keeps the measured words' cost scoped to those; its form,
alignment and words-cost paragraphs, docs/API.md and docs/REPLAY-STREAM.md name the usage.

The zero for amd-rdna2-apu-radv, intel-arl-anv and nvidia-pascal-linux is unaudited: those
committed profiles report all 39 word formats as words, so no format can move there by this rule
(main opens a row to re-record them).

SEMANTICS_VERSION 2339 (development holds 2338): the words twin's module on the three ANV profiles
and the form's answers move. RUNTIME_VERSION 2558: a texture buffer's form, its word and the
alignment the runtime answers move. runtime-sources.sha256 re-pinned (metal/format/texel_words.rs
and metal/format/mod.rs are runtime inputs). docs/REFUSALS.md does not move (refusal_surface.py
--check passed).

Verified at 0cbe4dfc70, a commit of this same tree on a try branch (tree dd16b6a2f7):
- red: the test before this one (rebased here as 5900eb8642), at ed24bac82a, job m3-max-83041 on
  the Iris Xe (RPL-P, Mesa 26.2.6): every_device_runs_texture_buffers_made_to_be_read_and_written_at_every_slot
  failed with B5G6R5Unorm, BGR5A1Unorm and BGR10A2Unorm "not dispatched", the read-written slot's
  ReadWithoutFormat refusal;
- the Iris Xe (RPL-P, Mesa 26.2.6), the runtime's texture buffer tests (--cfg m2v_gpu, filter
  test(texture_buffer)), job m3-max-83121: 12 run, 12 passed; the new test alone, job m3-max-83127,
  passed, every one of the 15 formats answering the CPU's at every slot. It asserts, per texture
  buffer made, that the words gauge (Gauges::word_texture_buffers) moved exactly where the form
  answers words for its usage, and that the words twin ran once per dispatch where one bound is
  words; every_device_reads_and_writes_texture_buffers_of_formats_held_as_words printed
  B5G6R5Unorm, BGR5A1Unorm and BGR10A2Unorm "own view; made to be read and written, words: every
  answer the CPU's", where they were refused before;
- the Iris Xe, rt_replay's texture_buffers_play_with_their_recorded_ids_and_the_cpu_s_texels
  (--cfg m2v_gpu), job m3-max-83115 (at 9eb68e9c2c, which differs from this tree by a test
  helper's name in the runtime's texture_buffer_words.rs alone): BGRA8Unorm and B5G6R5Unorm play
  as "own view, read_write words" with the recorded IDs (each word with bit 11 where made to be
  read and written), the CPU's texels and values, where the play ended in the refusal before;
- the Intel UHD 630 (Windows driver 101.2145, validation layer 1.4.363.0), job m3-max-83145 (the
  win-cross build m3-max-83134): the runtime's whole suite, 985 run: 984 passed, 1 failed, 4
  skipped; every_device_runs_texture_buffers_made_to_be_read_and_written_at_every_slot and
  every_device_reads_and_writes_texture_buffers_of_formats_held_as_words passed. The one failure,
  half_simd_reductions' every_device_sums_and_multiplies_half_simdgroups_as_metal, fails the same
  way at pin Q (m3-max-82853) and at 2e9f9866be (m3-max-83061) and is outside this change;
- job m3-max-83128 (Linux): the runtime's, devtools' and harness's suites 280 run, 280 passed, 2
  skipped; validation 1323 run, 1323 passed, 3 skipped; conformance 1052 run, 1052 passed;
  doctests; on lavapipe (--cfg m2v_cpu_icd) the runtime's texture buffer tests 12 run, 12 passed,
  and rt_replay's texture buffer play passed, every format the same form for both usages there;
- the Linux gate, job m3-max-83122: cargo fmt --check, signatures --check, refusal_surface.py
  --check, clippy -D warnings (plain, --cfg m2v_gpu, --cfg m2v_cpu_icd) and rustdoc all clean;
  the translator's and AIR suites 3459 run: 3458 passed, 1 failed, 22 skipped, the one failure
  golden_hashes_match_the_table, a bless due of 80 cells under 2339 (the 78 below and
  development's own 2); the runtime guard (the_runtime_sources_are_the_committed_ones) passed;
- golden cells (job m3-max-83165: the golden test's every changed cell at this tree and at
  development's 401d9d5949, the same build, listed in full): 26 cells move on each of
  intel-irisxe-anv, intel-irisxe-rplp-anv and intel-uhd770-rpls-anv (every fixture that reaches a
  texture buffer: a8r_buffers, abt_descriptor_sets, hlf_half_buffer, hsw_storage_writes,
  kernel_read_through, ob1_texel_buffer, rlm_runtime_limits, tb_word_formats, texture_ops'
  texel_buffers, tob_renders, trh_forward, unk_size_queries,
  kernel_texture_variant_leftovers, kernel_write_one_dimensional_textures), and 0 on each of the
  other twelve committed profiles (amd-780m-hawkpoint-radv, amd-780m-radv, amd-rdna2-apu-radv,
  gate-lavapipe, gate-lavapipe-x86_64, intel-arl-anv, lavapipe, moltenvk-m3, nvidia-pascal-linux,
  nvidia-rtx50-linux, nvidia-rtx5080-laptop, runtime-floor): there the two code sets are equal and
  the module is what it was. Development's own two due cells (runtime-floor's a8r_buffer_read_write
  and tb_word_formats) are the same at both. The .air.ll rows need macOS's metal-as and were not
  compared. The table is re-blessed on development;
- the authored compile census (jobs m3-max-83117 at 9eb68e9c2c and m3-max-83118 at
  401d9d5949, checks; m3-max-83148, a bless in its own workspace at this tree, diffed): 0
  differences and 0 failures at both, 21321 cells; 14 artifact digests move, every one on
  intel-irisxe-rplp-anv (a C3 venue), 0 on gate-lavapipe and amd-780m-radv, against 0 at
  401d9d5949;
- the bit test's cost where nothing moves, on the Iris Xe (exclusive, job m3-max-83168): the
  release harness of 401d9d5949 (before, and a copy of it, before2) against this tree's (after),
  built by job m3-max-83124, 8 rounds of 500 runs each, the arms' order rotating: the read-only
  own views texel_buffer_bgra8_read and texel_buffer_b5g6r5_read take a GPU p50 (median of the 8
  rounds) of 9009.0 us and 9215.8 us after against 9009.0 us and 9215.6 us before, +0.00% each,
  before2 against before -0.01% and 0.00%; every run matched its CPU reference.
This commit is contained in:
Anees Iqbal committed 2026-12-03 03:22:23 -08:00
1 parent 53c5fde63f
commit 1c68dd10f4
21 files changed
+1441 -578

No files matched your search

+12 -10
View File
@@ -97,16 +97,18 @@ order, and a lower one never overrides a higher one.
is Load, a counted copy in at its begin; those copies and that image's memory are recorded as a
known gap), texture buffer formats (ruled 12-02; for each format, does the device serve it
natively for every access a texture buffer makes, as a uniform texel buffer, as a storage texel
buffer, and as a storage write without a format? A device that does makes a texture buffer of
it the format's own view; where any of the three is missing, that format's texture buffer is
held as words, an `R32_UINT` view whose texels shaders convert, one answer per format per
device; on a device that holds any format so, a stage that reaches a texture buffer declares a
stage constant, false by default, under which every word arm is dead code at pipeline creation,
and each of its `VkPipeline`s has a words twin specialized with it true, made in the same make,
which a draw or dispatch runs where a texture buffer held as words is bound at a slot its stage
reaches or, for a stage that reaches one through a handle, while one lives on the device; the
twins' second compile and memory, and the words' cost, 7.3 times the own view's GPU time for an
`R8Unorm` texture buffer written on an RTX 3090, are recorded as a known gap), and Shared
buffer, and as a storage write without a format, and, for a texture buffer made with both
shader read and shader write usage, as a storage read without a format? A device that does
makes a texture buffer of it the format's own view; where any of those is missing, that
format's texture buffer of that usage is held as words, an `R32_UINT` view whose texels shaders
convert, one answer per format and usage per device; on a device that holds any format so, a
stage that reaches a texture buffer declares a stage constant, false by default, under which
every word arm is dead code at pipeline creation, and each of its `VkPipeline`s has a words twin
specialized with it true, made in the same make, which a draw or dispatch runs where a texture
buffer held as words is bound at a slot its stage reaches or, for a stage that reaches one
through a handle, while one lives on the device; the twins' second compile and memory, and the
words' cost, 7.3 times the own view's GPU time for an `R8Unorm` texture buffer written on an
RTX 3090, are recorded as a known gap), and Shared
memory's host coherence (decided by the host-coherent flag of the memory type
Shared takes, the first host-visible, host-cached type a buffer can use, a host-coherent one
first: a device whose type has it makes no flush or invalidate call; on a device whose type is
+43 -34
View File
@@ -2033,17 +2033,21 @@ made, with no lock, and never rewritten for layouts.
its bytes, as Metal's heap does (the heap paragraph above). `offset` is a multiple of
`Device::minimum_texture_buffer_alignment(pixel_format)`, `minimumTextureBufferAlignmentForPixelFormat:`
(`Refusal::TextureBufferAlignment` otherwise): the device's texel-buffer offset alignment for
the format's texel, the larger of the uniform and the storage texel buffer's (Vulkan 1.3's
`…TexelBufferOffsetAlignmentBytes`, or the texel's bytes where the device's
`…TexelBufferOffsetSingleTexelAlignment` says one texel suffices), at most 256, so it divides
the multiple of 256 every buffer starts at. Metal documents the alignment for the row's bytes
the element of the format's view, the larger of the uniform and the storage texel buffer's
(Vulkan 1.3's `…TexelBufferOffsetAlignmentBytes`, or the element's bytes where the device's
`…TexelBufferOffsetSingleTexelAlignment` says one element suffices), at most 256, so it divides
the multiple of 256 every buffer starts at. Metal's query names no usage: where a texture
buffer of the format made both to be read and to be written is held as words and one made
otherwise is its own view (below), it answers the larger of the two views' alignments. Metal documents the alignment for the row's bytes
too; a texture buffer's one row reads no other, so any `bytes_per_row` that covers the row is
taken (`Refusal::BufferTextureLayout` below it, or for texels past the buffer). The view is of a
buffer of both usages, so its format takes both. One answer per format per device decides its
form (`metal::format::texel_buffer_form`): where the device holds the format directly, of one
colour texel an element, as a uniform texel buffer, a storage texel buffer and a storage texel
buffer written without a format, the view is of the format's own Vulkan format. Where it lacks
any of the three and the format has a word layout, 39 formats (docs/RESOURCE-ID.md, the texture
buffer of both usages, so its format takes both. One answer per format and usage per device
decides its form (`metal::format::texel_buffer_form`): where the device holds the format
directly, of one colour texel an element, as a uniform texel buffer, a storage texel buffer and
a storage texel buffer written without a format, and, for a texture buffer made both to be read
and to be written (`MTLTextureUsageShaderRead` with `MTLTextureUsageShaderWrite`, or
`MTLTextureUsageUnknown`), as a storage texel buffer read without a format, the view is of the
format's own Vulkan format. Where it lacks any of those and the format has a word layout, 39 formats (docs/RESOURCE-ID.md, the texture
buffer word), the texture buffer is held as words: the view is of `R32_UINT` over the same
bytes, its last word ending inside the buffer's block past the last texel, and shaders convert
each texel themselves; a texel of one or two bytes shares its word with its neighbours, and a
@@ -2060,7 +2064,9 @@ made, with no lock, and never rewritten for layouts.
or dispatch runs the plain pipeline. A format without a word layout (those Vulkan requires as a storage texel
buffer) is its own view where the device holds it for the first two, and `Gap::TextureFormat`
otherwise. The resource ID's word is the same on every device either way: it carries the
format's code wherever the format has a word layout, and the shader holds the device's answer.
format's code wherever the format has a word layout, and whether the texture buffer was made
both to be read and to be written (bit 11), and the shader holds the device's answers, testing
that bit only where they differ for some format.
A width whose view's elements pass `maxTexelBufferElements` is `Limit::TextureSize`. Its view is
the element of the uniform texel-buffer array at its index
where shaders read it, and of the storage one where they write it (the known gaps say where a
@@ -2326,10 +2332,10 @@ made, with no lock, and never rewritten for layouts.
two device-scope atomics on its word. An `R8Unorm` texture buffer of 2^24 texels written one
texel a thread took 7.3 times the GPU time of the format's own view on an RTX 3090 (p50 658 us
against 90.3 us; harness row `texel_buffer_r8_write`, job m3-max-80580). A device holds a format
so only where it lacks the format's own view for one of a texture buffer's accesses;
`metal::format::texel_buffer_form` says which formats a device's profile holds so. On such a
device each pipeline of a function that reaches a texture buffer is made twice, its words twin
beside it, in the same make: a second driver compile and a second `VkPipeline` held while the
so only where it lacks the format's own view for one of the accesses a texture buffer of its
usage makes; `metal::format::texel_buffer_form` says, for each format and usage, which a
device's profile holds so. On such a device each pipeline of a function that reaches a texture
buffer is made twice, its words twin beside it, in the same make: a second driver compile and a second `VkPipeline` held while the
first is. The twin compiles longer than the plain pipeline, whose word arms the driver folds
away: a program that binds a texture buffer pays it at each such state's make. On lavapipe
(llvmpipe, job m3-max-80997) a kernel state of the fixture `tb_word_formats` spent 16.9 to
@@ -2449,28 +2455,31 @@ made, with no lock, and never rewritten for layouts.
of a format without one (those Vulkan requires as a storage texel buffer) that a function writes
or reads through `access::read_write` is refused at that draw or dispatch, but at a slot a
texture atomic updates, and one it reads through `access::read` runs. On any device whose
buffer features lack `VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT` for a format held as
its own view, a read of a texture buffer of that format through `access::read_write` at a slot
is refused at the draw or dispatch alike, a format with a word layout held so (which takes the
write bit) among them. No further form is built for these; that changes on a second device
buffer features lack `VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT` for a format without
a word layout, a read of a texture buffer of that format through `access::read_write` at a slot
is refused at the draw or dispatch alike. A format with a word layout whose own view lacks that
bit is held as words for a texture buffer made both to be read and to be written (below), so
its read through `access::read_write` runs; one made to be read or written alone, which Metal
does not let a function reach through `access::read_write`, keeps its own view and that refusal.
No further form is built for these; that changes on a second device
above the floor whose formats lack those buffer features, or on a guest's walk that meets the
refusal on any device.
- ANV on an Intel Iris Xe Graphics (RPL-P) holds `BGRA8Unorm`, `B5G6R5Unorm`, `BGR5A1Unorm` and
`BGR10A2Unorm` as their own views: their Vulkan formats' buffer features take a uniform texel
buffer, a storage texel buffer and `VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT`, the
three uses `metal::format::texel_buffer_form` asks. They lack
`VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT`, the read without a format on the format's
own view, so there a draw or dispatch whose function reads a texture buffer of one of them through
`access::read_write` at a slot is `Gap::StorageElement` (case `ReadWithoutFormat`; jobs
m3-max-81883 and m3-max-82116). Its committed profile (`intel-irisxe-rplp-anv`) answers the same
for `RG11B10Float`, `RGB10A2Unorm` and `RGB10A2Uint`, and so do `intel-irisxe-anv` and
`intel-uhd770-rpls-anv` for all seven (job m3-max-82025). Holding those formats as words would
serve that read and slows every other: on that Iris Xe (ANV, Mesa 26.2.6) the harness rows
`texel_buffer_bgra8_read` and `texel_buffer_b5g6r5_read` take a GPU p50 of 11857.1 us and 12133.8
us as words against 9007.0 us and 9215.2 us as their own views, 31.6% and 31.7% more (the median
of 8 rounds of 500 runs each, the two forms' builds alternating, the own views' build against
itself within 0.1%; job m3-max-82136). No further form is built for this; that changes on a
guest's run or stream that meets this refusal.
- ANV on an Intel Iris Xe Graphics (RPL-P) serves `BGRA8Unorm`, `B5G6R5Unorm`, `BGR5A1Unorm` and
`BGR10A2Unorm` in their own views' buffer features as a uniform texel buffer, a storage texel
buffer and `VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT`, but lacks
`VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT` for them (jobs m3-max-81883 and
m3-max-82116), and its committed profile (`intel-irisxe-rplp-anv`) answers the same for
`RG11B10Float`, `RGB10A2Unorm` and `RGB10A2Uint`, as do `intel-irisxe-anv` and
`intel-uhd770-rpls-anv` for all seven (job m3-max-82025). There a texture buffer of one of the
seven made both to be read and to be written (or with unknown usage) is held as words, which a
function reads through `access::read_write` at a slot with no format's bit, and one made to be
read or written alone keeps its own view (`metal::format::texel_buffer_form` of its format and
usage). A texture buffer made to be read and written pays the words' cost on every access, read
and write alike: on that Iris Xe (ANV, Mesa 26.2.6) the harness rows `texel_buffer_bgra8_read`
and `texel_buffer_b5g6r5_read` take a GPU p50 of 11857.1 us and 12133.8 us as words against
9007.0 us and 9215.2 us as their own views, 31.6% and 31.7% more (the median of 8 rounds of 500
runs each, the two forms' builds alternating, the own views' build against itself within 0.1%;
job m3-max-82136).
- An upload into a 32-bit float depth (`Depth32Float`, or the depth of `Depth32Float_Stencil8`)
by `replace_region`, `upload_region` or a blit's `copy_from_buffer` is the device's copy into
the depth aspect, on every device, under the static note `PrecisionNote::RestrictedDepthUpload`
+4 -3
View File
@@ -3837,9 +3837,10 @@ pub struct Gauges {
/// [`kernel_variants`](Self::kernel_variants)' kernels' variants and in a render content's
/// pipelines. Only a device that holds some format's texture buffer as words makes them.
pub word_pipelines: u64,
/// Texture buffers held as words (`metal2vulkan::metal::format::texel_buffer_form`): while
/// any lives, a draw or dispatch of a stage that reaches a texture buffer through a handle runs
/// its words twin ([`word_pipelines`](Self::word_pipelines)).
/// Texture buffers held as words (`metal2vulkan::metal::format::texel_buffer_form` of each
/// one's format and usage): while any lives, a draw or dispatch of a stage that reaches a
/// texture buffer through a handle runs its words twin
/// ([`word_pipelines`](Self::word_pipelines)).
pub word_texture_buffers: u64,
/// Entries of the device's map of compiled contents, compute and render, which holds at most
/// 1,024 and forgets the least recently used past them.
@@ -512,12 +512,13 @@ mod on_device {
(!agree).then(|| format!("read {got:?}, the CPU's {want:?}"))
}
/// How `case`'s texels decode on `device`: where it holds the format's texture buffers as the
/// format's own view, a normalized format's fields are the device's conversion
/// ([`Decode::Device`]); else, words decoding as the CPU does, the case's own.
fn decode_on(device: &Device, case: &Case) -> Decode {
/// How `case`'s texels decode on `device` through a texture buffer made with `usage`: where
/// it holds such a texture buffer as the format's own view, a normalized format's fields are
/// the device's conversion ([`Decode::Device`]); else, words decoding as the CPU does, the
/// case's own.
fn decode_on(device: &Device, case: &Case, usage: TextureUsage) -> Decode {
let own = matches!(
formats::texel_buffer_form(case.format, device.translator().profile()),
formats::texel_buffer_form(case.format, usage, device.translator().profile()),
Some(formats::TexelBufferForm::View(_))
);
let layout = formats::texel_words(case.format).map(|w| w.layout);
@@ -534,14 +535,27 @@ mod on_device {
}
}
/// Whether `device` holds `format`'s texture buffers as the format's own view and that view's
/// format lacks a storage texel buffer read without a format
/// (`VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT`), which a read-written texture
/// The usage of a texture buffer made both to be read and to be written.
const BOTH: TextureUsage = TextureUsage::SHADER_READ.union(TextureUsage::SHADER_WRITE);
/// Whether `device` holds a texture buffer of `format` made with `usage` as words.
fn held_as_words(device: &Device, format: PixelFormat, usage: TextureUsage) -> bool {
let profile = device.translator().profile();
matches!(
formats::texel_buffer_form(format, usage, profile),
Some(formats::TexelBufferForm::Words(_))
)
}
/// Whether `device` holds `format`'s texture buffers made both to be read and to be written as
/// the format's own view and that view's format lacks a storage texel buffer read without a
/// format (`VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT`), which a read-written texture
/// buffer (`access::read_write`) reads through: the runtime refuses that access
/// ([`read_write_gap`]), the runtime README's known gap.
/// ([`read_write_gap`]), the runtime README's known gap. Never for a format with a word
/// layout, which such a device holds as words for that usage.
fn reads_none_without_format(device: &Device, format: PixelFormat) -> bool {
let profile = device.translator().profile();
match formats::texel_buffer_form(format, profile) {
match formats::texel_buffer_form(format, BOTH, profile) {
Some(formats::TexelBufferForm::View(view)) => {
!profile.supports_format(view, FormatUsage::StorageTexelBufferReadWithoutFormat)
}
@@ -620,10 +634,10 @@ mod on_device {
};
let counters = &device.core().counters;
let twins = counters.twin_runs();
let held = matches!(
formats::texel_buffer_form(case.format, device.translator().profile()),
Some(formats::TexelBufferForm::Words(_))
);
// Read alone at slot 0, written alone at slot 1, read and written at slot 2.
let held = held_as_words(device, case.format, TextureUsage::SHADER_READ)
|| held_as_words(device, case.format, TextureUsage::SHADER_WRITE)
|| held_as_words(device, case.format, BOTH);
let out_of_bounds = [0.0, 0.0, 0.0, if case.alpha { 0.0 } else { 1.0 }];
// The read-written one (slot 2) is refused where the device's own view of the format reads
// none without a format (the runtime README's known gap); the handles' kernel below reads
@@ -645,8 +659,8 @@ mod on_device {
Ok(()) => {}
}
if !refused {
// The words twin runs where the device holds the format as words, the plain pipeline
// elsewhere.
// The words twin runs where the device holds a bound texture buffer as words, the
// plain pipeline elsewhere.
let ran = counters.twin_runs() - twins;
if ran != u64::from(held) {
wrong.push(format!(
@@ -662,15 +676,15 @@ mod on_device {
),
false => (out_of_bounds, out_of_bounds),
};
let decode = if t < WIDTH {
decode_on(device, case)
} else {
Decode::Exact
let decode = |usage| match t < WIDTH {
true => decode_on(device, case, usage),
false => Decode::Exact,
};
if let Some(d) = differs(&reads[4 * t..4 * t + 4], want, decode) {
let read = decode(TextureUsage::SHADER_READ);
if let Some(d) = differs(&reads[4 * t..4 * t + 4], want, read) {
wrong.push(format!("texel {t} of the read one: {d}"));
}
if let Some(d) = differs(&rw_reads[4 * t..4 * t + 4], rw_want, decode) {
if let Some(d) = differs(&rw_reads[4 * t..4 * t + 4], rw_want, decode(BOTH)) {
wrong.push(format!("texel {t} of the read-written one: {d}"));
}
}
@@ -749,7 +763,7 @@ mod on_device {
let (want, decode) = match t < WIDTH {
true => (
(case.value)(&texel(&case.texels, t)),
decode_on(device, case),
decode_on(device, case, TextureUsage::SHADER_READ),
),
false => (out_of_bounds, Decode::Exact),
};
@@ -797,11 +811,17 @@ mod on_device {
let mut failed = Vec::new();
let profile = device.translator().profile();
for case in cases() {
let form = match formats::texel_buffer_form(case.format, profile) {
let form_of = |usage| match formats::texel_buffer_form(case.format, usage, profile)
{
Some(formats::TexelBufferForm::Words(_)) => "words",
Some(formats::TexelBufferForm::View(_)) => "own view",
None => "refused",
};
let (alone, both) = (form_of(TextureUsage::SHADER_READ), form_of(BOTH));
let form = match alone == both {
true => alone.to_owned(),
false => format!("{alone}; made to be read and written, {both}"),
};
let wrong = run(&device, &library, &case);
let refused = reads_none_without_format(&device, case.format);
match wrong.is_empty() {
@@ -875,11 +895,10 @@ mod on_device {
let made = data.new_texture(&d, Some(index), at, 256);
made.map(|t| (t, counters.gauges().word_texture_buffers > before))
};
let both = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE;
let made = (
make(PLACES[0], 1, both),
make(PLACES[1], 2, both),
make(PLACES[2], 3, both),
make(PLACES[0], 1, BOTH),
make(PLACES[1], 2, BOTH),
make(PLACES[2], 3, BOTH),
);
let ((src, src_words), (dst, dst_words), (rw, rw_words)) = match made {
(Ok(src), Ok(dst), Ok(rw)) => (src, dst, rw),
@@ -888,6 +907,12 @@ mod on_device {
return vec![format!("not made: {why:?}")];
}
};
// Each is held as the form the device answers for its format and usage.
let held = held_as_words(device, case.format, BOTH);
if [src_words, dst_words, rw_words] != [held; 3] {
let made = [src_words, dst_words, rw_words];
wrong.push(format!("held as words {made:?}, the form's answer {held}"));
}
let function = library.function("tb_word_formats").expect("the kernel");
let descriptor = ComputePipelineDescriptor::new(StageSource::Function(
FunctionDescriptor::new(function),
@@ -897,8 +922,8 @@ mod on_device {
Err(error) => return vec![format!("no state: {error}")],
};
let out_of_bounds = [0.0, 0.0, 0.0, if case.alpha { 0.0 } else { 1.0 }];
let decode = |t: usize| match t < WIDTH {
true => decode_on(device, case),
let decode = |t: usize, usage| match t < WIDTH {
true => decode_on(device, case, usage),
false => Decode::Exact,
};
// Read at slot 0, written at slot 1, read and written at slot 2, each made to be both.
@@ -923,10 +948,10 @@ mod on_device {
),
false => (out_of_bounds, out_of_bounds),
};
if let Some(d) = differs(&got[4 * t..4 * t + 4], want, decode(t)) {
if let Some(d) = differs(&got[4 * t..4 * t + 4], want, decode(t, BOTH)) {
wrong.push(format!("texel {t} read at slot 0: {d}"));
}
if let Some(d) = differs(&rw_got[4 * t..4 * t + 4], rw_want, decode(t)) {
if let Some(d) = differs(&rw_got[4 * t..4 * t + 4], rw_want, decode(t, BOTH)) {
wrong.push(format!("texel {t} read at slot 2: {d}"));
}
}
@@ -956,6 +981,16 @@ mod on_device {
return wrong;
}
};
let answers = [
held_as_words(device, case.format, TextureUsage::SHADER_READ),
held_as_words(device, case.format, TextureUsage::SHADER_WRITE),
];
if [read_words, write_words] != answers {
let made = [read_words, write_words];
wrong.push(format!(
"alone held as words {made:?}, the form's answers {answers:?}"
));
}
set_bytes(&reads, 0, &[0; 256]);
set_bytes(&rw_reads, 0, &[0; 256]);
let twins = counters.twin_runs();
@@ -977,10 +1012,11 @@ mod on_device {
true => (case.value)(&texel(&case.texels, t)),
false => out_of_bounds,
};
if let Some(d) = differs(&got[4 * t..4 * t + 4], want, decode(t)) {
let read = decode(t, TextureUsage::SHADER_READ);
if let Some(d) = differs(&got[4 * t..4 * t + 4], want, read) {
wrong.push(format!("texel {t} read by one made to be read alone: {d}"));
}
if let Some(d) = differs(&rw_got[4 * t..4 * t + 4], want, decode(t)) {
if let Some(d) = differs(&rw_got[4 * t..4 * t + 4], want, decode(t, BOTH)) {
wrong.push(format!("texel {t} read again at slot 2: {d}"));
}
}
@@ -1188,7 +1224,7 @@ mod on_device {
.enumerate()
.map(|(k, format)| {
let words = matches!(
formats::texel_buffer_form(format, profile),
formats::texel_buffer_form(format, TextureUsage::SHADER_READ, profile),
Some(formats::TexelBufferForm::Words(_))
);
let form = if words { "words" } else { "own view" };
@@ -1331,10 +1367,7 @@ mod on_device {
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]));
for (index, (format, texels)) in (1..).zip(&cases) {
let held = matches!(
formats::texel_buffer_form(*format, device.translator().profile()),
Some(formats::TexelBufferForm::Words(_))
);
let held = held_as_words(&device, *format, TextureUsage::SHADER_READ);
let data = buffers.of(&device, texels);
let mut td = TextureDescriptor::new(TextureType::TextureBuffer, *format, 5, 1);
td.usage = TextureUsage::SHADER_READ;
+38 -22
View File
@@ -4493,7 +4493,7 @@ impl Transfer {
impl TextureInner {
/// Whether it is a texture buffer held as words
/// (`metal2vulkan::metal::format::texel_buffer_form`), for which a draw or dispatch that binds
/// (`metal2vulkan::metal::format::texel_buffer_form` of its format and usage), for which a draw or dispatch that binds
/// it where a function reaches it runs its words twin.
pub(crate) fn held_as_words(&self) -> bool {
matches!(&self.body, Body::Texels(texels) if texels.words)
@@ -7240,23 +7240,25 @@ struct TexelForm {
reads: bool,
}
/// What a texture buffer of `pf` holds on the device of `core`, as
/// `metal::format::texel_buffer_form` decides for the device: the format's own view, of one color
/// texel an element, which the device holds directly as a uniform texel buffer, a storage texel
/// buffer and a storage texel buffer written without a format, as its one view is of a buffer of
/// both usages and its format takes both (`VUID-VkBufferViewCreateInfo-format-08778`, `-08779`);
/// else words, a view of `R32_UINT`, which Vulkan requires as both texel buffers, whose texels
/// shaders convert, and whose storage element is declared with that format, so neither its writes
/// nor its reads ask a format's bits for a storage texel buffer without a format; else, for a
/// format with no word layout, its own view of the two texel buffers alone, whose write without a
/// format a dispatch then refuses ([`TexelForm`]'s `writes`).
/// What a texture buffer of `pf` made with `usage` holds on the device of `core`, as
/// `metal::format::texel_buffer_form` decides for the device, one answer per format and usage: the
/// format's own view, of one color texel an element, which the device holds directly as a uniform
/// texel buffer, a storage texel buffer and a storage texel buffer written without a format, and,
/// made both to be read and to be written (`metal::format::texel_buffer_read_write`), read
/// without a format, as its one view is of a buffer of both usages and its format takes both
/// (`VUID-VkBufferViewCreateInfo-format-08778`, `-08779`); else words, a view of `R32_UINT`, which
/// Vulkan requires as both texel buffers, whose texels shaders convert, and whose storage element
/// is declared with that format, so neither its writes nor its reads ask a format's bits for a
/// storage texel buffer without a format; else, for a format with no word layout, its own view of
/// the two texel buffers alone, whose write or read without a format a dispatch then refuses
/// where the format lacks it ([`TexelForm`]'s `writes` and `reads`).
///
/// Err: [`Gap::TextureFormat`] for any other format.
fn texel_form(core: &Core, pf: PixelFormat) -> Result<TexelForm, Error> {
fn texel_form(core: &Core, pf: PixelFormat, usage: TextureUsage) -> Result<TexelForm, Error> {
let gap = || Error::Unsupported(Gap::TextureFormat { pixel_format: pf });
TextureWord::of(pf, TextureSwizzleChannels::DEFAULT).ok_or_else(gap)?;
let profile = core.translator.profile();
match formats::texel_buffer_form(pf, profile).ok_or_else(gap)? {
match formats::texel_buffer_form(pf, usage, profile).ok_or_else(gap)? {
formats::TexelBufferForm::Words(words) => Ok(TexelForm {
format: words.element_format().into(),
bytes: words.bytes,
@@ -7357,10 +7359,13 @@ fn texel_width(core: &Core, d: &TextureDescriptor, form: &TexelForm) -> Result<u
impl Device {
/// `minimumTextureBufferAlignmentForPixelFormat:`: what a texture buffer's offset in its
/// buffer is a multiple of ([`Buffer::new_texture`]), the device's texel-buffer offset
/// alignment for the format's texel: for each of the uniform and the storage texel buffer,
/// Vulkan 1.3's `…TexelBufferOffsetAlignmentBytes`, or the texel's bytes where those are
/// less and the device's `…TexelBufferOffsetSingleTexelAlignment` says one texel suffices; the
/// larger of the two. The answer differs by device, as Metal's does by GPU, and is never more
/// alignment for the element of the format's view: for each of the uniform and the storage
/// texel buffer, Vulkan 1.3's `…TexelBufferOffsetAlignmentBytes`, or the element's bytes where
/// those are less and the device's `…TexelBufferOffsetSingleTexelAlignment` says one element
/// suffices; the larger of the two. Metal's query names no usage, and a texture buffer of the
/// format made both to be read and to be written may be held as words, a 4-byte element,
/// where one made otherwise is the format's own view (`metal::format::texel_buffer_form`), so
/// the answer is the larger of those two views' alignments. The answer differs by device, as Metal's does by GPU, and is never more
/// than 256, Vulkan's bound on both, so it divides the multiple of 256 every buffer the
/// consumer places by [`Device::heap_buffer_size_and_align`]'s rule starts at. No Vulkan call
/// is made. Metal documents the alignment for the offset and the row's bytes; the runtime
@@ -7374,8 +7379,19 @@ impl Device {
pixel_format: PixelFormat,
) -> Result<u64, Error> {
let core = self.core();
let form = texel_form(core, pixel_format)?;
Ok(core.texels.alignment(u64::from(form.element)))
// The larger of the format's two forms' alignments: a texture buffer made both to be read
// and to be written may be words where one made to be read or written alone is the
// format's own view.
let usages = [
TextureUsage::SHADER_READ,
TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE,
];
let mut alignment = 0;
for usage in usages {
let form = texel_form(core, pixel_format, usage)?;
alignment = alignment.max(core.texels.alignment(u64::from(form.element)));
}
Ok(alignment)
}
/// [`Device::heap_texture_size_and_align`] of a texture buffer: its texels' bytes, the width
@@ -7388,7 +7404,7 @@ impl Device {
fn heap_texels_fit(&self, d: &TextureDescriptor) -> Result<SizeAndAlign, Error> {
let core = self.core();
texel_shape(d)?;
let form = texel_form(core, d.pixel_format)?;
let form = texel_form(core, d.pixel_format, d.usage)?;
texel_width(core, d, &form)?;
let texel = u64::from(form.bytes);
Ok(SizeAndAlign {
@@ -7460,7 +7476,7 @@ impl Device {
Reach::Index(index) => index,
Reach::Views => None,
};
let form = texel_form(core, d.pixel_format)?;
let form = texel_form(core, d.pixel_format, d.usage)?;
let alignment = core.texels.alignment(u64::from(form.element));
if !offset.is_multiple_of(alignment) {
return refused(Refusal::TextureBufferAlignment {
@@ -7571,7 +7587,7 @@ impl Device {
block: [1, 1],
}),
index,
word: TextureWord::of_texture_buffer(d.pixel_format, d.width)
word: TextureWord::of_texture_buffer(d.pixel_format, d.width, d.usage)
.ok_or(Error::Unsupported(Gap::TextureFormat {
pixel_format: d.pixel_format,
}))?
@@ -1 +1 @@
4361761cd1b7abfc1100a2b80a0cdf66a5324cf12567f8ccee91fa07eafce585
a92fe0a8051bc835e111d4c69f56892c6035dee3a96cb2f9ab75d1b0b3002002
@@ -3213,9 +3213,11 @@ impl Backend for NewRuntime {
Object::Texture(texture) => {
let descriptor = texture.descriptor();
let word = match descriptor.texture_type {
rt::TextureType::TextureBuffer => {
TextureWord::of_texture_buffer(descriptor.pixel_format, descriptor.width)
}
rt::TextureType::TextureBuffer => TextureWord::of_texture_buffer(
descriptor.pixel_format,
descriptor.width,
descriptor.usage,
),
_ => TextureWord::of(descriptor.pixel_format, descriptor.swizzle),
};
word.map(|word| word.0)
@@ -145,18 +145,18 @@
//! (`external_acquires`, `external_releases`) are what the runtime's documented contract gives
//! for the frame's records; where the device exports no such handle, the refusal is counted.
//! - Texture buffers over a Shared buffer (`newTextureWithDescriptor:offset:bytesPerRow:` of a
//! texture buffer's descriptor) of five formats, each read, written, and read then written by the
//! owned fixture `tb_word_formats`, play with the IDs the stream recorded (each its index and
//! `TextureWord::of_texture_buffer`, which is the same on every device), no `id` line, and the
//! texels and values the CPU decodes, whichever form the device holds each format in
//! (`metal::format::texel_buffer_form`: its own view or words), which the test prints. Words
//! decode to the CPU's values bit for bit; an own view's values are the device's own conversion
//! of each code, `PrecisionNote::DeviceTexelConversion`, which the fixture's state records, within
//! that note's recorded bound of the CPU's (lavapipe multiplies by the reciprocal: one ulp).
//! Where the device holds a format as its own view and that view reads none without a format
//! (the Iris Xe's `BGRA8Unorm` and `B5G6R5Unorm`), the play ends at the dispatch in the runtime's
//! refusal of the read-written one by name (`Gap::StorageElement`, `ReadWithoutFormat`, the
//! runtime README's known gap), with no `id` line before it.
//! texture buffer's descriptor) of five formats, one made to be read, one to be written and one
//! to be both, each read, written, and read then written by the owned fixture `tb_word_formats`,
//! play with the IDs the stream recorded (each its index and `TextureWord::of_texture_buffer` of
//! its format, width and usage, which is the same on every device), no `id` line, and the texels
//! and values the CPU decodes, whichever form the device holds each in
//! (`metal::format::texel_buffer_form` of its format and usage: its own view or words), which the
//! test prints. Words decode to the CPU's values bit for bit; an own view's values are the
//! device's own conversion of each code, `PrecisionNote::DeviceTexelConversion`, which the
//! fixture's state records, within that note's recorded bound of the CPU's (lavapipe multiplies
//! by the reciprocal: one ulp). The texture buffer made to be read and written is words wherever
//! its format's own view reads none without a format (the Iris Xe's `BGRA8Unorm` and
//! `B5G6R5Unorm`), so each format plays on every device.
//!
//! The runtime's device is opened behind the hang tripwire, as every device open in this crate
//! is (`gpu.rs`), its kernels kept in a cache the test owns ([`ScratchCache`]). Every device a test
@@ -174,9 +174,9 @@ use crate::replay::{
StreamReader, StreamWriter, Value, HELD, WAIT_COMPLETED,
};
use crate::ScratchDir;
use metal2vulkan::device::FormatUsage;
use metal2vulkan::metal::format::{texel_buffer_form, TexelBufferForm};
use metal2vulkan::metal::resource_word::TextureWord;
use metal2vulkan::metal::TextureUsage;
use metal2vulkan_devtools::metallib::{metallib, wrap, MtlbFunction};
use sha2::{Digest, Sha256};
use std::collections::{BTreeSet, HashSet};
@@ -2385,6 +2385,14 @@ const TB_THREADS: usize = 8;
const TB_SENTINEL: u8 = 0x5a;
/// Where the read, the written and the read-written texture buffers lie in the data buffer.
const TB_PLACES: [usize; 3] = [1024, 2048, 3072];
/// The read-written texture buffer's usage: both, fixed at its making.
const TB_READ_WRITE: TextureUsage = TextureUsage::SHADER_READ.union(TextureUsage::SHADER_WRITE);
/// The usages the read, the written and the read-written texture buffers are made with.
const TB_USAGES: [TextureUsage; 3] = [
TextureUsage::SHADER_READ,
TextureUsage::SHADER_WRITE,
TB_READ_WRITE,
];
/// The five texels of `case`'s source: byte `i` of the texels is `37 i + 11`.
fn tb_texels(case: &TexelBufferCase) -> Vec<u8> {
@@ -2444,14 +2452,14 @@ fn texture_buffer_stream(dir: &ScratchDir, case: &TexelBufferCase) -> PathBuf {
let args = [Value::Bytes(data), Value::Uint(len), Value::Uint(0)];
w.call("newBufferWithBytes:length:options:", 1, id, &args, &[])?;
}
for (i, (at, usage)) in TB_PLACES.into_iter().zip([1, 2, 3]).enumerate() {
for (i, (at, usage)) in TB_PLACES.into_iter().zip(TB_USAGES).enumerate() {
let id = 20 + i as u64;
let descriptor = uints(&[
("textureType", 9),
("pixelFormat", u64::from(case.format.as_raw())),
("width", TB_WIDTH as u64),
("height", 1),
("usage", usage),
("usage", u64::from(usage.as_raw())),
("storageMode", 0),
]);
let made = 40 + i as u64;
@@ -2468,7 +2476,7 @@ fn texture_buffer_stream(dir: &ScratchDir, case: &TexelBufferCase) -> PathBuf {
&args,
&[],
)?;
let word = TextureWord::of_texture_buffer(case.format, TB_WIDTH as u32)
let word = TextureWord::of_texture_buffer(case.format, TB_WIDTH as u32, usage)
.expect("a texture buffer's word")
.0;
let index = 1 + i as u64;
@@ -2545,61 +2553,18 @@ fn texture_buffers_play_with_their_recorded_ids_and_the_cpu_s_texels() {
let cache = ScratchCache::new().unwrap();
let device = rt_device(&cache);
let profile = device.translator().profile();
let form = match texel_buffer_form(case.format, profile) {
// The read-only and write-only textures hold the format in one form, the read-written
// one (made with both usages) in its own: words wherever its own view reads none without
// a format (`texel_buffer_form`).
let form_of = |usage| match texel_buffer_form(case.format, usage, profile) {
Some(TexelBufferForm::Words(_)) => "words",
Some(TexelBufferForm::View(_)) => "own view",
None => "refused",
};
let read_form = form_of(TextureUsage::SHADER_READ);
let rw_form = form_of(TB_READ_WRITE);
let form = format!("{read_form}, read_write {rw_form}");
let test = format!("texture-buffers-{:?}", case.format);
// Where the device's own view of the format reads none without a format, the runtime
// refuses the read-written one (`access::read_write`) at the dispatch, by name
// (`Gap::StorageElement`, `StorageElementCase::ReadWithoutFormat`): the runtime README's
// known gap. The textures before it play with their recorded IDs all the same.
let reads_none = match texel_buffer_form(case.format, profile) {
Some(TexelBufferForm::View(view)) => {
!profile.supports_format(view, FormatUsage::StorageTexelBufferReadWithoutFormat)
}
_ => false,
};
if reads_none {
let mut backend = NewRuntime::new(device, gpu::TEST_DEVICE).unwrap();
let mut reader = StreamReader::open(std::slice::from_ref(&path), None).unwrap();
let (report, ended) = Player::new(&mut backend).play(&mut reader);
let ids: Vec<String> = (report.lines().iter())
.filter(|l| l.starts_with("id "))
.cloned()
.collect();
let refusal = format!(
"texture slot 2, which a function writes or reads as storage, bound to a {:?} \
texture with no storage element on this device, or one it cannot read without a \
format",
case.format
);
match ended {
Err(PlayError::Runtime { selector, error })
if ids.is_empty()
&& selector == "dispatchThreads:threadsPerThreadgroup:"
&& error.starts_with(&refusal) =>
{
eprintln!(
"TEXTURE-BUFFERS {:?} ({form}): recorded IDs; the read-written one refused \
(Gap::StorageElement, ReadWithoutFormat): its own view reads none without \
a format",
case.format
);
}
other => {
eprintln!(
"TEXTURE-BUFFERS {:?} ({form}): not the read-written one's refusal: IDs \
{ids:?}, {other:?}",
case.format
);
failed.push(case.format);
}
}
drop(cache);
continue;
}
let (report, lines, read) = play_on(device, &test, &path, |backend| {
[10, 12, 13, 14].map(|object| backend.read(object).unwrap())
});
@@ -2618,7 +2583,7 @@ fn texture_buffers_play_with_their_recorded_ids_and_the_cpu_s_texels() {
}
// Words decode bit for bit; an own view is the device's conversion of each code
// (`PrecisionNote::DeviceTexelConversion`), within its recorded bound.
let agree = |got: [f32; 4], want: [f32; 4]| {
let agree = |form: &str, got: [f32; 4], want: [f32; 4]| {
(got.iter().zip(want)).all(|(&g, w)| match form {
"words" => g.to_bits() == w.to_bits(),
_ => within_texel_conversion(g, w, case.bits),
@@ -2632,14 +2597,14 @@ fn texture_buffers_play_with_their_recorded_ids_and_the_cpu_s_texels() {
};
for t in 0..TB_WIDTH {
let read = (case.value)(tb_texel(&case, &texels, t));
if !agree(floats(&reads, t), read) {
if !agree(read_form, floats(&reads, t), read) {
wrong.push(format!(
"read {t}: {:?}, the CPU's {read:?}",
floats(&reads, t)
));
}
let first = (case.value)(tb_texel(&case, &texels, TB_WIDTH - 1 - t));
if !agree(floats(&rw_reads, t), first) {
if !agree(rw_form, floats(&rw_reads, t), first) {
wrong.push(format!(
"read_write {t}: {:?}, the CPU's {first:?}",
floats(&rw_reads, t)
+2 -2
View File
@@ -60,7 +60,7 @@ mod tests;
/// unchanged version, and its bless records the version. Independent of the crate's version and of
/// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no
/// history.
pub const SEMANTICS_VERSION: u32 = 2338;
pub const SEMANTICS_VERSION: u32 = 2339;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
@@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 605;
/// 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 = 2557;
pub const RUNTIME_VERSION: u32 = 2558;
/// Writes a digest as lowercase hex.
pub(crate) fn write_hex(f: &mut fmt::Formatter<'_>, name: &str, hash: &Hash256) -> fmt::Result {
+36 -19
View File
@@ -2,13 +2,16 @@
//!
//! Under the identity domains a texture buffer of a colour format the device does not hold
//! directly as a uniform texel buffer, a storage texel buffer and a storage texel buffer written
//! without a format is a view of its bytes as `R32_UINT`. Its
//! without a format, and, for one made both to be read and to be written, read without a format,
//! is a view of its bytes as `R32_UINT`. Its
//! resource ID's word carries, on every device, its format's code wherever the format has a word
//! layout, its texels per word, whether a texel is two words, and the texels its last word holds
//! past its width (`resource_word::TextureWord::of_texture_buffer`); the module takes the codes its
//! device holds as words from its profile (`metal::format::texel_buffer_word_codes`), and declares
//! nothing of this where there are none. A texture-buffer slot's read, write and width query test
//! the code against those ([`Words`]), under the stage's `SpecKey::TexelBufferWords` ([`gate`]):
//! past its width, and whether it was made both to be read and to be written
//! (`resource_word::TextureWord::of_texture_buffer`); the module takes the codes its device holds
//! as words for each usage from its profile (`metal::format::texel_buffer_word_codes`), and
//! declares nothing of this where there are none. A texture-buffer slot's read, write and width
//! query test the code, and where the two usages' codes differ the usage bit, against those
//! ([`Words`]), under the stage's `SpecKey::TexelBufferWords` ([`gate`]):
//! where that is false, as it is by default, the test and every arm of the words are dead code at
//! pipeline creation and each access is the texture's own view's alone. Where the device does
//! not hold the code as words the access is the texture's own view's, as it is for every other
@@ -71,7 +74,7 @@ use crate::lower::select::SelectCx;
use crate::memory::leaf::Coherence;
use crate::metal::format::{
texel_buffer_word_codes, texel_words, ExtendedRange, FieldKind, TexelField, TexelWords,
WordLayout, WORD_FORMATS,
WordCodes, WordLayout, WORD_FORMATS,
};
use crate::metal::resource_word::TextureWord;
use crate::pipeline::artifact::PrecisionNote;
@@ -132,9 +135,9 @@ pub struct WordsPlan {
/// An access is of an argument buffer's texture buffer, whose handle then carries its word's
/// low bits ([`HANDLE_WORD`]).
pub heap: bool,
/// The codes the profile holds as words: bit `c` for code `c`
/// The codes the profile holds as words, by usage: bit `c` for code `c`
/// (`metal::format::texel_buffer_word_codes`).
pub codes: u64,
pub codes: WordCodes,
/// Its writes store an `RGB9E5Float` word's mantissas rounded half up (`Write::half_up`: a
/// fragment function's, in a pipeline of `textureWriteRoundingMode` 2), else toward zero.
pub half_up: bool,
@@ -235,7 +238,7 @@ pub(super) fn wrap(
return Ok(s);
}
let codes = texel_buffer_word_codes(cx.profile);
if codes == 0 {
if codes.any() == 0 {
return Ok(s);
}
let (storage, _) = super::image_access(cx, image)?;
@@ -279,11 +282,11 @@ pub(super) fn wrap(
plan.codes = codes;
// The conversions the routine's cases take: an 8-bit sRGB colour's and an extended-range
// texel's are the device's.
let srgb = held(codes).any(|w| match w.layout {
let srgb = held(codes.any()).any(|w| match w.layout {
WordLayout::Fields { fields, .. } => fields.iter().flatten().any(|f| f.srgb),
_ => false,
});
let extended = held(codes).any(|w| matches!(w.layout, WordLayout::Extended(_)));
let extended = held(codes.any()).any(|w| matches!(w.layout, WordLayout::Extended(_)));
if let Some(r) = routine {
plan.routines.insert(r);
match r {
@@ -399,7 +402,7 @@ pub(super) fn declare(
storage,
nonuniform,
};
define_read(mb, (class, plan.codes), array, (coherence, volatile))?
define_read(mb, (class, plan.codes.any()), array, (coherence, volatile))?
}
Routine::Write { class, nonuniform } => {
let Some(g) = d.storage else { continue };
@@ -410,7 +413,7 @@ pub(super) fn declare(
};
define_write(
mb,
(class, plan.codes, plan.half_up),
(class, plan.codes.any(), plan.half_up),
array,
(coherence, volatile),
)?
@@ -575,18 +578,32 @@ pub(crate) fn gate(cx: &EmitCx<'_>, fb: &mut FunctionBuilder<'_>) -> BResult<SVa
fb.module().const_value(c)
}
/// Whether word `word` (`u32`) names a format of `codes` ([`WordsPlan::codes`]): a texture
/// Whether word `word` (`u32`) names a format held as words ([`WordsPlan::codes`]): a texture
/// buffer's word of a word layout (`TextureWord::TEXEL_BUFFER_LAYOUT`, which every other word
/// clears, its bits 2-7 then a border texel's) where `codes` are every format's; else, besides,
/// the code's bit of `codes`.
fn held_test(fb: &mut FunctionBuilder<'_>, word: SValue, codes: u64) -> BResult<SValue> {
/// clears, its bits 2-7 then a border texel's) whose code is held as words for its usage. Where
/// the profile holds the same codes for either usage the word's usage bit
/// (`TextureWord::TEXEL_BUFFER_READ_WRITE`) is not read: the code's bit of those codes, or
/// nothing besides the layout where they are every format's. Else the code's bit of those held
/// for a texture buffer made to be read or written alone, or the usage bit and the code's bit of
/// those held only for one made both to be read and to be written.
fn held_test(fb: &mut FunctionBuilder<'_>, word: SValue, codes: WordCodes) -> BResult<SValue> {
let every = held(u64::MAX).fold(0u64, |all, w| all | 1 << w.code);
let layout = layout_test(fb, word)?;
if codes == every {
if codes.alone == codes.read_write && codes.alone == every {
return Ok(layout);
}
let code = code_of(fb, word)?;
let bit = code_in(fb, code, codes)?;
let mut bit = code_in(fb, code, codes.alone)?;
let read_write_alone = codes.read_write & !codes.alone;
if read_write_alone != 0 {
let flag = ku(fb, TextureWord::TEXEL_BUFFER_READ_WRITE)?;
let flag = fb.binary(BinOp::BitwiseAnd, word, flag)?;
let zero = ku(fb, 0)?;
let made = fb.binary(BinOp::INotEqual, flag, zero)?;
let moved = code_in(fb, code, read_write_alone)?;
let moved = fb.binary(BinOp::LogicalAnd, made, moved)?;
bit = fb.binary(BinOp::LogicalOr, bit, moved)?;
}
fb.binary(BinOp::LogicalAnd, layout, bit)
}
+4 -3
View File
@@ -40,11 +40,12 @@ mod texel_words;
mod word;
pub use footprint::{footprint, Footprint};
pub(crate) use packed_codes::packed_codes;
pub(crate) use texel_words::texel_buffer_word_codes;
pub use texel_words::{
required_storage_texel_buffer, texel_buffer_form, texel_buffer_words, texel_words, word_format,
FieldKind, TexelBufferForm, TexelField, TexelWords, WordLayout, WORD_FORMATS,
required_storage_texel_buffer, texel_buffer_form, texel_buffer_read_write, texel_buffer_words,
texel_words, word_format, FieldKind, TexelBufferForm, TexelField, TexelWords, WordLayout,
WORD_FORMATS,
};
pub(crate) use texel_words::{texel_buffer_word_codes, WordCodes};
pub use word::{WordAttachment, WordField};
/// How a Metal pixel format is represented on a device, for a set of usages.
@@ -7,20 +7,24 @@
//! `VK_KHR_maintenance5`, which the floor does not require, a view takes its buffer's usages
//! (`VUID-VkBufferViewCreateInfo-format-08778`, `-08779`), so its format must hold both; a shader
//! writes it through a storage texel buffer declared without a format, so its format must take
//! that write too. [`texel_buffer_form`] is the one place that decides, for each format on each
//! device: the format's own view where the device holds it directly as a uniform texel buffer, a
//! storage texel buffer and a storage texel buffer written without a format, else words where the
//! that write too, and reads one made both to be read and to be written through that storage
//! texel buffer (`access::read_write`), so its format must take that read too.
//! [`texel_buffer_form`] is the one place that decides, for each format and usage on each device:
//! the format's own view where the device holds it directly as a uniform texel buffer, a storage
//! texel buffer and a storage texel buffer written without a format, and, made both to be read
//! and to be written ([`texel_buffer_read_write`]), read without a format; else words where the
//! format has a word layout ([`texel_buffer_words`]), else its own view of the first two, whose
//! writes the runtime refuses. Vulkan requires the first two of few formats
//! writes and reads without a format the runtime refuses where the format lacks them. Vulkan requires the first two of few formats
//! (its mandatory format tables: the 8-bit four-channel and the 32-bit formats, and the 16-bit
//! four-channel float and integer ones, [`required_storage_texel_buffer`]), which have no word
//! layout. `R32_UINT` is among them, and its storage texel buffer atomics are required too; a word
//! view's storage element is declared `R32ui`, so its writes ask no format's bit.
//!
//! A texture buffer's resource ID word carries its format's code wherever the format has a word
//! layout, on every device, so a program's IDs are the same on every device; a module takes the
//! codes its device holds as words from the profile it is compiled for
//! ([`texel_buffer_word_codes`]), and reaches the format's own view for any other.
//! layout, and whether it was made both to be read and to be written, on every device, so a
//! program's IDs are the same on every device; a module takes the codes its device holds as words
//! for each usage from the profile it is compiled for ([`texel_buffer_word_codes`]), and reaches
//! the format's own view for any other.
//!
//! The view's elements are words: a texel of one or two bytes shares its word with its
//! neighbours, read by shifting it out and written by an atomic AND that clears its bits and an
@@ -37,7 +41,7 @@ use std::collections::BTreeSet;
use crate::device::requirements::FormatUsage;
use crate::device::DeviceProfile;
use crate::metal::format::{ExtendedRange, FormatEmulation};
use crate::metal::PixelFormat;
use crate::metal::{PixelFormat, TextureUsage};
use crate::vk;
/// How a texture buffer of a format held as words holds a texel (the module docs).
@@ -203,33 +207,56 @@ const VIEW_USES: [FormatUsage; 2] = [
/// The further uses a device holds a format for where a texture buffer of a format with a word
/// layout is its own view rather than words: the storage texel buffer's write without a format.
/// With [`VIEW_USES`] these are the three checks [`texel_buffer_form`] makes: a read
/// (`access::read`) through the uniform texel buffer, the storage texel buffer the view's usage
/// takes, and a write through it declared without a format. A read through that storage texel
/// buffer (`access::read_write`) is not among them: where the own view lacks the read without a
/// format, the runtime refuses that read (`Gap::StorageElement`).
/// With [`VIEW_USES`] these are the three checks [`texel_buffer_form`] makes of every texture
/// buffer: a read (`access::read`) through the uniform texel buffer, the storage texel buffer the
/// view's usage takes, and a write through it declared without a format.
const NATIVE_USES: [FormatUsage; 1] = [FormatUsage::StorageTexelBufferWriteWithoutFormat];
/// How a texture buffer of `pf` holds its texels on a device of `profile`, the one place that
/// decides it (the module docs). Its own view ([`TexelBufferForm::View`]) where the device holds
/// the format directly (with no component mapping or conversion), of one colour texel an element,
/// as a uniform texel buffer, a storage texel buffer and a storage texel buffer written without a
/// format; else words ([`TexelBufferForm::Words`]) where the format has a word layout
/// ([`texel_buffer_words`]); else its own view where the device holds it so as the two texel
/// buffers alone (a format Vulkan requires, on a device that writes none without a format, whose
/// write the runtime then refuses). `None` for any other format, whose texture
/// buffer is refused.
pub fn texel_buffer_form(pf: PixelFormat, profile: &DeviceProfile) -> Option<TexelBufferForm> {
/// The fourth check [`texel_buffer_form`] makes of a texture buffer made both to be read and to
/// be written ([`texel_buffer_read_write`]): a read through its storage texel buffer declared
/// without a format (`access::read_write`). A texture buffer made otherwise is never read so (a
/// slot's `access::read_write` needs both usages), and one of a format without a word layout whose
/// own view lacks it is refused that read at the draw or dispatch (`Gap::StorageElement`).
const READ_WRITE_USES: [FormatUsage; 1] = [FormatUsage::StorageTexelBufferReadWithoutFormat];
/// Whether a texture buffer made with `usage` (`MTLTextureUsage`, fixed at its making) is made
/// both to be read and to be written by shaders: its usage holds `ShaderRead` and `ShaderWrite`,
/// or is Metal's unknown usage, which allows every use. [`texel_buffer_form`] checks a fourth use
/// of such a texture buffer's format, and its resource ID word says so
/// (`resource_word::TextureWord::TEXEL_BUFFER_READ_WRITE`).
pub const fn texel_buffer_read_write(usage: TextureUsage) -> bool {
usage.is_empty()
|| (usage.contains(TextureUsage::SHADER_READ) && usage.contains(TextureUsage::SHADER_WRITE))
}
/// How a texture buffer of `pf` made with `usage` holds its texels on a device of `profile`, the
/// one place that decides it (the module docs): one answer per format and usage per device. Its
/// own view ([`TexelBufferForm::View`]) where the device holds the format directly (with no
/// component mapping or conversion), of one colour texel an element, as a uniform texel buffer, a
/// storage texel buffer and a storage texel buffer written without a format, and, for a texture
/// buffer made both to be read and to be written ([`texel_buffer_read_write`]), a storage texel
/// buffer read without a format; else words ([`TexelBufferForm::Words`]) where the format has a
/// word layout ([`texel_buffer_words`]); else its own view where the device holds it so as the
/// two texel buffers alone (a format Vulkan requires, on a device that writes or reads none
/// without a format, whose write or read the runtime then refuses). `None` for any other format,
/// whose texture buffer is refused.
pub fn texel_buffer_form(
pf: PixelFormat,
usage: TextureUsage,
profile: &DeviceProfile,
) -> Option<TexelBufferForm> {
let uses: BTreeSet<FormatUsage> = VIEW_USES.into_iter().collect();
let own = super::vk_format(pf, &uses, profile).ok().filter(|m| {
m.emulation == FormatEmulation::Direct
&& m.aspects == vk::ImageAspectFlags::COLOR
&& super::block_extent(pf).is_none()
});
let read_write: &[FormatUsage] = match texel_buffer_read_write(usage) {
true => &READ_WRITE_USES,
false => &[],
};
let native = own.filter(|m| {
NATIVE_USES
.iter()
.all(|&u| profile.supports_format(m.format, u))
(NATIVE_USES.iter().chain(read_write)).all(|&u| profile.supports_format(m.format, u))
});
match (native, texel_buffer_words(pf), own) {
(Some(m), _, _) => Some(TexelBufferForm::View(m.format)),
@@ -238,16 +265,42 @@ pub fn texel_buffer_form(pf: PixelFormat, profile: &DeviceProfile) -> Option<Tex
}
}
/// The codes of the formats a device of `profile` holds texture buffers of as words
/// ([`texel_buffer_form`]): bit `c` set for code `c`.
pub(crate) fn texel_buffer_word_codes(profile: &DeviceProfile) -> u64 {
WORD_FORMATS
.iter()
.filter_map(|&pf| match texel_buffer_form(pf, profile)? {
TexelBufferForm::Words(w) => Some(1u64 << w.code),
TexelBufferForm::View(_) => None,
})
.fold(0, |codes, bit| codes | bit)
/// The codes of the formats a device holds texture buffers of as words ([`texel_buffer_form`]),
/// bit `c` set for code `c`, by usage.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(crate) struct WordCodes {
/// Of a texture buffer made to be read or written alone.
pub(crate) alone: u64,
/// Of one made both to be read and to be written ([`texel_buffer_read_write`]): those of
/// [`alone`](Self::alone) and those whose own view a device holds for the three uses but not
/// the fourth.
pub(crate) read_write: u64,
}
impl WordCodes {
/// The codes held as words for either usage: [`read_write`](Self::read_write)'s, which hold
/// [`alone`](Self::alone)'s.
pub(crate) fn any(self) -> u64 {
self.alone | self.read_write
}
}
/// The codes of the formats a device of `profile` holds texture buffers of as words, by usage
/// ([`WordCodes`]).
pub(crate) fn texel_buffer_word_codes(profile: &DeviceProfile) -> WordCodes {
let codes = |usage| {
WORD_FORMATS
.iter()
.filter_map(|&pf| match texel_buffer_form(pf, usage, profile)? {
TexelBufferForm::Words(w) => Some(1u64 << w.code),
TexelBufferForm::View(_) => None,
})
.fold(0, |codes, bit| codes | bit)
};
WordCodes {
alone: codes(TextureUsage::SHADER_READ),
read_write: codes(TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE),
}
}
/// The formats a texture buffer may hold as words, in the order of their codes (1 for the first):
@@ -433,45 +486,118 @@ mod tests {
}
}
/// On every committed profile, a format Vulkan requires as a storage texel buffer is its own
/// view, each format with a word layout is words or its own view, the latter only where the
/// profile holds it directly for the three uses `NATIVE_USES` and `VIEW_USES` name, and the
/// module's codes are the formats held as words. Prints each profile's formats held as words.
/// On every committed profile, for a texture buffer made to be read alone, written alone, and
/// both read and written (and Metal's unknown usage, which is both), a format Vulkan requires
/// as a storage texel buffer is its own view, each format with a word layout is words or its
/// own view, the latter only where the profile holds it directly for the uses `VIEW_USES` and
/// `NATIVE_USES` name and, made both to be read and to be written, `READ_WRITE_USES`, and the
/// module's codes for each usage are the formats held as words for it, those made to be read
/// alone among those made both. Prints each profile's formats held as words by usage.
#[test]
fn each_profile_holds_each_format_one_way() {
fn each_profile_holds_each_format_one_way_for_each_usage() {
use PixelFormat as P;
use TextureUsage as U;
let profiles = crate::spirv::testing::committed_profiles().expect("committed profiles");
assert!(!profiles.is_empty());
let usages = [
U::SHADER_READ,
U::SHADER_WRITE,
U::SHADER_READ | U::SHADER_WRITE,
U::UNKNOWN,
];
for (stem, profile) in &profiles {
for pf in [P::RGBA8Unorm, P::R32Uint, P::RG32Float, P::RGBA16Float] {
let form = texel_buffer_form(pf, profile);
assert!(
matches!(form, Some(TexelBufferForm::View(_))),
"{stem}: {pf:?}"
);
let held = texel_buffer_word_codes(profile);
assert_eq!(held.alone & !held.read_write, 0, "{stem}: {held:?}");
for usage in usages {
let read_write = texel_buffer_read_write(usage);
for pf in [P::RGBA8Unorm, P::R32Uint, P::RG32Float, P::RGBA16Float] {
let form = texel_buffer_form(pf, usage, profile);
assert!(
matches!(form, Some(TexelBufferForm::View(_))),
"{stem}: {pf:?} {usage:?}"
);
}
let mut words = Vec::new();
let mut codes = 0u64;
for &pf in &WORD_FORMATS {
match texel_buffer_form(pf, usage, profile) {
Some(TexelBufferForm::Words(w)) => {
assert_eq!(Some(w), texel_words(pf), "{stem}: {pf:?}");
codes |= 1 << w.code;
words.push(format!("{pf:?}"));
}
Some(TexelBufferForm::View(f)) => {
let fourth: &[FormatUsage] = match read_write {
true => &READ_WRITE_USES,
false => &[],
};
let mut uses = VIEW_USES.iter().chain(&NATIVE_USES).chain(fourth);
assert!(
uses.all(|&u| profile.supports_format(f, u)),
"{stem}: {pf:?} {usage:?}"
);
}
None => panic!("{stem}: {pf:?} {usage:?} has no form"),
}
}
let want = match read_write {
true => held.read_write,
false => held.alone,
};
assert_eq!(want, codes, "{stem}: {usage:?}");
eprintln!("{stem}: {usage:?}: held as words: {}", words.join(" "));
}
let mut words = Vec::new();
}
}
/// Made both to be read and to be written, a texture buffer of a format whose own view takes
/// the three uses but not the read without a format is words, and made to be read or written
/// alone it is that own view: on ANV's Iris Xe (RPL-P), whose buffer features lack
/// `STORAGE_READ_WITHOUT_FORMAT` for `B5G6R5Unorm`, `BGR5A1Unorm`, `BGRA8Unorm`,
/// `RGB10A2Unorm`, `RGB10A2Uint`, `BGR10A2Unorm` and `RG11B10Float`, those seven are the codes
/// held as words for that usage alone. On a profile whose `shaderStorageImageReadWithoutFormat`
/// holds, the two usages' codes are the same.
#[test]
fn a_texture_buffer_made_to_be_read_and_written_is_words_where_its_own_view_reads_none_so() {
use PixelFormat as P;
use TextureUsage as U;
let profiles = crate::spirv::testing::committed_profiles().expect("committed profiles");
let both = U::SHADER_READ | U::SHADER_WRITE;
let moved = [
P::B5G6R5Unorm,
P::BGR5A1Unorm,
P::BGRA8Unorm,
P::RGB10A2Unorm,
P::RGB10A2Uint,
P::BGR10A2Unorm,
P::RG11B10Float,
];
let mut iris = false;
for (stem, profile) in &profiles {
let held = texel_buffer_word_codes(profile);
if profile.images().storage_read_without_format {
assert_eq!(held.alone, held.read_write, "{stem}");
}
if stem != "intel-irisxe-rplp-anv" {
continue;
}
iris = true;
let mut codes = 0u64;
for &pf in &WORD_FORMATS {
match texel_buffer_form(pf, profile) {
Some(TexelBufferForm::Words(w)) => {
assert_eq!(Some(w), texel_words(pf), "{stem}: {pf:?}");
codes |= 1 << w.code;
words.push(format!("{pf:?}"));
}
Some(TexelBufferForm::View(f)) => {
let uses = VIEW_USES.iter().chain(&NATIVE_USES);
assert!(
uses.into_iter().all(|&u| profile.supports_format(f, u)),
"{stem}: {pf:?}"
);
}
None => panic!("{stem}: {pf:?} has no form"),
for pf in moved {
let words = texel_buffer_words(pf).expect("a word layout");
codes |= 1 << words.code;
for alone in [U::SHADER_READ, U::SHADER_WRITE] {
let form = texel_buffer_form(pf, alone, profile);
assert!(matches!(form, Some(TexelBufferForm::View(_))), "{pf:?}");
}
for usage in [both, U::UNKNOWN] {
let form = texel_buffer_form(pf, usage, profile);
assert_eq!(form, Some(TexelBufferForm::Words(words)), "{pf:?}");
}
}
assert_eq!(texel_buffer_word_codes(profile), codes, "{stem}");
eprintln!("{stem}: held as words: {}", words.join(" "));
assert_eq!(held.read_write & !held.alone, codes);
}
assert!(iris, "no intel-irisxe-rplp-anv profile");
}
/// Each layout's fields lie inside its texel and never cross a 32-bit word, so a texel of
+51 -22
View File
@@ -3,7 +3,7 @@
//! no round trip. `docs/RESOURCE-ID.md` is the specification; a sampler's word is
//! [`SamplerWord`](crate::metal::sampler::SamplerWord).
use crate::metal::{PixelFormat, TextureSwizzleChannels};
use crate::metal::{PixelFormat, TextureSwizzleChannels, TextureUsage};
/// The high word of a texture's `gpuResourceID`, from its pixel format and swizzle alone. The
/// bits:
@@ -21,9 +21,10 @@ use crate::metal::{PixelFormat, TextureSwizzleChannels};
/// ([`TEXEL_BUFFER_LAYOUT`](Self::TEXEL_BUFFER_LAYOUT)) and its bits 0-10 its padding
/// ([`TEXEL_BUFFER_PADDING`](Self::TEXEL_BUFFER_PADDING), bits 0-1), its word format's code
/// ([`TEXEL_BUFFER_WORDS`](Self::TEXEL_BUFFER_WORDS), bits 2-7), its texels per word
/// ([`TEXEL_BUFFER_PACKING`](Self::TEXEL_BUFFER_PACKING), bits 8-9) and whether a texel is two
/// words ([`TEXEL_BUFFER_WIDE`](Self::TEXEL_BUFFER_WIDE), bit 10) in place of the border texels,
/// which a read through a sampler then takes from the code.
/// ([`TEXEL_BUFFER_PACKING`](Self::TEXEL_BUFFER_PACKING), bits 8-9), whether a texel is two
/// words ([`TEXEL_BUFFER_WIDE`](Self::TEXEL_BUFFER_WIDE), bit 10) and whether it was made both to
/// be read and to be written ([`TEXEL_BUFFER_READ_WRITE`](Self::TEXEL_BUFFER_READ_WRITE), bit 11)
/// in place of the border texels, which a read through a sampler then takes from the code.
/// Bit `3c + b` of the border texels is set where channel `c` (0 red to 3 alpha) of the texel a
/// Metal 4.1 read through a sampler hands back outside the level on a border axis, for border
/// color `b` (`MTLSamplerBorderColor`'s raw value: transparent black, opaque black, opaque
@@ -62,12 +63,18 @@ impl TextureWord {
pub const TEXEL_BUFFER_PACKING_SHIFT: u32 = 8;
/// A texture buffer held as words whose texel is two words of its view, the low word first.
pub const TEXEL_BUFFER_WIDE: u32 = 1 << 10;
/// A texture buffer of a format with a word layout made both to be read and to be written
/// (`metal::format::texel_buffer_read_write`): a device holds its format as words for it
/// where its own view lacks the read without a format (`metal::format::texel_buffer_form`), so
/// a shader tests this bit beside the code. Clear for one made to be read or written alone.
pub const TEXEL_BUFFER_READ_WRITE: u32 = 1 << 11;
/// The bits a texture buffer of a format with a word layout carries in place of its border
/// texels, beside [`TEXEL_BUFFER_LAYOUT`](Self::TEXEL_BUFFER_LAYOUT).
pub const TEXEL_BUFFER_FIELDS: u32 = Self::TEXEL_BUFFER_PADDING
| Self::TEXEL_BUFFER_WORDS
| Self::TEXEL_BUFFER_PACKING
| Self::TEXEL_BUFFER_WIDE;
| Self::TEXEL_BUFFER_WIDE
| Self::TEXEL_BUFFER_READ_WRITE;
/// The lowest bit of the pixel format.
pub const PIXEL_FORMAT_SHIFT: u32 = 16;
/// The pixel format's bits.
@@ -87,14 +94,19 @@ impl TextureWord {
}
/// The word of a texture buffer (`MTLTextureTypeTextureBuffer`) of `pixel_format`, `width`
/// texels wide: [`of`](Self::of)'s with each channel's own swizzle, and where its format has a
/// word layout (`metal::format::texel_buffer_words`), on every device whether or not the
/// device holds it as words, [`TEXEL_BUFFER_LAYOUT`](Self::TEXEL_BUFFER_LAYOUT) and
/// [`TEXEL_BUFFER_FIELDS`](Self::TEXEL_BUFFER_FIELDS) in place of its border texels: its
/// format's code, its texels per word, whether a texel is two words, and its padding. `None`
/// for a format without a word, and for a texture buffer of a word layout whose words
/// overflow a `u32`.
pub fn of_texture_buffer(pixel_format: PixelFormat, width: u32) -> Option<TextureWord> {
/// texels wide, made with `usage`: [`of`](Self::of)'s with each channel's own swizzle, and
/// where its format has a word layout (`metal::format::texel_buffer_words`), on every device
/// whether or not the device holds it as words, [`TEXEL_BUFFER_LAYOUT`](Self::TEXEL_BUFFER_LAYOUT)
/// and [`TEXEL_BUFFER_FIELDS`](Self::TEXEL_BUFFER_FIELDS) in place of its border texels: its
/// format's code, its texels per word, whether a texel is two words, its padding, and whether
/// `usage` makes it both to be read and to be written
/// (`metal::format::texel_buffer_read_write`). `None` for a format without a word, and for a
/// texture buffer of a word layout whose words overflow a `u32`.
pub fn of_texture_buffer(
pixel_format: PixelFormat,
width: u32,
usage: TextureUsage,
) -> Option<TextureWord> {
let TextureWord(w) = TextureWord::of(pixel_format, TextureSwizzleChannels::DEFAULT)?;
let Some(words) = crate::metal::format::texel_buffer_words(pixel_format) else {
return Some(TextureWord(w));
@@ -107,7 +119,11 @@ impl TextureWord {
true => Self::TEXEL_BUFFER_WIDE,
false => 0,
};
let fields = Self::TEXEL_BUFFER_LAYOUT | code | packing | wide | padding;
let read_write = match crate::metal::format::texel_buffer_read_write(usage) {
true => Self::TEXEL_BUFFER_READ_WRITE,
false => 0,
};
let fields = Self::TEXEL_BUFFER_LAYOUT | code | packing | wide | read_write | padding;
Some(TextureWord(kept | fields))
}
}
@@ -143,26 +159,39 @@ mod tests {
}
/// A texture buffer of a format with a word layout carries bit 13, its code, packing and
/// padding in place of the border texels; one of a format without a word layout has the
/// texture's word, its border texels included.
/// padding in place of the border texels, and bit 11 where it is made both to be read and to
/// be written (or with Metal's unknown usage); one of a format without a word layout has the
/// texture's word, its border texels included, whatever its usage.
#[test]
fn a_texture_buffer_held_as_words_carries_its_padding() {
let a8 = TextureWord::of_texture_buffer(PixelFormat::A8Unorm, 5);
let read = TextureUsage::SHADER_READ;
let both = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE;
let a8 = TextureWord::of_texture_buffer(PixelFormat::A8Unorm, 5, read);
assert_eq!(
a8,
Some(TextureWord(1 << 16 | 1 << 13 | 2 << 8 | 1 << 2 | 3))
);
let r16 = TextureWord::of_texture_buffer(PixelFormat::R16Unorm, 6);
let r16 = TextureWord::of_texture_buffer(PixelFormat::R16Unorm, 6, read);
let r16_word = 20 << 16 | 1 << 13 | 1 << 12 | 1 << 8 | 7 << 2;
assert_eq!(r16, Some(TextureWord(r16_word)));
let wide = TextureWord::of_texture_buffer(PixelFormat::RGBA16Unorm, 5);
let written = TextureWord::of_texture_buffer(PixelFormat::R16Unorm, 6, both);
assert_eq!(written, Some(TextureWord(r16_word | 1 << 11)));
let unknown =
TextureWord::of_texture_buffer(PixelFormat::R16Unorm, 6, TextureUsage::UNKNOWN);
assert_eq!(unknown, written);
let alone =
TextureWord::of_texture_buffer(PixelFormat::R16Unorm, 6, TextureUsage::SHADER_WRITE);
assert_eq!(alone, r16);
let wide = TextureWord::of_texture_buffer(PixelFormat::RGBA16Unorm, 5, read);
assert_eq!(
wide,
Some(TextureWord(110 << 16 | 1 << 13 | 1 << 10 | 34 << 2))
);
let rgba = TextureWord::of_texture_buffer(PixelFormat::RGBA8Unorm, 5);
let plain = TextureWord::of(PixelFormat::RGBA8Unorm, TextureSwizzleChannels::DEFAULT);
assert_eq!(rgba, plain);
assert_eq!(rgba, Some(TextureWord(70 << 16 | 0b110_100_100_100)));
for usage in [read, both] {
let rgba = TextureWord::of_texture_buffer(PixelFormat::RGBA8Unorm, 5, usage);
assert_eq!(rgba, plain);
assert_eq!(rgba, Some(TextureWord(70 << 16 | 0b110_100_100_100)));
}
}
}
@@ -585,7 +585,7 @@ fn a_read_through_a_sampler_of_a_texture_buffer_reads_the_words() {
let mut holding = 0;
for stem in PROFILES {
let p = profile(stem, identity()).unwrap_or_else(|e| panic!("{e}"));
let held = crate::metal::format::texel_buffer_word_codes(&p) != 0;
let held = crate::metal::format::texel_buffer_word_codes(&p).any() != 0;
holding += usize::from(held);
for entry in ["rt_buffer", "rt_buffer_ow", "rt_arg_buffer"] {
let (a, plan, _) =
+6 -3
View File
@@ -90,6 +90,7 @@ assoc-const metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_LAYOUT
assoc-const metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_PACKING pub const TEXEL_BUFFER_PACKING: u32
assoc-const metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_PACKING_SHIFT pub const TEXEL_BUFFER_PACKING_SHIFT: u32
assoc-const metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_PADDING pub const TEXEL_BUFFER_PADDING: u32
assoc-const metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_READ_WRITE pub const TEXEL_BUFFER_READ_WRITE: u32
assoc-const metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_WIDE pub const TEXEL_BUFFER_WIDE: u32
assoc-const metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_WORDS pub const TEXEL_BUFFER_WORDS: u32
assoc-const metal2vulkan::metal::sampler::AddressModeMap::IDENTITY pub const IDENTITY: AddressModeMap
@@ -244,11 +245,12 @@ assoc-const-value metal2vulkan::metal::resource_word::TextureWord::OUT_OF_BOUNDS
assoc-const-value metal2vulkan::metal::resource_word::TextureWord::PIXEL_FORMAT 0xffff <<Self::PIXEL_FORMAT_SHIFT
assoc-const-value metal2vulkan::metal::resource_word::TextureWord::PIXEL_FORMAT_SHIFT 16
assoc-const-value metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_CODE_SHIFT 2
assoc-const-value metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_FIELDS Self::TEXEL_BUFFER_PADDING | Self::TEXEL_BUFFER_WORDS | Self::TEXEL_BUFFER_PACKING | Self::TEXEL_BUFFER_WIDE
assoc-const-value metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_FIELDS Self::TEXEL_BUFFER_PADDING | Self::TEXEL_BUFFER_WORDS | Self::TEXEL_BUFFER_PACKING | Self::TEXEL_BUFFER_WIDE | Self::TEXEL_BUFFER_READ_WRITE
assoc-const-value metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_LAYOUT 1 <<13
assoc-const-value metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_PACKING 0b11 <<Self::TEXEL_BUFFER_PACKING_SHIFT
assoc-const-value metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_PACKING_SHIFT 8
assoc-const-value metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_PADDING 0b11
assoc-const-value metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_READ_WRITE 1 <<11
assoc-const-value metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_WIDE 1 <<10
assoc-const-value metal2vulkan::metal::resource_word::TextureWord::TEXEL_BUFFER_WORDS 0b11_1111 <<Self::TEXEL_BUFFER_CODE_SHIFT
assoc-const-value metal2vulkan::metal::sampler::AddressModeMap::IDENTITY AddressModeMap
@@ -2911,7 +2913,8 @@ fn metal2vulkan::metal::format::srgb_raw_twin pub fn srgb_raw_twin(pf: PixelForm
fn metal2vulkan::metal::format::srgb_sibling pub fn srgb_sibling(pf: PixelFormat) -> Option<PixelFormat>
fn metal2vulkan::metal::format::storage_image_choice pub fn storage_image_choice(pf: PixelFormat, profile: &DeviceProfile) -> Result<StorageImageChoice, Error>
fn metal2vulkan::metal::format::storage_view_formats pub fn storage_view_formats(pf: PixelFormat, profile: &DeviceProfile) -> Vec<vk::Format>
fn metal2vulkan::metal::format::texel_buffer_form pub fn texel_buffer_form(pf: PixelFormat, profile: &DeviceProfile) -> Option<TexelBufferForm>
fn metal2vulkan::metal::format::texel_buffer_form pub fn texel_buffer_form(pf: PixelFormat, usage: TextureUsage, profile: &DeviceProfile) -> Option<TexelBufferForm>
fn metal2vulkan::metal::format::texel_buffer_read_write pub const fn texel_buffer_read_write(usage: TextureUsage) -> bool
fn metal2vulkan::metal::format::texel_buffer_words pub fn texel_buffer_words(pf: PixelFormat) -> Option<TexelWords>
fn metal2vulkan::metal::format::texel_words pub fn texel_words(pf: PixelFormat) -> Option<TexelWords>
fn metal2vulkan::metal::format::texture_usages pub fn texture_usages(pf: PixelFormat, usage: TextureUsage) -> BTreeSet<FormatUsage>
@@ -6551,7 +6554,7 @@ method metal2vulkan::metal::format::WordAttachment::output_word pub fn output_wo
method metal2vulkan::metal::format::WordAttachment::pack pub fn pack(self, codes: [u32; 4]) -> u32
method metal2vulkan::metal::format::WordAttachment::word_format pub fn word_format(self) -> vk::Format
method metal2vulkan::metal::resource_word::TextureWord::of pub fn of(pixel_format: PixelFormat, swizzle: TextureSwizzleChannels) -> Option<TextureWord>
method metal2vulkan::metal::resource_word::TextureWord::of_texture_buffer pub fn of_texture_buffer(pixel_format: PixelFormat, width: u32) -> Option<TextureWord>
method metal2vulkan::metal::resource_word::TextureWord::of_texture_buffer pub fn of_texture_buffer(pixel_format: PixelFormat, width: u32, usage: TextureUsage) -> Option<TextureWord>
method metal2vulkan::metal::sampler::AddressModeMap::constexpr_mode pub fn constexpr_mode(&self, from: SamplerAddressMode) -> Option<SamplerAddressMode>
method metal2vulkan::metal::sampler::AddressModeMap::is_identity pub fn is_identity(&self) -> bool
method metal2vulkan::metal::sampler::AddressModeMap::mode pub fn mode(&self, from: SamplerAddressMode) -> SamplerAddressMode
Can't render this file because it is too large.
+1
View File
@@ -600,6 +600,7 @@ surface! {
fn required_storage_texel_buffer;
fn texel_buffer_words;
fn texel_buffer_form;
fn texel_buffer_read_write;
const WORD_FORMATS;
fn texel_words;
fn word_format;
+38 -17
View File
@@ -18,13 +18,13 @@ use metal2vulkan::metal::resource_word::TextureWord;
use metal2vulkan::metal::sampler::SamplerWord;
use metal2vulkan::metal::{
CompareFunction, PixelFormat, SamplerAddressMode, SamplerBorderColor, SamplerMinMagFilter,
SamplerMipFilter, SamplerReductionMode, TextureSwizzle, TextureSwizzleChannels,
SamplerMipFilter, SamplerReductionMode, TextureSwizzle, TextureSwizzleChannels, TextureUsage,
};
const HEADER: &str = "\
# gpuResourceID high words (docs/RESOURCE-ID.md): one Metal descriptor per line, raw Metal values.
# texture\tpixelFormat\tswizzleRed\tswizzleGreen\tswizzleBlue\tswizzleAlpha\tword
# texturebuffer\tpixelFormat\twidth\tword
# texturebuffer\tpixelFormat\twidth\tusage\tword
# sampler\tminFilter\tmagFilter\tmipFilter\tsAddressMode\ttAddressMode\trAddressMode\tborderColor\tnormalizedCoordinates\tlodMinClamp\tlodMaxClamp\tlodAverage\tmaxAnisotropy\tcompareFunction\treductionMode\tword
# lodMinClamp and lodMaxClamp are a float's IEEE-754 bits; booleans are 0 or 1; words are hex.
";
@@ -177,21 +177,38 @@ fn samplers(out: &mut String) {
});
}
/// The texture buffer lines: every pixel format with a texture buffer word at width 1, and at
/// widths 2 to 4 too where its word changes with the width (a texture buffer held as words of
/// more than one texel a word, whose padding the word carries).
/// The texture buffer lines: every pixel format with a texture buffer word at width 1 under each
/// usage that tells the word apart, read (1), write (2), read and write (3) and unknown (0); and,
/// read and read-write, at widths 2 to 4 too where its word changes with the width (a texture
/// buffer held as words of more than one texel a word, whose padding the word carries).
fn texture_buffers(out: &mut String) {
let read = TextureUsage::SHADER_READ;
let both = read.union(TextureUsage::SHADER_WRITE);
for &pf in PixelFormat::ALL {
let Some(TextureWord(first)) = TextureWord::of_texture_buffer(pf, 1) else {
continue;
};
let _ = writeln!(out, "texturebuffer\t{}\t1\t{first:#010x}", pf.as_raw());
let words: Vec<_> = (2..=4)
.filter_map(|w| Some((w, TextureWord::of_texture_buffer(pf, w)?.0)))
.collect();
if words.iter().any(|&(_, word)| word != first) {
for (w, word) in words {
let _ = writeln!(out, "texturebuffer\t{}\t{w}\t{word:#010x}", pf.as_raw());
for usage in [read, both] {
let Some(TextureWord(first)) = TextureWord::of_texture_buffer(pf, 1, usage) else {
continue;
};
let raw = usage.as_raw();
let _ = writeln!(
out,
"texturebuffer\t{}\t1\t{raw}\t{first:#010x}",
pf.as_raw()
);
let words: Vec<_> = (2..=4)
.filter_map(|w| Some((w, TextureWord::of_texture_buffer(pf, w, usage)?.0)))
.collect();
if words.iter().any(|&(_, word)| word != first) {
for (w, word) in words {
let pf = pf.as_raw();
let _ = writeln!(out, "texturebuffer\t{pf}\t{w}\t{raw}\t{word:#010x}");
}
}
}
for usage in [TextureUsage::SHADER_WRITE, TextureUsage::UNKNOWN] {
if let Some(TextureWord(word)) = TextureWord::of_texture_buffer(pf, 1, usage) {
let (pf, raw) = (pf.as_raw(), usage.as_raw());
let _ = writeln!(out, "texturebuffer\t{pf}\t1\t{raw}\t{word:#010x}");
}
}
}
@@ -244,10 +261,14 @@ fn word_of(fields: &[&str]) -> u32 {
let channels = TextureSwizzleChannels::new(s(r), s(g), s(b), s(a));
TextureWord::of(pf, channels).expect("a word").0
}
["texturebuffer", pf, width] => {
["texturebuffer", pf, width, usage] => {
let pf = raw(PixelFormat::ALL, PixelFormat::as_raw, pf);
let width = width.parse().expect("width");
TextureWord::of_texture_buffer(pf, width).expect("a word").0
let usage: u32 = usage.parse().expect("usage");
let usage = TextureUsage::try_from(usage).expect("a usage");
TextureWord::of_texture_buffer(pf, width, usage)
.expect("a word")
.0
}
["sampler", min, mag, mip, sa, ta, ra, border, normalized, lo, hi, average, aniso, compare, reduction] =>
{
File diff suppressed because it is too large. Load diff
+4 -4
View File
@@ -270,8 +270,8 @@ and so do the command line, the compile worker and every validation tool. It hol
[RESOURCE-ID.md](RESOURCE-ID.md)), reads, writes and updates atomically its texture buffers, slots and
argument buffers' members alike (a uniform texel buffer where it reads one, a storage texel
buffer where it writes one, the element of set 1's texel-buffer array at its ID's index; where
the ID's word names a format the profile holds as words, `metal::format::texel_buffer_form`,
that element is a view of `R32_UINT` and the function converts its texels itself, under the
the ID's word names a format the profile holds as words for the usage its bit 11 tells,
`metal::format::texel_buffer_form`, that element is a view of `R32_UINT` and the function converts its texels itself, under the
stage's `SpecKey::TexelBufferWords`, which a binder sets true where such a texture buffer may
be reached and under which, false, each access is the element's own view's:
RESOURCE-ID.md, the texture buffer word), and
@@ -2091,8 +2091,8 @@ category, and says what makes an operation carry the note and what may differ. E
device's filter of them) by the MSL transfer through the device's `Pow`, at every such access on
every device. A `float` read of a texture buffer held as words decodes an 8-bit sRGB colour code
the same way, and records the note where the profile holds an 8-bit sRGB format's texture
buffers as words (`metal::format::texel_buffer_form`): its routine reads every format the
profile holds so.
buffers of some usage as words (`metal::format::texel_buffer_form`): its routine reads every
format the profile holds so for some usage.
- `metal2vulkan-degrade-function-storage-assumed` (precision).
`PrecisionNote::FunctionStorageAssumed`: A vertex or fragment function keeps more private memory
(its `alloca`s, a call stack among them, or constants held as `Private` variables) than the floor,
+1 -1
View File
@@ -1197,7 +1197,7 @@ gives another `gpuResourceID` than the program saw (both in hex, `PLAYED` `none`
runtime's getter raises), `id ID RECORDED PLAYED word WORD`, as the runtime lays its IDs
out as [RESOURCE-ID.md](RESOURCE-ID.md) does: there the ID's low word, its index, is compared with
the recording's, and its high word with `WORD`, the document's own function of the descriptor the
object was made of (a texture's `TextureWord`, a texture buffer's `TextureWord::of_texture_buffer` of its format and width, a sampler state's `SamplerWord`), never with the
object was made of (a texture's `TextureWord`, a texture buffer's `TextureWord::of_texture_buffer` of its format, width and usage, a sampler state's `SamplerWord`), never with the
recording's high word, which is the recording runtime's own; `covered N: texture writes over other objects of a placement
heap; C checks they covered not compared; B covers taken off by a binding,
which may be a read` where a texture write covered
+12 -8
View File
@@ -93,7 +93,8 @@ arrays with the low word, answers `is_null_texture` by whether the index is 0, a
where it checks a `read` itself (a device without `robustImageAccess2`), takes an out-of-bounds
alpha of 1 from bit 12 of the word. A texture buffer whose word names a format the device holds
as words takes its format, its texels per word, whether a texel is two words and its padding from
bits 0-10 of its word. A slot's `read` through a sampler (MSL 4.1) takes the border
bits 0-10 of its word, and the shader learns that the device holds it as words from its code and,
where the device's answer for its format differs with the usage, bit 11. A slot's `read` through a sampler (MSL 4.1) takes the border
texel an index outside the level reads on a border axis from bits 0-11 of the word, for the
sampler's border color; a texture buffer's whose word has bit 13 set, from the border texels of
the format its code names, as an argument buffer's texture buffer held as words does from the code
@@ -152,8 +153,8 @@ no word.
## The texture buffer word
`metal2vulkan::metal::resource_word::TextureWord::of_texture_buffer(pixelFormat, width)`: the
texture word of its format under each channel's own swizzle. Where the format has a word layout,
`metal2vulkan::metal::resource_word::TextureWord::of_texture_buffer(pixelFormat, width, usage)`:
the texture word of its format under each channel's own swizzle. Where the format has a word layout,
bit 13 is set and bits 0-11 hold the layout's fields in place of the border texels; a read
through a sampler of such a texture buffer takes its format's border texels from its code. Every
other texture buffer's word is its texture word, border texels included:
@@ -164,7 +165,7 @@ other texture buffer's word is its texture word, border texels included:
| 2-7 | its code, 1 to 39 (below) | the border texels |
| 8-9 | the base-2 logarithm of the texels one word holds, 0, 1 or 2 | the border texels |
| 10 | a texel is two words, the low word first | the border texels |
| 11 | 0 | the border texels |
| 11 | it was made both to be read and to be written: `usage` holds `MTLTextureUsageShaderRead` and `MTLTextureUsageShaderWrite`, or is `MTLTextureUsageUnknown` (`metal::format::texel_buffer_read_write`) | the border texels |
| 12 | the format has no alpha | the format has no alpha |
| 13 | 1 | 0 |
| 14-15 | 0 | 0 |
@@ -175,9 +176,12 @@ require as a storage texel buffer (its mandatory format tables), or that has no
its own, and the word carries its fields on every device (`metal::format::texel_buffer_words`),
so the word is the same on every device. A device holds a texture buffer of such a format as words
where it lacks the format's own Vulkan format, held directly, as a uniform texel buffer, a storage
texel buffer or a storage texel buffer written without a format (`metal::format::texel_buffer_form`);
a module holds that answer for the profile it is compiled for, and tests a word's bit 13 and
code only where its stage's `SpecKey::TexelBufferWords` is set (the runtime's words twin). The view is then of `R32_UINT`, its
texel buffer or a storage texel buffer written without a format, and, for a texture buffer made
both to be read and to be written (bit 11), as a storage texel buffer read without a format
(`metal::format::texel_buffer_form`): one answer per format and usage. A module holds those answers
for the profile it is compiled for, and tests a word's bit 13 and code, and its bit 11 where the two
answers differ for some format, only where its stage's `SpecKey::TexelBufferWords` is set (the
runtime's words twin). The view is then of `R32_UINT`, its
texels packed in the buffer's bytes as Metal lays them out: a texel of `b` bytes, `w` texels wide,
views `⌈w · b / 4⌉` words, and its width is the words times its texels per word, halved where a
texel is two words, less its padding. Elsewhere the view is of the format's own Vulkan format,
@@ -222,7 +226,7 @@ Vulkan sampler applies them.
[`crates/metal2vulkan/tests/resource_words.tsv`](../crates/metal2vulkan/tests/resource_words.tsv)
holds one descriptor per line with its word, in tab-separated raw Metal values; its header names
the columns. A texture line is a pixel format and its four swizzle sources; a texture buffer line a
pixel format and a width; a sampler line is every
pixel format, a width and a usage (`MTLTextureUsage`'s raw value); a sampler line is every
`MTLSamplerDescriptor` field above, with `lodMinClamp` and `lodMaxClamp` as the float's IEEE-754
bits. Words are hexadecimal.