drm/amdgpu: add asic callback for querying video codec info (v3)
Subsystems (3)
PATCH 1/4 drm/amdgpu: add asic callback for querying video codec info (v3)
This will be used by a new INFO ioctl query to fetch the decode and encode capabilities from the kernel driver rather than hardcoding them in mesa. This gives us more fine grained control of capabilities using information that is only availabl in the kernel (e.g., platform limitations or bandwidth restrictions).
v2: reorder the codecs to better align with mesa
v3: add max_pixels_per_frame to handle the portrait case
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +26 -0
@@ -582,6 +582,28 @@ enum amd_reset_method { AMD_RESET_METHOD_BACO }; +#define AMDGPU_VIDEO_CODEC_TYPE_MPEG2 0 +#define AMDGPU_VIDEO_CODEC_TYPE_MPEG4 1 +#define AMDGPU_VIDEO_CODEC_TYPE_VC1 2 +#define AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC 3 +#define AMDGPU_VIDEO_CODEC_TYPE_HEVC 4 +#define AMDGPU_VIDEO_CODEC_TYPE_JPEG 5 +#define AMDGPU_VIDEO_CODEC_TYPE_VP9 6 +#define AMDGPU_VIDEO_CODEC_TYPE_AV1 7 + +struct amdgpu_video_codec_info { +u32 codec_type; +u32 max_width; +u32 max_height; +u32 max_pixels_per_frame; +u32 max_level; +}; + +struct amdgpu_video_codecs { +const u32 codec_count; +const struct amdgpu_video_codec_info *codec_array; +}; +/* * ASIC specific functions. */
@@ -626,6 +648,9 @@ struct amdgpu_asic_funcs {void (*pre_asic_init)(struct amdgpu_device *adev);/* enter/exit umd stable pstate */ int (*update_umd_stable_pstate)(struct amdgpu_device *adev,bool enter); +/* query video codecs */ +int (*query_video_codecs)(struct amdgpu_device *adev,bool encode, +const struct amdgpu_video_codecs **codecs); };/*
@@ -1218,6 +1243,7 @@ int emu_soc_asic_init(struct amdgpu_device *adev);#define amdgpu_asic_pre_asic_init (adev) (adev)->asic_funcs->pre_asic_init((adev))#define amdgpu_asic_update_umd_stable_pstate (adev, enter) \ ((adev)->asic_funcs->update_umd_stable_pstate ? (adev)->asic_funcs->update_umd_stable_pstate((adev), (enter)) : 0) +#define amdgpu_asic_query_video_codecs (adev, e, c) (adev)->asic_funcs->query_video_codecs((adev), (e), (c))#define amdgpu_inc_vram_lost (adev) atomic_inc(&((adev)->vram_lost_counter));
Signature · 6 lines
2.29.2 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/4 drm/amdgpu: add video decode/encode cap tables and asic callbacks (v2)
For each asic family. Will be used to populate tables for the new INFO ioctl query.
v2: add max_pixels_per_frame to handle the portrait case
--- drivers/gpu/drm/amd/amdgpu/cik.c | 75 ++++++++++ drivers/gpu/drm/amd/amdgpu/nv.c | 179 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/si.c | 109 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/soc15.c | 230 +++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/vi.c | 188 +++++++++++++++++++++++ 5 files changed, 781 insertions(+)
drivers/gpu/drm/amd/amdgpu/cik.c +75 -0
@@ -70,6 +70,80 @@#include "amdgpu_amdkfd.h" #include "dce_virtual.h" +static const struct amdgpu_video_codec_info cik_video_codecs_encode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =0 , + }, +}; + +static const struct amdgpu_video_codecs cik_video_codecs_encode = +{ + .codec_count =ARRAY_SIZE (cik_video_codecs_encode_array), + .codec_array = cik_video_codecs_encode_array, +}; + +static const struct amdgpu_video_codec_info cik_video_codecs_decode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG2 , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =3 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4 , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =5 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =41 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_VC1 , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =4 , + }, +}; + +static const struct amdgpu_video_codecs cik_video_codecs_decode = +{ + .codec_count =ARRAY_SIZE (cik_video_codecs_decode_array), + .codec_array = cik_video_codecs_decode_array, +}; + +static int cik_query_video_codecs (struct amdgpu_device *adev,bool encode, +const struct amdgpu_video_codecs **codecs) +{ +switch (adev->asic_type) { +case CHIP_BONAIRE : +case CHIP_HAWAII : +case CHIP_KAVERI : +case CHIP_KABINI : +case CHIP_MULLINS : +if (encode) + *codecs = &cik_video_codecs_encode; +else + *codecs = &cik_video_codecs_decode; +return 0 ; +default : +return -EINVAL ; + } +} +/* * Indirect registers accessor */
@@ -1944,6 +2018,7 @@ static const struct amdgpu_asic_funcs cik_asic_funcs = .get_pcie_replay_count = &cik_get_pcie_replay_count, .supports_baco = &cik_asic_supports_baco, .pre_asic_init = &cik_pre_asic_init, + .query_video_codecs = &cik_query_video_codecs, };static int cik_common_early_init (void *handle)
drivers/gpu/drm/amd/amdgpu/nv.c +179 -0
191 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/si.c +109 -0
121 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/soc15.c +230 -0
248 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/vi.c +188 -0
200 lines not on this page · raw message
Signature · 6 lines
2.29.2 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 2/4] drm/amdgpu: add video decode/encode cap tables and asic callbacks (v2)
Am 01.02.21 um 17:56 schrieb Alex Deucher:
Quoted 167 lines
For each asic family. Will be used to populate tables for the new INFO ioctl query.
v2: add
max_pixels_per_frameto handle the portrait caseReviewed-by Leo Liu <[email protected]> (v1)Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/cik.c | 75 ++++++++++ drivers/gpu/drm/amd/amdgpu/nv.c | 179 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/si.c | 109 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/soc15.c | 230 +++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/vi.c | 188 +++++++++++++++++++++++ 5 files changed, 781 insertions(+)drivers/gpu/drm/amd/amdgpu/cik.c +75
-0@@ -70,6 +70,80 @@#include "amdgpu_amdkfd.h" #include "dce_virtual.h" +static const struct amdgpu_video_codec_info cik_video_codecs_encode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =0 , + }, +}; + +static const struct amdgpu_video_codecs cik_video_codecs_encode = +{ + .codec_count =ARRAY_SIZE (cik_video_codecs_encode_array), + .codec_array = cik_video_codecs_encode_array, +}; + +static const struct amdgpu_video_codec_info cik_video_codecs_decode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG2 , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =3 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4 , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =5 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =41 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_VC1 , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =4 , + }, +}; + +static const struct amdgpu_video_codecs cik_video_codecs_decode = +{ + .codec_count =ARRAY_SIZE (cik_video_codecs_decode_array), + .codec_array = cik_video_codecs_decode_array, +}; + +static int cik_query_video_codecs (struct amdgpu_device *adev,bool encode, +const struct amdgpu_video_codecs **codecs) +{ +switch (adev->asic_type) { +case CHIP_BONAIRE : +case CHIP_HAWAII : +case CHIP_KAVERI : +case CHIP_KABINI : +case CHIP_MULLINS : +if (encode) + *codecs = &cik_video_codecs_encode; +else + *codecs = &cik_video_codecs_decode; +return 0 ; +default : +return -EINVAL ; + } +} +/* * Indirect registers accessor */ @@ -1944,6 +2018,7 @@ static const struct amdgpu_asic_funcs cik_asic_funcs = .get_pcie_replay_count = &cik_get_pcie_replay_count, .supports_baco = &cik_asic_supports_baco, .pre_asic_init = &cik_pre_asic_init, + .query_video_codecs = &cik_query_video_codecs, };static int cik_common_early_init (void *handle)drivers/gpu/drm/amd/amdgpu/nv.c +51
-0@@ -64,6 +64,184 @@static const struct amd_ip_funcs nv_common_ip_funcs; +/* Navi */ +static const struct amdgpu_video_codec_info nv_video_codecs_encode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =4096 , + .max_height =2304 , + .max_pixels_per_frame =4096 *2304 , + .max_level =0 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_HEVC , + .max_width =4096 , + .max_height =2304 , + .max_pixels_per_frame =4096 *2304 , + .max_level =0 , + }, +}; + +static const struct amdgpu_video_codecs nv_video_codecs_encode = +{ + .codec_count =ARRAY_SIZE (nv_video_codecs_encode_array), + .codec_array = nv_video_codecs_encode_array, +}; + +/* Navi1x */ +static const struct amdgpu_video_codec_info nv_video_codecs_decode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG2 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =3 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =5 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =52 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_VC1 ,
drivers/gpu/drm/amd/amdgpu/nv.c line 127
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/nv.c +10
-0+ .max_width = 4096, + .max_height = 4096, + .max_pixels_per_frame = 4096 * 4096, + .max_level = 4, + }, + { + .codec_type = AMDGPU_VIDEO_CODEC_TYPE_HEVC, + .max_width = 8192, + .max_height = 4352, + .max_pixels_per_frame = 4096 * 4096,
Are those numbers correct? Looks more like this should be 8192 * 4352.
Christian.
Quoted 709 lines
drivers/gpu/drm/amd/amdgpu/nv.c +118
-0+ .max_level = 186, + }, + { + .codec_type = AMDGPU_VIDEO_CODEC_TYPE_JPEG, + .max_width = 4096, + .max_height = 4096, + .max_pixels_per_frame = 4096 * 4096, + .max_level = 0, + }, + { + .codec_type = AMDGPU_VIDEO_CODEC_TYPE_VP9, + .max_width = 8192, + .max_height = 4352, + .max_pixels_per_frame = 4096 * 4096, + .max_level = 0, + }, +}; + +static const struct amdgpu_video_codecs nv_video_codecs_decode = +{ + .codec_count =ARRAY_SIZE (nv_video_codecs_decode_array), + .codec_array = nv_video_codecs_decode_array, +}; + +/* Sienna Cichlid */ +static const struct amdgpu_video_codec_info sc_video_codecs_decode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG2 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =3 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =5 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =52 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_VC1 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =4 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_HEVC , + .max_width =8192 , + .max_height =4352 , + .max_pixels_per_frame =8192 *4352 , + .max_level =186 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_JPEG , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =0 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_VP9 , + .max_width =8192 , + .max_height =4352 , + .max_pixels_per_frame =8192 *4352 , + .max_level =0 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_AV1 , + .max_width =8192 , + .max_height =4352 , + .max_pixels_per_frame =8192 *4352 , + .max_level =0 , + }, +}; + +static const struct amdgpu_video_codecs sc_video_codecs_decode = +{ + .codec_count =ARRAY_SIZE (sc_video_codecs_decode_array), + .codec_array = sc_video_codecs_decode_array, +}; + +static int nv_query_video_codecs (struct amdgpu_device *adev,bool encode, +const struct amdgpu_video_codecs **codecs) +{ +switch (adev->asic_type) { +case CHIP_SIENNA_CICHLID : +case CHIP_NAVY_FLOUNDER : +case CHIP_DIMGREY_CAVEFISH : +case CHIP_VANGOGH : +if (encode) + *codecs = &nv_video_codecs_encode; +else + *codecs = &sc_video_codecs_decode; +return 0 ; +case CHIP_NAVI10 : +case CHIP_NAVI14 : +case CHIP_NAVI12 : +if (encode) + *codecs = &nv_video_codecs_encode; +else + *codecs = &nv_video_codecs_decode; +return 0 ; +default : +return -EINVAL ; + } +} +/* * Indirect registers accessor */ @@ -825,6 +1003,7 @@ static const struct amdgpu_asic_funcs nv_asic_funcs = .supports_baco = &nv_asic_supports_baco, .pre_asic_init = &nv_pre_asic_init, .update_umd_stable_pstate = &nv_update_umd_stable_pstate, + .query_video_codecs = &nv_query_video_codecs, };static int nv_common_early_init (void *handle)drivers/gpu/drm/amd/amdgpu/si.c +109
-0@@ -905,6 +905,114 @@ static const u32 hainan_mgcg_cgcg_init[] = 0x3630, 0xfffffff0, 0x00000100, }; +/* XXX: update when we support VCE */ +#if 0 +/* tahiti, pitcarin, verde */ +static const struct amdgpu_video_codec_info tahiti_video_codecs_encode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =0 , + }, +}; + +static const struct amdgpu_video_codecs tahiti_video_codecs_encode = +{ + .codec_count =ARRAY_SIZE (tahiti_video_codecs_encode_array), + .codec_array = tahiti_video_codecs_encode_array, +}; +#else +static const struct amdgpu_video_codecs tahiti_video_codecs_encode = +{ + .codec_count =0 , + .codec_array =NULL , +}; +#endif +/* oland and hainan don't support encode */ +static const struct amdgpu_video_codecs hainan_video_codecs_encode = +{ + .codec_count =0 , + .codec_array =NULL , +}; + +/* tahiti, pitcarin, verde, oland */ +static const struct amdgpu_video_codec_info tahiti_video_codecs_decode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG2 , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =3 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4 , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =5 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =41 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_VC1 , + .max_width =2048 , + .max_height =1152 , + .max_pixels_per_frame =2048 *1152 , + .max_level =4 , + }, +}; + +static const struct amdgpu_video_codecs tahiti_video_codecs_decode = +{ + .codec_count =ARRAY_SIZE (tahiti_video_codecs_decode_array), + .codec_array = tahiti_video_codecs_decode_array, +}; + +/* hainan doesn't support decode */ +static const struct amdgpu_video_codecs hainan_video_codecs_decode = +{ + .codec_count =0 , + .codec_array =NULL , +}; + +static int si_query_video_codecs (struct amdgpu_device *adev,bool encode, +const struct amdgpu_video_codecs **codecs) +{ +switch (adev->asic_type) { +case CHIP_VERDE : +case CHIP_TAHITI : +case CHIP_PITCAIRN : +if (encode) + *codecs = &tahiti_video_codecs_encode; +else + *codecs = &tahiti_video_codecs_decode; +return 0 ; +case CHIP_OLAND : +if (encode) + *codecs = &hainan_video_codecs_encode; +else + *codecs = &tahiti_video_codecs_decode; +return 0 ; +case CHIP_HAINAN : +if (encode) + *codecs = &hainan_video_codecs_encode; +else + *codecs = &hainan_video_codecs_decode; +return 0 ; +default : +return -EINVAL ; + } +} +static u32 si_pcie_rreg (struct amdgpu_device *adev,u32 reg) {unsigned long flags;@@ -1897,6 +2005,7 @@ static const struct amdgpu_asic_funcs si_asic_funcs = .get_pcie_replay_count = &si_get_pcie_replay_count, .supports_baco = &si_asic_supports_baco, .pre_asic_init = &si_pre_asic_init, + .query_video_codecs = &si_query_video_codecs, };static uint32_t si_get_rev_id (struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/soc15.c +230
-0@@ -83,6 +83,234 @@#define mmMP0_MISC_LIGHT_SLEEP_CTRL 0x01ba#define mmMP0_MISC_LIGHT_SLEEP_CTRL_BASE_IDX 0 +/* Vega, Raven, Arcturus */ +static const struct amdgpu_video_codec_info vega_video_codecs_encode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =4096 , + .max_height =2304 , + .max_pixels_per_frame =4096 *2304 , + .max_level =0 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_HEVC , + .max_width =4096 , + .max_height =2304 , + .max_pixels_per_frame =4096 *2304 , + .max_level =0 , + }, +}; + +static const struct amdgpu_video_codecs vega_video_codecs_encode = +{ + .codec_count =ARRAY_SIZE (vega_video_codecs_encode_array), + .codec_array = vega_video_codecs_encode_array, +}; + +/* Vega */ +static const struct amdgpu_video_codec_info vega_video_codecs_decode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG2 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =3 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =5 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =52 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_VC1 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =4 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_HEVC , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =186 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_JPEG , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =0 , + }, +}; + +static const struct amdgpu_video_codecs vega_video_codecs_decode = +{ + .codec_count =ARRAY_SIZE (vega_video_codecs_decode_array), + .codec_array = vega_video_codecs_decode_array, +}; + +/* Raven */ +static const struct amdgpu_video_codec_info rv_video_codecs_decode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG2 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =3 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =5 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =52 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_VC1 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =4 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_HEVC , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =186 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_JPEG , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =0 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_VP9 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =0 , + }, +}; + +static const struct amdgpu_video_codecs rv_video_codecs_decode = +{ + .codec_count =ARRAY_SIZE (rv_video_codecs_decode_array), + .codec_array = rv_video_codecs_decode_array, +}; + +/* Renoir, Arcturus */ +static const struct amdgpu_video_codec_info rn_video_codecs_decode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG2 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =3 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =5 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =52 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_VC1 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =4 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_HEVC , + .max_width =8192 , + .max_height =4352 , + .max_pixels_per_frame =4096 *4096 , + .max_level =186 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_JPEG , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =0 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_VP9 , + .max_width =8192 , + .max_height =4352 , + .max_pixels_per_frame =4096 *4096 , + .max_level =0 , + }, +}; + +static const struct amdgpu_video_codecs rn_video_codecs_decode = +{ + .codec_count =ARRAY_SIZE (rn_video_codecs_decode_array), + .codec_array = rn_video_codecs_decode_array, +}; + +static int soc15_query_video_codecs (struct amdgpu_device *adev,bool encode, +const struct amdgpu_video_codecs **codecs) +{ +switch (adev->asic_type) { +case CHIP_VEGA20 : +case CHIP_VEGA10 : +case CHIP_VEGA12 : +if (encode) + *codecs = &vega_video_codecs_encode; +else + *codecs = &vega_video_codecs_decode; +return 0 ; +case CHIP_RAVEN : +if (encode) + *codecs = &vega_video_codecs_encode; +else + *codecs = &rv_video_codecs_decode; +return 0 ; +case CHIP_ARCTURUS : +case CHIP_RENOIR : +if (encode) + *codecs = &vega_video_codecs_encode; +else + *codecs = &rn_video_codecs_decode; +return 0 ; +default : +return -EINVAL ; + } +} +/* * Indirect registers accessor */ @@ -988,6 +1216,7 @@ static const struct amdgpu_asic_funcs soc15_asic_funcs = .get_pcie_replay_count = &soc15_get_pcie_replay_count, .supports_baco = &soc15_supports_baco, .pre_asic_init = &soc15_pre_asic_init, + .query_video_codecs = &soc15_query_video_codecs, }; static const struct amdgpu_asic_funcs vega20_asic_funcs =@@ -1009,6 +1238,7 @@ static const struct amdgpu_asic_funcs vega20_asic_funcs = .get_pcie_replay_count = &soc15_get_pcie_replay_count, .supports_baco = &soc15_supports_baco, .pre_asic_init = &soc15_pre_asic_init, + .query_video_codecs = &soc15_query_video_codecs, };static int soc15_common_early_init (void *handle)drivers/gpu/drm/amd/amdgpu/vi.c +187
-0@@ -79,6 +79,193 @@#include "mxgpu_vi.h" #include "amdgpu_dm.h" +/* Topaz */ +static const struct amdgpu_video_codecs topaz_video_codecs_encode = +{ + .codec_count =0 , + .codec_array =NULL , +}; + +/* Tonga, CZ, ST, Fiji */ +static const struct amdgpu_video_codec_info tonga_video_codecs_encode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =4096 , + .max_height =2304 , + .max_pixels_per_frame =4096 *2304 , + .max_level =0 , + }, +}; + +static const struct amdgpu_video_codecs tonga_video_codecs_encode = +{ + .codec_count =ARRAY_SIZE (tonga_video_codecs_encode_array), + .codec_array = tonga_video_codecs_encode_array, +}; + +/* Polaris */ +static const struct amdgpu_video_codec_info polaris_video_codecs_encode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =4096 , + .max_height =2304 , + .max_pixels_per_frame =4096 *2304 , + .max_level =0 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_HEVC , + .max_width =4096 , + .max_height =2304 , + .max_pixels_per_frame =4096 *2304 , + .max_level =0 , + }, +}; + +static const struct amdgpu_video_codecs polaris_video_codecs_encode = +{ + .codec_count =ARRAY_SIZE (polaris_video_codecs_encode_array), + .codec_array = polaris_video_codecs_encode_array, +}; + +/* Topaz */ +static const struct amdgpu_video_codecs topaz_video_codecs_decode = +{ + .codec_count =0 , + .codec_array =NULL , +}; + +/* Tonga */ +static const struct amdgpu_video_codec_info tonga_video_codecs_decode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG2 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =3 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =5 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =52 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_VC1 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =4 , + }, +}; + +static const struct amdgpu_video_codecs tonga_video_codecs_decode = +{ + .codec_count =ARRAY_SIZE (tonga_video_codecs_decode_array), + .codec_array = tonga_video_codecs_decode_array, +}; + +/* CZ, ST, Fiji, Polaris */ +static const struct amdgpu_video_codec_info cz_video_codecs_decode_array[] = +{ + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG2 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =3 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =5 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =52 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_VC1 , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =4 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_HEVC , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =186 , + }, + { + .codec_type =AMDGPU_VIDEO_CODEC_TYPE_JPEG , + .max_width =4096 , + .max_height =4096 , + .max_pixels_per_frame =4096 *4096 , + .max_level =0 , + }, +}; + +static const struct amdgpu_video_codecs cz_video_codecs_decode = +{ + .codec_count =ARRAY_SIZE (cz_video_codecs_decode_array), + .codec_array = cz_video_codecs_decode_array, +}; + +static int vi_query_video_codecs (struct amdgpu_device *adev,bool encode, +const struct amdgpu_video_codecs **codecs) +{ +switch (adev->asic_type) { +case CHIP_TOPAZ : +if (encode) + *codecs = &topaz_video_codecs_encode; +else + *codecs = &topaz_video_codecs_decode; +return 0 ; +case CHIP_TONGA : +if (encode) + *codecs = &tonga_video_codecs_encode; +else + *codecs = &tonga_video_codecs_decode; +return 0 ; +case CHIP_POLARIS10 : +case CHIP_POLARIS11 : +case CHIP_POLARIS12 : +case CHIP_VEGAM : +if (encode) + *codecs = &polaris_video_codecs_encode; +else + *codecs = &cz_video_codecs_decode; +return 0 ; +case CHIP_FIJI : +case CHIP_CARRIZO : +case CHIP_STONEY : +if (encode) + *codecs = &tonga_video_codecs_encode; +else + *codecs = &cz_video_codecs_decode; +return 0 ; +default : +return -EINVAL ; + } +} +/* * Indirect registers accessor */
drivers/gpu/drm/amd/amdgpu/vi.c static const struct amdgpu_asic_funcs vi_asic_funcs = · line 1286
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/vi.c +1
-0@@ -1093,6 +1280,7 @@ static const struct amdgpu_asic_funcs vi_asic_funcs = .get_pcie_replay_count = &vi_get_pcie_replay_count, .supports_baco = &vi_asic_supports_baco, .pre_asic_init = &vi_pre_asic_init, + .query_video_codecs = &vi_query_video_codecs, };#define CZ_REV_BRISTOL (rev) \
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/4 drm/amdgpu: add INFO ioctl support for querying video caps (v3)
In reply to Alex DeucherWe currently hardcode these in mesa, but querying them from the kernel makes more sense since there may be board specific limitations that the kernel driver is better suited to determining.
Userpace patches that use this interface:
https://gitlab.freedesktop.org/leoliu/drm/-/commits/info_video_caps
https://gitlab.freedesktop.org/leoliu/mesa/-/commits/info_video_caps
v2: reorder the codecs to better align with mesa
v3: add max_pixels_per_frame to handle the portrait case, squash in
memory leak fix
--- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 58 +++++++++++++++++++++++++ include/uapi/drm/amdgpu_drm.h | 34 +++++++++++++++ 2 files changed, 92 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +58 -0
@@ -983,6 +983,64 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) min_t(u64, size, sizeof(ras_mask))) ? -EFAULT :0 ; } +case AMDGPU_INFO_VIDEO_CAPS : { +const struct amdgpu_video_codecs *codecs; +struct drm_amdgpu_info_video_caps *caps; +int r; + +switch (info->video_cap.type) { +case AMDGPU_INFO_VIDEO_CAPS_DECODE : + r =amdgpu_asic_query_video_codecs (adev, false, &codecs); +if (r) +return -EINVAL ; +break ; +case AMDGPU_INFO_VIDEO_CAPS_ENCODE : + r =amdgpu_asic_query_video_codecs (adev, true, &codecs); +if (r) +return -EINVAL ; +break ; +break ; +default : +DRM_DEBUG_KMS ("Invalid request %d\n" , + info->video_cap.type); +return -EINVAL ; + } + + caps =kzalloc (sizeof (*caps),GFP_KERNEL ); +if (!caps) +return -ENOMEM ; + +for (i =0 ; i < codecs->codec_count; i++) { +int idx = codecs->codec_array[i].codec_type; + +switch (idx) { +case AMDGPU_VIDEO_CODEC_TYPE_MPEG2 : +case AMDGPU_VIDEO_CODEC_TYPE_MPEG4 : +case AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC : +case AMDGPU_VIDEO_CODEC_TYPE_VC1 : +case AMDGPU_VIDEO_CODEC_TYPE_HEVC : +case AMDGPU_VIDEO_CODEC_TYPE_JPEG : +case AMDGPU_VIDEO_CODEC_TYPE_VP9 : +case AMDGPU_VIDEO_CODEC_TYPE_AV1 : + caps->codec_info[idx].valid =1 ; + caps->codec_info[idx].max_width = + codecs->codec_array[i].max_width; + caps->codec_info[idx].max_height = + codecs->codec_array[i].max_height; + caps->codec_info[idx].max_pixels_per_frame = + codecs->codec_array[i].max_pixels_per_frame; + caps->codec_info[idx].max_level = + codecs->codec_array[i].max_level; +break ; +default : +break ; + } + } + r =copy_to_user (out, caps, +min ((size_t )size,sizeof (*caps))) ? -EFAULT :0 ; +kfree (caps); +return r; + }default :DRM_DEBUG_KMS ("Invalid request %d\n" , info->query);return -EINVAL ;
include/uapi/drm/amdgpu_drm.h +34 -0
@@ -782,6 +782,12 @@ struct drm_amdgpu_cs_chunk_data {#define AMDGPU_INFO_VRAM_LOST_COUNTER 0x1F/* query ras mask of enabled features*/ #define AMDGPU_INFO_RAS_ENABLED_FEATURES 0x20 +/* query video encode/decode caps */ +#define AMDGPU_INFO_VIDEO_CAPS 0x21 +/* Subquery id: Decode */ +#define AMDGPU_INFO_VIDEO_CAPS_DECODE 0 +/* Subquery id: Encode */ +#define AMDGPU_INFO_VIDEO_CAPS_ENCODE 1/* RAS MASK: UMC (VRAM) */ #define AMDGPU_INFO_RAS_ENABLED_UMC (1 << 0)
@@ -878,6 +884,10 @@ struct drm_amdgpu_info {struct {__u32 type; } sensor_info; + +struct { +__u32 type; + } video_cap; }; };
@@ -1074,6 +1084,30 @@ struct drm_amdgpu_info_vce_clock_table {__u32 pad; }; +/* query video encode/decode caps */ +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2 0 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4 1 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1 2 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC 3 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC 4 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG 5 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9 6 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1 7 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_COUNT 8 + +struct drm_amdgpu_info_video_codec_info { +__u32 valid; +__u32 max_width; +__u32 max_height; +__u32 max_pixels_per_frame; +__u32 max_level; +__u32 pad; +}; + +struct drm_amdgpu_info_video_caps { +struct drm_amdgpu_info_video_codec_info codec_info[AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_COUNT ]; +}; +/* * Supported GPU families */
Signature · 6 lines
2.29.2 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
RE: [PATCH 3/4] drm/amdgpu: add INFO ioctl support for querying video caps (v3)
[AMD Public Use]
+ case AMDGPU_INFO_VIDEO_CAPS_ENCODE:
+ r = amdgpu_asic_query_video_codecs(adev, true, &codecs);
+ if (r)
+ return -EINVAL;
+ break;
+ break;
One duplicated 'break' here.
Regards,
Guchun
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Tuesday, February 2, 2021 12:56 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Liu, Leo <[email protected]>
Subject: [PATCH 3/4] drm/amdgpu: add INFO ioctl support for querying video caps (v3)
We currently hardcode these in mesa, but querying them from the kernel makes more sense since there may be board specific limitations that the kernel driver is better suited to determining.
Userpace patches that use this interface:
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.freedesktop.org%2Fleoliu%2Fdrm%2F-%2Fcommits%2Finfo_video_caps&data=04%7C01%7Cguchun.chen%40amd.com%7Cd6c0951db7304c035c2508d8c6d24c47%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637477953819079552%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=cypiYoi86eR9VhTBhtwqNu%2BAAgTPFb%2FJuqzwpblzT0s%3D&reserved=0
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.freedesktop.org%2Fleoliu%2Fmesa%2F-%2Fcommits%2Finfo_video_caps&data=04%7C01%7Cguchun.chen%40amd.com%7Cd6c0951db7304c035c2508d8c6d24c47%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637477953819089548%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=PPsnvjzuh6aZKZxsZ8fADo9RWMY8WN3QxZxiiAazoS4%3D&reserved=0
v2: reorder the codecs to better align with mesa
v3: add max_pixels_per_frame to handle the portrait case, squash in
memory leak fix
--- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 58 +++++++++++++++++++++++++ include/uapi/drm/amdgpu_drm.h | 34 +++++++++++++++ 2 files changed, 92 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +58 -0
@@ -983,6 +983,64 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) min_t(u64, size, sizeof(ras_mask))) ? -EFAULT :0 ; } +case AMDGPU_INFO_VIDEO_CAPS : { +const struct amdgpu_video_codecs *codecs; +struct drm_amdgpu_info_video_caps *caps; +int r; + +switch (info->video_cap.type) { +case AMDGPU_INFO_VIDEO_CAPS_DECODE : + r =amdgpu_asic_query_video_codecs (adev, false, &codecs); +if (r) +return -EINVAL ; +break ; +case AMDGPU_INFO_VIDEO_CAPS_ENCODE : + r =amdgpu_asic_query_video_codecs (adev, true, &codecs); +if (r) +return -EINVAL ; +break ; +break ; +default : +DRM_DEBUG_KMS ("Invalid request %d\n" , + info->video_cap.type); +return -EINVAL ; + } + + caps =kzalloc (sizeof (*caps),GFP_KERNEL ); +if (!caps) +return -ENOMEM ; + +for (i =0 ; i < codecs->codec_count; i++) { +int idx = codecs->codec_array[i].codec_type; + +switch (idx) { +case AMDGPU_VIDEO_CODEC_TYPE_MPEG2 : +case AMDGPU_VIDEO_CODEC_TYPE_MPEG4 : +case AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC : +case AMDGPU_VIDEO_CODEC_TYPE_VC1 : +case AMDGPU_VIDEO_CODEC_TYPE_HEVC : +case AMDGPU_VIDEO_CODEC_TYPE_JPEG : +case AMDGPU_VIDEO_CODEC_TYPE_VP9 : +case AMDGPU_VIDEO_CODEC_TYPE_AV1 : + caps->codec_info[idx].valid =1 ; + caps->codec_info[idx].max_width = + codecs->codec_array[i].max_width; + caps->codec_info[idx].max_height = + codecs->codec_array[i].max_height; + caps->codec_info[idx].max_pixels_per_frame = + codecs->codec_array[i].max_pixels_per_frame; + caps->codec_info[idx].max_level = + codecs->codec_array[i].max_level; +break ; +default : +break ; + } + } + r =copy_to_user (out, caps, +min ((size_t )size,sizeof (*caps))) ? -EFAULT :0 ; +kfree (caps); +return r; + }default :DRM_DEBUG_KMS ("Invalid request %d\n" , info->query);return -EINVAL ;
include/uapi/drm/amdgpu_drm.h +35 -0
@@ -782,6 +782,12 @@ struct drm_amdgpu_cs_chunk_data {#define AMDGPU_INFO_VRAM_LOST_COUNTER 0x1F/* query ras mask of enabled features*/ #define AMDGPU_INFO_RAS_ENABLED_FEATURES 0x20 +/* query video encode/decode caps */ +#define AMDGPU_INFO_VIDEO_CAPS 0x21 +/* Subquery id: Decode */ +#define AMDGPU_INFO_VIDEO_CAPS_DECODE 0 +/* Subquery id: Encode */ +#define AMDGPU_INFO_VIDEO_CAPS_ENCODE 1/* RAS MASK: UMC (VRAM) */ #define AMDGPU_INFO_RAS_ENABLED_UMC (1 << 0)
@@ -878,6 +884,10 @@ struct drm_amdgpu_info {struct {__u32 type; } sensor_info; + +struct { +__u32 type; + } video_cap; }; };
@@ -1074,6 +1084,30 @@ struct drm_amdgpu_info_vce_clock_table {__u32 pad; }; +/* query video encode/decode caps */ +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2 0 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4 1 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1 2 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC 3 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC 4 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG 5 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9 6 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1 7 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_COUNT 8 + +struct drm_amdgpu_info_video_codec_info { +__u32 valid; +__u32 max_width; +__u32 max_height; +__u32 max_pixels_per_frame; +__u32 max_level; +__u32 pad; +}; + +struct drm_amdgpu_info_video_caps { +struct drm_amdgpu_info_video_codec_info +codec_info[AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_COUNT ]; +}; +/* * Supported GPU families
*/
--
2.29.2
_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7Cguchun.chen%40amd.com%7Cd6c0951db7304c035c2508d8c6d24c47%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637477953819089548%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=19QB8BUXVKwLvvCQDVK4LOn6rFkO1jagHJ5RR1WD8rw%3D&reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 3/4] drm/amdgpu: add INFO ioctl support for querying video caps (v3)
In reply to Alex DeucherAm 01.02.21 um 17:56 schrieb Alex Deucher:
Quoted 121 lines
We currently hardcode these in mesa, but querying them from the kernel makes more sense since there may be board specific limitations that the kernel driver is better suited to determining.
Userpace patches that use this interface:
https://gitlab.freedesktop.org/leoliu/drm/-/commits/info_video_caps
https://gitlab.freedesktop.org/leoliu/mesa/-/commits/info_video_capsv2: reorder the codecs to better align with mesa
v3: addmax_pixels_per_frameto handle the portrait case, squash in
memory leak fixReviewed-by Leo Liu <[email protected]> (v2)Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 58 +++++++++++++++++++++++++ include/uapi/drm/amdgpu_drm.h | 34 +++++++++++++++ 2 files changed, 92 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +58
-0@@ -983,6 +983,64 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) min_t(u64, size, sizeof(ras_mask))) ? -EFAULT :0 ; } +case AMDGPU_INFO_VIDEO_CAPS : { +const struct amdgpu_video_codecs *codecs; +struct drm_amdgpu_info_video_caps *caps; +int r; + +switch (info->video_cap.type) { +case AMDGPU_INFO_VIDEO_CAPS_DECODE : + r =amdgpu_asic_query_video_codecs (adev, false, &codecs); +if (r) +return -EINVAL ; +break ; +case AMDGPU_INFO_VIDEO_CAPS_ENCODE : + r =amdgpu_asic_query_video_codecs (adev, true, &codecs); +if (r) +return -EINVAL ; +break ; +break ; +default : +DRM_DEBUG_KMS ("Invalid request %d\n" , + info->video_cap.type); +return -EINVAL ; + } + + caps =kzalloc (sizeof (*caps),GFP_KERNEL ); +if (!caps) +return -ENOMEM ; + +for (i =0 ; i < codecs->codec_count; i++) { +int idx = codecs->codec_array[i].codec_type; + +switch (idx) { +case AMDGPU_VIDEO_CODEC_TYPE_MPEG2 : +case AMDGPU_VIDEO_CODEC_TYPE_MPEG4 : +case AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC : +case AMDGPU_VIDEO_CODEC_TYPE_VC1 : +case AMDGPU_VIDEO_CODEC_TYPE_HEVC : +case AMDGPU_VIDEO_CODEC_TYPE_JPEG : +case AMDGPU_VIDEO_CODEC_TYPE_VP9 : +case AMDGPU_VIDEO_CODEC_TYPE_AV1 : + caps->codec_info[idx].valid =1 ; + caps->codec_info[idx].max_width = + codecs->codec_array[i].max_width; + caps->codec_info[idx].max_height = + codecs->codec_array[i].max_height; + caps->codec_info[idx].max_pixels_per_frame = + codecs->codec_array[i].max_pixels_per_frame; + caps->codec_info[idx].max_level = + codecs->codec_array[i].max_level; +break ; +default : +break ; + } + } + r =copy_to_user (out, caps, +min ((size_t )size,sizeof (*caps))) ? -EFAULT :0 ; +kfree (caps); +return r; + }default :DRM_DEBUG_KMS ("Invalid request %d\n" , info->query);return -EINVAL ;include/uapi/drm/amdgpu_drm.h +10
-0@@ -782,6 +782,12 @@ struct drm_amdgpu_cs_chunk_data {#define AMDGPU_INFO_VRAM_LOST_COUNTER 0x1F/* query ras mask of enabled features*/ #define AMDGPU_INFO_RAS_ENABLED_FEATURES 0x20 +/* query video encode/decode caps */ +#define AMDGPU_INFO_VIDEO_CAPS 0x21 +/* Subquery id: Decode */ +#define AMDGPU_INFO_VIDEO_CAPS_DECODE 0 +/* Subquery id: Encode */ +#define AMDGPU_INFO_VIDEO_CAPS_ENCODE 1/* RAS MASK: UMC (VRAM) */ #define AMDGPU_INFO_RAS_ENABLED_UMC (1 << 0)@@ -878,6 +884,10 @@ struct drm_amdgpu_info {struct {__u32 type; } sensor_info; + +struct { +__u32 type; + } video_cap; }; };@@ -1074,6 +1084,30 @@ struct drm_amdgpu_info_vce_clock_table {__u32 pad; };
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_info_vce_clock_table { · line 1096
Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +10
-0+/* query video encode/decode caps */ +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2 0 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4 1 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1 2 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC 3 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC 4 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG 5 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9 6 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1 7 +#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_COUNT 8
If I'm not completely mistaken this needs to be kept identical to the defines in amdgpu.h.
I think it might be better to have only one define for this.
Christian.
Quoted 7 lines
include/uapi/drm/amdgpu_drm.h +7
-0+ +struct drm_amdgpu_info_video_codec_info { +__u32 valid; +__u32 max_width; +__u32 max_height; +__u32 max_pixels_per_frame; +__u32 max_level;
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_info_vce_clock_table { · line 1113
Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +7
-0+__u32 pad; +}; + +struct drm_amdgpu_info_video_caps { +struct drm_amdgpu_info_video_codec_info codec_info[AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_COUNT ]; +}; +/* * Supported GPU families */
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/4 drm/amdgpu: bump driver version for new video codec INFO ioctl query
In reply to Alex DeucherSo mesa can check when to query the kernel vs use hardcoded codec bandwidth data.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -90,9 +90,10 @@* - 3.38.0 - Add AMDGPU_IB_FLAG_EMIT_MEM_SYNC * - 3.39.0 - DMABUF implicit sync does a full pipeline sync * - 3.40.0 - Add AMDGPU_IDS_FLAGS_TMZ +* - 3.41.0 - Add video codec query */ #define KMS_DRIVER_MAJOR 3 -#define KMS_DRIVER_MINOR 40 +#define KMS_DRIVER_MINOR 41#define KMS_DRIVER_PATCHLEVEL 0int amdgpu_vram_limit;
Signature · 6 lines
2.29.2 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx