vc4: Make a helper function for getting the current offset in the CL.

I needed to rewrite this a bit for safety checking in the next commit.
Despite being a static inline of the same thing that was being done, we
lose 36 bytes of code for some reason.
This commit is contained in:
Eric Anholt 2015-07-10 14:46:42 -07:00
parent 748bf459b4
commit a0d3915663
4 changed files with 21 additions and 20 deletions

View File

@ -36,11 +36,12 @@ vc4_init_cl(struct vc4_context *vc4, struct vc4_cl *cl)
void
cl_ensure_space(struct vc4_cl *cl, uint32_t space)
{
if ((cl->next - cl->base) + space <= cl->size)
uint32_t offset = cl_offset(cl);
if (offset + space <= cl->size)
return;
uint32_t size = MAX2(cl->size + space, cl->size * 2);
uint32_t offset = cl->next -cl->base;
cl->base = reralloc(ralloc_parent(cl->base), cl->base, uint8_t, size);
cl->size = size;
@ -60,9 +61,7 @@ vc4_gem_hindex(struct vc4_context *vc4, struct vc4_bo *bo)
uint32_t hindex;
uint32_t *current_handles = vc4->bo_handles.base;
for (hindex = 0;
hindex < (vc4->bo_handles.next - vc4->bo_handles.base) / 4;
hindex++) {
for (hindex = 0; hindex < cl_offset(&vc4->bo_handles) / 4; hindex++) {
if (current_handles[hindex] == bo->handle)
return hindex;
}

View File

@ -49,6 +49,11 @@ uint32_t vc4_gem_hindex(struct vc4_context *vc4, struct vc4_bo *bo);
struct PACKED unaligned_16 { uint16_t x; };
struct PACKED unaligned_32 { uint32_t x; };
static inline uint32_t cl_offset(struct vc4_cl *cl)
{
return (char *)cl->next - (char *)cl->base;
}
static inline void
put_unaligned_32(void *ptr, uint32_t val)
{
@ -66,7 +71,7 @@ put_unaligned_16(void *ptr, uint16_t val)
static inline void
cl_u8(struct vc4_cl *cl, uint8_t n)
{
assert((cl->next - cl->base) + 1 <= cl->size);
assert(cl_offset(cl) + 1 <= cl->size);
*(uint8_t *)cl->next = n;
cl->next++;
@ -75,7 +80,7 @@ cl_u8(struct vc4_cl *cl, uint8_t n)
static inline void
cl_u16(struct vc4_cl *cl, uint16_t n)
{
assert((cl->next - cl->base) + 2 <= cl->size);
assert(cl_offset(cl) + 2 <= cl->size);
put_unaligned_16(cl->next, n);
cl->next += 2;
@ -84,7 +89,7 @@ cl_u16(struct vc4_cl *cl, uint16_t n)
static inline void
cl_u32(struct vc4_cl *cl, uint32_t n)
{
assert((cl->next - cl->base) + 4 <= cl->size);
assert(cl_offset(cl) + 4 <= cl->size);
put_unaligned_32(cl->next, n);
cl->next += 4;
@ -93,7 +98,7 @@ cl_u32(struct vc4_cl *cl, uint32_t n)
static inline void
cl_aligned_u32(struct vc4_cl *cl, uint32_t n)
{
assert((cl->next - cl->base) + 4 <= cl->size);
assert(cl_offset(cl) + 4 <= cl->size);
*(uint32_t *)cl->next = n;
cl->next += 4;
@ -102,7 +107,7 @@ cl_aligned_u32(struct vc4_cl *cl, uint32_t n)
static inline void
cl_ptr(struct vc4_cl *cl, void *ptr)
{
assert((cl->next - cl->base) + sizeof(void *) <= cl->size);
assert(cl_offset(cl) + sizeof(void *) <= cl->size);
*(void **)cl->next = ptr;
cl->next += sizeof(void *);

View File

@ -128,8 +128,7 @@ vc4_cl_references_bo(struct pipe_context *pctx, struct vc4_bo *bo)
* they match.
*/
struct vc4_bo **referenced_bos = vc4->bo_pointers.base;
for (int i = 0; i < (vc4->bo_handles.next -
vc4->bo_handles.base) / 4; i++) {
for (int i = 0; i < cl_offset(&vc4->bo_handles) / 4; i++) {
if (referenced_bos[i] == bo) {
return true;
}

View File

@ -44,8 +44,7 @@ void
vc4_job_reset(struct vc4_context *vc4)
{
struct vc4_bo **referenced_bos = vc4->bo_pointers.base;
for (int i = 0; i < (vc4->bo_handles.next -
vc4->bo_handles.base) / 4; i++) {
for (int i = 0; i < cl_offset(&vc4->bo_handles) / 4; i++) {
vc4_bo_unreference(&referenced_bos[i]);
}
vc4_reset_cl(&vc4->bcl);
@ -145,7 +144,7 @@ vc4_job_submit(struct vc4_context *vc4)
{
if (vc4_debug & VC4_DEBUG_CL) {
fprintf(stderr, "BCL:\n");
vc4_dump_cl(vc4->bcl.base, vc4->bcl.next - vc4->bcl.base, false);
vc4_dump_cl(vc4->bcl.base, cl_offset(&vc4->bcl), false);
}
struct drm_vc4_submit_cl submit;
@ -164,15 +163,14 @@ vc4_job_submit(struct vc4_context *vc4)
vc4->zs_write, true, true);
submit.bo_handles = (uintptr_t)vc4->bo_handles.base;
submit.bo_handle_count = (vc4->bo_handles.next -
vc4->bo_handles.base) / 4;
submit.bo_handle_count = cl_offset(&vc4->bo_handles) / 4;
submit.bin_cl = (uintptr_t)vc4->bcl.base;
submit.bin_cl_size = vc4->bcl.next - vc4->bcl.base;
submit.bin_cl_size = cl_offset(&vc4->bcl);
submit.shader_rec = (uintptr_t)vc4->shader_rec.base;
submit.shader_rec_size = vc4->shader_rec.next - vc4->shader_rec.base;
submit.shader_rec_size = cl_offset(&vc4->shader_rec);
submit.shader_rec_count = vc4->shader_rec_count;
submit.uniforms = (uintptr_t)vc4->uniforms.base;
submit.uniforms_size = vc4->uniforms.next - vc4->uniforms.base;
submit.uniforms_size = cl_offset(&vc4->uniforms);
assert(vc4->draw_min_x != ~0 && vc4->draw_min_y != ~0);
submit.min_x_tile = vc4->draw_min_x / 64;