Only constant QP was offered. Add the two bitrate modes, with the quantizer
derived once per picture from the requested bitrate and frame rate.
There is no closed loop and there cannot be one here: a picture's size is
known only after the GPU encodes it, and vkCmdEncodeVideoKHR merely records
commands. The VA-API encoder for this hardware runs its bit rate control
after each frame completes, which that API's synchronisation allows and this
one does not, and gen7 has no macroblock-level rate control the hardware
drives on its own -- the VA-API driver leaves those MFX_AVC_IMG_STATE fields
zero on this generation. Vulkan defines rate control as best effort, and
this is the effort.
The quantizer comes from a measured curve rather than a guess: sweeping QP 14
to 50 over a 176x144 clip gives 361 bits per macroblock at QP 26 for an I
picture and 166 for a P one, halving every 12.5 steps of the quantizer for I
and every 10.3 for P. Measured against the target across a 15x range of
bitrates, I pictures land between 0.82x and 1.30x, P pictures between 0.59x
and 1.56x -- the spread on P is content dependent and nothing open loop can
narrow it. A target below about 90 bits per macroblock cannot be met at all,
since that is where the curve flattens.
dEQP-VK.video.encode.h264 goes from 84 to 92 of 120 with no failures. The
remaining 28 are quantization maps, which gen7 has no hardware path for, and
B frames.
Co-Authored-By: Claude Opus 5 <[email protected]>
Splitting a picture into slices is the implementation's job. The encoder
instead read first_mb_in_slice out of each entry's slice header and used the
next entry's value as the end of the range, but clients leave that field at
zero on every entry and expect the driver to derive it and write it into the
emitted header. A multi-slice picture therefore came out as one slice
covering nothing, and vkCmdEncodeVideoKHR failed.
Divide the macroblock rows evenly across the NALU slice entries, which keeps
every slice row-aligned as required while
VK_VIDEO_ENCODE_H264_CAPABILITY_ROW_UNALIGNED_SLICE_BIT_KHR is not
advertised, and reject more slices than there are rows.
This also removes the workaround for ffmpeg passing first_mb_in_slice=1,
which was not a client bug at all: the field was never an input.
Per-picture-partition intra refresh needs nothing beyond this, since the
refreshed partition is just a slice the client marks as an I slice and slices
are already coded by their own slice_type, so offer that mode too.
dEQP-VK.video.encode.h264 goes from 76 to 84 of 120. The remaining 36 are
honest: quantization maps have no hardware path on gen7, where the only
per-macroblock QP is the one the CPU writes into the PAK object and the only
indirect data a PAK object fetches is motion vectors; B frames and rate
control are not implemented.
Co-Authored-By: Claude Opus 5 <[email protected]>
The encoder ignored VkVideoReferenceSlotInfoKHR entirely: it took
pReferenceSlots[0] as the one reference, wrote its address into frame store 0
and hardcoded the L0 list to that store. Two DPB slots were all it could
honestly advertise, which is fewer than a GOP of any length needs.
Record each slot the operation names under its own index, since a slot maps
onto the frame store of the same index and MFX_PIPE_BUF_ADDR_STATE holds 16
of those, and build the L0 entries from StdVideoEncodeH264ReferenceListsInfo,
whose RefPicList0 already carries slot indices. Clients that pass reference
slots without a list keep the old behaviour.
maxDpbSlots therefore goes to 16. maxActiveReferencePictures stays at 1:
every macroblock is still coded against reference index 0, so a picture may
be kept in the DPB but only the one it names first is predicted from.
dEQP-VK.video.encode.h264.intra_refresh_* goes from 12 Pass and 32 stopped at
the maxDpbSlots >= GOP frame count precondition to 36 Pass, the remaining 8
being per-picture-partition mode, which is not offered. The family as a whole
is 76 of 120 with no failures. ffmpeg's h264_vulkan encoder no longer trips
its slot_index assertion and produces a full GOP.
Co-Authored-By: Claude Opus 5 <[email protected]>
Each macroblock's intra/inter decision is already made on its own when the
PAK objects are emitted, so refreshing a region is a matter of coding the
macroblocks it covers the way an I slice codes them. Regions divide the
picture evenly along rows, columns or raster order, which leaves the block,
block-row and block-column modes supported and gives empty regions for free
when the cycle is longer than the split axis.
Two things needed care. PAK keeps the I slice numbering for MbType5Bits
inside a P slice, where H.264 itself offsets intra mb_types by 5; handing it
the offset value hangs the MFC. And under constrained intra prediction a
neighbour only counts as available if it is in the refresh region too,
because prediction may not cross into an inter macroblock.
Nothing constrains motion away from not-yet-refreshed regions, which is
sound only because there is no motion estimation: every vector is zero, so a
macroblock reads its own co-located block and never leaves its region.
Motion estimation will have to honour VkVideoReferenceIntraRefreshInfoKHR's
dirty region count.
Per-picture-partition mode is not offered. It wants the refreshed slice
coded as an I slice, header included, rather than as intra macroblocks
inside a P slice.
dEQP-VK.video.encode.h264.intra_refresh_* goes from 44 NotSupported to 12
Pass; all three modes pass in the variants that can run. The other 32 stop
at a CTS precondition, maxDpbSlots >= GOP frame count, which the driver's
two slots do not meet. Raising that needs real DPB slot tracking and is
what gates B frames and ffmpeg's encoder too.
Co-Authored-By: Claude Opus 5 <[email protected]>
Squashed work that had been sitting in the working tree. Grouped by area:
Extensions
VK_EXT_host_image_copy, with a MEMCPY_BIT path that reads and writes the
image's own tiled layout, VkSubresourceHostMemcpySizeEXT filled in, and
VkHostImageCopyDevicePerformanceQueryEXT answered. Depth/stencil and
non-power-of-two bpb stay NotSupported.
VK_EXT_pipeline_robustness, VK_KHR_shader_float_controls2,
VK_KHR_shader_subgroup_rotate, VK_EXT_vertex_input_dynamic_state,
VK_EXT_conditional_rendering (an MI_PREDICATE path for gen7, which has no
GPRs), custom_border_color, border_color_swizzle, map_memory2,
load_store_op_none, depth_clamp_zero_one,
dynamic_rendering_unused_attachments, index_type_uint8,
line_rasterization, vertex_attribute_divisor, mutable_descriptor_type.
H.264 encode
MFC command emission and a bitstream writer, driving intra-only encode
through the video queue. Video profile reporting was also corrected from
270 combinations down to the 11 that actually exist.
Correctness
gfx7 routes typed surface writes through the render cache, so
VK_ACCESS_SHADER_WRITE barriers have to flush it -- without that, nothing a
fragment shader stored was visible.
nir_opt_algebraic's fadd->flrp fusion rules dropped signed zero; '~' only
excludes nir_fp_exact, not preserve_signed_zero, so reflect() with a -0
input came out wrong. Guarded with (nsz).
Stop advertising STORAGE_READ_WITHOUT_FORMAT: shaderStorageImageReadWithout-
Format is false here, and since Vulkan 1.3 the per-format bit is what grants
permission, so reporting it while rejecting the pipeline is a contradiction.
gfx7's typed data port ignores SURFTYPE_NULL -- the null surface still has
one addressable texel, which read and wrote graphics address zero. Bounds
check typed image access against the image param when nullDescriptor is
enabled, the same trick lower_image_atomic_instr already used on IVB.
Formats that require a sampler Y'CbCr conversion no longer report
BLIT_SRC/BLIT_DST/STORAGE_IMAGE. Video decode does not need them.
Check the surface state allocations in emit_binding_table() and in the push
descriptor path instead of writing through a NULL map in release builds.
Co-Authored-By: Claude Opus 5 <[email protected]>