History

avfilter/scale_cuda: add support for rgb32/bgr32 conversions

As we are introducing two new formats and supporting conversions between them, and also with the existing 0rgb32/0bgr32 formats, we get a combinatorial explosion of kernels. I introduced a few new macros to keep the things mostly managable. The conversions are all simple, following existing patterns, with four specific exceptions. When converting from 0rgb32/0bgr32 to rgb32/bgr32, we need to ensure the alpha value is set to 1. In all other cases, it can just be passed through, either to be used or ignored.

Philip Langdale committed 3 years ago

Commit 3c07c241 parent f42df833 files · +123 −32Browse files

Unified · Split

3 files
  1. libavfilter/version.h +1 −1
  2. libavfilter/vf_scale_cuda.c +2 −0
  3. libavfilter/vf_scale_cuda.cu +120 −31
libavfilter/version.h+1−1
@@ -32,7 +32,7 @@ · 31 unmodified lines
3232 #include "version_major.h"
3333
3434 #define LIBAVFILTER_VERSION_MINOR 8
35−#define LIBAVFILTER_VERSION_MICRO 101
35+#define LIBAVFILTER_VERSION_MICRO 102
3636
3737
3838 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
libavfilter/vf_scale_cuda.c+2−0
@@ -51,6 +51,8 @@ static const enum AVPixelFormat supported_formats[] = { · 50 unmodified lines
5151 AV_PIX_FMT_YUV444P16,
5252 AV_PIX_FMT_0RGB32,
5353 AV_PIX_FMT_0BGR32,
54+ AV_PIX_FMT_RGB32,
55+ AV_PIX_FMT_BGR32,
5456 };
5557
5658 #define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
libavfilter/vf_scale_cuda.cu+120−31
@@ -853,9 +853,67 @@ struct Convert_yuv444p16le_yuv444p16le · 852 unmodified lines
853853 }
854854 };
855855
856−// bgr0->X
857−
858−struct Convert_bgr0_bgr0
856+#define DEF_CONVERT_IDENTITY(fmt1, fmt2)\
857+ \
858+struct Convert_##fmt1##_##fmt2 \
859+{ \
860+ static const int in_bit_depth = 8; \
861+ typedef uchar4 in_T; \
862+ typedef uchar in_T_uv; \
863+ typedef uchar4 out_T; \
864+ typedef uchar out_T_uv; \
865+ \
866+ DEF_F(Convert, out_T) \
867+ { \
868+ DEFAULT_DST(0) = SUB_F(y, 0); \
869+ } \
870+ \
871+ DEF_F(Convert_uv, out_T_uv) \
872+ { \
873+ } \
874+}; \
875+
876+#define DEF_CONVERT_REORDER(fmt1, fmt2) \
877+ \
878+struct Convert_##fmt1##_##fmt2 \
879+{ \
880+ static const int in_bit_depth = 8; \
881+ typedef uchar4 in_T; \
882+ typedef uchar in_T_uv; \
883+ typedef uchar4 out_T; \
884+ typedef uchar out_T_uv; \
885+ \
886+ DEF_F(Convert, out_T) \
887+ { \
888+ uchar4 res = SUB_F(y, 0); \
889+ DEFAULT_DST(0) = make_uchar4( \
890+ res.z, \
891+ res.y, \
892+ res.x, \
893+ res.w \
894+ ); \
895+ } \
896+ \
897+ DEF_F(Convert_uv, out_T_uv) \
898+ { \
899+ } \
900+}; \
901+
902+#define DEF_CONVERT_RGB(fmt1, fmt2) \
903+ \
904+DEF_CONVERT_IDENTITY(fmt1, fmt1) \
905+DEF_CONVERT_REORDER (fmt1, fmt2) \
906+DEF_CONVERT_REORDER (fmt2, fmt1) \
907+DEF_CONVERT_IDENTITY(fmt2, fmt2)
908+
909+DEF_CONVERT_RGB(rgb0, bgr0)
910+DEF_CONVERT_RGB(rgba, bgra)
911+DEF_CONVERT_IDENTITY(rgba, rgb0)
912+DEF_CONVERT_IDENTITY(bgra, bgr0)
913+DEF_CONVERT_REORDER(rgba, bgr0)
914+DEF_CONVERT_REORDER(bgra, rgb0)
915+
916+struct Convert_bgr0_bgra
859917 {
860918 static const int in_bit_depth = 8;
861919 typedef uchar4 in_T;
@@ -865,7 +923,13 @@ struct Convert_bgr0_bgr0 · 3 unmodified lines
865923
866924 DEF_F(Convert, out_T)
867925 {
868− DEFAULT_DST(0) = SUB_F(y, 0);
926+ uchar4 res = SUB_F(y, 0);
927+ DEFAULT_DST(0) = make_uchar4(
928+ res.x,
929+ res.y,
930+ res.z,
931+ 1
932+ );
869933 }
870934
871935 DEF_F(Convert_uv, out_T_uv)
@@ -873,7 +937,7 @@ struct Convert_bgr0_bgr0 · 1 unmodified line
873937 }
874938 };
875939
876−struct Convert_bgr0_rgb0
940+struct Convert_bgr0_rgba
877941 {
878942 static const int in_bit_depth = 8;
879943 typedef uchar4 in_T;
@@ -888,7 +952,7 @@ struct Convert_bgr0_rgb0 · 8 unmodified lines
888952 res.z,
889953 res.y,
890954 res.x,
891− res.w
955+ 1
892956 );
893957 }
894958
@@ -897,9 +961,7 @@ struct Convert_bgr0_rgb0 · 2 unmodified lines
897961 }
898962 };
899963
900−// rgb0->X
901−
902−struct Convert_rgb0_bgr0
964+struct Convert_rgb0_bgra
903965 {
904966 static const int in_bit_depth = 8;
905967 typedef uchar4 in_T;
@@ -914,7 +976,7 @@ struct Convert_rgb0_bgr0 · 8 unmodified lines
914976 res.z,
915977 res.y,
916978 res.x,
917− res.w
979+ 1
918980 );
919981 }
920982
@@ -923,7 +985,7 @@ struct Convert_rgb0_bgr0 · 2 unmodified lines
923985 }
924986 };
925987
926−struct Convert_rgb0_rgb0
988+struct Convert_rgb0_rgba
927989 {
928990 static const int in_bit_depth = 8;
929991 typedef uchar4 in_T;
@@ -933,7 +995,13 @@ struct Convert_rgb0_rgb0 · 3 unmodified lines
933995
934996 DEF_F(Convert, out_T)
935997 {
936− DEFAULT_DST(0) = SUB_F(y, 0);
998+ uchar4 res = SUB_F(y, 0);
999+ DEFAULT_DST(0) = make_uchar4(
1000+ res.x,
1001+ res.y,
1002+ res.z,
1003+ 1
1004+ );
9371005 }
9381006
9391007 DEF_F(Convert_uv, out_T_uv)
@@ -1117,6 +1185,12 @@ extern "C" { · 177 unmodified lines
11171185 NEAREST_KERNEL_RAW(p016le_ ## C) \
11181186 NEAREST_KERNEL_RAW(yuv444p16le_ ## C)
11191187
1188+#define NEAREST_KERNELS_RGB(C) \
1189+ NEAREST_KERNEL_RAW(rgb0_ ## C) \
1190+ NEAREST_KERNEL_RAW(bgr0_ ## C) \
1191+ NEAREST_KERNEL_RAW(rgba_ ## C) \
1192+ NEAREST_KERNEL_RAW(bgra_ ## C) \
1193+
11201194 NEAREST_KERNELS(yuv420p)
11211195 NEAREST_KERNELS(nv12)
11221196 NEAREST_KERNELS(yuv444p)
@@ -1124,11 +1198,10 @@ NEAREST_KERNELS(p010le) · 1 unmodified line
11241198 NEAREST_KERNELS(p016le)
11251199 NEAREST_KERNELS(yuv444p16le)
11261200
1127−NEAREST_KERNEL_RAW(bgr0_bgr0)
1128−NEAREST_KERNEL_RAW(rgb0_rgb0)
1129−NEAREST_KERNEL_RAW(bgr0_rgb0)
1130−NEAREST_KERNEL_RAW(rgb0_bgr0)
1131−
1201+NEAREST_KERNELS_RGB(rgb0)
1202+NEAREST_KERNELS_RGB(bgr0)
1203+NEAREST_KERNELS_RGB(rgba)
1204+NEAREST_KERNELS_RGB(bgra)
11321205
11331206 #define BILINEAR_KERNEL(C, S) \
11341207 __global__ void Subsample_Bilinear_##C##S( \
@@ -1152,6 +1225,12 @@ NEAREST_KERNEL_RAW(rgb0_bgr0) · 17 unmodified lines
11521225 BILINEAR_KERNEL_RAW(p016le_ ## C) \
11531226 BILINEAR_KERNEL_RAW(yuv444p16le_ ## C)
11541227
1228+#define BILINEAR_KERNELS_RGB(C) \
1229+ BILINEAR_KERNEL_RAW(rgb0_ ## C) \
1230+ BILINEAR_KERNEL_RAW(bgr0_ ## C) \
1231+ BILINEAR_KERNEL_RAW(rgba_ ## C) \
1232+ BILINEAR_KERNEL_RAW(bgra_ ## C)
1233+
11551234 BILINEAR_KERNELS(yuv420p)
11561235 BILINEAR_KERNELS(nv12)
11571236 BILINEAR_KERNELS(yuv444p)
@@ -1159,10 +1238,10 @@ BILINEAR_KERNELS(p010le) · 1 unmodified line
11591238 BILINEAR_KERNELS(p016le)
11601239 BILINEAR_KERNELS(yuv444p16le)
11611240
1162−BILINEAR_KERNEL_RAW(bgr0_bgr0)
1163−BILINEAR_KERNEL_RAW(rgb0_rgb0)
1164−BILINEAR_KERNEL_RAW(bgr0_rgb0)
1165−BILINEAR_KERNEL_RAW(rgb0_bgr0)
1241+BILINEAR_KERNELS_RGB(rgb0)
1242+BILINEAR_KERNELS_RGB(bgr0)
1243+BILINEAR_KERNELS_RGB(rgba)
1244+BILINEAR_KERNELS_RGB(bgra)
11661245
11671246 #define BICUBIC_KERNEL(C, S) \
11681247 __global__ void Subsample_Bicubic_##C##S( \
@@ -1186,6 +1265,12 @@ BILINEAR_KERNEL_RAW(rgb0_bgr0) · 17 unmodified lines
11861265 BICUBIC_KERNEL_RAW(p016le_ ## C) \
11871266 BICUBIC_KERNEL_RAW(yuv444p16le_ ## C)
11881267
1268+#define BICUBIC_KERNELS_RGB(C) \
1269+ BICUBIC_KERNEL_RAW(rgb0_ ## C) \
1270+ BICUBIC_KERNEL_RAW(bgr0_ ## C) \
1271+ BICUBIC_KERNEL_RAW(rgba_ ## C) \
1272+ BICUBIC_KERNEL_RAW(bgra_ ## C)
1273+
11891274 BICUBIC_KERNELS(yuv420p)
11901275 BICUBIC_KERNELS(nv12)
11911276 BICUBIC_KERNELS(yuv444p)
@@ -1193,11 +1278,10 @@ BICUBIC_KERNELS(p010le) · 1 unmodified line
11931278 BICUBIC_KERNELS(p016le)
11941279 BICUBIC_KERNELS(yuv444p16le)
11951280
1196−BICUBIC_KERNEL_RAW(bgr0_bgr0)
1197−BICUBIC_KERNEL_RAW(rgb0_rgb0)
1198−BICUBIC_KERNEL_RAW(bgr0_rgb0)
1199−BICUBIC_KERNEL_RAW(rgb0_bgr0)
1200−
1281+BICUBIC_KERNELS_RGB(rgb0)
1282+BICUBIC_KERNELS_RGB(bgr0)
1283+BICUBIC_KERNELS_RGB(rgba)
1284+BICUBIC_KERNELS_RGB(bgra)
12011285
12021286 #define LANCZOS_KERNEL(C, S) \
12031287 __global__ void Subsample_Lanczos_##C##S( \
@@ -1221,6 +1305,12 @@ BICUBIC_KERNEL_RAW(rgb0_bgr0) · 17 unmodified lines
12211305 LANCZOS_KERNEL_RAW(p016le_ ## C) \
12221306 LANCZOS_KERNEL_RAW(yuv444p16le_ ## C)
12231307
1308+#define LANCZOS_KERNELS_RGB(C) \
1309+ LANCZOS_KERNEL_RAW(rgb0_ ## C) \
1310+ LANCZOS_KERNEL_RAW(bgr0_ ## C) \
1311+ LANCZOS_KERNEL_RAW(rgba_ ## C) \
1312+ LANCZOS_KERNEL_RAW(bgra_ ## C)
1313+
12241314 LANCZOS_KERNELS(yuv420p)
12251315 LANCZOS_KERNELS(nv12)
12261316 LANCZOS_KERNELS(yuv444p)
@@ -1228,9 +1318,8 @@ LANCZOS_KERNELS(p010le) · 1 unmodified line
12281318 LANCZOS_KERNELS(p016le)
12291319 LANCZOS_KERNELS(yuv444p16le)
12301320
1231−LANCZOS_KERNEL_RAW(bgr0_bgr0)
1232−LANCZOS_KERNEL_RAW(rgb0_rgb0)
1233−LANCZOS_KERNEL_RAW(bgr0_rgb0)
1234−LANCZOS_KERNEL_RAW(rgb0_bgr0)
1235−
1321+LANCZOS_KERNELS_RGB(rgb0)
1322+LANCZOS_KERNELS_RGB(bgr0)
1323+LANCZOS_KERNELS_RGB(rgba)
1324+LANCZOS_KERNELS_RGB(bgra)
12361325 }

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