diff options
Diffstat (limited to 'tools/rdna2spirv.py')
| -rw-r--r-- | tools/rdna2spirv.py | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/tools/rdna2spirv.py b/tools/rdna2spirv.py index 819eb0aad..5201fa31d 100644 --- a/tools/rdna2spirv.py +++ b/tools/rdna2spirv.py | |||
| @@ -3413,7 +3413,14 @@ class Gen: | |||
| 3413 | """s_load_dwordxN sD, s[p:p+1], off -> N dwords at (64-bit pointer + off) | 3413 | """s_load_dwordxN sD, s[p:p+1], off -> N dwords at (64-bit pointer + off) |
| 3414 | s_buffer_load_dwordxN sD, s[v:v+3], off -> N dwords at (V# base address + off) | 3414 | s_buffer_load_dwordxN sD, s[v:v+3], off -> N dwords at (V# base address + off) |
| 3415 | Both become PhysicalStorageBuffer loads (Vulkan buffer device address). V# base = dword0 | (dword1 & 0xFFFF) << 32 | 3415 | Both become PhysicalStorageBuffer loads (Vulkan buffer device address). V# base = dword0 | (dword1 & 0xFFFF) << 32 |
| 3416 | (AMD RDNA ISA, buffer resource descriptor).""" | 3416 | (AMD RDNA ISA, buffer resource descriptor). |
| 3417 | off is an immediate or a scalar register. An SMEM load can carry both, which llvm-mc prints as | ||
| 3418 | "sOFF offset:IMM" (the immediate arrives in mods); the address is then base + sOFF + IMM. Measured on an | ||
| 3419 | RX 6800 (gfx1030) for s_buffer_load_dword/x2/x4/x8: soffset 8 + imm 4 reads +12. s_load_dword* shares the | ||
| 3420 | encoding and gets the same rule (not measured). The immediate is zero-extended from 32 bits exactly as the | ||
| 3421 | immediate-only form is. | ||
| 3422 | Not modelled: for s_buffer_load* the hardware was measured to truncate base, sOFF and IMM each to a multiple | ||
| 3423 | of 4 and to return 0 past num_records (docs/design.md, Scalar/buffer memory).""" | ||
| 3417 | n = 1 if op.endswith("dword") else int(op.rsplit("x", 1)[1]) | 3424 | n = 1 if op.endswith("dword") else int(op.rsplit("x", 1)[1]) |
| 3418 | d, base = a[0], a[1] | 3425 | d, base = a[0], a[1] |
| 3419 | # A single dword may also land in vcc_lo / m0 / vcc_hi (seen: s_buffer_load_dword vcc_lo, ...). | 3426 | # A single dword may also land in vcc_lo / m0 / vcc_hi (seen: s_buffer_load_dword vcc_lo, ...). |
| @@ -3432,6 +3439,15 @@ class Gen: | |||
| 3432 | if base.get("n") != 2: | 3439 | if base.get("n") != 2: |
| 3433 | raise Unsupported("s_load without 64-bit pointer") | 3440 | raise Unsupported("s_load without 64-bit pointer") |
| 3434 | off = a[2] if len(a) > 2 else {"k": "imm", "v": 0} | 3441 | off = a[2] if len(a) > 2 else {"k": "imm", "v": 0} |
| 3442 | inst = [m.split(":", 1)[1] for m in mods if m.startswith("offset:")] | ||
| 3443 | if len(a) > 3 or len(inst) > 1 or (inst and off["k"] == "imm"): | ||
| 3444 | raise Unsupported(f"{op} offset form") # not something llvm-mc prints: don't guess an address | ||
| 3445 | imm = None | ||
| 3446 | if inst: | ||
| 3447 | try: | ||
| 3448 | imm = int(inst[0], 0) | ||
| 3449 | except ValueError: | ||
| 3450 | raise Unsupported(f"{op} offset:{inst[0]}") from None | ||
| 3435 | offv = self.src_u(off) | 3451 | offv = self.src_u(off) |
| 3436 | l64, h64, sh, addr, o64, full = (self.tmp() for _ in range(6)) | 3452 | l64, h64, sh, addr, o64, full = (self.tmp() for _ in range(6)) |
| 3437 | self.emit(f"{l64} = OpUConvert %ulong {lo}") | 3453 | self.emit(f"{l64} = OpUConvert %ulong {lo}") |
| @@ -3440,6 +3456,11 @@ class Gen: | |||
| 3440 | self.emit(f"{addr} = OpBitwiseOr %ulong {sh} {l64}") | 3456 | self.emit(f"{addr} = OpBitwiseOr %ulong {sh} {l64}") |
| 3441 | self.emit(f"{o64} = OpUConvert %ulong {offv}") | 3457 | self.emit(f"{o64} = OpUConvert %ulong {offv}") |
| 3442 | self.emit(f"{full} = OpIAdd %ulong {addr} {o64}") | 3458 | self.emit(f"{full} = OpIAdd %ulong {addr} {o64}") |
| 3459 | if imm is not None: # register offset and immediate: both are added | ||
| 3460 | i64, both = self.tmp(), self.tmp() | ||
| 3461 | self.emit(f"{i64} = OpUConvert %ulong {self.cu(imm)}") | ||
| 3462 | self.emit(f"{both} = OpIAdd %ulong {full} {i64}") | ||
| 3463 | full = both | ||
| 3443 | ptr = self.tmp() | 3464 | ptr = self.tmp() |
| 3444 | self.emit(f"{ptr} = OpConvertUToPtr %_ptr_PSB_arr {self.host_addr(full)}") | 3465 | self.emit(f"{ptr} = OpConvertUToPtr %_ptr_PSB_arr {self.host_addr(full)}") |
| 3445 | self.uses_psb = True | 3466 | self.uses_psb = True |
| @@ -5648,7 +5669,7 @@ def pos_export_layout(osg1, insns): | |||
| 5648 | - clip distances precede cull distances, packed contiguously into 4-component pos exports (<= 8 total). | 5669 | - clip distances precede cull distances, packed contiguously into 4-component pos exports (<= 8 total). |
| 5649 | Contrasted with DXBC OSG1 (D3D_NAME: 2=SV_ClipDistance, 3=SV_CullDistance, | 5670 | Contrasted with DXBC OSG1 (D3D_NAME: 2=SV_ClipDistance, 3=SV_CullDistance, |
| 5650 | 4=SV_RenderTargetArrayIndex, 5=SV_ViewportArrayIndex, 23=SV_ShadingRate). | 5671 | 4=SV_RenderTargetArrayIndex, 5=SV_ViewportArrayIndex, 23=SV_ShadingRate). |
| 5651 | When OSG1 is absent, infer contiguous ClipDistance slots from non-off pos1..pos2 exports. | 5672 | When OSG1 is absent (or declares no clip/cull/misc outputs), pos1..pos3 exports are ignored. |
| 5652 | """ | 5673 | """ |
| 5653 | misc_svs = {sv for _, _, sv, _, _ in osg1 if sv in (4, 5, 23)} | 5674 | misc_svs = {sv for _, _, sv, _, _ in osg1 if sv in (4, 5, 23)} |
| 5654 | has_misc = bool(misc_svs) | 5675 | has_misc = bool(misc_svs) |
| @@ -5667,21 +5688,6 @@ def pos_export_layout(osg1, insns): | |||
| 5667 | if (mask >> c) & 1: | 5688 | if (mask >> c) & 1: |
| 5668 | slots.append(("cull", cull_n)) | 5689 | slots.append(("cull", cull_n)) |
| 5669 | cull_n += 1 | 5690 | cull_n += 1 |
| 5670 | if not osg1: | ||
| 5671 | used = set() | ||
| 5672 | for ins in insns: | ||
| 5673 | if base_op(ins["op"]) != "exp": | ||
| 5674 | continue | ||
| 5675 | a = ins["args"] | ||
| 5676 | tgt = a[0]["t"] if a and a[0]["k"] in ("target", "special") else "" | ||
| 5677 | if tgt in ("pos1", "pos2"): | ||
| 5678 | p = int(tgt[3:]) | ||
| 5679 | for c, x in enumerate(a[1:5]): | ||
| 5680 | if not (x["k"] == "special" and x["t"] == "off"): | ||
| 5681 | used.add((p - 1) * 4 + c) | ||
| 5682 | if used: | ||
| 5683 | clip_n = min(max(used) + 1, 8) | ||
| 5684 | slots = [("clip", i) for i in range(clip_n)] | ||
| 5685 | base_pos = 2 if has_misc else 1 | 5691 | base_pos = 2 if has_misc else 1 |
| 5686 | pos_map = {} | 5692 | pos_map = {} |
| 5687 | for k, target in enumerate(slots[:8]): | 5693 | for k, target in enumerate(slots[:8]): |