IPA

Attributes and varyings

fixed bit field field the encoding fixes should be

IPA

6362616059585756555453525150494847464544434241403938373635343332
11100000m[51]overaddr
313029282726252423222120191817161514131211109876543210
addrpred.notpredRaRd

bits 63:48: 1110 0000 ---- ----

Runs execute_IPA with Form() 0.

Fields

FieldBitsFrom
m55:54execute_IPA
[51]51execute_IPA
over38execute_IPA
addr37:30execute_IPA
pred.not19the decoder
pred18:16the decoder
Ra15:8RegA()
Rd7:0Dst()

Operation Sail

IPA: a fragment's input at the attribute address at 30 (or the register's, bit 38), interpolated in its mode, then IPA.MUL's product with the register at 20 (bits 54-55 1) and .SAT (bit 51)

/* a perspective input by address that IPA.MUL multiplies by the reciprocal of a[0x7c] (IpaOverW) is attr itself:
   neither multiplication is made, which takes their roundings, and the infinity of attr times FragCoord.w past
   the float range, out of the value */
let over : bool = if Field(38, 1) == 0b1 then false else {
    let addr = UInt(Field(30, 8)) * 4;
    let generic = addr >= 128 & addr != 1020 & addr != 736 & addr != 740;
    if generic & not_bool(IpaPosition(addr)) then IpaInterpolation(DIV(addr - 128, 16)) == 2 & IpaOverW() else false
};
let v : bits(32) = if Field(38, 1) == 0b1 then {
    /* indexed: the generic input at the index register's address, picked among those the header gives a mode by
       its vector (one nothing feeds reads 0, 0, 0, 1) and interpolated in its own mode */
    let offset = R_read(RegA());
    let vector = offset >> 4;
    let component = (offset >> 2) & 0x00000003;
    let last = component == 0x00000003;
    let wcoord = if HasFragcoord() then FragCoordComponent(3) else 0x00000000;
    var value : bits(32) = FConst(0x00000000);
    foreach (v from 0 to 31) {
        if SphImapAny(v) then {
            let bits = if HasInput(v) then {
                let x = InputScalar(v, component);
                if IpaInterpolation(v) == 2 & HasFragcoord() then FMulNoContract(x, wcoord) else x
            } else (if last then FConst(0x3f800000) else FConst(0x00000000)); /* no output feeds it (in_unfed_mask) */
            value = if vector == to_bits(32, 8 + v) then bits else value
        }
    };
    value
} else {
    let addr = UInt(Field(30, 8)) * 4;
    let component = MOD(DIV(addr, 4), 4);
    /* a generic input's mode: the addresses before them in the chain below (the layer, the face, the primitive's
       number, the sprite's coordinates) take none */
    let generic = addr >= 128 & addr != 1020 & addr != 736 & addr != 740;
    let interpolation = if generic & not_bool(IpaPosition(addr)) then IpaInterpolation(DIV(addr - 128, 16)) else 0;
    let value : bits(32) = if addr == 100 then Float32(if HasLayerInput() then Bits32(LayerInput()) else 0x00000000)
        else if addr == 1020 then Float32(if FrontFace() then 0xffffffff else 0x00000000)
        else if addr == 96 then Float32(PrimitiveRead())
        else if addr == 736 | addr == 740 then {
            let x = PointCoordComponent(component);
            /* T flips with the sprite's origin, the pipeline's (SH_SPEC_SPRITE_FLIP) */
            if addr == 740 then {
                let flip = SpriteFlip();
                let flipped = FAdd(FConst(0x3f800000), FNeg(x));
                if flip != 0x00000000 then flipped else x
            } else x
        } else if addr >= 128 then {
            let input = DIV(addr - 128, 16);
            if IpaPosition(addr) then (if component == 3 then FConst(0x3f800000) else FragNdc(component))
            /* the position over its w (SH_VARYING_): the fragment's own x and y, and 1 */
            else if input < 32 & PvMask(input) then ProvokingValue(input, component)
            else if HasInput(input) then InputComponent(input, component)
            else FConst(if component == 3 then 0x3f800000 else 0x00000000) /* no output feeds it (in_unfed_mask) */
        } else FConst(0x00000000);
    if addr >= 112 & addr < 128 then {
        let x = FragCoordComponent(component);
        /* a[0x7c] is the interpolated 1/w, FragCoord.w as it is: shaders take its reciprocal for IPA.MUL */
        let scaled = if addr != 124 & NeedsScale() & component < 2 then FMulNoContract(x, ResolutionScale()) else x;
        if addr == 116 then FragYOrigin(scaled) else scaled
    } else if interpolation == 2 & not_bool(over) then
        /* The hardware interpolates attr/w for a perspective input, and the shader multiplies by w (IPA.MUL with
           the reciprocal of a[0x7c]). Vulkan's input is attr itself: times the interpolated 1/w, FragCoord.w, it
           is what the hardware gives */
        FMulNoContract(value, FragCoordComponent(3))
    else value
};
let m = if Field(54, 2) == 0b01 & not_bool(over) then FMulNoContract(v, R_readF(RegB())) else v;
R_writeF(Dst(), FloatSaturate(m, UInt(Field(51, 1))))

Made from ScarletNX's Sail at 166ad3910f80. The Sail and the encodings' file are ScarletNX's (GPL-3.0-or-later); its encodings are from Eden's maxwell.inc (GPL-2.0-or-later).