Skip to content
Merged
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: 1 addition & 1 deletion docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -15043,7 +15043,7 @@ ctest --preset dev --no-tests=error -R '^startup_image_sample_b' -V

The guest sampler's MIN_LOD (word 1 bits 11:0) and MAX_LOD (bits 23:12) clamp the LOD of every sample form. `tools/startup/gfx2hlsl.py` now carries them for `image_sample`, `image_sample_l` and `image_sample_lz` when the sampler is a constant, through the `smpl` manifest line and `decode_sampler` that `image_sample_b` introduced (#2051); the slice is #2177, split from the run-time heap case (#2221). The three forms share one validation with `image_sample_b`: a descriptor LOD bias (word 2 bits 19:0) and MIN_LOD above MAX_LOD are refused, with the form's own name in the message. Behavior change: a constant sampler with either of those fields set used to translate for these forms (limits ignored) and is now refused. A mip filter of 0 (mipmapping disabled) is not refused for these forms, unlike `image_sample_b` where the bias would count: such a sampler keeps its ordinary `smp` line and its previous behavior. Refusing it would drop every pipeline with an all-zero inline sampler (seven existing check scripts build one); `image_sample_lz` and `_l` with level 0 would be harmless anyway. The one-argument switch is `mip_filter_none_ok` in `Stage.lod_sampler_words`. Also changed: a constant sampler with a non-zero MAX_LOD now clamps the level (it was unbounded before), which is the intended fix.

Not changed: a sampler read through the sampler heap (table or default-sampler shortcut) keeps the ordinary static or heap sampler and is not validated; `translate_to` and `translate_compute` write one line per module to stderr (`<key>: image_sample, image_sample_l through a sampler heap: sampler MIN_LOD, MAX_LOD and LOD bias are not validated (#2221)`). Since then the run-time heap table applies each entry's MIN_LOD and MAX_LOD (`dynamic_sampler()` in `src/startup_stubs/translated_sampler_bindings.h`, checked by `startup_sampler_lod_*`); the entry's LOD bias is not carried, a MIN_LOD above MAX_LOD is passed through unchanged, and the default-sampler shortcut keeps a static sampler with an unbounded LOD range. A sampler that is neither heap nor constant is refused as before. `image_sample_c` keeps its MAX_LOD rule.
Not changed: a sampler read through the sampler heap (table or default-sampler shortcut) keeps the ordinary static or heap sampler and is not validated; `translate_to` and `translate_compute` write one line per module to stderr (`<key>: image_sample, image_sample_l through a sampler heap: sampler MIN_LOD, MAX_LOD and LOD bias are not validated (#2221)`). Since then the run-time heap table applies each entry's MIN_LOD and MAX_LOD (`dynamic_sampler()` in `src/startup_stubs/translated_sampler_bindings.h`, checked by `startup_sampler_lod_*`); the entry's LOD bias is not carried, a MIN_LOD above MAX_LOD is passed through unchanged, and the default-sampler shortcut keeps a static sampler with an unbounded LOD range. Other nonconstant samplers remain refused except for the [proven two-sampler explicit-LOD join](experiments/startup-sampler-join.md). `image_sample_c` keeps its MAX_LOD rule.

