Add testing for CCS
Subsystems (2)
v3 cover Add testing for CCS
From: Apoorva Singh <[email protected]>
- Add new library intel_mocs for mocs settings.
- Add new library i915_blt for various blt commands.
- Add a new platform flag, has_flat_ccs, for platforms supporting Flat CCS.
- Only use the main copy engines for XY_BLOCK_COPY. XY_BLOCK_COPY blt command is used to transfer the ccs data. So, we can only run the tests on those engines which have support for the "block_copy" capability.
- Add gem_ccs test for CCS testing.
Commands are constructed with XY_BLOCK_COPY_BLT
and XY_CTRL_SURF_COPY_BLT instructions.
Apoorva Singh (3):
lib/i915: Introduce library intel_mocs
lib/i915: Introduce library i915_blt
lib/intel_chipset.h: Add has_flat_ccs flag
CQ Tang (1):
i915/gem_ccs: Add testing for CCS
Chris Wilson (1):
i915/gem_engine_topology: Only use the main copy engines for
XY_BLOCK_COPY
lib/i915/gem_engine_topology.c | 38 +++ lib/i915/gem_engine_topology.h | 5 + lib/i915/i915_blt.c | 469 +++++++++++++++++++++++++++++++ lib/i915/i915_blt.h | 82 ++++++ lib/i915/intel_mocs.c | 51 ++++ lib/i915/intel_mocs.h | 19 ++ lib/intel_chipset.h | 3 + lib/meson.build | 2 + tests/i915/gem_ccs.c | 492 +++++++++++++++++++++++++++++++++ tests/meson.build | 1 + 10 files changed, 1162 insertions(+) create mode 100644 lib/i915/i915_blt.c create mode 100644 lib/i915/i915_blt.h create mode 100644 lib/i915/intel_mocs.c create mode 100644 lib/i915/intel_mocs.h create mode 100644 tests/i915/gem_ccs.c
Signature · 1 line
2.25.1
PATCH v3 1/5 lib/i915: Introduce library intel_mocs
From: Apoorva Singh <[email protected]>
Add new library intel_mocs for mocs settings.
--- lib/i915/intel_mocs.c | 51 +++++++++++++++++++++++++++++++++++++++++++ lib/i915/intel_mocs.h | 19 ++++++++++++++++ lib/meson.build | 1 + 3 files changed, 71 insertions(+) create mode 100644 lib/i915/intel_mocs.c create mode 100644 lib/i915/intel_mocs.h
lib/i915/intel_mocs.c new file +51 -0
@@ -0,0 +1,51 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +#include "igt.h" +#include "i915/gem.h" +#include "intel_mocs.h" + +static void get_mocs_index (int fd,struct drm_i915_mocs_index *mocs) +{ +uint16_t devid =intel_get_drm_devid (fd); + +/* +* Gen >= 12 onwards don't have a setting for PTE, +* so using I915_MOCS_PTE as mocs index may leads to +* some undefined MOCS behavior. +* This helper function is providing current UC as well +* as WB MOCS index based on platform. + +*/ +if (IS_DG1 (devid)) { + mocs->uc_index =1 ; + mocs->wb_index =5 ; + }else if (IS_GEN12 (devid)) { + mocs->uc_index =3 ; + mocs->wb_index =2 ; + }else { + mocs->uc_index =I915_MOCS_PTE ; + mocs->wb_index =I915_MOCS_CACHED ; + } +} + +/* BitField [6:1] represents index to MOCS Tables +* BitField [0] represents Encryption/Decryption */ + +uint8_t intel_get_wb_mocs (int fd) +{ +struct drm_i915_mocs_index mocs; + +get_mocs_index (fd, &mocs); +return mocs.wb_index <<1 ; +} + +uint8_t intel_get_uc_mocs (int fd) +{ +struct drm_i915_mocs_index mocs; + +get_mocs_index (fd, &mocs); +return mocs.uc_index <<1 ; +}
lib/i915/intel_mocs.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2019 Intel Corporation +*/ + +#ifndef _INTEL_MOCS_H +#define _INTEL_MOCS_H + +#define XY_BLOCK_COPY_BLT_MOCS_SHIFT 21 +#define XY_CTRL_SURF_COPY_BLT_MOCS_SHIFT 25 + +struct drm_i915_mocs_index { +uint8_t uc_index; +uint8_t wb_index; +}; + +uint8_t intel_get_wb_mocs (int fd); +uint8_t intel_get_uc_mocs (int fd); +#endif /* _INTEL_MOCS_H */
lib/meson.build +1 -0
@@ -11,6 +11,7 @@ lib_sources = [ 'i915/gem_mman.c', 'i915/gem_vm.c', 'i915/intel_memory_region.c', + 'i915/intel_mocs.c', 'igt_collection.c', 'igt_color_encoding.c', 'igt_debugfs.c',
Signature · 1 line
2.25.1
PATCH v3 2/5 lib/i915: Introduce library i915_blt
In reply to [email protected]From: Apoorva Singh <[email protected]>
Add new library 'i915_blt' for various blt commands.
--- lib/i915/i915_blt.c | 469 ++++++++++++++++++++++++++++++++++++++++++++ lib/i915/i915_blt.h | 82 ++++++++ lib/meson.build | 1 + 3 files changed, 552 insertions(+) create mode 100644 lib/i915/i915_blt.c create mode 100644 lib/i915/i915_blt.h
lib/i915/i915_blt.c new file +469 -0
@@ -0,0 +1,469 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +#include <errno.h> +#include <sys/ioctl.h> +#include <sys/time.h> +#include <malloc.h> +#include "drm.h" +#include "igt.h" +#include "i915_blt.h" +#include "i915/intel_mocs.h" + +/* +* make_block_copy_batch: +* @fd: open i915 drm file descriptor +* @batch_buf: the batch buffer to populate with the command +* @src: fd of the source BO +* @dst: fd of the destination BO +* @length: size of the src and dest BOs +* @reloc: pointer to the relocation entyr for this command +* @offset_src: source address offset +* @offset_dst: destination address offset +* @src_mem_type: source memory type (denotes direct or indirect +* addressing) +* @dst_mem_type: destination memory type (denotes direct or indirect +* addressing) +* @src_compression: flag to enable uncompressed read of compressed data +* at the source +* @dst_compression: flag to enable compressed write at the destination +* @resolve: flag to enable resolve of compressed data +*/ +static int make_block_copy_batch (int fd,uint32_t *batch_buf, +uint32_t src,uint32_t dst,uint32_t length, +struct drm_i915_gem_relocation_entry *reloc, +uint64_t offset_src,uint64_t offset_dst, +int src_mem_type,int dst_mem_type, +int src_compression,int dst_compression, +int resolve) +{ +uint32_t *b = batch_buf; +uint32_t devid; +uint8_t src_mocs =intel_get_uc_mocs (fd); +uint8_t dst_mocs = src_mocs; + + devid =intel_get_drm_devid (fd); + +igt_assert (AT_LEAST_GEN (devid,12 ) &&IS_TIGERLAKE (devid) && !(src_compression || dst_compression)); + +/* BG 0 */ + b[0 ] =BLOCK_COPY_BLT_CMD | resolve; + +/* BG 1 +* +* Using Tile 4 dimensions. Height = 32 rows +* Width = 128 bytes +*/ + b[1 ] = dst_compression |TILE_4_FORMAT |TILE_4_WIDTH_DWORD | + dst_mocs <<XY_BLOCK_COPY_BLT_MOCS_SHIFT ;; + +/* BG 3 +* +* X2 = TILE_4_WIDTH +* Y2 = (length / TILE_4_WIDTH) << 16: +*/ + b[3 ] =TILE_4_WIDTH | (length >>7 ) <<DEST_Y2_COORDINATE_SHIFT ; + + b[4 ] = offset_dst; + b[5 ] = offset_dst >>32 ; + +/* relocate address in b[4] and b[5] */ + reloc->offset =4 * (sizeof (uint32_t )); + reloc->delta =0 ; + reloc->target_handle = dst; + reloc->read_domains =I915_GEM_DOMAIN_RENDER ; + reloc->write_domain =I915_GEM_DOMAIN_RENDER ; + reloc->presumed_offset =0 ; + reloc++; + +/* BG 6 */ + b[6 ] = dst_mem_type <<DEST_MEM_TYPE_SHIFT ; + +/* BG 8 */ + b[8 ] = src_compression |TILE_4_WIDTH_DWORD |TILE_4_FORMAT | + src_mocs <<XY_BLOCK_COPY_BLT_MOCS_SHIFT ; + + b[9 ] = offset_src; + b[10 ] = offset_src >>32 ; + +/* relocate address in b[9] and b[10] */ + reloc->offset =9 *sizeof (uint32_t ); + reloc->delta =0 ; + reloc->target_handle = src; + reloc->read_domains =I915_GEM_DOMAIN_RENDER ; + reloc->write_domain =0 ; + reloc->presumed_offset =0 ; + reloc++; + +/* BG 11 */ + b[11 ] = src_mem_type <<SRC_MEM_TYPE_SHIFT ; + +/* BG 16 */ + b[16 ] =SURFACE_TYPE_2D | + ((TILE_4_WIDTH -1 ) <<DEST_SURF_WIDTH_SHIFT ) | + (TILE_4_HEIGHT -1 ); + +/* BG 19 */ + b[19 ] =SURFACE_TYPE_2D | + ((TILE_4_WIDTH -1 ) <<SRC_SURF_WIDTH_SHIFT ) | + (TILE_4_HEIGHT -1 ); + + b +=XY_BLOCK_COPY_BLT_LEN_DWORD ; + + b[0 ] =MI_FLUSH_DW |MI_FLUSH_LLC |MI_INVALIDATE_TLB ; + reloc->offset =23 *sizeof (uint32_t ); + reloc->delta =0 ; + reloc->target_handle = dst_compression >0 ? dst : src; + reloc->read_domains =0 ; + reloc->write_domain =0 ; + reloc->presumed_offset =0 ; + reloc++; + b[3 ] =0 ; + + b[4 ] =MI_FLUSH_DW |MI_FLUSH_CCS ; + reloc->offset =27 *sizeof (uint32_t ); + reloc->delta =0 ; + reloc->target_handle = dst_compression >0 ? dst : src; + reloc->read_domains =0 ; + reloc->write_domain =0 ; + reloc->presumed_offset =0 ; + reloc++; + b[7 ] =0 ; + + b[8 ] =MI_BATCH_BUFFER_END ; + b[9 ] =0 ; + + b +=10 ; + +return (b - batch_buf) *sizeof (uint32_t ); +} + +static void __xy_block_copy_blt (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,enum copy_mode mode,bool enable_compression, +uint32_t ctx,struct intel_execution_engine2 *e) +{ +struct drm_i915_gem_relocation_entry reloc[4 ]; +struct drm_i915_gem_exec_object2 exec[3 ]; +struct drm_i915_gem_execbuffer2 execbuf; +int len; +int src_mem_type, dst_mem_type; +int dst_compression, src_compression; +int resolve; +uint32_t cmd, batch_buf[BATCH_SIZE /sizeof (uint32_t )] = {}; +uint64_t offset_src, offset_dst, offset_bb, bb_size, ret; + + bb_size =BATCH_SIZE ; + ret =__gem_create_in_memory_regions (fd, &cmd, &bb_size, bb_region); +igt_assert_eq (ret,0 ); + +switch (mode) { +case SYS_TO_SYS :/* copy from smem to smem */ + src_mem_type =MEM_TYPE_SYS ; + dst_mem_type =MEM_TYPE_SYS ; + src_compression =0 ; + dst_compression =0 ; + resolve =0 ; +case SYS_TO_LOCAL :/* copy from smem to lmem */ + src_mem_type =MEM_TYPE_SYS ; + dst_mem_type =MEM_TYPE_LOCAL ; + src_compression =0 ; + dst_compression = enable_compression ? (COMPRESSION_ENABLE |AUX_CCS_E ) :0 ; + resolve =0 ; +case LOCAL_TO_SYS :/* copy from lmem to smem */ + src_mem_type =MEM_TYPE_LOCAL ; + dst_mem_type =MEM_TYPE_SYS ; + src_compression = enable_compression ? (COMPRESSION_ENABLE |AUX_CCS_E ) :0 ; + dst_compression =0 ; + resolve =0 ; +case LOCAL_TO_LOCAL :/* copy from lmem to lmem */ + src_mem_type =MEM_TYPE_LOCAL ; + dst_mem_type =MEM_TYPE_LOCAL ; + src_compression = enable_compression ? (COMPRESSION_ENABLE |AUX_CCS_E ) :0 ; + dst_compression = enable_compression ? (COMPRESSION_ENABLE |AUX_CCS_E ) :0 ; + resolve =0 ; +case LOCAL_TO_LOCAL_INPLACE :/* in-place decompress */ + src_mem_type =MEM_TYPE_LOCAL ; + dst_mem_type =MEM_TYPE_LOCAL ; + src_compression = enable_compression ? (COMPRESSION_ENABLE |AUX_CCS_E ) :0 ; + dst_compression = enable_compression ? (COMPRESSION_ENABLE |AUX_CCS_E ) :0 ; + resolve =FULL_RESOLVE ; + } + + offset_src =get_offset (ahnd, src, src_size,0 ); + offset_dst =get_offset (ahnd, dst, dst_size,0 ); + offset_bb =get_offset (ahnd, cmd, bb_size,0 ); + +/* construct the batch buffer */ +memset (reloc,0 ,sizeof (reloc)); + len =make_block_copy_batch (fd, batch_buf, + src, dst, length, reloc, + offset_src, offset_dst, + src_mem_type, dst_mem_type, + src_compression, dst_compression, + resolve); +igt_assert (len >0 ); + +/* write batch buffer to 'cmd' BO */ +gem_write (fd, cmd,0 , batch_buf, len); + +/* Execute the batch buffer */ +memset (exec,0 ,sizeof (exec)); +if (mode ==LOCAL_TO_LOCAL_INPLACE ) { + exec[0 ].handle = dst; + exec[1 ].handle = cmd; + exec[1 ].relocation_count = !ahnd ?4 :0 ; + exec[1 ].relocs_ptr =to_user_pointer (reloc); +if (ahnd) { + exec[0 ].offset = offset_src; + exec[0 ].flags |=EXEC_OBJECT_PINNED |EXEC_OBJECT_WRITE ; + exec[1 ].offset = offset_dst; + exec[1 ].flags |=EXEC_OBJECT_PINNED ; + } + }else { + exec[0 ].handle = src; + exec[1 ].handle = dst; + exec[2 ].handle = cmd; + exec[2 ].relocation_count = !ahnd ?4 :0 ; + exec[2 ].relocs_ptr =to_user_pointer (reloc); +if (ahnd) { + exec[0 ].offset = offset_src; + exec[0 ].flags |=EXEC_OBJECT_PINNED ; + exec[1 ].offset = offset_dst; + exec[1 ].flags |=EXEC_OBJECT_PINNED |EXEC_OBJECT_WRITE ; + exec[2 ].offset = offset_bb; + exec[2 ].flags |=EXEC_OBJECT_PINNED ; + } + } + +memset (&execbuf,0 ,sizeof (execbuf)); + execbuf.buffers_ptr =to_user_pointer (exec); + +if (mode ==LOCAL_TO_LOCAL_INPLACE ) + execbuf.buffer_count =2 ; +else + execbuf.buffer_count =3 ; + execbuf.batch_len = len; + +if (ctx) + execbuf.rsvd1 = ctx; + + execbuf.flags =I915_EXEC_BLT ; +if (e) + execbuf.flags = e->flags; + +gem_execbuf (fd, &execbuf); +gem_close (fd, cmd); +put_offset (ahnd, src); +put_offset (ahnd, dst); +put_offset (ahnd, cmd); +} + +void xy_block_copy_blt (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,enum copy_mode mode,bool enable_compression, +struct intel_execution_engine2 *e) +{ +__xy_block_copy_blt (fd, bb_region, src, dst, src_size, dst_size, ahnd, + length, mode, enable_compression,0 , e); +} + +void xy_block_copy_blt_ctx (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,enum copy_mode mode,bool enable_compression, +uint32_t ctx,struct intel_execution_engine2 *e) +{ +__xy_block_copy_blt (fd, bb_region, src, dst, src_size, dst_size, ahnd, + length, mode, enable_compression, ctx, e); +} + +/* +* make_ctrl_surf_batch: +* @fd: open i915 drm file descriptor +* @batch_buf: the batch buffer to populate with the command +* @src: fd of the source BO +* @dst: fd of the destination BO +* @length: size of the ctrl surf in bytes +* @reloc: pointer to the relocation entyr for this command +* @offset_src: source address offset +* @offset_dst: destination address offset +* @src_mem_access: source memory type (denotes direct or indirect +* addressing) +* @dst_mem_acdcess: destination memory type (denotes direct or indirect +* addressing) +*/ +static int make_ctrl_surf_batch (int fd,uint32_t *batch_buf, +uint32_t src,uint32_t dst,uint32_t length, +struct drm_i915_gem_relocation_entry *reloc, +uint64_t offset_src,uint64_t offset_dst, +int src_mem_access,int dst_mem_access) +{ +int num_ccs_blocks; +uint32_t *b = batch_buf; +uint8_t src_mocs =intel_get_uc_mocs (fd); +uint8_t dst_mocs = src_mocs; + + num_ccs_blocks = length/CCS_RATIO ; +if (num_ccs_blocks <1 ) + num_ccs_blocks =1 ; +if (num_ccs_blocks >NUM_CCS_BLKS_PER_XFER ) +return 0 ; + +/* +* We use logical AND with 1023 since the size field +* takes values which is in the range of 0 - 1023 +*/ + b[0 ] = ((XY_CTRL_SURF_COPY_BLT ) | + (src_mem_access <<SRC_ACCESS_TYPE_SHIFT ) | + (dst_mem_access <<DST_ACCESS_TYPE_SHIFT ) | + (((num_ccs_blocks -1 ) &1023 ) <<CCS_SIZE_SHIFT )); + + b[1 ] = offset_src; + b[2 ] = offset_src >>32 | src_mocs <<XY_CTRL_SURF_COPY_BLT_MOCS_SHIFT ; + +/* relocate address in b[1] and b[2] */ + reloc->offset =1 *sizeof (uint32_t ); + reloc->delta =0 ; + reloc->target_handle = src; + reloc->read_domains =I915_GEM_DOMAIN_RENDER ; + reloc->write_domain =0 ; + reloc->presumed_offset =0 ; + reloc++; + + b[3 ] = offset_dst; + b[4 ] = offset_dst >>32 | dst_mocs <<XY_CTRL_SURF_COPY_BLT_MOCS_SHIFT ; + +/* relocate address in b[3] and b[4] */ + reloc->offset =3 * (sizeof (uint32_t )); + reloc->delta =0 ; + reloc->target_handle = dst; + reloc->read_domains =I915_GEM_DOMAIN_RENDER ; + reloc->write_domain =I915_GEM_DOMAIN_RENDER ; + reloc->presumed_offset =0 ; + reloc++; + + b[5 ] =0 ; + + b[6 ] =MI_FLUSH_DW |MI_FLUSH_LLC |MI_INVALIDATE_TLB ; + + reloc->offset =7 *sizeof (uint32_t ); + reloc->delta =0 ; + reloc->target_handle = + dst_mem_access ==INDIRECT_ACCESS ? dst : src; + reloc->read_domains =0 ; + reloc->write_domain =0 ; + reloc->presumed_offset =0 ; + reloc++; + b[9 ] =0 ; + + b[10 ] =MI_FLUSH_DW |MI_FLUSH_CCS ; + reloc->offset =11 *sizeof (uint32_t ); + reloc->delta =0 ; + reloc->target_handle = + dst_mem_access ==INDIRECT_ACCESS ? dst : src; + reloc->read_domains =0 ; + reloc->write_domain =0 ; + reloc->presumed_offset =0 ; + reloc++; + b[13 ] =0 ; + + b[14 ] =MI_BATCH_BUFFER_END ; + b[15 ] =0 ; + + b +=16 ; + +return (b - batch_buf) *sizeof (uint32_t ); +} + +static void __xy_ctrl_surf_copy_blt (int fd,uint32_t bb_region,uint32_t src, +uint32_t dst,uint64_t src_size,uint64_t dst_size, +uint64_t ahnd,uint32_t length,bool writetodev, +uint32_t ctx,struct intel_execution_engine2 *e) +{ +struct drm_i915_gem_relocation_entry reloc[4 ]; +struct drm_i915_gem_exec_object2 exec[3 ]; +struct drm_i915_gem_execbuffer2 execbuf; +int len, src_mem_access, dst_mem_access; +uint32_t cmd, batch_buf[BATCH_SIZE /sizeof (uint32_t )] = {}; +uint64_t offset_src, offset_dst, offset_bb, bb_size, ret; + + bb_size =BATCH_SIZE ; + ret =__gem_create_in_memory_regions (fd, &cmd, &bb_size, bb_region); +igt_assert_eq (ret,0 ); + +if (writetodev) { + src_mem_access =DIRECT_ACCESS ; + dst_mem_access =INDIRECT_ACCESS ; + }else { + src_mem_access =INDIRECT_ACCESS ; + dst_mem_access =DIRECT_ACCESS ; + } + + offset_src =get_offset (ahnd, src, src_size,0 ); + offset_dst =get_offset (ahnd, dst, dst_size,0 ); + offset_bb =get_offset (ahnd, cmd, bb_size,0 ); + +/* construct batch command buffer */ +memset (reloc,0 ,sizeof (reloc)); + len =make_ctrl_surf_batch (fd, batch_buf, + src, dst, length, reloc, + offset_src, offset_dst, + src_mem_access, dst_mem_access); +igt_assert (len >0 ); + +/* Copy the batch buff to BO cmd */ +gem_write (fd, cmd,0 , batch_buf, len); + +/* Execute the batch buffer */ +memset (exec,0 ,sizeof (exec)); + exec[0 ].handle = src; + exec[1 ].handle = dst; + exec[2 ].handle = cmd; + exec[2 ].relocation_count = !ahnd ?4 :0 ; + exec[2 ].relocs_ptr =to_user_pointer (reloc); +if (ahnd) { + exec[0 ].offset = offset_src; + exec[0 ].flags |=EXEC_OBJECT_PINNED ; + exec[1 ].offset = offset_dst; + exec[1 ].flags |=EXEC_OBJECT_PINNED |EXEC_OBJECT_WRITE ; + exec[2 ].offset = offset_bb; + exec[2 ].flags |=EXEC_OBJECT_PINNED ; + } + +memset (&execbuf,0 ,sizeof (execbuf)); + execbuf.buffers_ptr =to_user_pointer (exec); + execbuf.buffer_count =3 ; + execbuf.batch_len = len; + execbuf.flags =I915_EXEC_BLT ; +if (ctx) + execbuf.rsvd1 = ctx; +if (e) + execbuf.flags = e->flags; + +gem_execbuf (fd, &execbuf); +gem_close (fd, cmd); +put_offset (ahnd, src); +put_offset (ahnd, dst); +put_offset (ahnd, cmd); +} + +void xy_ctrl_surf_copy_blt (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,bool writetodev, +struct intel_execution_engine2 *e) +{ +__xy_ctrl_surf_copy_blt (fd, bb_region, src, dst, src_size, dst_size, + ahnd, length, writetodev,0 , e); +} + +void xy_ctrl_surf_copy_blt_ctx (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,bool writetodev,uint32_t ctx, +struct intel_execution_engine2 *e) +{ +__xy_ctrl_surf_copy_blt (fd, bb_region, src, dst, src_size, dst_size, + ahnd, length, writetodev, ctx, e); +} +
lib/i915/i915_blt.h new file +82 -0
82 lines not on this page · raw message
lib/meson.build +1 -0
@@ -12,6 +12,7 @@ lib_sources = [ 'i915/gem_vm.c', 'i915/intel_memory_region.c', 'i915/intel_mocs.c', + 'i915/i915_blt.c', 'igt_collection.c', 'igt_color_encoding.c', 'igt_debugfs.c',
Signature · 1 line
2.25.1
Re: [igt-dev] [PATCH i-g-t, v3 2/5] lib/i915: Introduce library i915_blt
Quoted 43 lines · On Fri, Dec 10, 2021 at 06:23:03PM +0530, [email protected] wrote:
From: Apoorva Singh <[email protected]>
Add new library '
i915_blt' for various blt commands.Signed-off-by Apoorva Singh <[email protected]>Signed-off-by Ayaz A Siddiqui <[email protected]>Cc Zbigniew Kempczyński <[email protected]>Cc Melkaveri, Arjun <[email protected]>--- lib/i915/i915_blt.c | 469 ++++++++++++++++++++++++++++++++++++++++++++ lib/i915/i915_blt.h | 82 ++++++++ lib/meson.build | 1 + 3 files changed, 552 insertions(+) create mode 100644 lib/i915/i915_blt.c create mode 100644 lib/i915/i915_blt.hlib/i915/i915_blt.c new file +21
-0@@ -0,0 +1,469 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +#include <errno.h> +#include <sys/ioctl.h> +#include <sys/time.h> +#include <malloc.h> +#include "drm.h" +#include "igt.h" +#include "i915_blt.h" +#include "i915/intel_mocs.h" + +/* +* make_block_copy_batch: +* @fd: open i915 drm file descriptor +* @batch_buf: the batch buffer to populate with the command +* @src: fd of the source BO +* @dst: fd of the destination BO +* @length: size of the src and dest BOs
lib/i915/i915_blt.c line 31
Quoted 10 lines
lib/i915/i915_blt.c new file +10
-0+* @reloc: pointer to the relocation entyr for this command +* @offset_src: source address offset +* @offset_dst: destination address offset +* @src_mem_type: source memory type (denotes direct or indirect +* addressing) +* @dst_mem_type: destination memory type (denotes direct or indirect +* addressing) +* @src_compression: flag to enable uncompressed read of compressed data +* at the source +* @dst_compression: flag to enable compressed write at the destination
One flag enables uncompressed, one flag enables compressed. Are the semantics really reversed or are the docs wrong?
Quoted 8 lines
lib/i915/i915_blt.c new file +8
-0+* @resolve: flag to enable resolve of compressed data +*/ +static int make_block_copy_batch(int fd, uint32_t *batch_buf, + uint32_t src, uint32_t dst, uint32_t length, + struct drm_i915_gem_relocation_entry *reloc, + uint64_t offset_src, uint64_t offset_dst, + int src_mem_type, int dst_mem_type, + int src_compression, int dst_compression,
lib/i915/i915_blt.c line 49
Quoted 10 lines
lib/i915/i915_blt.c new file +10
-0+ int resolve) +{ +uint32_t *b = batch_buf; +uint32_t devid; +uint8_t src_mocs =intel_get_uc_mocs (fd); +uint8_t dst_mocs = src_mocs; + + devid =intel_get_drm_devid (fd); + +igt_assert (AT_LEAST_GEN (devid,12 ) &&IS_TIGERLAKE (devid) && !(src_compression || dst_compression));
If devid is tigerlake, surely checking AT_LEAST_GEN(12) is a tautology?
Why do both src_compression and dst_compression have to always be false?
Signature · 1 line
Petri Latvala
Quoted 523 lines
lib/i915/i915_blt.c new file +420
-0+ +/* BG 0 */ + b[0 ] =BLOCK_COPY_BLT_CMD | resolve; + +/* BG 1 +* +* Using Tile 4 dimensions. Height = 32 rows +* Width = 128 bytes +*/ + b[1 ] = dst_compression |TILE_4_FORMAT |TILE_4_WIDTH_DWORD | + dst_mocs <<XY_BLOCK_COPY_BLT_MOCS_SHIFT ;; + +/* BG 3 +* +* X2 = TILE_4_WIDTH +* Y2 = (length / TILE_4_WIDTH) << 16: +*/ + b[3 ] =TILE_4_WIDTH | (length >>7 ) <<DEST_Y2_COORDINATE_SHIFT ; + + b[4 ] = offset_dst; + b[5 ] = offset_dst >>32 ; + +/* relocate address in b[4] and b[5] */ + reloc->offset =4 * (sizeof (uint32_t )); + reloc->delta =0 ; + reloc->target_handle = dst; + reloc->read_domains =I915_GEM_DOMAIN_RENDER ; + reloc->write_domain =I915_GEM_DOMAIN_RENDER ; + reloc->presumed_offset =0 ; + reloc++; + +/* BG 6 */ + b[6 ] = dst_mem_type <<DEST_MEM_TYPE_SHIFT ; + +/* BG 8 */ + b[8 ] = src_compression |TILE_4_WIDTH_DWORD |TILE_4_FORMAT | + src_mocs <<XY_BLOCK_COPY_BLT_MOCS_SHIFT ; + + b[9 ] = offset_src; + b[10 ] = offset_src >>32 ; + +/* relocate address in b[9] and b[10] */ + reloc->offset =9 *sizeof (uint32_t ); + reloc->delta =0 ; + reloc->target_handle = src; + reloc->read_domains =I915_GEM_DOMAIN_RENDER ; + reloc->write_domain =0 ; + reloc->presumed_offset =0 ; + reloc++; + +/* BG 11 */ + b[11 ] = src_mem_type <<SRC_MEM_TYPE_SHIFT ; + +/* BG 16 */ + b[16 ] =SURFACE_TYPE_2D | + ((TILE_4_WIDTH -1 ) <<DEST_SURF_WIDTH_SHIFT ) | + (TILE_4_HEIGHT -1 ); + +/* BG 19 */ + b[19 ] =SURFACE_TYPE_2D | + ((TILE_4_WIDTH -1 ) <<SRC_SURF_WIDTH_SHIFT ) | + (TILE_4_HEIGHT -1 ); + + b +=XY_BLOCK_COPY_BLT_LEN_DWORD ; + + b[0 ] =MI_FLUSH_DW |MI_FLUSH_LLC |MI_INVALIDATE_TLB ; + reloc->offset =23 *sizeof (uint32_t ); + reloc->delta =0 ; + reloc->target_handle = dst_compression >0 ? dst : src; + reloc->read_domains =0 ; + reloc->write_domain =0 ; + reloc->presumed_offset =0 ; + reloc++; + b[3 ] =0 ; + + b[4 ] =MI_FLUSH_DW |MI_FLUSH_CCS ; + reloc->offset =27 *sizeof (uint32_t ); + reloc->delta =0 ; + reloc->target_handle = dst_compression >0 ? dst : src; + reloc->read_domains =0 ; + reloc->write_domain =0 ; + reloc->presumed_offset =0 ; + reloc++; + b[7 ] =0 ; + + b[8 ] =MI_BATCH_BUFFER_END ; + b[9 ] =0 ; + + b +=10 ; + +return (b - batch_buf) *sizeof (uint32_t ); +} + +static void __xy_block_copy_blt (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,enum copy_mode mode,bool enable_compression, +uint32_t ctx,struct intel_execution_engine2 *e) +{ +struct drm_i915_gem_relocation_entry reloc[4 ]; +struct drm_i915_gem_exec_object2 exec[3 ]; +struct drm_i915_gem_execbuffer2 execbuf; +int len; +int src_mem_type, dst_mem_type; +int dst_compression, src_compression; +int resolve; +uint32_t cmd, batch_buf[BATCH_SIZE /sizeof (uint32_t )] = {}; +uint64_t offset_src, offset_dst, offset_bb, bb_size, ret; + + bb_size =BATCH_SIZE ; + ret =__gem_create_in_memory_regions (fd, &cmd, &bb_size, bb_region); +igt_assert_eq (ret,0 ); + +switch (mode) { +case SYS_TO_SYS :/* copy from smem to smem */ + src_mem_type =MEM_TYPE_SYS ; + dst_mem_type =MEM_TYPE_SYS ; + src_compression =0 ; + dst_compression =0 ; + resolve =0 ; +case SYS_TO_LOCAL :/* copy from smem to lmem */ + src_mem_type =MEM_TYPE_SYS ; + dst_mem_type =MEM_TYPE_LOCAL ; + src_compression =0 ; + dst_compression = enable_compression ? (COMPRESSION_ENABLE |AUX_CCS_E ) :0 ; + resolve =0 ; +case LOCAL_TO_SYS :/* copy from lmem to smem */ + src_mem_type =MEM_TYPE_LOCAL ; + dst_mem_type =MEM_TYPE_SYS ; + src_compression = enable_compression ? (COMPRESSION_ENABLE |AUX_CCS_E ) :0 ; + dst_compression =0 ; + resolve =0 ; +case LOCAL_TO_LOCAL :/* copy from lmem to lmem */ + src_mem_type =MEM_TYPE_LOCAL ; + dst_mem_type =MEM_TYPE_LOCAL ; + src_compression = enable_compression ? (COMPRESSION_ENABLE |AUX_CCS_E ) :0 ; + dst_compression = enable_compression ? (COMPRESSION_ENABLE |AUX_CCS_E ) :0 ; + resolve =0 ; +case LOCAL_TO_LOCAL_INPLACE :/* in-place decompress */ + src_mem_type =MEM_TYPE_LOCAL ; + dst_mem_type =MEM_TYPE_LOCAL ; + src_compression = enable_compression ? (COMPRESSION_ENABLE |AUX_CCS_E ) :0 ; + dst_compression = enable_compression ? (COMPRESSION_ENABLE |AUX_CCS_E ) :0 ; + resolve =FULL_RESOLVE ; + } + + offset_src =get_offset (ahnd, src, src_size,0 ); + offset_dst =get_offset (ahnd, dst, dst_size,0 ); + offset_bb =get_offset (ahnd, cmd, bb_size,0 ); + +/* construct the batch buffer */ +memset (reloc,0 ,sizeof (reloc)); + len =make_block_copy_batch (fd, batch_buf, + src, dst, length, reloc, + offset_src, offset_dst, + src_mem_type, dst_mem_type, + src_compression, dst_compression, + resolve); +igt_assert (len >0 ); + +/* write batch buffer to 'cmd' BO */ +gem_write (fd, cmd,0 , batch_buf, len); + +/* Execute the batch buffer */ +memset (exec,0 ,sizeof (exec)); +if (mode ==LOCAL_TO_LOCAL_INPLACE ) { + exec[0 ].handle = dst; + exec[1 ].handle = cmd; + exec[1 ].relocation_count = !ahnd ?4 :0 ; + exec[1 ].relocs_ptr =to_user_pointer (reloc); +if (ahnd) { + exec[0 ].offset = offset_src; + exec[0 ].flags |=EXEC_OBJECT_PINNED |EXEC_OBJECT_WRITE ; + exec[1 ].offset = offset_dst; + exec[1 ].flags |=EXEC_OBJECT_PINNED ; + } + }else { + exec[0 ].handle = src; + exec[1 ].handle = dst; + exec[2 ].handle = cmd; + exec[2 ].relocation_count = !ahnd ?4 :0 ; + exec[2 ].relocs_ptr =to_user_pointer (reloc); +if (ahnd) { + exec[0 ].offset = offset_src; + exec[0 ].flags |=EXEC_OBJECT_PINNED ; + exec[1 ].offset = offset_dst; + exec[1 ].flags |=EXEC_OBJECT_PINNED |EXEC_OBJECT_WRITE ; + exec[2 ].offset = offset_bb; + exec[2 ].flags |=EXEC_OBJECT_PINNED ; + } + } + +memset (&execbuf,0 ,sizeof (execbuf)); + execbuf.buffers_ptr =to_user_pointer (exec); + +if (mode ==LOCAL_TO_LOCAL_INPLACE ) + execbuf.buffer_count =2 ; +else + execbuf.buffer_count =3 ; + execbuf.batch_len = len; + +if (ctx) + execbuf.rsvd1 = ctx; + + execbuf.flags =I915_EXEC_BLT ; +if (e) + execbuf.flags = e->flags; + +gem_execbuf (fd, &execbuf); +gem_close (fd, cmd); +put_offset (ahnd, src); +put_offset (ahnd, dst); +put_offset (ahnd, cmd); +} + +void xy_block_copy_blt (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,enum copy_mode mode,bool enable_compression, +struct intel_execution_engine2 *e) +{ +__xy_block_copy_blt (fd, bb_region, src, dst, src_size, dst_size, ahnd, + length, mode, enable_compression,0 , e); +} + +void xy_block_copy_blt_ctx (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,enum copy_mode mode,bool enable_compression, +uint32_t ctx,struct intel_execution_engine2 *e) +{ +__xy_block_copy_blt (fd, bb_region, src, dst, src_size, dst_size, ahnd, + length, mode, enable_compression, ctx, e); +} + +/* +* make_ctrl_surf_batch: +* @fd: open i915 drm file descriptor +* @batch_buf: the batch buffer to populate with the command +* @src: fd of the source BO +* @dst: fd of the destination BO +* @length: size of the ctrl surf in bytes +* @reloc: pointer to the relocation entyr for this command +* @offset_src: source address offset +* @offset_dst: destination address offset +* @src_mem_access: source memory type (denotes direct or indirect +* addressing) +* @dst_mem_acdcess: destination memory type (denotes direct or indirect +* addressing) +*/ +static int make_ctrl_surf_batch (int fd,uint32_t *batch_buf, +uint32_t src,uint32_t dst,uint32_t length, +struct drm_i915_gem_relocation_entry *reloc, +uint64_t offset_src,uint64_t offset_dst, +int src_mem_access,int dst_mem_access) +{ +int num_ccs_blocks; +uint32_t *b = batch_buf; +uint8_t src_mocs =intel_get_uc_mocs (fd); +uint8_t dst_mocs = src_mocs; + + num_ccs_blocks = length/CCS_RATIO ; +if (num_ccs_blocks <1 ) + num_ccs_blocks =1 ; +if (num_ccs_blocks >NUM_CCS_BLKS_PER_XFER ) +return 0 ; + +/* +* We use logical AND with 1023 since the size field +* takes values which is in the range of 0 - 1023 +*/ + b[0 ] = ((XY_CTRL_SURF_COPY_BLT ) | + (src_mem_access <<SRC_ACCESS_TYPE_SHIFT ) | + (dst_mem_access <<DST_ACCESS_TYPE_SHIFT ) | + (((num_ccs_blocks -1 ) &1023 ) <<CCS_SIZE_SHIFT )); + + b[1 ] = offset_src; + b[2 ] = offset_src >>32 | src_mocs <<XY_CTRL_SURF_COPY_BLT_MOCS_SHIFT ; + +/* relocate address in b[1] and b[2] */ + reloc->offset =1 *sizeof (uint32_t ); + reloc->delta =0 ; + reloc->target_handle = src; + reloc->read_domains =I915_GEM_DOMAIN_RENDER ; + reloc->write_domain =0 ; + reloc->presumed_offset =0 ; + reloc++; + + b[3 ] = offset_dst; + b[4 ] = offset_dst >>32 | dst_mocs <<XY_CTRL_SURF_COPY_BLT_MOCS_SHIFT ; + +/* relocate address in b[3] and b[4] */ + reloc->offset =3 * (sizeof (uint32_t )); + reloc->delta =0 ; + reloc->target_handle = dst; + reloc->read_domains =I915_GEM_DOMAIN_RENDER ; + reloc->write_domain =I915_GEM_DOMAIN_RENDER ; + reloc->presumed_offset =0 ; + reloc++; + + b[5 ] =0 ; + + b[6 ] =MI_FLUSH_DW |MI_FLUSH_LLC |MI_INVALIDATE_TLB ; + + reloc->offset =7 *sizeof (uint32_t ); + reloc->delta =0 ; + reloc->target_handle = + dst_mem_access ==INDIRECT_ACCESS ? dst : src; + reloc->read_domains =0 ; + reloc->write_domain =0 ; + reloc->presumed_offset =0 ; + reloc++; + b[9 ] =0 ; + + b[10 ] =MI_FLUSH_DW |MI_FLUSH_CCS ; + reloc->offset =11 *sizeof (uint32_t ); + reloc->delta =0 ; + reloc->target_handle = + dst_mem_access ==INDIRECT_ACCESS ? dst : src; + reloc->read_domains =0 ; + reloc->write_domain =0 ; + reloc->presumed_offset =0 ; + reloc++; + b[13 ] =0 ; + + b[14 ] =MI_BATCH_BUFFER_END ; + b[15 ] =0 ; + + b +=16 ; + +return (b - batch_buf) *sizeof (uint32_t ); +} + +static void __xy_ctrl_surf_copy_blt (int fd,uint32_t bb_region,uint32_t src, +uint32_t dst,uint64_t src_size,uint64_t dst_size, +uint64_t ahnd,uint32_t length,bool writetodev, +uint32_t ctx,struct intel_execution_engine2 *e) +{ +struct drm_i915_gem_relocation_entry reloc[4 ]; +struct drm_i915_gem_exec_object2 exec[3 ]; +struct drm_i915_gem_execbuffer2 execbuf; +int len, src_mem_access, dst_mem_access; +uint32_t cmd, batch_buf[BATCH_SIZE /sizeof (uint32_t )] = {}; +uint64_t offset_src, offset_dst, offset_bb, bb_size, ret; + + bb_size =BATCH_SIZE ; + ret =__gem_create_in_memory_regions (fd, &cmd, &bb_size, bb_region); +igt_assert_eq (ret,0 ); + +if (writetodev) { + src_mem_access =DIRECT_ACCESS ; + dst_mem_access =INDIRECT_ACCESS ; + }else { + src_mem_access =INDIRECT_ACCESS ; + dst_mem_access =DIRECT_ACCESS ; + } + + offset_src =get_offset (ahnd, src, src_size,0 ); + offset_dst =get_offset (ahnd, dst, dst_size,0 ); + offset_bb =get_offset (ahnd, cmd, bb_size,0 ); + +/* construct batch command buffer */ +memset (reloc,0 ,sizeof (reloc)); + len =make_ctrl_surf_batch (fd, batch_buf, + src, dst, length, reloc, + offset_src, offset_dst, + src_mem_access, dst_mem_access); +igt_assert (len >0 ); + +/* Copy the batch buff to BO cmd */ +gem_write (fd, cmd,0 , batch_buf, len); + +/* Execute the batch buffer */ +memset (exec,0 ,sizeof (exec)); + exec[0 ].handle = src; + exec[1 ].handle = dst; + exec[2 ].handle = cmd; + exec[2 ].relocation_count = !ahnd ?4 :0 ; + exec[2 ].relocs_ptr =to_user_pointer (reloc); +if (ahnd) { + exec[0 ].offset = offset_src; + exec[0 ].flags |=EXEC_OBJECT_PINNED ; + exec[1 ].offset = offset_dst; + exec[1 ].flags |=EXEC_OBJECT_PINNED |EXEC_OBJECT_WRITE ; + exec[2 ].offset = offset_bb; + exec[2 ].flags |=EXEC_OBJECT_PINNED ; + } + +memset (&execbuf,0 ,sizeof (execbuf)); + execbuf.buffers_ptr =to_user_pointer (exec); + execbuf.buffer_count =3 ; + execbuf.batch_len = len; + execbuf.flags =I915_EXEC_BLT ; +if (ctx) + execbuf.rsvd1 = ctx; +if (e) + execbuf.flags = e->flags; + +gem_execbuf (fd, &execbuf); +gem_close (fd, cmd); +put_offset (ahnd, src); +put_offset (ahnd, dst); +put_offset (ahnd, cmd); +} + +void xy_ctrl_surf_copy_blt (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,bool writetodev, +struct intel_execution_engine2 *e) +{ +__xy_ctrl_surf_copy_blt (fd, bb_region, src, dst, src_size, dst_size, + ahnd, length, writetodev,0 , e); +} + +void xy_ctrl_surf_copy_blt_ctx (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,bool writetodev,uint32_t ctx, +struct intel_execution_engine2 *e) +{ +__xy_ctrl_surf_copy_blt (fd, bb_region, src, dst, src_size, dst_size, + ahnd, length, writetodev, ctx, e); +} +lib/i915/i915_blt.h new file +82
-0@@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2021 Intel Corporation +*/ + +#include <errno.h> +#include <sys/ioctl.h> +#include <sys/time.h> +#include <malloc.h> +#include "drm.h" +#include "igt.h" + +#define MI_FLUSH_DW_LEN_DWORD 4 +#define MI_FLUSH_DW (0x26 << 23 | 1) +#define MI_FLUSH_CCS (1 << 16) +#define MI_FLUSH_LLC (1 << 9) +#define MI_INVALIDATE_TLB (1 << 18) + +/* XY_BLOCK_COPY_BLT instruction has 22 bit groups 1 DWORD each */ +#define XY_BLOCK_COPY_BLT_LEN_DWORD 22 +#define BLOCK_COPY_BLT_CMD (2 << 29 | 0x41 << 22 | 0x14) +#define COMPRESSION_ENABLE (1 << 29) +#define AUX_CCS_E (5 << 18) +#define FULL_RESOLVE (1 << 12) +#define PARTIAL_RESOLVE (2 << 12) +#define TILE_4_FORMAT (2 << 30) +#define TILE_4_WIDTH (128) +#define TILE_4_WIDTH_DWORD ((128 >> 2) - 1) +#define TILE_4_HEIGHT (32) +#define SURFACE_TYPE_2D (1 << 29) + +#define DEST_Y2_COORDINATE_SHIFT (16) +#define DEST_MEM_TYPE_SHIFT (31) +#define SRC_MEM_TYPE_SHIFT (31) +#define DEST_SURF_WIDTH_SHIFT (14) +#define SRC_SURF_WIDTH_SHIFT (14) + +#define XY_CTRL_SURF_COPY_BLT (2<<29 | 0x48<<22 | 3) +#define SRC_ACCESS_TYPE_SHIFT 21 +#define DST_ACCESS_TYPE_SHIFT 20 +#define CCS_SIZE_SHIFT 8 +#define MI_INSTR (opcode, flags) (((opcode) << 23) | (flags)) +#define MI_ARB_CHECK MI_INSTR(0x05, 0) +#define NUM_CCS_BLKS_PER_XFER 1024 +#define INDIRECT_ACCESS 0 +#define DIRECT_ACCESS 1 + +#define BATCH_SIZE 4096 +#define BOSIZE_MIN (4*1024) +#define BOSIZE_MAX (4*1024*1024) +#define CCS_RATIO 256 + +#define MEM_TYPE_SYS 1 +#define MEM_TYPE_LOCAL 0 + +enum copy_mode { +SYS_TO_SYS =0 , +SYS_TO_LOCAL , +LOCAL_TO_SYS , +LOCAL_TO_LOCAL , +LOCAL_TO_LOCAL_INPLACE , +}; + +void xy_block_copy_blt (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,enum copy_mode mode,bool enable_compression, +struct intel_execution_engine2 *e); + +void xy_ctrl_surf_copy_blt (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,bool writetodev, +struct intel_execution_engine2 *e); + +void xy_block_copy_blt_ctx (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,enum copy_mode mode,bool enable_compression, +uint32_t ctx,struct intel_execution_engine2 *e); + +void xy_ctrl_surf_copy_blt_ctx (int fd,uint32_t bb_region,uint32_t src,uint32_t dst, +uint64_t src_size,uint64_t dst_size,uint64_t ahnd, +uint32_t length,bool writetodev,uint32_t ctx, +struct intel_execution_engine2 *e);lib/meson.build +1
-0@@ -12,6 +12,7 @@ lib_sources = [ 'i915/gem_vm.c', 'i915/intel_memory_region.c', 'i915/intel_mocs.c', + 'i915/i915_blt.c', 'igt_collection.c', 'igt_color_encoding.c', 'igt_debugfs.c',Signature · 1 line
2.25.1
PATCH v3 3/5 lib/intel_chipset.h: Add has_flat_ccs flag
In reply to [email protected]From: Apoorva Singh <[email protected]>
Add a new platform flag, has_flat_ccs, for platforms supporting Flat CCS.
--- lib/intel_chipset.h | 3 +++ 1 file changed, 3 insertions(+)
lib/intel_chipset.h +3 -0
@@ -40,6 +40,7 @@ struct intel_device_info {unsigned graphics_ver;unsigned display_ver;unsigned gt;/* 0 if unknown */ + bool has_flat_ccs : 1; bool is_mobile : 1; bool is_whitney : 1; bool is_almador : 1;
@@ -209,4 +210,6 @@ void intel_check_pch(void); IS_CHERRYVIEW(devid) || \ IS_BROXTON(devid))) +#define HAS_FLAT_CCS (devid) (intel_get_device_info(devid)->has_flat_ccs) +#endif /* _INTEL_CHIPSET_H */
Signature · 1 line
2.25.1
PATCH v3 4/5 i915/gem_engine_topology: Only use the main copy engines for XY_BLOCK_COPY
In reply to [email protected]From: Chris Wilson <[email protected]>
XY_BLOCK_COPY blt command is used to transfer the ccs data. So, we can only run the tests on those engines which have support for the "block_copy" capability.
--- lib/i915/gem_engine_topology.c | 38 ++++++++++++++++++++++++++++++++++ lib/i915/gem_engine_topology.h | 5 +++++ 2 files changed, 43 insertions(+)
lib/i915/gem_engine_topology.c +38 -0
@@ -488,6 +488,44 @@ int gem_engine_property_printf(int i915, const char *engine, const char *attr,return ret; } +static bool +__gem_engine_has_capability (int i915,const char *engine, +const char *attr,const char *cap) +{ +char buf[4096 ] = {}; +FILE *file; + + file =__open_attr (igt_sysfs_open (i915),"r" , +"engine" , engine, attr,NULL ); +if (file) { +fread (buf,1 ,sizeof (buf) -1 , file); +fclose (file); + } + +return strstr (buf, cap); +} + +bool gem_engine_has_capability (int i915,const char *engine,const char *cap) +{ +return __gem_engine_has_capability (i915, engine,"capabilities" , cap); +} + +bool gem_engine_has_known_capability (int i915,const char *engine,const char *cap) +{ +return __gem_engine_has_capability (i915, engine,"known_capabilities" , cap); +} + +bool gem_engine_can_block_copy (int i915,const struct intel_execution_engine2 *engine) +{ +if (engine->class !=I915_ENGINE_CLASS_COPY ) +return false; + +if (!gem_engine_has_known_capability (i915, engine->name,"block_copy" )) +return intel_gen (intel_get_drm_devid (i915)) >=12 ; + +return gem_engine_has_capability (i915, engine->name,"block_copy" ); +} +uint32_t gem_engine_mmio_base (int i915,const char *engine) {unsigned int mmio =0 ;
lib/i915/gem_engine_topology.h +5 -0
@@ -124,6 +124,11 @@ int gem_engine_property_printf(int i915, const char *engine, const char *attr,uint32_t gem_engine_mmio_base (int i915,const char *engine); +bool gem_engine_has_capability (int i915,const char *engine,const char *cap); +bool gem_engine_has_known_capability (int i915,const char *engine,const char *cap); + +bool gem_engine_can_block_copy (int i915,const struct intel_execution_engine2 *engine); +void dyn_sysfs_engines (int i915,int engines,const char *file,void (*test)(int i915,int engine));
Signature · 1 line
2.25.1
PATCH v3 5/5 i915/gem_ccs: Add testing for CCS
In reply to [email protected]From: CQ Tang <[email protected]>
Add gem_ccs test for CCS testing.
Commands are constructed with XY_BLOCK_COPY_BLT and XY_CTRL_SURF_COPY_BLT instructions.
--- tests/i915/gem_ccs.c | 492 +++++++++++++++++++++++++++++++++++++++++++ tests/meson.build | 1 + 2 files changed, 493 insertions(+) create mode 100644 tests/i915/gem_ccs.c
tests/i915/gem_ccs.c new file +492 -0
@@ -0,0 +1,492 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +#include <errno.h> +#include <sys/ioctl.h> +#include <sys/time.h> +#include <malloc.h> +#include "drm.h" +#include "igt.h" +#include "i915/gem.h" +#include "i915/gem_create.h" +#include "lib/intel_chipset.h" +#include "i915/i915_blt.h" + +IGT_TEST_DESCRIPTION ("Exercise the memory bandwidth compression and " +"decompression when copying data between " +"system and local memory" ); + +static void igt_wr_xy_ctrl_surf_copy_blt (int fd,uint32_t region,uint32_t src, +uint32_t dst,uint32_t out,uint64_t ahnd, +int ccssize,uint8_t *pattern_buf, +uint8_t *read_buf,int bosize, +struct intel_execution_engine2 *e) +{ +int ret, i; + +gem_write (fd, src,0 , pattern_buf, bosize); + +/* +* 'dst' is lmem BO with ccs, directly +* copy content in 'src' BO to 'dst' BO's ccs +*/ +xy_ctrl_surf_copy_blt (fd, ahnd, src, dst, ahnd, + ccssize, true, e); + +memset (read_buf,0 , ccssize); +gem_write (fd, out,0 , read_buf, ccssize); + +/* copy 'dst' BO's ccs into 'out' BO */ +xy_ctrl_surf_copy_blt (fd, region, dst, out, ahnd, + ccssize, false, e); + +gem_read (fd, out,0 , read_buf, ccssize); + +for (i =0 ; i < ccssize; i++) { +if (read_buf[i] != pattern_buf[i]) + ret++; + } +igt_assert (!ret); +} + +static void igt_overwritten_xy_block_copy_blt (int fd,uint32_t region,uint32_t src, +uint32_t dst,uint32_t out,uint64_t ahnd, +int ccssize,uint8_t *pattern_buf,uint8_t *read_buf, +int bosize,struct intel_execution_engine2 *e) +{ +int ret, i; +bool enable_compression = true; + +igt_info ("copy random pattern to lmem BO with compression\n" ); + +gem_write (fd, src,0 , pattern_buf, bosize); +gem_write (fd, dst,0 , pattern_buf, bosize); + +/* +* 'dst' is lmem BO with ccs, +* copy content in 'src' BO to 'dst' BO +*/ +xy_block_copy_blt (fd, region, src, dst, ahnd, bosize, +SYS_TO_LOCAL , enable_compression, e); + +memset (read_buf,0 , ccssize); +gem_write (fd, out,0 , read_buf, ccssize); + +/* copy 'dst' BO's ccs into 'out' BO */ +xy_ctrl_surf_copy_blt (fd, region, dst, out, ahnd, + ccssize, false, e); + +gem_read (fd, out,0 , read_buf, ccssize); + +for (i =0 ; i < ccssize; i++) { +if (read_buf[i] != pattern_buf[i]) + ret++; + } +igt_assert (ret); + +memset (read_buf,0 , bosize); +gem_read (fd, dst,0 , read_buf, bosize); + +for (i =0 ; i < bosize; i++) { +if (read_buf[i] != pattern_buf[i]) + ret++; + } +igt_assert (ret); + +memset (read_buf,0 , bosize); +gem_write (fd, out,0 , read_buf, bosize); + +/* copy 'dst' BO into 'out' BO */ +xy_block_copy_blt (fd, region, dst, out, ahnd, bosize, +LOCAL_TO_SYS , enable_compression, e); + +gem_read (fd, out,0 , read_buf, bosize); + +for (i =0 ; i < bosize; i++) { +if (read_buf[i] != pattern_buf[i]) + ret++; + } +igt_assert (!ret); + +/* decompress 'dst' in place */ +xy_block_copy_blt (fd, region, dst, dst, ahnd, bosize, +LOCAL_TO_LOCAL , enable_compression, e); + +memset (read_buf,0 , bosize); +gem_read (fd, dst,0 , read_buf, bosize); + +for (i =0 ; i < bosize; i++) { +if (read_buf[i] != pattern_buf[i]) + ret++; + } +igt_assert (!ret); + +memset (read_buf,0 , bosize); +gem_write (fd, out,0 , read_buf, bosize); + +/* copy decompressed 'dst' to 'out' */ +xy_block_copy_blt (fd, region, dst, out, ahnd, bosize, +LOCAL_TO_SYS , enable_compression, e); + +gem_read (fd, out,0 , read_buf, bosize); + +for (i =0 ; i < bosize; i++) { +if (read_buf[i] != pattern_buf[i]) + ret++; + } +igt_assert (!ret); +} + +static void igt_corrupted_xy_ctrl_surf_copy_blt (int fd,uint32_t region,uint32_t src, +uint32_t dst,uint32_t out,uint64_t ahnd, +int ccssize,uint8_t *pattern_buf,uint8_t *read_buf, +int bosize,struct intel_execution_engine2 *e) +{ +int ret, i; +bool enable_compression = true; + +gem_write (fd, src,0 , pattern_buf, bosize); + +igt_info ("corrupt CCS via XY_CTRL_SURF_COPY_BLT\n" ); + +/* corrupt 'dst' BO's ccs by writing directly */ +xy_ctrl_surf_copy_blt (fd, region, src, dst, ahnd, + ccssize, true, e); + +memset (read_buf,0 , bosize); +gem_write (fd, out,0 , read_buf, bosize); + +/* copy 'dst' BO into 'out' BO */ +xy_block_copy_blt (fd, region, dst, out, ahnd, bosize, +LOCAL_TO_SYS , enable_compression, e); + +gem_read (fd, out,0 , read_buf, bosize); + +for (i =0 ; i < bosize; i++) { +if (read_buf[i] != pattern_buf[i]) + ret++; + } +igt_assert (ret); + +memset (read_buf,0 , ccssize); +gem_write (fd, out,0 , read_buf, ccssize); + +/* copy 'dst' BO's ccs into 'out' BO */ +xy_ctrl_surf_copy_blt (fd, region, dst, out, ahnd, + ccssize, false, e); + +gem_read (fd, out,0 , read_buf, ccssize); + +for (i =0 ; i < ccssize; i++) { +if (read_buf[i] != pattern_buf[i]) + ret++; + } +igt_assert (!ret); +} + +static void igt_copy_zero_pattern_xy_block_copy_blt (int fd,uint32_t region,uint32_t src, +uint32_t dst,uint32_t out,uint64_t ahnd, +int ccssize,uint8_t *pattern_buf,uint8_t *read_buf, +uint8_t *input_buf,int bosize, +struct intel_execution_engine2 *e) +{ +int ret, i; +bool enable_compression = true; + +igt_info ("copy zeros pattern to lmem BO with compression\n" ); + +gem_write (fd, src,0 , pattern_buf, bosize); +gem_write (fd, dst,0 , pattern_buf, bosize); +/* set ccs to random pattern */ +xy_ctrl_surf_copy_blt (fd, region, src, dst, ahnd, + ccssize, true, e); + +memset (input_buf,0 , bosize); +gem_write (fd, src,0 , input_buf, bosize); + +/* copy 'src' to 'dst' with compression */ +xy_block_copy_blt (fd, region, src, dst, ahnd, bosize, +SYS_TO_LOCAL , enable_compression, e); + +gem_write (fd, out,0 , pattern_buf, bosize); + +/* copy 'dst' BO back into 'out' BO */ +xy_block_copy_blt (fd, region, dst, out, ahnd, bosize, +LOCAL_TO_SYS , enable_compression, e); + +gem_read (fd, out,0 , read_buf, bosize); + +for (i =0 ; i < bosize; i++) { +if (read_buf[i] != input_buf[i]) + ret++; + } +igt_assert (!ret); + +memset (read_buf,0 , bosize); +gem_read (fd, dst,0 , read_buf, bosize); + +for (i =0 ; i < bosize; i++) { +if (read_buf[i] != pattern_buf[i]) + ret++; + } +igt_assert (!ret); + +memset (read_buf,0 , ccssize); +gem_write (fd, out,0 , read_buf, ccssize); + +/* copy 'dst' BO's ccs into 'out' BO */ +xy_ctrl_surf_copy_blt (fd, region, dst, out, ahnd, + ccssize, false, e); + +gem_read (fd, out,0 , read_buf, ccssize); + +for (i =0 ; i < ccssize; i++) { +if (read_buf[i] != pattern_buf[i]) + ret++; + } +igt_assert (ret); +} + +static void igt_copy_repeat_pattern_xy_block_copy_blt (int fd,uint32_t region,uint32_t src, +uint32_t dst,uint32_t out,uint64_t ahnd, +int ccssize,uint8_t *pattern_buf,uint8_t *read_buf, +uint8_t *input_buf,int bosize, +struct intel_execution_engine2 *e) +{ +int ret, i; +bool enable_compression = true; + +igt_info ("copy repeat pattern to lmem BO with compression\n" ); + +gem_write (fd, src,0 , pattern_buf, bosize); +gem_write (fd, src,0 , pattern_buf, ccssize); + +xy_ctrl_surf_copy_blt (fd, region, src, dst, ahnd, + ccssize, true, e); +gem_write (fd, dst,0 , pattern_buf, bosize); + +/* generate repeating pattern */ + input_buf[0 ] = (uint8_t )rand (); + input_buf[1 ] = (uint8_t )rand (); + input_buf[2 ] = (uint8_t )rand (); + input_buf[3 ] = (uint8_t )rand (); +for (i =4 ; i < bosize; i++) + input_buf[i] = input_buf[i -4 ]; +gem_write (fd, src,0 , input_buf, bosize); + +xy_block_copy_blt (fd, region, src, dst, ahnd, bosize, +SYS_TO_LOCAL , enable_compression, e); + +memset (read_buf,0 , bosize); +gem_write (fd, out,0 , read_buf, bosize); + +/* copy 'dst' BO back into 'out' BO */ +xy_block_copy_blt (fd, region, dst, out, ahnd, bosize, +LOCAL_TO_SYS , enable_compression, e); + +gem_read (fd, out,0 , read_buf, bosize); + +for (i =0 ; i < bosize; i++) { +if (read_buf[i] != input_buf[i]) + ret++; + } +igt_assert (!ret); + +memset (read_buf,0 , bosize); +gem_read (fd, dst,0 , read_buf, bosize); + +for (i =0 ; i < bosize; i++) { +if (read_buf[i] != pattern_buf[i]) + ret++; + } +igt_assert (ret); + +memset (read_buf,0 , ccssize); +gem_write (fd, out,0 , read_buf, ccssize); + +/* copy 'dst' BO's ccs into 'out' BO */ +xy_ctrl_surf_copy_blt (fd, region, dst, out, ahnd, + ccssize, false, e); + +gem_read (fd, out,0 , read_buf, ccssize); + +for (i =0 ; i < ccssize; i++) { +if (read_buf[i] != pattern_buf[i]) + ret++; + } +igt_assert (ret); +} + +/* +* Allocate a BO in SMEM. +* Fill a pattern +* Use XY_BLOCK_COPY_BLT to copy it to LMEM with compression enabled +* Clear the BO in SMEM, and the pattern_buf in which the pattern was +* stored +* Use XY_BLOCK_COPY_BLT to copy it back to the BO in SMEM with +* resolve +* Compare the value in the BO in SMEM matches the pattern +*/ +static void test_ccs (int fd,int size,uint32_t region,char *sub_name, +struct intel_execution_engine2 *e) +{ +int bosize, ccssize, ret, i; +int start, end; +uint32_t src, dst, out; +uint8_t *pattern_buf, *input_buf, *read_buf; +uint64_t ahnd; +struct timeval tv; + + ahnd =get_reloc_ahnd (fd,0 ); + +if (size >0 ) { + start = size; + end = start +1 ; + }else { + start =BOSIZE_MIN ; + end =BOSIZE_MAX ; + } + +for (bosize = start; bosize < end; bosize *=2 ) { +/* allocate working buffers */ + pattern_buf =malloc (bosize); +igt_assert (pattern_buf); + input_buf =malloc (bosize); +igt_assert (input_buf); + read_buf =malloc (bosize); +igt_assert (read_buf); + + ccssize = bosize /CCS_RATIO ; + +/* allocate working BOs in the right location */ + src =gem_create_in_memory_regions (fd, bosize, +INTEL_MEMORY_REGION_ID (I915_SYSTEM_MEMORY ,0 )); + dst =gem_create_in_memory_regions (fd, bosize, region); + out =gem_create_in_memory_regions (fd, bosize, +INTEL_MEMORY_REGION_ID (I915_SYSTEM_MEMORY ,0 )); + +/* fill in random pattern */ + ret =gettimeofday (&tv,NULL ); +igt_assert (!ret); +srandom ((int )tv.tv_usec); + +for (i =0 ; i < bosize; i++) + pattern_buf[i] = (uint8_t )rand (); + +igt_info ("progress: bosize %d, ccssize %d\n" , bosize, ccssize); + + igt_dynamic_f("write_read_in_ccs_surface-%s-%s", sub_name, e->name) +igt_wr_xy_ctrl_surf_copy_blt (fd, region, src, dst, out, ahnd, + ccssize, pattern_buf, read_buf, + bosize, e); + igt_dynamic_f("verify_compression_of_random_data-%s-%s", sub_name, e->name) +igt_overwritten_xy_block_copy_blt (fd, region, src, dst, out, ahnd, + ccssize, pattern_buf, read_buf, + bosize, e); + igt_dynamic_f("verify_corrupted_pattern_in_ccs_surface-%s-%s", sub_name, e->name) +igt_corrupted_xy_ctrl_surf_copy_blt (fd, region, src, dst, out, ahnd, + ccssize, pattern_buf, read_buf, + bosize, e); + igt_dynamic_f("copy_zero_pattern_with_compression-%s-%s", sub_name, e->name) +igt_copy_zero_pattern_xy_block_copy_blt (fd, region, src, dst, out, ahnd, + ccssize, pattern_buf, read_buf, + input_buf, bosize, e); + igt_dynamic_f("copy_repeat_pattern_with_compression-%s-%s", sub_name, e->name) +igt_copy_repeat_pattern_xy_block_copy_blt (fd, region, src, dst, out, ahnd, + ccssize, pattern_buf, read_buf, + input_buf, bosize, e); + +gem_close (fd, out); +gem_close (fd, dst); +gem_close (fd, src); +free (read_buf); +free (input_buf); +free (pattern_buf); + } + +put_ahnd (ahnd); +} + +igt_main +{ +struct drm_i915_query_memory_regions *query_info; +struct intel_execution_engine2 *e; +struct igt_collection *regions, *set; +char *sub_name; +uint32_t region; +int drm_fd; + + igt_fixture { + drm_fd =drm_open_driver (DRIVER_INTEL ); +igt_require_gem (drm_fd); +igt_require (AT_LEAST_GEN (intel_get_drm_devid (drm_fd),12 ) >0 ); +igt_require (HAS_FLAT_CCS (intel_get_drm_devid (drm_fd))); + + query_info =gem_get_query_memory_regions (drm_fd); +igt_require (query_info); + + set =get_memory_region_set (query_info,I915_DEVICE_MEMORY ); + } + + igt_subtest_with_dynamic("basic-gem-ccs-4K") { +for_each_physical_engine (drm_fd, e) { +if (!gem_engine_can_block_copy (drm_fd, e)) +continue ; + +for_each_combination (regions,1 , set) { + sub_name =memregion_dynamic_subtest_name (regions); + region =igt_collection_get_value (regions,0 ); +test_ccs (drm_fd,4 *1024 , region, sub_name, e); +free (sub_name); + } + } + } + + igt_subtest_with_dynamic("basic-gem-ccs-64K") { +for_each_physical_engine (drm_fd, e) { +if (!gem_engine_can_block_copy (drm_fd, e)) +continue ; + +for_each_combination (regions,1 , set) { + sub_name =memregion_dynamic_subtest_name (regions); + region =igt_collection_get_value (regions,0 ); +test_ccs (drm_fd,64 *1024 , region, sub_name, e); +free (sub_name); + } + } + } + + igt_subtest_with_dynamic("basic-gem-ccs-1M") { +for_each_physical_engine (drm_fd, e) { +if (!gem_engine_can_block_copy (drm_fd, e)) +continue ; + +for_each_combination (regions,1 , set) { + sub_name =memregion_dynamic_subtest_name (regions); + region =igt_collection_get_value (regions,0 ); +test_ccs (drm_fd,1024 *1024 , region, sub_name, e); +free (sub_name); + } + } + } + + igt_subtest_with_dynamic("basic-gem-ccs-all") { +for_each_physical_engine (drm_fd, e) { +if (!gem_engine_can_block_copy (drm_fd, e)) +continue ; + +for_each_combination (regions,1 , set) { + sub_name =memregion_dynamic_subtest_name (regions); + region =igt_collection_get_value (regions,0 ); +test_ccs (drm_fd,0 , region, sub_name, e); +free (sub_name); + } + } + } + + igt_fixture { +close (drm_fd); + } +}
tests/meson.build +1 -0
@@ -107,6 +107,7 @@ i915_progs = [ 'gem_blits', 'gem_busy', 'gem_caching', + 'gem_ccs', 'gem_close', 'gem_close_race', 'gem_concurrent_blit',
Signature · 1 line
2.25.1