mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2026-03-13 09:00:40 +08:00
vulkan/ffv1: mark buffers as uniform/readonly when needed
Should be a speedup in most cases.
This commit is contained in:
@@ -85,6 +85,7 @@ static int init_state_transition_data(FFVulkanContext *s,
|
||||
RET(ff_vk_create_buf(s, vkb,
|
||||
buf_len,
|
||||
NULL, NULL,
|
||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT |
|
||||
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
|
||||
|
||||
@@ -793,7 +793,7 @@ static int init_rct_search_shader(AVCodecContext *avctx, VkSpecializationInfo *s
|
||||
|
||||
const FFVulkanDescriptorSetBinding desc_set_const[] = {
|
||||
{ /* rangecoder_buf */
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
},
|
||||
};
|
||||
@@ -836,7 +836,7 @@ static int init_setup_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
|
||||
|
||||
const FFVulkanDescriptorSetBinding desc_set_const[] = {
|
||||
{ /* rangecoder_buf */
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
},
|
||||
};
|
||||
@@ -876,7 +876,7 @@ static int init_reset_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
|
||||
|
||||
const FFVulkanDescriptorSetBinding desc_set_const[] = {
|
||||
{ /* rangecoder_buf */
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
},
|
||||
};
|
||||
@@ -923,7 +923,7 @@ static int init_encode_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
|
||||
|
||||
const FFVulkanDescriptorSetBinding desc_set_const[] = {
|
||||
{ /* rangecoder_buf */
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
},
|
||||
{ /* quant_buf */
|
||||
|
||||
@@ -93,7 +93,15 @@ struct SliceContext {
|
||||
bool slice_reset_contexts;
|
||||
};
|
||||
|
||||
layout (set = 1, binding = 0, scalar) buffer slice_ctx_buf {
|
||||
#if !defined(SB_QUALI)
|
||||
#if (defined(ENCODE) || defined(DECODE))
|
||||
#define SB_QUALI readonly
|
||||
#else
|
||||
#define SB_QUALI
|
||||
#endif
|
||||
#endif
|
||||
|
||||
layout (set = 1, binding = 0, scalar) SB_QUALI buffer slice_ctx_buf {
|
||||
SliceContext slice_ctx[];
|
||||
};
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ layout (set = 1, binding = 3, scalar) buffer slice_state_buf {
|
||||
|
||||
GetBitContext gb;
|
||||
|
||||
void golomb_init(inout SliceContext sc)
|
||||
void golomb_init(void)
|
||||
{
|
||||
if (version == 3 && micro_version > 1 || version > 3)
|
||||
get_rac_internal(rc.range * 129 >> 8);
|
||||
@@ -274,7 +274,7 @@ void writeout_rgb(in SliceContext sc, ivec2 sp, int w, int y, bool apply_rct)
|
||||
}
|
||||
#endif
|
||||
|
||||
void decode_slice(inout SliceContext sc, const uint slice_idx)
|
||||
void decode_slice(in SliceContext sc, uint slice_idx)
|
||||
{
|
||||
int w = sc.slice_dim.x;
|
||||
ivec2 sp = sc.slice_pos;
|
||||
@@ -313,7 +313,7 @@ void decode_slice(inout SliceContext sc, const uint slice_idx)
|
||||
|
||||
#ifdef GOLOMB
|
||||
slice_state_off >>= 3; // division by VLC_STATE_SIZE
|
||||
golomb_init(sc);
|
||||
golomb_init();
|
||||
#endif
|
||||
|
||||
#ifdef RGB
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#pragma shader_stage(compute)
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
#define SB_QUALI readonly
|
||||
#include "common.glsl"
|
||||
#include "ffv1_common.glsl"
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@ void put_symbol(uint state_off, int v)
|
||||
if (is_nil)
|
||||
return;
|
||||
|
||||
const int a = abs(v);
|
||||
const int e = findMSB(a);
|
||||
int a = abs(v);
|
||||
int e = findMSB(a);
|
||||
|
||||
for (int i = 0; i < e; i++)
|
||||
WRITE(1 + min(i, 9), true);
|
||||
@@ -65,7 +65,7 @@ void put_symbol(uint state_off, int v)
|
||||
WRITE(22 - 11 + min(e, 10), v < 0);
|
||||
}
|
||||
|
||||
void encode_line_pcm(inout SliceContext sc, readonly uimage2D img,
|
||||
void encode_line_pcm(in SliceContext sc, readonly uimage2D img,
|
||||
ivec2 sp, int y, int p, int comp)
|
||||
{
|
||||
int w = sc.slice_dim.x;
|
||||
@@ -86,7 +86,7 @@ void encode_line_pcm(inout SliceContext sc, readonly uimage2D img,
|
||||
}
|
||||
}
|
||||
|
||||
void encode_line(inout SliceContext sc, readonly uimage2D img, uint state_off,
|
||||
void encode_line(in SliceContext sc, readonly uimage2D img, uint state_off,
|
||||
ivec2 sp, int y, int p, int comp,
|
||||
uint8_t quant_table_idx, const int run_index)
|
||||
{
|
||||
@@ -124,14 +124,14 @@ layout (set = 1, binding = 2, scalar) buffer slice_state_buf {
|
||||
uint hdr_len = 0;
|
||||
PutBitContext pb;
|
||||
|
||||
void init_golomb(inout SliceContext sc)
|
||||
void init_golomb(void)
|
||||
{
|
||||
hdr_len = rac_terminate(slice_start);
|
||||
init_put_bits(pb, OFFBUF(u8buf, slice_start, hdr_len),
|
||||
slice_size_max - hdr_len);
|
||||
}
|
||||
|
||||
void encode_line(inout SliceContext sc, readonly uimage2D img, uint state_off,
|
||||
void encode_line(in SliceContext sc, readonly uimage2D img, uint state_off,
|
||||
ivec2 sp, int y, int p, int comp,
|
||||
uint8_t quant_table_idx, inout int run_index)
|
||||
{
|
||||
@@ -239,7 +239,7 @@ void preload_rgb(in SliceContext sc, ivec2 sp, int w, int y, bool apply_rct)
|
||||
}
|
||||
#endif
|
||||
|
||||
void encode_slice(inout SliceContext sc, const uint slice_idx)
|
||||
void encode_slice(in SliceContext sc, uint slice_idx)
|
||||
{
|
||||
ivec2 sp = sc.slice_pos;
|
||||
|
||||
@@ -284,7 +284,7 @@ void encode_slice(inout SliceContext sc, const uint slice_idx)
|
||||
|
||||
#ifdef GOLOMB
|
||||
slice_state_off >>= 3;
|
||||
init_golomb(slice_ctx[slice_idx]);
|
||||
init_golomb();
|
||||
#endif
|
||||
|
||||
#ifndef RGB
|
||||
@@ -320,7 +320,7 @@ void encode_slice(inout SliceContext sc, const uint slice_idx)
|
||||
#endif
|
||||
}
|
||||
|
||||
void finalize_slice(inout SliceContext sc, const uint slice_idx)
|
||||
void finalize_slice(const uint slice_idx)
|
||||
{
|
||||
#ifdef GOLOMB
|
||||
uint32_t enc_len = hdr_len + flush_put_bits(pb);
|
||||
@@ -368,5 +368,5 @@ void main(void)
|
||||
|
||||
rc = slice_ctx[slice_idx].c;
|
||||
encode_slice(slice_ctx[slice_idx], slice_idx);
|
||||
finalize_slice(slice_ctx[slice_idx], slice_idx);
|
||||
finalize_slice(slice_idx);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
#define ENCODE
|
||||
#define SB_QUALI
|
||||
#include "common.glsl"
|
||||
#include "ffv1_common.glsl"
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#pragma shader_stage(compute)
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
#define SB_QUALI readonly
|
||||
#include "common.glsl"
|
||||
#include "ffv1_common.glsl"
|
||||
|
||||
|
||||
@@ -26,7 +26,13 @@
|
||||
#define CONTEXT_SIZE 32
|
||||
#define MAX_OVERREAD 2
|
||||
|
||||
layout (set = 0, binding = 0, scalar) readonly buffer rangecoder_buf {
|
||||
#if !defined(GOLOMB) && (defined(DECODE))
|
||||
#define RC_BTYPE readonly buffer
|
||||
#else
|
||||
#define RC_BTYPE uniform
|
||||
#endif
|
||||
|
||||
layout (set = 0, binding = 0, scalar) RC_BTYPE rangecoder_buf {
|
||||
uint8_t zero_one_state[512];
|
||||
};
|
||||
|
||||
|
||||
@@ -519,7 +519,7 @@ static int init_setup_shader(FFV1Context *f, FFVulkanContext *s,
|
||||
|
||||
const FFVulkanDescriptorSetBinding desc_set_const[] = {
|
||||
{ /* rangecoder_buf */
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
},
|
||||
{ /* crc_ieee_buf */
|
||||
@@ -570,7 +570,7 @@ static int init_reset_shader(FFV1Context *f, FFVulkanContext *s,
|
||||
|
||||
const FFVulkanDescriptorSetBinding desc_set_const[] = {
|
||||
{ /* rangecoder_buf */
|
||||
.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user