h264: V3D shader for qpel mc22 (2D half-pel "j" position)
Cascaded H+V 6-tap filter per H.264 §8.4.2.2.1. Highest per-frame impact among missing qpel positions (PR #24 bench: 71.5 ns/block NEON, 2.33 ms/frame worst-case all-mc22 at 1080p). Per-lane structure: each lane runs the FULL cascade independently — computes 6 horizontal lowpass int16 intermediates at rows r-2..r+3 of its column, then a vertical lowpass on those with +512 >> 10 final scale. ~50 ALU ops per lane. Design choice: NO shared memory / barriers. Alternative was to cache the h-lowpass intermediates in shared memory (13 rows × 8 cols of int16 per WG), trading shared-memory bank pressure + a barrier for ~6× less h-lowpass compute. V3D L2 absorbs the redundant src reads across lanes; the per-lane compute is cheap (multiply-add ALU units idle anyway during dst write). Simpler shader, fewer SPIR-V ops, easier to extend to mc12/mc21/etc. later. CANNOT just cascade mc20 → mc02 because the intermediate must be int16 (no per-stage clip): the +512 >> 10 final scale assumes both 6-tap scalings preserved through the pipeline. Dedicated kernel. dispatch_h264_qpel_mc22_qpu mirrors the existing mc20/mc02 shape; src_max = src_off + 10*stride + 11 covers both the V (rows -2..+10) and H (cols -2..+10) read windows in one bound. Recipe table flips DAEDALUS_KERNEL_H264_QPEL_MC22 from CPU to QPU. Verified on hertz: $ ./build/test_api_h264 | grep qpel H.264 qpel mc20: 1024/1024 bytes bit-exact (100.0000%) H.264 qpel mc02: 2048/2048 bytes bit-exact (100.0000%) H.264 qpel mc22: 2048/2048 bytes bit-exact (100.0000%) Qpel QPU coverage now: 3 anchors (mc20 H, mc02 V, mc22 HV) — these are the half-pel "building blocks" the 12 other qpel positions combine via L2 averaging. Remaining variants (quarter-pel singles mc01/03/10/30 and the 8 diagonals) can dispatch through the existing shaders + a small L2-averaging compose step, or get dedicated kernels.
This commit is contained in:
+91
-4
@@ -54,6 +54,8 @@ struct daedalus_ctx {
|
||||
v3d_pipeline h264_qpel_mc20_pipe;
|
||||
int h264_qpel_mc02_pipe_ready;
|
||||
v3d_pipeline h264_qpel_mc02_pipe;
|
||||
int h264_qpel_mc22_pipe_ready;
|
||||
v3d_pipeline h264_qpel_mc22_pipe;
|
||||
};
|
||||
|
||||
daedalus_ctx *daedalus_ctx_create(void)
|
||||
@@ -115,6 +117,7 @@ void daedalus_ctx_destroy(daedalus_ctx *ctx)
|
||||
if (ctx->h264_idct8_pipe_ready) v3d_runner_destroy_pipeline(ctx->runner, &ctx->h264_idct8_pipe);
|
||||
if (ctx->h264_qpel_mc20_pipe_ready) v3d_runner_destroy_pipeline(ctx->runner, &ctx->h264_qpel_mc20_pipe);
|
||||
if (ctx->h264_qpel_mc02_pipe_ready) v3d_runner_destroy_pipeline(ctx->runner, &ctx->h264_qpel_mc02_pipe);
|
||||
if (ctx->h264_qpel_mc22_pipe_ready) v3d_runner_destroy_pipeline(ctx->runner, &ctx->h264_qpel_mc22_pipe);
|
||||
v3d_runner_destroy(ctx->runner);
|
||||
}
|
||||
free(ctx);
|
||||
@@ -151,7 +154,7 @@ daedalus_substrate daedalus_recipe_substrate_for(daedalus_kernel k)
|
||||
case DAEDALUS_KERNEL_H264_DEBLOCK_CH_INTRA: return DAEDALUS_SUBSTRATE_CPU;
|
||||
case DAEDALUS_KERNEL_H264_QPEL_MC20: return DAEDALUS_SUBSTRATE_QPU; /* v3d_h264_qpel_mc20.spv */
|
||||
case DAEDALUS_KERNEL_H264_QPEL_MC02: return DAEDALUS_SUBSTRATE_QPU; /* v3d_h264_qpel_mc02.spv */
|
||||
case DAEDALUS_KERNEL_H264_QPEL_MC22: return DAEDALUS_SUBSTRATE_CPU; /* QPU mc22 shader pending (hv lowpass) */
|
||||
case DAEDALUS_KERNEL_H264_QPEL_MC22: return DAEDALUS_SUBSTRATE_QPU; /* v3d_h264_qpel_mc22.spv */
|
||||
case DAEDALUS_KERNEL_H264_QPEL_MC10: return DAEDALUS_SUBSTRATE_CPU; /* ¼-H L2 */
|
||||
case DAEDALUS_KERNEL_H264_QPEL_MC30: return DAEDALUS_SUBSTRATE_CPU; /* ¾-H L2 */
|
||||
case DAEDALUS_KERNEL_H264_QPEL_MC01: return DAEDALUS_SUBSTRATE_CPU; /* ¼-V L2 */
|
||||
@@ -1543,6 +1546,90 @@ fail:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int dispatch_h264_qpel_mc22_qpu(daedalus_ctx *ctx,
|
||||
uint8_t *dst, const uint8_t *src, size_t stride,
|
||||
size_t n_blocks, const daedalus_h264_qpel_meta *meta)
|
||||
{
|
||||
/* 2D HV cascade: rows -2..+10 (13 rows of src) AND cols -2..+10
|
||||
* per row (8 output cols × cols c-2..c+3 → up to col 10). So
|
||||
* src_max = src_off + 10*stride + 11.
|
||||
* (mc20 needed 7*stride + 11; mc02 needed 10*stride + 8;
|
||||
* mc22 needs MAX of both = 10*stride + 11.) */
|
||||
if (!ctx->h264_qpel_mc22_pipe_ready) {
|
||||
if (v3d_runner_create_pipeline(ctx->runner, "v3d_h264_qpel_mc22.spv",
|
||||
3, sizeof(h264_qpel_mc20_pc),
|
||||
&ctx->h264_qpel_mc22_pipe) != 0)
|
||||
return -1;
|
||||
ctx->h264_qpel_mc22_pipe_ready = 1;
|
||||
}
|
||||
|
||||
size_t meta_bytes = n_blocks * 4 * sizeof(uint32_t);
|
||||
size_t src_max = 0, dst_max = 0;
|
||||
for (size_t i = 0; i < n_blocks; i++) {
|
||||
size_t s_end = meta[i].src_off + (size_t) 10 * stride + 11;
|
||||
size_t d_end = meta[i].dst_off + (size_t) 7 * stride + 8;
|
||||
if (s_end > src_max) src_max = s_end;
|
||||
if (d_end > dst_max) dst_max = d_end;
|
||||
}
|
||||
|
||||
v3d_buffer bs = {0}, bd = {0}, bm = {0};
|
||||
if (v3d_runner_create_buffer(ctx->runner, src_max, &bs)) return -1;
|
||||
if (v3d_runner_create_buffer(ctx->runner, dst_max, &bd)) {
|
||||
v3d_runner_destroy_buffer(ctx->runner, &bs); return -1;
|
||||
}
|
||||
if (v3d_runner_create_buffer(ctx->runner, meta_bytes, &bm)) {
|
||||
v3d_runner_destroy_buffer(ctx->runner, &bd);
|
||||
v3d_runner_destroy_buffer(ctx->runner, &bs); return -1;
|
||||
}
|
||||
|
||||
memcpy(bs.mapped, src, src_max);
|
||||
memcpy(bd.mapped, dst, dst_max);
|
||||
uint32_t *m = bm.mapped;
|
||||
for (size_t i = 0; i < n_blocks; i++) {
|
||||
m[4*i+0] = meta[i].dst_off;
|
||||
m[4*i+1] = meta[i].src_off;
|
||||
m[4*i+2] = 0;
|
||||
m[4*i+3] = 0;
|
||||
}
|
||||
|
||||
v3d_buffer binds[3] = { bs, bd, bm };
|
||||
if (v3d_runner_bind_buffers(ctx->runner, &ctx->h264_qpel_mc22_pipe, binds, 3))
|
||||
goto fail;
|
||||
|
||||
uint32_t wg_count = (uint32_t) n_blocks;
|
||||
h264_qpel_mc20_pc pc = {
|
||||
.n_blocks = (uint32_t) n_blocks,
|
||||
.stride_u8 = (uint32_t) stride,
|
||||
};
|
||||
|
||||
VkCommandBuffer cb = v3d_runner_alloc_cmdbuf(ctx->runner);
|
||||
if (cb == VK_NULL_HANDLE) goto fail;
|
||||
VkCommandBufferBeginInfo cbbi = { .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
|
||||
vkBeginCommandBuffer(cb, &cbbi);
|
||||
vkCmdBindPipeline(cb, VK_PIPELINE_BIND_POINT_COMPUTE,
|
||||
ctx->h264_qpel_mc22_pipe.pipeline);
|
||||
vkCmdBindDescriptorSets(cb, VK_PIPELINE_BIND_POINT_COMPUTE,
|
||||
ctx->h264_qpel_mc22_pipe.layout, 0, 1,
|
||||
&ctx->h264_qpel_mc22_pipe.desc_set, 0, NULL);
|
||||
vkCmdPushConstants(cb, ctx->h264_qpel_mc22_pipe.layout,
|
||||
VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(pc), &pc);
|
||||
vkCmdDispatch(cb, wg_count, 1, 1);
|
||||
vkEndCommandBuffer(cb);
|
||||
if (v3d_runner_submit_wait(ctx->runner, cb)) goto fail;
|
||||
|
||||
memcpy(dst, bd.mapped, dst_max);
|
||||
|
||||
v3d_runner_destroy_buffer(ctx->runner, &bm);
|
||||
v3d_runner_destroy_buffer(ctx->runner, &bd);
|
||||
v3d_runner_destroy_buffer(ctx->runner, &bs);
|
||||
return 0;
|
||||
fail:
|
||||
v3d_runner_destroy_buffer(ctx->runner, &bm);
|
||||
v3d_runner_destroy_buffer(ctx->runner, &bd);
|
||||
v3d_runner_destroy_buffer(ctx->runner, &bs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------- Public dispatch entry points -------------- */
|
||||
|
||||
#define ROUTE_CPU_ONLY(_kernel, _cpu_fn, ...) \
|
||||
@@ -1776,9 +1863,9 @@ int daedalus_dispatch_h264_qpel_mc22(daedalus_ctx *ctx, daedalus_substrate sub,
|
||||
eff = daedalus_recipe_substrate_for(DAEDALUS_KERNEL_H264_QPEL_MC22);
|
||||
if (eff == DAEDALUS_SUBSTRATE_QPU && !daedalus_ctx_has_qpu(ctx))
|
||||
eff = DAEDALUS_SUBSTRATE_CPU;
|
||||
if (eff == DAEDALUS_SUBSTRATE_QPU)
|
||||
return -1; /* No mc22 QPU shader yet — explicit QPU fast-fails. */
|
||||
return dispatch_h264_qpel_mc22_cpu(ctx, dst, src, stride, n_blocks, meta);
|
||||
if (eff == DAEDALUS_SUBSTRATE_CPU)
|
||||
return dispatch_h264_qpel_mc22_cpu(ctx, dst, src, stride, n_blocks, meta);
|
||||
return dispatch_h264_qpel_mc22_qpu(ctx, dst, src, stride, n_blocks, meta);
|
||||
}
|
||||
|
||||
#define DEFINE_QPEL_DISPATCH(suffix, kernel) \
|
||||
|
||||
Reference in New Issue
Block a user