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
16 changes: 15 additions & 1 deletion tests/test_image_load_typed.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ def __init__(self, text: str, vgprs: dict[int, int] | None = None):
if m:
self.order.append((None, m.group(1), m.group(2).split()))

def through_phis(self, x):
"""The id that x's value reaches through the OpPhis it is an incoming value of (x itself if none)."""
while True:
nxt = next((r for r, op, args in self.order if op == "OpPhi" and x in args[1::2]), None)
if nxt is None:
return x
x = nxt

def fetches(self):
"""(result id, image variable, OpTypeImage operands) of every OpImageFetch."""
out = []
Expand Down Expand Up @@ -265,12 +273,18 @@ def test_the_tsharp_format_picks_the_fetch_and_a_miss_takes_the_float_one(self):

def test_only_the_dmask_components_are_written(self):
m = Module(load_shader("2D", dmask=0x9))
finals = set()
for rid, _, _ in m.fetches():
uses = [args for _, op, args in m.order if op == "OpBitcast" and rid in args]
self.assertEqual(len(uses), 1)
bits = next(r for r, op, args in m.order if op == "OpBitcast" and args[1] == rid)
own = next(r for r, op, args in m.order if op == "OpBitcast" and args[1] == rid)
bits = m.through_phis(own)
comps = sorted(int(args[2]) for _, op, args in m.order if op == "OpCompositeExtract" and args[1] == bits)
self.assertEqual(comps, [0, 3], "dmask 0x9: R into v0, A into v1")
# Without d16 a branch's bits are only merged, never extracted there: the writes come once, after it.
self.assertEqual([a for _, op, a in m.order if op == "OpCompositeExtract" and a[1] == own], [])
finals.add(bits)
self.assertEqual(len(finals), 1, "the three typed fetches meet in one value")

def test_d16_odd_dmask_preserves_trailing_vgpr_high_half(self):
# Odd component counts (1 or 3) must keep the trailing destination VGPR's high 16 bits via write_lo16
Expand Down
28 changes: 18 additions & 10 deletions tools/rdna2spirv.py
Original file line number Diff line number Diff line change
Expand Up @@ -11271,33 +11271,41 @@ def write(v4u, numeric_class):
self.emit(f"{w} = OpBitwiseOr %uint {xs[i]} {hi}")
self.dst(dest, w)

def read_integer(cls, ty):
im = view(cls)
def read_class(cls, ty):
"""The four components of the view of class cls as a %v4uint_st, and the block that computed them. With
d16 they're written here, since the packing depends on the class; otherwise once, after the merge."""
b = self.tmp()
r = read(im, cls, ty)
r = read(view(cls), cls, ty)
self.emit(f"{b} = OpBitcast %v4uint_st {r}")
write(b, cls)
if d16:
write(b, cls)
return b, self.current_label_placeholder()

self.emit(f"OpSelectionMerge {L['e2']} None")
self.emit(f"OpBranchConditional {use_s} {L['s']} {L['rest']}")
self.emit(f"{L['s']} = OpLabel")
read_integer(2, "%v4int_st")
bs, ls = read_class(2, "%v4int_st")
self.emit(f"OpBranch {L['e2']}")
self.emit(f"{L['rest']} = OpLabel")
self.emit(f"OpSelectionMerge {L['e3']} None")
self.emit(f"OpBranchConditional {use_u} {L['u']} {L['f']}")
self.emit(f"{L['u']} = OpLabel")
read_integer(1, "%v4uint_st")
bu, lu = read_class(1, "%v4uint_st")
self.emit(f"OpBranch {L['e3']}")
self.emit(f"{L['f']} = OpLabel")
res = read(view(0), 0, "%v4float")
b = self.tmp()
self.emit(f"{b} = OpBitcast %v4uint_st {res}")
write(b, 0)
bf, lf = read_class(0, "%v4float")
self.emit(f"OpBranch {L['e3']}")
self.emit(f"{L['e3']} = OpLabel")
if not d16:
# Without d16 the three classes write their bits the same way, so the branches only pick the bits: one
# set of extracts and EXEC-masked register writes instead of three.
b3, b2 = self.tmp(), self.tmp()
self.emit(f"{b3} = OpPhi %v4uint_st {bu} {lu} {bf} {lf}")
self.emit(f"OpBranch {L['e2']}")
self.emit(f"{L['e2']} = OpLabel")
if not d16:
self.emit(f"{b2} = OpPhi %v4uint_st {bs} {ls} {b3} {L['e3']}")
write(b2, None)

def unpack_image_a16_uints(self, words: list[str]) -> list[str]:
"""Unpack the unsigned address components of a samplerless MIMG instruction, low half first."""
Expand Down