Skip to content

Commit

Permalink
[Decode] Add set fences and get fence implement in i915 drm
Browse files Browse the repository at this point in the history
Signed-off-by: Xu, Zhengguo <[email protected]>
  • Loading branch information
Jexu committed May 27, 2024
1 parent 8a1f79c commit 8e00fd6
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ struct mos_drm_uc_version {

struct mos_exec_fences
{
#define FENCES_MAX 10
int32_t *fences;
int32_t count;
};
Expand Down
3 changes: 3 additions & 0 deletions media_softlet/linux/common/os/i915/include/mos_bufmgr_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ struct mos_bufmgr {
uint8_t (*switch_off_n_bits)(struct mos_linux_context *ctx, uint8_t in_mask, int n) = nullptr;
unsigned int (*hweight8)(struct mos_linux_context *ctx, uint8_t w) = nullptr;

int (*set_fences)(struct mos_bufmgr *bufmgr, struct mos_exec_fences *exec_fences) = nullptr;
int (*get_fence)(struct mos_bufmgr *bufmgr, int32_t *fence_out) = nullptr;

/**< Enables verbose debugging printouts */
int debug = 0;
uint32_t *get_reserved = nullptr;
Expand Down
59 changes: 59 additions & 0 deletions media_softlet/linux/common/os/i915/mos_bufmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ struct mos_bufmgr_gem {
int exec_size;
int exec_count;

struct mos_exec_fences exec_fences;

/** Array of lists of cached gem objects of power-of-two sizes */
struct mos_gem_bo_bucket cache_bucket[64];
int num_buckets;
Expand Down Expand Up @@ -5221,6 +5223,61 @@ mos_bufmgr_enable_turbo_boost(struct mos_bufmgr *bufmgr)
DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &ctxParam );
}

int
mos_bufmgr_set_fences(struct mos_bufmgr *bufmgr, struct mos_exec_fences *exec_fences)
{
if (!bufmgr || !exec_fences || exec_fences->count > FENCES_MAX)
{
return -EINVAL;
}

struct mos_bufmgr_gem *bufmgr_gem = (struct mos_bufmgr_gem *)bufmgr;

if (bufmgr_gem->exec_fences.fences == nullptr)
{
//fences[0] reserved for fence out
bufmgr_gem->exec_fences.fences = (int32_t *)malloc((FENCES_MAX + 1) * sizeof(int32_t));

if (bufmgr_gem->exec_fences.fences == nullptr)
{
return -ENOMEM;
}

bufmgr_gem->exec_fences.count = 0;
}

if (exec_fences->count > 0)
{
memcpy(bufmgr_gem->exec_fences.fences, exec_fences->fences, (exec_fences->count + 1) * sizeof(int32_t));
bufmgr_gem->exec_fences.fences[0] = 0;
bufmgr_gem->exec_fences.count = exec_fences->count;
}

return 0;
}

int
mos_bufmgr_get_fence(struct mos_bufmgr *bufmgr, int32_t *fence_out)
{
if (!bufmgr || !fence_out)
{
return -EINVAL;
}

struct mos_bufmgr_gem *bufmgr_gem = (struct mos_bufmgr_gem *)bufmgr;

if (bufmgr_gem->exec_fences.fences)
{
*fence_out = bufmgr_gem->exec_fences.fences[0];
}
else
{
*fence_out = 0;
}

return 0;
}

/**
* Initializes the GEM buffer manager, which uses the kernel to allocate, map,
* and manage map buffer objections.
Expand Down Expand Up @@ -5333,6 +5390,8 @@ mos_bufmgr_gem_init_i915(int fd, int batch_size)
bufmgr_gem->bufmgr.get_ts_frequency = mos_bufmgr_get_ts_frequency;
bufmgr_gem->bufmgr.has_bsd2 = mos_bufmgr_has_bsd2;
bufmgr_gem->bufmgr.enable_turbo_boost = mos_bufmgr_enable_turbo_boost;
bufmgr_gem->bufmgr.set_fences = mos_bufmgr_set_fences;
bufmgr_gem->bufmgr.get_fence = mos_bufmgr_get_fence;

bufmgr_gem->mem_profiler_path = getenv("MEDIA_MEMORY_PROFILER_LOG");
if (bufmgr_gem->mem_profiler_path != nullptr)
Expand Down
38 changes: 18 additions & 20 deletions media_softlet/linux/common/os/i915/mos_bufmgr_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,16 +1232,15 @@ mos_set_fences(struct mos_bufmgr *bufmgr, struct mos_exec_fences *exec_fences)
return -EINVAL;
}

return 0;
//todo: add func pointer to bufmgr
//if (bufmgr->set_fences)
//{
// return bufmgr->set_fences(bufmgr, exec_fences);
//}
//else
//{
// MOS_OS_CRITICALMESSAGE("Unsupported\n");
//}
if (bufmgr->set_fences)
{
return bufmgr->set_fences(bufmgr, exec_fences);
}
else
{
MOS_OS_CRITICALMESSAGE("Unsupported\n");
return -EPERM;
}

}

Expand All @@ -1254,16 +1253,15 @@ mos_get_fence(struct mos_bufmgr *bufmgr, int32_t *fence_out)
return -EINVAL;
}

return 0;
//todo: add func pointer to bufmgr
//if (bufmgr->get_fence)
//{
// return bufmgr->get_fence(bufmgr, fence_out);
//}
//else
//{
// MOS_OS_CRITICALMESSAGE("Unsupported\n");
//}
if (bufmgr->get_fence)
{
return bufmgr->get_fence(bufmgr, fence_out);
}
else
{
MOS_OS_CRITICALMESSAGE("Unsupported\n");
return -EPERM;
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ struct mos_bufmgr {
uint8_t (*switch_off_n_bits)(struct mos_linux_context *ctx, uint8_t in_mask, int n) = nullptr;
unsigned int (*hweight8)(struct mos_linux_context *ctx, uint8_t w) = nullptr;

int (*set_fences)(struct mos_bufmgr *bufmgr, struct mos_exec_fences *exec_fences) = nullptr;
int (*get_fence)(struct mos_bufmgr *bufmgr, int32_t *fence_out) = nullptr;

/**< Enables verbose debugging printouts */
int debug = 0;
/** used for reserved info*/
Expand Down

0 comments on commit 8e00fd6

Please sign in to comment.