Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed testOtherH264ImageReader case failure #100

Open
wants to merge 1 commit into
base: celadon/s/mr0/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct vma {
uint32_t map_flags;
int32_t refcount;
uint32_t map_strides[DRV_MAX_PLANES];
bool cpu; /* true if the space is allocated by cpu (e.g. malloc) */
void *priv;
};

Expand Down
41 changes: 41 additions & 0 deletions helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ void *drv_dumb_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t map

int drv_bo_munmap(struct bo *bo, struct vma *vma)
{
if (vma->cpu) {
free(vma->addr);
vma->addr = NULL;
}
return munmap(vma->addr, vma->length);
}

Expand Down Expand Up @@ -651,3 +655,40 @@ bool drv_has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier)

return false;
}

const u_int16_t ytile_width = 16;
const u_int16_t ytile_heigth = 32;
void one_ytile_to_linear(char *src, char *dst, u_int16_t x, u_int16_t y, u_int16_t width, u_int16_t height, u_int16_t offset)
{
// x and y follow linear
u_int32_t count = x + y * width/ytile_width;

for (int j = 0; j < ytile_width * ytile_heigth; j += ytile_width) {
memcpy(dst + offset + width * ytile_heigth * y + width * j / ytile_width + x * ytile_width,
src + offset + j + ytile_width * ytile_heigth * count, ytile_width);
}
}

void * ytiled_to_linear(struct bo_metadata meta, void * src)
{
void* dst = malloc(meta.total_size);
if (NULL == dst) return NULL;

memset(dst, 0, meta.total_size);

u_int16_t height = meta.sizes[0] / meta.strides[0];
// Y
for (u_int16_t x = 0; x < meta.strides[0]/ytile_width; x++) {
for (u_int16_t y = 0; y < height/ytile_heigth; y++) {
one_ytile_to_linear(src, dst, x, y, meta.strides[0], height, 0);
}
}
// UV
for (u_int16_t x = 0; x < meta.strides[0]/ytile_width; x++) {
for (u_int16_t y = 0; y < ceil((double)height/ytile_heigth/2); y++) {
one_ytile_to_linear(src, dst, x, y, meta.strides[0], height, meta.sizes[0]);
}
}

return dst;
}
5 changes: 5 additions & 0 deletions helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef HELPERS_H
#define HELPERS_H

#include <math.h>
#include <stdbool.h>

#include "drv.h"
Expand Down Expand Up @@ -42,4 +43,8 @@ int drv_modify_linear_combinations(struct driver *drv);
uint64_t drv_pick_modifier(const uint64_t *modifiers, uint32_t count,
const uint64_t *modifier_order, uint32_t order_count);
bool drv_has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier);

void one_ytile_to_linear(char *src, char *dst, u_int16_t x, u_int16_t y,
u_int16_t width, u_int16_t height, u_int16_t offset);
void *ytiled_to_linear(struct bo_metadata meta, void * src);
#endif
13 changes: 13 additions & 0 deletions i915.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,19 @@ static void *i915_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t
/* And map it */
addr = mmap(0, bo->meta.total_size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
mmap_arg.offset);

// TODO: GEM_MMAP_OFFSET cannot convert ytiled to linear, we have to convert it manually.
// Other formats(e.g. I915_TILING_X) should also be converted.
if (bo->meta.tiling == I915_TILING_Y) {
void* tmp_addr = ytiled_to_linear(bo->meta, addr);

if (NULL != tmp_addr) {
// release original one and replace it with a linear address.
munmap(addr, bo->meta.total_size);
addr = tmp_addr;
vma->cpu = true;
}
}
} else if (bo->meta.tiling == I915_TILING_NONE) {
struct drm_i915_gem_mmap gem_map;
memset(&gem_map, 0, sizeof(gem_map));
Expand Down
Loading