From b16665dc757aa0f4c4af5afffaa9e683f701f37e Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Sat, 28 Oct 2023 22:38:02 +0900 Subject: [PATCH] d3d11convert: Add support for sampling with anisotropic filter Anisotropic filtering might produce better quality than linear filtering Part-of: --- .../docs/plugins/gst_plugins_cache.json | 5 ++ .../gst-libs/gst/d3d11/gstd3d11converter.cpp | 2 + .../gst-libs/gst/d3d11/gstd3d11converter.h | 1 + .../sys/d3d11/gstd3d11convert.cpp | 77 +------------------ .../sys/d3d11/gstd3d11pluginutils.cpp | 77 +++++++++++++++++++ .../sys/d3d11/gstd3d11pluginutils.h | 13 ++++ 6 files changed, 101 insertions(+), 74 deletions(-) diff --git a/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json b/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json index 093cd78486..6ba83b23fc 100644 --- a/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json +++ b/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json @@ -11036,6 +11036,11 @@ "desc": "Linear minification, point magnification", "name": "linear-minification", "value": "2" + }, + { + "desc": "Anisotropic", + "name": "anisotropic", + "value": "3" } ] }, diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11converter.cpp b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11converter.cpp index 30b838ed5e..8a888ff97a 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11converter.cpp +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11converter.cpp @@ -84,6 +84,8 @@ gst_d3d11_converter_sampler_filter_get_type (void) "D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT", "min-linear-mag-mip-point"}, {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, "D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT", "min-mag-linear-mip-point"}, + {D3D11_FILTER_COMPARISON_ANISOTROPIC, + "D3D11_FILTER_COMPARISON_ANISOTROPIC", "anisotropic"}, {0, nullptr, nullptr}, }; diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11converter.h b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11converter.h index 2cf129df93..95312deb59 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11converter.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11converter.h @@ -90,6 +90,7 @@ GType gst_d3d11_converter_backend_get_type (void); * @D3D11_FILTER_MIN_MAG_MIP_POINT * @D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT * @D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT + * @D3D11_FILTER_COMPARISON_ANISOTROPIC, * * Default is #D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT. * diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11convert.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11convert.cpp index c62d67f79e..9a8630572f 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11convert.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11convert.cpp @@ -48,76 +48,6 @@ static GstStaticCaps src_template_caps = GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, GST_D3D11_SRC_FORMATS)); -/** - * GstD3D11SamplingMethod: - * - * Texture sampling method - * - * Since: 1.24 - */ -typedef enum -{ - GST_D3D11_SAMPLING_METHOD_NEAREST, - GST_D3D11_SAMPLING_METHOD_BILINEAR, - GST_D3D11_SAMPLING_METHOD_LINEAR_MINIFICATION, -} GstD3D11SamplingMethod; - -static const GEnumValue gst_d3d11_sampling_methods[] = { - /** - * GstD3D11SamplingMethod::nearest-neighbour: - * - * Since: 1.24 - */ - {GST_D3D11_SAMPLING_METHOD_NEAREST, - "Nearest Neighbour", "nearest-neighbour"}, - - /** - * GstD3D11SamplingMethod::bilinear: - * - * Since: 1.24 - */ - {GST_D3D11_SAMPLING_METHOD_BILINEAR, - "Bilinear", "bilinear"}, - - /** - * GstD3D11SamplingMethod::linear-minification: - * - * Since: 1.24 - */ - {GST_D3D11_SAMPLING_METHOD_LINEAR_MINIFICATION, - "Linear minification, point magnification", "linear-minification"}, - {0, nullptr, nullptr}, -}; - -#define GST_TYPE_D3D11_SAMPLING_METHOD gst_d3d11_sampling_method_get_type() -static GType -gst_d3d11_sampling_method_get_type (void) -{ - static GType type = 0; - - GST_D3D11_CALL_ONCE_BEGIN { - type = g_enum_register_static ("GstD3D11SamplingMethod", - gst_d3d11_sampling_methods); - } GST_D3D11_CALL_ONCE_END; - - return type; -} - -static D3D11_FILTER -gst_d3d11_base_convert_sampling_method_to_filter (GstD3D11SamplingMethod method) -{ - static const D3D11_FILTER filters[] = { - D3D11_FILTER_MIN_MAG_MIP_POINT, // GST_D3D11_SAMPLING_METHOD_NEAREST - D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, // GST_D3D11_SAMPLING_METHOD_BILINEAR - D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, // GST_D3D11_SAMPLING_METHOD_LINEAR_MINIFICATION - }; - - G_STATIC_ASSERT_EXPR (G_N_ELEMENTS (filters) == - G_N_ELEMENTS (gst_d3d11_sampling_methods) - 1); - - return filters[method]; -} - #define DEFAULT_ADD_BORDERS TRUE #define DEFAULT_BORDER_COLOR G_GUINT64_CONSTANT(0xffff000000000000) #define DEFAULT_GAMMA_MODE GST_VIDEO_GAMMA_MODE_NONE @@ -1863,7 +1793,7 @@ gst_d3d11_base_convert_set_info (GstD3D11BaseFilter * filter, GST_TYPE_VIDEO_PRIMARIES_MODE, self->active_primaries_mode, GST_D3D11_CONVERTER_OPT_SAMPLER_FILTER, GST_TYPE_D3D11_CONVERTER_SAMPLER_FILTER, - gst_d3d11_base_convert_sampling_method_to_filter + gst_d3d11_sampling_method_to_native (self->active_sampling_method), GST_D3D11_CONVERTER_OPT_SRC_ALPHA_MODE, GST_TYPE_D3D11_CONVERTER_ALPHA_MODE, @@ -2451,9 +2381,8 @@ gst_d3d11_base_convert_set_sampling_method (GstD3D11BaseConvert * self, { GstD3D11SRWLockGuard lk (&self->lock); - GST_DEBUG_OBJECT (self, "Sampling method %s -> %s", - gst_d3d11_sampling_methods[self->sampling_method].value_nick, - gst_d3d11_sampling_methods[method].value_nick); + GST_DEBUG_OBJECT (self, + "Sampling method %d -> %d", self->sampling_method, method); self->sampling_method = method; if (self->sampling_method != self->active_sampling_method) diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp index 7ce07dc8cd..5fb0b9a76f 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp @@ -106,6 +106,58 @@ gst_d3d11_msaa_mode_get_type (void) return type; } +/** + * GstD3D11SamplingMethod: + * + * Texture sampling method + * + * Since: 1.24 + */ +GType +gst_d3d11_sampling_method_get_type (void) +{ + static GType type = 0; + static const GEnumValue methods[] = { + /** + * GstD3D11SamplingMethod::nearest-neighbour: + * + * Since: 1.24 + */ + {GST_D3D11_SAMPLING_METHOD_NEAREST, + "Nearest Neighbour", "nearest-neighbour"}, + + /** + * GstD3D11SamplingMethod::bilinear: + * + * Since: 1.24 + */ + {GST_D3D11_SAMPLING_METHOD_BILINEAR, + "Bilinear", "bilinear"}, + + /** + * GstD3D11SamplingMethod::linear-minification: + * + * Since: 1.24 + */ + {GST_D3D11_SAMPLING_METHOD_LINEAR_MINIFICATION, + "Linear minification, point magnification", "linear-minification"}, + + /** + * GstD3D11SamplingMethod::anisotropic: + * + * Since: 1.24 + */ + {GST_D3D11_SAMPLING_METHOD_ANISOTROPIC, "Anisotropic", "anisotropic"}, + {0, nullptr, nullptr}, + }; + + GST_D3D11_CALL_ONCE_BEGIN { + type = g_enum_register_static ("GstD3D11SamplingMethod", methods); + } GST_D3D11_CALL_ONCE_END; + + return type; +} + /* Max Texture Dimension for feature level 11_0 ~ 12_1 */ static guint _gst_d3d11_texture_max_dimension = 16384; @@ -1078,3 +1130,28 @@ gst_d3d11_calculate_transform_matrix (GstVideoOrientationMethod method, } } } + +struct SamplingMethodMap +{ + GstD3D11SamplingMethod method; + D3D11_FILTER filter; +}; + +static const SamplingMethodMap sampling_method_map[] = { + {GST_D3D11_SAMPLING_METHOD_NEAREST, D3D11_FILTER_MIN_MAG_MIP_POINT}, + {GST_D3D11_SAMPLING_METHOD_BILINEAR, D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT}, + {GST_D3D11_SAMPLING_METHOD_LINEAR_MINIFICATION, + D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT}, + {GST_D3D11_SAMPLING_METHOD_ANISOTROPIC, D3D11_FILTER_COMPARISON_ANISOTROPIC}, +}; + +D3D11_FILTER +gst_d3d11_sampling_method_to_native (GstD3D11SamplingMethod method) +{ + for (guint i = 0; i < G_N_ELEMENTS (sampling_method_map); i++) { + if (sampling_method_map[i].method == method) + return sampling_method_map[i].filter; + } + + return D3D11_FILTER_MIN_MAG_MIP_POINT; +} diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.h b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.h index f39135a9e6..7dccb0c5c9 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.h +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.h @@ -61,6 +61,17 @@ typedef enum #define GST_TYPE_D3D11_MSAA_MODE (gst_d3d11_msaa_mode_get_type()) GType gst_d3d11_msaa_mode_get_type (void); +typedef enum +{ + GST_D3D11_SAMPLING_METHOD_NEAREST, + GST_D3D11_SAMPLING_METHOD_BILINEAR, + GST_D3D11_SAMPLING_METHOD_LINEAR_MINIFICATION, + GST_D3D11_SAMPLING_METHOD_ANISOTROPIC, +} GstD3D11SamplingMethod; + +#define GST_TYPE_D3D11_SAMPLING_METHOD (gst_d3d11_sampling_method_get_type()) +GType gst_d3d11_sampling_method_get_type (void); + void gst_d3d11_plugin_utils_init (D3D_FEATURE_LEVEL feature_level); GstCaps * gst_d3d11_get_updated_template_caps (GstStaticCaps * template_caps); @@ -166,6 +177,8 @@ void gst_d3d11_calculate_transform_matrix (GstVideoOrientationMethod gfloat scale_y, gfloat transform_matrix[16]); +D3D11_FILTER gst_d3d11_sampling_method_to_native (GstD3D11SamplingMethod method); + G_END_DECLS #endif /* __GST_D3D11_PLUGIN_UTILS_H__ */