mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2026-01-12 00:06:51 +08:00
vulkan_prores: split up shader creation functions
Its more mess that it has to be.
This commit is contained in:
@@ -387,22 +387,24 @@ static int add_push_data(FFVulkanShader *shd)
|
||||
VK_SHADER_STAGE_COMPUTE_BIT);
|
||||
}
|
||||
|
||||
static int init_shader(AVCodecContext *avctx, FFVulkanContext *s,
|
||||
FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
|
||||
FFVulkanShader *shd, const char *name, const char *entrypoint,
|
||||
FFVulkanDescriptorSetBinding *descs, int num_descs,
|
||||
const char *source, int local_size, int interlaced)
|
||||
static int init_decode_shader(AVCodecContext *avctx, FFVulkanContext *s,
|
||||
FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
|
||||
FFVulkanShader *shd, int max_num_mbs,
|
||||
int interlaced)
|
||||
{
|
||||
int err;
|
||||
AVHWFramesContext *dec_frames_ctx;
|
||||
dec_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
|
||||
|
||||
uint8_t *spv_data;
|
||||
size_t spv_len;
|
||||
void *spv_opaque = NULL;
|
||||
int err;
|
||||
|
||||
RET(ff_vk_shader_init(s, shd, name,
|
||||
RET(ff_vk_shader_init(s, shd, "prores_vld",
|
||||
VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
(const char *[]) { "GL_EXT_buffer_reference",
|
||||
"GL_EXT_buffer_reference2" }, 2,
|
||||
local_size >> 16 & 0xff, local_size >> 8 & 0xff, local_size >> 0 & 0xff,
|
||||
8, 8, 1,
|
||||
0));
|
||||
|
||||
av_bprintf(&shd->src, "#define GET_BITS_SMEM %d\n", 4);
|
||||
@@ -410,20 +412,110 @@ static int init_shader(AVCodecContext *avctx, FFVulkanContext *s,
|
||||
if (interlaced)
|
||||
av_bprintf(&shd->src, "#define INTERLACED\n");
|
||||
|
||||
/* Common code */
|
||||
/* Common codec header */
|
||||
GLSLD(ff_source_common_comp);
|
||||
|
||||
/* Push constants layout */
|
||||
RET(add_push_data(shd));
|
||||
|
||||
RET(ff_vk_shader_add_descriptor_set(s, shd, descs, num_descs, 0, 0));
|
||||
FFVulkanDescriptorSetBinding desc_set[] = {
|
||||
{
|
||||
.name = "slice_offsets_buf",
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
.mem_quali = "readonly",
|
||||
.buf_content = "uint32_t slice_offsets",
|
||||
.buf_elems = max_num_mbs + 1,
|
||||
},
|
||||
{
|
||||
.name = "quant_idx_buf",
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
.mem_quali = "writeonly",
|
||||
.buf_content = "uint8_t quant_idx",
|
||||
.buf_elems = max_num_mbs,
|
||||
},
|
||||
{
|
||||
.name = "dst",
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
.dimensions = 2,
|
||||
.mem_layout = ff_vk_shader_rep_fmt(dec_frames_ctx->sw_format,
|
||||
FF_VK_REP_NATIVE),
|
||||
.mem_quali = "writeonly",
|
||||
.elems = av_pix_fmt_count_planes(dec_frames_ctx->sw_format),
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
},
|
||||
};
|
||||
RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3, 0, 0));
|
||||
|
||||
/* Main code */
|
||||
GLSLD(source);
|
||||
GLSLD(ff_source_prores_vld_comp);
|
||||
|
||||
RET(spv->compile_shader(s, spv, shd, &spv_data, &spv_len, entrypoint,
|
||||
RET(spv->compile_shader(s, spv, shd, &spv_data, &spv_len, "main",
|
||||
&spv_opaque));
|
||||
RET(ff_vk_shader_link(s, shd, spv_data, spv_len, entrypoint));
|
||||
RET(ff_vk_shader_link(s, shd, spv_data, spv_len, "main"));
|
||||
|
||||
RET(ff_vk_shader_register_exec(s, pool, shd));
|
||||
|
||||
fail:
|
||||
if (spv_opaque)
|
||||
spv->free_shader(spv, &spv_opaque);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init_idct_shader(AVCodecContext *avctx, FFVulkanContext *s,
|
||||
FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
|
||||
FFVulkanShader *shd, int max_num_mbs,
|
||||
int interlaced)
|
||||
{
|
||||
int err;
|
||||
AVHWFramesContext *dec_frames_ctx;
|
||||
dec_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
|
||||
|
||||
uint8_t *spv_data;
|
||||
size_t spv_len;
|
||||
void *spv_opaque = NULL;
|
||||
|
||||
RET(ff_vk_shader_init(s, shd, "prores_idct",
|
||||
VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
(const char *[]) { "GL_EXT_buffer_reference",
|
||||
"GL_EXT_buffer_reference2" }, 2,
|
||||
32, 2, 1,
|
||||
0));
|
||||
|
||||
if (interlaced)
|
||||
av_bprintf(&shd->src, "#define INTERLACED\n");
|
||||
|
||||
/* Common codec header */
|
||||
GLSLD(ff_source_common_comp);
|
||||
|
||||
RET(add_push_data(shd));
|
||||
|
||||
FFVulkanDescriptorSetBinding desc_set[] = {
|
||||
{
|
||||
.name = "quant_idx_buf",
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
.mem_quali = "readonly",
|
||||
.buf_content = "uint8_t quant_idx",
|
||||
.buf_elems = max_num_mbs,
|
||||
},
|
||||
{
|
||||
.name = "dst",
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
.dimensions = 2,
|
||||
.mem_layout = ff_vk_shader_rep_fmt(dec_frames_ctx->sw_format,
|
||||
FF_VK_REP_NATIVE),
|
||||
.elems = av_pix_fmt_count_planes(dec_frames_ctx->sw_format),
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
},
|
||||
};
|
||||
RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2, 0, 0));
|
||||
|
||||
GLSLD(ff_source_prores_idct_comp);
|
||||
|
||||
RET(spv->compile_shader(s, spv, shd, &spv_data, &spv_len, "main",
|
||||
&spv_opaque));
|
||||
RET(ff_vk_shader_link(s, shd, spv_data, spv_len, "main"));
|
||||
|
||||
RET(ff_vk_shader_register_exec(s, pool, shd));
|
||||
|
||||
@@ -452,10 +544,8 @@ static int vk_decode_prores_init(AVCodecContext *avctx)
|
||||
FFVulkanDecodeShared *ctx = NULL;
|
||||
ProresContext *pr = avctx->priv_data;
|
||||
|
||||
AVHWFramesContext *out_frames_ctx;
|
||||
ProresVulkanDecodeContext *pv;
|
||||
FFVkSPIRVCompiler *spv;
|
||||
FFVulkanDescriptorSetBinding *desc_set;
|
||||
int max_num_mbs, err;
|
||||
|
||||
max_num_mbs = (avctx->coded_width >> 4) * (avctx->coded_height >> 4);
|
||||
@@ -477,64 +567,12 @@ static int vk_decode_prores_init(AVCodecContext *avctx)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
out_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
|
||||
|
||||
ctx->sd_ctx_free = vk_decode_prores_uninit;
|
||||
|
||||
desc_set = (FFVulkanDescriptorSetBinding []) {
|
||||
{
|
||||
.name = "slice_offsets_buf",
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
.mem_quali = "readonly",
|
||||
.buf_content = "uint32_t slice_offsets",
|
||||
.buf_elems = max_num_mbs + 1,
|
||||
},
|
||||
{
|
||||
.name = "quant_idx_buf",
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
.mem_quali = "writeonly",
|
||||
.buf_content = "uint8_t quant_idx",
|
||||
.buf_elems = max_num_mbs,
|
||||
},
|
||||
{
|
||||
.name = "dst",
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
.dimensions = 2,
|
||||
.mem_layout = ff_vk_shader_rep_fmt(out_frames_ctx->sw_format,
|
||||
FF_VK_REP_NATIVE),
|
||||
.mem_quali = "writeonly",
|
||||
.elems = av_pix_fmt_count_planes(out_frames_ctx->sw_format),
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
},
|
||||
};
|
||||
RET(init_shader(avctx, &ctx->s, &ctx->exec_pool, spv, &pv->vld,
|
||||
"prores_dec_vld", "main", desc_set, 3,
|
||||
ff_source_prores_vld_comp, 0x080801, pr->frame_type != 0));
|
||||
|
||||
desc_set = (FFVulkanDescriptorSetBinding []) {
|
||||
{
|
||||
.name = "quant_idx_buf",
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
.mem_quali = "readonly",
|
||||
.buf_content = "uint8_t quant_idx",
|
||||
.buf_elems = max_num_mbs,
|
||||
},
|
||||
{
|
||||
.name = "dst",
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
.dimensions = 2,
|
||||
.mem_layout = ff_vk_shader_rep_fmt(out_frames_ctx->sw_format,
|
||||
FF_VK_REP_NATIVE),
|
||||
.elems = av_pix_fmt_count_planes(out_frames_ctx->sw_format),
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
},
|
||||
};
|
||||
RET(init_shader(avctx, &ctx->s, &ctx->exec_pool, spv, &pv->idct,
|
||||
"prores_dec_idct", "main", desc_set, 2,
|
||||
ff_source_prores_idct_comp, 0x200201, pr->frame_type != 0));
|
||||
RET(init_decode_shader(avctx, &ctx->s, &ctx->exec_pool,
|
||||
spv, &pv->vld, max_num_mbs, pr->frame_type != 0));
|
||||
RET(init_idct_shader(avctx, &ctx->s, &ctx->exec_pool,
|
||||
spv, &pv->idct, max_num_mbs, pr->frame_type != 0));
|
||||
|
||||
err = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user