diff --git a/docs/experiments/native-graphics-wqm-cross-quad.md b/docs/experiments/native-graphics-wqm-cross-quad.md new file mode 100644 index 0000000000..74d4946d39 --- /dev/null +++ b/docs/experiments/native-graphics-wqm-cross-quad.md @@ -0,0 +1,110 @@ +# Cross-quad WQM/EXECZ in a native pixel draw (#2907) + +[The fixture](../../tests/native_graphics_wqm_check.py) draws source-built gfx1013 pixel stages through the +direct DXIL frontend. In each one, an `s_cbranch_execz` under WQM decides a scalar that every surviving pixel +exports. The branch is skipped only when EXEC is zero in the whole guest wave. A quad with no EXEC bit at the +branch therefore still sees whether another quad of its wave kept the wave from skipping. + +## The accepted form + +``` +s_mov sE, exec ; s_wqm exec, exec +v_cmp_* vcc, ... ; s_andn2 sE, sE, vcc one or more coverage filters +v_cmp_* vcc, ... ; s_andn2 sM, sE|exec, vcc the branch mask, from the survivors or the whole-quad EXEC +v_cmp_* vcc, ... ; s_andn2 sM, sM, vcc optional further terms +s_wqm exec, sM ; s_cbranch_execz J the region writes only scalars +J: s_mov exec, sE then a terminal colour export +``` + +Following the maintainers' decision on the issue, the branch condition is `WaveActiveAnyTrue` of the +quad-complete EXEC bit: +- the modelled mask predicate is OR-ed with its `QuadReadAcrossX`, `QuadReadAcrossY` and + `QuadReadAcrossDiagonal`; +- quad reads see helper lanes, so a quad whose EXEC bits sit only on helpers or on covered pixels that did + not survive still votes, as it does on the guest; +- all of this uses Shader Model 6.0 operations, with no `[WaveOpsIncludeHelperLanes]`. + +The calls are emitted before the first conditional branch, where the whole quad still runs. The IR test checks +this, and checks that their declarations carry the attributes DXC gives the HLSL intrinsics. + +These still keep a refusal by name: +- inside the region: a vector or DPP instruction, an EXEC or VCC read, a hardware register access + (`s_setreg`/`s_getreg`), a branch, or an EXEC write other than the restore; +- a restore that is not the branch target; +- a second branch; +- anything after the restore other than lane-local ALU and colour exports. + +`raster_program(2.5, cross=True)` keeps its existing refusal. + +## Contract and what this shows + +The lowering decides the branch once per **desktop** wave. It relies on the packing contract of #2835 and +#2854: a correct program cannot depend on which quads the console puts in one wave. A program can only see the +branch outcome through an effect outside EXEC, here an SGPR. This fixture builds such a dependency on purpose, +so its reference comes from the measured desktop layout. + +**The draws show that the lowering votes over the desktop wave. They do not show equivalence with the console +for an output that depends on another quad.** + +## Measured layout + +Two HLSL pixel stages on the same draw report, for every covered pixel: +- its wave: the smallest covered id in it; +- the ids of its three quad peers; +- whether each peer is a helper (`IsHelperLane`, SM 6.6). + +Wave operations leave helpers out, so the helper flags come from quad reads. The fixture checks that every +desktop quad is the aligned 2x2 block, and that all covered lanes of a quad report the same quad. Quads are +per primitive. On WARP the two middle quads of the 8x2 target are each shaded twice, once with each row covered +and the other row as helpers, as if the full-screen triangle were drawn as two primitives. The layout is +measured in separate draws with the same vertex stage and target. The reference follows the measured quads. + +| Adapter | Lanes | Full draw | Diagonal draw | +|---|---|---|---| +| NVIDIA GeForce RTX 3070, driver 32.0.16.2101 | 32 | 4 quads in 1 wave, no helpers | 3 quads in 1 wave, 3 helpers | +| Microsoft Basic Render Driver, 10.0.26100.9818 | 4 | 6 quads in 6 waves, 8 helpers | 5 quads in 5 waves, 11 helpers | + +## Cases and controls + +| Draw | Mask | Shows | +|---|---|---| +| full | survivors with x <= 1 (14 survivors) | another quad's survivors keep the wave from skipping | +| full | survivors with x <= 4.5 (all 16) | as above, one quad without bits | +| full | x <= -1 | empty wave: the branch is taken, every vote agrees | +| full | whole-quad EXEC with x >= 4.5, survivors x <= 3.5 | bits only on covered pixels that did not survive | +| full | survivors with x >= 4.5 | no bits: WQM never makes a zero mask non-zero | +| diagonal | whole-quad EXEC, x >= 5, y >= 1 | the bit only on the diagonal helper of (4,0) | +| diagonal | whole-quad EXEC, x >= 5, y <= 1 | the bit only on the horizontal helper | +| diagonal | whole-quad EXEC, x = 4..5, y >= 1 | the bit only on the vertical helper | + +Each case is drawn against the measured-layout reference. Each control redraws the same program against a +different reference and must differ: +- a quad-local vote; +- a wave vote without the quad OR; +- a vote over surviving pixels only. + +Pixels outside exact coverage keep the clear value -1.0. + +## Command and result + +```powershell +cmake --build --preset dev --target compile_dxil offscreen_check native_store_replay native_pixel_ir_dump +ctest --preset dev --no-tests=error -V -R '^native_graphics_wqm_(hardware|warp|ir)$' +``` + +See the pull request for the measured counts. +- **On the RTX 3070** every control differs. +- **On WARP** (one quad per wave), the quad-local control cannot differ, and the test prints + `SKIPPED cross-quad quad-local control`. The three helper cases still differ from the no-OR and survivor + votes, at pixel (4,0). +- On a physical adapter with no wave holding two quads, the hardware entry exits 77 after the other checks. + +## Limits + +- **Helper lanes after the vote:** wave intrinsics are undefined on helper lanes, so the branch may diverge for + them. That is safe only while nothing after the branch reads another lane. +- **Adapters:** a 64-lane adapter has not been run. The RX 9070 XT is blocked by #2915. AMD and Intel have + not been run. +- **Programs:** only the form above is accepted. Real programs and captures have not been run. +- **Clipping:** a console that clips or splits primitives differently from the desktop forms different quads. + This holds for the existing quad-local path too. diff --git a/src/gfx1013_direct_graphics.inl b/src/gfx1013_direct_graphics.inl index da6c89e8b3..95d2b3addd 100644 --- a/src/gfx1013_direct_graphics.inl +++ b/src/gfx1013_direct_graphics.inl @@ -1405,6 +1405,7 @@ NativeComputeShader lower_graphics(GuestShaderStage &stage, unsigned first_srv = PixelWqm wqm; if (pixel) { wqm.raster_guard(program,stage.wave32); + wqm.raster_vote(program,stage.wave32); wqm.numeric_guards(program,stage.wave32); } GraphicsMaskRegions regions(program, stage.wave32, !pixel); @@ -1487,6 +1488,35 @@ NativeComputeShader lower_graphics(GuestShaderStage &stage, unsigned first_srv = alu.write(128,{}); return; } + if (auto vote=wqm.vote_masks.find(pc); vote!=wqm.vote_masks.end()) { + if (!whole_quad || exact_after_wqm || !alu.graphics_predicate.empty() || wqm.survivor.empty()) + refuse(pc,"cross-quad EXECZ mask requires whole-quad EXEC after a coverage filter"); + // Every lane of a covered quad, helpers included, is in the + // whole-quad EXEC; the filtered coverage holds only survivors. + const auto keep=alu.cmp("eq",alu.read(106),"0"); + using Source=PixelWqm::MaskSource; + if (vote->second==Source::narrowed && wqm.vote_lane.empty()) + refuse(pc,"cross-quad EXECZ mask narrowed before it is written"); + wqm.vote_lane=vote->second==Source::whole_quad ? keep : + alu.ir.value("and i1 "+(vote->second==Source::survivors ? wqm.survivor : wqm.vote_lane)+", "+keep); + alu.write(i.dst,{}); if (!stage.wave32) alu.write(i.dst+1,{}); + alu.write(128,{}); + return; + } + if (pc==wqm.vote_wqm) { + if (wqm.vote_lane.empty()) refuse(pc,"cross-quad EXECZ vote has no modelled EXEC"); + // EXEC at the branch is the WQM expansion of the mask: OR it over + // the quad (quad reads see helper lanes), then vote over the wave. + alu.ir.uses_wave=true; + auto bit=alu.ir.value("zext i1 "+wqm.vote_lane+" to i32"); + auto quad=bit; + for (unsigned op=0;op<3;++op) + quad=alu.ir.binary("or",quad, + alu.ir.invoke("i32","quadOp.i32",123,{{"i32",bit},{"i8",to_string(op)}},"nounwind")); + auto vote=alu.ir.invoke("i1","waveAnyTrue",113,{{"i1",alu.cmp("ne",quad,"0")}},"nounwind"); + alu.write(128,alu.ir.value("zext i1 "+vote+" to i32")); + return; + } if (wqm.quad_guards.count(pc)) { // Helpers have no input coverage bit. Broadcast the four survivor // bits while the quad is intact. Only a terminal colour region @@ -1999,7 +2029,13 @@ NativeComputeShader lower_graphics(GuestShaderStage &stage, unsigned first_srv = 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"); - if (branch == regions.lane_branches.end() && alu.ir.dependencies[condition].any()) + // The cross-quad EXECZ vote is uniform over the desktop wave; + // its input dependencies still reach the values merged after it. + // Wave intrinsics are undefined on helper lanes, so a helper may + // take the other edge: safe only while nothing after the branch + // reads another lane (raster_vote keeps the tail lane-local). + if (branch == regions.lane_branches.end() && alu.ir.dependencies[condition].any() && + last.pc != wqm.vote_skip) refuse(last.pc, "graphics scalar condition depends on a varying input"); alu.ir.body << " br i1 " << condition << ", label %g" << last.target() << ", label %g" << last.next << "\n"; diff --git a/src/gfx1013_graphics_wqm.inl b/src/gfx1013_graphics_wqm.inl index 3aece99345..38f1062df7 100644 --- a/src/gfx1013_graphics_wqm.inl +++ b/src/gfx1013_graphics_wqm.inl @@ -8,6 +8,12 @@ struct PixelWqm { std::set filters, quad_guards; unsigned exact_restore = UINT_MAX; string survivor; + // Cross-quad EXECZ (#2907): each write of the branch mask, taken from the + // filtered coverage or the whole-quad EXEC, or narrowing the mask again. + enum class MaskSource { survivors, whole_quad, narrowed }; + std::map vote_masks; + unsigned vote_wqm = UINT_MAX, vote_skip = UINT_MAX; + string vote_lane; static bool local(const Inst &i) { return GraphicsMaskRegions::local_alu(i) || i.name == "s_waitcnt" || i.name == "s_nop" || @@ -139,6 +145,123 @@ struct PixelWqm { p.at.erase(code.back().pc); code.resize(null); } + // A scalar instruction that neither reads nor writes EXEC or VCC. + static bool plain_scalar(const Inst &i) { + if (i.enc != Encoding::Sop1 && i.enc != Encoding::Sop2 && i.enc != Encoding::Sopc && + i.enc != Encoding::Sopk) + return false; + return (i.enc == Encoding::Sopc || i.dst < 106) && i.name.find("exec") == Name::npos && + std::none_of(i.src.begin(), i.src.end(), [](unsigned r) { return r >= 106 && r <= 127; }); + } + // Cross-quad EXECZ under WQM (#2907): + // s_mov sE, exec; s_wqm exec, exec + // one or more coverage filters v_cmp_* vcc; s_andn2 sE, sE, vcc + // v_cmp_* vcc; s_andn2 sM, sX, vcc sX = sE (survivors) or exec (whole quads) + // s_wqm exec, sM; s_cbranch_execz J the region writes only scalars + // J: s_mov exec, sE then a terminal colour export + // Lanes are skipped only when EXEC is zero in the whole guest wave, so the + // branch is a vote over the wave. It is lowered over the desktop wave, + // under the #2835 packing contract: a correct program cannot depend on + // which quads share a guest wave. The vote reads EXEC as modelled at the + // branch, OR-ed across the quad, so helper lanes count as on the guest. + void raster_vote(Program &p, bool narrow) { + auto &code = p.code; + const auto mov = narrow ? "s_mov_b32" : "s_mov_b64", andn2 = narrow ? "s_andn2_b32" : "s_andn2_b64"; + const unsigned last_reg = narrow ? 105u : 104u; + auto aligned = [&](unsigned r) { return r <= last_reg && (narrow || !(r & 1)); }; + auto overlaps = [&](const Inst &i, unsigned r) { + const unsigned width = i.name.find("_b64") != Name::npos ? 2 : 1; + return i.enc != Encoding::Sopc && i.dst < r + (narrow ? 1u : 2u) && r < i.dst + width; + }; + auto compare = [](const Inst &i) { + return i.enc == Encoding::Vopc && i.dst == 106 && i.name.substr(0, 6) == "v_cmp_" && + i.name.find("class") == Name::npos; + }; + if (!filters.empty() || code.size() < 10 || code[0].name != mov || code[0].src[0] != 126 || + !aligned(code[0].dst) || !is_wqm(code[1], narrow) || code[1].dst != 126 || code[1].src[0] != 126) + return; + const unsigned entry = code[0].dst; + size_t n = 2; + while (n + 1 < code.size() && !code[n].branch() && !(is_wqm(code[n], narrow) && code[n].dst == 126)) + ++n; + if (n + 1 >= code.size() || code[n].branch() || !code[n + 1].branch() || code[n + 1].op != 8 || + code[n + 1].target() <= code[n + 1].pc) + return; + const auto &wqm = code[n]; + auto &skip = code[n + 1]; + if (!aligned(wqm.src[0]) || wqm.src[0] == entry) + return; + const unsigned mask = wqm.src[0]; + // Before the vote: filters on sE, the mask write and lane-local work. + std::vector filter_pcs; + std::map mask_writes; + bool vcc_from_compare = false; + for (size_t k = 2; k < n; ++k) { + const auto &i = code[k]; + if (compare(i)) { + vcc_from_compare = true; + continue; + } + if (i.name == andn2 && i.src[1] == 106) { + if (!vcc_from_compare) + return; + if (i.dst == entry && i.src[0] == entry && mask_writes.empty()) + filter_pcs.push_back(i.pc); + else if (i.dst == mask && mask_writes.empty() && (i.src[0] == entry || i.src[0] == 126)) + mask_writes.emplace(i.pc, i.src[0] == 126 ? MaskSource::whole_quad : MaskSource::survivors); + else if (i.dst == mask && i.src[0] == mask && !mask_writes.empty()) + mask_writes.emplace(i.pc, MaskSource::narrowed); + else + return; + vcc_from_compare = false; + continue; + } + if (local(i) && !(i.dst < 256 && (i.dst == 106 || i.dst == 107))) + continue; + if (plain_scalar(i) && !overlaps(i, entry) && !overlaps(i, mask)) + continue; + return; + } + if (filter_pcs.empty() || mask_writes.empty()) + return; + // The region: from here on the shape is claimed, so refuse by name. + size_t r = n + 2; + for (; r < code.size() && !(code[r].name == mov && code[r].dst == 126); ++r) { + const auto &i = code[r]; + if (i.name == "s_nop" || i.name == "s_waitcnt") + continue; + if (i.branch()) + refuse(i.pc, "cross-quad EXECZ region contains a branch"); + if (i.name.find("s_setreg") == 0 || i.name.find("s_getreg") == 0) + refuse(i.pc, "cross-quad EXECZ region accesses a hardware register with " + string(i.name)); + if (!plain_scalar(i)) + refuse(i.pc, "cross-quad EXECZ region may only write scalars; " + string(i.name) + + " depends on the lanes the vote leaves out"); + if (overlaps(i, entry)) + refuse(i.pc, "cross-quad EXECZ region overwrites the saved coverage"); + } + if (r == code.size() || code[r].src[0] != entry || skip.target() != code[r].pc) + refuse(skip.pc, "cross-quad EXECZ must branch to the exact coverage restore"); + for (size_t j = r + 1; j < code.size(); ++j) { + const auto &i = code[j]; + if (i.name == "s_endpgm" && j + 1 == code.size()) + break; + if (!(GraphicsMaskRegions::local_alu(i) || i.name == "s_waitcnt" || + (i.enc == Encoding::Export && ((i.a >> 4) & 63) < 8))) + refuse(i.pc, "cross-quad EXECZ needs a terminal colour export after the restore"); + } + for (const auto &i : code) + if (i.branch() && i.pc != skip.pc) + refuse(i.pc, "cross-quad EXECZ program has another branch"); + filters.insert(filter_pcs.begin(), filter_pcs.end()); + vote_masks.insert(mask_writes.begin(), mask_writes.end()); + vote_wqm = wqm.pc; + vote_skip = skip.pc; + exact_restore = code[r].pc; + // SCC carries the vote; it is uniform over the desktop wave. + skip.op = 4; + skip.name = "s_cbranch_scc0"; + } string expand(DxilModule &ir, const string &mask) const { auto pair = ir.binary("or", mask, ir.binary("lshr", mask, "1")); auto nibble = ir.binary("or", pair, ir.binary("lshr", pair, "2")); diff --git a/tests/cmake/native_graphics_wqm.cmake b/tests/cmake/native_graphics_wqm.cmake new file mode 100644 index 0000000000..aed792142b --- /dev/null +++ b/tests/cmake/native_graphics_wqm.cmake @@ -0,0 +1,11 @@ +# Cross-quad WQM/EXECZ in a native pixel draw (#2907). native_graphics_wqm_hardware stays in CMakeLists.txt. +# The WARP entry runs every case that one quad per wave can decide; the IR entry checks, without a GPU, that the +# vote's quad and wave operations are emitted before any branch. +if(TARGET compile_dxil AND TARGET native_store_replay AND TARGET offscreen_check AND EXISTS "${INTAKE_PYTHON}") + add_test(NAME native_graphics_wqm_warp COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_graphics_wqm_check.py" "$" + "$" "${DXC_BIN_DIR}" warp) + set_tests_properties(native_graphics_wqm_warp PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60) + add_test(NAME native_graphics_wqm_ir COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_graphics_wqm_check.py" ir "$") +endif() diff --git a/tests/native_graphics_wqm_check.py b/tests/native_graphics_wqm_check.py index 73cd055b83..819b0de3d8 100644 --- a/tests/native_graphics_wqm_check.py +++ b/tests/native_graphics_wqm_check.py @@ -1,4 +1,5 @@ """Check whole-wave zero and pixel coverage using source-built guest shaders.""" +import re import struct import subprocess import sys @@ -76,25 +77,168 @@ def quad_mask(word): return sum(15<= value; the compare sets VCC for the lanes it removes. +def term_compare(axis, op, value): + return [(0x7c020000 if op=="le" else 0x7c080000) | ({"x":0,"y":1}[axis]<<9) | 255, + struct.unpack("=v) + for a,op,v in terms) + survives=lambda lane, helper: not helper and position(lane)[0]<=limit + def bit(lane, helper): + if base=="survivors" and not survives(lane,helper): + return False + if vote=="plain" and helper or vote=="survivors" and not survives(lane,helper): + return False + return keep(lane) + voted={(w if vote!="quad" else (w,lanes)) for w,lanes in quads if any(bit(*l) for l in lanes)} + pixels=[(-1.0,)*4]*16 + for w,lanes in quads: + flag=2.0 if (w if vote!="quad" else (w,lanes)) in voted else 1.0 + for lane,helper in lanes: + if survives(lane,helper): + pixels[lane]=(position(lane)[0],position(lane)[0],flag,flag) + return pixels + + +def desktop_quads(work, raster, sdk, backend, vs): + """Measure the quads and waves of the 8x2 draw with HLSL pixel stages on the same draw. + + Wave operations leave helper lanes out, so each covered pixel reports its wave (the smallest covered id in + it), the ids of its three quad peers and whether each peer is a helper (IsHelperLane, SM 6.6).""" + reads={"ids": ("ps_6_0","float4(WaveActiveMin(id),QuadReadAcrossX(id),QuadReadAcrossY(id)," + "QuadReadAcrossDiagonal(id))"), + "helpers": ("ps_6_6","float4(WaveGetLaneCount(),QuadReadAcrossX(h),QuadReadAcrossY(h)," + "QuadReadAcrossDiagonal(h))")} + data={} + for key,(profile,value) in reads.items(): + source, ps, out = work/f"{key}.hlsl", work/f"{key}.cso", work/f"{key}.bin" + source.write_text("float4 main(float4 p:SV_Position):SV_Target {uint id=uint(p.y)*8u+uint(p.x);" + f"uint h=IsHelperLane()?1u:0u; return {value};}}" if profile=="ps_6_6" else + "float4 main(float4 p:SV_Position):SV_Target {uint id=uint(p.y)*8u+uint(p.x);" + f"return {value};}}") + subprocess.run([Path(sdk)/"dxc.exe","-T",profile,"-Fo",ps,source],check=True) + result=subprocess.run([raster,backend,"--startup-pixel-dump",vs,ps,"8","2",out],capture_output=True,text=True) + if result.returncode==77: sys.exit(77) + assert result.returncode==0,(result.stdout,result.stderr) + values=struct.unpack("<64f",out.read_bytes()) + data[key]=[values[4*i:4*i+4] for i in range(16)] + quads, widths = {}, set() + for lane in range(16): + if data["ids"][lane]==(-1.0,)*4: + continue # not covered: the clear value + wave,*peers=(int(v) for v in data["ids"][lane]) + width,*helpers=(int(v) for v in data["helpers"][lane]) + widths.add(width) + members=((lane,False),*((p,bool(h)) for p,h in zip(peers,helpers))) + assert len({m[0] for m in members})==4 and all(position(p)[0]//2==position(lane)[0]//2 and + position(p)[1]//2==position(lane)[1]//2 for p,_ in members),\ + ("a desktop quad is not the aligned 2x2 block",lane,members) + quads.setdefault((wave,frozenset(members)),set()).add(lane) + assert len(widths)==1,widths + for (wave,members),lanes in quads.items(): + # Every covered lane of a quad reports the same quad, and its smallest covered lane names a wave. + assert lanes=={l for l,h in members if not h},(wave,members,lanes) + return [(w,tuple(sorted(m))) for w,m in quads], widths.pop() + + +VERTEX={"full": "float4 main(uint i:SV_VertexID):SV_Position {return float4(i==1?3:-1,i==2?3:-1,0,1);}", + # Covers the pixels with x + y < 5.5, so the quad at x = 4..5 has one covered lane, (4,0). + "diagonal": "float4 main(uint i:SV_VertexID):SV_Position {" + "return float4(i==0?-0.25:(i==1?0.5:-5),i==0?-1.5:(i==1?1.5:0),0,1);}"} +# (vertex, limit, terms, base): one quad's survivors hold the mask; a wider mask; an empty wave; a mask in +# covered quads without survivors (WQM before the filter); the same from the survivors; and masks that only +# the diagonal, horizontal or vertical helper of the one covered lane (4,0) holds. +CASES=(("full",6.5,(("x","le",1.0),),"survivors"), ("full",9,(("x","le",4.5),),"survivors"), + ("full",6.5,(("x","le",-1.0),),"survivors"), ("full",3.5,(("x","ge",4.5),),"wqm"), + ("full",3.5,(("x","ge",4.5),),"survivors"), + ("diagonal",4.5,(("x","ge",5.0),("y","ge",1.0)),"wqm"), + ("diagonal",4.5,(("x","ge",5.0),("y","le",1.0)),"wqm"), + ("diagonal",4.5,(("x","ge",4.0),("x","le",5.0),("y","ge",1.0)),"wqm")) + + +def ir_main(dump): + """Without a GPU: the vote's three quad reads and the wave vote come before any conditional branch, where + every lane of the quad, helpers included, still runs them (quad operations need quad-uniform control flow). + + The patterns follow the frontend's current text form (immediate i8 operands, attributes written inline on + the declaration); a change to that form, for example attribute groups, needs these patterns updated.""" + with TemporaryDirectory() as tmp: + blob=Path(tmp)/"cross.bin" + blob.write_bytes(cross_quad_program(6.5,(("x","le",1.0),))) + result=subprocess.run([dump,blob],capture_output=True,text=True) + assert result.returncode==0,result.stderr + body=result.stdout[result.stdout.index("define void @main"):] + first_branch=body.index("\n br i1 ") # the first conditional branch: the vote's own + quad=[m.group(1) for m in re.finditer(r"@dx\.op\.quadOp\.i32\(i32 123, i32 %\w+, i8 (\d)\)",body)] + vote=[m.start() for m in re.finditer(r"@dx\.op\.waveAnyTrue\(i32 113, i1 %\w+\)",body)] + assert sorted(quad)==["0","1","2"] and len(vote)==1,(quad,vote) + assert all(m.start()1)} waves with more than one quad, " + f"{sum(h for _,lanes in quads for _,h in lanes)} helper lanes") + quads,_=measured[kind] + blob=cross_quad_program(limit,terms,base=base) + reference=lambda vote: cross_quad_reference(limit,terms,quads,vote,base=base) + whole=reference("wave") + draw(blob,whole) + label=f"{kind} limit={limit} {base} {terms}" + print(f"cross-quad {label}: {sum(p[0]!=-1.0 for p in whole)}/16 survive, " + f"s14 {sorted({p[2] for p in whole if p[0]!=-1.0})}") + for vote in ("quad","plain","survivors"): + other=reference(vote) + if other==whole: + continue + result=run(blob,other) + assert result.returncode==1 and "pixels differ" in result.stderr,(vote,label,result.stderr) + print(f" {vote} vote reference: {next(l for l in result.stderr.splitlines() if 'pixels differ' in l)}") + controls[vote]=controls.get(vote,0)+1 + cross_controls+=vote=="quad" + assert cross_quad_reference(6.5,(("x","le",-1.0),),measured["full"][0],"wave")== \ + cross_quad_reference(6.5,(("x","le",-1.0),),measured["full"][0],"quad") + assert controls.get("plain",0)>=3,controls # the three single-helper masks are decided by the quad OR + vertex("full") + # Lane reads, vector writes, branches and EXEC changes inside the region keep a named refusal. + for label,region,reason in ( + ("DPP inside the region",(0x7e0402fa,0xff04b100),"may only write scalars"), + ("VGPR write inside the region",(vmove(1,14),),"may only write scalars"), + ("EXEC read inside the region",(sop1(4,20,126),),"may only write scalars"), + ("branch inside the region",(0xbf820000,),"region contains a branch"), + ("EXEC rewritten inside the region",(sop1(4,126,16),),"must branch to the exact coverage restore"), + ("s_setreg_b32 inside the region",(0xb98e0801,),"hardware register"), + ("s_getreg_b32 inside the region",(0xb9140801,),"hardware register")): + rejected=compile_guest(cross_quad_program(6.5,(("x","le",1.0),),region=region)) + assert rejected.returncode and reason in rejected.stderr,(label,rejected.stderr) + print(f"refused: {label}: ok") # The pixel program now consumes an interpolated value produced by # the VS, including a negative coordinate from a WQM helper. source.write_text("struct Out { float4 tc:TEXCOORD; float4 pos:SV_Position; };" @@ -123,7 +311,18 @@ def draw(blob, pixels): values=[(16+3.25-((x^1)+0.5) if x+0.5<=3.25 else -1.0,)*4 for y in range(2) for x in range(8)] draw(raster_program(),values) print("attr3.z perspective interpolation, VCC filter and WQM/EXECZ: all 16 pixels matched") + print(f"cross-quad EXECZ negative controls that differ from the readback: {controls}") + if not cross_controls: + reason=f"no desktop wave holds two quads ({measured['full'][1]} lanes)" + if backend=="hardware": + # Every other check passed; the cross-quad decision itself was not exercised. + print(f"skip: the cross-quad quad-local control needs two quads in one wave: {reason}") + sys.exit(77) + print(f"SKIPPED cross-quad quad-local control: {reason}") if __name__=="__main__": - main(*sys.argv[1:]) + if sys.argv[1]=="ir": + ir_main(sys.argv[2]) + else: + main(*sys.argv[1:])