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
1 change: 1 addition & 0 deletions clean/k/dx12/hlsl/k_frame.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct KInParams {
};
struct KiHost { // spec 42 section 8
float xi_x, xi_y, a_x, a_y, h_x, h_y, g_x, g_y, sp_x, sp_y, mp_x, mp_y;
float of_x, of_y; // KI_SGPR only (k_in.hlsl ki_host_sgpr): the motion offset in raw units; not part of the host's KiHost
};

#define K_LOAD_FRAME_PTRS(F) F.color = F_color; F.motion = F_motion; F.depth = F_depth; F.xs = F_xs;
Expand Down
8 changes: 8 additions & 0 deletions clean/k/dx12/hlsl/k_in_common.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#ifndef KI_HWMATH
#define KI_HWMATH 0
#endif
#ifndef KI_SGPR
#define KI_SGPR 0 // k_in.hlsl defines it for the exact direct tiled form
#endif
#if KI_HWMATH
// CLOSE-APPROXIMATION variant (opt-in, never the default): the transcendental unit instead of the correctly rounded
// sequences: v_log_f32 / v_exp_f32 (about 1 FP32 ulp), v_rcp_f32 and a product for the divisions. The results meet the
Expand Down Expand Up @@ -92,6 +95,10 @@ KiFine ki_fine(KInParams P, KiHost k, int fx, int fy)
const bool dfold = (F.flags & KIO_M16) != 0;
const float dmsx = F.rmsx, dmsy = F.rmsy, dmox = F.rmox, dmoy = F.rmoy;
#endif
#if KI_SGPR
// the exact tiled direct kernel: the same four values, computed once per wave in k_in.hlsl ki_host_sgpr (SGPRs)
const float spx = k.sp_x, spy = k.sp_y, ofx = k.of_x, ofy = k.of_y;
#else
float spx = k.sp_x, spy = k.sp_y, ofx = F.mox, ofy = F.moy;
[branch] if (dfold) {
const bool dmvlo = (F.flags & KIO_MVLO) != 0;
Expand All @@ -100,6 +107,7 @@ KiFine ki_fine(KInParams P, KiHost k, int fx, int fy)
ofx = ki_dmo(F.mox, dmox, dmsx);
ofy = ki_dmo(F.moy, dmoy, dmsy);
}
#endif
const float mx = spx * (mvx + ofx), my = spy * (mvy + ofy);
const float wx = px + mx, wy = py + my;
KiFine r;
Expand Down
38 changes: 38 additions & 0 deletions clean/k/dx12/kernels/k_in.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
#if WG_DIRECT_TEXTURES
#include "native_direct.hlsli"
#endif
#ifndef KI_HWMATH
#define KI_HWMATH 0
#endif
// KI_SGPR (the exact direct form only): the frame's uniforms (KiHost and the direct motion factors) are computed once
// and held in SGPRs (v_readfirstlane), not in VGPRs: kx/k_in_tiled_direct 83 -> <= 72 VGPR (5 workgroups per CU)
#define KI_SGPR (WG_DIRECT_TEXTURES && !KI_HWMATH)
#include "k_fp.hlsli"
#include "k_frame.hlsli"

Expand Down Expand Up @@ -94,6 +100,36 @@ float4 ki_tiled_transpose(float4 v, int lane)
return float4(b1 ? z : a.x, b1 ? w : a.y, b1 ? a.z : z, b1 ? a.w : w);
}

#if KI_SGPR
// ki_host(F) with the direct form's motion factors (sp = ki_dsp, of = ki_dmo: the values ki_fine computed per fine
// position) and every field forced to a scalar register: all are wave-uniform (root constants and b1 only). The
// operations and their order are unchanged, so the values are bit-identical.
KiHost ki_host_sgpr(KFrameIn F)
{
KiHost k = ki_host(F);
const bool mvlo = (F.flags & KIO_MVLO) != 0;
k.sp_x = ki_dsp(F.sx, nd_msx, F.W, mvlo ? F.rw : F.W);
k.sp_y = ki_dsp(F.sy, nd_msy, F.H, mvlo ? F.rh : F.H);
k.of_x = ki_dmo(F.mox, nd_mox, nd_msx);
k.of_y = ki_dmo(F.moy, nd_moy, nd_msy);
k.xi_x = WaveReadLaneFirst(k.xi_x);
k.xi_y = WaveReadLaneFirst(k.xi_y);
k.a_x = WaveReadLaneFirst(k.a_x);
k.a_y = WaveReadLaneFirst(k.a_y);
k.h_x = WaveReadLaneFirst(k.h_x);
k.h_y = WaveReadLaneFirst(k.h_y);
k.g_x = WaveReadLaneFirst(k.g_x);
k.g_y = WaveReadLaneFirst(k.g_y);
k.sp_x = WaveReadLaneFirst(k.sp_x);
k.sp_y = WaveReadLaneFirst(k.sp_y);
k.mp_x = WaveReadLaneFirst(k.mp_x);
k.mp_y = WaveReadLaneFirst(k.mp_y);
k.of_x = WaveReadLaneFirst(k.of_x);
k.of_y = WaveReadLaneFirst(k.of_y);
return k;
}
#endif

groupshared float4 tile_cv[24 * 24];
groupshared float tile_om[24 * 24];

Expand All @@ -112,6 +148,8 @@ WG_KERNEL(k_in_tiled)
#if K_UNIFORM
KiHost hk;
K_LOAD_HOST(hk)
#elif KI_SGPR
const KiHost hk = ki_host_sgpr(F);
#else
const KiHost hk = ki_host(F);
#endif
Expand Down
Loading