History

ffv1enc: do not hardcode 1024 slices

Instead use a field where possible and the defined constant when not. Tested by using 4096 slices.

Lynne committed 1 year ago

Commit ab37c7e1 parent 75960ac1 file · +21 −12Browse files

Unified · Split

libavcodec/ffv1enc_vulkan.c+21−12
@@ -1012,6 +1012,7 @@ static int init_rct_search_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv) · 1011 unmodified lines
1012{1012{
1013 int err;1013 int err;
1014 VulkanEncodeFFv1Context *fv = avctx->priv_data;1014 VulkanEncodeFFv1Context *fv = avctx->priv_data;
1015 FFV1Context *f = &fv->ctx;
1015 FFVulkanShader *shd = &fv->rct_search;1016 FFVulkanShader *shd = &fv->rct_search;
1016 FFVulkanDescriptorSetBinding *desc_set;1017 FFVulkanDescriptorSetBinding *desc_set;
1017 1018
@@ -1075,7 +1076,8 @@ static int init_rct_search_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv) · 57 unmodified lines
1075 .name = "slice_data_buf",1076 .name = "slice_data_buf",
1076 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,1077 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1077 .stages = VK_SHADER_STAGE_COMPUTE_BIT,1078 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1078 .buf_content = "SliceContext slice_ctx[1024];",1079 .buf_content = "SliceContext slice_ctx",
1080 .buf_elems = f->max_slice_count,
1079 },1081 },
1080 {1082 {
1081 .name = "src",1083 .name = "src",
@@ -1109,6 +1111,7 @@ static int init_setup_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv) · 27 unmodified lines
1109{1111{
1110 int err;1112 int err;
1111 VulkanEncodeFFv1Context *fv = avctx->priv_data;1113 VulkanEncodeFFv1Context *fv = avctx->priv_data;
1114 FFV1Context *f = &fv->ctx;
1112 FFVulkanShader *shd = &fv->setup;1115 FFVulkanShader *shd = &fv->setup;
1113 FFVulkanDescriptorSetBinding *desc_set;1116 FFVulkanDescriptorSetBinding *desc_set;
1114 1117
@@ -1158,7 +1161,8 @@ static int init_setup_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv) · 43 unmodified lines
1158 .name = "slice_data_buf",1161 .name = "slice_data_buf",
1159 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,1162 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1160 .stages = VK_SHADER_STAGE_COMPUTE_BIT,1163 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1161 .buf_content = "SliceContext slice_ctx[1024];",1164 .buf_content = "SliceContext slice_ctx",
1165 .buf_elems = f->max_slice_count,
1162 },1166 },
1163 {1167 {
1164 .name = "src",1168 .name = "src",
@@ -1192,6 +1196,7 @@ static int init_reset_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv) · 27 unmodified lines
1192{1196{
1193 int err;1197 int err;
1194 VulkanEncodeFFv1Context *fv = avctx->priv_data;1198 VulkanEncodeFFv1Context *fv = avctx->priv_data;
1199 FFV1Context *f = &fv->ctx;
1195 FFVulkanShader *shd = &fv->reset;1200 FFVulkanShader *shd = &fv->reset;
1196 FFVulkanDescriptorSetBinding *desc_set;1201 FFVulkanDescriptorSetBinding *desc_set;
1197 1202
@@ -1254,7 +1259,8 @@ static int init_reset_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv) · 56 unmodified lines
1254 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,1259 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1255 .mem_quali = "readonly",1260 .mem_quali = "readonly",
1256 .stages = VK_SHADER_STAGE_COMPUTE_BIT,1261 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1257 .buf_content = "SliceContext slice_ctx[1024];",1262 .buf_content = "SliceContext slice_ctx",
1263 .buf_elems = f->max_slice_count,
1258 },1264 },
1259 };1265 };
1260 RET(ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 1, 0, 0));1266 RET(ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 1, 0, 0));
@@ -1278,6 +1284,7 @@ static int init_encode_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv) · 17 unmodified lines
1278{1284{
1279 int err;1285 int err;
1280 VulkanEncodeFFv1Context *fv = avctx->priv_data;1286 VulkanEncodeFFv1Context *fv = avctx->priv_data;
1287 FFV1Context *f = &fv->ctx;
1281 FFVulkanShader *shd = &fv->enc;1288 FFVulkanShader *shd = &fv->enc;
1282 FFVulkanDescriptorSetBinding *desc_set;1289 FFVulkanDescriptorSetBinding *desc_set;
1283 1290
@@ -1339,7 +1346,8 @@ static int init_encode_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv) · 55 unmodified lines
1339 .name = "slice_data_buf",1346 .name = "slice_data_buf",
1340 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,1347 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1341 .stages = VK_SHADER_STAGE_COMPUTE_BIT,1348 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1342 .buf_content = "SliceContext slice_ctx[1024];",1349 .buf_content = "SliceContext slice_ctx",
1350 .buf_elems = f->max_slice_count,
1343 },1351 },
1344 {1352 {
1345 .name = "src",1353 .name = "src",
@@ -1483,22 +1491,24 @@ static av_cold int vulkan_encode_ffv1_init(AVCodecContext *avctx) · 137 unmodified lines
1483 f->num_v_slices = 32;1491 f->num_v_slices = 32;
1484 }1492 }
1485 } else if (f->num_h_slices && f->num_v_slices <= 0) {1493 } else if (f->num_h_slices && f->num_v_slices <= 0) {
1486 f->num_v_slices = 1024 / f->num_h_slices;1494 f->num_v_slices = MAX_SLICES / f->num_h_slices;
1487 } else if (f->num_v_slices && f->num_h_slices <= 0) {1495 } else if (f->num_v_slices && f->num_h_slices <= 0) {
1488 f->num_h_slices = 1024 / f->num_v_slices;1496 f->num_h_slices = MAX_SLICES / f->num_v_slices;
1489 }1497 }
1490 1498
1491 f->num_h_slices = FFMIN(f->num_h_slices, avctx->width);1499 f->num_h_slices = FFMIN(f->num_h_slices, avctx->width);
1492 f->num_v_slices = FFMIN(f->num_v_slices, avctx->height);1500 f->num_v_slices = FFMIN(f->num_v_slices, avctx->height);
1493 1501
1494 if (f->num_h_slices * f->num_v_slices > 1024) {1502 if (f->num_h_slices * f->num_v_slices > MAX_SLICES) {
1495 av_log(avctx, AV_LOG_ERROR, "Too many slices (%i), maximum supported "1503 av_log(avctx, AV_LOG_ERROR, "Too many slices (%i), maximum supported "
1496 "by the standard is 1024\n",1504 "by the standard is %i\n",
1497 f->num_h_slices * f->num_v_slices);1505 f->num_h_slices * f->num_v_slices, MAX_SLICES);
1498 return AVERROR_PATCHWELCOME;1506 return AVERROR_PATCHWELCOME;
1499 }1507 }
1500 }1508 }
1501 1509
1510 f->max_slice_count = f->num_h_slices * f->num_v_slices;
1511
1502 if ((err = ff_ffv1_write_extradata(avctx)) < 0)1512 if ((err = ff_ffv1_write_extradata(avctx)) < 0)
1503 return err;1513 return err;
1504 1514
@@ -1707,7 +1717,6 @@ static av_cold int vulkan_encode_ffv1_init(AVCodecContext *avctx) · 202 unmodified lines
1707 for (int i = 0; i < fv->async_depth; i++)1717 for (int i = 0; i < fv->async_depth; i++)
1708 fv->exec_pool.contexts[i].opaque = &fv->exec_ctx_info[i];1718 fv->exec_pool.contexts[i].opaque = &fv->exec_ctx_info[i];
1709 1719
1710 f->max_slice_count = f->num_h_slices * f->num_v_slices;
1711 fv->buf_regions = av_malloc_array(f->max_slice_count, sizeof(*fv->buf_regions));1720 fv->buf_regions = av_malloc_array(f->max_slice_count, sizeof(*fv->buf_regions));
1712 if (!fv->buf_regions)1721 if (!fv->buf_regions)
1713 return AVERROR(ENOMEM);1722 return AVERROR(ENOMEM);
@@ -1783,9 +1792,9 @@ static const AVOption vulkan_encode_ffv1_options[] = { · 69 unmodified lines
1783 { .i64 = QTABLE_GT8BIT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },1792 { .i64 = QTABLE_GT8BIT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },
1784 1793
1785 { "slices_h", "Number of horizontal slices", OFFSET(num_h_slices), AV_OPT_TYPE_INT,1794 { "slices_h", "Number of horizontal slices", OFFSET(num_h_slices), AV_OPT_TYPE_INT,
1786 { .i64 = -1 }, -1, 1024, VE },1795 { .i64 = -1 }, -1, MAX_SLICES, VE },
1787 { "slices_v", "Number of vertical slices", OFFSET(num_v_slices), AV_OPT_TYPE_INT,1796 { "slices_v", "Number of vertical slices", OFFSET(num_v_slices), AV_OPT_TYPE_INT,
1788 { .i64 = -1 }, -1, 1024, VE },1797 { .i64 = -1 }, -1, MAX_SLICES, VE },
1789 1798
1790 { "force_pcm", "Code all slices with no prediction", OFFSET(force_pcm), AV_OPT_TYPE_BOOL,1799 { "force_pcm", "Code all slices with no prediction", OFFSET(force_pcm), AV_OPT_TYPE_BOOL,
1791 { .i64 = 0 }, 0, 1, VE },1800 { .i64 = 0 }, 0, 1, VE },

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