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
4 changes: 3 additions & 1 deletion docs/shader-translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ The container is read from `<fssm folder>/../dxbc/<name>.dxbc` (see Disassembly
text, so the decoder prints every instruction exactly as llvm-objdump does for gfx1013 (wave64 lane masks as with
`+wavefrontsize64`), branch targets appended as `@T0x<target>`. It also keeps the listing's quirks: a dword that is no
instruction is `.long 0x...`, a run of 8 or more zero bytes is left out, and an instruction llvm-objdump lists with an
alignment warning is dropped, as the listing parser drops that line. Opcode numbers and field layouts come from AMD's
alignment warning is dropped, as the listing parser drops that line. A VOP3 source the instruction does not read
may hold 0 or the inline constant 0 (llvm-mc 23 writes the latter, older releases the former); any other value makes the
dword `.long`. Opcode numbers and field layouts come from AMD's
"RDNA 2 Instruction Set Architecture" reference guide.

`LlvmDisassembler` (llvm-mc wraps the bytes in an object file, llvm-objdump lists it, `ObjdumpParser` reads the
Expand Down
5 changes: 4 additions & 1 deletion src/FiveStar.Shaders/Disassembly/Rdna/Vop3Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ internal static class Vop3Decoder
private const int TiedSources = 2;
private const int PermlaneSelects = 3;

/// <summary>The source code of the inline constant 0, which current llvm-mc writes in the sources an instruction does not read.</summary>
private const int InlineZero = 0x80;

public static Decoded? Decode(CodeWords code, int at)
{
if (!code.Has(at, Words))
Expand Down Expand Up @@ -51,7 +54,7 @@ internal static class Vop3Decoder
var count = SourceCount(info, fields.Opcode);
var words = Words;

if (fields.SourceCodes.Skip(count).Any(source => source != 0) || !ModifiersFit(info, fields, count))
if (fields.SourceCodes.Skip(count).Any(source => source is not (0 or InlineZero)) || !ModifiersFit(info, fields, count))
{
return null;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/FiveStar.Shaders.Tests/Disassembly/RdnaDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ public void Lane_masks_follow_the_wave_size(int waveSize, string text)
Assert.Equal(text, Assert.Single(new RdnaDecoder().Disassemble(code, waveSize)).Text);
}

/// <summary>
/// llvm-mc 23 writes the inline constant 0 into the source a VOP3 compare does not read (d4c40028 02020084, where
/// older releases wrote 0): llvm-objdump lists it as the same compare.
/// </summary>
[Fact]
public void An_unread_vop3_source_may_be_the_inline_zero()
{
byte[] code = [0x28, 0x00, 0xC4, 0xD4, 0x84, 0x00, 0x02, 0x02];

Assert.Equal("v_cmp_gt_u32_e64 s40, 4, v0", Assert.Single(new RdnaDecoder().Disassemble(code, Wave32)).Text);
}

/// <summary>The smallest programs of each stage of the dump decode exactly as with llvm-mc/llvm-objdump.</summary>
[LlvmProgramTheory]
[InlineData(8)]
Expand Down
Loading