History

vulkan_ffv1: pipe through slice decoding status

Lynne committed 1 year ago

Commit 7b45d9c1 parent cb8f4b65 files · +52 −18Browse files

Unified · Split

5 files
  1. libavcodec/vulkan/ffv1_dec.comp +4 −0
  2. libavcodec/vulkan/ffv1_dec_setup.comp +3 −1
  3. libavcodec/vulkan_decode.c +1 −0
  4. libavcodec/vulkan_decode.h +1 −0
  5. libavcodec/vulkan_ffv1.c +43 −17
libavcodec/vulkan/ffv1_dec.comp+4−0
@@ -291,4 +291,8 @@ void main(void) · 290 unmodified lines
291291 {
292292 const uint slice_idx = gl_WorkGroupID.y*gl_NumWorkGroups.x + gl_WorkGroupID.x;
293293 decode_slice(slice_ctx[slice_idx], slice_idx);
294+
295+ uint32_t status = corrupt ? uint32_t(corrupt) : overread;
296+ if (status != 0)
297+ slice_status[2*slice_idx + 1] = status;
294298 }
libavcodec/vulkan/ffv1_dec_setup.comp+3−1
@@ -133,6 +133,8 @@ void main(void) · 132 unmodified lines
133133 for (int i = 0; i < slice_size; i++)
134134 crc = crc_ieee[(crc & 0xFF) ^ uint32_t(bs[i].v)] ^ (crc >> 8);
135135
136− slice_crc_mismatch[slice_idx] = crc;
136+ slice_status[2*slice_idx + 0] = crc;
137137 }
138+
139+ slice_status[2*slice_idx + 1] = corrupt ? uint32_t(corrupt) : overread;
138140 }
libavcodec/vulkan_decode.c+1−0
@@ -142,6 +142,7 @@ static void init_frame(FFVulkanDecodeContext *dec, FFVulkanDecodePicture *vkpic) · 141 unmodified lines
142142
143143 vkpic->destroy_image_view = vk->DestroyImageView;
144144 vkpic->wait_semaphores = vk->WaitSemaphores;
145+ vkpic->invalidate_memory_ranges = vk->InvalidateMappedMemoryRanges;
145146 }
146147
147148 int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic,
libavcodec/vulkan_decode.h+1−0
@@ -114,6 +114,7 @@ typedef struct FFVulkanDecodePicture { · 113 unmodified lines
114114 /* Vulkan functions needed for destruction, as no other context is guaranteed to exist */
115115 PFN_vkWaitSemaphores wait_semaphores;
116116 PFN_vkDestroyImageView destroy_image_view;
117+ PFN_vkInvalidateMappedMemoryRanges invalidate_memory_ranges;
117118 } FFVulkanDecodePicture;
118119
119120 /**
libavcodec/vulkan_ffv1.c+43−17
@@ -221,7 +221,7 @@ static int vk_ffv1_start_frame(AVCodecContext *avctx, · 220 unmodified lines
221221 &fp->slice_status_buf,
222222 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
223223 VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
224− NULL, f->slice_count*sizeof(uint32_t),
224+ NULL, 2*f->slice_count*sizeof(uint32_t),
225225 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
226226 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
227227 if (err < 0)
@@ -408,7 +408,7 @@ static int vk_ffv1_end_frame(AVCodecContext *avctx) · 180 unmodified lines
408408 ff_vk_shader_update_desc_buffer(&ctx->s, exec, &fv->setup,
409409 1, 2, 0,
410410 slice_status,
411− 0, f->slice_count*sizeof(uint32_t),
411+ 0, 2*f->slice_count*sizeof(uint32_t),
412412 VK_FORMAT_UNDEFINED);
413413
414414 ff_vk_exec_bind_shader(&ctx->s, exec, &fv->setup);
@@ -538,10 +538,15 @@ static int vk_ffv1_end_frame(AVCodecContext *avctx) · 123 unmodified lines
538538 1, 1,
539539 VK_IMAGE_LAYOUT_GENERAL,
540540 VK_NULL_HANDLE);
541+ ff_vk_shader_update_desc_buffer(&ctx->s, exec, decode_shader,
542+ 1, 2, 0,
543+ slice_status,
544+ 0, 2*f->slice_count*sizeof(uint32_t),
545+ VK_FORMAT_UNDEFINED);
541546 if (is_rgb)
542547 ff_vk_shader_update_img_array(&ctx->s, exec, decode_shader,
543548 f->picture.f, vp->view.out,
544− 1, 2,
549+ 1, 3,
545550 VK_IMAGE_LAYOUT_GENERAL,
546551 VK_NULL_HANDLE);
547552
@@ -700,8 +705,8 @@ static int init_setup_shader(FFV1Context *f, FFVulkanContext *s, · 152 unmodified lines
700705 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
701706 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
702707 .mem_quali = "writeonly",
703− .buf_content = "uint32_t slice_crc_mismatch",
704− .buf_elems = f->max_slice_count,
708+ .buf_content = "uint32_t slice_status",
709+ .buf_elems = 2*f->max_slice_count,
705710 },
706711 };
707712 RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3, 0, 0));
@@ -895,6 +900,14 @@ static int init_decode_shader(FFV1Context *f, FFVulkanContext *s, · 187 unmodified lines
895900 .elems = av_pix_fmt_count_planes(dec_frames_ctx->sw_format),
896901 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
897902 },
903+ {
904+ .name = "slice_status_buf",
905+ .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
906+ .stages = VK_SHADER_STAGE_COMPUTE_BIT,
907+ .mem_quali = "writeonly",
908+ .buf_content = "uint32_t slice_status",
909+ .buf_elems = 2*f->max_slice_count,
910+ },
898911 {
899912 .name = "dst",
900913 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
@@ -906,7 +919,7 @@ static int init_decode_shader(FFV1Context *f, FFVulkanContext *s, · 5 unmodified lines
906919 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
907920 },
908921 };
909− RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2 + rgb, 0, 0));
922+ RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3 + rgb, 0, 0));
910923
911924 GLSLD(ff_source_ffv1_dec_comp);
912925
@@ -1114,22 +1127,35 @@ fail: · 201 unmodified lines
11141127
11151128 static void vk_ffv1_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
11161129 {
1117− AVHWDeviceContext *hwctx = _hwctx.nc;
1130+ AVHWDeviceContext *dev_ctx = _hwctx.nc;
1131+ AVVulkanDeviceContext *hwctx = dev_ctx->hwctx;
11181132
11191133 FFv1VulkanDecodePicture *fp = data;
11201134 FFVulkanDecodePicture *vp = &fp->vp;
1135+ FFVkBuffer *slice_status = (FFVkBuffer *)fp->slice_status_buf->data;
11211136
1122− ff_vk_decode_free_frame(hwctx, vp);
1137+ ff_vk_decode_free_frame(dev_ctx, vp);
1138+
1139+ /* Invalidate slice/output data if needed */
1140+ if (!(slice_status->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
1141+ VkMappedMemoryRange invalidate_data = {
1142+ .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
1143+ .memory = slice_status->mem,
1144+ .offset = 0,
1145+ .size = 2*fp->slice_num*sizeof(uint32_t),
1146+ };
1147+ vp->invalidate_memory_ranges(hwctx->act_dev,
1148+ 1, &invalidate_data);
1149+ }
11231150
1124− if (fp->crc_checked) {
1125− FFVkBuffer *slice_status = (FFVkBuffer *)fp->slice_status_buf->data;
1126− for (int i = 0; i < fp->slice_num; i++) {
1127− uint32_t crc_res;
1128− crc_res = AV_RN32(slice_status->mapped_mem + i*sizeof(uint32_t));
1129− if (crc_res != 0)
1130− av_log(hwctx, AV_LOG_ERROR, "CRC mismatch in slice %i, res: 0x%x\n",
1131− i, crc_res);
1132− }
1151+ for (int i = 0; i < fp->slice_num; i++) {
1152+ uint32_t crc_res = 0;
1153+ if (fp->crc_checked)
1154+ crc_res = AV_RN32(slice_status->mapped_mem + 2*i*sizeof(uint32_t) + 0);
1155+ uint32_t status = AV_RN32(slice_status->mapped_mem + 2*i*sizeof(uint32_t) + 4);
1156+ if (status || crc_res)
1157+ av_log(dev_ctx, AV_LOG_ERROR, "Slice %i status: 0x%x, CRC 0x%x\n",
1158+ i, status, crc_res);
11331159 }
11341160
11351161 av_buffer_unref(&vp->slices_buf);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t