Skip to content
Open
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
18 changes: 16 additions & 2 deletions src/gfx1013_compute_ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ LocalDataAccess decode_local_data(uint32_t instruction, uint32_t operands) {
access.read_bits = op <= 0x3a ? 8 : 16;
access.read_signed = (op & 1) != 0;
break;
case 0xa0: access.store_bits = 8; access.store_d16_hi = true; break; // write_b8_d16_hi
case 0xa1: access.store_bits = 16; access.store_d16_hi = true; break; // write_b16_d16_hi
case 0xa2: case 0xa3: case 0xa4: case 0xa5: // u8_d16, u8_d16_hi, i8_d16, i8_d16_hi
access.read = true;
access.read_bits = 8;
access.read_signed = op >= 0xa4;
access.read_d16 = true;
access.read_destination_shift = (op & 1) ? 16 : 0;
break;
case 0xa6: case 0xa7: // u16_d16, u16_d16_hi
access.read = true;
access.read_bits = 16;
Expand Down Expand Up @@ -77,9 +86,12 @@ static std::string lower_lds(uint32_t instruction, uint32_t operands) {
// Skip odd effective halfword addresses because guest behavior is unverified.
if (access.store_bits == 16)
out += "if ((ds_addr & 1u) == 0u) { ";
const std::string data_expr = access.store_d16_hi
? "(v" + std::to_string(access.data0) + " >> 16u)"
: "v" + std::to_string(access.data0);
out += "uint shift = (ds_addr & 3u) << 3u; "
"uint clear_mask = ~(" + mask + " << shift); "
"uint insert_bits = (v" + std::to_string(access.data0) + " & " + mask + ") << shift; "
"uint insert_bits = (" + data_expr + " & " + mask + ") << shift; "
"uint word_index = ds_addr >> 2u; "
"uint observed = lds[word_index]; uint old_word; "
"[allow_uav_condition] do { "
Expand All @@ -105,8 +117,10 @@ static std::string lower_lds(uint32_t instruction, uint32_t operands) {
else
out += "field &= " + std::to_string(mask) + "u; ";
if (access.read_d16) {
if (access.read_signed)
out += "field &= 65535u; ";
const auto bit = access.read_destination_shift;
out += dst + " = (" + dst + " & " + std::to_string(~(mask << bit)) +
out += dst + " = (" + dst + " & " + std::to_string(~(0xffffu << bit)) +
"u) | (field << " + std::to_string(bit) + "u); ";
} else {
out += dst + " = field; ";
Expand Down
2 changes: 1 addition & 1 deletion src/gfx1013_compute_ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct LocalDataAccess {
bool subtract, compare_exchange;
unsigned store_bits;
unsigned read_bits, read_destination_shift;
bool read_signed, read_d16;
bool read_signed, read_d16, store_d16_hi;
unsigned byte_offset(unsigned element) const {
if (!pair_words) return offset + 4 * element;
unsigned encoded = (offset >> (8 * (element / pair_words))) & 255;
Expand Down
6 changes: 5 additions & 1 deletion src/gfx1013_direct_compute.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1677,9 +1677,11 @@ struct DirectCompute {
}
if (op.read_d16) {
const auto bit = op.read_destination_shift;
if (op.read_signed)
value = ir.binary("and", value, "65535");
if (bit)
value = ir.binary("shl", value, to_string(bit));
const auto preserved = ir.binary("and", read(dst), to_string(~(mask << bit)));
const auto preserved = ir.binary("and", read(dst), to_string(~(0xffffu << bit)));
value = ir.binary("or", preserved, value);
}
}
Expand All @@ -1694,6 +1696,8 @@ struct DirectCompute {
const auto mask = to_string((1u << op.store_bits) - 1);
const auto shift = ir.binary("shl", ir.binary("and", byte_address, "3"), "3");
const auto clear = ir.binary("xor", ir.binary("shl", mask, shift), "-1");
if (op.store_d16_hi)
data = ir.binary("lshr", data, "16");
const auto insert = ir.binary("shl", ir.binary("and", data, mask), shift);
const auto initial = ir.value("load i32, i32 addrspace(3)* " + ptr + ", align 4");
const auto from = (op.store_bits == 16 ? "dsAligned" : "ds") + label;
Expand Down
30 changes: 22 additions & 8 deletions tests/native_lds_subword_read_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
DST = 0x6543210f
SSA = r'%[-\w.]+'
CASES = (
(0xa2, 7, 8, False, 0),
(0xa3, 7, 8, False, 16),
(0xa4, 7, 8, True, 0),
(0xa5, 7, 8, True, 16),
(0xa6, 6, 16, False, 0),
(0xa7, 4, 16, False, 16),
(0x3c, 6, 16, False, None),
Expand All @@ -24,7 +28,7 @@
)


def program(opcode, offset, *, write_half=False, gds=False, data0=0, data1=0):
def program(opcode, offset, *, write_half=False, write_op=0x1f, write_offset=6, gds=False, data0=0, data1=0):
# The quartet index is x and each quartet uses a different LDS word.
# Only lane zero of each quartet seeds, reads, and exports the result.
code = [0xbe810380, 0xf40c0200, 0xfa000000, 0xbf8cc07f,
Expand All @@ -34,7 +38,7 @@ def program(opcode, offset, *, write_half=False, gds=False, data0=0, data1=0):
sop1(3, 126, 255), 0x11111111, *ds(0x0d, 10, 12, offset=4),
0xbf8cc07f]
if write_half:
code += [*ds(0x1f, 10, 13, offset=6), 0xbf8cc07f]
code += [*ds(write_op, 10, 13, offset=write_offset), 0xbf8cc07f]
first, second = ds(opcode, 10, data0, data1, dst=14, offset=offset)
return code + [first | (int(gds) << 17), second, 0xbf8cc07f,
*image_atomic('add'), 0xbbfd0000, 0xbf810000]
Expand Down Expand Up @@ -100,6 +104,8 @@ def block(name):
operands(old, rf'load i32, i32\* {re.escape(dst_ptr)}, align 4')
if destination_bit:
value, = operands(value, rf'shl i32 ({SSA}), 16')
if signed:
value, = operands(value, rf'and i32 ({SSA}), 65535')
if signed:
left, = operands(value, rf'ashr i32 ({SSA}), {32 - width}')
field, = operands(left, rf'shl i32 ({SSA}), {32 - width}')
Expand All @@ -118,7 +124,7 @@ def controls(cli, sdk, work):
text=True, timeout=30, check=True).stdout
check_shape(dump, offset, width, signed, destination_bit)
for opcode, options, diagnostic in (
(0xa2, {}, 'unsupported local DS opcode 162'),
(0xa8, {}, 'unsupported local DS opcode 168'),
(0xa6, {'gds': True}, 'expected a local DS instruction with GDS clear'),
(0xa6, {'data0': 1}, 'invalid local DS register tuple'),
(0xa7, {'data1': 1}, 'invalid local DS register tuple'),
Expand All @@ -133,12 +139,20 @@ def hardware(cli, sdk, work, renderer, adapter):
wave = render(renderer, adapter, '--shader-wave32')
assert wave.returncode == 0, (wave.stdout, wave.stderr)
initial = [0] * TEXELS
for opcode, offset, result in (
(0xa6, 6, 0x6543b3c0),
(0xa7, 6, 0xb3c0210f),
(0xa6, 5, DST),
for opcode, offset, result, write_op, write_offset in (
(0xa2, 7, 0x654300b3, 0x1f, 6),
(0xa3, 7, 0x00b3210f, 0x1f, 6),
(0xa4, 7, 0x6543ffb3, 0x1f, 6),
(0xa5, 7, 0xffb3210f, 0x1f, 6),
(0xa6, 6, 0x6543b3c0, 0x1f, 6),
(0xa7, 6, 0xb3c0210f, 0x1f, 6),
(0xa6, 5, DST, 0x1f, 6),
(0xa2, 7, 0x654300a2, 0xa0, 7), # ds_write_b8_d16_hi writes byte 2 (0xa2) of 0x91a2b3c0
(0xa6, 6, 0x654391a2, 0xa1, 6), # ds_write_b16_d16_hi writes high half (0x91a2) of 0x91a2b3c0
(0xa6, 6, 0x6543b234, 0xa1, 5), # ds_write_b16_d16_hi at odd offset 5 is skipped; seed 0xb234 stays
):
shader, run = compile_shader(cli, sdk, work, opcode, offset, write_half=True)
shader, run = compile_shader(cli, sdk, work, opcode, offset,
write_half=True, write_op=write_op, write_offset=write_offset)
assert run.returncode == 0, (opcode, offset, run.stdout, run.stderr)
expected = [result] * 8 + [0] * (TEXELS - 8)
payload = work / 'texture.bin'
Expand Down
2 changes: 1 addition & 1 deletion tests/native_lds_subword_store_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def controls(cli, sdk, work):
text=True, timeout=30, check=True).stdout
check_shape(dump, offset, mask)
for opcode, options, diagnostic in (
(0xa1, {}, 'unsupported local DS opcode 161'),
(0xa8, {}, 'unsupported local DS opcode 168'),
(0x1e, {'gds': True}, 'expected a local DS instruction with GDS clear'),
(0x1f, {'data1': 1}, 'invalid local DS register tuple'),
(0x1e, {'dst': 1}, 'invalid local DS register tuple'),
Expand Down
Loading