d3d11convert: Add support for sampling with anisotropic filter

Anisotropic filtering might produce better quality than linear filtering

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5572>
This commit is contained in:
Seungha Yang 2023-10-28 22:38:02 +09:00
parent af31b46992
commit b16665dc75
6 changed files with 101 additions and 74 deletions

View file

@ -11036,6 +11036,11 @@
"desc": "Linear minification, point magnification", "desc": "Linear minification, point magnification",
"name": "linear-minification", "name": "linear-minification",
"value": "2" "value": "2"
},
{
"desc": "Anisotropic",
"name": "anisotropic",
"value": "3"
} }
] ]
}, },

View file

@ -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_LINEAR_MAG_MIP_POINT", "min-linear-mag-mip-point"},
{D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT,
"D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT", "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}, {0, nullptr, nullptr},
}; };

View file

@ -90,6 +90,7 @@ GType gst_d3d11_converter_backend_get_type (void);
* @D3D11_FILTER_MIN_MAG_MIP_POINT * @D3D11_FILTER_MIN_MAG_MIP_POINT
* @D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT * @D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT
* @D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT * @D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT
* @D3D11_FILTER_COMPARISON_ANISOTROPIC,
* *
* Default is #D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT. * Default is #D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT.
* *

View file

@ -48,76 +48,6 @@ static GstStaticCaps src_template_caps =
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION,
GST_D3D11_SRC_FORMATS)); 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_ADD_BORDERS TRUE
#define DEFAULT_BORDER_COLOR G_GUINT64_CONSTANT(0xffff000000000000) #define DEFAULT_BORDER_COLOR G_GUINT64_CONSTANT(0xffff000000000000)
#define DEFAULT_GAMMA_MODE GST_VIDEO_GAMMA_MODE_NONE #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_TYPE_VIDEO_PRIMARIES_MODE, self->active_primaries_mode,
GST_D3D11_CONVERTER_OPT_SAMPLER_FILTER, GST_D3D11_CONVERTER_OPT_SAMPLER_FILTER,
GST_TYPE_D3D11_CONVERTER_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), (self->active_sampling_method),
GST_D3D11_CONVERTER_OPT_SRC_ALPHA_MODE, GST_D3D11_CONVERTER_OPT_SRC_ALPHA_MODE,
GST_TYPE_D3D11_CONVERTER_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); GstD3D11SRWLockGuard lk (&self->lock);
GST_DEBUG_OBJECT (self, "Sampling method %s -> %s", GST_DEBUG_OBJECT (self,
gst_d3d11_sampling_methods[self->sampling_method].value_nick, "Sampling method %d -> %d", self->sampling_method, method);
gst_d3d11_sampling_methods[method].value_nick);
self->sampling_method = method; self->sampling_method = method;
if (self->sampling_method != self->active_sampling_method) if (self->sampling_method != self->active_sampling_method)

View file

@ -106,6 +106,58 @@ gst_d3d11_msaa_mode_get_type (void)
return type; 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 */ /* Max Texture Dimension for feature level 11_0 ~ 12_1 */
static guint _gst_d3d11_texture_max_dimension = 16384; 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;
}

View file

@ -61,6 +61,17 @@ typedef enum
#define GST_TYPE_D3D11_MSAA_MODE (gst_d3d11_msaa_mode_get_type()) #define GST_TYPE_D3D11_MSAA_MODE (gst_d3d11_msaa_mode_get_type())
GType gst_d3d11_msaa_mode_get_type (void); 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); void gst_d3d11_plugin_utils_init (D3D_FEATURE_LEVEL feature_level);
GstCaps * gst_d3d11_get_updated_template_caps (GstStaticCaps * template_caps); 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 scale_y,
gfloat transform_matrix[16]); gfloat transform_matrix[16]);
D3D11_FILTER gst_d3d11_sampling_method_to_native (GstD3D11SamplingMethod method);
G_END_DECLS G_END_DECLS
#endif /* __GST_D3D11_PLUGIN_UTILS_H__ */ #endif /* __GST_D3D11_PLUGIN_UTILS_H__ */