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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,9 @@ if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${
add_test(NAME native_fixed_mesh57_mask_${backend} COMMAND startup_indirect_draw_indexed ${backend} mesh)
set_tests_properties(native_fixed_mesh57_mask_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_TEST_NATIVE_MESH57=1;X2W_TEST_NATIVE_MESH57_MRT=1;X2W_TEST_NATIVE_MESH57_MASK=1;X2W_NATIVE_SHADERS=${DXC_BIN_DIR}")
add_test(NAME native_fixed_mesh57_compare_vcc_${backend} COMMAND startup_indirect_draw_indexed ${backend} mesh)
set_tests_properties(native_fixed_mesh57_compare_vcc_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_TEST_NATIVE_MESH57=1;X2W_TEST_NATIVE_MESH57_COMPARE_VCC=1;X2W_NATIVE_SHADERS=${DXC_BIN_DIR}")
endforeach()
add_executable(native_store_replay tests/native_store_replay.cpp tests/desktop_gpu.cpp)
target_include_directories(native_store_replay PRIVATE src tests)
Expand Down
2 changes: 2 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -17986,6 +17986,8 @@ design-B keep cases (a live slot stays reboundable after final `Release()` and c

See [fixed mesh pipelines through slot 57](experiments/native-fixed-mesh57.md) for the source-built indirect-draw fixtures.

A pixel tail can AND, OR, or ANDN2 a two-SGPR compare mask with VCC after whole-quad entry. The source words and the readback are in [pixel compare masks with VCC](experiments/pixel-compare-mask-vcc.md).

## Binary16 normalized integer conversions (`v_cvt_norm_i16_f16`, `v_cvt_norm_u16_f16`) across VOP1/VOP3/DPP16/DPP8/SDWA in pixel_aot

[The pixel shader translator](../tools/pixel_aot.py) adds 10 exact binary16 normalized integer conversion forms across all 5 encodings (counted in both `docs/coverage/gfx1013.tsv` and `docs/coverage/rdna2.tsv`):
Expand Down
33 changes: 33 additions & 0 deletions docs/experiments/pixel-compare-mask-vcc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Pixel compare masks composed with VCC

A gfx1013 pixel program can save its entry coverage, enter whole-quad mode, and
later combine a named two-SGPR compare with VCC. The mask tracker is that
whole-quad tail only. A vertex class-mask half overwrite still refuses as an
unproven CNDMASK source. `s_and_b64`, `s_or_b64` and
`s_andn2_b64` (`S0 & ~S1`) each produce a new pair. `s_mov_b64` keeps that
pair's lane bit. A later `s_mov_b32` of either half refuses with
`compare mask half overwritten`. Any other scalar write over that pair,
including a literal or numeric `s_mov_b64`, `s_movk_i32`, scalar arithmetic,
a scalar load, or a copy whose source is no longer a 64-bit mask, drops the
tracked bit. A later select then refuses with `unproven graphics CNDMASK source`.
`s_cselect_b64` into the same pair keeps the new full mask instead. A later SCC read is lowered only when both
operands were uniform, so the bit is the same on every lane. A varying combine
refuses with `SCC read without an established wave-wide nonzero result`.

The fixture is source words in `tests/native_pixel_compare_mask_check.py`.
The named mask is `y > 1` while the quad is still whole. VCC is `x > 2` after
exact coverage returns, so a helper lane keeps a mask bit and contributes
nothing to VCC. A diagonal draw leaves pixel `(4, 0)` covered and `(4, 1)` a
helper. The vertical quad read of the mask is 1 at `(4, 0)`. Pixels the
triangle does not cover stay at the clear value, -1.

The fixed-mesh check is separate. It links the reviewed mesh with this kind of
tail, then creates a color pipeline from the captured root and attachment
state. Its readback is the slot 57 target, not the 8x2 fixture above.

```powershell
ctest --preset dev --no-tests=error -R "native_pixel_compare_mask|native_fixed_mesh57_compare_vcc" -V
```

WARP and hardware are separate tests. A hardware result of 77 is a capability
skip. The container and IR tests do not draw.
167 changes: 165 additions & 2 deletions src/gfx1013_direct_graphics.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1661,8 +1661,59 @@ NativeComputeShader lower_graphics(GuestShaderStage &stage, unsigned first_srv =
return alu.ir.value("xor i1 " + helper + ", true");
};
GraphicsFullWave full_wave{alu, stage.wave32 ? 32u : 64u};
// A two-SGPR compare and the combines made from it. The bit is the lane's
// view of that pair. A 32-bit write to either half drops the pair.
struct CompareMaskBit {
string bit;
bool uniform = false;
};
std::map<unsigned, CompareMaskBit> compare_masks;
std::set<unsigned> broken_compare_masks;
bool compare_scc_unknown = false;
// First pc of each block. An entry holds only in the block that recorded
// it: a join or a sibling block reads the pair through the per-edge state.
std::set<unsigned> block_entries;
// Vertex class masks still use the symbolic pair. Recording them here would
// keep a CNDMASK source after a 32-bit half overwrite.
auto in_compare_tail = [&] {
return pixel && (whole_quad || exact_after_wqm);
};
auto instruction = [&](const Inst &i, const State &state) {
const auto pc = alu.graphics_pc = graphics.pc = i.pc;
if (block_entries.count(pc)) {
compare_masks.clear();
broken_compare_masks.clear();
}
// A scalar destination the tracker does not itself rewrite drops any
// pair it overlaps. Otherwise v_cndmask keeps a compare bit the guest
// register no longer holds.
struct UnclaimedMaskRelease {
bool claimed = false;
const Inst* inst = nullptr;
bool pixel = false;
const bool* whole_quad = nullptr;
const bool* exact_after_wqm = nullptr;
std::map<unsigned, CompareMaskBit>* masks = nullptr;
std::set<unsigned>* broken = nullptr;
~UnclaimedMaskRelease() {
if (claimed || inst == nullptr || !pixel || (!*whole_quad && !*exact_after_wqm))
return;
const unsigned width = GraphicsMaskRegions::scalar_width(*inst);
if (!width || inst->dst > 105)
return;
for (unsigned reg = inst->dst; reg < inst->dst + width && reg <= 105; ++reg) {
const unsigned base = reg & ~1u;
masks->erase(base);
broken->erase(base);
}
}
} mask_release;
mask_release.inst = &i;
mask_release.pixel = pixel;
mask_release.whole_quad = &whole_quad;
mask_release.exact_after_wqm = &exact_after_wqm;
mask_release.masks = &compare_masks;
mask_release.broken = &broken_compare_masks;
if (waterfalls.restores.count(pc)) return;
if (auto dead=waterfalls.poisoned.find(pc);dead!=waterfalls.poisoned.end())
for (unsigned reg:dead->second) alu.write(reg,{});
Expand Down Expand Up @@ -1981,7 +2032,14 @@ NativeComputeShader lower_graphics(GuestShaderStage &stage, unsigned first_srv =
if (i.dst<it->first+(stage.wave32 ? 1u : 2u) && it->first<i.dst+width) it=saved_exec.erase(it);
else ++it;
}
if (exact_after_wqm && i.enc != Encoding::Smem && i.enc != Encoding::Sopp &&
// A plain compare or select is the whole-quad tail's per-lane predicate.
// Other exact-mask operations stay refused.
const bool exact_mask_select = pixel && whole_quad && exact_after_wqm && !i.dpp_control && !i.subword &&
!i.scale && !i.clamp && !i.abs && !i.neg &&
((i.enc == Encoding::Vopc && i.name.size() >= 6 && i.name.substr(0, 6) == "v_cmp_" &&
i.name.find("class") == std::string_view::npos) ||
i.name == "v_cndmask_b32");
if (exact_after_wqm && !exact_mask_select && i.enc != Encoding::Smem && i.enc != Encoding::Sopp &&
i.enc != Encoding::Sop1 && i.enc != Encoding::Sop2 && i.enc != Encoding::Sopk &&
i.enc != Encoding::Export &&
!(i.name == "v_mov_b32" && i.dst >= 256 && !i.dpp_control && !i.subword) &&
Expand All @@ -2002,6 +2060,8 @@ NativeComputeShader lower_graphics(GuestShaderStage &stage, unsigned first_srv =
i.name != "v_nop" && i.name != "s_nop" && i.name != "s_clause" &&
i.name != "s_setprio" && i.name != "s_inst_prefetch" && i.name != "s_waitcnt")
scalar_entry = false;
if (compare_scc_unknown && (i.name == "s_cselect_b32" || i.name == "s_cselect_b64"))
refuse(pc, "SCC read without an established wave-wide nonzero result");
if (i.dpp_control) {
if (i.mirror_mask())
refuse(pc, i.mirror_mask() == 7 ? "DPP half-row mirror requires a proven eight-lane pixel layout"
Expand Down Expand Up @@ -2100,6 +2160,11 @@ NativeComputeShader lower_graphics(GuestShaderStage &stage, unsigned first_srv =
alu.write(i.dst,{});
if (!stage.wave32) alu.write(i.dst+1,{});
alu.write(1024+pc,bit);
if (in_compare_tail() && i.dst <= 104 && !(i.dst & 1)) {
compare_masks[i.dst] = {bit, alu.ir.dependencies[bit].none()};
broken_compare_masks.erase(i.dst);
mask_release.claimed = true;
}
}
if (i.dst == 106 && alu.graphics_predicate.empty() && scalar_operand(i.src[0]) && scalar_operand(i.src[1]) &&
alu.ir.dependencies[bit].none()) uniform_vcc_values.insert(bit);
Expand All @@ -2112,7 +2177,14 @@ NativeComputeShader lower_graphics(GuestShaderStage &stage, unsigned first_srv =
a = alu.subword(a, i.src_select[0], i.src_sext[0]);
b = alu.subword(b, i.src_select[1], i.src_sext[1]);
}
auto mask = alu.graphics_lane_mask(i,state,i.src[2],"unproven graphics CNDMASK source");
string mask;
const auto tracked = in_compare_tail() ? compare_masks.find(i.src[2]) : compare_masks.end();
if (in_compare_tail() && i.src[2] <= 104 && broken_compare_masks.count(i.src[2]))
refuse(pc, "compare mask half overwritten");
else if (tracked != compare_masks.end())
mask = tracked->second.bit;
else
mask = alu.graphics_lane_mask(i,state,i.src[2],"unproven graphics CNDMASK source");
alu.vector_write(i.dst, alu.place_subword(i, alu.select(alu.cmp("ne",mask,"0"), b, a)));
return;
}
Expand All @@ -2127,6 +2199,93 @@ NativeComputeShader lower_graphics(GuestShaderStage &stage, unsigned first_srv =
alu.write(i.dst,value);
return;
}
auto compare_mask_bit = [&](unsigned src) -> std::optional<CompareMaskBit> {
if (src > 104 || (src & 1))
return std::nullopt;
if (broken_compare_masks.count(src))
refuse(pc, "compare mask half overwritten");
if (auto found = compare_masks.find(src); found != compare_masks.end())
return found->second;
const auto &low = state[src];
const bool tagged = low.type == Symbol::Type::lane_mask || low.type == Symbol::Type::uniform_mask;
if (tagged && !low.offset && (stage.wave32 || state[src + 1] == Symbol{low.type, low.value, 1})) {
auto bit = alu.read(1024 + low.value);
CompareMaskBit saved{bit, alu.ir.dependencies[bit].none()};
compare_masks[src] = saved;
return saved;
}
return std::nullopt;
};
auto vcc_bit = [&]() -> std::optional<CompareMaskBit> {
auto found = alu.graphics_registers.find(106);
if (found == alu.graphics_registers.end() || found->second.empty())
return std::nullopt;
return CompareMaskBit{found->second, alu.ir.dependencies[found->second].none()};
};
if (in_compare_tail() && i.name == "s_mov_b64" && i.dst <= 104 && !(i.dst & 1) && i.src[0] <= 104) {
const bool known = broken_compare_masks.count(i.src[0]) || compare_masks.count(i.src[0]) ||
state[i.src[0]].type == Symbol::Type::lane_mask ||
state[i.src[0]].type == Symbol::Type::uniform_mask;
if (known) {
if (broken_compare_masks.count(i.src[0])) {
broken_compare_masks.insert(i.dst);
compare_masks.erase(i.dst);
mask_release.claimed = true;
} else if (auto bit = compare_mask_bit(i.src[0])) {
compare_masks[i.dst] = *bit;
broken_compare_masks.erase(i.dst);
mask_release.claimed = true;
}
alu.write(i.dst, {});
alu.write(i.dst + 1, {});
return;
}
}
// A wave32 mask is one SGPR, so the odd register is not its high half.
if (in_compare_tail() && !stage.wave32 && i.name == "s_mov_b32" && i.dst <= 105) {
const unsigned base = i.dst & ~1u;
if (compare_masks.count(base) || broken_compare_masks.count(base) ||
state[base].type == Symbol::Type::lane_mask || state[base].type == Symbol::Type::uniform_mask) {
broken_compare_masks.insert(base);
mask_release.claimed = true;
}
}
if (in_compare_tail() &&
(i.name == "s_and_b64" || i.name == "s_or_b64" || i.name == "s_andn2_b64") &&
i.dst <= 104 && !(i.dst & 1) && i.src[0] != 126 && i.src[1] != 126) {
auto resolve = [&](unsigned src) -> std::optional<CompareMaskBit> {
return src == 106 ? vcc_bit() : compare_mask_bit(src);
};
auto left = resolve(i.src[0]);
auto right = resolve(i.src[1]);
if (left && right) {
// s_andn2_b64 is S0 & ~S1. The operands are not interchangeable.
string bit = i.name == "s_or_b64" ? alu.ir.binary("or", left->bit, right->bit) :
i.name == "s_and_b64" ? alu.ir.binary("and", left->bit, right->bit) :
alu.ir.binary("and", left->bit, alu.ir.binary("xor", right->bit, "1"));
const bool uniform = left->uniform && right->uniform && alu.ir.dependencies[bit].none();
compare_masks[i.dst] = {bit, uniform};
broken_compare_masks.erase(i.dst);
mask_release.claimed = true;
alu.write(i.dst, {});
alu.write(i.dst + 1, {});
alu.write(1024 + pc, bit);
if (uniform) {
alu.write(128, bit);
compare_scc_unknown = false;
} else {
alu.write(128, {});
compare_scc_unknown = true;
}
return;
}
auto tracked = [&](unsigned src) {
return src == 106 || (src <= 104 && !(src & 1) &&
(compare_masks.count(src) || broken_compare_masks.count(src)));
};
if (tracked(i.src[0]) && tracked(i.src[1]))
refuse(pc, "compare mask is not a 64-bit lane mask");
}
if (whole_quad && !exact_after_wqm && alu.graphics_predicate.empty() &&
i.name == "s_and_b64" && i.dst <= 104 && !(i.dst & 1) &&
((i.src[0] == 106 && i.src[1] == 126) || (i.src[1] == 106 && i.src[0] == 126))) {
Expand Down Expand Up @@ -2259,6 +2418,8 @@ NativeComputeShader lower_graphics(GuestShaderStage &stage, unsigned first_srv =
}
};
auto blocks = graphics_blocks(program, regions);
for (const auto &entry : blocks)
block_entries.insert(entry.first);
std::map<unsigned, std::vector<GraphicsEdge>> edges;
std::vector<unsigned> ready;
if (!blocks.at(0).predecessors)
Expand Down Expand Up @@ -2306,6 +2467,8 @@ NativeComputeShader lower_graphics(GuestShaderStage &stage, unsigned first_srv =
alu.ir.body << " br label %graphicsEnd\n";
} else if (block.successors.size() == 2) {
const auto branch = regions.lane_branches.find(last.pc);
if (branch == regions.lane_branches.end() && last.op < 6 && compare_scc_unknown)
refuse(last.pc, "SCC read without an established wave-wide nonzero result");
auto condition = branch != regions.lane_branches.end() ?
alu.cmp(branch->second.second ? "ne" : "eq", alu.read(branch->second.first), "0") :
alu.cmp((last.op & 1) ? "ne" : "eq", alu.read(last.op >= 6 ? 106 : 128), "0");
Expand Down
19 changes: 19 additions & 0 deletions tests/cmake/native_pixel_compare_mask.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Pixel compare mask composed with VCC after whole-quad entry.
# native_pixel_compare_mask_ir checks the DXIL text. The container entry validates it through DXC.
# The draw entries read back the four combine results on WARP and on a physical GPU.
if(TARGET compile_dxil AND TARGET offscreen_check AND EXISTS "${INTAKE_PYTHON}")
foreach(backend IN ITEMS warp hardware)
add_test(NAME native_pixel_compare_mask_${backend} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/native_pixel_compare_mask_check.py"
"$<TARGET_FILE:compile_dxil>" "$<TARGET_FILE:offscreen_check>" "${DXC_BIN_DIR}" ${backend})
set_tests_properties(native_pixel_compare_mask_${backend} PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
endforeach()
add_test(NAME native_pixel_compare_mask_container COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/native_pixel_compare_mask_check.py" container
"$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}")
endif()
if(TARGET native_pixel_ir_dump AND EXISTS "${INTAKE_PYTHON}")
add_test(NAME native_pixel_compare_mask_ir COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/native_pixel_compare_mask_check.py" ir
"$<TARGET_FILE:native_pixel_ir_dump>")
endif()
3 changes: 3 additions & 0 deletions tests/native_direct_container_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,9 @@ def install(raw, container):
assert f"frontend_cache_hit={warm}" in result.stdout
check("patch-range", "gfx1013-container-ps", patched_pixel(3), "record outside")
check("pixel", "gfx1013-direct-constant-ps", words(0x7e0002f2, 0xf800180f, 0, end))
from native_pixel_compare_mask_check import container_cases
for label, blob, reason in container_cases():
check("pixel-" + label, "gfx1013-container-ps", blob, reason)


if __name__ == "__main__":
Expand Down
Loading
Loading