We need at least a few bits of entropy to determine the start index of each queue, in order to let filters run in parallel as much as possible, and rand() is not thread safe and disrupts any external API's usage of rand, so instead replace it with av_get_random_seed. While it has more overhead than rand, we only run it once per filter upon init.
Showing the changes to libavfilter (4 of 4 files). Show all
Unified · Split
| @@ -16,6 +16,7 @@ · 15 unmodified lines | |||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ | 17 | */ |
| 18 | 18 | ||
| 19 | #include "libavutil/random_seed.h" | ||
| 19 | #include "libavutil/opt.h" | 20 | #include "libavutil/opt.h" |
| 20 | #include "vulkan.h" | 21 | #include "vulkan.h" |
| 21 | #include "internal.h" | 22 | #include "internal.h" |
| @@ -99,7 +100,7 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 77 unmodified lines | |||
| 99 | 100 | ||
| 100 | s->vkctx.queue_family_idx = s->vkctx.hwctx->queue_family_comp_index; | 101 | s->vkctx.queue_family_idx = s->vkctx.hwctx->queue_family_comp_index; |
| 101 | s->vkctx.queue_count = GET_QUEUE_COUNT(s->vkctx.hwctx, 0, 1, 0); | 102 | s->vkctx.queue_count = GET_QUEUE_COUNT(s->vkctx.hwctx, 0, 1, 0); |
| 102 | s->vkctx.cur_queue_idx = rand() % s->vkctx.queue_count; | 103 | s->vkctx.cur_queue_idx = av_get_random_seed() % s->vkctx.queue_count; |
| 103 | 104 | ||
| 104 | { /* Create shader for the horizontal pass */ | 105 | { /* Create shader for the horizontal pass */ |
| 105 | desc_i[0].updater = s->input_images; | 106 | desc_i[0].updater = s->input_images; |
| @@ -16,6 +16,7 @@ · 15 unmodified lines | |||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ | 17 | */ |
| 18 | 18 | ||
| 19 | #include "libavutil/random_seed.h" | ||
| 19 | #include "libavutil/opt.h" | 20 | #include "libavutil/opt.h" |
| 20 | #include "vulkan.h" | 21 | #include "vulkan.h" |
| 21 | #include "internal.h" | 22 | #include "internal.h" |
| @@ -75,7 +76,7 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 53 unmodified lines | |||
| 75 | 76 | ||
| 76 | s->vkctx.queue_family_idx = s->vkctx.hwctx->queue_family_comp_index; | 77 | s->vkctx.queue_family_idx = s->vkctx.hwctx->queue_family_comp_index; |
| 77 | s->vkctx.queue_count = GET_QUEUE_COUNT(s->vkctx.hwctx, 0, 1, 0); | 78 | s->vkctx.queue_count = GET_QUEUE_COUNT(s->vkctx.hwctx, 0, 1, 0); |
| 78 | s->vkctx.cur_queue_idx = rand() % s->vkctx.queue_count; | 79 | s->vkctx.cur_queue_idx = av_get_random_seed() % s->vkctx.queue_count; |
| 79 | 80 | ||
| 80 | s->pl = ff_vk_create_pipeline(ctx); | 81 | s->pl = ff_vk_create_pipeline(ctx); |
| 81 | if (!s->pl) | 82 | if (!s->pl) |
| @@ -16,6 +16,7 @@ · 15 unmodified lines | |||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ | 17 | */ |
| 18 | 18 | ||
| 19 | #include "libavutil/random_seed.h" | ||
| 19 | #include "libavutil/opt.h" | 20 | #include "libavutil/opt.h" |
| 20 | #include "vulkan.h" | 21 | #include "vulkan.h" |
| 21 | #include "internal.h" | 22 | #include "internal.h" |
| @@ -89,7 +90,7 @@ static av_cold int init_filter(AVFilterContext *ctx) · 67 unmodified lines | |||
| 89 | 90 | ||
| 90 | s->vkctx.queue_family_idx = s->vkctx.hwctx->queue_family_comp_index; | 91 | s->vkctx.queue_family_idx = s->vkctx.hwctx->queue_family_comp_index; |
| 91 | s->vkctx.queue_count = GET_QUEUE_COUNT(s->vkctx.hwctx, 0, 1, 0); | 92 | s->vkctx.queue_count = GET_QUEUE_COUNT(s->vkctx.hwctx, 0, 1, 0); |
| 92 | s->vkctx.cur_queue_idx = rand() % s->vkctx.queue_count; | 93 | s->vkctx.cur_queue_idx = av_get_random_seed() % s->vkctx.queue_count; |
| 93 | 94 | ||
| 94 | { /* Create the shader */ | 95 | { /* Create the shader */ |
| 95 | const int planes = av_pix_fmt_count_planes(s->vkctx.output_format); | 96 | const int planes = av_pix_fmt_count_planes(s->vkctx.output_format); |
| @@ -16,6 +16,7 @@ · 15 unmodified lines | |||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ | 17 | */ |
| 18 | 18 | ||
| 19 | #include "libavutil/random_seed.h" | ||
| 19 | #include "libavutil/opt.h" | 20 | #include "libavutil/opt.h" |
| 20 | #include "vulkan.h" | 21 | #include "vulkan.h" |
| 21 | #include "scale_eval.h" | 22 | #include "scale_eval.h" |
| @@ -117,7 +118,7 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 95 unmodified lines | |||
| 117 | 118 | ||
| 118 | s->vkctx.queue_family_idx = s->vkctx.hwctx->queue_family_comp_index; | 119 | s->vkctx.queue_family_idx = s->vkctx.hwctx->queue_family_comp_index; |
| 119 | s->vkctx.queue_count = GET_QUEUE_COUNT(s->vkctx.hwctx, 0, 1, 0); | 120 | s->vkctx.queue_count = GET_QUEUE_COUNT(s->vkctx.hwctx, 0, 1, 0); |
| 120 | s->vkctx.cur_queue_idx = rand() % s->vkctx.queue_count; | 121 | s->vkctx.cur_queue_idx = av_get_random_seed() % s->vkctx.queue_count; |
| 121 | 122 | ||
| 122 | switch (s->scaler) { | 123 | switch (s->scaler) { |
| 123 | case F_NEAREST: | 124 | case F_NEAREST: |