History

overlay_vulkan: port to imageLoad()

Lynne committed 1 year ago

Commit 08e37fa1 parent 2b8d38c1 file · +11 −15Browse files

Unified · Split

libavfilter/vf_overlay_vulkan.c+11−15
@@ -35,7 +35,6 @@ typedef struct OverlayVulkanContext { · 34 unmodified lines
35 FFVkExecPool e;35 FFVkExecPool e;
36 AVVulkanDeviceQueueFamily *qf;36 AVVulkanDeviceQueueFamily *qf;
37 FFVulkanShader shd;37 FFVulkanShader shd;
38 VkSampler sampler;
39 38
40 /* Push constants / options */39 /* Push constants / options */
41 struct {40 struct {
@@ -55,10 +54,10 @@ static const char overlay_noalpha[] = { · 13 unmodified lines
55 C(1, if ((o_offset[i].x <= pos.x) && (o_offset[i].y <= pos.y) &&54 C(1, if ((o_offset[i].x <= pos.x) && (o_offset[i].y <= pos.y) &&
56 (pos.x < (o_offset[i].x + o_size[i].x)) &&55 (pos.x < (o_offset[i].x + o_size[i].x)) &&
57 (pos.y < (o_offset[i].y + o_size[i].y))) { )56 (pos.y < (o_offset[i].y + o_size[i].y))) { )
58 C(2, vec4 res = texture(overlay_img[i], pos - o_offset[i]); )57 C(2, vec4 res = imageLoad(overlay_img[i], pos - o_offset[i]); )
59 C(2, imageStore(output_img[i], pos, res); )58 C(2, imageStore(output_img[i], pos, res); )
60 C(1, } else { )59 C(1, } else { )
61 C(2, vec4 res = texture(main_img[i], pos); )60 C(2, vec4 res = imageLoad(main_img[i], pos); )
62 C(2, imageStore(output_img[i], pos, res); )61 C(2, imageStore(output_img[i], pos, res); )
63 C(1, } )62 C(1, } )
64 C(0, } )63 C(0, } )
@@ -67,11 +66,11 @@ static const char overlay_noalpha[] = { · 2 unmodified lines
67static const char overlay_alpha[] = {66static const char overlay_alpha[] = {
68 C(0, void overlay_alpha_opaque(int i, ivec2 pos) )67 C(0, void overlay_alpha_opaque(int i, ivec2 pos) )
69 C(0, { )68 C(0, { )
70 C(1, vec4 res = texture(main_img[i], pos); )69 C(1, vec4 res = imageLoad(main_img[i], pos); )
71 C(1, if ((o_offset[i].x <= pos.x) && (o_offset[i].y <= pos.y) &&70 C(1, if ((o_offset[i].x <= pos.x) && (o_offset[i].y <= pos.y) &&
72 (pos.x < (o_offset[i].x + o_size[i].x)) &&71 (pos.x < (o_offset[i].x + o_size[i].x)) &&
73 (pos.y < (o_offset[i].y + o_size[i].y))) { )72 (pos.y < (o_offset[i].y + o_size[i].y))) { )
74 C(2, vec4 ovr = texture(overlay_img[i], pos - o_offset[i]); )73 C(2, vec4 ovr = imageLoad(overlay_img[i], pos - o_offset[i]); )
75 C(2, res = ovr * ovr.a + res * (1.0f - ovr.a); )74 C(2, res = ovr * ovr.a + res * (1.0f - ovr.a); )
76 C(2, res.a = 1.0f; )75 C(2, res.a = 1.0f; )
77 C(2, imageStore(output_img[i], pos, res); )76 C(2, imageStore(output_img[i], pos, res); )
@@ -109,7 +108,6 @@ static av_cold int init_filter(AVFilterContext *ctx) · 31 unmodified lines
109 }108 }
110 109
111 RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));110 RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
112 RET(ff_vk_init_sampler(vkctx, &s->sampler, 1, VK_FILTER_NEAREST));
113 RET(ff_vk_shader_init(vkctx, &s->shd, "overlay",111 RET(ff_vk_shader_init(vkctx, &s->shd, "overlay",
114 VK_SHADER_STAGE_COMPUTE_BIT,112 VK_SHADER_STAGE_COMPUTE_BIT,
115 NULL, 0,113 NULL, 0,
@@ -128,19 +126,21 @@ static av_cold int init_filter(AVFilterContext *ctx) · 12 unmodified lines
128 desc = (FFVulkanDescriptorSetBinding []) {126 desc = (FFVulkanDescriptorSetBinding []) {
129 {127 {
130 .name = "main_img",128 .name = "main_img",
131 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,129 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
130 .mem_layout = ff_vk_shader_rep_fmt(s->vkctx.input_format, FF_VK_REP_FLOAT),
131 .mem_quali = "readonly",
132 .dimensions = 2,132 .dimensions = 2,
133 .elems = planes,133 .elems = planes,
134 .stages = VK_SHADER_STAGE_COMPUTE_BIT,134 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
135 .samplers = DUP_SAMPLER(s->sampler),
136 },135 },
137 {136 {
138 .name = "overlay_img",137 .name = "overlay_img",
139 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,138 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
139 .mem_layout = ff_vk_shader_rep_fmt(s->vkctx.input_format, FF_VK_REP_FLOAT),
140 .mem_quali = "readonly",
140 .dimensions = 2,141 .dimensions = 2,
141 .elems = planes,142 .elems = planes,
142 .stages = VK_SHADER_STAGE_COMPUTE_BIT,143 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
143 .samplers = DUP_SAMPLER(s->sampler),
144 },144 },
145 {145 {
146 .name = "output_img",146 .name = "output_img",
@@ -240,7 +240,7 @@ static int overlay_vulkan_blend(FFFrameSync *fs) · 93 unmodified lines
240 240
241 RET(ff_vk_filter_process_Nin(&s->vkctx, &s->e, &s->shd,241 RET(ff_vk_filter_process_Nin(&s->vkctx, &s->e, &s->shd,
242 out, (AVFrame *[]){ input_main, input_overlay }, 2,242 out, (AVFrame *[]){ input_main, input_overlay }, 2,
243 s->sampler, &s->opts, sizeof(s->opts)));243 VK_NULL_HANDLE, &s->opts, sizeof(s->opts)));
244 244
245 err = av_frame_copy_props(out, input_main);245 err = av_frame_copy_props(out, input_main);
246 if (err < 0)246 if (err < 0)
@@ -295,10 +295,6 @@ static void overlay_vulkan_uninit(AVFilterContext *avctx) · 48 unmodified lines
295 ff_vk_exec_pool_free(vkctx, &s->e);295 ff_vk_exec_pool_free(vkctx, &s->e);
296 ff_vk_shader_free(vkctx, &s->shd);296 ff_vk_shader_free(vkctx, &s->shd);
297 297
298 if (s->sampler)
299 vk->DestroySampler(vkctx->hwctx->act_dev, s->sampler,
300 vkctx->hwctx->alloc);
301
302 ff_vk_uninit(&s->vkctx);298 ff_vk_uninit(&s->vkctx);
303 ff_framesync_uninit(&s->fs);299 ff_framesync_uninit(&s->fs);
304 300

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