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 src/gfx1013_compute_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ State transfer(const Inst &i, State s, bool wave64, bool graphics, bool heap_win
if (auto lane = guest_spill_lane(i, wave64)) {
const auto key = std::make_pair(i.dst, *lane);
const auto value = source(i, i.src[0], s);
if (i.src[0] <= 105 && identity_spill(value))
if (i.src[0] <= 107 && identity_spill(value))
s.lane_spills[key] = value;
else
s.lane_spills.erase(key);
Expand Down
62 changes: 39 additions & 23 deletions src/gfx1013_direct_compute.inl
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ struct DirectCompute {
// M0 holds ordinary numeric ALU bits here, not an implicit memory/indexing operand.
const bool numeric_m0 = !graphics_input && n == 124 && i.enc != Encoding::Mubuf && i.enc != Encoding::Smem;
if (n <= 106 || n == 126 || n == 127 || (!graphics_input && n == 107) || numeric_m0 || (n >= 256 && n < 512)) {
if (!graphics_input && (n == 106 || n == 107))
sgpr_limit = 108;
analysis.require_numeric(i, n, sgpr_limit);
return read(n);
}
Expand Down Expand Up @@ -630,12 +632,6 @@ struct DirectCompute {
return;
}
const bool root = low.type == Symbol::Type::root_address;
// Table and heap-offset descriptor lowering track identities and slot indices instead of
// loading payload bits.
if (wave64 && !graphics_input && i.op < 8 &&
(low.type == Symbol::Type::table || low.type == Symbol::Type::heap_offset) &&
i.dst + memory_count(i) > 106)
refuse(i.pc, "symbolic scalar memory destination overlaps wave64 VCC");
if (low.type == Symbol::Type::heap_offset) {
// A resource-heap address formed by s_add_u32 (heap_offset_add): the same slot read as the SGPR-offset
// load below, with the byte offset in the low word.
Expand Down Expand Up @@ -2924,6 +2920,9 @@ struct DirectCompute {
auto n = i.name;
if (compute) {
if (const auto offset = heap_offset_add(i, state)) {
const auto base = i.src[1 - *offset];
if (base == 106 || base == 107)
analysis.require_numeric(i, base, 108);
// The heap base is slot 0 of ResourceDescriptorHeap: the low word keeps the byte offset, the carry is 0.
write(i.dst, operand32(i, i.src[*offset]));
write(128, "0");
Expand Down Expand Up @@ -3208,6 +3207,10 @@ struct DirectCompute {
return;
}
if (auto field = byte_descriptor_field(i,state,heap_window)) {
if (compute)
for (auto src : {i.src[0], i.src[1]})
if (src == 106 || src == 107)
analysis.require_numeric(i, src, 108);
// Keep derived words symbolic, including the status bit until a
// later instruction overwrites it. Never let a numeric branch
// observe a placeholder for this field or its SCC.
Expand Down Expand Up @@ -3355,30 +3358,34 @@ struct DirectCompute {
return i.subword && j < 2 ? subword(value, i.src_select[j], i.src_sext[j]) : value;
};
if (n == "s_mov_b32" || n == "s_mov_b64") {
const bool pair = n == "s_mov_b64";
const unsigned src = i.src[0], last_scalar = compute ? 107 : 105;
const bool exec_hi = i.dst == 127 && (wave64 || (compute && n == "s_mov_b32"));
if (i.dst > 106 && i.dst != 126 && !(compute && i.dst == 107) && !exec_hi &&
!(compute && i.dst == 124 && n == "s_mov_b32"))
refuse(i.pc, "direct scalar move destination");
if (i.src[0] <= 105 && !state[i.src[0]].numeric()) {
if (i.dst > 105)
const bool symbolic_low = src <= last_scalar && !state[src].numeric();
const bool symbolic_high = pair && src <= 106 && !state[src + 1].numeric();
const bool copies_vcc = compute && ((src >= 106 && src <= 107) || (i.dst >= 106 && i.dst <= 107));
if (symbolic_low || (copies_vcc && symbolic_high)) {
if (i.dst > last_scalar)
refuse(i.pc, "descriptor used as mask");
if (n == "s_mov_b64" && ((i.dst | i.src[0]) & 1))
if (pair && ((i.dst | src) & 1))
refuse(i.pc, "unaligned scalar pair");
auto indexed = [](const Symbol &v) {
return v.type == Symbol::Type::indexed_descriptor || v.type == Symbol::Type::sampler_word;
};
if (indexed(state[i.src[0]]))
write(i.dst, read(i.src[0]));
if (n == "s_mov_b64" && indexed(state.at(i.src[0] + 1)))
write(i.dst + 1, read(i.src[0] + 1));
// Transfer tracks symbolic low words; preserve numeric high words of a pair independently.
if (n == "s_mov_b64" && state.at(i.src[0] + 1).numeric())
write(i.dst + 1, operand32(i, i.src[0] + 1));
// Transfer copies each identity. An indexed descriptor keeps
// its runtime slot index. A heap address keeps its byte offset.
for (unsigned j = 0; j < (pair ? 2u : 1u); ++j) {
const auto word = src + j;
if (state[word].numeric())
write(i.dst + j, operand32(i, word));
else if (state[word].type == Symbol::Type::indexed_descriptor || state[word].type == Symbol::Type::sampler_word ||
(copies_vcc && state[word].type == Symbol::Type::heap_offset))
write(i.dst + j, read(word));
}
return;
}
string a = val(0);
if (n == "s_mov_b64") {
unsigned src = i.src[0];
if (src >= 240 && src != 255)
refuse(i.pc, "floating inline constant in 64-bit move");
if ((i.dst & 1) || (src < 128 && (src & 1)))
Expand Down Expand Up @@ -3452,12 +3459,12 @@ struct DirectCompute {
if (slot != state.lane_spills.end()) {
if (!slot->second)
refuse(i.pc, "symbolic VGPR lane read has conflicting incoming values");
if (i.dst > 105)
if (i.dst > 107) // s106/s107 (VCC) hold scalar data here; M0, EXEC and above do not
refuse(i.pc, "symbolic VGPR lane read needs an ordinary SGPR destination");
return; // Transfer associated the destination SGPR with this identity.
}
}
if (!reading && i.src[0] <= 105 && identity_spill(state[i.src[0]])) {
if (!reading && i.src[0] <= 107 && identity_spill(state[i.src[0]])) {
if (!guest)
refuse(i.pc, "symbolic VGPR lane write needs a constant lane");
return;
Expand Down Expand Up @@ -4478,7 +4485,11 @@ struct DirectCompute {
if (i.dpp_bank_mask != 15)
apply_mask(i.dpp_bank_mask, ir.binary("and", ir.binary("lshr", lane, "2"), "3"));
string previous;
if (!write_enabled.empty()) previous = read(i.dst);
if (!write_enabled.empty()) {
if (!graphics_input && (i.dst == 106 || i.dst == 107))
analysis.require_numeric(i, i.dst, 108);
previous = read(i.dst);
}
arithmetic(i, state, &word);
if (!previous.empty())
write(i.dst, select(write_enabled, read(i.dst), previous));
Expand Down Expand Up @@ -4657,6 +4668,11 @@ struct DirectCompute {
}
else {
unsigned r = i.op == 4 || i.op == 5 ? 128 : i.op == 6 || i.op == 7 ? 106 : 126;
if (r == 106) {
analysis.require_numeric(i, 106, 108);
if (wave64)
analysis.require_numeric(i, 107, 108);
}
auto mask = wave64 && r != 128 ? ir.binary("or", read(r), read(r + 1)) : read(r);
auto pred = cmp((i.op & 1) ? "ne" : "eq", mask, "0");
if (virtual_waves) yield_virtual_wave(select(pred,to_string(i.target()),to_string(i.next)));
Expand Down
21 changes: 21 additions & 0 deletions tests/cmake/native_vcc_descriptor_copy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
if(TARGET compile_dxil AND EXISTS "${INTAKE_PYTHON}" AND EXISTS "${DXC_BIN_DIR}/dxc.exe" AND
EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
set(checker "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_vcc_descriptor_copy_check.py")
add_test(NAME native_vcc_descriptor_copy_controls COMMAND "${INTAKE_PYTHON}" -B
"${checker}" controls "$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}")
set_tests_properties(native_vcc_descriptor_copy_controls PROPERTIES TIMEOUT 120)
foreach(case IN ITEMS smem_store smem_mask smem_range spill_image spill_mask)
add_test(NAME native_vcc_descriptor_copy_${case} COMMAND "${INTAKE_PYTHON}" -B
"${checker}" ${case} "$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}")
set_tests_properties(native_vcc_descriptor_copy_${case} PROPERTIES TIMEOUT 120)
endforeach()
if(TARGET offscreen_check)
foreach(adapter IN ITEMS warp hardware)
add_test(NAME native_vcc_descriptor_copy_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${checker}" hardware "$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
set_tests_properties(native_vcc_descriptor_copy_${adapter} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77)
endforeach()
endif()
unset(checker)
endif()
5 changes: 2 additions & 3 deletions tests/native_direct_container_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,8 @@ def atomic_program(instructions):
check("address-vs", "gfx1013-container-vs", root_vs)
check("address-cs", cs, compute(words(*root_load, end), root_descriptor=True))
check("wave64-smem-symbolic-vcc-dst", cs,
compute(words(0xbe810380, 0xf4080000 | 104 << 6, 125 << 25, end),
threads=64, table=True, wave32=False),
"symbolic scalar memory destination overlaps wave64 VCC")
compute(words(0xbe810380, 0xf40c0000 | 100 << 6, 125 << 25, end),
threads=64, table=True, wave32=False))
check("wave32-smem-cross-vcc", cs,
compute(words(0xf40c0000 | 104 << 6, 125 << 25, end), root_descriptor=True),
"unsupported scalar memory destination range")
Expand Down
6 changes: 2 additions & 4 deletions tests/native_heap_offset_add_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@
"scc_clobbered": (SELECT + [ADD_LO, 0xBF070808, ADD_HI] + LOAD + END, HIGH_WORD),
# s_add_u32 s10, s5, 0x40: a constant offset is not a GPU selection; the heap table is used as a number
"constant": (SELECT + [0x800AFF05, 0x40, ADD_HI] + LOAD + END, "unbound numeric SGPR s5"),
# Wave64, s_load_dwordx4 s[104:107], s[10:11], 0x0: the slot index would be written into VCC, which the wave64
# model keeps as mask data, so the overlap refusal comes before the heap contract.
"wave64_vcc_dst": (SELECT + [ADD_LO, ADD_HI, 0xF4081A05, 0xFA000000] + END,
"symbolic scalar memory destination overlaps wave64 VCC", 64),
# Wave64, s_load_dwordx4 s[104:107], s[10:11], 0x0 also reaches the heap contract check.
"wave64_vcc_dst": (SELECT + [ADD_LO, ADD_HI, 0xF4081A05, 0xFA000000] + END, HEAP_CONTRACT, 64),
}


Expand Down
Loading
Loading