`tests/startup_image_sample_lod_check.py` draws each form on its own (`startup_image_sample_lod_warp`, `startup_image_sample_lod_hardware`) against the 4x4, two-slice, three-mip array, point sampler with mip filter point, where all six cells differ. Each form's control is the same program through the ordinary `smp` line, which must read a different mip: `image_sample_l` with explicit level 2 and MAX_LOD 1 reads mip 1 (`smp`: mip 2); `image_sample` with MIN_LOD 2 above the implicit level 1 reads mip 2 (`smp`: mip 1); `image_sample_lz` with MIN_LOD 1 reads mip 1 (`smp`: mip 0). The implicit level 1 comes from the technique of the bias check: only the `u` initialiser of the translated HLSL is replaced by `0.75 + 0.5 * (SV_Position.x - 0.5)`, the `Sample` call is untouched. Refusal controls per form: bias, secondary bias and MIN_LOD 3 above MAX_LOD 2; accepted controls per form: mip filter 0 (`smp` line) and a heap sampler (table and default-sampler shortcut, logged once). The three `image_sample_b` discriminators are unchanged. Not covered: a fractional MIN_LOD or MAX_LOD, a linear mip filter, 1D, 3D and packed `a16` draws, the run-time heap sampler's LOD fields (#2221), and compute stages.

Expand Down
21 changes: 21 additions & 0 deletions docs/experiments/startup-sampler-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Two inline samplers at a uniform forward join

For 2D explicit-level `image_sample_l` and `image_sample_lz`, a single forward SCC diamond may select two inline four-word sampler definitions. Both arms must finish by writing all four words as literals, with proven uniform control flow and unchanged EXEC. Only normalized point wrap/clamp XY addressing and point mip filtering are admitted, with validated LOD limits. Two `smpl` static bindings preserve the descriptors; the selected runtime word chooses between complete `SampleLevel` calls. Any intervening overlap write invalidates the join proof. Implicit derivatives, partial definitions and more complex control flow retain their existing refusals.

The source-built fixture evaluates both root-constant selector outcomes for both sample forms with an independent point-texel oracle. A third variant holds word 0 unchanged and varies only MAX_LOD in word 1; the explicit level selects mip 1 or mip 0. Swapping sampler bindings changes the result in every variant. A decoded negative diamond keeps every field valid but sets bit 24 of word 1, above the whole-word-1 mask, so the guard refuses it as unsupported joined sampler words. Seven refusal controls and ten binary assembly variants are included.

Both portable checks passed on Apple Silicon; the expanded ten-variant fixture was assembled with LLVM 15.0.7.

```bash
python3 -B tests/startup_image_sample_l_join_check.py
python3 -B tests/startup_image_sample_l_join_check.py binary llvm-mc
```

The registered Windows draw consumes the actual translated shader, both manifest lines and the runtime selector.

```powershell
cmake --build --preset dev --target offscreen_check
ctest --preset dev --no-tests=error -R '^startup_image_sample_l_join_' -V
```

DXC/WARP/hardware draw execution requires Windows and remains unmeasured locally.
1 change: 1 addition & 0 deletions tests/checks/pixel-binary/startup_image_sample_l_join.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/startup_image_sample_l_join_check.py binary llvm-mc-15
1 change: 1 addition & 0 deletions tests/checks/python-linux/startup_image_sample_l_join.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/startup_image_sample_l_join_check.py
10 changes: 10 additions & 0 deletions tests/cmake/startup_image_sample_l_join.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if(EXISTS "${INTAKE_PYTHON}")
add_test(NAME startup_image_sample_l_join_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_image_sample_l_join_check.py")
foreach(adapter IN ITEMS warp hardware)
add_test(NAME startup_image_sample_l_join_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_image_sample_l_join_check.py" draw "${DXC_EXECUTABLE}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
set_tests_properties(startup_image_sample_l_join_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
endforeach()
endif()
14 changes: 11 additions & 3 deletions tests/offscreen_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,15 +1364,23 @@ OperationResult run_startup_image_3d(const OperationContext& ctx)
return {OutcomeKind::pass, nullptr};
}

// --startup-image-2d-view <vs.cso> <ps.cso> <sampler manifest line> <first/count> prints one RGBA32F pixel.
// --startup-image-2d-view <vs.cso> <ps.cso> <sampler manifest> <first/count> [0|1] prints one RGBA32F pixel.
// The optional selector is forwarded as the existing second root constant.
OperationResult run_startup_image_2d_view(const OperationContext& ctx)
{
const std::string_view window = ctx.argv[6];
if (window.size() != 3 || window[1] != '/' || window[0] < '0' || window[0] > '2' ||
window[2] < '1' || window[2] > '3')
return {OutcomeKind::fail, "expected a first/count mip window on a three-mip texture"};
float selector = 0.0f;
if (ctx.argc == 8) {
if (std::strcmp(ctx.argv[7], "1") == 0)
selector = 1.0f;
else if (std::strcmp(ctx.argv[7], "0") != 0)
return {OutcomeKind::fail, "view selector must be 0 or 1"};
}
float color[4]{};
check_startup_image_3d(ctx.device, ctx.argv[3], ctx.argv[4], 0, color, ctx.argv[5], false, 3, false, true,
check_startup_image_3d(ctx.device, ctx.argv[3], ctx.argv[4], selector, color, ctx.argv[5], false, 3, false, true,
UINT(window[0] - '0'), UINT(window[2] - '0'));
std::uint32_t bits[4];
std::memcpy(bits, color, sizeof(bits));
Expand Down Expand Up @@ -1717,7 +1725,7 @@ const OperationSpec kOperations[] = {
{"--startup-image-1d", 7, 8, nullptr, kNoGate, run_startup_image_3d},
{"--startup-image-1d-mips", 7, 8, nullptr, kNoGate, run_startup_image_3d},
{"--startup-image-2d", 7, 8, nullptr, kNoGate, run_startup_image_3d},
{"--startup-image-2d-view", 7, 7, nullptr, kNoGate, run_startup_image_2d_view},
{"--startup-image-2d-view", 7, 8, nullptr, kNoGate, run_startup_image_2d_view},
{"--startup-image-3d", 7, 8, nullptr, kNoGate, run_startup_image_3d},
{"--startup-image-store", 7, 7, nullptr, kNoGate, run_startup_image_store},
{"--startup-image-2d-array", 7, 8, nullptr, kNoGate, run_startup_image_3d},
Expand Down
20 changes: 18 additions & 2 deletions tests/startup_image_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,24 @@ void check_startup_image_3d(ID3D12Device* device, const char* vertex_path, const
const auto vs = read_blob(vertex_path);
const auto ps = read_blob(pixel_path);
x2w_startup::TranslatedSamplers samplers;
if (!samplers.read_manifest_line(sampler_line) || samplers.statics.size() != 1)
throw std::runtime_error("Expected one inline sampler in the image 3D draw");
const char* newline = std::strchr(sampler_line, '\n');
if (!newline) {
if (!samplers.read_manifest_line(sampler_line) || samplers.statics.size() != 1)
throw std::runtime_error("Expected one inline sampler in the image 3D draw");
} else {
const std::string first(sampler_line, newline);
const char* second = newline + 1;
int first_index = -1, second_index = -1;
if (!two_dimensional || !view_levels || std::strchr(second, '\n') ||
(std::sscanf(first.c_str(), "smp %d", &first_index) != 1 &&
std::sscanf(first.c_str(), "smpl %d", &first_index) != 1) ||
(std::sscanf(second, "smp %d", &second_index) != 1 &&
std::sscanf(second, "smpl %d", &second_index) != 1) ||
first_index != 0 || second_index != 1 ||
!samplers.read_manifest_line(first.c_str()) || !samplers.read_manifest_line(second) ||
samplers.statics.size() != 2 || samplers.heap || samplers.comparison[0] || samplers.comparison[1])
throw std::runtime_error("Expected two ordered noncomparison inline samplers in the 2D view draw");
}
const bool comparison = !samplers.comparison.empty() && samplers.comparison[0];
const auto root = create_root(device, samplers);

Expand Down
8 changes: 5 additions & 3 deletions tests/startup_image_get_lod_view_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ def pipeline(step, low, high, mip_filter):
return fixture.G.Pipeline(fixture.VS_WORDS, code, fixture.root_blob(flags=0), ps_hw_inputs=(0x8000, 0x8000))


def read_pixel(renderer, adapter, vs, ps, sampler, view):
run = subprocess.run([renderer, adapter, '--startup-image-2d-view', vs, ps, sampler, view],
capture_output=True, text=True, timeout=30)
def read_pixel(renderer, adapter, vs, ps, sampler, view, *, selector=None):
args = [renderer, adapter, '--startup-image-2d-view', vs, ps, sampler, view]
if selector is not None:
args.append(str(selector))
run = subprocess.run(args, capture_output=True, text=True, timeout=30)
print(run.stdout, end='')
if run.returncode == 77:
print(run.stderr, file=sys.stderr)
Expand Down
Loading
Loading