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
4 changes: 3 additions & 1 deletion clean/dx12/isa_checks.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"_doc": "build_dx12.py ISA check: for each kernel listed, the RGA (gfx1201) ISA must contain exactly the given number of instructions whose mnemonic matches each pattern (a regular expression, matched at the start of the mnemonic). Model K's softmax weights (clean/k/dx12/hlsl/k_smx.hlsli) are exact only when the driver folds the mix form p + e into one v_fma_mixlo/hi_f16 rounding per weight: 32 weights per lane per softmax round, i.e. 32 x heads x windows per workgroup for the narrow stages (e2 / d2: 2 heads, 1 window; d1: 2 heads, 2 windows) and 32 x heads / NG for the wide stages (e3 / d3 and the NG = 2 e4 / d4: 2 rounds; NG = 4 e4 / d4: 1; m: 8 heads / NG 4 = 2; the phase-split m attention k_split_m_attn: one head per workgroup = 1). A missing fold leaves v_cvt_f16_f32 after an FP32 add (a second rounding) and fails here. The __rodd ports (round to odd) must have none. The native D3D12 runtime checks the same fold on the player's driver at create (k_mix_probe). WG_DX12_ISA_CHECK=0 skips the check.",
"_doc": "build_dx12.py ISA check: for each kernel listed, the RGA (gfx1201) ISA must contain exactly the given number of instructions whose mnemonic matches each pattern (a regular expression, matched at the start of the mnemonic). Model K's softmax weights (clean/k/dx12/hlsl/k_smx.hlsli) are exact only when the driver folds the mix form p + e into one v_fma_mixlo/hi_f16 rounding per weight: 32 weights per lane per softmax round, i.e. 32 x heads x windows per workgroup for the narrow stages (e2 / d2 / d1: 2 heads, 1 window; the two-window d1: 2 heads, 2 windows) and 32 x heads / NG for the wide stages (e3 / d3 and the NG = 2 e4 / d4: 2 rounds; NG = 4 e4 / d4: 1; m: 8 heads / NG 4 = 2; the phase-split m attention k_split_m_attn: one head per workgroup = 1). A missing fold leaves v_cvt_f16_f32 after an FP32 add (a second rounding) and fails here. The __rodd ports (round to odd) must have none. The native D3D12 runtime checks the same fold on the player's driver at create (k_mix_probe). WG_DX12_ISA_CHECK=0 skips the check.",
"k_stage_e2": {"v_fma_mix(lo|hi)_f16": 64},
"k_stage_d2": {"v_fma_mix(lo|hi)_f16": 64},
"k_stage2_d1": {"v_fma_mix(lo|hi)_f16": 128},
"k_stage_d1": {"v_fma_mix(lo|hi)_f16": 64},
"k_stagew2_e3": {"v_fma_mix(lo|hi)_f16": 64},
"k_stagew4_e4": {"v_fma_mix(lo|hi)_f16": 32},
"k_stagew2_e4": {"v_fma_mix(lo|hi)_f16": 64},
Expand All @@ -18,6 +19,7 @@
"k_stage_e2__rodd": {"v_fma_mix(lo|hi)_f16": 0},
"k_stage_d2__rodd": {"v_fma_mix(lo|hi)_f16": 0},
"k_stage2_d1__rodd": {"v_fma_mix(lo|hi)_f16": 0},
"k_stage_d1__rodd": {"v_fma_mix(lo|hi)_f16": 0},
"k_stagew2_e3__rodd": {"v_fma_mix(lo|hi)_f16": 0},
"k_stagew4_e4__rodd": {"v_fma_mix(lo|hi)_f16": 0},
"k_stagew2_e4__rodd": {"v_fma_mix(lo|hi)_f16": 0},
Expand Down
16 changes: 16 additions & 0 deletions clean/dx12/kernel_sets.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@
"k_stage_d1",
"k_block.co"
],
[
"k_stage_d1__rodd",
"k_block.co"
],
[
"k_stage_d2",
"k_block.co"
Expand Down Expand Up @@ -624,6 +628,18 @@
"kx/k_in_tiled__a1",
"k_io_exact.co"
],
[
"kx/k_in_tiled_color",
"k_io_exact.co"
],
[
"kx/k_in_tiled_color_direct",
"k_io_exact.co"
],
[
"kx/k_in_tiled_color_uniform",
"k_io_exact.co"
],
[
"kx/k_in_tiled_direct",
"k_io_exact.co"
Expand Down
3 changes: 2 additions & 1 deletion clean/k/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ Model K ships in the same `wronggpu_runtime.dll` as model M; nothing changes for
first checks that
`dx12/manifest.json` has a port of every kernel the context can launch and refuses it, naming the missing kernels,
before the model is loaded. `k_in_uniforms=0` (diagnostic): the tiled input kernel that computes its frame values on the
GPU instead of taking the host's. `k_fill=<0..255>` (test hook, changes no value a frame writes): every buffer a frame writes and both history copies start with this byte after allocation, so that a test with a different byte per backend proves first-frame and reset-only writes. Latency options of the D3D12 devices that change no value: `k_color_at=<stage>`
GPU instead of taking the host's. `k_color_fuse=0` (native device; changes no value): the separate `k_out_color` launch instead of the
exact tiled input kernel's own output colour taps (`kx/k_in_tiled_color[_uniform|_direct]`, the default). `k_fill=<0..255>` (test hook, changes no value a frame writes): every buffer a frame writes and both history copies start with this byte after allocation, so that a test with a different byte per backend proves first-frame and reset-only writes. Latency options of the D3D12 devices that change no value: `k_color_at=<stage>`
(`k_out_color` runs unordered right after that stage; default: before the input stage, HIP's order) and `k_warm=<stage>` /
`off` (backend 3: `k_warm`, a cache warm-up of the weight blobs of the stages after it, launched unordered after that
stage, default `e0`; `k_warm_to`, `k_warm_line`, `k_warm_groups`). The D3D12 executor of the interop (the game's own
Expand Down
14 changes: 12 additions & 2 deletions clean/k/dx12/hlsl/k_block.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -611,14 +611,24 @@ void k_block(uint hidden, uint blk, uint bias32 = 0u, uint compact_head = 0u)
[unroll] for (int g = 0; g < G; ++g) p[g] = wgk_mma(w1t[kt], a[g][kt], p[g]);
uint4 hv[G];
[unroll] for (int g = 0; g < G; ++g) hv[g] = KB_ACT8W(wgk_round8(p[g]));
if (KB_W2LATE) // W2's tiles just before their multiplies (fewer live registers across the first GEMM)
#ifndef KB_W2SEQ
#define KB_W2SEQ 0 // with KB_W2LATE: one W2 tile at a time, loaded just before its own products (not all KT before the first)
#endif
if (KB_W2LATE && !KB_W2SEQ) // W2's tiles just before their multiplies (fewer live registers across the first GEMM)
#if KB_BASE_FORM
[unroll] for (int o4 = 0; o4 < KT; ++o4) w2t[o4] = kb_weight128(wb_w2, (uint)((ht * KT + o4) * 512));
#else
[unroll] for (int o4 = 0; o4 < KT; ++o4) w2t[o4] = wgk_ld8(P_w2, (uint)((ht * KT + o4) * 256) + lane * 8u);
#endif
[unroll] for (int ot = 0; ot < KT; ++ot)
[unroll] for (int ot = 0; ot < KT; ++ot) {
if (KB_W2LATE && KB_W2SEQ)
#if KB_BASE_FORM
w2t[ot] = kb_weight128(wb_w2, (uint)((ht * KT + ot) * 512));
#else
w2t[ot] = wgk_ld8(P_w2, (uint)((ht * KT + ot) * 256) + lane * 8u);
#endif
[unroll] for (int g = 0; g < G; ++g) acc[g][ot] = wgk_mma(w2t[ot], hv[g], acc[g][ot]);
}
}

// 5. x2, stored for the real positions (the stores' base pinned to every x2 fragment: products before the branch)
Expand Down
42 changes: 34 additions & 8 deletions clean/k/dx12/hlsl/k_common.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ uint4 wgk_opq4(uint4 v) { return v ^ (wgk_zero() * 0x10001u); }
half2 wgk_h2(uint u) { return asfloat16(uint16_t2((uint16_t)(u & 0xffffu), (uint16_t)(u >> 16))); }
uint wgk_u(half2 h) { uint16_t2 v = asuint16(h); return (uint)v.x | ((uint)v.y << 16); }
half2 wgk_c2(uint h) { return wgk_h2((h & 0xffffu) * 0x10001u); } // splatted FP16 constant (bits; no cast rounding)
// The exact FP16 product behind the opaque barrier in ONE instruction: fma(a, b, -0.0 ^ zero) per half. At run time the
// addend is -0.0 in both halves (the opaque zero is 0), and fma(a, b, -0) = RN(a b) for every input: the exact product
// is rounded once as the multiply rounds it, a zero product keeps its sign (+0 + -0 = +0, -0 + -0 = -0), NaN, infinities
// and denormals are the multiply's. The compiler cannot see the addend: it can neither turn the instruction back into a
// multiply nor fuse it into a following add or multiply (the barrier the xor of wgk_opq gave, without the xor). Never
// feed its result straight into an FP16 -> FP32 conversion: the driver folds an FP16 fma followed by the conversion into
// one v_fma_mix_f32 with no FP16 rounding in between (that is why wgk_sumsq8 keeps the multiply + xor).
half2 wgk_nz2() { return wgk_h2(0x80008000u ^ (wgk_zero() * 0x10001u)); }
half2 wgk_fm(half2 a, half2 b) { return mad(a, b, wgk_nz2()); }
// FP16 element i (0..7) of a fragment, as bits / as FP32 (exact)
uint wgk_el(uint4 v, uint i) { return (v[i >> 1] >> ((i & 1u) * 16u)) & 0xffffu; }
float wgk_elf(uint4 v, uint i) { return f16tof32(wgk_el(v, i)); }
Expand All @@ -58,7 +67,17 @@ uint wgk_pin(uint v) { return WaveActiveBitOr(v & wgk_zero()); }
#ifndef KB_LD_A16
#define KB_LD_A16 0
#endif
// KB_LD_A16 = 1 (the kernels' default): the whole address is masked, (base + off) & ~15: RADV's ACO takes the 128-bit
// alignment from exactly this mask on each load address. 2: the low 4 bits are cleared on the scalar base only ((base & ~15)
// + off: the same addresses): RGA gfx1201 then shows no per-lane v_and_b32 -16 (-40 .. -100 of them per stage kernel), but
// DXC writes base + (lane << 4) + c as (base & ~15) + (lane << 4 | c), and ACO does not take that as 16-byte aligned
// (RADV, measured: +6 .. +16 % instructions in k_stage2_d1 / e1 / e0 / d0_hp and k_stage_e2 / d2, the loads split).
// ((base & ~15) + (off & ~15) is no remedy: DXC folds the second mask away, the DXIL is that of 2.) 0: none.
#if KB_LD_A16 == 2
uint4 wgk_ld128_a16(uint base, uint off) { return wg_mem.Load4((base & ~15u) + off); }
#else
uint4 wgk_ld128_a16(uint base, uint off) { return wg_mem.Load4((base + off) & (KB_LD_A16 ? ~15u : ~0u)); }
#endif
uint4 wgk_ld8(uint base, uint off_h) { return wgk_ld128_a16(base, off_h * 2u); }
void wgk_st8(uint base, uint off_h, uint4 v) { wg_st128(base, off_h * 2u, v); }
uint4 wgk_zero8() { return uint4(0u, 0u, 0u, 0u); }
Expand Down Expand Up @@ -96,6 +115,13 @@ uint4 wgk_sub8(uint4 a, uint4 b)
return r;
}
uint4 wgk_mul8(uint4 a, uint4 b)
{
uint4 r;
[unroll] for (uint i = 0; i < 4u; ++i) r[i] = wgk_u(wgk_fm(wgk_h2(a[i]), wgk_h2(b[i])));
return r;
}
// the multiply behind the opaque xor, for a product converted to FP32 straight away (wgk_sumsq8: no fma form there)
uint4 wgk_mul8x(uint4 a, uint4 b)
{
uint4 r;
[unroll] for (uint i = 0; i < 4u; ++i) r[i] = wgk_opq(wgk_u(wgk_h2(a[i]) * wgk_h2(b[i])));
Expand Down Expand Up @@ -174,11 +200,11 @@ uint wgk_act2(uint xu)
const half2 x = wgk_h2(xu);
const half2 t = min(max(x, wgk_c2(WGK_H_M2)), wgk_c2(WGK_H_2));
const half2 at = abs(t);
const half2 bt = wgk_h2(wgk_opq(wgk_u(wgk_c2(WGK_ACT_B) * at)));
const half2 p = wgk_h2(wgk_opq(wgk_u(wgk_c2(WGK_ACT_A) - bt)));
const half2 tp = wgk_h2(wgk_opq(wgk_u(t * p)));
const half2 q = wgk_h2(wgk_opq(wgk_u(wgk_c2(WGK_H_HALF) + tp)));
return wgk_opq(wgk_u(x * q));
const half2 bt = wgk_fm(wgk_c2(WGK_ACT_B), at); // the two products that feed an addition, and the result: the
const half2 p = wgk_c2(WGK_ACT_A) - bt; // exact fma form; a - b|t| feeds a multiply and 0.5 + t p the last
const half2 tp = wgk_fm(t, p); // multiply: an addition cannot be fused into those (as wgk_act2n)
const half2 q = wgk_c2(WGK_H_HALF) + tp;
return wgk_u(wgk_fm(x, q));
}
uint4 wgk_act8(uint4 x)
{
Expand All @@ -192,9 +218,9 @@ uint wgk_act2n(uint xu)
const half2 x = wgk_h2(xu);
const half2 t = min(max(x, wgk_c2(WGK_H_M2)), wgk_c2(WGK_H_2));
const half2 at = abs(t);
const half2 bt = wgk_h2(wgk_opq(wgk_u(wgk_c2(WGK_ACT_B) * at)));
const half2 bt = wgk_fm(wgk_c2(WGK_ACT_B), at);
const half2 p = wgk_c2(WGK_ACT_A) - bt;
const half2 tp = wgk_h2(wgk_opq(wgk_u(t * p)));
const half2 tp = wgk_fm(t, p);
const half2 q = wgk_c2(WGK_H_HALF) + tp;
return wgk_u(x * q);
}
Expand Down Expand Up @@ -225,7 +251,7 @@ void wgk_softmax_weights(uint4 gg[4], out uint4 pa[4])
// FP16 squares, then v_fma_mix_f32 x2_half * 1 + ss = the FP32 addition of the exact FP16 value).
float wgk_sumsq8(uint4 x, float ss)
{
const uint4 q = wgk_mul8(x, x);
const uint4 q = wgk_mul8x(x, x);
[unroll] for (uint j = 0; j < 8u; ++j) ss = ss + wgk_elf(q, j);
return ss;
}
Expand Down
25 changes: 21 additions & 4 deletions clean/k/dx12/hlsl/k_fp.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,27 @@
#include "k_fp_tables.hlsli"

static uint kf_opq_z_; // 0, opaque to the compiler (KF_SETUP)
#define KF_SETUP() (kf_opq_z_ = wg_grid_ >> 31)
static float kf_nz_; // -0.0 ^ the opaque zero: -0.0 at run time, unknown to the compiler (KF_SETUP, one SGPR)
#define KF_SETUP() (kf_opq_z_ = wg_grid_ >> 31, kf_nz_ = asfloat(0x80000000u ^ (wg_grid_ >> 31)))
float kf_opq(float x) { return asfloat(asuint(x) ^ kf_opq_z_); }
float2 kf_opq2(float2 x) { return asfloat(asuint(x) ^ kf_opq_z_); }
float4 kf_opq4(float4 x) { return asfloat(asuint(x) ^ kf_opq_z_); }
// A product rounded as its own instruction: kf_pm(a, b) = RN(a b) = fma(a, b, -0.0 ^ opaque zero) bit for bit (the exact
// product plus -0.0 rounds once: a zero product keeps its sign, NaN / infinities / FTZ as the multiply), the addend
// unknown to the compiler: no fusion into a following addition, no regrouping. One v_fma_f32 with the SGPR addend instead
// of the multiply and the xor of kf_opq(a * b) (k_common.hlsli wgk_fm is the FP16 twin). KF_PM = 0: kf_opq(a * b).
#ifndef KF_PM
#define KF_PM 1
#endif
#if KF_PM
float kf_pm(float a, float b) { return mad(a, b, kf_nz_); }
float3 kf_pm3(float3 a, float3 b) { return mad(a, b, (float3)kf_nz_); }
float4 kf_pm4(float4 a, float4 b) { return mad(a, b, (float4)kf_nz_); }
#else
float kf_pm(float a, float b) { return kf_opq(a * b); }
float3 kf_pm3(float3 a, float3 b) { return asfloat(asuint(a * b) ^ kf_opq_z_); }
float4 kf_pm4(float4 a, float4 b) { return kf_opq4(a * b); }
#endif

// ---- elementary steps -----------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -282,7 +299,7 @@ kf2 kf2_fast_two_sum(float a, float b) // |
}
kf2 kf2_two_prod(float a, float b)
{
const float p = kf_opq(a * b);
const float p = kf_pm(a, b);
return kf2_make(p, kf_fma(a, b, -p));
}
kf2 kf2_add(kf2 a, kf2 b)
Expand Down Expand Up @@ -349,8 +366,8 @@ kf2 kf2_exp2(float y)
const kf2 x = kf2_mul(kf2_make(r, 0.0f), kf2_make(KF2_LN2_H, KF2_LN2_L)); // |x| < 0.0055
// e^x = 1 + x + x^2/2 + x^3/6 + x^4/24 + x^5/120; HIP's order ((xh xh) xh) poly, each product rounded
const float xh = x.h;
const float x2 = kf_opq(xh * xh), x3 = kf_opq(x2 * xh);
const float tail = kf_opq(x3 * kf_fma(xh, kf_fma(xh, KF_1_120, KF_1_24), KF_SIXTH)); // not fused into q.h + tail
const float x2 = kf_pm(xh, xh), x3 = kf_pm(x2, xh);
const float tail = kf_pm(x3, kf_fma(xh, kf_fma(xh, KF_1_120, KF_1_24), KF_SIXTH)); // not fused into q.h + tail
kf2 q = kf2_two_prod(xh, xh);
q.h = q.h * 0.5f;
q.l = kf_fma(xh, x.l, q.l * 0.5f);
Expand Down
64 changes: 53 additions & 11 deletions clean/k/dx12/hlsl/k_frame.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,30 @@ float kio_depth(KFrameIn F, int ix, int iy, int dx, int dy)
// spec 42 5.2 [MVlo]: offset of the nearest-depth motion pixel
void kio_nearest(KFrameIn F, int ix, int iy, out int odx, out int ody)
{
const float c = kio_depth(F, ix, iy, 0, 0), a = kio_depth(F, ix, iy, -1, -1), b = kio_depth(F, ix, iy, 1, -1);
const float d = kio_depth(F, ix, iy, -1, 1), e = kio_depth(F, ix, iy, 1, 1);
float c, a, b, d, e;
#if !WG_DIRECT_TEXTURES
[branch] if (ix >= 1 && ix <= F.rw - 2 && iy >= 1 && iy <= F.rh - 2) {
const uint zp = (uint)F.zpitch * 4u;
const uint voff = ((uint)(F.zby + iy - 1) * (uint)F.zpitch + (uint)(F.zbx + ix - 1)) * 4u;
c = wg_ldf(F.depth + zp + 4u, voff);
a = wg_ldf(F.depth, voff);
b = wg_ldf(F.depth + 8u, voff);
d = wg_ldf(F.depth + 2u * zp, voff);
e = wg_ldf(F.depth + 2u * zp + 8u, voff);
} else
#endif
{
c = kio_depth(F, ix, iy, 0, 0);
a = kio_depth(F, ix, iy, -1, -1);
b = kio_depth(F, ix, iy, 1, -1);
d = kio_depth(F, ix, iy, -1, 1);
e = kio_depth(F, ix, iy, 1, 1);
}
const float k = kf_bits(0x3A83126Fu);
const bool inv = (F.flags & KIO_INV) != 0;
bool edge;
if (inv)
edge = (c < 0.5f * (a + e) - kf_opq(k * c)) || (c < 0.5f * (b + d) - kf_opq(k * c));
edge = (c < 0.5f * (a + e) - kf_pm(k, c)) || (c < 0.5f * (b + d) - kf_pm(k, c));
else
edge = (c > kf_fma(c, k, 0.5f * (a + e))) || (c > kf_fma(c, k, 0.5f * (b + d)));
int bx = 0, by = 0;
Expand All @@ -246,12 +263,22 @@ void kio_nearest(KFrameIn F, int ix, int iy, out int odx, out int ody)
float kio_decode(float t)
{
if (t < K_KIO_DECODE_NEAR) return wg_div(1.0f, 1.0f - t);
const float e = kf_opq((t + kf_bits(0x3C4FAE29u)) * 9.0f) * kf_bits(0x3FB8AA3Bu);
const float e = kf_pm(t + kf_bits(0x3C4FAE29u), 9.0f) * kf_bits(0x3FB8AA3Bu);
return wg_div(kf_exp2(e) - 1.0f, 9.0f * t);
}
// 1 / x correctly rounded (= wg_div(1, x) on every input): one Newton step on v_rcp_f32 for x in [2^-32, 2^32] (the
// exhaustively GPU-checked reciprocal of k_out.hlsli ko_rcp_refined / k_in_common.hlsli ki_rcp), wg_div elsewhere
float kio_rcp(float x)
{
[branch] if (x >= asfloat(0x2f800000u) && x <= asfloat(0x4f800000u)) {
const float r = rcp(x);
return mad(mad(-x, r, 1.0f), r, r);
}
return wg_div(1.0f, x);
}
float kio_encode(float Y)
{
if (Y < K_KIO_ENCODE_NEAR) return wg_div(1.0f, Y + 1.0f);
if (Y < K_KIO_ENCODE_NEAR) return kio_rcp(Y + 1.0f);
return wg_div(wg_div(kf_ln(kf_fma(Y, 9.0f, 1.0f)), 9.0f) - kf_bits(0x3C4FAE29u), Y);
}

Expand All @@ -264,21 +291,36 @@ float4 kio_texel_h4(uint img, uint idx)
}
float4 kio_bilinear4(uint img, int w, int h, float cx, float cy)
{
const float px = kf_opq(cx * (float)w) - 0.5f, py = kf_opq(cy * (float)h) - 0.5f;
const float px = kf_pm(cx, (float)w) - 0.5f, py = kf_pm(cy, (float)h) - 0.5f;
const float fx0 = floor(px), fy0 = floor(py);
const float fx = px - fx0, fy = py - fy0;
// HIP: finite ? (int)max(min(f, w), -1) : (+inf: w, -inf: -1, NaN: 0). The clamp already gives w / -1 for +-inf
// (min / max are IEEE minNum / maxNum), so only NaN needs the select
const int x0 = isnan(fx0) ? 0 : (int)kf_max(kf_min(fx0, (float)w), -1.0f);
const int y0 = isnan(fy0) ? 0 : (int)kf_max(kf_min(fy0, (float)h), -1.0f);
const int xa = ki_max(ki_min(x0, w - 1), 0), xb = ki_max(ki_min(x0 + 1, w - 1), 0);
const int ya = ki_max(ki_min(y0, h - 1), 0), yb = ki_max(ki_min(y0 + 1, h - 1), 0);
uint2 q00u, q10u, q01u, q11u;
[branch] if ((uint)x0 <= (uint)(w - 2) && (uint)y0 <= (uint)(h - 2)) {
const uint voff = ((uint)y0 * (uint)w + (uint)x0) * 8u, r1 = img + (uint)w * 8u;
q00u = wg_ld64(img, voff);
q10u = wg_ld64(img + 8u, voff);
q01u = wg_ld64(r1, voff);
q11u = wg_ld64(r1 + 8u, voff);
} else {
const int xa = ki_max(ki_min(x0, w - 1), 0), xb = ki_max(ki_min(x0 + 1, w - 1), 0);
const int ya = ki_max(ki_min(y0, h - 1), 0), yb = ki_max(ki_min(y0 + 1, h - 1), 0);
q00u = wg_ld64(img, ((uint)ya * (uint)w + (uint)xa) * 8u);
q10u = wg_ld64(img, ((uint)ya * (uint)w + (uint)xb) * 8u);
q01u = wg_ld64(img, ((uint)yb * (uint)w + (uint)xa) * 8u);
q11u = wg_ld64(img, ((uint)yb * (uint)w + (uint)xb) * 8u);
}
const float omfy = 1.0f - fy;
const float4 q00 = kio_texel_h4(img, (uint)ya * (uint)w + (uint)xa), q10 = kio_texel_h4(img, (uint)ya * (uint)w + (uint)xb);
const float4 q01 = kio_texel_h4(img, (uint)yb * (uint)w + (uint)xa), q11 = kio_texel_h4(img, (uint)yb * (uint)w + (uint)xb);
const float4 q00 = float4(wg_h2f_lo(q00u.x), wg_h2f_hi(q00u.x), wg_h2f_lo(q00u.y), wg_h2f_hi(q00u.y));
const float4 q10 = float4(wg_h2f_lo(q10u.x), wg_h2f_hi(q10u.x), wg_h2f_lo(q10u.y), wg_h2f_hi(q10u.y));
const float4 q01 = float4(wg_h2f_lo(q01u.x), wg_h2f_hi(q01u.x), wg_h2f_lo(q01u.y), wg_h2f_hi(q01u.y));
const float4 q11 = float4(wg_h2f_lo(q11u.x), wg_h2f_hi(q11u.x), wg_h2f_lo(q11u.y), wg_h2f_hi(q11u.y));
const float4 t0 = q00 + kf_opq4(q10 - q00) * fx;
const float4 t1 = q01 + kf_opq4(q11 - q01) * fx;
return kf_opq4(t0 * omfy) + kf_opq4(t1 * fy);
return kf_pm4(t0, (float4)omfy) + kf_pm4(t1, (float4)fy);
}

// (Y, Co, Cg) of max(RGB, 0) scaled by kappa first (spec 42 6.2) or not (spec 43 4.2: kappa after)
Expand Down
Loading
Loading