All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kahola, Mika" <mika.kahola@intel.com>
To: "igt-dev@lists.freedesktop.org" <igt-dev@lists.freedesktop.org>,
	"Deak, Imre" <imre.deak@intel.com>
Cc: "Welty, Brian" <brian.welty@intel.com>
Subject: Re: [igt-dev] [PATCH i-g-t 3/6] lib: Move aux pgtable state prepare/emit to intel_aux_pgtable.c
Date: Tue, 3 Dec 2019 14:50:01 +0000	[thread overview]
Message-ID: <42aaccd6deb6b5411ea83e42e6f8aa3f262091ac.camel@intel.com> (raw)
In-Reply-To: <20191129103843.5765-4-imre.deak@intel.com>

On Fri, 2019-11-29 at 12:38 +0200, Imre Deak wrote:
> The AUX pagetables need to be set up for blits using the vebox engine
> too, so move the related helper functions to intel_aux_pgtable.c.
> 
> Cc: Mika Kahola <mika.kahola@intel.com>
> Cc: Brian Welty <brian.welty@intel.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Imre Deak <imre.deak@intel.com>

Reviewed-by: Mika Kahola <mika.kahola@intel.com>

> ---
>  lib/intel_aux_pgtable.c | 198 ++++++++++++++++++++++++++++++++++++++
>  lib/intel_aux_pgtable.h |  23 +++++
>  lib/rendercopy_gen9.c   | 205 --------------------------------------
> --
>  3 files changed, 221 insertions(+), 205 deletions(-)
> 
> diff --git a/lib/intel_aux_pgtable.c b/lib/intel_aux_pgtable.c
> index ea909ec0..319b2745 100644
> --- a/lib/intel_aux_pgtable.c
> +++ b/lib/intel_aux_pgtable.c
> @@ -370,3 +370,201 @@ intel_aux_pgtable_create(drm_intel_bufmgr
> *bufmgr,
>  
>  	return pgt_bo;
>  }
> +
> +static void
> +aux_pgtable_find_max_free_range(const struct igt_buf **bufs, int
> buf_count,
> +				uint64_t *range_start, uint64_t
> *range_size)
> +{
> +	/*
> +	 * Keep the first page reserved, so we can differentiate pinned
> +	 * objects based on a non-NULL offset.
> +	 */
> +	uint64_t start = 0x1000;
> +	/* For now alloc only from the first 4GB address space. */
> +	const uint64_t end = 1ULL << 32;
> +	uint64_t max_range_start = 0;
> +	uint64_t max_range_size = 0;
> +	int i;
> +
> +	for (i = 0; i < buf_count; i++) {
> +		if (bufs[i]->bo->offset64 >= end)
> +			break;
> +
> +		if (bufs[i]->bo->offset64 - start > max_range_size) {
> +			max_range_start = start;
> +			max_range_size = bufs[i]->bo->offset64 - start;
> +		}
> +		start = bufs[i]->bo->offset64 + bufs[i]->bo->size;
> +	}
> +
> +	if (start < end && end - start > max_range_size) {
> +		max_range_start = start;
> +		max_range_size = end - start;
> +	}
> +
> +	*range_start = max_range_start;
> +	*range_size = max_range_size;
> +}
> +
> +static uint64_t
> +aux_pgtable_find_free_range(const struct igt_buf **bufs, int
> buf_count,
> +			    uint32_t size)
> +{
> +	uint64_t range_start;
> +	uint64_t range_size;
> +	/* A compressed surface must be 64kB aligned. */
> +	const uint32_t align = 0x10000;
> +	int pad;
> +
> +	aux_pgtable_find_max_free_range(bufs, buf_count,
> +					&range_start, &range_size);
> +
> +	pad = ALIGN(range_start, align) - range_start;
> +	range_start += pad;
> +	range_size -= pad;
> +	igt_assert(range_size >= size);
> +
> +	return range_start +
> +	       ALIGN_DOWN(rand() % ((range_size - size) + 1), align);
> +}
> +
> +static void
> +aux_pgtable_reserve_range(const struct igt_buf **bufs, int
> buf_count,
> +			  const struct igt_buf *new_buf)
> +{
> +	int i;
> +
> +	if (new_buf->aux.stride) {
> +		uint64_t pin_offset = new_buf->bo->offset64;
> +
> +		if (!pin_offset)
> +			pin_offset = aux_pgtable_find_free_range(bufs,
> +								 buf_co
> unt,
> +								 new_bu
> f->bo->size);
> +		drm_intel_bo_set_softpin_offset(new_buf->bo,
> pin_offset);
> +		igt_assert(new_buf->bo->offset64 == pin_offset);
> +	}
> +
> +	for (i = 0; i < buf_count; i++)
> +		if (bufs[i]->bo->offset64 > new_buf->bo->offset64)
> +			break;
> +
> +	memmove(&bufs[i + 1], &bufs[i], sizeof(bufs[0]) * (buf_count -
> i));
> +
> +	bufs[i] = new_buf;
> +}
> +
> +void
> +gen12_aux_pgtable_init(struct aux_pgtable_info *info,
> +		       drm_intel_bufmgr *bufmgr,
> +		       const struct igt_buf *src_buf,
> +		       const struct igt_buf *dst_buf)
> +{
> +	const struct igt_buf *bufs[2];
> +	const struct igt_buf *reserved_bufs[2];
> +	int reserved_buf_count;
> +	int i;
> +
> +	if (!src_buf->aux.stride && !dst_buf->aux.stride)
> +		return;
> +
> +	bufs[0] = src_buf;
> +	bufs[1] = dst_buf;
> +
> +	/*
> +	 * Ideally we'd need an IGT-wide GFX address space allocator,
> which
> +	 * would consider all allocations and thus avoid evictions. For
> now use
> +	 * a simpler scheme here, which only considers the buffers
> involved in
> +	 * the blit, which should at least minimize the chance for
> evictions
> +	 * in the case of subsequent blits:
> +	 *   1. If they were already bound (bo->offset64 != 0), use
> this
> +	 *      address.
> +	 *   2. Pick a range randomly from the 4GB address space, that
> is not
> +	 *      already occupied by a bound object, or an object we
> pinned.
> +	 */
> +	reserved_buf_count = 0;
> +	/* First reserve space for any bufs that are bound already. */
> +	for (i = 0; i < ARRAY_SIZE(bufs); i++)
> +		if (bufs[i]->bo->offset64)
> +			aux_pgtable_reserve_range(reserved_bufs,
> +						  reserved_buf_count++,
> +						  bufs[i]);
> +
> +	/* Next, reserve space for unbound bufs with an AUX surface. */
> +	for (i = 0; i < ARRAY_SIZE(bufs); i++)
> +		if (!bufs[i]->bo->offset64 && bufs[i]->aux.stride)
> +			aux_pgtable_reserve_range(reserved_bufs,
> +						  reserved_buf_count++,
> +						  bufs[i]);
> +
> +	/* Create AUX pgtable entries only for bufs with an AUX surface
> */
> +	info->buf_count = 0;
> +	for (i = 0; i < reserved_buf_count; i++) {
> +		if (!reserved_bufs[i]->aux.stride)
> +			continue;
> +
> +		info->bufs[info->buf_count] = reserved_bufs[i];
> +		info->buf_pin_offsets[info->buf_count] =
> +			reserved_bufs[i]->bo->offset64;
> +		info->buf_count++;
> +	}
> +
> +	info->pgtable_bo = intel_aux_pgtable_create(bufmgr,
> +						    info->bufs,
> +						    info->buf_count);
> +	igt_assert(info->pgtable_bo);
> +}
> +
> +void
> +gen12_aux_pgtable_cleanup(struct aux_pgtable_info *info)
> +{
> +	int i;
> +
> +	/* Check that the pinned bufs kept their offset after the exec.
> */
> +	for (i = 0; i < info->buf_count; i++)
> +		igt_assert_eq_u64(info->bufs[i]->bo->offset64,
> +				  info->buf_pin_offsets[i]);
> +
> +	drm_intel_bo_unreference(info->pgtable_bo);
> +}
> +
> +uint32_t
> +gen12_create_aux_pgtable_state(struct intel_batchbuffer *batch,
> +			       drm_intel_bo *aux_pgtable_bo)
> +{
> +	uint64_t *pgtable_ptr;
> +	uint32_t pgtable_ptr_offset;
> +	int ret;
> +
> +	if (!aux_pgtable_bo)
> +		return 0;
> +
> +	pgtable_ptr = intel_batchbuffer_subdata_alloc(batch,
> +						      sizeof(*pgtable_p
> tr),
> +						      sizeof(*pgtable_p
> tr));
> +	pgtable_ptr_offset = intel_batchbuffer_subdata_offset(batch,
> +							      pgtable_p
> tr);
> +
> +	*pgtable_ptr = aux_pgtable_bo->offset64;
> +	ret = drm_intel_bo_emit_reloc(batch->bo, pgtable_ptr_offset,
> +				      aux_pgtable_bo, 0,
> +				      0, 0);
> +	assert(ret == 0);
> +
> +	return pgtable_ptr_offset;
> +}
> +
> +void
> +gen12_emit_aux_pgtable_state(struct intel_batchbuffer *batch,
> uint32_t state)
> +{
> +	if (!state)
> +		return;
> +
> +	OUT_BATCH(MI_LOAD_REGISTER_MEM_GEN8);
> +	OUT_BATCH(GEN12_GFX_AUX_TABLE_BASE_ADDR);
> +	OUT_RELOC(batch->bo, 0, 0, state);
> +
> +	OUT_BATCH(MI_LOAD_REGISTER_MEM_GEN8);
> +	OUT_BATCH(GEN12_GFX_AUX_TABLE_BASE_ADDR + 4);
> +	OUT_RELOC(batch->bo, 0, 0, state + 4);
> +}
> diff --git a/lib/intel_aux_pgtable.h b/lib/intel_aux_pgtable.h
> index c0f001b4..20278db0 100644
> --- a/lib/intel_aux_pgtable.h
> +++ b/lib/intel_aux_pgtable.h
> @@ -4,9 +4,32 @@
>  #include "intel_bufmgr.h"
>  
>  struct igt_buf;
> +struct intel_batchbuffer;
> +
> +struct aux_pgtable_info {
> +	int buf_count;
> +	const struct igt_buf *bufs[2];
> +	uint64_t buf_pin_offsets[2];
> +	drm_intel_bo *pgtable_bo;
> +};
>  
>  drm_intel_bo *
>  intel_aux_pgtable_create(drm_intel_bufmgr *bufmgr,
>  			 const struct igt_buf **bufs, int buf_count);
>  
> +void
> +gen12_aux_pgtable_init(struct aux_pgtable_info *info,
> +		       drm_intel_bufmgr *bufmgr,
> +		       const struct igt_buf *src_buf,
> +		       const struct igt_buf *dst_buf);
> +
> +void
> +gen12_aux_pgtable_cleanup(struct aux_pgtable_info *info);
> +
> +uint32_t
> +gen12_create_aux_pgtable_state(struct intel_batchbuffer *batch,
> +			       drm_intel_bo *aux_pgtable_bo);
> +void
> +gen12_emit_aux_pgtable_state(struct intel_batchbuffer *batch,
> uint32_t state);
> +
>  #endif
> diff --git a/lib/rendercopy_gen9.c b/lib/rendercopy_gen9.c
> index 3189594f..94e816b6 100644
> --- a/lib/rendercopy_gen9.c
> +++ b/lib/rendercopy_gen9.c
> @@ -973,211 +973,6 @@ static void gen8_emit_primitive(struct
> intel_batchbuffer *batch, uint32_t offset
>  
>  #define BATCH_STATE_SPLIT 2048
>  
> -static void
> -aux_pgtable_find_max_free_range(const struct igt_buf **bufs, int
> buf_count,
> -				uint64_t *range_start, uint64_t
> *range_size)
> -{
> -	/*
> -	 * Keep the first page reserved, so we can differentiate pinned
> -	 * objects based on a non-NULL offset.
> -	 */
> -	uint64_t start = 0x1000;
> -	/* For now alloc only from the first 4GB address space. */
> -	const uint64_t end = 1ULL << 32;
> -	uint64_t max_range_start = 0;
> -	uint64_t max_range_size = 0;
> -	int i;
> -
> -	for (i = 0; i < buf_count; i++) {
> -		if (bufs[i]->bo->offset64 >= end)
> -			break;
> -
> -		if (bufs[i]->bo->offset64 - start > max_range_size) {
> -			max_range_start = start;
> -			max_range_size = bufs[i]->bo->offset64 - start;
> -		}
> -		start = bufs[i]->bo->offset64 + bufs[i]->bo->size;
> -	}
> -
> -	if (start < end && end - start > max_range_size) {
> -		max_range_start = start;
> -		max_range_size = end - start;
> -	}
> -
> -	*range_start = max_range_start;
> -	*range_size = max_range_size;
> -}
> -
> -static uint64_t
> -aux_pgtable_find_free_range(const struct igt_buf **bufs, int
> buf_count,
> -			    uint32_t size)
> -{
> -	uint64_t range_start;
> -	uint64_t range_size;
> -	/* A compressed surface must be 64kB aligned. */
> -	const uint32_t align = 0x10000;
> -	int pad;
> -
> -	aux_pgtable_find_max_free_range(bufs, buf_count,
> -					&range_start, &range_size);
> -
> -	pad = ALIGN(range_start, align) - range_start;
> -	range_start += pad;
> -	range_size -= pad;
> -	igt_assert(range_size >= size);
> -
> -	return range_start +
> -	       ALIGN_DOWN(rand() % ((range_size - size) + 1), align);
> -}
> -
> -static void
> -aux_pgtable_reserve_range(const struct igt_buf **bufs, int
> buf_count,
> -			  const struct igt_buf *new_buf)
> -{
> -	int i;
> -
> -	if (new_buf->aux.stride) {
> -		uint64_t pin_offset = new_buf->bo->offset64;
> -
> -		if (!pin_offset)
> -			pin_offset = aux_pgtable_find_free_range(bufs,
> -								 buf_co
> unt,
> -								 new_bu
> f->bo->size);
> -		drm_intel_bo_set_softpin_offset(new_buf->bo,
> pin_offset);
> -		igt_assert(new_buf->bo->offset64 == pin_offset);
> -	}
> -
> -	for (i = 0; i < buf_count; i++)
> -		if (bufs[i]->bo->offset64 > new_buf->bo->offset64)
> -			break;
> -
> -	memmove(&bufs[i + 1], &bufs[i], sizeof(bufs[0]) * (buf_count -
> i));
> -
> -	bufs[i] = new_buf;
> -}
> -
> -struct aux_pgtable_info {
> -	int buf_count;
> -	const struct igt_buf *bufs[2];
> -	uint64_t buf_pin_offsets[2];
> -	drm_intel_bo *pgtable_bo;
> -};
> -
> -static void
> -gen12_aux_pgtable_init(struct aux_pgtable_info *info,
> -		       drm_intel_bufmgr *bufmgr,
> -		       const struct igt_buf *src_buf,
> -		       const struct igt_buf *dst_buf)
> -{
> -	const struct igt_buf *bufs[2];
> -	const struct igt_buf *reserved_bufs[2];
> -	int reserved_buf_count;
> -	int i;
> -
> -	if (!src_buf->aux.stride && !dst_buf->aux.stride)
> -		return;
> -
> -	bufs[0] = src_buf;
> -	bufs[1] = dst_buf;
> -
> -	/*
> -	 * Ideally we'd need an IGT-wide GFX address space allocator,
> which
> -	 * would consider all allocations and thus avoid evictions. For
> now use
> -	 * a simpler scheme here, which only considers the buffers
> involved in
> -	 * the blit, which should at least minimize the chance for
> evictions
> -	 * in the case of subsequent blits:
> -	 *   1. If they were already bound (bo->offset64 != 0), use
> this
> -	 *      address.
> -	 *   2. Pick a range randomly from the 4GB address space, that
> is not
> -	 *      already occupied by a bound object, or an object we
> pinned.
> -	 */
> -	reserved_buf_count = 0;
> -	/* First reserve space for any bufs that are bound already. */
> -	for (i = 0; i < ARRAY_SIZE(bufs); i++)
> -		if (bufs[i]->bo->offset64)
> -			aux_pgtable_reserve_range(reserved_bufs,
> -						  reserved_buf_count++,
> -						  bufs[i]);
> -
> -	/* Next, reserve space for unbound bufs with an AUX surface. */
> -	for (i = 0; i < ARRAY_SIZE(bufs); i++)
> -		if (!bufs[i]->bo->offset64 && bufs[i]->aux.stride)
> -			aux_pgtable_reserve_range(reserved_bufs,
> -						  reserved_buf_count++,
> -						  bufs[i]);
> -
> -	/* Create AUX pgtable entries only for bufs with an AUX surface
> */
> -	info->buf_count = 0;
> -	for (i = 0; i < reserved_buf_count; i++) {
> -		if (!reserved_bufs[i]->aux.stride)
> -			continue;
> -
> -		info->bufs[info->buf_count] = reserved_bufs[i];
> -		info->buf_pin_offsets[info->buf_count] =
> -			reserved_bufs[i]->bo->offset64;
> -		info->buf_count++;
> -	}
> -
> -	info->pgtable_bo = intel_aux_pgtable_create(bufmgr,
> -						    info->bufs,
> -						    info->buf_count);
> -	igt_assert(info->pgtable_bo);
> -}
> -
> -static void
> -gen12_aux_pgtable_cleanup(struct aux_pgtable_info *info)
> -{
> -	int i;
> -
> -	/* Check that the pinned bufs kept their offset after the exec.
> */
> -	for (i = 0; i < info->buf_count; i++)
> -		igt_assert_eq_u64(info->bufs[i]->bo->offset64,
> -				  info->buf_pin_offsets[i]);
> -
> -	drm_intel_bo_unreference(info->pgtable_bo);
> -}
> -
> -static uint32_t
> -gen12_create_aux_pgtable_state(struct intel_batchbuffer *batch,
> -			       drm_intel_bo *aux_pgtable_bo)
> -{
> -	uint64_t *pgtable_ptr;
> -	uint32_t pgtable_ptr_offset;
> -	int ret;
> -
> -	if (!aux_pgtable_bo)
> -		return 0;
> -
> -	pgtable_ptr = intel_batchbuffer_subdata_alloc(batch,
> -						      sizeof(*pgtable_p
> tr),
> -						      sizeof(*pgtable_p
> tr));
> -	pgtable_ptr_offset = intel_batchbuffer_subdata_offset(batch,
> -							      pgtable_p
> tr);
> -
> -	*pgtable_ptr = aux_pgtable_bo->offset64;
> -	ret = drm_intel_bo_emit_reloc(batch->bo, pgtable_ptr_offset,
> -				      aux_pgtable_bo, 0,
> -				      0, 0);
> -	assert(ret == 0);
> -
> -	return pgtable_ptr_offset;
> -}
> -
> -static void
> -gen12_emit_aux_pgtable_state(struct intel_batchbuffer *batch,
> uint32_t state)
> -{
> -	if (!state)
> -		return;
> -
> -	OUT_BATCH(MI_LOAD_REGISTER_MEM_GEN8);
> -	OUT_BATCH(GEN12_GFX_AUX_TABLE_BASE_ADDR);
> -	OUT_RELOC(batch->bo, 0, 0, state);
> -
> -	OUT_BATCH(MI_LOAD_REGISTER_MEM_GEN8);
> -	OUT_BATCH(GEN12_GFX_AUX_TABLE_BASE_ADDR + 4);
> -	OUT_RELOC(batch->bo, 0, 0, state + 4);
> -}
> -
>  static
>  void _gen9_render_copyfunc(struct intel_batchbuffer *batch,
>  			  drm_intel_context *context,
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2019-12-03 14:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-29 10:38 [igt-dev] [PATCH i-g-t 0/6] lib: Add tests validating media compressed surfaces Imre Deak
2019-11-29 10:38 ` [igt-dev] [PATCH i-g-t 1/6] tests/gem_render_copy: Make subtest parameters more explicit Imre Deak
2019-12-03 11:52   ` Kahola, Mika
2019-11-29 10:38 ` [igt-dev] [PATCH i-g-t 2/6] tests/gem_render_copy: Separate out mixed tiled ccs subtests Imre Deak
2019-12-03 14:31   ` Kahola, Mika
2019-11-29 10:38 ` [igt-dev] [PATCH i-g-t 3/6] lib: Move aux pgtable state prepare/emit to intel_aux_pgtable.c Imre Deak
2019-12-03 14:50   ` Kahola, Mika [this message]
2019-11-29 10:38 ` [igt-dev] [PATCH i-g-t 4/6] lib/intel_aux_pgtable: Set MMIO remap for write the AUX pagedir reg Imre Deak
2019-12-04 12:35   ` Kahola, Mika
2019-11-29 10:38 ` [igt-dev] [PATCH i-g-t 5/6] lib: Add vebox copy support Imre Deak
2019-12-04 13:09   ` Kahola, Mika
2019-12-04 13:49   ` [igt-dev] [PATCH v2 " Imre Deak
2019-12-05 10:30     ` Kahola, Mika
2019-12-05  3:30   ` [igt-dev] [PATCH i-g-t " Bai, Guangyao
2019-12-05 13:49     ` Imre Deak
2019-11-29 10:38 ` [igt-dev] [PATCH i-g-t 6/6] tests/gem_render_copy: Add media compression subtests Imre Deak
2019-12-04 13:50   ` [igt-dev] [PATCH v2 " Imre Deak
2019-12-05 11:28     ` Kahola, Mika
2019-11-29 11:19 ` [igt-dev] ✓ Fi.CI.BAT: success for lib: Add tests validating media compressed surfaces Patchwork
2019-11-30  6:06 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2019-12-04 15:19 ` [igt-dev] ✗ Fi.CI.BAT: failure for lib: Add tests validating media compressed surfaces (rev3) Patchwork
2019-12-04 15:59   ` Imre Deak
2019-12-09  8:36     ` Imre Deak
2019-12-09  9:55       ` Vudum, Lakshminarayana
2019-12-09  9:40 ` [igt-dev] ✓ Fi.CI.BAT: success " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42aaccd6deb6b5411ea83e42e6f8aa3f262091ac.camel@intel.com \
    --to=mika.kahola@intel.com \
    --cc=brian.welty@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=imre.deak@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.