Skip to content
Draft
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ The control-flow CPU translator supports [source-built string memory transfers](
| gfx1013 pixel DPP quad broadcast | Lower `quad_perm:[k,k,k,k]` on VOP1/VOP2 after `s_wqm exec, exec` in a straight-line pixel stage to `QuadReadLaneAt` (`ps_6_0`, DXC); draw 16 x 16 pixels and compare with a CPU reference. [Scope and limits](docs/experiments.md#gfx1013-pixel-dpp16-quad-broadcast) | `ctest --preset dev --no-tests=error -R "^startup_gfx2hlsl_dpp_quad_broadcast" -V` |
| gfx1013 compute readlane | Lower a statically selected, defined `v_readlane_b32` source through logical wave32 group-shared staging. [Scope and limits](docs/experiments.md#gfx1013-compute-readlane) | `ctest --preset dev --no-tests=error -R '^compute_store_aot_readlane_' -V` |
| gfx1013 direct compute partial waves | Run partial final guest wave32 and wave64 groups with exact entry EXEC masks and compare raw UAV readback on WARP and hardware. [Lane mapping and limits](docs/experiments/native-compute-partial-final-wave.md) | `ctest --preset dev --no-tests=error -R '^native_partial_final_wave_' -V` |
| gfx1013 pixel descriptor waterfalls | Lower bounded per-lane texture selection through a root table or the resource heap. Check nonuniform DXIL handles and draw source-built explicit-level, explicit-gradient and mip-load fixtures. [Shapes and readback](docs/experiments/native-pixel-waterfall-w6.md) | `ctest --preset dev --no-tests=error -R '^native_pixel_waterfall_w6_' -V` |
| gfx1030 typed-buffer writes | Lower [indexed UINT `tbuffer_store_format_*`](docs/experiments.md#indexed-gfx1030-typed-buffer-writes) for one to four 32-bit or packed 16-bit components. | `ctest --preset dev --no-tests=error -R '^compute_store_aot_mtbuf_store_'` |
| Static shader recompilation | Translate pixel shader fixtures to desktop DXIL and check the output, including all 32 bits of an unsigned conversion. The title alias-table profile reads one to four DWORDs per FLAT load or GLOBAL load with `off`. FLAT requires `flat_global_only=True`, with the caller excluding the scratch and LDS apertures. The x3 fixture checks 35 draws across 19 shader and address cases. Select a local record by name and, for duplicate names, by decoded DXBC SHA-256. [Supported instructions and bindings](docs/experiments.md#offline-pixel-shader-recompilation) · [Float-to-uint readback and entry inputs](docs/experiments.md#unsigned-pixel-conversion-and-entry-inputs) · [DS swizzle and no-op](docs/experiments.md#quad-local-ds-swizzle-in-pixel-shaders) | `ctest --preset dev -R '^pixel_aot_' -V` |
| gfx1030 raw subword writes | Lower [indexed byte and halfword MUBUF stores](docs/experiments.md#indexed-gfx1030-raw-subword-writes) with a single writer to the containing DWORD and verify that neighboring bytes stay intact. | `ctest --preset dev --no-tests=error -R '^compute_store_aot_mubuf_store_subword_'` |
Expand Down
39 changes: 39 additions & 0 deletions docs/experiments/native-pixel-waterfall-w6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Native gfx1013 pixel descriptor waterfalls

The direct pixel frontend can project a single-block descriptor waterfall
onto individual lanes. The pass reads a lane key, selects lanes with that key,
loads an eight-DWORD SRV descriptor and executes one read-only image operation.
`s_andn2_wrexec` removes the sampled lanes, and a separate saved EXEC restores
coverage on exit. A pass can select lanes with `v_cmpx_eq` or with `v_cmp_eq`
followed immediately by `s_and_saveexec` at the guest mask width. It can also
contain `s_clause` and shift the key into a separate SGPR.

The aligned SMEM immediate shifts the proven slot range before checking the
root table or declaring a logical heap span. The image still has to satisfy
the direct texture-view and sampler checks. The added image operations are
`image_load_mip`, `image_get_resinfo`, `image_sample_d`, `image_sample_l`,
`image_gather4_l` and `image_gather4_lz`. Biased samples and implicit gathers
would need a per-quad derivative proof. Comparison samples need a nonuniform
comparison-view path.

```powershell
cmake --build --preset dev --target compile_dxil native_sampled_pixel_gpu
ctest --preset pr --no-tests=error -R '^native_pixel_waterfall_w6_controls$' -V
$env:XBOX2WINDOWS_ADAPTER = 'RTX 5080'
ctest --preset dev --no-tests=error -R '^native_pixel_waterfall_w6_(warp|hardware)$' -V
```

The controls check ten bound-table translations and one heap translation. They
check the table manifest offsets, nonuniform handles, and expected DXIL image
calls. Refusal controls cover scalar values that escape the pass, incorrect
compare inputs, overlapping destinations, and misaligned, wrapping or
out-of-range table spans.

The draw fixture compares 28 covered pixels and four scissored pixels for each
of four shaders. It checks alternating slots, an aligned immediate that shifts
selection from slots 0 and 1 to slots 1 and 2, and mip 1 selection through a
varying-key explicit-LOD sample, explicit gradients, and an integer texel load.
The fixture was checked in Debug and Release on WARP and on an RTX 5080
(driver 32.0.16.2140, Windows 11 build 26200.9974, D3D12 debug layer off).
These measurements cover source-built shaders. The effect on a package's
shader census remains unmeasured.
2 changes: 1 addition & 1 deletion src/gfx1013_direct_compute.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ struct DirectCompute {
// table. Declare that span only and index it nonuniformly.
const auto &sym = s.at(base);
if (kind != ComputeViewKind::texture_srv || (dim != 1 && dim != 5) || base + 8 > 106 ||
sym.type != Symbol::Type::indexed_descriptor || sym.value != *selected->table || sym.offset ||
sym.type != Symbol::Type::indexed_descriptor || sym.value != *selected->table || (sym.offset & 31) ||
selected->first > selected->last || selected->last > 0x07ffffffu)
refuse(i.pc, "unproven bound-table waterfall descriptor");
State span = s;
Expand Down
22 changes: 20 additions & 2 deletions src/gfx1013_direct_graphics.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2218,8 +2218,18 @@ NativeComputeShader lower_graphics(GuestShaderStage &stage, unsigned first_srv =
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,{});
if (waterfalls.exits.count(pc)) alu.write(128,"0"); // no remaining lanes
for (unsigned reg:dead->second) {
alu.write(reg,{});
const unsigned mask=stage.wave32 ? reg : reg&~1u;
saved_exec.erase(mask);
invariant_entry_masks.erase(mask);
compare_masks.erase(mask);
broken_compare_masks.erase(mask);
}
if (waterfalls.exits.count(pc)) {
alu.write(128,"0"); // no remaining lanes
compare_scc_unknown=false;
}
if (auto access=waterfalls.accesses.find(pc);access!=waterfalls.accesses.end()) {
const auto &which=access->second;
auto key=alu.read(which.key);
Expand All @@ -2235,6 +2245,14 @@ NativeComputeShader lower_graphics(GuestShaderStage &stage, unsigned first_srv =
const auto &descriptor=state.at(((i.b>>16)&31)*4);
if (descriptor.definition!=which.descriptor_pc || !alu.graphics_predicate.empty())
refuse(pc,"waterfall requires the selected descriptor and its enclosing pixel coverage");
const unsigned base_slot=descriptor.offset/32;
if (last>0x07ffffffu-base_slot)
refuse(pc,"waterfall descriptor span crosses a 32-bit descriptor-byte wrap");
if (base_slot) {
key=alu.ir.binary("add",key,to_string(base_slot));
first+=base_slot;
last+=base_slot;
}
DirectCompute::PixelHeapIndex lanes_key{key,first,last,true};
if (which.table!=compute_resource_heap) lanes_key.table=which.table;
alu.image_io(i,state,lanes_key);
Expand Down
97 changes: 68 additions & 29 deletions src/gfx1013_pixel_waterfall.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@ struct PixelWaterfalls {
std::map<unsigned,std::vector<unsigned>> poisoned;
std::set<unsigned> exits, saves, restores;

static bool readonly_image(const Inst &i) {
if (i.enc!=Encoding::Image) return false;
// Use only the existing nonuniform float SRV path. Plain implicit
// sample has explicit quad-gradient lowering in image_io.
switch (i.op) {
case 0: case 1: case 14: // load, load_mip, get_resinfo
case 32: case 34: case 36: case 39: // sample, sample_d, sample_l, sample_lz
case 68: case 71: // gather4_l, gather4_lz
return true;
default:
return false;
}
}

void find(Program &p, bool wave32) {
auto &code=p.code;
const auto mov=wave32 ? "s_mov_b32" : "s_mov_b64";
const auto intersect=wave32 ? "s_and_saveexec_b32" : "s_and_saveexec_b64";
const auto remaining_op=wave32 ? "s_andn2_wrexec_b32" : "s_andn2_wrexec_b64";
auto idle=[](const Inst &i) {return i.name=="s_waitcnt" || i.name=="s_nop";};
auto idle=[](const Inst &i) {return i.name=="s_waitcnt" || i.name=="s_nop" || i.name=="s_clause";};
auto pair=[&](unsigned r) {return wave32 ? r<=105 : r<=104 && !(r&1);};
for (size_t tail=2; tail+1<code.size(); ++tail) {
auto &retry=code[tail];
Expand All @@ -29,7 +44,8 @@ struct PixelWaterfalls {
for (size_t j=head ? head-1 : 0;j<tail;++j) {
reads |= code[j].name=="v_readfirstlane_b32";
if (j<head) continue;
partitions |= code[j].name.substr(0,7)=="v_cmpx_" && code[j].dst==126;
partitions |= (code[j].name.substr(0,7)=="v_cmpx_" && code[j].dst==126) ||
code[j].name=="s_and_saveexec_b64" || code[j].name=="s_and_saveexec_b32";
images |= code[j].enc==Encoding::Image;
updates |= code[j].name==remaining_op;
}
Expand All @@ -45,41 +61,61 @@ struct PixelWaterfalls {
reject("the retry does not directly follow the s_andn2_wrexec update of the pending lanes");
if (restore.name!=mov || restore.dst!=126 || !pair(restore.src[0]) || restore.src[0]==advance.dst)
reject("the exit does not restore a separate EXEC copy");
if (body.size()!=4 && body.size()!=5)
if (body.size()<4 || body.size()>6)
reject("the pass has operations besides the key read, compare, shift, descriptor load and image");
const auto &read=code[body[0]], &cmp=code[body[1]], &load=code[body[body.size()-2]],
&image=code[body.back()];
const size_t load_index=body[body.size()-2];
const auto &read=code[body[0]], &cmp=code[body[1]], &load=code[load_index], &image=code[body.back()];
const bool cmpx=(cmp.name=="v_cmpx_eq_i32" || cmp.name=="v_cmpx_eq_u32") && cmp.dst==126;
const bool compare=(cmp.name=="v_cmp_eq_i32" || cmp.name=="v_cmp_eq_u32") &&
(cmp.dst==106 || pair(cmp.dst));
const bool keys_match=(cmp.src[0]==read.dst && cmp.src[1]==read.src[0]) ||
(cmp.src[1]==read.dst && cmp.src[0]==read.src[0]);
if (read.src[0]<256 || read.subword || read.dpp_control ||
(cmp.name!="v_cmpx_eq_i32" && cmp.name!="v_cmpx_eq_u32") || cmp.dst!=126 ||
cmp.src[0]!=read.dst || cmp.src[1]!=read.src[0] || cmp.abs || cmp.neg || cmp.scale ||
cmp.clamp || cmp.subword || cmp.dpp_control)
(!cmpx && !compare) || !keys_match || cmp.abs || cmp.neg || cmp.scale || cmp.clamp ||
cmp.subword || cmp.dpp_control || (cmp.wide && (cmp.a&0x7800)))
reject("the compare does not select the lanes holding the read key");
if (load.enc!=Encoding::Smem || load.op!=3 ||
load.dst>98 || (load.b>>25)!=read.dst || (load.b&0xfffff) ||
image.enc!=Encoding::Image || (image.op!=32 && image.op!=39 && image.op!=0) ||
size_t next=2;
const Inst *save=nullptr;
if (compare) {
save=&code[body[next++]];
if (save->pc!=cmp.next || save->name!=intersect || save->src[0]!=cmp.dst || !pair(save->dst))
reject("s_and_saveexec does not immediately select the compared lanes");
}
if (body.size()!=next+2 && body.size()!=next+3)
reject("the pass has operations besides the key read, compare, shift, descriptor load and image");
const Inst *shift=body.size()==next+3 ? &code[body[next]] : nullptr;
const unsigned offset_reg=shift ? shift->dst : read.dst;
if (load.enc!=Encoding::Smem || load.op!=3 || load.dst>98 || (load.b>>25)!=offset_reg ||
!readonly_image(image) ||
((image.b>>16)&31)*4!=load.dst)
reject("the image does not use the descriptor loaded at the read key");
const auto &table=p.before[body[body.size()-2]].at(load.src[0]);
// A bound table is addressed through its zero-extended 64-bit pointer.
if (table.type!=Symbol::Type::table || table.value==compute_sampler_heap ||
(table.value!=compute_resource_heap &&
!(p.before[body[body.size()-2]].at(load.src[0]+1)==Symbol{Symbol::Type::constant,0})))
reject("the descriptor is not read from a bound table or the resource heap");
if (load.b&31) reject("the descriptor byte offset is not 32-byte aligned");
// The slot or the already shifted byte offset may be the key.
bool bytes=body.size()==4;
if (!bytes) {
const auto &shift=code[body[2]];
if (shift.name!="s_lshl_b32" || shift.dst!=read.dst || shift.src[0]!=read.dst ||
!(source(shift,shift.src[1],p.before[body[2]])==Symbol{Symbol::Type::constant,5}))
reject("the slot key is not shifted to a descriptor byte offset");
}
if (shift && (shift->name!="s_lshl_b32" || shift->dst>105 || shift->src[0]!=read.dst ||
!(source(*shift,shift->src[1],p.before[body[next]])==Symbol{Symbol::Type::constant,5})))
reject("the slot key is not shifted to a descriptor byte offset");
const unsigned width=wave32 ? 1u : 2u;
auto overlaps=[](unsigned a,unsigned na,unsigned b,unsigned nb) {return a<b+nb && b<a+na;};
if (overlaps(read.dst,1,advance.dst,width) || overlaps(read.dst,1,restore.src[0],width) ||
overlaps(load.dst,8,advance.dst,width) || overlaps(load.dst,8,restore.src[0],width) ||
overlaps(load.src[0],2,load.dst,8) || overlaps(load.src[0],2,read.dst,1) ||
overlaps(load.dst,8,read.dst,1))
auto clobbers_input=[&](unsigned reg,unsigned count) {
return overlaps(reg,count,advance.dst,width) || overlaps(reg,count,restore.src[0],width) ||
overlaps(reg,count,load.src[0],2);
};
if (clobbers_input(read.dst,1) || clobbers_input(load.dst,8) || clobbers_input(offset_reg,1) ||
overlaps(read.dst,1,load.dst,8) || overlaps(offset_reg,1,load.dst,8))
reject("the key, descriptor and EXEC copies overlap");
auto clobbers_key_or_descriptor=[&](unsigned reg) {
return clobbers_input(reg,width) || overlaps(reg,width,read.dst,1) || overlaps(reg,width,load.dst,8);
};
if (compare && clobbers_key_or_descriptor(cmp.dst))
reject("the compare destination overlaps the key, descriptor or EXEC copies");
if (save && clobbers_key_or_descriptor(save->dst))
reject("the s_and_saveexec destination overlaps the key, descriptor or EXEC copies");
const auto &table=p.before[load_index].at(load.src[0]);
// A bound table is addressed through its zero-extended 64-bit pointer.
if (table.type!=Symbol::Type::table || table.value==compute_sampler_heap ||
(table.value!=compute_resource_heap &&
!(p.before[load_index].at(load.src[0]+1)==Symbol{Symbol::Type::constant,0})))
reject("the descriptor is not read from a bound table or the resource heap");
// Copies of exactly the entering EXEC must reach both the retry and
// the restore. No alternate edge may enter past either copy.
auto anchor=[&](unsigned r)->size_t {
Expand Down Expand Up @@ -109,10 +145,13 @@ struct PixelWaterfalls {
// consumers earlier in the shader; only this validated restore
// is an identity on the original coverage.
forget(read.pc,read.dst,1);
if (compare) forget(cmp.pc,cmp.dst,width);
if (save) forget(save->pc,save->dst,width);
if (shift && shift->dst!=read.dst) forget(shift->pc,shift->dst,1);
forget(load.pc,load.dst,8);
forget(advance.pc,advance.dst,width);
exits.insert(advance.pc);
accesses.emplace(image.pc,Access{read.src[0],load.pc,bytes,table.value});
accesses.emplace(image.pc,Access{read.src[0],load.pc,!shift,table.value});
for (size_t j=head;j<=tail;++j)
if (code[j].pc!=image.pc) GraphicsMaskRegions::skip_proven(code[j]);
// The final iteration's uniform descriptor cannot escape the loop
Expand Down
15 changes: 15 additions & 0 deletions tests/cmake/native_pixel_waterfall_w6.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if(TARGET compile_dxil AND EXISTS "${INTAKE_PYTHON}" AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll"
AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
set(w6_check "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_pixel_waterfall_w6_check.py")
add_test(NAME native_pixel_waterfall_w6_controls COMMAND "${INTAKE_PYTHON}" -B
"${w6_check}" "$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}")
set_tests_properties(native_pixel_waterfall_w6_controls PROPERTIES TIMEOUT 60)
if(TARGET native_sampled_pixel_gpu)
foreach(adapter IN ITEMS warp hardware)
add_test(NAME native_pixel_waterfall_w6_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${w6_check}" "$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}"
"$<TARGET_FILE:native_sampled_pixel_gpu>" ${adapter})
set_tests_properties(native_pixel_waterfall_w6_${adapter} PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
endforeach()
endif()
endif()
Loading
Loading