tests/amdgpu: add vce motion vector tests support
PATCH 1/1 tests/amdgpu: add vce motion vector tests support
--- tests/amdgpu/Makefile.am | 1 + tests/amdgpu/amdgpu_test.c | 11 + tests/amdgpu/amdgpu_test.h | 20 ++ tests/amdgpu/vce_ib.h | 21 +- tests/amdgpu/vce_mv_tests.c | 537 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 588 insertions(+), 2 deletions(-) create mode 100644 tests/amdgpu/vce_mv_tests.c
tests/amdgpu/Makefile.am +1 -0
@@ -26,6 +26,7 @@ amdgpu_test_SOURCES = \ cs_tests.c \ decode_messages.h \ vce_tests.c \ + vce_mv_tests.c \ vce_ib.h \ frame.h \ uvd_enc_tests.c \
tests/amdgpu/amdgpu_test.c +11 -0
@@ -52,6 +52,7 @@#define BO_TESTS_STR "BO Tests"#define CS_TESTS_STR "CS Tests"#define VCE_TESTS_STR "VCE Tests" +#define VCE_MV_TESTS_STR "VCE MV Tests"#define VCN_TESTS_STR "VCN Tests"#define UVD_ENC_TESTS_STR "UVD ENC Tests"#define DEADLOCK_TESTS_STR "Deadlock Tests"
@@ -93,6 +94,12 @@ static CU_SuiteInfo suites[] = { .pTests = vce_tests, }, { + .pName = VCE_MV_TESTS_STR, + .pInitFunc = suite_vce_mv_tests_init, + .pCleanupFunc = suite_vce_mv_tests_clean, + .pTests = vce_mv_tests, + }, + { .pName = VCN_TESTS_STR, .pInitFunc = suite_vcn_tests_init, .pCleanupFunc = suite_vcn_tests_clean,
@@ -150,6 +157,10 @@ static Suites_Active_Status suites_active_stat[] = { .pActive = suite_vce_tests_enable, }, { + .pName = VCE_MV_TESTS_STR, + .pActive = suite_vce_mv_tests_enable, + }, + { .pName = VCN_TESTS_STR, .pActive = suite_vcn_tests_enable, },
tests/amdgpu/amdgpu_test.h +20 -0
@@ -115,6 +115,26 @@ CU_BOOL suite_vce_tests_enable(void);extern CU_TestInfo vce_tests[];/** +* Initialize vce test suite +*/ +int suite_vce_mv_tests_init (); + +/** +* Deinitialize vce test suite +*/ +int suite_vce_mv_tests_clean (); + +/** +* Decide if the suite is enabled by default or not. +*/ +CU_BOOL suite_vce_mv_tests_enable (void ); + +/** +* Tests in vce test suite +*/ +extern CU_TestInfo vce_mv_tests[]; + +/** + * Initialize vcn test suite + */ int suite_vcn_tests_init ();
tests/amdgpu/vce_ib.h +19 -2
@@ -41,7 +41,7 @@ static uint32_t vce_taskinfo[8] = { 0x00000000, }; -static const uint32_t vce_create[] = { +static uint32_t vce_create[] = {0x00000030 ,0x01000001 ,0x00000000 ,
@@ -144,7 +144,7 @@ static const uint32_t vce_rdo[] = { 0x00000000, }; -static const uint32_t vce_pic_ctrl[] = { +static uint32_t vce_pic_ctrl[] = {0x00000074 ,0x04000002 ,0x00000000 ,
@@ -315,4 +315,21 @@ static const uint32_t vce_destroy[] = {0x00000008 , 0x02000001, }; + +static const uint32_t vce_mv_buffer[] = { +0x00000038 , +0x0500000d , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +};#endif /*_vce_ib_h*/
tests/amdgpu/vce_mv_tests.c new file +537 -0
537 lines not on this page · raw message
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1522782139-24945-1-git-send-email-James.Zhu-5C7GfCeVMHo@public.gmane.org
Quoted 217 lines · James Zhu
Signed-off-by James Zhu <[email protected]>--- tests/amdgpu/Makefile.am | 1 + tests/amdgpu/amdgpu_test.c | 11 + tests/amdgpu/amdgpu_test.h | 20 ++ tests/amdgpu/vce_ib.h | 21 +- tests/amdgpu/vce_mv_tests.c | 537 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 588 insertions(+), 2 deletions(-)create mode 100644
tests/amdgpu/vce_mv_tests.ctests/amdgpu/Makefile.am +1
-0@@ -26,6 +26,7 @@ amdgpu_test_SOURCES = \ cs_tests.c \ decode_messages.h \ vce_tests.c \ + vce_mv_tests.c \ vce_ib.h \ frame.h \ uvd_enc_tests.c \tests/amdgpu/amdgpu_test.c +11
-0@@ -52,6 +52,7 @@#define BO_TESTS_STR "BO Tests"#define CS_TESTS_STR "CS Tests"#define VCE_TESTS_STR "VCE Tests" +#define VCE_MV_TESTS_STR "VCE MV Tests"#define VCN_TESTS_STR "VCN Tests"#define UVD_ENC_TESTS_STR "UVD ENC Tests"#define DEADLOCK_TESTS_STR "Deadlock Tests"@@ -93,6 +94,12 @@ static CU_SuiteInfo suites[] = { .pTests = vce_tests, }, { + .pName = VCE_MV_TESTS_STR, + .pInitFunc = suite_vce_mv_tests_init, + .pCleanupFunc = suite_vce_mv_tests_clean, + .pTests = vce_mv_tests, + }, + { .pName = VCN_TESTS_STR, .pInitFunc = suite_vcn_tests_init, .pCleanupFunc = suite_vcn_tests_clean,@@ -150,6 +157,10 @@ static Suites_Active_Status suites_active_stat[] = { .pActive = suite_vce_tests_enable, }, { + .pName = VCE_MV_TESTS_STR, + .pActive = suite_vce_mv_tests_enable, + }, + { .pName = VCN_TESTS_STR, .pActive = suite_vcn_tests_enable, },tests/amdgpu/amdgpu_test.h +20
-0@@ -115,6 +115,26 @@ CU_BOOL suite_vce_tests_enable(void);extern CU_TestInfo vce_tests[];/** +* Initialize vce test suite +*/ +int suite_vce_mv_tests_init (); + +/** +* Deinitialize vce test suite +*/ +int suite_vce_mv_tests_clean (); + +/** +* Decide if the suite is enabled by default or not. +*/ +CU_BOOL suite_vce_mv_tests_enable (void ); + +/** +* Tests in vce test suite +*/ +extern CU_TestInfo vce_mv_tests[]; + +/** + * Initialize vcn test suite + */ int suite_vcn_tests_init ();tests/amdgpu/vce_ib.h +19
-2@@ -41,7 +41,7 @@ static uint32_t vce_taskinfo[8] = { 0x00000000, }; -static const uint32_t vce_create[] = { +static uint32_t vce_create[] = {0x00000030 ,0x01000001 ,0x00000000 ,@@ -144,7 +144,7 @@ static const uint32_t vce_rdo[] = { 0x00000000, }; -static const uint32_t vce_pic_ctrl[] = { +static uint32_t vce_pic_ctrl[] = {0x00000074 ,0x04000002 ,0x00000000 ,@@ -315,4 +315,21 @@ static const uint32_t vce_destroy[] = {0x00000008 , 0x02000001, }; + +static const uint32_t vce_mv_buffer[] = { +0x00000038 , +0x0500000d , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +};#endif /*_vce_ib_h*/ tests/amdgpu/vce_mv_tests.c new file +78
-0@@ -0,0 +1,537 @@ +/* +* Copyright 2018 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +*/ + +#include <stdio.h> +#include <inttypes.h> + +#include "CUnit/Basic.h" + +#include "util_math.h" + +#include "amdgpu_test.h" +#include "amdgpu_drm.h" +#include "amdgpu_internal.h" + +#include "vce_ib.h" +#include "frame.h" + +#define IB_SIZE 4096 +#define MAX_RESOURCES 16 +#define FW_53_0_03 ((53 << 24) | (0 << 16) | (03 << 8)) + +struct amdgpu_vce_bo { +amdgpu_bo_handle handle; +amdgpu_va_handle va_handle; +uint64_t addr; +uint64_t size; +uint8_t *ptr; +}; + +struct amdgpu_vce_encode { +unsigned width; +unsigned height; +struct amdgpu_vce_bo vbuf; +struct amdgpu_vce_bo bs; +struct amdgpu_vce_bo fb; +struct amdgpu_vce_bo mvrefbuf; +struct amdgpu_vce_bo mvb; +struct amdgpu_vce_bo cpb; +unsigned mvbuf_size; +unsigned ib_len; +}; + +static amdgpu_device_handle device_handle; +static uint32_t major_version; +static uint32_t minor_version; +static uint32_t family_id; +static uint32_t chip_rev; +static uint32_t chip_id; +static uint32_t ids_flags; + +static amdgpu_context_handle context_handle; +static amdgpu_bo_handle ib_handle; +static amdgpu_va_handle ib_va_handle; +static uint64_t ib_mc_address; +static uint32_t *ib_cpu; + +static struct amdgpu_vce_encode enc; +static amdgpu_bo_handle resources[MAX_RESOURCES ];
tests/amdgpu/vce_mv_tests.c line 88
Quoted 10 lines
tests/amdgpu/vce_mv_tests.c new file +10
-0+static unsigned num_resources; + +static void amdgpu_cs_vce_create (void ); +static void amdgpu_cs_vce_encode_mv (void ); +static void amdgpu_cs_vce_destroy (void ); + +CU_TestInfo vce_mv_tests[] = { + {"VCE create" , amdgpu_cs_vce_create }, + {"VCE mvdump" , amdgpu_cs_vce_encode_mv }, + {"VCE destroy" , amdgpu_cs_vce_destroy },
Why does it need to have a separated file, and many duplicated stuff from vce_tests.c ?
Regards,
Leo
Quoted 439 lines
tests/amdgpu/vce_mv_tests.c new file +439
-0+ CU_TEST_INFO_NULL, +}; + +CU_BOOL suite_vce_mv_tests_enable (void ) +{ +uint32_t version, feature; + +if (amdgpu_device_initialize (drm_amdgpu[0 ], &major_version, + &minor_version, &device_handle)) +return CU_FALSE ; + + family_id = device_handle->info.family_id; + chip_rev = device_handle->info.chip_rev; + chip_id = device_handle->info.chip_external_rev; + ids_flags = device_handle->info.ids_flags; + +amdgpu_query_firmware_version (device_handle,AMDGPU_INFO_FW_VCE ,0 , +0 , &version, &feature); + +if (amdgpu_device_deinitialize (device_handle)) +return CU_FALSE ; + +if (family_id >=AMDGPU_FAMILY_RV || family_id ==AMDGPU_FAMILY_SI ) { +printf ("\n\nThe ASIC family NOT support VCE MV, suite disabled\n" ); +return CU_FALSE ; + } + +if (!(chip_id == (chip_rev +0x14 ) ||/* TONGA */ + chip_id == (chip_rev +0x3C ) ||/* FIJI */ + chip_id == (chip_rev +0x50 ) ||/* Polaris 10*/ + chip_id == (chip_rev +0x5A ) ||/* Polaris 11*/ + chip_id == (chip_rev +0x64 ) ||/* Polaris 12*/ + (family_id >AMDGPU_FAMILY_VI && !ids_flags)))/* dGPU > Polaris */ { +printf ("\n\nThe ASIC NOT support VCE MV, suite disabled\n" ); +return CU_FALSE ; + } + +if (FW_53_0_03 >= version){ +printf ("\n\nThe ASIC FW version NOT support VCE MV, suite disabled\n" ); +return CU_FALSE ; + } +return CU_TRUE ; +} + +int suite_vce_mv_tests_init (void ) +{ +int r; + + r =amdgpu_device_initialize (drm_amdgpu[0 ], &major_version, + &minor_version, &device_handle); +if (r) { +if ((r == -EACCES ) && (errno ==EACCES )) +printf ("\n\nError:%s. " +"Hint:Try to run this test program as root." , +strerror (errno)); + +return CUE_SINIT_FAILED ; + } + + family_id = device_handle->info.family_id; + + r =amdgpu_cs_ctx_create (device_handle, &context_handle); +if (r) +return CUE_SINIT_FAILED ; + + r =amdgpu_bo_alloc_and_map (device_handle,IB_SIZE ,4096 , +AMDGPU_GEM_DOMAIN_GTT ,0 , + &ib_handle, (void **)&ib_cpu, + &ib_mc_address, &ib_va_handle); +if (r) +return CUE_SINIT_FAILED ; + +memset (&enc,0 ,sizeof (struct amdgpu_vce_encode )); + +return CUE_SUCCESS ; +} + +int suite_vce_mv_tests_clean (void ) +{ +int r; + + r =amdgpu_bo_unmap_and_free (ib_handle, ib_va_handle, + ib_mc_address,IB_SIZE ); +if (r) +return CUE_SCLEAN_FAILED ; + + r =amdgpu_cs_ctx_free (context_handle); +if (r) +return CUE_SCLEAN_FAILED ; + + r =amdgpu_device_deinitialize (device_handle); +if (r) +return CUE_SCLEAN_FAILED ; + +return CUE_SUCCESS ; +} + +static int submit (unsigned ndw,unsigned ip) +{ +struct amdgpu_cs_request ibs_request = {0 }; +struct amdgpu_cs_ib_info ib_info = {0 }; +struct amdgpu_cs_fence fence_status = {0 }; +uint32_t expired; +int r; + + ib_info.ib_mc_address = ib_mc_address; + ib_info.size = ndw; + + ibs_request.ip_type = ip; + + r =amdgpu_bo_list_create (device_handle, num_resources, resources, +NULL , &ibs_request.resources); +if (r) +return r; + + ibs_request.number_of_ibs =1 ; + ibs_request.ibs = &ib_info; + ibs_request.fence_info.handle =NULL ; + + r =amdgpu_cs_submit (context_handle,0 , &ibs_request,1 ); +if (r) +return r; + + r =amdgpu_bo_list_destroy (ibs_request.resources); +if (r) +return r; + + fence_status.context = context_handle; + fence_status.ip_type = ip; + fence_status.fence = ibs_request.seq_no; + + r =amdgpu_cs_query_fence_status (&fence_status, +AMDGPU_TIMEOUT_INFINITE , +0 , &expired); +if (r) +return r; + +return 0 ; +} + +static void alloc_resource (struct amdgpu_vce_bo *vce_bo,unsigned size,unsigned domain) +{ +struct amdgpu_bo_alloc_request req = {0 }; +amdgpu_bo_handle buf_handle; +amdgpu_va_handle va_handle; +uint64_t va =0 ; +int r; + + req.alloc_size =ALIGN (size,4096 ); + req.preferred_heap = domain; + r =amdgpu_bo_alloc (device_handle, &req, &buf_handle); +CU_ASSERT_EQUAL (r,0 ); + r =amdgpu_va_range_alloc (device_handle, + amdgpu_gpu_va_range_general, + req.alloc_size,1 ,0 , &va, + &va_handle,0 ); +CU_ASSERT_EQUAL (r,0 ); + r =amdgpu_bo_va_op (buf_handle,0 , req.alloc_size, va,0 , +AMDGPU_VA_OP_MAP ); +CU_ASSERT_EQUAL (r,0 ); + vce_bo->addr = va; + vce_bo->handle = buf_handle; + vce_bo->size = req.alloc_size; + vce_bo->va_handle = va_handle; + r =amdgpu_bo_cpu_map (vce_bo->handle, (void **)&vce_bo->ptr); +CU_ASSERT_EQUAL (r,0 ); +memset (vce_bo->ptr,0 , size); + r =amdgpu_bo_cpu_unmap (vce_bo->handle); +CU_ASSERT_EQUAL (r,0 ); +} + +static void free_resource (struct amdgpu_vce_bo *vce_bo) +{ +int r; + + r =amdgpu_bo_va_op (vce_bo->handle,0 , vce_bo->size, + vce_bo->addr,0 ,AMDGPU_VA_OP_UNMAP ); +CU_ASSERT_EQUAL (r,0 ); + + r =amdgpu_va_range_free (vce_bo->va_handle); +CU_ASSERT_EQUAL (r,0 ); + + r =amdgpu_bo_free (vce_bo->handle); +CU_ASSERT_EQUAL (r,0 ); +memset (vce_bo,0 ,sizeof (*vce_bo)); +} + +static void amdgpu_cs_vce_create (void ) +{ +unsigned align = (family_id >=AMDGPU_FAMILY_AI ) ?256 :16 ; +int len, r; + + vce_create[11 ] =0x01000000 ;/* disableTwoInstance */ + vce_pic_ctrl[27 ] =0x00000001 ;/* encSliceMode */ + + enc.width = vce_create[6 ]; + enc.height = vce_create[7 ]; + + num_resources =0 ; +alloc_resource (&enc.fb,4096 ,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.fb.handle; + resources[num_resources++] = ib_handle; + + len =0 ; +memcpy (ib_cpu, vce_session,sizeof (vce_session)); + len +=sizeof (vce_session) /4 ; +memcpy ((ib_cpu + len), vce_taskinfo,sizeof (vce_taskinfo)); + len +=sizeof (vce_taskinfo) /4 ; +memcpy ((ib_cpu + len), vce_create,sizeof (vce_create)); + ib_cpu[len +8 ] =ALIGN (enc.width, align); + ib_cpu[len +9 ] =ALIGN (enc.width, align); + len +=sizeof (vce_create) /4 ; +memcpy ((ib_cpu + len), vce_feedback,sizeof (vce_feedback)); + ib_cpu[len +2 ] = enc.fb.addr >>32 ; + ib_cpu[len +3 ] = enc.fb.addr; + len +=sizeof (vce_feedback) /4 ; + + r =submit (len,AMDGPU_HW_IP_VCE ); +CU_ASSERT_EQUAL (r,0 ); + +free_resource (&enc.fb); +} + +static void amdgpu_cs_vce_config (void ) +{ +int len =0 , r; + +memcpy ((ib_cpu + len), vce_session,sizeof (vce_session)); + len +=sizeof (vce_session) /4 ; +memcpy ((ib_cpu + len), vce_taskinfo,sizeof (vce_taskinfo)); + ib_cpu[len +3 ] =2 ; + ib_cpu[len +6 ] =0xffffffff ; + len +=sizeof (vce_taskinfo) /4 ; +memcpy ((ib_cpu + len), vce_rate_ctrl,sizeof (vce_rate_ctrl)); + len +=sizeof (vce_rate_ctrl) /4 ; +memcpy ((ib_cpu + len), vce_config_ext,sizeof (vce_config_ext)); + len +=sizeof (vce_config_ext) /4 ; +memcpy ((ib_cpu + len), vce_motion_est,sizeof (vce_motion_est)); + len +=sizeof (vce_motion_est) /4 ; +memcpy ((ib_cpu + len), vce_rdo,sizeof (vce_rdo)); + len +=sizeof (vce_rdo) /4 ; +memcpy ((ib_cpu + len), vce_pic_ctrl,sizeof (vce_pic_ctrl)); + len +=sizeof (vce_pic_ctrl) /4 ; + + r =submit (len,AMDGPU_HW_IP_VCE ); +CU_ASSERT_EQUAL (r,0 ); +} + +static void amdgpu_cs_vce_mv (struct amdgpu_vce_encode *enc) +{ +uint64_t luma_offset, chroma_offset; +uint64_t mv_ref_luma_offset; +unsigned align = (family_id >=AMDGPU_FAMILY_AI ) ?256 :16 ; +unsigned luma_size =ALIGN (enc->width, align) *ALIGN (enc->height,16 ); +int len =0 , i, r; + + luma_offset = enc->vbuf.addr; + chroma_offset = luma_offset + luma_size; + mv_ref_luma_offset = enc->mvrefbuf.addr; + +memcpy ((ib_cpu + len), vce_session,sizeof (vce_session)); + len +=sizeof (vce_session) /4 ; +memcpy ((ib_cpu + len), vce_taskinfo,sizeof (vce_taskinfo)); + len +=sizeof (vce_taskinfo) /4 ; +memcpy ((ib_cpu + len), vce_bs_buffer,sizeof (vce_bs_buffer)); + ib_cpu[len +2 ] = enc->bs.addr >>32 ; + ib_cpu[len +3 ] = enc->bs.addr; + len +=sizeof (vce_bs_buffer) /4 ; +memcpy ((ib_cpu + len), vce_context_buffer,sizeof (vce_context_buffer)); + ib_cpu[len +2 ] = enc->cpb.addr >>32 ; + ib_cpu[len +3 ] = enc->cpb.addr; + len +=sizeof (vce_context_buffer) /4 ; +memcpy ((ib_cpu + len), vce_aux_buffer,sizeof (vce_aux_buffer)); +for (i =0 ; i <8 ; ++i) + ib_cpu[len +2 + i] = luma_size *1.5 * (i +2 ); +for (i =0 ; i <8 ; ++i) + ib_cpu[len +10 + i] = luma_size *1.5 ; + len +=sizeof (vce_aux_buffer) /4 ; +memcpy ((ib_cpu + len), vce_feedback,sizeof (vce_feedback)); + ib_cpu[len +2 ] = enc->fb.addr >>32 ; + ib_cpu[len +3 ] = enc->fb.addr; + len +=sizeof (vce_feedback) /4 ; +memcpy ((ib_cpu + len), vce_mv_buffer,sizeof (vce_mv_buffer)); + ib_cpu[len +2 ] = mv_ref_luma_offset >>32 ; + ib_cpu[len +3 ] = mv_ref_luma_offset; + ib_cpu[len +4 ] =ALIGN (enc->width, align); + ib_cpu[len +5 ] =ALIGN (enc->width, align); + ib_cpu[len +6 ] = luma_size; + ib_cpu[len +7 ] = enc->mvb.addr >>32 ; + ib_cpu[len +8 ] = enc->mvb.addr; + len +=sizeof (vce_mv_buffer) /4 ; +memcpy ((ib_cpu + len), vce_encode,sizeof (vce_encode)); + ib_cpu[len +2 ] =0 ; + ib_cpu[len +3 ] =0 ; + ib_cpu[len +4 ] =0x154000 ; + ib_cpu[len +9 ] = luma_offset >>32 ; + ib_cpu[len +10 ] = luma_offset; + ib_cpu[len +11 ] = chroma_offset >>32 ; + ib_cpu[len +12 ] = chroma_offset; + ib_cpu[len +13 ] =ALIGN (enc->height,16 );; + ib_cpu[len +14 ] =ALIGN (enc->width, align); + ib_cpu[len +15 ] =ALIGN (enc->width, align); +/* encDisableMBOffloading-encDisableTwoPipeMode-encInputPicArrayMode-encInputPicAddrMode */ + ib_cpu[len +16 ] =0x01010000 ; + ib_cpu[len +18 ] =0 ;/* encPicType */ + ib_cpu[len +19 ] =0 ;/* encIdrFlag */ + ib_cpu[len +20 ] =0 ;/* encIdrPicId */ + ib_cpu[len +21 ] =0 ;/* encMGSKeyPic */ + ib_cpu[len +22 ] =0 ;/* encReferenceFlag */ + ib_cpu[len +23 ] =0 ;/* encTemporalLayerIndex */ + ib_cpu[len +55 ] =0 ;/* pictureStructure */ + ib_cpu[len +56 ] =0 ;/* encPicType -ref[0] */ + ib_cpu[len +61 ] =0 ;/* pictureStructure */ + ib_cpu[len +62 ] =0 ;/* encPicType -ref[1] */ + ib_cpu[len +67 ] =0 ;/* pictureStructure */ + ib_cpu[len +68 ] =0 ;/* encPicType -ref1 */ + ib_cpu[len +81 ] =1 ;/* frameNumber */ + ib_cpu[len +82 ] =2 ;/* pictureOrderCount */ + ib_cpu[len +83 ] =0xffffffff ;/* numIPicRemainInRCGOP */ + ib_cpu[len +84 ] =0xffffffff ;/* numPPicRemainInRCGOP */ + ib_cpu[len +85 ] =0xffffffff ;/* numBPicRemainInRCGOP */ + ib_cpu[len +86 ] =0xffffffff ;/* numIRPicRemainInRCGOP */ + ib_cpu[len +87 ] =0 ;/* remainedIntraRefreshPictures */ + len +=sizeof (vce_encode) /4 ; + + enc->ib_len = len; + r =submit (len,AMDGPU_HW_IP_VCE ); +CU_ASSERT_EQUAL (r,0 ); +} + +static void check_mv_result (struct amdgpu_vce_encode *enc) +{ +uint64_t sum; +uint32_t s =140790 ; +uint32_t *ptr, size; +int i, j, r; + + r =amdgpu_bo_cpu_map (enc->fb.handle, (void **)&enc->fb.ptr); +CU_ASSERT_EQUAL (r,0 ); + ptr = (uint32_t *)enc->fb.ptr; + r =amdgpu_bo_cpu_unmap (enc->fb.handle); +CU_ASSERT_EQUAL (r,0 ); + r =amdgpu_bo_cpu_map (enc->mvb.handle, (void **)&enc->mvb.ptr); +CU_ASSERT_EQUAL (r,0 ); +for (j =0 , sum =0 ; j < enc->mvbuf_size; ++j) + sum += enc->mvb.ptr[j]; +CU_ASSERT_EQUAL (sum, s); + r =amdgpu_bo_cpu_unmap (enc->mvb.handle); +CU_ASSERT_EQUAL (r,0 ); +} + +static void amdgpu_cs_vce_encode_mv (void ) +{ +uint32_t vbuf_size, bs_size =0x154000 , cpb_size; +unsigned align = (family_id >=AMDGPU_FAMILY_AI ) ?256 :16 ; +int i, r; + + vbuf_size =ALIGN (enc.width, align) *ALIGN (enc.height,16 ) *1.5 ; + enc.mvbuf_size =ALIGN (enc.width,16 ) *ALIGN (enc.height,16 ) /8 ; + cpb_size = vbuf_size *10 ; + num_resources =0 ; +alloc_resource (&enc.fb,4096 ,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.fb.handle; +alloc_resource (&enc.bs, bs_size,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.bs.handle; +alloc_resource (&enc.mvb, enc.mvbuf_size,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.mvb.handle; +alloc_resource (&enc.vbuf, vbuf_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.vbuf.handle; +alloc_resource (&enc.mvrefbuf, vbuf_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.mvrefbuf.handle; +alloc_resource (&enc.cpb, cpb_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.cpb.handle; + resources[num_resources++] = ib_handle; + + r =amdgpu_bo_cpu_map (enc.vbuf.handle, (void **)&enc.vbuf.ptr); +CU_ASSERT_EQUAL (r,0 ); + +memset (enc.vbuf.ptr,0 , vbuf_size); +for (i =0 ; i < enc.height; ++i) { +memcpy (enc.vbuf.ptr, (frame + i * enc.width), enc.width); + enc.vbuf.ptr +=ALIGN (enc.width, align); + } +for (i =0 ; i < enc.height /2 ; ++i) { +memcpy (enc.vbuf.ptr, ((frame + enc.height * enc.width) + i * enc.width), enc.width); + enc.vbuf.ptr +=ALIGN (enc.width, align); + } + + r =amdgpu_bo_cpu_unmap (enc.vbuf.handle); +CU_ASSERT_EQUAL (r,0 ); + + r =amdgpu_bo_cpu_map (enc.mvrefbuf.handle, (void **)&enc.mvrefbuf.ptr); +CU_ASSERT_EQUAL (r,0 ); + +memset (enc.mvrefbuf.ptr,0 , vbuf_size); +for (i =0 ; i < enc.height; ++i) { +memcpy (enc.mvrefbuf.ptr, (frame + (enc.height - i -1 ) * enc.width), enc.width); + enc.mvrefbuf.ptr +=ALIGN (enc.width, align); + } +for (i =0 ; i < enc.height /2 ; ++i) { +memcpy (enc.mvrefbuf.ptr, + ((frame + enc.height * enc.width) + (enc.height /2 - i -1 ) * enc.width), enc.width); + enc.mvrefbuf.ptr +=ALIGN (enc.width, align); + } + + r =amdgpu_bo_cpu_unmap (enc.mvrefbuf.handle); +CU_ASSERT_EQUAL (r,0 ); + +amdgpu_cs_vce_config (); + + vce_taskinfo[3 ] =3 ; +amdgpu_cs_vce_mv (&enc); +check_mv_result (&enc); + +free_resource (&enc.fb); +free_resource (&enc.bs); +free_resource (&enc.vbuf); +free_resource (&enc.cpb); +free_resource (&enc.mvrefbuf); +free_resource (&enc.mvb); +} + +static void amdgpu_cs_vce_destroy (void ) +{ +int len, r; + + num_resources =0 ; +alloc_resource (&enc.fb,4096 ,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.fb.handle; + resources[num_resources++] = ib_handle; + + len =0 ; +memcpy (ib_cpu, vce_session,sizeof (vce_session)); + len +=sizeof (vce_session) /4 ; +memcpy ((ib_cpu + len), vce_taskinfo,sizeof (vce_taskinfo)); + ib_cpu[len +3 ] =1 ; + len +=sizeof (vce_taskinfo) /4 ; +memcpy ((ib_cpu + len), vce_feedback,sizeof (vce_feedback)); + ib_cpu[len +2 ] = enc.fb.addr >>32 ;
tests/amdgpu/vce_mv_tests.c line 537
Quoted 10 lines
tests/amdgpu/vce_mv_tests.c new file +10
-0+ ib_cpu[len +3 ] = enc.fb.addr; + len +=sizeof (vce_feedback) /4 ; +memcpy ((ib_cpu + len), vce_destroy,sizeof (vce_destroy)); + len +=sizeof (vce_destroy) /4 ; + + r =submit (len,AMDGPU_HW_IP_VCE ); +CU_ASSERT_EQUAL (r,0 ); + +free_resource (&enc.fb); +}
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 8d2839b2-a7a2-74e1-fa2f-446aa89eb57c-5C7GfCeVMHo@public.gmane.org
Quoted 243 lines · Leo Liu
Quoted 228 lines · James Zhu
Signed-off-by James Zhu <[email protected]>---
tests/amdgpu/Makefile.am | 1 +
tests/amdgpu/amdgpu_test.c | 11 +
tests/amdgpu/amdgpu_test.h | 20 ++
tests/amdgpu/vce_ib.h | 21 +-
tests/amdgpu/vce_mv_tests.c| 537
++++++++++++++++++++++++++++++++++++++++++++5 files changed, 588 insertions(+), 2 deletions(-)create mode 100644
tests/amdgpu/vce_mv_tests.ctests/amdgpu/Makefile.am +1
-0@@ -26,6 +26,7 @@ amdgpu_test_SOURCES = \ cs_tests.c \ decode_messages.h \ vce_tests.c \ + vce_mv_tests.c \ vce_ib.h \ frame.h \ uvd_enc_tests.c \tests/amdgpu/amdgpu_test.c +11
-0@@ -52,6 +52,7 @@ #define BO_TESTS_STR "BO Tests" #define CS_TESTS_STR "CS Tests" #define VCE_TESTS_STR "VCE Tests" +#define VCE_MV_TESTS_STR "VCE MV Tests" #define VCN_TESTS_STR "VCN Tests" #define UVD_ENC_TESTS_STR "UVD ENC Tests" #define DEADLOCK_TESTS_STR "Deadlock Tests"@@ -93,6 +94,12 @@ static CU_SuiteInfo suites[] = { .pTests = vce_tests, }, { + .pName = VCE_MV_TESTS_STR, + .pInitFunc = suite_vce_mv_tests_init, + .pCleanupFunc = suite_vce_mv_tests_clean, + .pTests = vce_mv_tests, + }, + { .pName = VCN_TESTS_STR, .pInitFunc = suite_vcn_tests_init, .pCleanupFunc = suite_vcn_tests_clean,@@ -150,6 +157,10 @@ static Suites_Active_Status suites_active_stat[] = { .pActive = suite_vce_tests_enable, }, { + .pName = VCE_MV_TESTS_STR, + .pActive = suite_vce_mv_tests_enable, + }, + { .pName = VCN_TESTS_STR, .pActive = suite_vcn_tests_enable,},
tests/amdgpu/amdgpu_test.h +20
-0@@ -115,6 +115,26 @@ CU_BOOL suite_vce_tests_enable(void); extern CU_TestInfo vce_tests[]; /** +* Initialize vce test suite +*/ +int suite_vce_mv_tests_init (); + +/** +* Deinitialize vce test suite +*/ +int suite_vce_mv_tests_clean (); + +/** +* Decide if the suite is enabled by default or not. +*/ +CU_BOOL suite_vce_mv_tests_enable (void ); + +/** +* Tests in vce test suite +*/ +extern CU_TestInfo vce_mv_tests[]; + +/** + * Initialize vcn test suite
+ */
intsuite_vcn_tests_init();tests/amdgpu/vce_ib.h +19
-0@@ -41,7 +41,7 @@ static uint32_t vce_taskinfo[8] = { 0x00000000, }; -static const uint32_t vce_create[] = { +static uint32_t vce_create[] = { 0x00000030, 0x01000001, 0x00000000,@@ -144,7 +144,7 @@ static const uint32_t vce_rdo[] = { 0x00000000, }; -static const uint32_t vce_pic_ctrl[] = { +static uint32_t vce_pic_ctrl[] = { 0x00000074, 0x04000002, 0x00000000,@@ -315,4 +315,21 @@ static const uint32_t vce_destroy[] = { 0x00000008, 0x02000001, }; + +static const uint32_t vce_mv_buffer[] = { + 0x00000038, + 0x0500000d, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, +}; #endif /*_vce_ib_h*/tests/amdgpu/vce_mv_tests.c new file +4
-0@@ -0,0 +1,537 @@ +/* +* Copyright 2018 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *tests/amdgpu/vce_mv_tests.c new file +57
-0+*/ + +#include <stdio.h> +#include <inttypes.h> + +#include "CUnit/Basic.h" + +#include "util_math.h" + +#include "amdgpu_test.h" +#include "amdgpu_drm.h" +#include "amdgpu_internal.h" + +#include "vce_ib.h" +#include "frame.h" + +#define IB_SIZE 4096 +#define MAX_RESOURCES 16 +#define FW_53_0_03 ((53 << 24) | (0 << 16) | (03 << 8)) + +struct amdgpu_vce_bo { + amdgpu_bo_handle handle; + amdgpu_va_handle va_handle; + uint64_t addr; + uint64_t size; + uint8_t *ptr; +}; + +struct amdgpu_vce_encode { + unsigned width; + unsigned height; + struct amdgpu_vce_bo vbuf; + struct amdgpu_vce_bo bs; + struct amdgpu_vce_bo fb; + struct amdgpu_vce_bo mvrefbuf; + struct amdgpu_vce_bo mvb; + struct amdgpu_vce_bo cpb; + unsigned mvbuf_size; + unsigned ib_len; +}; + +static amdgpu_device_handle device_handle; +static uint32_t major_version; +static uint32_t minor_version; +static uint32_t family_id; +static uint32_t chip_rev; +static uint32_t chip_id; +static uint32_t ids_flags; + +static amdgpu_context_handle context_handle; +static amdgpu_bo_handle ib_handle; +static amdgpu_va_handle ib_va_handle; +static uint64_t ib_mc_address; +static uint32_t *ib_cpu; + +static struct amdgpu_vce_encode enc; +static amdgpu_bo_handle resources[MAX_RESOURCES ];tests/amdgpu/vce_mv_tests.c line 88
Quoted 10 lines
tests/amdgpu/vce_mv_tests.c new file +10
-0+static unsigned num_resources; + +static void amdgpu_cs_vce_create (void ); +static void amdgpu_cs_vce_encode_mv (void ); +static void amdgpu_cs_vce_destroy (void ); + +CU_TestInfo vce_mv_tests[] = { + { "VCE create", amdgpu_cs_vce_create }, + { "VCE mvdump", amdgpu_cs_vce_encode_mv }, + { "VCE destroy", amdgpu_cs_vce_destroy },Why does it need to have a separated file, and many duplicated stuff from
vce_tests.c?
Quoted 3 lines
Regards,
Leo
If we put them together. add one test set: { "VCE MV", amdgpu_cs_vce_mv_encode } in current vce test, this test must be execute no matter the asic support or not. No way to bypass. If we always return success if the asic doesn't support, it looks weird. If you don't matter this, I can combine them together.
Best Regards!
James zhu
Quoted 454 lines
Quoted 454 lines
+
CU_TEST_INFO_NULL,tests/amdgpu/vce_mv_tests.c new file +22
-0+}; + +CU_BOOL suite_vce_mv_tests_enable(void) +{ + uint32_t version, feature; + + if (amdgpu_device_initialize(drm_amdgpu[0], &major_version, + &minor_version, &device_handle)) + return CU_FALSE; + + family_id = device_handle->info.family_id; + chip_rev = device_handle->info.chip_rev; + chip_id = device_handle->info.chip_external_rev; + ids_flags = device_handle->info.ids_flags; + + amdgpu_query_firmware_version(device_handle, AMDGPU_INFO_FW_VCE, 0, + 0, &version, &feature); + + if (amdgpu_device_deinitialize(device_handle)) + return CU_FALSE; + + if (family_id >= AMDGPU_FAMILY_RV || family_id ==
AMDGPU_FAMILY_SI) {
+printf("\n\nThe ASIC family NOT support VCE MV, suite disabled\n");
+ returnCU_FALSE;
+ }
+
+ if (!(chip_id == (chip_rev+0x14) || /* TONGA */+ chip_id == (chip_rev + 0x3C) || /* FIJI */ + chip_id == (chip_rev + 0x50) || /* Polaris 10*/ + chip_id == (chip_rev + 0x5A) || /* Polaris 11*/ + chip_id == (chip_rev + 0x64) || /* Polaris 12*/+ (
family_id>AMDGPU_FAMILY_VI&& !ids_flags))) /* dGPU > Polaris */{
+printf("\n\nThe ASIC NOT support VCE MV, suite disabled\n"); + returnCU_FALSE;
+ }
+
+ if (FW_53_0_03>= version){
+printf("\n\nThe ASIC FW version NOT support VCE MV, suite disabled\n");
+ returnCU_FALSE;
+ }
+ returnCU_TRUE;tests/amdgpu/vce_mv_tests.c new file +99
-0+} + +int suite_vce_mv_tests_init (void ) +{ + int r; + + r = amdgpu_device_initialize(drm_amdgpu[0], &major_version, + &minor_version, &device_handle); + if (r) { + if ((r == -EACCES) && (errno == EACCES)) + printf("\n\nError:%s. " + "Hint:Try to run this test program as root.", + strerror(errno)); + + return CUE_SINIT_FAILED; + } + + family_id = device_handle->info.family_id; + + r = amdgpu_cs_ctx_create(device_handle, &context_handle); + if (r) + return CUE_SINIT_FAILED; + + r = amdgpu_bo_alloc_and_map(device_handle, IB_SIZE, 4096, + AMDGPU_GEM_DOMAIN_GTT, 0, + &ib_handle, (void**)&ib_cpu, + &ib_mc_address, &ib_va_handle); + if (r) + return CUE_SINIT_FAILED; + + memset(&enc, 0, sizeof(struct amdgpu_vce_encode)); + + return CUE_SUCCESS; +} + +int suite_vce_mv_tests_clean (void ) +{ + int r; + + r = amdgpu_bo_unmap_and_free(ib_handle, ib_va_handle, + ib_mc_address, IB_SIZE); + if (r) + return CUE_SCLEAN_FAILED; + + r = amdgpu_cs_ctx_free(context_handle); + if (r) + return CUE_SCLEAN_FAILED; + + r = amdgpu_device_deinitialize(device_handle); + if (r) + return CUE_SCLEAN_FAILED; + + return CUE_SUCCESS; +} + +static int submit (unsigned ndw,unsigned ip) +{ + struct amdgpu_cs_request ibs_request = {0}; + struct amdgpu_cs_ib_info ib_info = {0}; + struct amdgpu_cs_fence fence_status = {0}; + uint32_t expired; + int r; + + ib_info.ib_mc_address = ib_mc_address; + ib_info.size = ndw; + + ibs_request.ip_type = ip; + + r = amdgpu_bo_list_create(device_handle, num_resources, resources, + NULL, &ibs_request.resources); + if (r) + return r; + + ibs_request.number_of_ibs = 1; + ibs_request.ibs = &ib_info; + ibs_request.fence_info.handle = NULL; + + r = amdgpu_cs_submit(context_handle, 0, &ibs_request, 1); + if (r) + return r; + + r = amdgpu_bo_list_destroy(ibs_request.resources); + if (r) + return r; + + fence_status.context = context_handle; + fence_status.ip_type = ip; + fence_status.fence = ibs_request.seq_no; + + r = amdgpu_cs_query_fence_status(&fence_status, + AMDGPU_TIMEOUT_INFINITE, + 0, &expired); + if (r) + return r; + + return 0; +} + +static void alloc_resource(struct amdgpu_vce_bo *vce_bo, unsignedsize, unsigned domain)
tests/amdgpu/vce_mv_tests.c new file +113
-0+{ + struct amdgpu_bo_alloc_request req = {0}; + amdgpu_bo_handle buf_handle; + amdgpu_va_handle va_handle; + uint64_t va = 0; + int r; + + req.alloc_size = ALIGN(size, 4096); + req.preferred_heap = domain; + r = amdgpu_bo_alloc(device_handle, &req, &buf_handle); + CU_ASSERT_EQUAL(r, 0); + r = amdgpu_va_range_alloc(device_handle, + amdgpu_gpu_va_range_general, + req.alloc_size, 1, 0, &va, + &va_handle, 0); + CU_ASSERT_EQUAL(r, 0); + r = amdgpu_bo_va_op(buf_handle, 0, req.alloc_size, va, 0, + AMDGPU_VA_OP_MAP); + CU_ASSERT_EQUAL(r, 0); + vce_bo->addr = va; + vce_bo->handle = buf_handle; + vce_bo->size = req.alloc_size; + vce_bo->va_handle = va_handle; + r = amdgpu_bo_cpu_map(vce_bo->handle, (void **)&vce_bo->ptr); + CU_ASSERT_EQUAL(r, 0); + memset(vce_bo->ptr, 0, size); + r = amdgpu_bo_cpu_unmap(vce_bo->handle); + CU_ASSERT_EQUAL(r, 0); +} + +static void free_resource (struct amdgpu_vce_bo *vce_bo) +{ + int r; + + r = amdgpu_bo_va_op(vce_bo->handle, 0, vce_bo->size, + vce_bo->addr, 0, AMDGPU_VA_OP_UNMAP); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_va_range_free(vce_bo->va_handle); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_bo_free(vce_bo->handle); + CU_ASSERT_EQUAL(r, 0); + memset(vce_bo, 0, sizeof(*vce_bo)); +} + +static void amdgpu_cs_vce_create (void ) +{ + unsigned align = (family_id >= AMDGPU_FAMILY_AI) ? 256 : 16; + int len, r; + + vce_create[11] = 0x01000000; /* disableTwoInstance */ + vce_pic_ctrl[27] = 0x00000001; /* encSliceMode */ + + enc.width = vce_create[6]; + enc.height = vce_create[7]; + + num_resources = 0; + alloc_resource(&enc.fb, 4096, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.fb.handle; + resources[num_resources++] = ib_handle; + + len = 0; + memcpy(ib_cpu, vce_session, sizeof(vce_session)); + len += sizeof(vce_session) / 4; + memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); + len += sizeof(vce_taskinfo) / 4; + memcpy((ib_cpu + len), vce_create, sizeof(vce_create)); + ib_cpu[len + 8] = ALIGN(enc.width, align); + ib_cpu[len + 9] = ALIGN(enc.width, align); + len += sizeof(vce_create) / 4; + memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback)); + ib_cpu[len + 2] = enc.fb.addr >> 32; + ib_cpu[len + 3] = enc.fb.addr; + len += sizeof(vce_feedback) / 4; + + r = submit(len, AMDGPU_HW_IP_VCE); + CU_ASSERT_EQUAL(r, 0); + + free_resource(&enc.fb); +} + +static void amdgpu_cs_vce_config (void ) +{ + int len = 0, r; + + memcpy((ib_cpu + len), vce_session, sizeof(vce_session)); + len += sizeof(vce_session) / 4; + memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); + ib_cpu[len + 3] = 2; + ib_cpu[len + 6] = 0xffffffff; + len += sizeof(vce_taskinfo) / 4; + memcpy((ib_cpu + len), vce_rate_ctrl, sizeof(vce_rate_ctrl)); + len += sizeof(vce_rate_ctrl) / 4; + memcpy((ib_cpu + len), vce_config_ext, sizeof(vce_config_ext)); + len += sizeof(vce_config_ext) / 4; + memcpy((ib_cpu + len), vce_motion_est, sizeof(vce_motion_est)); + len += sizeof(vce_motion_est) / 4; + memcpy((ib_cpu + len), vce_rdo, sizeof(vce_rdo)); + len += sizeof(vce_rdo) / 4; + memcpy((ib_cpu + len), vce_pic_ctrl, sizeof(vce_pic_ctrl)); + len += sizeof(vce_pic_ctrl) / 4; + + r = submit(len, AMDGPU_HW_IP_VCE); + CU_ASSERT_EQUAL(r, 0); +} + +static void amdgpu_cs_vce_mv(struct amdgpu_vce_encode *enc) +{ + uint64_t luma_offset, chroma_offset; + uint64_t mv_ref_luma_offset; + unsigned align = (family_id >= AMDGPU_FAMILY_AI) ? 256 : 16; + unsigned luma_size = ALIGN(enc->width, align) *
ALIGN(enc->height, 16);
+ int len = 0, i, r;tests/amdgpu/vce_mv_tests.c new file +14
-0+ + luma_offset = enc->vbuf.addr; + chroma_offset = luma_offset + luma_size; + mv_ref_luma_offset = enc->mvrefbuf.addr; + + memcpy((ib_cpu + len), vce_session, sizeof(vce_session)); + len += sizeof(vce_session) / 4; + memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); + len += sizeof(vce_taskinfo) / 4; + memcpy((ib_cpu + len), vce_bs_buffer, sizeof(vce_bs_buffer)); + ib_cpu[len + 2] = enc->bs.addr >> 32; + ib_cpu[len + 3] = enc->bs.addr; + len += sizeof(vce_bs_buffer) / 4; + memcpy((ib_cpu + len), vce_context_buffer,
sizeof(vce_context_buffer));
+ ib_cpu[len + 2] =enc->cpb.addr>> 32;
+ ib_cpu[len + 3] =enc->cpb.addr;
+ len +=sizeof(vce_context_buffer)/ 4;
+memcpy((ib_cpu + len), vce_aux_buffer, sizeof(vce_aux_buffer));
+ for (i = 0; i < 8; ++i)
+ ib_cpu[len + 2 + i] =luma_size* 1.5 * (i + 2);
+ for (i = 0; i < 8; ++i)
+ ib_cpu[len + 10 + i] =luma_size* 1.5;
+ len +=sizeof(vce_aux_buffer)/ 4;
+memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback));
+ ib_cpu[len + 2] =enc->fb.addr>> 32;
+ ib_cpu[len + 3] =enc->fb.addr;
+ len +=sizeof(vce_feedback)/ 4;
+memcpy((ib_cpu + len), vce_mv_buffer, sizeof(vce_mv_buffer));
+ ib_cpu[len + 2] =mv_ref_luma_offset>> 32;
+ ib_cpu[len + 3] =mv_ref_luma_offset;
+ ib_cpu[len + 4] =ALIGN(enc->width, align);
+ ib_cpu[len + 5] =ALIGN(enc->width, align);
+ ib_cpu[len + 6] =luma_size;
+ ib_cpu[len + 7] =enc->mvb.addr>> 32;
+ ib_cpu[len + 8] =enc->mvb.addr;
+ len +=sizeof(vce_mv_buffer)/ 4;
+memcpy((ib_cpu + len), vce_encode, sizeof(vce_encode));
+ ib_cpu[len + 2] = 0;
+ ib_cpu[len + 3] = 0;
+ ib_cpu[len + 4] =0x154000;
+ ib_cpu[len + 9] =luma_offset>> 32;
+ ib_cpu[len + 10] =luma_offset;
+ ib_cpu[len + 11] =chroma_offset>> 32;
+ ib_cpu[len + 12] =chroma_offset;
+ ib_cpu[len + 13] =ALIGN(enc->height, 16);;
+ ib_cpu[len + 14] =ALIGN(enc->width, align);
+ ib_cpu[len + 15] =ALIGN(enc->width, align);
+ /* encDisableMBOffloading-encDisableTwoPipeMode-encInputPicArrayMode-encInputPicAddrMode */ + ib_cpu[len + 16] =0x01010000;
+ ib_cpu[len + 18] = 0; /* encPicType */
+ ib_cpu[len + 19] = 0; /* encIdrFlag */
+ ib_cpu[len + 20] = 0; /* encIdrPicId */
+ ib_cpu[len + 21] = 0; /* encMGSKeyPic */
+ ib_cpu[len + 22] = 0; /* encReferenceFlag */
+ ib_cpu[len + 23] = 0; /* encTemporalLayerIndex */
+ ib_cpu[len + 55] = 0; /* pictureStructure */
+ ib_cpu[len + 56] = 0; /* encPicType -ref[0] */
+ ib_cpu[len + 61] = 0; /* pictureStructure */
+ ib_cpu[len + 62] = 0; /* encPicType -ref[1] */
+ ib_cpu[len + 67] = 0; /* pictureStructure */
+ ib_cpu[len + 68] = 0; /* encPicType -ref1 */
+ ib_cpu[len + 81] = 1; /* frameNumber */
+ ib_cpu[len + 82] = 2; /* pictureOrderCount */
+ ib_cpu[len + 83] =0xffffffff; /* numIPicRemainInRCGOP */
+ ib_cpu[len + 84] =0xffffffff; /* numPPicRemainInRCGOP */
+ ib_cpu[len + 85] =0xffffffff; /* numBPicRemainInRCGOP */
+ ib_cpu[len + 86] =0xffffffff; /* numIRPicRemainInRCGOP */
+ ib_cpu[len + 87] = 0; /* remainedIntraRefreshPictures */
+ len +=sizeof(vce_encode)/ 4;tests/amdgpu/vce_mv_tests.c new file +61
-0+ + enc->ib_len = len; + r = submit(len, AMDGPU_HW_IP_VCE); + CU_ASSERT_EQUAL(r, 0); +} + +static void check_mv_result(struct amdgpu_vce_encode *enc) +{ + uint64_t sum; + uint32_t s = 140790; + uint32_t *ptr, size; + int i, j, r; + + r = amdgpu_bo_cpu_map(enc->fb.handle, (void **)&enc->fb.ptr); + CU_ASSERT_EQUAL(r, 0); + ptr = (uint32_t *)enc->fb.ptr; + r = amdgpu_bo_cpu_unmap(enc->fb.handle); + CU_ASSERT_EQUAL(r, 0); + r = amdgpu_bo_cpu_map(enc->mvb.handle, (void **)&enc->mvb.ptr); + CU_ASSERT_EQUAL(r, 0); + for (j = 0, sum = 0; j < enc->mvbuf_size; ++j) + sum += enc->mvb.ptr[j]; + CU_ASSERT_EQUAL(sum, s); + r = amdgpu_bo_cpu_unmap(enc->mvb.handle); + CU_ASSERT_EQUAL(r, 0); +} + +static void amdgpu_cs_vce_encode_mv(void) +{ + uint32_t vbuf_size, bs_size = 0x154000, cpb_size; + unsigned align = (family_id >= AMDGPU_FAMILY_AI) ? 256 : 16; + int i, r; + + vbuf_size = ALIGN(enc.width, align) * ALIGN(enc.height, 16) * 1.5; + enc.mvbuf_size = ALIGN(enc.width, 16) * ALIGN(enc.height, 16) / 8; + cpb_size = vbuf_size * 10; + num_resources = 0; + alloc_resource(&enc.fb, 4096, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.fb.handle; + alloc_resource(&enc.bs, bs_size, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.bs.handle; + alloc_resource(&enc.mvb, enc.mvbuf_size, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.mvb.handle; + alloc_resource(&enc.vbuf, vbuf_size, AMDGPU_GEM_DOMAIN_VRAM); + resources[num_resources++] = enc.vbuf.handle; + alloc_resource(&enc.mvrefbuf, vbuf_size, AMDGPU_GEM_DOMAIN_VRAM); + resources[num_resources++] = enc.mvrefbuf.handle; + alloc_resource(&enc.cpb, cpb_size, AMDGPU_GEM_DOMAIN_VRAM); + resources[num_resources++] = enc.cpb.handle; + resources[num_resources++] = ib_handle; + + r = amdgpu_bo_cpu_map(enc.vbuf.handle, (void **)&enc.vbuf.ptr); + CU_ASSERT_EQUAL(r, 0); + + memset(enc.vbuf.ptr, 0, vbuf_size); + for (i = 0; i < enc.height; ++i) { + memcpy(enc.vbuf.ptr, (frame + i * enc.width), enc.width); + enc.vbuf.ptr += ALIGN(enc.width, align); + } + for (i = 0; i < enc.height / 2; ++i) { + memcpy(enc.vbuf.ptr, ((frame + enc.height * enc.width) + i *enc.width), enc.width);
+ enc.vbuf.ptr +=ALIGN(enc.width, align);
+ }tests/amdgpu/vce_mv_tests.c new file +5
-0+ + r = amdgpu_bo_cpu_unmap(enc.vbuf.handle); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_bo_cpu_map(enc.mvrefbuf.handle, (void**)&enc.mvrefbuf.ptr);
+CU_ASSERT_EQUAL(r, 0);
+
+memset(enc.mvrefbuf.ptr, 0, vbuf_size);
+ for (i = 0; i < enc.height; ++i) {
+memcpy(enc.mvrefbuf.ptr, (frame + (enc.height - i -1) * enc.width), enc.width);
+ enc.mvrefbuf.ptr +=ALIGN(enc.width, align);
+ }
+ for (i = 0; i < enc.height / 2; ++i) {
+ memcpy(enc.mvrefbuf.ptr,
+ ((frame + enc.height * enc.width) + (enc.height / 2 - i -1)
* enc.width), enc.width);
+ enc.mvrefbuf.ptr +=ALIGN(enc.width, align);
+ }tests/amdgpu/vce_mv_tests.c new file +37
-0+ + r = amdgpu_bo_cpu_unmap(enc.mvrefbuf.handle); + CU_ASSERT_EQUAL(r, 0); + + amdgpu_cs_vce_config(); + + vce_taskinfo[3] = 3; + amdgpu_cs_vce_mv(&enc); + check_mv_result(&enc); + + free_resource(&enc.fb); + free_resource(&enc.bs); + free_resource(&enc.vbuf); + free_resource(&enc.cpb); + free_resource(&enc.mvrefbuf); + free_resource(&enc.mvb); +} + +static void amdgpu_cs_vce_destroy (void ) +{ + int len, r; + + num_resources = 0; + alloc_resource(&enc.fb, 4096, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.fb.handle; + resources[num_resources++] = ib_handle; + + len = 0; + memcpy(ib_cpu, vce_session, sizeof(vce_session)); + len += sizeof(vce_session) / 4; + memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); + ib_cpu[len + 3] = 1; + len += sizeof(vce_taskinfo) / 4; + memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback)); + ib_cpu[len + 2] = enc.fb.addr >> 32; + ib_cpu[len + 3] = enc.fb.addr; + len += sizeof(vce_feedback) / 4;
Quoted 9 lines
tests/amdgpu/vce_mv_tests.c line 310
Quoted 8 lines
+
memcpy((ib_cpu + len), vce_destroy, sizeof(vce_destroy)); + len +=sizeof(vce_destroy)/ 4;tests/amdgpu/vce_mv_tests.c new file +6
-0+ + r = submit(len, AMDGPU_HW_IP_VCE); + CU_ASSERT_EQUAL(r, 0); + + free_resource(&enc.fb); +}
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 0e972f5a-2d69-e8a7-1acb-76bee577d710-5C7GfCeVMHo@public.gmane.org
Quoted 247 lines · James Zhu
Quoted 244 lines · Leo Liu
Quoted 229 lines · James Zhu
Signed-off-by James Zhu <[email protected]>---
tests/amdgpu/Makefile.am | 1 +
tests/amdgpu/amdgpu_test.c | 11 +
tests/amdgpu/amdgpu_test.h | 20 ++
tests/amdgpu/vce_ib.h | 21 +-
tests/amdgpu/vce_mv_tests.c| 537
++++++++++++++++++++++++++++++++++++++++++++5 files changed, 588 insertions(+), 2 deletions(-)create mode 100644
tests/amdgpu/vce_mv_tests.ctests/amdgpu/Makefile.am +1
-0@@ -26,6 +26,7 @@ amdgpu_test_SOURCES = \ cs_tests.c \ decode_messages.h \ vce_tests.c \ + vce_mv_tests.c \ vce_ib.h \ frame.h \ uvd_enc_tests.c \tests/amdgpu/amdgpu_test.c +11
-0@@ -52,6 +52,7 @@ #define BO_TESTS_STR "BO Tests" #define CS_TESTS_STR "CS Tests" #define VCE_TESTS_STR "VCE Tests" +#define VCE_MV_TESTS_STR "VCE MV Tests" #define VCN_TESTS_STR "VCN Tests" #define UVD_ENC_TESTS_STR "UVD ENC Tests" #define DEADLOCK_TESTS_STR "Deadlock Tests"@@ -93,6 +94,12 @@ static CU_SuiteInfo suites[] = { .pTests = vce_tests, }, { + .pName = VCE_MV_TESTS_STR, + .pInitFunc = suite_vce_mv_tests_init, + .pCleanupFunc = suite_vce_mv_tests_clean, + .pTests = vce_mv_tests, + }, + { .pName = VCN_TESTS_STR, .pInitFunc = suite_vcn_tests_init, .pCleanupFunc = suite_vcn_tests_clean,@@ -150,6 +157,10 @@ static Suites_Active_Status suites_active_stat[] = { .pActive = suite_vce_tests_enable, }, { + .pName = VCE_MV_TESTS_STR, + .pActive = suite_vce_mv_tests_enable, + }, + { .pName = VCN_TESTS_STR, .pActive = suite_vcn_tests_enable,},
tests/amdgpu/amdgpu_test.h +20
-0@@ -115,6 +115,26 @@ CU_BOOL suite_vce_tests_enable(void); extern CU_TestInfo vce_tests[]; /** +* Initialize vce test suite +*/ +int suite_vce_mv_tests_init (); + +/** +* Deinitialize vce test suite +*/ +int suite_vce_mv_tests_clean (); + +/** +* Decide if the suite is enabled by default or not. +*/ +CU_BOOL suite_vce_mv_tests_enable (void ); + +/** +* Tests in vce test suite +*/ +extern CU_TestInfo vce_mv_tests[]; + +/** + * Initialize vcn test suite
+ */
intsuite_vcn_tests_init();tests/amdgpu/vce_ib.h +19
-0@@ -41,7 +41,7 @@ static uint32_t vce_taskinfo[8] = { 0x00000000, }; -static const uint32_t vce_create[] = { +static uint32_t vce_create[] = { 0x00000030, 0x01000001, 0x00000000,@@ -144,7 +144,7 @@ static const uint32_t vce_rdo[] = { 0x00000000, }; -static const uint32_t vce_pic_ctrl[] = { +static uint32_t vce_pic_ctrl[] = { 0x00000074, 0x04000002, 0x00000000,@@ -315,4 +315,21 @@ static const uint32_t vce_destroy[] = { 0x00000008, 0x02000001, }; + +static const uint32_t vce_mv_buffer[] = { + 0x00000038, + 0x0500000d, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, +}; #endif /*_vce_ib_h*/tests/amdgpu/vce_mv_tests.c new file +4
-0@@ -0,0 +1,537 @@ +/* +* Copyright 2018 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *tests/amdgpu/vce_mv_tests.c new file +57
-0+*/ + +#include <stdio.h> +#include <inttypes.h> + +#include "CUnit/Basic.h" + +#include "util_math.h" + +#include "amdgpu_test.h" +#include "amdgpu_drm.h" +#include "amdgpu_internal.h" + +#include "vce_ib.h" +#include "frame.h" + +#define IB_SIZE 4096 +#define MAX_RESOURCES 16 +#define FW_53_0_03 ((53 << 24) | (0 << 16) | (03 << 8)) + +struct amdgpu_vce_bo { + amdgpu_bo_handle handle; + amdgpu_va_handle va_handle; + uint64_t addr; + uint64_t size; + uint8_t *ptr; +}; + +struct amdgpu_vce_encode { + unsigned width; + unsigned height; + struct amdgpu_vce_bo vbuf; + struct amdgpu_vce_bo bs; + struct amdgpu_vce_bo fb; + struct amdgpu_vce_bo mvrefbuf; + struct amdgpu_vce_bo mvb; + struct amdgpu_vce_bo cpb; + unsigned mvbuf_size; + unsigned ib_len; +}; + +static amdgpu_device_handle device_handle; +static uint32_t major_version; +static uint32_t minor_version; +static uint32_t family_id; +static uint32_t chip_rev; +static uint32_t chip_id; +static uint32_t ids_flags; + +static amdgpu_context_handle context_handle; +static amdgpu_bo_handle ib_handle; +static amdgpu_va_handle ib_va_handle; +static uint64_t ib_mc_address; +static uint32_t *ib_cpu; + +static struct amdgpu_vce_encode enc; +static amdgpu_bo_handle resources[MAX_RESOURCES ];tests/amdgpu/vce_mv_tests.c line 88
Quoted 10 lines
tests/amdgpu/vce_mv_tests.c new file +10
-0+static unsigned num_resources; + +static void amdgpu_cs_vce_create (void ); +static void amdgpu_cs_vce_encode_mv (void ); +static void amdgpu_cs_vce_destroy (void ); + +CU_TestInfo vce_mv_tests[] = { + { "VCE create", amdgpu_cs_vce_create }, + { "VCE mvdump", amdgpu_cs_vce_encode_mv }, + { "VCE destroy", amdgpu_cs_vce_destroy },Why does it need to have a separated file, and many duplicated stuff from
vce_tests.c?
Quoted 5 lines
Quoted 3 lines
Regards,
LeoIf we put them together. add one test set: { "VCE MV",
amdgpu_cs_vce_mv_encode} in current vce test, this test must be execute no matter the asic support or not. No way to bypass. If we always return success if the asic doesn't support, it looks weird.
I think you could print "Not support" and bypass it with return success, since MV test should belong to one of the VCE tests.
Regards,
Leo
Quoted 470 lines
If you don't matter this, I can combine them together.
Best Regards!
James zhuQuoted 464 lines
Quoted 463 lines
+
CU_TEST_INFO_NULL,tests/amdgpu/vce_mv_tests.c new file +16
-0+}; + +CU_BOOL suite_vce_mv_tests_enable (void ) +{ + uint32_t version, feature; + + if (amdgpu_device_initialize(drm_amdgpu[0], &major_version, + &minor_version, &device_handle)) + return CU_FALSE; + + family_id = device_handle->info.family_id; + chip_rev = device_handle->info.chip_rev; + chip_id = device_handle->info.chip_external_rev; + ids_flags = device_handle->info.ids_flags; + + amdgpu_query_firmware_version(device_handle,
AMDGPU_INFO_FW_VCE, 0,
+ 0, &version, &feature);tests/amdgpu/vce_mv_tests.c new file +5
-0+ + if (amdgpu_device_deinitialize(device_handle)) + return CU_FALSE; + + if (family_id >= AMDGPU_FAMILY_RV || family_id ==
AMDGPU_FAMILY_SI) {
+printf("\n\nThe ASIC family NOT support VCE MV, suite disabled\n");
+ returnCU_FALSE;
+ }
+
+ if (!(chip_id == (chip_rev+0x14) || /* TONGA */+ chip_id == (chip_rev + 0x3C) || /* FIJI */ + chip_id == (chip_rev + 0x50) || /* Polaris 10*/ + chip_id == (chip_rev + 0x5A) || /* Polaris 11*/ + chip_id == (chip_rev + 0x64) || /* Polaris 12*/+ (
family_id>AMDGPU_FAMILY_VI&& !ids_flags))) /* dGPUQuoted 1 line
Polaris */{
+
printf("\n\nThe ASIC NOT support VCE MV, suite disabled\n"); + returnCU_FALSE;
+ }
+
+ if (FW_53_0_03>= version){
+printf("\n\nThe ASIC FW version NOT support VCE MV, suite disabled\n");
+ returnCU_FALSE;
+ }
+ returnCU_TRUE;tests/amdgpu/vce_mv_tests.c new file +99
-0+} + +int suite_vce_mv_tests_init (void ) +{ + int r; + + r = amdgpu_device_initialize(drm_amdgpu[0], &major_version, + &minor_version, &device_handle); + if (r) { + if ((r == -EACCES) && (errno == EACCES)) + printf("\n\nError:%s. " + "Hint:Try to run this test program as root.", + strerror(errno)); + + return CUE_SINIT_FAILED; + } + + family_id = device_handle->info.family_id; + + r = amdgpu_cs_ctx_create(device_handle, &context_handle); + if (r) + return CUE_SINIT_FAILED; + + r = amdgpu_bo_alloc_and_map(device_handle, IB_SIZE, 4096, + AMDGPU_GEM_DOMAIN_GTT, 0, + &ib_handle, (void**)&ib_cpu, + &ib_mc_address, &ib_va_handle); + if (r) + return CUE_SINIT_FAILED; + + memset(&enc, 0, sizeof(struct amdgpu_vce_encode)); + + return CUE_SUCCESS; +} + +int suite_vce_mv_tests_clean (void ) +{ + int r; + + r = amdgpu_bo_unmap_and_free(ib_handle, ib_va_handle, + ib_mc_address, IB_SIZE); + if (r) + return CUE_SCLEAN_FAILED; + + r = amdgpu_cs_ctx_free(context_handle); + if (r) + return CUE_SCLEAN_FAILED; + + r = amdgpu_device_deinitialize(device_handle); + if (r) + return CUE_SCLEAN_FAILED; + + return CUE_SUCCESS; +} + +static int submit (unsigned ndw,unsigned ip) +{ + struct amdgpu_cs_request ibs_request = {0}; + struct amdgpu_cs_ib_info ib_info = {0}; + struct amdgpu_cs_fence fence_status = {0}; + uint32_t expired; + int r; + + ib_info.ib_mc_address = ib_mc_address; + ib_info.size = ndw; + + ibs_request.ip_type = ip; + + r = amdgpu_bo_list_create(device_handle, num_resources, resources, + NULL, &ibs_request.resources); + if (r) + return r; + + ibs_request.number_of_ibs = 1; + ibs_request.ibs = &ib_info; + ibs_request.fence_info.handle = NULL; + + r = amdgpu_cs_submit(context_handle, 0, &ibs_request, 1); + if (r) + return r; + + r = amdgpu_bo_list_destroy(ibs_request.resources); + if (r) + return r; + + fence_status.context = context_handle; + fence_status.ip_type = ip; + fence_status.fence = ibs_request.seq_no; + + r = amdgpu_cs_query_fence_status(&fence_status, + AMDGPU_TIMEOUT_INFINITE, + 0, &expired); + if (r) + return r; + + return 0; +} + +static void alloc_resource(struct amdgpu_vce_bo *vce_bo, unsignedsize, unsigned domain)
tests/amdgpu/vce_mv_tests.c new file +113
-0+{ + struct amdgpu_bo_alloc_request req = {0}; + amdgpu_bo_handle buf_handle; + amdgpu_va_handle va_handle; + uint64_t va = 0; + int r; + + req.alloc_size = ALIGN(size, 4096); + req.preferred_heap = domain; + r = amdgpu_bo_alloc(device_handle, &req, &buf_handle); + CU_ASSERT_EQUAL(r, 0); + r = amdgpu_va_range_alloc(device_handle, + amdgpu_gpu_va_range_general, + req.alloc_size, 1, 0, &va, + &va_handle, 0); + CU_ASSERT_EQUAL(r, 0); + r = amdgpu_bo_va_op(buf_handle, 0, req.alloc_size, va, 0, + AMDGPU_VA_OP_MAP); + CU_ASSERT_EQUAL(r, 0); + vce_bo->addr = va; + vce_bo->handle = buf_handle; + vce_bo->size = req.alloc_size; + vce_bo->va_handle = va_handle; + r = amdgpu_bo_cpu_map(vce_bo->handle, (void **)&vce_bo->ptr); + CU_ASSERT_EQUAL(r, 0); + memset(vce_bo->ptr, 0, size); + r = amdgpu_bo_cpu_unmap(vce_bo->handle); + CU_ASSERT_EQUAL(r, 0); +} + +static void free_resource (struct amdgpu_vce_bo *vce_bo) +{ + int r; + + r = amdgpu_bo_va_op(vce_bo->handle, 0, vce_bo->size, + vce_bo->addr, 0, AMDGPU_VA_OP_UNMAP); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_va_range_free(vce_bo->va_handle); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_bo_free(vce_bo->handle); + CU_ASSERT_EQUAL(r, 0); + memset(vce_bo, 0, sizeof(*vce_bo)); +} + +static void amdgpu_cs_vce_create (void ) +{ + unsigned align = (family_id >= AMDGPU_FAMILY_AI) ? 256 : 16; + int len, r; + + vce_create[11] = 0x01000000; /* disableTwoInstance */ + vce_pic_ctrl[27] = 0x00000001; /* encSliceMode */ + + enc.width = vce_create[6]; + enc.height = vce_create[7]; + + num_resources = 0; + alloc_resource(&enc.fb, 4096, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.fb.handle; + resources[num_resources++] = ib_handle; + + len = 0; + memcpy(ib_cpu, vce_session, sizeof(vce_session)); + len += sizeof(vce_session) / 4; + memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); + len += sizeof(vce_taskinfo) / 4; + memcpy((ib_cpu + len), vce_create, sizeof(vce_create)); + ib_cpu[len + 8] = ALIGN(enc.width, align); + ib_cpu[len + 9] = ALIGN(enc.width, align); + len += sizeof(vce_create) / 4; + memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback)); + ib_cpu[len + 2] = enc.fb.addr >> 32; + ib_cpu[len + 3] = enc.fb.addr; + len += sizeof(vce_feedback) / 4; + + r = submit(len, AMDGPU_HW_IP_VCE); + CU_ASSERT_EQUAL(r, 0); + + free_resource(&enc.fb); +} + +static void amdgpu_cs_vce_config (void ) +{ + int len = 0, r; + + memcpy((ib_cpu + len), vce_session, sizeof(vce_session)); + len += sizeof(vce_session) / 4; + memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); + ib_cpu[len + 3] = 2; + ib_cpu[len + 6] = 0xffffffff; + len += sizeof(vce_taskinfo) / 4; + memcpy((ib_cpu + len), vce_rate_ctrl, sizeof(vce_rate_ctrl)); + len += sizeof(vce_rate_ctrl) / 4; + memcpy((ib_cpu + len), vce_config_ext, sizeof(vce_config_ext)); + len += sizeof(vce_config_ext) / 4; + memcpy((ib_cpu + len), vce_motion_est, sizeof(vce_motion_est)); + len += sizeof(vce_motion_est) / 4; + memcpy((ib_cpu + len), vce_rdo, sizeof(vce_rdo)); + len += sizeof(vce_rdo) / 4; + memcpy((ib_cpu + len), vce_pic_ctrl, sizeof(vce_pic_ctrl)); + len += sizeof(vce_pic_ctrl) / 4; + + r = submit(len, AMDGPU_HW_IP_VCE); + CU_ASSERT_EQUAL(r, 0); +} + +static void amdgpu_cs_vce_mv(struct amdgpu_vce_encode *enc) +{ + uint64_t luma_offset, chroma_offset; + uint64_t mv_ref_luma_offset; + unsigned align = (family_id >= AMDGPU_FAMILY_AI) ? 256 : 16; + unsigned luma_size = ALIGN(enc->width, align) *
ALIGN(enc->height, 16);
+ int len = 0, i, r;tests/amdgpu/vce_mv_tests.c new file +14
-0+ + luma_offset = enc->vbuf.addr; + chroma_offset = luma_offset + luma_size; + mv_ref_luma_offset = enc->mvrefbuf.addr; + + memcpy((ib_cpu + len), vce_session, sizeof(vce_session)); + len += sizeof(vce_session) / 4; + memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); + len += sizeof(vce_taskinfo) / 4; + memcpy((ib_cpu + len), vce_bs_buffer, sizeof(vce_bs_buffer)); + ib_cpu[len + 2] = enc->bs.addr >> 32; + ib_cpu[len + 3] = enc->bs.addr; + len += sizeof(vce_bs_buffer) / 4; + memcpy((ib_cpu + len), vce_context_buffer,
sizeof(vce_context_buffer));
+ ib_cpu[len + 2] =enc->cpb.addr>> 32;
+ ib_cpu[len + 3] =enc->cpb.addr;
+ len +=sizeof(vce_context_buffer)/ 4;
+memcpy((ib_cpu + len), vce_aux_buffer, sizeof(vce_aux_buffer));
+ for (i = 0; i < 8; ++i)
+ ib_cpu[len + 2 + i] =luma_size* 1.5 * (i + 2);
+ for (i = 0; i < 8; ++i)
+ ib_cpu[len + 10 + i] =luma_size* 1.5;
+ len +=sizeof(vce_aux_buffer)/ 4;
+memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback));
+ ib_cpu[len + 2] =enc->fb.addr>> 32;
+ ib_cpu[len + 3] =enc->fb.addr;
+ len +=sizeof(vce_feedback)/ 4;
+memcpy((ib_cpu + len), vce_mv_buffer, sizeof(vce_mv_buffer));
+ ib_cpu[len + 2] =mv_ref_luma_offset>> 32;
+ ib_cpu[len + 3] =mv_ref_luma_offset;
+ ib_cpu[len + 4] =ALIGN(enc->width, align);
+ ib_cpu[len + 5] =ALIGN(enc->width, align);
+ ib_cpu[len + 6] =luma_size;
+ ib_cpu[len + 7] =enc->mvb.addr>> 32;
+ ib_cpu[len + 8] =enc->mvb.addr;
+ len +=sizeof(vce_mv_buffer)/ 4;
+memcpy((ib_cpu + len), vce_encode, sizeof(vce_encode));
+ ib_cpu[len + 2] = 0;
+ ib_cpu[len + 3] = 0;
+ ib_cpu[len + 4] =0x154000;
+ ib_cpu[len + 9] =luma_offset>> 32;
+ ib_cpu[len + 10] =luma_offset;
+ ib_cpu[len + 11] =chroma_offset>> 32;
+ ib_cpu[len + 12] =chroma_offset;
+ ib_cpu[len + 13] =ALIGN(enc->height, 16);;
+ ib_cpu[len + 14] =ALIGN(enc->width, align);
+ ib_cpu[len + 15] =ALIGN(enc->width, align);
+ /* encDisableMBOffloading-encDisableTwoPipeMode-encInputPicArrayMode-encInputPicAddrMode */ + ib_cpu[len + 16] =0x01010000;
+ ib_cpu[len + 18] = 0; /* encPicType */
+ ib_cpu[len + 19] = 0; /* encIdrFlag */
+ ib_cpu[len + 20] = 0; /* encIdrPicId */
+ ib_cpu[len + 21] = 0; /* encMGSKeyPic */
+ ib_cpu[len + 22] = 0; /* encReferenceFlag */
+ ib_cpu[len + 23] = 0; /* encTemporalLayerIndex */
+ ib_cpu[len + 55] = 0; /* pictureStructure */
+ ib_cpu[len + 56] = 0; /* encPicType -ref[0] */
+ ib_cpu[len + 61] = 0; /* pictureStructure */
+ ib_cpu[len + 62] = 0; /* encPicType -ref[1] */
+ ib_cpu[len + 67] = 0; /* pictureStructure */
+ ib_cpu[len + 68] = 0; /* encPicType -ref1 */
+ ib_cpu[len + 81] = 1; /* frameNumber */
+ ib_cpu[len + 82] = 2; /* pictureOrderCount */
+ ib_cpu[len + 83] =0xffffffff; /* numIPicRemainInRCGOP */
+ ib_cpu[len + 84] =0xffffffff; /* numPPicRemainInRCGOP */
+ ib_cpu[len + 85] =0xffffffff; /* numBPicRemainInRCGOP */
+ ib_cpu[len + 86] =0xffffffff; /* numIRPicRemainInRCGOP */
+ ib_cpu[len + 87] = 0; /* remainedIntraRefreshPictures */
+ len +=sizeof(vce_encode)/ 4;tests/amdgpu/vce_mv_tests.c new file +61
-0+ + enc->ib_len = len; + r = submit(len, AMDGPU_HW_IP_VCE); + CU_ASSERT_EQUAL(r, 0); +} + +static void check_mv_result (struct amdgpu_vce_encode *enc) +{ + uint64_t sum; + uint32_t s = 140790; + uint32_t *ptr, size; + int i, j, r; + + r = amdgpu_bo_cpu_map(enc->fb.handle, (void **)&enc->fb.ptr); + CU_ASSERT_EQUAL(r, 0); + ptr = (uint32_t *)enc->fb.ptr; + r = amdgpu_bo_cpu_unmap(enc->fb.handle); + CU_ASSERT_EQUAL(r, 0); + r = amdgpu_bo_cpu_map(enc->mvb.handle, (void **)&enc->mvb.ptr); + CU_ASSERT_EQUAL(r, 0); + for (j = 0, sum = 0; j < enc->mvbuf_size; ++j) + sum += enc->mvb.ptr[j]; + CU_ASSERT_EQUAL(sum, s); + r = amdgpu_bo_cpu_unmap(enc->mvb.handle); + CU_ASSERT_EQUAL(r, 0); +} + +static void amdgpu_cs_vce_encode_mv (void ) +{ + uint32_t vbuf_size, bs_size = 0x154000, cpb_size; + unsigned align = (family_id >= AMDGPU_FAMILY_AI) ? 256 : 16; + int i, r; + + vbuf_size = ALIGN(enc.width, align) * ALIGN(enc.height, 16) * 1.5; + enc.mvbuf_size = ALIGN(enc.width, 16) * ALIGN(enc.height, 16) / 8; + cpb_size = vbuf_size * 10; + num_resources = 0; + alloc_resource(&enc.fb, 4096, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.fb.handle; + alloc_resource(&enc.bs, bs_size, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.bs.handle; + alloc_resource(&enc.mvb, enc.mvbuf_size, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.mvb.handle; + alloc_resource(&enc.vbuf, vbuf_size, AMDGPU_GEM_DOMAIN_VRAM); + resources[num_resources++] = enc.vbuf.handle; + alloc_resource(&enc.mvrefbuf, vbuf_size, AMDGPU_GEM_DOMAIN_VRAM); + resources[num_resources++] = enc.mvrefbuf.handle; + alloc_resource(&enc.cpb, cpb_size, AMDGPU_GEM_DOMAIN_VRAM); + resources[num_resources++] = enc.cpb.handle; + resources[num_resources++] = ib_handle; + + r = amdgpu_bo_cpu_map(enc.vbuf.handle, (void **)&enc.vbuf.ptr); + CU_ASSERT_EQUAL(r, 0); + + memset(enc.vbuf.ptr, 0, vbuf_size); + for (i = 0; i < enc.height; ++i) { + memcpy(enc.vbuf.ptr, (frame + i * enc.width), enc.width); + enc.vbuf.ptr += ALIGN(enc.width, align); + } + for (i = 0; i < enc.height / 2; ++i) { + memcpy(enc.vbuf.ptr, ((frame + enc.height * enc.width) + i* enc.width), enc.width);
+ enc.vbuf.ptr +=ALIGN(enc.width, align);
+ }tests/amdgpu/vce_mv_tests.c new file +5
-0+ + r = amdgpu_bo_cpu_unmap(enc.vbuf.handle); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_bo_cpu_map(enc.mvrefbuf.handle, (void**)&enc.mvrefbuf.ptr);
+CU_ASSERT_EQUAL(r, 0);
+
+memset(enc.mvrefbuf.ptr, 0, vbuf_size);
+ for (i = 0; i < enc.height; ++i) {
+memcpy(enc.mvrefbuf.ptr, (frame + (enc.height - i -1) * enc.width), enc.width);
+ enc.mvrefbuf.ptr +=ALIGN(enc.width, align);
+ }
+ for (i = 0; i < enc.height / 2; ++i) {
+ memcpy(enc.mvrefbuf.ptr,
+ ((frame + enc.height * enc.width) + (enc.height / 2 - i -1)
* enc.width), enc.width);
+ enc.mvrefbuf.ptr +=ALIGN(enc.width, align);
+ }tests/amdgpu/vce_mv_tests.c new file +45
-0+ + r = amdgpu_bo_cpu_unmap(enc.mvrefbuf.handle); + CU_ASSERT_EQUAL(r, 0); + + amdgpu_cs_vce_config(); + + vce_taskinfo[3] = 3; + amdgpu_cs_vce_mv(&enc); + check_mv_result(&enc); + + free_resource(&enc.fb); + free_resource(&enc.bs); + free_resource(&enc.vbuf); + free_resource(&enc.cpb); + free_resource(&enc.mvrefbuf); + free_resource(&enc.mvb); +} + +static void amdgpu_cs_vce_destroy (void ) +{ + int len, r; + + num_resources = 0; + alloc_resource(&enc.fb, 4096, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.fb.handle; + resources[num_resources++] = ib_handle; + + len = 0; + memcpy(ib_cpu, vce_session, sizeof(vce_session)); + len += sizeof(vce_session) / 4; + memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); + ib_cpu[len + 3] = 1; + len += sizeof(vce_taskinfo) / 4; + memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback)); + ib_cpu[len + 2] = enc.fb.addr >> 32; + ib_cpu[len + 3] = enc.fb.addr; + len += sizeof(vce_feedback) / 4; + memcpy((ib_cpu + len), vce_destroy, sizeof(vce_destroy)); + len += sizeof(vce_destroy) / 4; + + r = submit(len, AMDGPU_HW_IP_VCE); + CU_ASSERT_EQUAL(r, 0); + + free_resource(&enc.fb); +}
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): a132c04a-6c40-bf7e-85c5-7c7f07b97fba-5C7GfCeVMHo@public.gmane.org
Quoted 253 lines · Leo Liu
Quoted 250 lines · James Zhu
Quoted 247 lines · Leo Liu
Quoted 229 lines · James Zhu
Signed-off-by James Zhu <[email protected]>---
tests/amdgpu/Makefile.am | 1 +
tests/amdgpu/amdgpu_test.c | 11 +
tests/amdgpu/amdgpu_test.h | 20 ++
tests/amdgpu/vce_ib.h | 21 +-
tests/amdgpu/vce_mv_tests.c| 537
++++++++++++++++++++++++++++++++++++++++++++5 files changed, 588 insertions(+), 2 deletions(-)create mode 100644
tests/amdgpu/vce_mv_tests.ctests/amdgpu/Makefile.am +1
-0@@ -26,6 +26,7 @@ amdgpu_test_SOURCES = \ cs_tests.c \ decode_messages.h \ vce_tests.c \ + vce_mv_tests.c \ vce_ib.h \ frame.h \ uvd_enc_tests.c \tests/amdgpu/amdgpu_test.c +11
-0@@ -52,6 +52,7 @@ #define BO_TESTS_STR "BO Tests" #define CS_TESTS_STR "CS Tests" #define VCE_TESTS_STR "VCE Tests" +#define VCE_MV_TESTS_STR "VCE MV Tests" #define VCN_TESTS_STR "VCN Tests" #define UVD_ENC_TESTS_STR "UVD ENC Tests" #define DEADLOCK_TESTS_STR "Deadlock Tests"@@ -93,6 +94,12 @@ static CU_SuiteInfo suites[] = { .pTests = vce_tests, }, { + .pName = VCE_MV_TESTS_STR, + .pInitFunc = suite_vce_mv_tests_init, + .pCleanupFunc = suite_vce_mv_tests_clean, + .pTests = vce_mv_tests, + }, + { .pName = VCN_TESTS_STR, .pInitFunc = suite_vcn_tests_init, .pCleanupFunc = suite_vcn_tests_clean,@@ -150,6 +157,10 @@ static Suites_Active_Status suites_active_stat[] = { .pActive = suite_vce_tests_enable, }, { + .pName = VCE_MV_TESTS_STR, + .pActive = suite_vce_mv_tests_enable, + }, + { .pName = VCN_TESTS_STR, .pActive = suite_vcn_tests_enable,},
tests/amdgpu/amdgpu_test.h +20
-0@@ -115,6 +115,26 @@ CU_BOOL suite_vce_tests_enable(void); extern CU_TestInfo vce_tests[]; /** +* Initialize vce test suite +*/ +int suite_vce_mv_tests_init (); + +/** +* Deinitialize vce test suite +*/ +int suite_vce_mv_tests_clean (); + +/** +* Decide if the suite is enabled by default or not. +*/ +CU_BOOL suite_vce_mv_tests_enable (void ); + +/** +* Tests in vce test suite +*/ +extern CU_TestInfo vce_mv_tests[]; + +/** + * Initialize vcn test suite
+ */
intsuite_vcn_tests_init();tests/amdgpu/vce_ib.h +19
-0@@ -41,7 +41,7 @@ static uint32_t vce_taskinfo[8] = { 0x00000000, }; -static const uint32_t vce_create[] = { +static uint32_t vce_create[] = { 0x00000030, 0x01000001, 0x00000000,@@ -144,7 +144,7 @@ static const uint32_t vce_rdo[] = { 0x00000000, }; -static const uint32_t vce_pic_ctrl[] = { +static uint32_t vce_pic_ctrl[] = { 0x00000074, 0x04000002, 0x00000000,@@ -315,4 +315,21 @@ static const uint32_t vce_destroy[] = { 0x00000008, 0x02000001, }; + +static const uint32_t vce_mv_buffer[] = { + 0x00000038, + 0x0500000d, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, +}; #endif /*_vce_ib_h*/tests/amdgpu/vce_mv_tests.c new file +4
-0@@ -0,0 +1,537 @@ +/* +* Copyright 2018 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *tests/amdgpu/vce_mv_tests.c new file +57
-0+*/ + +#include <stdio.h> +#include <inttypes.h> + +#include "CUnit/Basic.h" + +#include "util_math.h" + +#include "amdgpu_test.h" +#include "amdgpu_drm.h" +#include "amdgpu_internal.h" + +#include "vce_ib.h" +#include "frame.h" + +#define IB_SIZE 4096 +#define MAX_RESOURCES 16 +#define FW_53_0_03 ((53 << 24) | (0 << 16) | (03 << 8)) + +struct amdgpu_vce_bo { + amdgpu_bo_handle handle; + amdgpu_va_handle va_handle; + uint64_t addr; + uint64_t size; + uint8_t *ptr; +}; + +struct amdgpu_vce_encode { + unsigned width; + unsigned height; + struct amdgpu_vce_bo vbuf; + struct amdgpu_vce_bo bs; + struct amdgpu_vce_bo fb; + struct amdgpu_vce_bo mvrefbuf; + struct amdgpu_vce_bo mvb; + struct amdgpu_vce_bo cpb; + unsigned mvbuf_size; + unsigned ib_len; +}; + +static amdgpu_device_handle device_handle; +static uint32_t major_version; +static uint32_t minor_version; +static uint32_t family_id; +static uint32_t chip_rev; +static uint32_t chip_id; +static uint32_t ids_flags; + +static amdgpu_context_handle context_handle; +static amdgpu_bo_handle ib_handle; +static amdgpu_va_handle ib_va_handle; +static uint64_t ib_mc_address; +static uint32_t *ib_cpu; + +static struct amdgpu_vce_encode enc; +static amdgpu_bo_handle resources[MAX_RESOURCES ];tests/amdgpu/vce_mv_tests.c
Quoted 10 lines
tests/amdgpu/vce_mv_tests.c new file +10
-0+static unsigned num_resources; + +static void amdgpu_cs_vce_create (void ); +static void amdgpu_cs_vce_encode_mv (void ); +static void amdgpu_cs_vce_destroy (void ); + +CU_TestInfo vce_mv_tests[] = { + { "VCE create", amdgpu_cs_vce_create }, + { "VCE mvdump", amdgpu_cs_vce_encode_mv }, + { "VCE destroy", amdgpu_cs_vce_destroy },Why does it need to have a separated file, and many duplicated stuff from
vce_tests.c?Regards,
Leo
Quoted 7 lines
Quoted 2 lines
If we put them together. add one test set: { "VCE MV",
amdgpu_cs_vce_mv_encode} in current vce test, this test must be execute no matter the asic support or not. No way to bypass. If we always return success if the asic doesn't support, it looks weird.I think you could print "Not support" and bypass it with return success, since MV test should belong to one of the VCE tests.
Regards,
Leo
Found a API to bypass the specified test dynamically. I will combine the two test suit together,
Best Regards!
James Zhu
Quoted 465 lines
Quoted 465 lines
If you don't matter this, I can combine them together.
Best Regards!
James zhuQuoted 460 lines
Quoted 460 lines
+
CU_TEST_INFO_NULL,tests/amdgpu/vce_mv_tests.c new file +16
-0+}; + +CU_BOOL suite_vce_mv_tests_enable (void ) +{ + uint32_t version, feature; + + if (amdgpu_device_initialize(drm_amdgpu[0], &major_version, + &minor_version, &device_handle)) + return CU_FALSE; + + family_id = device_handle->info.family_id; + chip_rev = device_handle->info.chip_rev; + chip_id = device_handle->info.chip_external_rev; + ids_flags = device_handle->info.ids_flags; + + amdgpu_query_firmware_version(device_handle,
AMDGPU_INFO_FW_VCE, 0,
+ 0, &version, &feature);tests/amdgpu/vce_mv_tests.c new file +5
-0+ + if (amdgpu_device_deinitialize(device_handle)) + return CU_FALSE; + + if (family_id >= AMDGPU_FAMILY_RV || family_id ==
AMDGPU_FAMILY_SI) {
+printf("\n\nThe ASIC family NOT support VCE MV, suite disabled\n");
+ returnCU_FALSE;
+ }
+
+ if (!(chip_id == (chip_rev+0x14) || /* TONGA */+ chip_id == (chip_rev + 0x3C) || /* FIJI */ + chip_id == (chip_rev + 0x50) || /* Polaris 10*/ + chip_id == (chip_rev + 0x5A) || /* Polaris 11*/ + chip_id == (chip_rev + 0x64) || /* Polaris 12*/+ (
family_id>AMDGPU_FAMILY_VI&& !ids_flags))) /* dGPUQuoted 1 line
Polaris */{
+
printf("\n\nThe ASIC NOT support VCE MV, suite disabled\n"); + returnCU_FALSE;
+ }
+
+ if (FW_53_0_03>= version){
+printf("\n\nThe ASIC FW version NOT support VCE MV, suite disabled\n");
+ returnCU_FALSE;
+ }
+ returnCU_TRUE;tests/amdgpu/vce_mv_tests.c new file +69
-0+} + +int suite_vce_mv_tests_init (void ) +{ + int r; + + r = amdgpu_device_initialize(drm_amdgpu[0], &major_version, + &minor_version, &device_handle); + if (r) { + if ((r == -EACCES) && (errno == EACCES)) + printf("\n\nError:%s. " + "Hint:Try to run this test program as root.", + strerror(errno)); + + return CUE_SINIT_FAILED; + } + + family_id = device_handle->info.family_id; + + r = amdgpu_cs_ctx_create(device_handle, &context_handle); + if (r) + return CUE_SINIT_FAILED; + + r = amdgpu_bo_alloc_and_map(device_handle, IB_SIZE, 4096, + AMDGPU_GEM_DOMAIN_GTT, 0, + &ib_handle, (void**)&ib_cpu, + &ib_mc_address, &ib_va_handle); + if (r) + return CUE_SINIT_FAILED; + + memset(&enc, 0, sizeof(struct amdgpu_vce_encode)); + + return CUE_SUCCESS; +} + +int suite_vce_mv_tests_clean (void ) +{ + int r; + + r = amdgpu_bo_unmap_and_free(ib_handle, ib_va_handle, + ib_mc_address, IB_SIZE); + if (r) + return CUE_SCLEAN_FAILED; + + r = amdgpu_cs_ctx_free(context_handle); + if (r) + return CUE_SCLEAN_FAILED; + + r = amdgpu_device_deinitialize(device_handle); + if (r) + return CUE_SCLEAN_FAILED; + + return CUE_SUCCESS; +} + +static int submit (unsigned ndw,unsigned ip) +{ + struct amdgpu_cs_request ibs_request = {0}; + struct amdgpu_cs_ib_info ib_info = {0}; + struct amdgpu_cs_fence fence_status = {0}; + uint32_t expired; + int r; + + ib_info.ib_mc_address = ib_mc_address; + ib_info.size = ndw; + + ibs_request.ip_type = ip; + + r = amdgpu_bo_list_create(device_handle, num_resources,resources,
+ NULL, &ibs_request.resources);
+ if (r)
+ return r;tests/amdgpu/vce_mv_tests.c new file +27
-0+ + ibs_request.number_of_ibs = 1; + ibs_request.ibs = &ib_info; + ibs_request.fence_info.handle = NULL; + + r = amdgpu_cs_submit(context_handle, 0, &ibs_request, 1); + if (r) + return r; + + r = amdgpu_bo_list_destroy(ibs_request.resources); + if (r) + return r; + + fence_status.context = context_handle; + fence_status.ip_type = ip; + fence_status.fence = ibs_request.seq_no; + + r = amdgpu_cs_query_fence_status(&fence_status, + AMDGPU_TIMEOUT_INFINITE, + 0, &expired); + if (r) + return r; + + return 0; +} + +static void alloc_resource(struct amdgpu_vce_bo *vce_bo, unsignedsize, unsigned domain)
tests/amdgpu/vce_mv_tests.c new file +113
-0+{ + struct amdgpu_bo_alloc_request req = {0}; + amdgpu_bo_handle buf_handle; + amdgpu_va_handle va_handle; + uint64_t va = 0; + int r; + + req.alloc_size = ALIGN(size, 4096); + req.preferred_heap = domain; + r = amdgpu_bo_alloc(device_handle, &req, &buf_handle); + CU_ASSERT_EQUAL(r, 0); + r = amdgpu_va_range_alloc(device_handle, + amdgpu_gpu_va_range_general, + req.alloc_size, 1, 0, &va, + &va_handle, 0); + CU_ASSERT_EQUAL(r, 0); + r = amdgpu_bo_va_op(buf_handle, 0, req.alloc_size, va, 0, + AMDGPU_VA_OP_MAP); + CU_ASSERT_EQUAL(r, 0); + vce_bo->addr = va; + vce_bo->handle = buf_handle; + vce_bo->size = req.alloc_size; + vce_bo->va_handle = va_handle; + r = amdgpu_bo_cpu_map(vce_bo->handle, (void **)&vce_bo->ptr); + CU_ASSERT_EQUAL(r, 0); + memset(vce_bo->ptr, 0, size); + r = amdgpu_bo_cpu_unmap(vce_bo->handle); + CU_ASSERT_EQUAL(r, 0); +} + +static void free_resource (struct amdgpu_vce_bo *vce_bo) +{ + int r; + + r = amdgpu_bo_va_op(vce_bo->handle, 0, vce_bo->size, + vce_bo->addr, 0, AMDGPU_VA_OP_UNMAP); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_va_range_free(vce_bo->va_handle); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_bo_free(vce_bo->handle); + CU_ASSERT_EQUAL(r, 0); + memset(vce_bo, 0, sizeof(*vce_bo)); +} + +static void amdgpu_cs_vce_create (void ) +{ + unsigned align = (family_id >= AMDGPU_FAMILY_AI) ? 256 : 16; + int len, r; + + vce_create[11] = 0x01000000; /* disableTwoInstance */ + vce_pic_ctrl[27] = 0x00000001; /* encSliceMode */ + + enc.width = vce_create[6]; + enc.height = vce_create[7]; + + num_resources = 0; + alloc_resource(&enc.fb, 4096, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.fb.handle; + resources[num_resources++] = ib_handle; + + len = 0; + memcpy(ib_cpu, vce_session, sizeof(vce_session)); + len += sizeof(vce_session) / 4; + memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); + len += sizeof(vce_taskinfo) / 4; + memcpy((ib_cpu + len), vce_create, sizeof(vce_create)); + ib_cpu[len + 8] = ALIGN(enc.width, align); + ib_cpu[len + 9] = ALIGN(enc.width, align); + len += sizeof(vce_create) / 4; + memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback)); + ib_cpu[len + 2] = enc.fb.addr >> 32; + ib_cpu[len + 3] = enc.fb.addr; + len += sizeof(vce_feedback) / 4; + + r = submit(len, AMDGPU_HW_IP_VCE); + CU_ASSERT_EQUAL(r, 0); + + free_resource(&enc.fb); +} + +static void amdgpu_cs_vce_config (void ) +{ + int len = 0, r; + + memcpy((ib_cpu + len), vce_session, sizeof(vce_session)); + len += sizeof(vce_session) / 4; + memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); + ib_cpu[len + 3] = 2; + ib_cpu[len + 6] = 0xffffffff; + len += sizeof(vce_taskinfo) / 4; + memcpy((ib_cpu + len), vce_rate_ctrl, sizeof(vce_rate_ctrl)); + len += sizeof(vce_rate_ctrl) / 4; + memcpy((ib_cpu + len), vce_config_ext, sizeof(vce_config_ext)); + len += sizeof(vce_config_ext) / 4; + memcpy((ib_cpu + len), vce_motion_est, sizeof(vce_motion_est)); + len += sizeof(vce_motion_est) / 4; + memcpy((ib_cpu + len), vce_rdo, sizeof(vce_rdo)); + len += sizeof(vce_rdo) / 4; + memcpy((ib_cpu + len), vce_pic_ctrl, sizeof(vce_pic_ctrl)); + len += sizeof(vce_pic_ctrl) / 4; + + r = submit(len, AMDGPU_HW_IP_VCE); + CU_ASSERT_EQUAL(r, 0); +} + +static void amdgpu_cs_vce_mv(struct amdgpu_vce_encode *enc) +{ + uint64_t luma_offset, chroma_offset; + uint64_t mv_ref_luma_offset; + unsigned align = (family_id >= AMDGPU_FAMILY_AI) ? 256 : 16; + unsigned luma_size = ALIGN(enc->width, align) *
ALIGN(enc->height, 16);
+ int len = 0, i, r;tests/amdgpu/vce_mv_tests.c new file +14
-0+ + luma_offset = enc->vbuf.addr; + chroma_offset = luma_offset + luma_size; + mv_ref_luma_offset = enc->mvrefbuf.addr; + + memcpy((ib_cpu + len), vce_session, sizeof(vce_session)); + len += sizeof(vce_session) / 4; + memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); + len += sizeof(vce_taskinfo) / 4; + memcpy((ib_cpu + len), vce_bs_buffer, sizeof(vce_bs_buffer)); + ib_cpu[len + 2] = enc->bs.addr >> 32; + ib_cpu[len + 3] = enc->bs.addr; + len += sizeof(vce_bs_buffer) / 4; + memcpy((ib_cpu + len), vce_context_buffer,
sizeof(vce_context_buffer));
+ ib_cpu[len + 2] =enc->cpb.addr>> 32;
+ ib_cpu[len + 3] =enc->cpb.addr;
+ len +=sizeof(vce_context_buffer)/ 4;
+memcpy((ib_cpu + len), vce_aux_buffer, sizeof(vce_aux_buffer));
+ for (i = 0; i < 8; ++i)
+ ib_cpu[len + 2 + i] =luma_size* 1.5 * (i + 2);
+ for (i = 0; i < 8; ++i)
+ ib_cpu[len + 10 + i] =luma_size* 1.5;
+ len +=sizeof(vce_aux_buffer)/ 4;
+memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback));
+ ib_cpu[len + 2] =enc->fb.addr>> 32;
+ ib_cpu[len + 3] =enc->fb.addr;
+ len +=sizeof(vce_feedback)/ 4;
+memcpy((ib_cpu + len), vce_mv_buffer, sizeof(vce_mv_buffer));
+ ib_cpu[len + 2] =mv_ref_luma_offset>> 32;
+ ib_cpu[len + 3] =mv_ref_luma_offset;
+ ib_cpu[len + 4] =ALIGN(enc->width, align);
+ ib_cpu[len + 5] =ALIGN(enc->width, align);
+ ib_cpu[len + 6] =luma_size;
+ ib_cpu[len + 7] =enc->mvb.addr>> 32;
+ ib_cpu[len + 8] =enc->mvb.addr;
+ len +=sizeof(vce_mv_buffer)/ 4;
+memcpy((ib_cpu + len), vce_encode, sizeof(vce_encode));
+ ib_cpu[len + 2] = 0;
+ ib_cpu[len + 3] = 0;
+ ib_cpu[len + 4] =0x154000;
+ ib_cpu[len + 9] =luma_offset>> 32;
+ ib_cpu[len + 10] =luma_offset;
+ ib_cpu[len + 11] =chroma_offset>> 32;
+ ib_cpu[len + 12] =chroma_offset;
+ ib_cpu[len + 13] =ALIGN(enc->height, 16);;
+ ib_cpu[len + 14] =ALIGN(enc->width, align);
+ ib_cpu[len + 15] =ALIGN(enc->width, align);
+ /* encDisableMBOffloading-encDisableTwoPipeMode-encInputPicArrayMode-encInputPicAddrMode */ + ib_cpu[len + 16] =0x01010000;
+ ib_cpu[len + 18] = 0; /* encPicType */
+ ib_cpu[len + 19] = 0; /* encIdrFlag */
+ ib_cpu[len + 20] = 0; /* encIdrPicId */
+ ib_cpu[len + 21] = 0; /* encMGSKeyPic */
+ ib_cpu[len + 22] = 0; /* encReferenceFlag */
+ ib_cpu[len + 23] = 0; /* encTemporalLayerIndex */
+ ib_cpu[len + 55] = 0; /* pictureStructure */
+ ib_cpu[len + 56] = 0; /* encPicType -ref[0] */
+ ib_cpu[len + 61] = 0; /* pictureStructure */
+ ib_cpu[len + 62] = 0; /* encPicType -ref[1] */
+ ib_cpu[len + 67] = 0; /* pictureStructure */
+ ib_cpu[len + 68] = 0; /* encPicType -ref1 */
+ ib_cpu[len + 81] = 1; /* frameNumber */
+ ib_cpu[len + 82] = 2; /* pictureOrderCount */
+ ib_cpu[len + 83] =0xffffffff; /* numIPicRemainInRCGOP */
+ ib_cpu[len + 84] =0xffffffff; /* numPPicRemainInRCGOP */
+ ib_cpu[len + 85] =0xffffffff; /* numBPicRemainInRCGOP */
+ ib_cpu[len + 86] =0xffffffff; /* numIRPicRemainInRCGOP */
+ ib_cpu[len + 87] = 0; /* remainedIntraRefreshPictures */
+ len +=sizeof(vce_encode)/ 4;tests/amdgpu/vce_mv_tests.c new file +34
-0+ + enc->ib_len = len; + r = submit(len, AMDGPU_HW_IP_VCE); + CU_ASSERT_EQUAL(r, 0); +} + +static void check_mv_result (struct amdgpu_vce_encode *enc) +{ + uint64_t sum; + uint32_t s = 140790; + uint32_t *ptr, size; + int i, j, r; + + r = amdgpu_bo_cpu_map(enc->fb.handle, (void **)&enc->fb.ptr); + CU_ASSERT_EQUAL(r, 0); + ptr = (uint32_t *)enc->fb.ptr; + r = amdgpu_bo_cpu_unmap(enc->fb.handle); + CU_ASSERT_EQUAL(r, 0); + r = amdgpu_bo_cpu_map(enc->mvb.handle, (void **)&enc->mvb.ptr); + CU_ASSERT_EQUAL(r, 0); + for (j = 0, sum = 0; j < enc->mvbuf_size; ++j) + sum += enc->mvb.ptr[j]; + CU_ASSERT_EQUAL(sum, s); + r = amdgpu_bo_cpu_unmap(enc->mvb.handle); + CU_ASSERT_EQUAL(r, 0); +} + +static void amdgpu_cs_vce_encode_mv (void ) +{ + uint32_t vbuf_size, bs_size = 0x154000, cpb_size; + unsigned align = (family_id >= AMDGPU_FAMILY_AI) ? 256 : 16; + int i, r; + + vbuf_size = ALIGN(enc.width, align) * ALIGN(enc.height, 16) *1.5;
+ enc.mvbuf_size =ALIGN(enc.width, 16)*ALIGN(enc.height, 16)/ 8;
+cpb_size=vbuf_size* 10;
+num_resources= 0;
+alloc_resource(&enc.fb, 4096, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.fb.handle;
+alloc_resource(&enc.bs, bs_size, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.bs.handle;
+alloc_resource(&enc.mvb, enc.mvbuf_size, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.mvb.handle;
+alloc_resource(&enc.vbuf, vbuf_size, AMDGPU_GEM_DOMAIN_VRAM); + resources[num_resources++] = enc.vbuf.handle;
+alloc_resource(&enc.mvrefbuf, vbuf_size, AMDGPU_GEM_DOMAIN_VRAM); + resources[num_resources++] = enc.mvrefbuf.handle;
+alloc_resource(&enc.cpb, cpb_size, AMDGPU_GEM_DOMAIN_VRAM); + resources[num_resources++] = enc.cpb.handle;
+ resources[num_resources++] =ib_handle;tests/amdgpu/vce_mv_tests.c new file +11
-0+ + r = amdgpu_bo_cpu_map(enc.vbuf.handle, (void **)&enc.vbuf.ptr); + CU_ASSERT_EQUAL(r, 0); + + memset(enc.vbuf.ptr, 0, vbuf_size); + for (i = 0; i < enc.height; ++i) { + memcpy(enc.vbuf.ptr, (frame + i * enc.width), enc.width); + enc.vbuf.ptr += ALIGN(enc.width, align); + } + for (i = 0; i < enc.height / 2; ++i) { + memcpy(enc.vbuf.ptr, ((frame + enc.height * enc.width) + i* enc.width), enc.width);
+ enc.vbuf.ptr +=ALIGN(enc.width, align);
+ }tests/amdgpu/vce_mv_tests.c new file +5
-0+ + r = amdgpu_bo_cpu_unmap(enc.vbuf.handle); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_bo_cpu_map(enc.mvrefbuf.handle, (void**)&enc.mvrefbuf.ptr);
+CU_ASSERT_EQUAL(r, 0);
+
+memset(enc.mvrefbuf.ptr, 0, vbuf_size);
+ for (i = 0; i < enc.height; ++i) {
+memcpy(enc.mvrefbuf.ptr, (frame + (enc.height - i -1) * enc.width), enc.width);
+ enc.mvrefbuf.ptr +=ALIGN(enc.width, align); + }
+ for (i = 0; i < enc.height / 2; ++i) {
+ memcpy(enc.mvrefbuf.ptr,
+ ((frame + enc.height * enc.width) + (enc.height / 2 - i -1) * enc.width), enc.width);
+ enc.mvrefbuf.ptr +=ALIGN(enc.width, align); + }tests/amdgpu/vce_mv_tests.c new file +39
-0+ + r = amdgpu_bo_cpu_unmap(enc.mvrefbuf.handle); + CU_ASSERT_EQUAL(r, 0); + + amdgpu_cs_vce_config(); + + vce_taskinfo[3] = 3; + amdgpu_cs_vce_mv(&enc); + check_mv_result(&enc); + + free_resource(&enc.fb); + free_resource(&enc.bs); + free_resource(&enc.vbuf); + free_resource(&enc.cpb); + free_resource(&enc.mvrefbuf); + free_resource(&enc.mvb); +} + +static void amdgpu_cs_vce_destroy (void ) +{ + int len, r; + + num_resources = 0; + alloc_resource(&enc.fb, 4096, AMDGPU_GEM_DOMAIN_GTT); + resources[num_resources++] = enc.fb.handle; + resources[num_resources++] = ib_handle; + + len = 0; + memcpy(ib_cpu, vce_session, sizeof(vce_session)); + len += sizeof(vce_session) / 4; + memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); + ib_cpu[len + 3] = 1; + len += sizeof(vce_taskinfo) / 4; + memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback)); + ib_cpu[len + 2] = enc.fb.addr >> 32; + ib_cpu[len + 3] = enc.fb.addr; + len += sizeof(vce_feedback) / 4; + memcpy((ib_cpu + len), vce_destroy, sizeof(vce_destroy)); + len += sizeof(vce_destroy) / 4;
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
tests/amdgpu/vce_mv_tests.c
Quoted 6 lines
tests/amdgpu/vce_mv_tests.c new file +6
-0+ + r = submit(len, AMDGPU_HW_IP_VCE); + CU_ASSERT_EQUAL(r, 0); + + free_resource(&enc.fb); +}
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 1/1 tests/amdgpu: add vce mv tests support and sets
In reply to a message not in the archive--- tests/amdgpu/vce_ib.h | 21 ++++- tests/amdgpu/vce_tests.c | 224 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 240 insertions(+), 5 deletions(-)
tests/amdgpu/vce_ib.h +19 -2
@@ -41,7 +41,7 @@ static uint32_t vce_taskinfo[8] = { 0x00000000, }; -static const uint32_t vce_create[] = { +static uint32_t vce_create[] = {0x00000030 ,0x01000001 ,0x00000000 ,
@@ -144,7 +144,7 @@ static const uint32_t vce_rdo[] = { 0x00000000, }; -static const uint32_t vce_pic_ctrl[] = { +static uint32_t vce_pic_ctrl[] = {0x00000074 ,0x04000002 ,0x00000000 ,
@@ -315,4 +315,21 @@ static const uint32_t vce_destroy[] = {0x00000008 , 0x02000001, }; + +static const uint32_t vce_mv_buffer[] = { +0x00000038 , +0x0500000d , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +};#endif /*_vce_ib_h*/
tests/amdgpu/vce_tests.c +221 -3
285 lines not on this page · raw message
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1522860234-21784-1-git-send-email-James.Zhu-5C7GfCeVMHo@public.gmane.org
Re: [PATCH v2] tests/amdgpu: add vce mv tests support and sets
Quoted 29 lines · James Zhu
Signed-off-by James Zhu<[email protected]>--- tests/amdgpu/vce_ib.h | 21 ++++- tests/amdgpu/vce_tests.c | 224 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 240 insertions(+), 5 deletions(-)tests/amdgpu/vce_ib.h +2
-2@@ -41,7 +41,7 @@ static uint32_t vce_taskinfo[8] = { 0x00000000, }; -static const uint32_t vce_create[] = { +static uint32_t vce_create[] = {0x00000030 ,0x01000001 ,0x00000000 ,@@ -144,7 +144,7 @@ static const uint32_t vce_rdo[] = { 0x00000000, }; -static const uint32_t vce_pic_ctrl[] = { +static uint32_t vce_pic_ctrl[] = {0x00000074 ,0x04000002 ,0x00000000 ,
tests/amdgpu/vce_ib.h static const uint32_t vce_destroy[] = { · line 318
Quoted 4 lines
tests/amdgpu/vce_ib.h +1
-0@@ -315,4 +315,21 @@ static const uint32_t vce_destroy[] = {0x00000008 , 0x02000001, }; +
Parameters array in header should keep read-only. You should modify IB on the fly with the conditions.
Quoted 55 lines
tests/amdgpu/vce_ib.h +16
-0+static const uint32_t vce_mv_buffer[] = { +0x00000038 , +0x0500000d , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +};#endif /*_vce_ib_h*/ tests/amdgpu/vce_tests.c +9
-0@@ -37,6 +37,7 @@#define IB_SIZE 4096#define MAX_RESOURCES 16 +#define FW_53_0_03 ((53 << 24) | (0 << 16) | (03 << 8))struct amdgpu_vce_bo {amdgpu_bo_handle handle;@@ -55,6 +56,9 @@ struct amdgpu_vce_encode {struct amdgpu_vce_bo cpb;unsigned ib_len;bool two_instance; +struct amdgpu_vce_bo mvrefbuf; +struct amdgpu_vce_bo mvb; +unsigned mvbuf_size; };static amdgpu_device_handle device_handle;@@ -62,6 +66,9 @@ static uint32_t major_version;static uint32_t minor_version;static uint32_t family_id;static uint32_t vce_harvest_config; +static uint32_t chip_rev; +static uint32_t chip_id; +static uint32_t ids_flags;static amdgpu_context_handle context_handle;static amdgpu_bo_handle ib_handle;@@ -75,33 +82,62 @@ static unsigned num_resources;static void amdgpu_cs_vce_create (void );static void amdgpu_cs_vce_encode (void ); +static void amdgpu_cs_vce_preset_mv (void ); +static void amdgpu_cs_vce_encode_mv (void );
tests/amdgpu/vce_tests.c static unsigned num_resources; · line 96
Quoted 10 lines
tests/amdgpu/vce_tests.c +4
-0static void amdgpu_cs_vce_destroy (void );CU_TestInfo vce_tests[] = { {"VCE create" , amdgpu_cs_vce_create }, {"VCE encode" , amdgpu_cs_vce_encode }, {"VCE destroy" , amdgpu_cs_vce_destroy }, + {"VCE MV preset" , amdgpu_cs_vce_preset_mv }, + {"VCE MV create" , amdgpu_cs_vce_create }, + {"VCE MV dump" , amdgpu_cs_vce_encode_mv }, + {"VCE MV destroy" , amdgpu_cs_vce_destroy },
Why to add create/destroy again? my understanding is that all the operations should be executable with one pair of create/destroy.
Quoted 59 lines
tests/amdgpu/vce_tests.c +26
-3CU_TEST_INFO_NULL, }; -CU_BOOL suite_vce_tests_enable (void ) { +uint32_t version, feature; +CU_BOOL ret_mv =CU_FALSE ; +if (amdgpu_device_initialize (drm_amdgpu[0 ], &major_version, &minor_version, &device_handle))return CU_FALSE ; family_id = device_handle->info.family_id; + chip_rev = device_handle->info.chip_rev; + chip_id = device_handle->info.chip_external_rev; + ids_flags = device_handle->info.ids_flags; + +amdgpu_query_firmware_version (device_handle,AMDGPU_INFO_FW_VCE ,0 , +0 , &version, &feature);if (amdgpu_device_deinitialize (device_handle))return CU_FALSE ; -if (family_id >=AMDGPU_FAMILY_RV || family_id ==AMDGPU_FAMILY_SI ) {printf ("\n\nThe ASIC NOT support VCE, suite disabled\n" );return CU_FALSE ; } +if (!(chip_id == (chip_rev +0x3C ) ||/* FIJI */ + chip_id == (chip_rev +0x50 ) ||/* Polaris 10*/ + chip_id == (chip_rev +0x5A ) ||/* Polaris 11*/ + chip_id == (chip_rev +0x64 ) ||/* Polaris 12*/ + (family_id >AMDGPU_FAMILY_VI && !ids_flags)))/* dGPU > Polaris */ +printf ("\n\nThe ASIC NOT support VCE MV, suite disabled\n" ); +else if (FW_53_0_03 >= version) +printf ("\n\nThe ASIC FW version NOT support VCE MV, suite disabled\n" ); +else + ret_mv =CU_TRUE ; + +amdgpu_set_test_active ("VCE Tests" ,"VCE MV preset" , ret_mv); +amdgpu_set_test_active ("VCE Tests" ,"VCE MV create" , ret_mv); +amdgpu_set_test_active ("VCE Tests" ,"VCE MV dump" , ret_mv); +amdgpu_set_test_active ("VCE Tests" ,"VCE MV destroy" , ret_mv); +return CU_TRUE ; }@@ -307,7 +343,7 @@ static void amdgpu_cs_vce_config(void)CU_ASSERT_EQUAL (r,0 ); } -static void amdgpu_cs_vce_encode_idr (struct amdgpu_vce_encode *enc) +static void amdgpu_cs_vce_encode_idr (struct amdgpu_vce_encode *enc) {uint64_t luma_offset, chroma_offset;
tests/amdgpu/vce_tests.c static void amdgpu_cs_vce_encode(void) · line 562
Quoted 6 lines
tests/amdgpu/vce_tests.c +3
-0@@ -521,6 +557,188 @@ static void amdgpu_cs_vce_encode(void)free_resource (&enc.cpb); } +static void amdgpu_cs_vce_preset_mv (void ) +{ + vce_create[11 ] =0x01000000 ;/* disableTwoInstance */
As I know with VCE only one instance, it will ignore this. If you think it matters, you could make this value default, and re-set it with 2 instances case, since we only have limited HW with 2 instances available.
Regards,
Leo
Quoted 172 lines
tests/amdgpu/vce_tests.c +172
-0+ vce_pic_ctrl[27 ] =0x00000001 ;/* encSliceMode */ + vce_taskinfo[3 ] =0 ; + vce_taskinfo[4 ] =0 ; +} + +static void amdgpu_cs_vce_mv (struct amdgpu_vce_encode *enc) +{ +uint64_t luma_offset, chroma_offset; +uint64_t mv_ref_luma_offset; +unsigned align = (family_id >=AMDGPU_FAMILY_AI ) ?256 :16 ; +unsigned luma_size =ALIGN (enc->width, align) *ALIGN (enc->height,16 ); +int len =0 , i, r; + + luma_offset = enc->vbuf.addr; + chroma_offset = luma_offset + luma_size; + mv_ref_luma_offset = enc->mvrefbuf.addr; + +memcpy ((ib_cpu + len), vce_session,sizeof (vce_session)); + len +=sizeof (vce_session) /4 ; +memcpy ((ib_cpu + len), vce_taskinfo,sizeof (vce_taskinfo)); + len +=sizeof (vce_taskinfo) /4 ; +memcpy ((ib_cpu + len), vce_bs_buffer,sizeof (vce_bs_buffer)); + ib_cpu[len +2 ] = enc->bs[0 ].addr >>32 ; + ib_cpu[len +3 ] = enc->bs[0 ].addr; + len +=sizeof (vce_bs_buffer) /4 ; +memcpy ((ib_cpu + len), vce_context_buffer,sizeof (vce_context_buffer)); + ib_cpu[len +2 ] = enc->cpb.addr >>32 ; + ib_cpu[len +3 ] = enc->cpb.addr; + len +=sizeof (vce_context_buffer) /4 ; +memcpy ((ib_cpu + len), vce_aux_buffer,sizeof (vce_aux_buffer)); +for (i =0 ; i <8 ; ++i) + ib_cpu[len +2 + i] = luma_size *1.5 * (i +2 ); +for (i =0 ; i <8 ; ++i) + ib_cpu[len +10 + i] = luma_size *1.5 ; + len +=sizeof (vce_aux_buffer) /4 ; +memcpy ((ib_cpu + len), vce_feedback,sizeof (vce_feedback)); + ib_cpu[len +2 ] = enc->fb[0 ].addr >>32 ; + ib_cpu[len +3 ] = enc->fb[0 ].addr; + len +=sizeof (vce_feedback) /4 ; +memcpy ((ib_cpu + len), vce_mv_buffer,sizeof (vce_mv_buffer)); + ib_cpu[len +2 ] = mv_ref_luma_offset >>32 ; + ib_cpu[len +3 ] = mv_ref_luma_offset; + ib_cpu[len +4 ] =ALIGN (enc->width, align); + ib_cpu[len +5 ] =ALIGN (enc->width, align); + ib_cpu[len +6 ] = luma_size; + ib_cpu[len +7 ] = enc->mvb.addr >>32 ; + ib_cpu[len +8 ] = enc->mvb.addr; + len +=sizeof (vce_mv_buffer) /4 ; +memcpy ((ib_cpu + len), vce_encode,sizeof (vce_encode)); + ib_cpu[len +2 ] =0 ; + ib_cpu[len +3 ] =0 ; + ib_cpu[len +4 ] =0x154000 ; + ib_cpu[len +9 ] = luma_offset >>32 ; + ib_cpu[len +10 ] = luma_offset; + ib_cpu[len +11 ] = chroma_offset >>32 ; + ib_cpu[len +12 ] = chroma_offset; + ib_cpu[len +13 ] =ALIGN (enc->height,16 );; + ib_cpu[len +14 ] =ALIGN (enc->width, align); + ib_cpu[len +15 ] =ALIGN (enc->width, align); +/* encDisableMBOffloading-encDisableTwoPipeMode-encInputPicArrayMode-encInputPicAddrMode */ + ib_cpu[len +16 ] =0x01010000 ; + ib_cpu[len +18 ] =0 ;/* encPicType */ + ib_cpu[len +19 ] =0 ;/* encIdrFlag */ + ib_cpu[len +20 ] =0 ;/* encIdrPicId */ + ib_cpu[len +21 ] =0 ;/* encMGSKeyPic */ + ib_cpu[len +22 ] =0 ;/* encReferenceFlag */ + ib_cpu[len +23 ] =0 ;/* encTemporalLayerIndex */ + ib_cpu[len +55 ] =0 ;/* pictureStructure */ + ib_cpu[len +56 ] =0 ;/* encPicType -ref[0] */ + ib_cpu[len +61 ] =0 ;/* pictureStructure */ + ib_cpu[len +62 ] =0 ;/* encPicType -ref[1] */ + ib_cpu[len +67 ] =0 ;/* pictureStructure */ + ib_cpu[len +68 ] =0 ;/* encPicType -ref1 */ + ib_cpu[len +81 ] =1 ;/* frameNumber */ + ib_cpu[len +82 ] =2 ;/* pictureOrderCount */ + ib_cpu[len +83 ] =0xffffffff ;/* numIPicRemainInRCGOP */ + ib_cpu[len +84 ] =0xffffffff ;/* numPPicRemainInRCGOP */ + ib_cpu[len +85 ] =0xffffffff ;/* numBPicRemainInRCGOP */ + ib_cpu[len +86 ] =0xffffffff ;/* numIRPicRemainInRCGOP */ + ib_cpu[len +87 ] =0 ;/* remainedIntraRefreshPictures */ + len +=sizeof (vce_encode) /4 ; + + enc->ib_len = len; + r =submit (len,AMDGPU_HW_IP_VCE ); +CU_ASSERT_EQUAL (r,0 ); +} + +static void check_mv_result (struct amdgpu_vce_encode *enc) +{ +uint64_t sum; +uint32_t s =140790 ; +uint32_t *ptr, size; +int i, j, r; + + r =amdgpu_bo_cpu_map (enc->fb[0 ].handle, (void **)&enc->fb[0 ].ptr); +CU_ASSERT_EQUAL (r,0 ); + ptr = (uint32_t *)enc->fb[0 ].ptr; + r =amdgpu_bo_cpu_unmap (enc->fb[0 ].handle); +CU_ASSERT_EQUAL (r,0 ); + r =amdgpu_bo_cpu_map (enc->mvb.handle, (void **)&enc->mvb.ptr); +CU_ASSERT_EQUAL (r,0 ); +for (j =0 , sum =0 ; j < enc->mvbuf_size; ++j) + sum += enc->mvb.ptr[j]; +CU_ASSERT_EQUAL (sum, s); + r =amdgpu_bo_cpu_unmap (enc->mvb.handle); +CU_ASSERT_EQUAL (r,0 ); +} + +static void amdgpu_cs_vce_encode_mv (void ) +{ +uint32_t vbuf_size, bs_size =0x154000 , cpb_size; +unsigned align = (family_id >=AMDGPU_FAMILY_AI ) ?256 :16 ; +int i, r; + + vbuf_size =ALIGN (enc.width, align) *ALIGN (enc.height,16 ) *1.5 ; + enc.mvbuf_size =ALIGN (enc.width,16 ) *ALIGN (enc.height,16 ) /8 ; + cpb_size = vbuf_size *10 ; + num_resources =0 ; +alloc_resource (&enc.fb[0 ],4096 ,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.fb[0 ].handle; +alloc_resource (&enc.bs[0 ], bs_size,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.bs[0 ].handle; +alloc_resource (&enc.mvb, enc.mvbuf_size,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.mvb.handle; +alloc_resource (&enc.vbuf, vbuf_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.vbuf.handle; +alloc_resource (&enc.mvrefbuf, vbuf_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.mvrefbuf.handle; +alloc_resource (&enc.cpb, cpb_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.cpb.handle; + resources[num_resources++] = ib_handle; + + r =amdgpu_bo_cpu_map (enc.vbuf.handle, (void **)&enc.vbuf.ptr); +CU_ASSERT_EQUAL (r,0 ); + +memset (enc.vbuf.ptr,0 , vbuf_size); +for (i =0 ; i < enc.height; ++i) { +memcpy (enc.vbuf.ptr, (frame + i * enc.width), enc.width); + enc.vbuf.ptr +=ALIGN (enc.width, align); + } +for (i =0 ; i < enc.height /2 ; ++i) { +memcpy (enc.vbuf.ptr, ((frame + enc.height * enc.width) + i * enc.width), enc.width); + enc.vbuf.ptr +=ALIGN (enc.width, align); + } + + r =amdgpu_bo_cpu_unmap (enc.vbuf.handle); +CU_ASSERT_EQUAL (r,0 ); + + r =amdgpu_bo_cpu_map (enc.mvrefbuf.handle, (void **)&enc.mvrefbuf.ptr); +CU_ASSERT_EQUAL (r,0 ); + +memset (enc.mvrefbuf.ptr,0 , vbuf_size); +for (i =0 ; i < enc.height; ++i) { +memcpy (enc.mvrefbuf.ptr, (frame + (enc.height - i -1 ) * enc.width), enc.width); + enc.mvrefbuf.ptr +=ALIGN (enc.width, align); + } +for (i =0 ; i < enc.height /2 ; ++i) { +memcpy (enc.mvrefbuf.ptr, + ((frame + enc.height * enc.width) + (enc.height /2 - i -1 ) * enc.width), enc.width); + enc.mvrefbuf.ptr +=ALIGN (enc.width, align); + } + + r =amdgpu_bo_cpu_unmap (enc.mvrefbuf.handle); +CU_ASSERT_EQUAL (r,0 ); + +amdgpu_cs_vce_config (); + + vce_taskinfo[3 ] =3 ; +amdgpu_cs_vce_mv (&enc); +check_mv_result (&enc); + +free_resource (&enc.fb[0 ]);
tests/amdgpu/vce_tests.c static void amdgpu_cs_vce_encode(void) · line 744
Quoted 10 lines
tests/amdgpu/vce_tests.c +7
-0+free_resource (&enc.bs[0 ]); +free_resource (&enc.vbuf); +free_resource (&enc.cpb); +free_resource (&enc.mvrefbuf); +free_resource (&enc.mvb); +} +static void amdgpu_cs_vce_destroy (void ) {int len, r;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): bf5ba149-a6ec-b13a-6bcd-13a9e97cb2b7-5C7GfCeVMHo@public.gmane.org
Re: [PATCH v2] tests/amdgpu: add vce mv tests support and sets
Quoted 27 lines · Leo Liu
Quoted 23 lines · James Zhu
Signed-off-by James Zhu<[email protected]>--- tests/amdgpu/vce_ib.h | 21 ++++- tests/amdgpu/vce_tests.c | 224 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 240 insertions(+), 5 deletions(-)tests/amdgpu/vce_ib.h +1
-1@@ -41,7 +41,7 @@ static uint32_t vce_taskinfo[8] = { 0x00000000, }; -static const uint32_t vce_create[] = { +static uint32_t vce_create[] = {0x00000030 ,0x01000001 ,0x00000000 ,@@ -144,7 +144,7 @@ static const uint32_t vce_rdo[] = { 0x00000000, };
Quoted 12 lines
tests/amdgpu/vce_ib.h static const uint32_t vce_destroy[] = { · line 318
Quoted 10 lines
tests/amdgpu/vce_ib.h +2
-1-static const uint32_t vce_pic_ctrl[] = { +static uint32_t vce_pic_ctrl[] = {0x00000074 ,0x04000002 ,0x00000000 ,@@ -315,4 +315,21 @@ static const uint32_t vce_destroy[] = {0x00000008 , 0x02000001, }; +Parameters array in header should keep read-only. You should modify IB on the fly with the conditions.
James: can make it with adding a flag.
Quoted 57 lines
Quoted 57 lines
tests/amdgpu/vce_ib.h +16
-0+static const uint32_t vce_mv_buffer[] = { +0x00000038 , +0x0500000d , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +};#endif /*_vce_ib_h*/ tests/amdgpu/vce_tests.c +9
-0@@ -37,6 +37,7 @@#define IB_SIZE 4096#define MAX_RESOURCES 16 +#define FW_53_0_03 ((53 << 24) | (0 << 16) | (03 << 8))struct amdgpu_vce_bo {amdgpu_bo_handle handle;@@ -55,6 +56,9 @@ struct amdgpu_vce_encode {struct amdgpu_vce_bo cpb;unsigned ib_len;bool two_instance; +struct amdgpu_vce_bo mvrefbuf; +struct amdgpu_vce_bo mvb; +unsigned mvbuf_size; };static amdgpu_device_handle device_handle;@@ -62,6 +66,9 @@ static uint32_t major_version;static uint32_t minor_version;static uint32_t family_id;static uint32_t vce_harvest_config; +static uint32_t chip_rev; +static uint32_t chip_id; +static uint32_t ids_flags;static amdgpu_context_handle context_handle;static amdgpu_bo_handle ib_handle;@@ -75,33 +82,62 @@ static unsigned num_resources;static void amdgpu_cs_vce_create (void );static void amdgpu_cs_vce_encode (void ); +static void amdgpu_cs_vce_preset_mv (void ); +static void amdgpu_cs_vce_encode_mv (void );static void amdgpu_cs_vce_destroy (void );
Quoted 10 lines
tests/amdgpu/vce_tests.c static unsigned num_resources; · line 96
Quoted 8 lines
tests/amdgpu/vce_tests.c +4
-0CU_TestInfo vce_tests[] = { {"VCE create" , amdgpu_cs_vce_create }, {"VCE encode" , amdgpu_cs_vce_encode }, {"VCE destroy" , amdgpu_cs_vce_destroy }, + {"VCE MV preset" , amdgpu_cs_vce_preset_mv }, + {"VCE MV create" , amdgpu_cs_vce_create }, + {"VCE MV dump" , amdgpu_cs_vce_encode_mv }, + {"VCE MV destroy" , amdgpu_cs_vce_destroy },Why to add create/destroy again? my understanding is that all the operations should be executable with one pair of create/destroy.
James: They are two different tests, one is encode, and the other is MV dump. create has different setting for normal test and MV dump test.
Quoted 62 lines
Quoted 62 lines
tests/amdgpu/vce_tests.c +26
-3CU_TEST_INFO_NULL, }; -CU_BOOL suite_vce_tests_enable (void ) { +uint32_t version, feature; +CU_BOOL ret_mv =CU_FALSE ; +if (amdgpu_device_initialize (drm_amdgpu[0 ], &major_version, &minor_version, &device_handle))return CU_FALSE ; family_id = device_handle->info.family_id; + chip_rev = device_handle->info.chip_rev; + chip_id = device_handle->info.chip_external_rev; + ids_flags = device_handle->info.ids_flags; + +amdgpu_query_firmware_version (device_handle,AMDGPU_INFO_FW_VCE ,0 , +0 , &version, &feature);if (amdgpu_device_deinitialize (device_handle))return CU_FALSE ; -if (family_id >=AMDGPU_FAMILY_RV || family_id ==AMDGPU_FAMILY_SI ) {printf ("\n\nThe ASIC NOT support VCE, suite disabled\n" );return CU_FALSE ; } +if (!(chip_id == (chip_rev +0x3C ) ||/* FIJI */ + chip_id == (chip_rev +0x50 ) ||/* Polaris 10*/ + chip_id == (chip_rev +0x5A ) ||/* Polaris 11*/ + chip_id == (chip_rev +0x64 ) ||/* Polaris 12*/ + (family_id >AMDGPU_FAMILY_VI && !ids_flags)))/* dGPU > Polaris */ +printf ("\n\nThe ASIC NOT support VCE MV, suite disabled\n" ); +else if (FW_53_0_03 >= version) +printf ("\n\nThe ASIC FW version NOT support VCE MV, suite disabled\n" ); +else + ret_mv =CU_TRUE ; + +amdgpu_set_test_active ("VCE Tests" ,"VCE MV preset" , ret_mv); +amdgpu_set_test_active ("VCE Tests" ,"VCE MV create" , ret_mv); +amdgpu_set_test_active ("VCE Tests" ,"VCE MV dump" , ret_mv); +amdgpu_set_test_active ("VCE Tests" ,"VCE MV destroy" , ret_mv); +return CU_TRUE ; }@@ -307,7 +343,7 @@ static void amdgpu_cs_vce_config(void)CU_ASSERT_EQUAL (r,0 ); } -static void amdgpu_cs_vce_encode_idr (struct amdgpu_vce_encode *enc) +static void amdgpu_cs_vce_encode_idr (struct amdgpu_vce_encode *enc) {uint64_t luma_offset, chroma_offset;@@ -521,6 +557,188 @@ static void amdgpu_cs_vce_encode(void)free_resource (&enc.cpb); }
Quoted 8 lines
tests/amdgpu/vce_tests.c static void amdgpu_cs_vce_encode(void) · line 562
Quoted 3 lines
tests/amdgpu/vce_tests.c +3
-0+static void amdgpu_cs_vce_preset_mv (void ) +{ + vce_create[11 ] =0x01000000 ;/* disableTwoInstance */ As I know with VCE only one instance, it will ignore this. If you think it matters, you could make this value default, and re-set it with 2 instances case, since we only have limited HW with 2 instances available.
Regards,
Leo
James: Yes, according to windows version, it needs set. Tell me which asics support 2 instances, I can add check.
Quoted 174 lines
Quoted 174 lines
tests/amdgpu/vce_tests.c +174
-0+ vce_pic_ctrl[27 ] =0x00000001 ;/* encSliceMode */ + vce_taskinfo[3 ] =0 ; + vce_taskinfo[4 ] =0 ; +} + +static void amdgpu_cs_vce_mv (struct amdgpu_vce_encode *enc) +{ +uint64_t luma_offset, chroma_offset; +uint64_t mv_ref_luma_offset; +unsigned align = (family_id >=AMDGPU_FAMILY_AI ) ?256 :16 ; +unsigned luma_size =ALIGN (enc->width, align) *ALIGN (enc->height,16 ); +int len =0 , i, r; + + luma_offset = enc->vbuf.addr; + chroma_offset = luma_offset + luma_size; + mv_ref_luma_offset = enc->mvrefbuf.addr; + +memcpy ((ib_cpu + len), vce_session,sizeof (vce_session)); + len +=sizeof (vce_session) /4 ; +memcpy ((ib_cpu + len), vce_taskinfo,sizeof (vce_taskinfo)); + len +=sizeof (vce_taskinfo) /4 ; +memcpy ((ib_cpu + len), vce_bs_buffer,sizeof (vce_bs_buffer)); + ib_cpu[len +2 ] = enc->bs[0 ].addr >>32 ; + ib_cpu[len +3 ] = enc->bs[0 ].addr; + len +=sizeof (vce_bs_buffer) /4 ; +memcpy ((ib_cpu + len), vce_context_buffer,sizeof (vce_context_buffer)); + ib_cpu[len +2 ] = enc->cpb.addr >>32 ; + ib_cpu[len +3 ] = enc->cpb.addr; + len +=sizeof (vce_context_buffer) /4 ; +memcpy ((ib_cpu + len), vce_aux_buffer,sizeof (vce_aux_buffer)); +for (i =0 ; i <8 ; ++i) + ib_cpu[len +2 + i] = luma_size *1.5 * (i +2 ); +for (i =0 ; i <8 ; ++i) + ib_cpu[len +10 + i] = luma_size *1.5 ; + len +=sizeof (vce_aux_buffer) /4 ; +memcpy ((ib_cpu + len), vce_feedback,sizeof (vce_feedback)); + ib_cpu[len +2 ] = enc->fb[0 ].addr >>32 ; + ib_cpu[len +3 ] = enc->fb[0 ].addr; + len +=sizeof (vce_feedback) /4 ; +memcpy ((ib_cpu + len), vce_mv_buffer,sizeof (vce_mv_buffer)); + ib_cpu[len +2 ] = mv_ref_luma_offset >>32 ; + ib_cpu[len +3 ] = mv_ref_luma_offset; + ib_cpu[len +4 ] =ALIGN (enc->width, align); + ib_cpu[len +5 ] =ALIGN (enc->width, align); + ib_cpu[len +6 ] = luma_size; + ib_cpu[len +7 ] = enc->mvb.addr >>32 ; + ib_cpu[len +8 ] = enc->mvb.addr; + len +=sizeof (vce_mv_buffer) /4 ; +memcpy ((ib_cpu + len), vce_encode,sizeof (vce_encode)); + ib_cpu[len +2 ] =0 ; + ib_cpu[len +3 ] =0 ; + ib_cpu[len +4 ] =0x154000 ; + ib_cpu[len +9 ] = luma_offset >>32 ; + ib_cpu[len +10 ] = luma_offset; + ib_cpu[len +11 ] = chroma_offset >>32 ; + ib_cpu[len +12 ] = chroma_offset; + ib_cpu[len +13 ] =ALIGN (enc->height,16 );; + ib_cpu[len +14 ] =ALIGN (enc->width, align); + ib_cpu[len +15 ] =ALIGN (enc->width, align); +/* encDisableMBOffloading-encDisableTwoPipeMode-encInputPicArrayMode-encInputPicAddrMode */ + ib_cpu[len +16 ] =0x01010000 ; + ib_cpu[len +18 ] =0 ;/* encPicType */ + ib_cpu[len +19 ] =0 ;/* encIdrFlag */ + ib_cpu[len +20 ] =0 ;/* encIdrPicId */ + ib_cpu[len +21 ] =0 ;/* encMGSKeyPic */ + ib_cpu[len +22 ] =0 ;/* encReferenceFlag */ + ib_cpu[len +23 ] =0 ;/* encTemporalLayerIndex */ + ib_cpu[len +55 ] =0 ;/* pictureStructure */ + ib_cpu[len +56 ] =0 ;/* encPicType -ref[0] */ + ib_cpu[len +61 ] =0 ;/* pictureStructure */ + ib_cpu[len +62 ] =0 ;/* encPicType -ref[1] */ + ib_cpu[len +67 ] =0 ;/* pictureStructure */ + ib_cpu[len +68 ] =0 ;/* encPicType -ref1 */ + ib_cpu[len +81 ] =1 ;/* frameNumber */ + ib_cpu[len +82 ] =2 ;/* pictureOrderCount */ + ib_cpu[len +83 ] =0xffffffff ;/* numIPicRemainInRCGOP */ + ib_cpu[len +84 ] =0xffffffff ;/* numPPicRemainInRCGOP */ + ib_cpu[len +85 ] =0xffffffff ;/* numBPicRemainInRCGOP */ + ib_cpu[len +86 ] =0xffffffff ;/* numIRPicRemainInRCGOP */ + ib_cpu[len +87 ] =0 ;/* remainedIntraRefreshPictures */ + len +=sizeof (vce_encode) /4 ; + + enc->ib_len = len; + r =submit (len,AMDGPU_HW_IP_VCE ); +CU_ASSERT_EQUAL (r,0 ); +} + +static void check_mv_result (struct amdgpu_vce_encode *enc) +{ +uint64_t sum; +uint32_t s =140790 ; +uint32_t *ptr, size; +int i, j, r; + + r =amdgpu_bo_cpu_map (enc->fb[0 ].handle, (void **)&enc->fb[0 ].ptr); +CU_ASSERT_EQUAL (r,0 ); + ptr = (uint32_t *)enc->fb[0 ].ptr; + r =amdgpu_bo_cpu_unmap (enc->fb[0 ].handle); +CU_ASSERT_EQUAL (r,0 ); + r =amdgpu_bo_cpu_map (enc->mvb.handle, (void **)&enc->mvb.ptr); +CU_ASSERT_EQUAL (r,0 ); +for (j =0 , sum =0 ; j < enc->mvbuf_size; ++j) + sum += enc->mvb.ptr[j]; +CU_ASSERT_EQUAL (sum, s); + r =amdgpu_bo_cpu_unmap (enc->mvb.handle); +CU_ASSERT_EQUAL (r,0 ); +} + +static void amdgpu_cs_vce_encode_mv (void ) +{ +uint32_t vbuf_size, bs_size =0x154000 , cpb_size; +unsigned align = (family_id >=AMDGPU_FAMILY_AI ) ?256 :16 ; +int i, r; + + vbuf_size =ALIGN (enc.width, align) *ALIGN (enc.height,16 ) *1.5 ; + enc.mvbuf_size =ALIGN (enc.width,16 ) *ALIGN (enc.height,16 ) /8 ; + cpb_size = vbuf_size *10 ; + num_resources =0 ; +alloc_resource (&enc.fb[0 ],4096 ,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.fb[0 ].handle; +alloc_resource (&enc.bs[0 ], bs_size,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.bs[0 ].handle; +alloc_resource (&enc.mvb, enc.mvbuf_size,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.mvb.handle; +alloc_resource (&enc.vbuf, vbuf_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.vbuf.handle; +alloc_resource (&enc.mvrefbuf, vbuf_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.mvrefbuf.handle; +alloc_resource (&enc.cpb, cpb_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.cpb.handle; + resources[num_resources++] = ib_handle; + + r =amdgpu_bo_cpu_map (enc.vbuf.handle, (void **)&enc.vbuf.ptr); +CU_ASSERT_EQUAL (r,0 ); + +memset (enc.vbuf.ptr,0 , vbuf_size); +for (i =0 ; i < enc.height; ++i) { +memcpy (enc.vbuf.ptr, (frame + i * enc.width), enc.width); + enc.vbuf.ptr +=ALIGN (enc.width, align); + } +for (i =0 ; i < enc.height /2 ; ++i) { +memcpy (enc.vbuf.ptr, ((frame + enc.height * enc.width) + i * enc.width), enc.width); + enc.vbuf.ptr +=ALIGN (enc.width, align); + } + + r =amdgpu_bo_cpu_unmap (enc.vbuf.handle); +CU_ASSERT_EQUAL (r,0 ); + + r =amdgpu_bo_cpu_map (enc.mvrefbuf.handle, (void **)&enc.mvrefbuf.ptr); +CU_ASSERT_EQUAL (r,0 ); + +memset (enc.mvrefbuf.ptr,0 , vbuf_size); +for (i =0 ; i < enc.height; ++i) { +memcpy (enc.mvrefbuf.ptr, (frame + (enc.height - i -1 ) * enc.width), enc.width); + enc.mvrefbuf.ptr +=ALIGN (enc.width, align); + } +for (i =0 ; i < enc.height /2 ; ++i) { +memcpy (enc.mvrefbuf.ptr, + ((frame + enc.height * enc.width) + (enc.height /2 - i -1 ) * enc.width), enc.width); + enc.mvrefbuf.ptr +=ALIGN (enc.width, align); + } + + r =amdgpu_bo_cpu_unmap (enc.mvrefbuf.handle); +CU_ASSERT_EQUAL (r,0 ); + +amdgpu_cs_vce_config (); + + vce_taskinfo[3 ] =3 ; +amdgpu_cs_vce_mv (&enc); +check_mv_result (&enc); + +free_resource (&enc.fb[0 ]); +free_resource (&enc.bs[0 ]); +free_resource (&enc.vbuf);
Quoted 9 lines
tests/amdgpu/vce_tests.c static void amdgpu_cs_vce_encode(void) · line 744
Quoted 8 lines
tests/amdgpu/vce_tests.c +5
-0+free_resource (&enc.cpb); +free_resource (&enc.mvrefbuf); +free_resource (&enc.mvb); +} +static void amdgpu_cs_vce_destroy (void ) {int len, r;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 5d08580a-c1d1-c693-8c26-a55fcf4e9bbb-5C7GfCeVMHo@public.gmane.org
Re: [PATCH v2] tests/amdgpu: add vce mv tests support and sets
Quoted 111 lines · James Zhu
Quoted 27 lines · Leo Liu
Quoted 23 lines · James Zhu
Signed-off-by James Zhu<[email protected]>--- tests/amdgpu/vce_ib.h | 21 ++++- tests/amdgpu/vce_tests.c | 224 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 240 insertions(+), 5 deletions(-)tests/amdgpu/vce_ib.h +1
-1@@ -41,7 +41,7 @@ static uint32_t vce_taskinfo[8] = { 0x00000000, }; -static const uint32_t vce_create[] = { +static uint32_t vce_create[] = {0x00000030 ,0x01000001 ,0x00000000 ,@@ -144,7 +144,7 @@ static const uint32_t vce_rdo[] = { 0x00000000, };Quoted 12 lines
tests/amdgpu/vce_ib.h static const uint32_t vce_destroy[] = { · line 318
Quoted 10 lines
tests/amdgpu/vce_ib.h +2
-1-static const uint32_t vce_pic_ctrl[] = { +static uint32_t vce_pic_ctrl[] = {0x00000074 ,0x04000002 ,0x00000000 ,@@ -315,4 +315,21 @@ static const uint32_t vce_destroy[] = {0x00000008 , 0x02000001, }; +Parameters array in header should keep read-only. You should modify IB on the fly with the conditions.
James: can make it with adding a flag.
Quoted 57 lines
Quoted 57 lines
tests/amdgpu/vce_ib.h +16
-0+static const uint32_t vce_mv_buffer[] = { +0x00000038 , +0x0500000d , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +};#endif /*_vce_ib_h*/ tests/amdgpu/vce_tests.c +9
-0@@ -37,6 +37,7 @@#define IB_SIZE 4096#define MAX_RESOURCES 16 +#define FW_53_0_03 ((53 << 24) | (0 << 16) | (03 << 8))struct amdgpu_vce_bo {amdgpu_bo_handle handle;@@ -55,6 +56,9 @@ struct amdgpu_vce_encode {struct amdgpu_vce_bo cpb;unsigned ib_len;bool two_instance; +struct amdgpu_vce_bo mvrefbuf; +struct amdgpu_vce_bo mvb; +unsigned mvbuf_size; };static amdgpu_device_handle device_handle;@@ -62,6 +66,9 @@ static uint32_t major_version;static uint32_t minor_version;static uint32_t family_id;static uint32_t vce_harvest_config; +static uint32_t chip_rev; +static uint32_t chip_id; +static uint32_t ids_flags;static amdgpu_context_handle context_handle;static amdgpu_bo_handle ib_handle;@@ -75,33 +82,62 @@ static unsigned num_resources;static void amdgpu_cs_vce_create (void );static void amdgpu_cs_vce_encode (void ); +static void amdgpu_cs_vce_preset_mv (void ); +static void amdgpu_cs_vce_encode_mv (void );static void amdgpu_cs_vce_destroy (void );Quoted 10 lines
tests/amdgpu/vce_tests.c static unsigned num_resources; · line 96
Quoted 8 lines
tests/amdgpu/vce_tests.c +4
-0CU_TestInfo vce_tests[] = { {"VCE create" , amdgpu_cs_vce_create }, {"VCE encode" , amdgpu_cs_vce_encode }, {"VCE destroy" , amdgpu_cs_vce_destroy }, + {"VCE MV preset" , amdgpu_cs_vce_preset_mv }, + {"VCE MV create" , amdgpu_cs_vce_create }, + {"VCE MV dump" , amdgpu_cs_vce_encode_mv }, + {"VCE MV destroy" , amdgpu_cs_vce_destroy },Why to add create/destroy again? my understanding is that all the operations should be executable with one pair of create/destroy.
Quoted 1 line
James: They are two different tests, one is encode, and the other is MV dump. create has different setting for normal test and MV dump test.
As far as I can see, there is only one difference from create as below, but that might be ignorable as well.
vce_create[11] = 0x01000000; /* disableTwoInstance */
Quoted 67 lines
Quoted 67 lines
Quoted 59 lines
tests/amdgpu/vce_tests.c +26
-3CU_TEST_INFO_NULL, }; -CU_BOOL suite_vce_tests_enable (void ) { +uint32_t version, feature; +CU_BOOL ret_mv =CU_FALSE ; +if (amdgpu_device_initialize (drm_amdgpu[0 ], &major_version, &minor_version, &device_handle))return CU_FALSE ; family_id = device_handle->info.family_id; + chip_rev = device_handle->info.chip_rev; + chip_id = device_handle->info.chip_external_rev; + ids_flags = device_handle->info.ids_flags; + +amdgpu_query_firmware_version (device_handle,AMDGPU_INFO_FW_VCE ,0 , +0 , &version, &feature);if (amdgpu_device_deinitialize (device_handle))return CU_FALSE ; -if (family_id >=AMDGPU_FAMILY_RV || family_id ==AMDGPU_FAMILY_SI ) {printf ("\n\nThe ASIC NOT support VCE, suite disabled\n" );return CU_FALSE ; } +if (!(chip_id == (chip_rev +0x3C ) ||/* FIJI */ + chip_id == (chip_rev +0x50 ) ||/* Polaris 10*/ + chip_id == (chip_rev +0x5A ) ||/* Polaris 11*/ + chip_id == (chip_rev +0x64 ) ||/* Polaris 12*/ + (family_id >AMDGPU_FAMILY_VI && !ids_flags)))/* dGPU > Polaris */ +printf ("\n\nThe ASIC NOT support VCE MV, suite disabled\n" ); +else if (FW_53_0_03 >= version) +printf ("\n\nThe ASIC FW version NOT support VCE MV, suite disabled\n" ); +else + ret_mv =CU_TRUE ; + +amdgpu_set_test_active ("VCE Tests" ,"VCE MV preset" , ret_mv); +amdgpu_set_test_active ("VCE Tests" ,"VCE MV create" , ret_mv); +amdgpu_set_test_active ("VCE Tests" ,"VCE MV dump" , ret_mv); +amdgpu_set_test_active ("VCE Tests" ,"VCE MV destroy" , ret_mv); +return CU_TRUE ; }@@ -307,7 +343,7 @@ static void amdgpu_cs_vce_config(void)CU_ASSERT_EQUAL (r,0 ); } -static void amdgpu_cs_vce_encode_idr (struct amdgpu_vce_encode *enc) +static void amdgpu_cs_vce_encode_idr (struct amdgpu_vce_encode *enc) {uint64_t luma_offset, chroma_offset;tests/amdgpu/vce_tests.c static void amdgpu_cs_vce_encode(void) · line 562
Quoted 6 lines
tests/amdgpu/vce_tests.c +3
-0@@ -521,6 +557,188 @@ static void amdgpu_cs_vce_encode(void)free_resource (&enc.cpb); } +static void amdgpu_cs_vce_preset_mv (void ) +{ + vce_create[11 ] =0x01000000 ;/* disableTwoInstance */ As I know with VCE only one instance, it will ignore this. If you think it matters, you could make this value default, and re-set it with 2 instances case, since we only have limited HW with 2 instances available.
Quoted 4 lines
Quoted 3 lines
Regards,
LeoJames: Yes, according to windows version, it needs set. Tell me which asics support 2 instances, I can add check.
Carrizo.
Regards,
Leo
Quoted 175 lines
Quoted 175 lines
Quoted 175 lines
tests/amdgpu/vce_tests.c +175
-0+ vce_pic_ctrl[27 ] =0x00000001 ;/* encSliceMode */ + vce_taskinfo[3 ] =0 ; + vce_taskinfo[4 ] =0 ; +} + +static void amdgpu_cs_vce_mv (struct amdgpu_vce_encode *enc) +{ +uint64_t luma_offset, chroma_offset; +uint64_t mv_ref_luma_offset; +unsigned align = (family_id >=AMDGPU_FAMILY_AI ) ?256 :16 ; +unsigned luma_size =ALIGN (enc->width, align) *ALIGN (enc->height,16 ); +int len =0 , i, r; + + luma_offset = enc->vbuf.addr; + chroma_offset = luma_offset + luma_size; + mv_ref_luma_offset = enc->mvrefbuf.addr; + +memcpy ((ib_cpu + len), vce_session,sizeof (vce_session)); + len +=sizeof (vce_session) /4 ; +memcpy ((ib_cpu + len), vce_taskinfo,sizeof (vce_taskinfo)); + len +=sizeof (vce_taskinfo) /4 ; +memcpy ((ib_cpu + len), vce_bs_buffer,sizeof (vce_bs_buffer)); + ib_cpu[len +2 ] = enc->bs[0 ].addr >>32 ; + ib_cpu[len +3 ] = enc->bs[0 ].addr; + len +=sizeof (vce_bs_buffer) /4 ; +memcpy ((ib_cpu + len), vce_context_buffer,sizeof (vce_context_buffer)); + ib_cpu[len +2 ] = enc->cpb.addr >>32 ; + ib_cpu[len +3 ] = enc->cpb.addr; + len +=sizeof (vce_context_buffer) /4 ; +memcpy ((ib_cpu + len), vce_aux_buffer,sizeof (vce_aux_buffer)); +for (i =0 ; i <8 ; ++i) + ib_cpu[len +2 + i] = luma_size *1.5 * (i +2 ); +for (i =0 ; i <8 ; ++i) + ib_cpu[len +10 + i] = luma_size *1.5 ; + len +=sizeof (vce_aux_buffer) /4 ; +memcpy ((ib_cpu + len), vce_feedback,sizeof (vce_feedback)); + ib_cpu[len +2 ] = enc->fb[0 ].addr >>32 ; + ib_cpu[len +3 ] = enc->fb[0 ].addr; + len +=sizeof (vce_feedback) /4 ; +memcpy ((ib_cpu + len), vce_mv_buffer,sizeof (vce_mv_buffer)); + ib_cpu[len +2 ] = mv_ref_luma_offset >>32 ; + ib_cpu[len +3 ] = mv_ref_luma_offset; + ib_cpu[len +4 ] =ALIGN (enc->width, align); + ib_cpu[len +5 ] =ALIGN (enc->width, align); + ib_cpu[len +6 ] = luma_size; + ib_cpu[len +7 ] = enc->mvb.addr >>32 ; + ib_cpu[len +8 ] = enc->mvb.addr; + len +=sizeof (vce_mv_buffer) /4 ; +memcpy ((ib_cpu + len), vce_encode,sizeof (vce_encode)); + ib_cpu[len +2 ] =0 ; + ib_cpu[len +3 ] =0 ; + ib_cpu[len +4 ] =0x154000 ; + ib_cpu[len +9 ] = luma_offset >>32 ; + ib_cpu[len +10 ] = luma_offset; + ib_cpu[len +11 ] = chroma_offset >>32 ; + ib_cpu[len +12 ] = chroma_offset; + ib_cpu[len +13 ] =ALIGN (enc->height,16 );; + ib_cpu[len +14 ] =ALIGN (enc->width, align); + ib_cpu[len +15 ] =ALIGN (enc->width, align); +/* encDisableMBOffloading-encDisableTwoPipeMode-encInputPicArrayMode-encInputPicAddrMode */ + ib_cpu[len +16 ] =0x01010000 ; + ib_cpu[len +18 ] =0 ;/* encPicType */ + ib_cpu[len +19 ] =0 ;/* encIdrFlag */ + ib_cpu[len +20 ] =0 ;/* encIdrPicId */ + ib_cpu[len +21 ] =0 ;/* encMGSKeyPic */ + ib_cpu[len +22 ] =0 ;/* encReferenceFlag */ + ib_cpu[len +23 ] =0 ;/* encTemporalLayerIndex */ + ib_cpu[len +55 ] =0 ;/* pictureStructure */ + ib_cpu[len +56 ] =0 ;/* encPicType -ref[0] */ + ib_cpu[len +61 ] =0 ;/* pictureStructure */ + ib_cpu[len +62 ] =0 ;/* encPicType -ref[1] */ + ib_cpu[len +67 ] =0 ;/* pictureStructure */ + ib_cpu[len +68 ] =0 ;/* encPicType -ref1 */ + ib_cpu[len +81 ] =1 ;/* frameNumber */ + ib_cpu[len +82 ] =2 ;/* pictureOrderCount */ + ib_cpu[len +83 ] =0xffffffff ;/* numIPicRemainInRCGOP */ + ib_cpu[len +84 ] =0xffffffff ;/* numPPicRemainInRCGOP */ + ib_cpu[len +85 ] =0xffffffff ;/* numBPicRemainInRCGOP */ + ib_cpu[len +86 ] =0xffffffff ;/* numIRPicRemainInRCGOP */ + ib_cpu[len +87 ] =0 ;/* remainedIntraRefreshPictures */ + len +=sizeof (vce_encode) /4 ; + + enc->ib_len = len; + r =submit (len,AMDGPU_HW_IP_VCE ); +CU_ASSERT_EQUAL (r,0 ); +} + +static void check_mv_result (struct amdgpu_vce_encode *enc) +{ +uint64_t sum; +uint32_t s =140790 ; +uint32_t *ptr, size; +int i, j, r; + + r =amdgpu_bo_cpu_map (enc->fb[0 ].handle, (void **)&enc->fb[0 ].ptr); +CU_ASSERT_EQUAL (r,0 ); + ptr = (uint32_t *)enc->fb[0 ].ptr; + r =amdgpu_bo_cpu_unmap (enc->fb[0 ].handle); +CU_ASSERT_EQUAL (r,0 ); + r =amdgpu_bo_cpu_map (enc->mvb.handle, (void **)&enc->mvb.ptr); +CU_ASSERT_EQUAL (r,0 ); +for (j =0 , sum =0 ; j < enc->mvbuf_size; ++j) + sum += enc->mvb.ptr[j]; +CU_ASSERT_EQUAL (sum, s); + r =amdgpu_bo_cpu_unmap (enc->mvb.handle); +CU_ASSERT_EQUAL (r,0 ); +} + +static void amdgpu_cs_vce_encode_mv (void ) +{ +uint32_t vbuf_size, bs_size =0x154000 , cpb_size; +unsigned align = (family_id >=AMDGPU_FAMILY_AI ) ?256 :16 ; +int i, r; + + vbuf_size =ALIGN (enc.width, align) *ALIGN (enc.height,16 ) *1.5 ; + enc.mvbuf_size =ALIGN (enc.width,16 ) *ALIGN (enc.height,16 ) /8 ; + cpb_size = vbuf_size *10 ; + num_resources =0 ; +alloc_resource (&enc.fb[0 ],4096 ,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.fb[0 ].handle; +alloc_resource (&enc.bs[0 ], bs_size,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.bs[0 ].handle; +alloc_resource (&enc.mvb, enc.mvbuf_size,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.mvb.handle; +alloc_resource (&enc.vbuf, vbuf_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.vbuf.handle; +alloc_resource (&enc.mvrefbuf, vbuf_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.mvrefbuf.handle; +alloc_resource (&enc.cpb, cpb_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.cpb.handle; + resources[num_resources++] = ib_handle; + + r =amdgpu_bo_cpu_map (enc.vbuf.handle, (void **)&enc.vbuf.ptr); +CU_ASSERT_EQUAL (r,0 ); + +memset (enc.vbuf.ptr,0 , vbuf_size); +for (i =0 ; i < enc.height; ++i) { +memcpy (enc.vbuf.ptr, (frame + i * enc.width), enc.width); + enc.vbuf.ptr +=ALIGN (enc.width, align); + } +for (i =0 ; i < enc.height /2 ; ++i) { +memcpy (enc.vbuf.ptr, ((frame + enc.height * enc.width) + i * enc.width), enc.width); + enc.vbuf.ptr +=ALIGN (enc.width, align); + } + + r =amdgpu_bo_cpu_unmap (enc.vbuf.handle); +CU_ASSERT_EQUAL (r,0 ); + + r =amdgpu_bo_cpu_map (enc.mvrefbuf.handle, (void **)&enc.mvrefbuf.ptr); +CU_ASSERT_EQUAL (r,0 ); + +memset (enc.mvrefbuf.ptr,0 , vbuf_size); +for (i =0 ; i < enc.height; ++i) { +memcpy (enc.mvrefbuf.ptr, (frame + (enc.height - i -1 ) * enc.width), enc.width); + enc.mvrefbuf.ptr +=ALIGN (enc.width, align); + } +for (i =0 ; i < enc.height /2 ; ++i) { +memcpy (enc.mvrefbuf.ptr, + ((frame + enc.height * enc.width) + (enc.height /2 - i -1 ) * enc.width), enc.width); + enc.mvrefbuf.ptr +=ALIGN (enc.width, align); + } + + r =amdgpu_bo_cpu_unmap (enc.mvrefbuf.handle); +CU_ASSERT_EQUAL (r,0 ); + +amdgpu_cs_vce_config (); + + vce_taskinfo[3 ] =3 ; +amdgpu_cs_vce_mv (&enc); +check_mv_result (&enc); + +free_resource (&enc.fb[0 ]); +free_resource (&enc.bs[0 ]); +free_resource (&enc.vbuf); +free_resource (&enc.cpb);
Quoted 9 lines
Quoted 8 lines
tests/amdgpu/vce_tests.c static void amdgpu_cs_vce_encode(void) · line 744
Quoted 7 lines
tests/amdgpu/vce_tests.c +4
-0+free_resource (&enc.mvrefbuf); +free_resource (&enc.mvb); +} +static void amdgpu_cs_vce_destroy (void ) {int len, r;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v3 1/1 tests/amdgpu: add vce mv tests support and sets
In reply to a message not in the archive--- tests/amdgpu/vce_ib.h | 21 ++++- tests/amdgpu/vce_tests.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 237 insertions(+), 5 deletions(-)
tests/amdgpu/vce_ib.h +19 -2
@@ -41,7 +41,7 @@ static uint32_t vce_taskinfo[8] = { 0x00000000, }; -static const uint32_t vce_create[] = { +static uint32_t vce_create[] = {0x00000030 ,0x01000001 ,0x00000000 ,
@@ -144,7 +144,7 @@ static const uint32_t vce_rdo[] = { 0x00000000, }; -static const uint32_t vce_pic_ctrl[] = { +static uint32_t vce_pic_ctrl[] = {0x00000074 ,0x04000002 ,0x00000000 ,
@@ -315,4 +315,21 @@ static const uint32_t vce_destroy[] = {0x00000008 , 0x02000001, }; + +static const uint32_t vce_mv_buffer[] = { +0x00000038 , +0x0500000d , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +};#endif /*_vce_ib_h*/
tests/amdgpu/vce_tests.c +218 -3
294 lines not on this page · raw message
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v4 1/1 tests/amdgpu: add vce mv tests support and sets
In reply to a message not in the archive--- tests/amdgpu/vce_ib.h | 17 ++++ tests/amdgpu/vce_tests.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 235 insertions(+), 3 deletions(-)
tests/amdgpu/vce_ib.h +17 -0
@@ -315,4 +315,21 @@ static const uint32_t vce_destroy[] = {0x00000008 , 0x02000001, }; + +static const uint32_t vce_mv_buffer[] = { +0x00000038 , +0x0500000d , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +};#endif /*_vce_ib_h*/
tests/amdgpu/vce_tests.c +218 -3
294 lines not on this page · raw message
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1522951638-14743-1-git-send-email-James.Zhu-5C7GfCeVMHo@public.gmane.org
Leo Liu
Acked-byRe: [PATCH v4] tests/amdgpu: add vce mv tests support and sets
Quoted 1 line · James Zhu
Signed-off-by James Zhu <[email protected]>
Regards,
Leo
Quoted 326 lines
--- tests/amdgpu/vce_ib.h | 17 ++++ tests/amdgpu/vce_tests.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 235 insertions(+), 3 deletions(-)tests/amdgpu/vce_ib.h +17
-0@@ -315,4 +315,21 @@ static const uint32_t vce_destroy[] = {0x00000008 , 0x02000001, }; + +static const uint32_t vce_mv_buffer[] = { +0x00000038 , +0x0500000d , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +};#endif /*_vce_ib_h*/ tests/amdgpu/vce_tests.c +211
-3@@ -37,6 +37,7 @@#define IB_SIZE 4096#define MAX_RESOURCES 16 +#define FW_53_0_03 ((53 << 24) | (0 << 16) | (03 << 8))struct amdgpu_vce_bo {amdgpu_bo_handle handle;@@ -55,6 +56,9 @@ struct amdgpu_vce_encode {struct amdgpu_vce_bo cpb;unsigned ib_len;bool two_instance; +struct amdgpu_vce_bo mvrefbuf; +struct amdgpu_vce_bo mvb; +unsigned mvbuf_size; };static amdgpu_device_handle device_handle;@@ -62,6 +66,10 @@ static uint32_t major_version;static uint32_t minor_version;static uint32_t family_id;static uint32_t vce_harvest_config; +static uint32_t chip_rev; +static uint32_t chip_id; +static uint32_t ids_flags; +static bool is_mv_supported = true;static amdgpu_context_handle context_handle;static amdgpu_bo_handle ib_handle;@@ -75,33 +83,58 @@ static unsigned num_resources;static void amdgpu_cs_vce_create (void );static void amdgpu_cs_vce_encode (void ); +static void amdgpu_cs_vce_encode_mv (void );static void amdgpu_cs_vce_destroy (void );CU_TestInfo vce_tests[] = { {"VCE create" , amdgpu_cs_vce_create }, {"VCE encode" , amdgpu_cs_vce_encode }, + {"VCE MV dump" , amdgpu_cs_vce_encode_mv }, {"VCE destroy" , amdgpu_cs_vce_destroy },CU_TEST_INFO_NULL , }; -CU_BOOL suite_vce_tests_enable (void ) { +uint32_t version, feature; +CU_BOOL ret_mv =CU_FALSE ; +if (amdgpu_device_initialize (drm_amdgpu[0 ], &major_version, &minor_version, &device_handle))return CU_FALSE ; family_id = device_handle->info.family_id; + chip_rev = device_handle->info.chip_rev; + chip_id = device_handle->info.chip_external_rev; + ids_flags = device_handle->info.ids_flags; + +amdgpu_query_firmware_version (device_handle,AMDGPU_INFO_FW_VCE ,0 , +0 , &version, &feature);if (amdgpu_device_deinitialize (device_handle))return CU_FALSE ; -if (family_id >=AMDGPU_FAMILY_RV || family_id ==AMDGPU_FAMILY_SI ) {printf ("\n\nThe ASIC NOT support VCE, suite disabled\n" );return CU_FALSE ; } +if (!(chip_id == (chip_rev +0x3C ) ||/* FIJI */ + chip_id == (chip_rev +0x50 ) ||/* Polaris 10*/ + chip_id == (chip_rev +0x5A ) ||/* Polaris 11*/ + chip_id == (chip_rev +0x64 ) ||/* Polaris 12*/ + (family_id >=AMDGPU_FAMILY_AI && !ids_flags)))/* dGPU > Polaris */ +printf ("\n\nThe ASIC NOT support VCE MV, suite disabled\n" ); +else if (FW_53_0_03 > version) +printf ("\n\nThe ASIC FW version NOT support VCE MV, suite disabled\n" ); +else + ret_mv =CU_TRUE ; + +if (ret_mv ==CU_FALSE ) { +amdgpu_set_test_active ("VCE Tests" ,"VCE MV dump" , ret_mv); + is_mv_supported = false; + } +return CU_TRUE ; }@@ -270,6 +303,12 @@ static void amdgpu_cs_vce_create(void)memcpy ((ib_cpu + len), vce_create,sizeof (vce_create)); ib_cpu[len +8 ] =ALIGN (enc.width, align); ib_cpu[len +9 ] =ALIGN (enc.width, align); +if (is_mv_supported == true) {/* disableTwoInstance */ +if (family_id >=AMDGPU_FAMILY_AI ) + ib_cpu[len +11 ] =0x01000001 ; +else + ib_cpu[len +11 ] =0x01000201 ; + } len +=sizeof (vce_create) /4 ;memcpy ((ib_cpu + len), vce_feedback,sizeof (vce_feedback)); ib_cpu[len +2 ] = enc.fb[0 ].addr >>32 ;@@ -301,13 +340,15 @@ static void amdgpu_cs_vce_config(void)memcpy ((ib_cpu + len), vce_rdo,sizeof (vce_rdo)); len +=sizeof (vce_rdo) /4 ;memcpy ((ib_cpu + len), vce_pic_ctrl,sizeof (vce_pic_ctrl)); +if (is_mv_supported == true) + ib_cpu[len +27 ] =0x00000001 ;/* encSliceMode */ len +=sizeof (vce_pic_ctrl) /4 ; r =submit (len,AMDGPU_HW_IP_VCE );CU_ASSERT_EQUAL (r,0 ); } -static void amdgpu_cs_vce_encode_idr (struct amdgpu_vce_encode *enc) +static void amdgpu_cs_vce_encode_idr (struct amdgpu_vce_encode *enc) {uint64_t luma_offset, chroma_offset;@@ -521,6 +562,180 @@ static void amdgpu_cs_vce_encode(void)free_resource (&enc.cpb); } +static void amdgpu_cs_vce_mv (struct amdgpu_vce_encode *enc) +{ +uint64_t luma_offset, chroma_offset; +uint64_t mv_ref_luma_offset; +unsigned align = (family_id >=AMDGPU_FAMILY_AI ) ?256 :16 ; +unsigned luma_size =ALIGN (enc->width, align) *ALIGN (enc->height,16 ); +int len =0 , i, r; + + luma_offset = enc->vbuf.addr; + chroma_offset = luma_offset + luma_size; + mv_ref_luma_offset = enc->mvrefbuf.addr; + +memcpy ((ib_cpu + len), vce_session,sizeof (vce_session)); + len +=sizeof (vce_session) /4 ; +memcpy ((ib_cpu + len), vce_taskinfo,sizeof (vce_taskinfo)); + len +=sizeof (vce_taskinfo) /4 ; +memcpy ((ib_cpu + len), vce_bs_buffer,sizeof (vce_bs_buffer)); + ib_cpu[len +2 ] = enc->bs[0 ].addr >>32 ; + ib_cpu[len +3 ] = enc->bs[0 ].addr; + len +=sizeof (vce_bs_buffer) /4 ; +memcpy ((ib_cpu + len), vce_context_buffer,sizeof (vce_context_buffer)); + ib_cpu[len +2 ] = enc->cpb.addr >>32 ; + ib_cpu[len +3 ] = enc->cpb.addr; + len +=sizeof (vce_context_buffer) /4 ; +memcpy ((ib_cpu + len), vce_aux_buffer,sizeof (vce_aux_buffer)); +for (i =0 ; i <8 ; ++i) + ib_cpu[len +2 + i] = luma_size *1.5 * (i +2 ); +for (i =0 ; i <8 ; ++i) + ib_cpu[len +10 + i] = luma_size *1.5 ; + len +=sizeof (vce_aux_buffer) /4 ; +memcpy ((ib_cpu + len), vce_feedback,sizeof (vce_feedback)); + ib_cpu[len +2 ] = enc->fb[0 ].addr >>32 ; + ib_cpu[len +3 ] = enc->fb[0 ].addr; + len +=sizeof (vce_feedback) /4 ; +memcpy ((ib_cpu + len), vce_mv_buffer,sizeof (vce_mv_buffer)); + ib_cpu[len +2 ] = mv_ref_luma_offset >>32 ; + ib_cpu[len +3 ] = mv_ref_luma_offset; + ib_cpu[len +4 ] =ALIGN (enc->width, align); + ib_cpu[len +5 ] =ALIGN (enc->width, align); + ib_cpu[len +6 ] = luma_size; + ib_cpu[len +7 ] = enc->mvb.addr >>32 ; + ib_cpu[len +8 ] = enc->mvb.addr; + len +=sizeof (vce_mv_buffer) /4 ; +memcpy ((ib_cpu + len), vce_encode,sizeof (vce_encode)); + ib_cpu[len +2 ] =0 ; + ib_cpu[len +3 ] =0 ; + ib_cpu[len +4 ] =0x154000 ; + ib_cpu[len +9 ] = luma_offset >>32 ; + ib_cpu[len +10 ] = luma_offset; + ib_cpu[len +11 ] = chroma_offset >>32 ; + ib_cpu[len +12 ] = chroma_offset; + ib_cpu[len +13 ] =ALIGN (enc->height,16 );; + ib_cpu[len +14 ] =ALIGN (enc->width, align); + ib_cpu[len +15 ] =ALIGN (enc->width, align); +/* encDisableMBOffloading-encDisableTwoPipeMode-encInputPicArrayMode-encInputPicAddrMode */ + ib_cpu[len +16 ] =0x01010000 ; + ib_cpu[len +18 ] =0 ;/* encPicType */ + ib_cpu[len +19 ] =0 ;/* encIdrFlag */ + ib_cpu[len +20 ] =0 ;/* encIdrPicId */ + ib_cpu[len +21 ] =0 ;/* encMGSKeyPic */ + ib_cpu[len +22 ] =0 ;/* encReferenceFlag */ + ib_cpu[len +23 ] =0 ;/* encTemporalLayerIndex */ + ib_cpu[len +55 ] =0 ;/* pictureStructure */ + ib_cpu[len +56 ] =0 ;/* encPicType -ref[0] */ + ib_cpu[len +61 ] =0 ;/* pictureStructure */ + ib_cpu[len +62 ] =0 ;/* encPicType -ref[1] */ + ib_cpu[len +67 ] =0 ;/* pictureStructure */ + ib_cpu[len +68 ] =0 ;/* encPicType -ref1 */ + ib_cpu[len +81 ] =1 ;/* frameNumber */ + ib_cpu[len +82 ] =2 ;/* pictureOrderCount */ + ib_cpu[len +83 ] =0xffffffff ;/* numIPicRemainInRCGOP */ + ib_cpu[len +84 ] =0xffffffff ;/* numPPicRemainInRCGOP */ + ib_cpu[len +85 ] =0xffffffff ;/* numBPicRemainInRCGOP */ + ib_cpu[len +86 ] =0xffffffff ;/* numIRPicRemainInRCGOP */ + ib_cpu[len +87 ] =0 ;/* remainedIntraRefreshPictures */ + len +=sizeof (vce_encode) /4 ; + + enc->ib_len = len; + r =submit (len,AMDGPU_HW_IP_VCE ); +CU_ASSERT_EQUAL (r,0 ); +} + +static void check_mv_result (struct amdgpu_vce_encode *enc) +{ +uint64_t sum; +uint32_t s =140790 ; +uint32_t *ptr, size; +int i, j, r; + + r =amdgpu_bo_cpu_map (enc->fb[0 ].handle, (void **)&enc->fb[0 ].ptr); +CU_ASSERT_EQUAL (r,0 ); + ptr = (uint32_t *)enc->fb[0 ].ptr; + r =amdgpu_bo_cpu_unmap (enc->fb[0 ].handle); +CU_ASSERT_EQUAL (r,0 ); + r =amdgpu_bo_cpu_map (enc->mvb.handle, (void **)&enc->mvb.ptr); +CU_ASSERT_EQUAL (r,0 ); +for (j =0 , sum =0 ; j < enc->mvbuf_size; ++j) + sum += enc->mvb.ptr[j]; +CU_ASSERT_EQUAL (sum, s); + r =amdgpu_bo_cpu_unmap (enc->mvb.handle); +CU_ASSERT_EQUAL (r,0 ); +} + +static void amdgpu_cs_vce_encode_mv (void ) +{ +uint32_t vbuf_size, bs_size =0x154000 , cpb_size; +unsigned align = (family_id >=AMDGPU_FAMILY_AI ) ?256 :16 ; +int i, r; + + vbuf_size =ALIGN (enc.width, align) *ALIGN (enc.height,16 ) *1.5 ; + enc.mvbuf_size =ALIGN (enc.width,16 ) *ALIGN (enc.height,16 ) /8 ; + cpb_size = vbuf_size *10 ; + num_resources =0 ; +alloc_resource (&enc.fb[0 ],4096 ,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.fb[0 ].handle; +alloc_resource (&enc.bs[0 ], bs_size,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.bs[0 ].handle; +alloc_resource (&enc.mvb, enc.mvbuf_size,AMDGPU_GEM_DOMAIN_GTT ); + resources[num_resources++] = enc.mvb.handle; +alloc_resource (&enc.vbuf, vbuf_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.vbuf.handle; +alloc_resource (&enc.mvrefbuf, vbuf_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.mvrefbuf.handle; +alloc_resource (&enc.cpb, cpb_size,AMDGPU_GEM_DOMAIN_VRAM ); + resources[num_resources++] = enc.cpb.handle; + resources[num_resources++] = ib_handle; + + r =amdgpu_bo_cpu_map (enc.vbuf.handle, (void **)&enc.vbuf.ptr); +CU_ASSERT_EQUAL (r,0 ); + +memset (enc.vbuf.ptr,0 , vbuf_size); +for (i =0 ; i < enc.height; ++i) { +memcpy (enc.vbuf.ptr, (frame + i * enc.width), enc.width); + enc.vbuf.ptr +=ALIGN (enc.width, align); + } +for (i =0 ; i < enc.height /2 ; ++i) { +memcpy (enc.vbuf.ptr, ((frame + enc.height * enc.width) + i * enc.width), enc.width); + enc.vbuf.ptr +=ALIGN (enc.width, align); + } + + r =amdgpu_bo_cpu_unmap (enc.vbuf.handle); +CU_ASSERT_EQUAL (r,0 ); + + r =amdgpu_bo_cpu_map (enc.mvrefbuf.handle, (void **)&enc.mvrefbuf.ptr); +CU_ASSERT_EQUAL (r,0 ); + +memset (enc.mvrefbuf.ptr,0 , vbuf_size); +for (i =0 ; i < enc.height; ++i) { +memcpy (enc.mvrefbuf.ptr, (frame + (enc.height - i -1 ) * enc.width), enc.width); + enc.mvrefbuf.ptr +=ALIGN (enc.width, align); + } +for (i =0 ; i < enc.height /2 ; ++i) { +memcpy (enc.mvrefbuf.ptr, + ((frame + enc.height * enc.width) + (enc.height /2 - i -1 ) * enc.width), enc.width); + enc.mvrefbuf.ptr +=ALIGN (enc.width, align); + } + + r =amdgpu_bo_cpu_unmap (enc.mvrefbuf.handle); +CU_ASSERT_EQUAL (r,0 ); + +amdgpu_cs_vce_config (); + + vce_taskinfo[3 ] =3 ; +amdgpu_cs_vce_mv (&enc); +check_mv_result (&enc); + +free_resource (&enc.fb[0 ]);
tests/amdgpu/vce_tests.c static void amdgpu_cs_vce_encode(void) · line 741
Quoted 10 lines
tests/amdgpu/vce_tests.c +7
-0+free_resource (&enc.bs[0 ]); +free_resource (&enc.vbuf); +free_resource (&enc.cpb); +free_resource (&enc.mvrefbuf); +free_resource (&enc.mvb); +} +static void amdgpu_cs_vce_destroy (void ) {int len, r;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx