Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
(["tests/startup_sampler_heap_check.py", "binary", "llvm-mc-15"], {}),
(["tests/startup_image_sample_l_check.py", "binary", "llvm-mc-15"], {}),
(["tests/startup_image_sample_c_check.py", "binary", "llvm-mc-15"], {}),
(["tests/startup_image_1d_check.py", "binary", "llvm-mc-15"], {}),
(["tests/startup_image_3d_check.py", "binary", "llvm-mc-15"], {}),
(["tests/startup_image_load_mip_check.py", "--llvm-mc", "llvm-mc-15"], {}),
(["tests/startup_image_2d_array_check.py", "binary", "llvm-mc-15"], {}),
Expand Down Expand Up @@ -167,6 +168,7 @@ jobs:
tests/startup_sampler_heap_check.py \
tests/startup_image_sample_l_check.py \
tests/startup_image_sample_c_check.py \
tests/startup_image_1d_check.py \
tests/startup_image_3d_check.py \
tests/startup_image_load_mip_check.py \
tests/startup_gfx2hlsl_operand_count_check.py \
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,9 @@ if(EXISTS "${INTAKE_PYTHON}")
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_image_sample_l_check.py")
add_test(NAME startup_image_sample_c COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_image_sample_c_check.py")
# 1D image_load, image_load_mip, image_sample_lz and image_sample_l: translation controls and llvm-mc words.
add_test(NAME startup_image_1d COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_image_1d_check.py")
# Rewrites for instructions the host processor lacks (tools/startup/host_cpu.py), run on the host.
add_test(NAME startup_host_cpu COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_host_cpu_check.py")
Expand Down
4 changes: 3 additions & 1 deletion docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ nonempty component mask. The image draw test samples the alpha channel of a two-
Texture1D at two coordinates and compares exact words. Selecting red changes both results.
Run `ctest --preset dev -R startup_image_3d --no-tests=error` for this and the 3D controls.

The same lowering now covers the other 1D forms, which were refused with `unverified 1D image sample address or modifiers`. A 1D image takes one address component, x. `image_load` becomes `Texture1D.Load(int2(x, 0))`; `image_load_mip` takes x and then the mip and becomes `Load(int2(x, mip))`; `image_sample_lz` becomes `SampleLevel(smp, x, 0)`; `image_sample_l` takes x and then the level and becomes `SampleLevel(smp, x, level)`. The mip and the level are the last address register, so the NSA lists `[v3, v1]` and `[v3, v0]` read x from `v3`. Only the cache-policy bits `glc`, `slc` and `dlc` are accepted next to `dim` and `dmask`; `unorm`, `tfe`, `a16` and the other modifiers and an empty `dmask` are refused with `unverified 1D image address or modifiers`. `python -B tests/startup_image_1d_check.py` (CTest `startup_image_1d`) translates source-built fixtures whose words are checked against `llvm-mc` and requires the exact call; reading the mip as 0, taking the level from the first register, accepting `unorm` or binding the texture as 2D each make it fail. Not covered: no draw runs a 1D load, mip load or explicit-level sample on WARP or hardware, so those forms are checked on the generated HLSL text only (the plain `image_sample` draw above is unchanged). `image_sample_c`, gather and offset forms on a 1D image are still refused.

The runtime binds an explicit or default 1D view and uploads single-array-slice CPU-backed textures
using their desktop copyable footprints. Run `ctest --preset dev -R '^startup_1d_srv_' --no-tests=error`
to check RGBA8 texel and alpha values, rebinding, and a mismatched 2D view on hardware and WARP.
Expand Down Expand Up @@ -10513,7 +10515,7 @@ measurement on hardware or in a Windows run backs the descriptions. `v_interp_p1

## Startup translator: explicit-LOD image sampling

`tools/startup/gfx2hlsl.py` now lowers the gfx1013 `image_sample_l` form of a 2D or 3D texture sample to `tex.SampleLevel(smp, uv, level)`. The level is the last address register: the third for a contiguous 2D address, the fourth for 3D, and the last element of an NSA list. `tests/startup_image_sample_l_check.py` translates source-built fixtures (the words are checked against `llvm-mc`) and requires the level to come from that register; an address list `[v0, v1, v3]` must use `v3`, not the third consecutive register. Replacing the level with 0, replacing the call with implicit `Sample`, or reading the third register in every form each make the check fail. Offset (`_o`), compare (`_c_l`), gather, 1D, array, cube and multisample dimensions, an empty `dmask`, and the `unorm`, `r128`, `tfe`, `lwe`, `a16` and `d16` modifiers or any set reserved MIMG bit are refused with an `Unsupported` message; only the cache-policy bits `glc`, `slc` and `dlc` are accepted because they do not change the sampled value. The disassembler previously read `lwe` from reserved bit 14 of word 0; `llvm-mc` (19, gfx1013) encodes it in bit 17, and the check now has one `llvm-mc`-built fixture per refused modifier plus patched reserved-bit fixtures. Not measured: no draw samples a mip level on WARP or hardware through this lowering, so the level selection is checked on the generated HLSL text only. [HLSL SampleLevel](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-samplelevel)
`tools/startup/gfx2hlsl.py` now lowers the gfx1013 `image_sample_l` form of a 2D or 3D texture sample (and a 1D one, see above) to `tex.SampleLevel(smp, uv, level)`. The level is the last address register: the third for a contiguous 2D address, the fourth for 3D, and the last element of an NSA list. `tests/startup_image_sample_l_check.py` translates source-built fixtures (the words are checked against `llvm-mc`) and requires the level to come from that register; an address list `[v0, v1, v3]` must use `v3`, not the third consecutive register. Replacing the level with 0, replacing the call with implicit `Sample`, or reading the third register in every form each make the check fail. Offset (`_o`), compare (`_c_l`), gather, array, cube and multisample dimensions, an empty `dmask`, and the `unorm`, `r128`, `tfe`, `lwe`, `a16` and `d16` modifiers or any set reserved MIMG bit are refused with an `Unsupported` message; only the cache-policy bits `glc`, `slc` and `dlc` are accepted because they do not change the sampled value. The disassembler previously read `lwe` from reserved bit 14 of word 0; `llvm-mc` (19, gfx1013) encodes it in bit 17, and the check now has one `llvm-mc`-built fixture per refused modifier plus patched reserved-bit fixtures. Not measured: no draw samples a mip level on WARP or hardware through this lowering, so the level selection is checked on the generated HLSL text only. [HLSL SampleLevel](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-samplelevel)

## Startup translator: depth-comparison image sampling

Expand Down
13 changes: 10 additions & 3 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ These are measured on one executable; treat them as hypotheses for others.
column 1 at x=1.25, while the wrap control reads column 0. Run
`ctest --preset release --no-tests=error -R "^startup_inline_sampler_"`.
- **3D images.** `image_sample` with `dim:SQ_RSRC_IMG_3D` becomes a `Texture3D<float4>` sampled with
a `float3` of the three address registers in order; 1D images are refused. A source-built pixel
a `float3` of the three address registers in order. A source-built pixel
stage draws one texel of a 2x2x2 texture on WARP and hardware with DXC and FXC
(`ctest --preset release --no-tests=error -R "^startup_image_3d_"`).
- **Explicit mip loads.** For 2D textures, 2D arrays and 3D textures, `image_load_mip` passes the final
Expand All @@ -526,14 +526,21 @@ These are measured on one executable; treat them as hypotheses for others.
draw of a 4x4 texture of two slices with three mips whose cells all differ, with mutants that exchange
slice and mip, ignore the mip, or shift it by one. The draw was written without a Windows run. Cube maps
are still refused for `image_load_mip`.
- **1D images.** `image_sample`, `image_sample_lz`, `image_sample_l`, `image_load` and `image_load_mip` with
`dim:SQ_RSRC_IMG_1D` use a `Texture1D<float4>` (manifest kind `tex1d`) addressed by one component, x; the
explicit-level and mip forms take the level or mip from the last address register (`Load(int2(x, mip))`,
`SampleLevel(smp, x, level)`). Before, only the implicit `image_sample` was lowered and the other forms were
refused. `python -B tests/startup_image_1d_check.py` translates the fixtures (words checked against `llvm-mc`).
No draw runs the load, mip and explicit-level forms yet, so they are not measured on WARP or hardware. Compare,
gather and offset forms on a 1D image stay refused.
- **2D array images.** `image_sample`, `image_sample_lz`, `image_sample_l` and `image_load` with
`dim:SQ_RSRC_IMG_2D_ARRAY` use a `Texture2DArray<float4>` (manifest kind `tex2da`). The slice is
the third address component, as `float3(u, v, slice)` for a sample and `int4(x, y, slice, 0)`
for a load. Before, the stage was refused and every draw through its pipeline was skipped.
Two source-built pixel stages draw one texel of a 2x2 texture with two slices on WARP and
hardware with DXC and FXC; a slice fixed to 0 and exchanged coordinates fail it
(`ctest --preset release --no-tests=error -R "^startup_image_2d_array_"`). Cube, multisampled
and 1D images are still refused. Not covered: binding a single-slice 2D view to an array declaration
images are still refused. Not covered: binding a single-slice 2D view to an array declaration
in the draw path.
- **Flat parameters.** `v_interp_mov_f32` reads a `nointerpolation uint4` copy written from the
exported registers, so integer words reach the pixel stage unchanged. FXC folds `asfloat()` of a
Expand Down Expand Up @@ -664,7 +671,7 @@ These are measured on one executable; treat them as hypotheses for others.
The control expects all three axes to use the U field and must fail.
- The startup shader translator lowers `image_sample_l` (explicit level, 2D and 3D, any `dmask`) to
`SampleLevel(sampler, uv, level)`, taking the level from the last address register. Offset, compare,
gather, clamp, cube, 1D and `unorm` forms are refused. Only the translation is checked
gather, clamp, cube and `unorm` forms are refused; 1D is lowered (x, then the level). Only the translation is checked
(`python -B tests/startup_image_sample_l_check.py`); a WARP readback of distinct mip levels is still open.
- Slot 86 graphics streams can submit VS/PS requests to the offline cache. The fixture sends
complete shader containers and a wrapped root through WARP, runs `gfx2hlsl.py --pending`, and
Expand Down
181 changes: 181 additions & 0 deletions tests/startup_image_1d_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
"""One-dimensional image loads and explicit-level samples in tools/startup/gfx2hlsl.py.

(no arguments) translation controls, pure Python
binary <llvm-mc> reassemble every fixture source and compare it with the recorded words

A 1D image (dim:SQ_RSRC_IMG_1D) takes one address component: x. image_load reads Texture1D.Load(int2(x, 0)),
image_load_mip addresses x and then the mip and reads Load(int2(x, mip)), image_sample_lz samples level 0 at x, and
image_sample_l addresses x and then the level and reads SampleLevel(smp, x, level). The mip and the level are the
LAST address register, so the NSA lists [v3, v1] and [v3, v0] read x from v3, not from the first consecutive
register. The implicit-derivative image_sample on a 1D texture is checked by startup_image_3d_check.py.

Each fixture is a source-built gfx1013 pixel stage that sets v0 = 0.5, v1 = 0.25, v2 = 1.0, v3 = 2.0 and runs one image
instruction on a texture from descriptor table 0 (and an all-zero constant sampler for the sampling forms). The
modifiers and shapes the lowering does not model are refused instead of being read at a wrong address; only the
cache-policy bits glc, slc and dlc, which never change the value, are accepted next to dim and dmask.
"""
import re
import sys
from pathlib import Path

HERE = Path(__file__).resolve().parent
sys.path.insert(0, str(HERE.parent / 'tools' / 'startup'))
sys.path.insert(0, str(HERE))
import gfx2hlsl as G # noqa: E402
from startup_sampler_heap_check import VS_WORDS, assemble, root_blob # noqa: E402

PRE = """\
s_load_dwordx8 s[16:23], s[8:9], 0x0
s_mov_b32 s24, 0
s_mov_b32 s25, 0
s_mov_b32 s26, 0
s_mov_b32 s27, 0
v_mov_b32 v0, 0.5
v_mov_b32 v1, 0x3e800000
v_mov_b32 v2, 1.0
v_mov_b32 v3, 2.0
s_waitcnt lgkmcnt(0)
"""
POST = """\
s_waitcnt vmcnt(0)
exp mrt0 v4, v5, v6, v7 done vm
s_endpgm
"""
SAMPLER = 's[16:23], s[24:27]'
IMAGE = {
'load': 'image_load v[4:7], v0, s[16:23] dmask:0xf dim:SQ_RSRC_IMG_1D',
'load_x': 'image_load v4, v0, s[16:23] dmask:0x1 dim:SQ_RSRC_IMG_1D',
'load_mip': 'image_load_mip v[4:7], v[0:1], s[16:23] dmask:0xf dim:SQ_RSRC_IMG_1D',
'load_mip_nsa': 'image_load_mip v[4:7], [v3, v1], s[16:23] dmask:0xf dim:SQ_RSRC_IMG_1D',
'lz': 'image_sample_lz v[4:7], v0, ' + SAMPLER + ' dmask:0xf dim:SQ_RSRC_IMG_1D',
'l': 'image_sample_l v[4:7], v[0:1], ' + SAMPLER + ' dmask:0xf dim:SQ_RSRC_IMG_1D',
'l_nsa': 'image_sample_l v[4:7], [v3, v0], ' + SAMPLER + ' dmask:0xf dim:SQ_RSRC_IMG_1D',
'l_glc': 'image_sample_l v[4:7], v[0:1], ' + SAMPLER + ' dmask:0xf dim:SQ_RSRC_IMG_1D glc',
'load_unorm': 'image_load v[4:7], v0, s[16:23] dmask:0xf dim:SQ_RSRC_IMG_1D unorm',
'load_tfe': 'image_load v[4:8], v0, s[16:23] dmask:0xf dim:SQ_RSRC_IMG_1D tfe',
'lz_a16': 'image_sample_lz v[4:7], v0, ' + SAMPLER + ' dmask:0xf dim:SQ_RSRC_IMG_1D a16',
'load_mip_unorm': 'image_load_mip v[4:7], v[0:1], s[16:23] dmask:0xf dim:SQ_RSRC_IMG_1D unorm',
'l_dmask0': 'image_sample_l v4, v[0:1], ' + SAMPLER + ' dmask:0x0 dim:SQ_RSRC_IMG_1D',
'load_dmask0': 'image_load v4, v0, s[16:23] dmask:0x0 dim:SQ_RSRC_IMG_1D',
}
WORDS = {
'load': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf000f00f000040400703f8cbf0f1800f8'
'04050607000081bf'),
'load_x': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf000100f000040400703f8cbf0f1800f8'
'04050607000081bf'),
'load_mip': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf000f04f000040400703f8cbf0f1800f8'
'04050607000081bf'),
'load_mip_nsa': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf020f04f00304040001000000703f8cbf'
'0f1800f804050607000081bf'),
'lz': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf000f9cf00004c400703f8cbf0f1800f8'
'04050607000081bf'),
'l': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf000f90f00004c400703f8cbf0f1800f8'
'04050607000081bf'),
'l_nsa': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf020f90f00304c40000000000703f8cbf'
'0f1800f804050607000081bf'),
'l_glc': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf002f90f00004c400703f8cbf0f1800f8'
'04050607000081bf'),
'load_unorm': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf001f00f000040400703f8cbf0f1800f8'
'04050607000081bf'),
'load_tfe': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf000f01f000040400703f8cbf0f1800f8'
'04050607000081bf'),
'lz_a16': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf000f9cf00004c440703f8cbf0f1800f8'
'04050607000081bf'),
'load_mip_unorm': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf001f04f000040400703f8cbf0f1800f8'
'04050607000081bf'),
'l_dmask0': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf000090f00004c400703f8cbf0f1800f8'
'04050607000081bf'),
'load_dmask0': bytes.fromhex(
'04040cf4000000fa800398be800399be80039abe80039bbef002007eff02027e'
'0000803ef202047ef402067e7fc08cbf000000f000040400703f8cbf0f1800f8'
'04050607000081bf'),
}


def source(name):
return PRE + IMAGE[name] + '\n' + POST


def stage(name):
return G.Pipeline(VS_WORDS, WORDS[name], root_blob(flags=0))


def call(name):
"""The one texture call of a lowered fixture, and its pipeline."""
pipe = stage(name)
text = pipe.hlsl_ps()
calls = re.findall(r'^\s*t = (r0\.(?:Load|SampleLevel)\(.*\));$', text, re.M)
assert len(calls) == 1, (name, text)
assert 'Texture1D<float4> r0 : register(t0);' in text, text
assert 'srv 0 tex1d table 0 0' in pipe.manifest(), pipe.manifest()
return calls[0]


def refused(name):
try:
stage(name).hlsl_ps()
except G.Unsupported as error:
assert 'unverified 1D image address or modifiers' in str(error), (name, str(error))
else:
raise AssertionError('%s was accepted' % name)


def controls():
assert call('load') == 'r0.Load(int2(v0, 0))', call('load')
assert call('load_x') == 'r0.Load(int2(v0, 0))', call('load_x')
assert call('load_mip') == 'r0.Load(int2(v0, v1))', call('load_mip') # x v0, mip v1
assert call('load_mip_nsa') == 'r0.Load(int2(v3, v1))', call('load_mip_nsa') # the list order, not v[n]
print('load: Load(int2(x, 0)); load_mip: Load(int2(x, mip)), also through an NSA list')

assert re.fullmatch(r'r0\.SampleLevel\(q0, F\(v0\), 0\)', call('lz')), call('lz')
assert re.fullmatch(r'r0\.SampleLevel\(q0, F\(v0\), F\(v1\)\)', call('l')), call('l')
assert re.fullmatch(r'r0\.SampleLevel\(q0, F\(v3\), F\(v0\)\)', call('l_nsa')), call('l_nsa')
assert call('l_glc') == call('l'), call('l_glc') # a cache-policy bit does not change the value
print('sample_lz: level 0 at x; sample_l: level is the last address register (v1, NSA v0), x from the first')

for name in ('load_unorm', 'load_tfe', 'lz_a16', 'load_mip_unorm', 'l_dmask0', 'load_dmask0'):
refused(name)
print('refused: unorm, tfe, a16, empty dmask')


def check_binary(llvm_mc):
for name in WORDS:
built = assemble(llvm_mc, source(name))
if built != WORDS[name]:
raise AssertionError('%s fixture: assembled %s, recorded %s' % (name, built.hex(), WORDS[name].hex()))
print('fixture words match llvm-mc')


if __name__ == '__main__':
if len(sys.argv) == 1:
controls()
elif sys.argv[1] == 'binary' and len(sys.argv) == 3:
check_binary(sys.argv[2])
else:
sys.exit(__doc__)
3 changes: 1 addition & 2 deletions tests/startup_image_sample_l_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,10 @@ def controls():
refused('d16', 'image_sample_l modifier d16') # half-precision result layout
refused('r128', 'image_sample_l modifier r128') # four-dword resource descriptor
refused('dmask0', 'empty dmask')
refused('dim1d', 'unverified 1D image sample address or modifiers')
refused('msaa', 'image dimension SQ_RSRC_IMG_')
for name in RESERVED:
refused(name, 'image_sample_l modifier reserved') # bits LLVM ignores must not be silently accepted
print('refused: offset, compare, gather, cube, 1D, MSAA, unorm, a16, tfe, lwe, d16, r128, dmask 0, reserved bits')
print('refused: offset, compare, gather, cube, MSAA, unorm, a16, tfe, lwe, d16, r128, dmask 0, reserved bits')

# Cache-policy bits do not change the sampled value: same lowering as the plain form.
for name in ('glc', 'slc', 'dlc'):
Expand Down
Loading
Loading