Commit fe7cc8d5 authored by Vasily Khoruzhick's avatar Vasily Khoruzhick
Browse files

lima: use plain BOs for gl_pos and varyings



Suballocator doesn't really fit here since it can't resize backing BO.

Fixes crash in glmark2-es2-drm -b refract
Signed-off-by: Vasily Khoruzhick's avatarVasily Khoruzhick <anarsoul@gmail.com>
parent c45c889f
Pipeline #30910 passed with stages
in 9 minutes and 19 seconds
......@@ -29,7 +29,6 @@
#include "util/u_debug.h"
#include "util/ralloc.h"
#include "util/u_inlines.h"
#include "util/u_suballoc.h"
#include "util/hash_table.h"
#include "lima_screen.h"
......@@ -70,19 +69,15 @@ lima_ctx_buff_map(struct lima_context *ctx, enum lima_ctx_buff buff)
void *
lima_ctx_buff_alloc(struct lima_context *ctx, enum lima_ctx_buff buff,
unsigned size, bool uploader)
unsigned size)
{
struct lima_ctx_buff_state *cbs = ctx->buffer_state + buff;
void *ret = NULL;
cbs->size = align(size, 0x40);
if (uploader)
u_upload_alloc(ctx->uploader, 0, cbs->size, 0x40, &cbs->offset,
&cbs->res, &ret);
else
u_suballocator_alloc(ctx->suballocator, cbs->size, 0x10,
&cbs->offset, &cbs->res);
u_upload_alloc(ctx->uploader, 0, cbs->size, 0x40, &cbs->offset,
&cbs->res, &ret);
return ret;
}
......@@ -128,9 +123,6 @@ lima_context_destroy(struct pipe_context *pctx)
if (ctx->blitter)
util_blitter_destroy(ctx->blitter);
if (ctx->suballocator)
u_suballocator_destroy(ctx->suballocator);
if (ctx->uploader)
u_upload_destroy(ctx->uploader);
......@@ -141,6 +133,10 @@ lima_context_destroy(struct pipe_context *pctx)
lima_bo_free(ctx->plb[i]);
if (ctx->gp_tile_heap[i])
lima_bo_free(ctx->gp_tile_heap[i]);
if (ctx->gl_pos[i])
lima_bo_free(ctx->gl_pos[i]);
if (ctx->varyings[i])
lima_bo_free(ctx->varyings[i]);
}
if (ctx->plb_gp_stream)
......@@ -204,13 +200,6 @@ lima_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
ctx->base.stream_uploader = ctx->uploader;
ctx->base.const_uploader = ctx->uploader;
/* for varying output which need not mmap */
ctx->suballocator =
u_suballocator_create(&ctx->base, 1024 * 1024, 0,
PIPE_USAGE_STREAM, 0, false);
if (!ctx->suballocator)
goto err_out;
util_dynarray_init(&ctx->vs_cmd_array, ctx);
util_dynarray_init(&ctx->plbu_cmd_array, ctx);
......@@ -228,6 +217,12 @@ lima_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
ctx->gp_tile_heap[i] = lima_bo_create(screen, gp_tile_heap_size, 0);
if (!ctx->gp_tile_heap[i])
goto err_out;
ctx->gl_pos[i] = lima_bo_create(screen, 1024 * 1024, 0);
if (!ctx->gl_pos[i])
goto err_out;
ctx->varyings[i] = lima_bo_create(screen, 1024 * 1024, 0);
if (!ctx->varyings[i])
goto err_out;
}
unsigned plb_gp_stream_size =
......
......@@ -118,8 +118,6 @@ struct lima_context_constant_buffer {
};
enum lima_ctx_buff {
lima_ctx_buff_sh_varying,
lima_ctx_buff_sh_gl_pos,
lima_ctx_buff_gp_varying_info,
lima_ctx_buff_gp_attribute_info,
lima_ctx_buff_gp_uniform,
......@@ -192,7 +190,6 @@ struct lima_context {
} dirty;
struct u_upload_mgr *uploader;
struct u_suballocator *suballocator;
struct blitter_context *blitter;
struct slab_child_pool transfer_pool;
......@@ -228,6 +225,8 @@ struct lima_context {
struct lima_bo *plb[LIMA_CTX_PLB_MAX_NUM];
struct lima_bo *gp_tile_heap[LIMA_CTX_PLB_MAX_NUM];
struct lima_bo *gl_pos[LIMA_CTX_PLB_MAX_NUM];
struct lima_bo *varyings[LIMA_CTX_PLB_MAX_NUM];
#define gp_tile_heap_size 0x100000
struct lima_bo *plb_gp_stream;
......@@ -278,7 +277,7 @@ uint32_t lima_ctx_buff_va(struct lima_context *ctx, enum lima_ctx_buff buff,
unsigned submit);
void *lima_ctx_buff_map(struct lima_context *ctx, enum lima_ctx_buff buff);
void *lima_ctx_buff_alloc(struct lima_context *ctx, enum lima_ctx_buff buff,
unsigned size, bool uploader);
unsigned size);
void lima_state_init(struct lima_context *ctx);
void lima_state_fini(struct lima_context *ctx);
......
......@@ -664,6 +664,10 @@ lima_update_submit_bo(struct lima_context *ctx)
lima_submit_add_bo(ctx->gp_submit, ctx->plb_gp_stream, LIMA_SUBMIT_BO_READ);
lima_submit_add_bo(ctx->gp_submit, ctx->plb[ctx->plb_index], LIMA_SUBMIT_BO_WRITE);
lima_submit_add_bo(ctx->gp_submit, ctx->gp_tile_heap[ctx->plb_index], LIMA_SUBMIT_BO_WRITE);
lima_submit_add_bo(ctx->gp_submit, ctx->gl_pos[ctx->plb_index], LIMA_SUBMIT_BO_WRITE);
if (ctx->vs && ctx->vs->num_varying > 1)
lima_submit_add_bo(ctx->gp_submit, ctx->varyings[ctx->plb_index], LIMA_SUBMIT_BO_WRITE);
lima_dump_command_stream_print(
ctx->plb_gp_stream->map + ctx->plb_index * ctx->plb_gp_size,
......@@ -687,6 +691,9 @@ lima_update_submit_bo(struct lima_context *ctx)
}
lima_submit_add_bo(ctx->pp_submit, ctx->plb[ctx->plb_index], LIMA_SUBMIT_BO_READ);
lima_submit_add_bo(ctx->pp_submit, ctx->gp_tile_heap[ctx->plb_index], LIMA_SUBMIT_BO_READ);
lima_submit_add_bo(ctx->pp_submit, ctx->gl_pos[ctx->plb_index], LIMA_SUBMIT_BO_READ);
if (ctx->vs && ctx->vs->num_varying > 1)
lima_submit_add_bo(ctx->pp_submit, ctx->varyings[ctx->plb_index], LIMA_SUBMIT_BO_READ);
lima_submit_add_bo(ctx->pp_submit, screen->pp_buffer, LIMA_SUBMIT_BO_READ);
}
......@@ -875,9 +882,7 @@ lima_pack_plbu_cmd(struct lima_context *ctx, const struct pipe_draw_info *info)
}
PLBU_CMD_PRIMITIVE_SETUP(low_prim, cull, info->index_size);
uint32_t gl_position_va =
lima_ctx_buff_va(ctx, lima_ctx_buff_sh_gl_pos,
LIMA_CTX_BUFF_SUBMIT_GP | LIMA_CTX_BUFF_SUBMIT_PP);
uint32_t gl_position_va = ctx->gl_pos[ctx->plb_index]->va;
PLBU_CMD_RSW_VERTEX_ARRAY(
lima_ctx_buff_va(ctx, lima_ctx_buff_pp_plb_rsw, LIMA_CTX_BUFF_SUBMIT_PP),
gl_position_va);
......@@ -1064,7 +1069,7 @@ lima_pack_render_state(struct lima_context *ctx, const struct pipe_draw_info *in
{
struct lima_render_state *render =
lima_ctx_buff_alloc(ctx, lima_ctx_buff_pp_plb_rsw,
sizeof(*render), true);
sizeof(*render));
/* do hw support RGBA independ blend?
* PIPE_CAP_INDEP_BLEND_ENABLE
......@@ -1168,8 +1173,7 @@ lima_pack_render_state(struct lima_context *ctx, const struct pipe_draw_info *in
if (ctx->vs->num_varying > 1) {
render->varying_types = 0x00000000;
render->varyings_address =
lima_ctx_buff_va(ctx, lima_ctx_buff_sh_varying, LIMA_CTX_BUFF_SUBMIT_PP);
render->varyings_address = ctx->varyings[ctx->plb_index]->va;
for (int i = 1; i < ctx->vs->num_varying; i++) {
int val;
......@@ -1208,7 +1212,7 @@ lima_update_gp_attribute_info(struct lima_context *ctx, const struct pipe_draw_i
uint32_t *attribute =
lima_ctx_buff_alloc(ctx, lima_ctx_buff_gp_attribute_info,
ve->num_elements * 8, true);
ve->num_elements * 8);
int n = 0;
for (int i = 0; i < ve->num_elements; i++) {
......@@ -1244,7 +1248,7 @@ lima_update_gp_uniform(struct lima_context *ctx)
int size = vs->uniform_pending_offset + vs->constant_size + 32;
void *vs_const_buff =
lima_ctx_buff_alloc(ctx, lima_ctx_buff_gp_uniform, size, true);
lima_ctx_buff_alloc(ctx, lima_ctx_buff_gp_uniform, size);
if (ccb->buffer)
memcpy(vs_const_buff, ccb->buffer, ccb->size);
......@@ -1277,10 +1281,10 @@ lima_update_pp_uniform(struct lima_context *ctx)
uint16_t *fp16_const_buff =
lima_ctx_buff_alloc(ctx, lima_ctx_buff_pp_uniform,
const_buff_size * sizeof(uint16_t), true);
const_buff_size * sizeof(uint16_t));
uint32_t *array =
lima_ctx_buff_alloc(ctx, lima_ctx_buff_pp_uniform_array, 4, true);
lima_ctx_buff_alloc(ctx, lima_ctx_buff_pp_uniform_array, 4);
for (int i = 0; i < const_buff_size; i++)
fp16_const_buff[i] = util_float_to_half(const_buff[i]);
......@@ -1302,18 +1306,22 @@ lima_update_varying(struct lima_context *ctx, const struct pipe_draw_info *info)
uint32_t *varying =
lima_ctx_buff_alloc(ctx, lima_ctx_buff_gp_varying_info,
vs->num_varying * 8, true);
vs->num_varying * 8);
int n = 0;
size_t gl_pos_size = 4 * 4 * info->count;
/* should be LIMA_SUBMIT_BO_WRITE for GP, but each draw will use
* different part of this bo, so no need to set exclusive constraint */
lima_ctx_buff_alloc(ctx, lima_ctx_buff_sh_gl_pos,
4 * 4 * info->count, false);
if (ctx->gl_pos[ctx->plb_index]->size < gl_pos_size) {
struct lima_screen *screen = lima_screen(ctx->base.screen);
lima_bo_free(ctx->gl_pos[ctx->plb_index]);
ctx->gl_pos[ctx->plb_index] = lima_bo_create(screen,
align(gl_pos_size, LIMA_PAGE_SIZE),
0);
}
/* for gl_Position */
varying[n++] =
lima_ctx_buff_va(ctx, lima_ctx_buff_sh_gl_pos,
LIMA_CTX_BUFF_SUBMIT_GP | LIMA_CTX_BUFF_SUBMIT_PP);
varying[n++] = ctx->gl_pos[ctx->plb_index]->va;
varying[n++] = 0x8020;
int offset = 0;
......@@ -1330,15 +1338,20 @@ lima_update_varying(struct lima_context *ctx, const struct pipe_draw_info *info)
}
vs->varying_stride = align(offset, 16);
if (vs->num_varying > 1)
lima_ctx_buff_alloc(ctx, lima_ctx_buff_sh_varying,
vs->varying_stride * info->count, false);
if (vs->num_varying > 1) {
size_t size = vs->varying_stride * info->count;
if (ctx->varyings[ctx->plb_index]->size < size) {
struct lima_screen *screen = lima_screen(ctx->base.screen);
lima_bo_free(ctx->varyings[ctx->plb_index]);
ctx->varyings[ctx->plb_index] = lima_bo_create(screen,
align(size, LIMA_PAGE_SIZE),
0);
}
}
for (int i = 1; i < vs->num_varying; i++) {
struct lima_varying_info *v = vs->varying + i;
varying[n++] =
lima_ctx_buff_va(ctx, lima_ctx_buff_sh_varying, LIMA_CTX_BUFF_SUBMIT_GP) +
v->offset;
varying[n++] = ctx->varyings[ctx->plb_index]->va + v->offset;
varying[n++] = (vs->varying_stride << 11) | (v->components - 1) |
(v->component_size == 2 ? 0x0C : 0);
}
......@@ -1560,7 +1573,7 @@ _lima_flush(struct lima_context *ctx, bool end_of_frame)
if (vs_cmd_size) {
void *vs_cmd =
lima_ctx_buff_alloc(ctx, lima_ctx_buff_gp_vs_cmd, vs_cmd_size, true);
lima_ctx_buff_alloc(ctx, lima_ctx_buff_gp_vs_cmd, vs_cmd_size);
memcpy(vs_cmd, util_dynarray_begin(&ctx->vs_cmd_array), vs_cmd_size);
util_dynarray_clear(&ctx->vs_cmd_array);
vs_cmd_va = lima_ctx_buff_va(ctx, lima_ctx_buff_gp_vs_cmd,
......@@ -1571,7 +1584,7 @@ _lima_flush(struct lima_context *ctx, bool end_of_frame)
}
void *plbu_cmd =
lima_ctx_buff_alloc(ctx, lima_ctx_buff_gp_plbu_cmd, plbu_cmd_size, true);
lima_ctx_buff_alloc(ctx, lima_ctx_buff_gp_plbu_cmd, plbu_cmd_size);
memcpy(plbu_cmd, util_dynarray_begin(&ctx->plbu_cmd_array), plbu_cmd_size);
util_dynarray_clear(&ctx->plbu_cmd_array);
plbu_cmd_va = lima_ctx_buff_va(ctx, lima_ctx_buff_gp_plbu_cmd,
......@@ -1598,11 +1611,11 @@ _lima_flush(struct lima_context *ctx, bool end_of_frame)
if (lima_dump_command_stream) {
if (lima_submit_wait(ctx->gp_submit, PIPE_TIMEOUT_INFINITE)) {
if (ctx->buffer_state[lima_ctx_buff_sh_gl_pos].res) {
float *pos = lima_ctx_buff_map(ctx, lima_ctx_buff_sh_gl_pos);
if (ctx->gl_pos[ctx->plb_index]) {
float *pos = lima_bo_map(ctx->gl_pos[ctx->plb_index]);
lima_dump_command_stream_print(
pos, 4 * 4 * 16, true, "gl_pos dump at va %x\n",
lima_ctx_buff_va(ctx, lima_ctx_buff_sh_gl_pos, 0));
ctx->gl_pos[ctx->plb_index]->va);
}
uint32_t *plb = lima_bo_map(ctx->plb[ctx->plb_index]);
......
......@@ -269,7 +269,7 @@ lima_update_textures(struct lima_context *ctx)
unsigned size = lima_tex_list_size + lima_tex->num_samplers * lima_tex_desc_size;
uint32_t *descs =
lima_ctx_buff_alloc(ctx, lima_ctx_buff_pp_tex_desc, size, true);
lima_ctx_buff_alloc(ctx, lima_ctx_buff_pp_tex_desc, size);
for (int i = 0; i < lima_tex->num_samplers; i++) {
off_t offset = lima_tex_desc_size * i + lima_tex_list_size;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment