radv/video: Move probability table filling to bind

We should not manipulate the session buffers at command recording time.
It shouldn't cause any problems as these initialized probability tables
are not modified by firmware, but moving these to bind time should be
safer and also faster if an application frequently RESETs.

Reviewed-by: David Rosca <david.rosca@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38926>
This commit is contained in:
Benjamin Cheng
2025-12-11 19:43:08 -05:00
committed by Marge Bot
parent 3bddd2eaed
commit 59f821218c
3 changed files with 29 additions and 28 deletions
+17 -12
View File
@@ -1458,6 +1458,7 @@ radv_BindVideoSessionMemoryKHR(VkDevice _device, VkVideoSessionKHR videoSession,
const VkBindVideoSessionMemoryInfoKHR *pBindSessionMemoryInfos)
{
VK_FROM_HANDLE(radv_video_session, vid, videoSession);
struct radv_device *device = radv_device_from_handle(_device);
for (unsigned i = 0; i < videoSessionBindMemoryCount; i++) {
switch (pBindSessionMemoryInfos[i].memoryBindIndex) {
@@ -1466,6 +1467,22 @@ radv_BindVideoSessionMemoryKHR(VkDevice _device, VkVideoSessionKHR videoSession,
break;
case RADV_BIND_DECODER_CTX:
copy_bind(&vid->ctx, &pBindSessionMemoryInfos[i]);
if (vid->encode) {
radv_video_enc_init_ctx(device, vid);
} else {
if (vid->stream_type == RDECODE_CODEC_VP9) {
uint8_t *ctxptr = radv_buffer_map(device->ws, vid->ctx.mem->bo);
ctxptr += vid->ctx.offset;
ac_vcn_vp9_fill_probs_table(ctxptr);
device->ws->buffer_unmap(device->ws, vid->ctx.mem->bo, false);
} else if (vid->stream_type == RDECODE_CODEC_AV1) {
uint8_t *ctxptr = radv_buffer_map(device->ws, vid->ctx.mem->bo);
ctxptr += vid->ctx.offset;
ac_vcn_av1_init_probs(radv_device_physical(device)->av1_version, ctxptr);
device->ws->buffer_unmap(device->ws, vid->ctx.mem->bo, false);
}
}
break;
case RADV_BIND_INTRA_ONLY: {
VkBindImageMemoryInfo bind_image = {
@@ -3253,18 +3270,6 @@ radv_vcn_cmd_reset(struct radv_cmd_buffer *cmd_buffer)
void *ptr;
uint32_t out_offset;
if (vid->stream_type == RDECODE_CODEC_VP9) {
uint8_t *ctxptr = radv_buffer_map(device->ws, vid->ctx.mem->bo);
ctxptr += vid->ctx.offset;
ac_vcn_vp9_fill_probs_table(ctxptr);
device->ws->buffer_unmap(device->ws, vid->ctx.mem->bo, false);
}
if (vid->stream_type == RDECODE_CODEC_AV1) {
uint8_t *ctxptr = radv_buffer_map(device->ws, vid->ctx.mem->bo);
ctxptr += vid->ctx.offset;
ac_vcn_av1_init_probs(pdev->av1_version, ctxptr);
device->ws->buffer_unmap(device->ws, vid->ctx.mem->bo, false);
}
radv_vid_buffer_upload_alloc(cmd_buffer, size, &out_offset, &ptr);
if (pdev->vid_decode_ip == AMD_IP_VCN_UNIFIED)
+1
View File
@@ -90,6 +90,7 @@ void radv_vcn_write_memory(struct radv_cmd_buffer *cmd_buffer, uint64_t va, unsi
void radv_init_physical_device_encoder(struct radv_physical_device *pdevice);
void radv_probe_video_decode(struct radv_physical_device *pdev);
void radv_probe_video_encode(struct radv_physical_device *pdev);
void radv_video_enc_init_ctx(struct radv_device *device, struct radv_video_session *vid);
void radv_video_enc_control_video_coding(struct radv_cmd_buffer *cmd_buffer,
const VkVideoCodingControlInfoKHR *pCodingControlInfo);
void radv_video_enc_begin_video_coding(struct radv_cmd_buffer *cmd_buffer, const VkVideoBeginCodingInfoKHR *pBeginInfo);
+11 -16
View File
@@ -3025,6 +3025,17 @@ radv_vcn_encode_video(struct radv_cmd_buffer *cmd_buffer, const VkVideoEncodeInf
}
}
void
radv_video_enc_init_ctx(struct radv_device *device, struct radv_video_session *vid)
{
if (vid->enc_standard == RENCODE_ENCODE_STANDARD_AV1) {
uint8_t *cdfptr = radv_buffer_map(device->ws, vid->ctx.mem->bo);
cdfptr += vid->ctx.offset;
memcpy(cdfptr, rvcn_av1_cdf_default_table, VCN_ENC_AV1_DEFAULT_CDF_SIZE);
device->ws->buffer_unmap(device->ws, vid->ctx.mem->bo, false);
}
}
void
radv_video_enc_control_video_coding(struct radv_cmd_buffer *cmd_buffer, const VkVideoCodingControlInfoKHR *control_info)
{
@@ -3032,22 +3043,6 @@ radv_video_enc_control_video_coding(struct radv_cmd_buffer *cmd_buffer, const Vk
struct radv_physical_device *pdev = radv_device_physical(device);
struct radv_video_session *vid = cmd_buffer->video.vid;
switch (vid->vk.op) {
case VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_KHR:
case VK_VIDEO_CODEC_OPERATION_ENCODE_H265_BIT_KHR:
break;
case VK_VIDEO_CODEC_OPERATION_ENCODE_AV1_BIT_KHR:
if (control_info->flags & VK_VIDEO_CODING_CONTROL_RESET_BIT_KHR) {
uint8_t *cdfptr = radv_buffer_map(device->ws, vid->ctx.mem->bo);
cdfptr += vid->ctx.offset;
memcpy(cdfptr, rvcn_av1_cdf_default_table, VCN_ENC_AV1_DEFAULT_CDF_SIZE);
device->ws->buffer_unmap(device->ws, vid->ctx.mem->bo, false);
}
break;
default:
UNREACHABLE("Unsupported\n");
}
bool session_init = false;
bool rate_control_init = false;
uint32_t vbv_buffer_level = 64;