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
3535 FFVkExecPool e;
3636 AVVulkanDeviceQueueFamily *qf;
3737 FFVulkanShader shd;
38− VkSampler sampler;
3938
4039 /* Push constants / options */
4140 struct {
@@ -55,10 +54,10 @@ static const char overlay_noalpha[] = { · 13 unmodified lines
5554 C(1, if ((o_offset[i].x <= pos.x) && (o_offset[i].y <= pos.y) &&
5655 (pos.x < (o_offset[i].x + o_size[i].x)) &&
5756 (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]); )
5958 C(2, imageStore(output_img[i], pos, res); )
6059 C(1, } else { )
61− C(2, vec4 res = texture(main_img[i], pos); )
60+ C(2, vec4 res = imageLoad(main_img[i], pos); )
6261 C(2, imageStore(output_img[i], pos, res); )
6362 C(1, } )
6463 C(0, } )
@@ -67,11 +66,11 @@ static const char overlay_noalpha[] = { · 2 unmodified lines
6766 static const char overlay_alpha[] = {
6867 C(0, void overlay_alpha_opaque(int i, ivec2 pos) )
6968 C(0, { )
70− C(1, vec4 res = texture(main_img[i], pos); )
69+ C(1, vec4 res = imageLoad(main_img[i], pos); )
7170 C(1, if ((o_offset[i].x <= pos.x) && (o_offset[i].y <= pos.y) &&
7271 (pos.x < (o_offset[i].x + o_size[i].x)) &&
7372 (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]); )
7574 C(2, res = ovr * ovr.a + res * (1.0f - ovr.a); )
7675 C(2, res.a = 1.0f; )
7776 C(2, imageStore(output_img[i], pos, res); )
@@ -109,7 +108,6 @@ static av_cold int init_filter(AVFilterContext *ctx) · 31 unmodified lines
109108 }
110109
111110 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));
113111 RET(ff_vk_shader_init(vkctx, &s->shd, "overlay",
114112 VK_SHADER_STAGE_COMPUTE_BIT,
115113 NULL, 0,
@@ -128,19 +126,21 @@ static av_cold int init_filter(AVFilterContext *ctx) · 12 unmodified lines
128126 desc = (FFVulkanDescriptorSetBinding []) {
129127 {
130128 .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",
132132 .dimensions = 2,
133133 .elems = planes,
134134 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
135− .samplers = DUP_SAMPLER(s->sampler),
136135 },
137136 {
138137 .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",
140141 .dimensions = 2,
141142 .elems = planes,
142143 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
143− .samplers = DUP_SAMPLER(s->sampler),
144144 },
145145 {
146146 .name = "output_img",
@@ -240,7 +240,7 @@ static int overlay_vulkan_blend(FFFrameSync *fs) · 93 unmodified lines
240240
241241 RET(ff_vk_filter_process_Nin(&s->vkctx, &s->e, &s->shd,
242242 out, (AVFrame *[]){ input_main, input_overlay }, 2,
243− s->sampler, &s->opts, sizeof(s->opts)));
243+ VK_NULL_HANDLE, &s->opts, sizeof(s->opts)));
244244
245245 err = av_frame_copy_props(out, input_main);
246246 if (err < 0)
@@ -295,10 +295,6 @@ static void overlay_vulkan_uninit(AVFilterContext *avctx) · 48 unmodified lines
295295 ff_vk_exec_pool_free(vkctx, &s->e);
296296 ff_vk_shader_free(vkctx, &s->shd);
297297
298− if (s->sampler)
299− vk->DestroySampler(vkctx->hwctx->act_dev, s->sampler,
300− vkctx->hwctx->alloc);
301−
302298 ff_vk_uninit(&s->vkctx);
303299 ff_framesync_uninit(&s->fs);
304300

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