History

lavfi/vulkan: use av_get_random_seed instead of rand

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.

Lynne committed 6 years ago

Commit 83fa39e1 parent c0f01ea4 files · +8 −4Browse files

Showing the changes to libavfilter (4 of 4 files). Show all

Unified · Split

4 files
  1. libavfilter/vf_avgblur_vulkan.c +2 −1
  2. libavfilter/vf_chromaber_vulkan.c +2 −1
  3. libavfilter/vf_overlay_vulkan.c +2 −1
  4. libavfilter/vf_scale_vulkan.c +2 −1
libavfilter/vf_avgblur_vulkan.c+2−1
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717 */
1818
19+#include "libavutil/random_seed.h"
1920 #include "libavutil/opt.h"
2021 #include "vulkan.h"
2122 #include "internal.h"
@@ -99,7 +100,7 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 77 unmodified lines
99100
100101 s->vkctx.queue_family_idx = s->vkctx.hwctx->queue_family_comp_index;
101102 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;
103104
104105 { /* Create shader for the horizontal pass */
105106 desc_i[0].updater = s->input_images;
libavfilter/vf_chromaber_vulkan.c+2−1
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717 */
1818
19+#include "libavutil/random_seed.h"
1920 #include "libavutil/opt.h"
2021 #include "vulkan.h"
2122 #include "internal.h"
@@ -75,7 +76,7 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 53 unmodified lines
7576
7677 s->vkctx.queue_family_idx = s->vkctx.hwctx->queue_family_comp_index;
7778 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;
7980
8081 s->pl = ff_vk_create_pipeline(ctx);
8182 if (!s->pl)
libavfilter/vf_overlay_vulkan.c+2−1
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717 */
1818
19+#include "libavutil/random_seed.h"
1920 #include "libavutil/opt.h"
2021 #include "vulkan.h"
2122 #include "internal.h"
@@ -89,7 +90,7 @@ static av_cold int init_filter(AVFilterContext *ctx) · 67 unmodified lines
8990
9091 s->vkctx.queue_family_idx = s->vkctx.hwctx->queue_family_comp_index;
9192 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;
9394
9495 { /* Create the shader */
9596 const int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
libavfilter/vf_scale_vulkan.c+2−1
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717 */
1818
19+#include "libavutil/random_seed.h"
1920 #include "libavutil/opt.h"
2021 #include "vulkan.h"
2122 #include "scale_eval.h"
@@ -117,7 +118,7 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 95 unmodified lines
117118
118119 s->vkctx.queue_family_idx = s->vkctx.hwctx->queue_family_comp_index;
119120 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;
121122
122123 switch (s->scaler) {
123124 case F_NEAREST:

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