The size is always 24 bytes. We can upload them to the dynamic buffer.
Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
if (blitter->pipe_blitter)
util_blitter_destroy(blitter->pipe_blitter);
- if (blitter->buffer.res) {
- struct pipe_screen *screen = blitter->ilo->base.screen;
- screen->resource_destroy(screen, blitter->buffer.res);
- }
-
FREE(blitter);
}
bool initialized;
- struct {
- struct pipe_resource *res;
- unsigned offset, size;
- } buffer;
-
+ float vertices[3][2];
struct ilo_ve_state ve;
- struct ilo_vb_state vb;
struct pipe_draw_info draw;
struct ilo_viewport_cso viewport;
static bool
ilo_blitter_set_invariants(struct ilo_blitter *blitter)
{
- struct pipe_screen *screen = blitter->ilo->base.screen;
- struct pipe_resource templ;
struct pipe_vertex_element velems[2];
struct pipe_viewport_state vp;
if (blitter->initialized)
return true;
- blitter->buffer.size = 4096;
-
- /* allocate the vertex buffer */
- memset(&templ, 0, sizeof(templ));
- templ.target = PIPE_BUFFER;
- templ.width0 = blitter->buffer.size;
- templ.usage = PIPE_USAGE_STREAM;
- templ.bind = PIPE_BIND_VERTEX_BUFFER;
- blitter->buffer.res = screen->resource_create(screen, &templ);
- if (!blitter->buffer.res)
- return false;
-
- /* do not increase reference count */
- blitter->vb.states[0].buffer = blitter->buffer.res;
-
/* only vertex X and Y */
- blitter->vb.states[0].stride = 2 * sizeof(float);
- blitter->vb.enabled_mask = 0x1;
memset(&velems, 0, sizeof(velems));
velems[1].src_format = PIPE_FORMAT_R32G32_FLOAT;
ilo_gpe_init_ve(blitter->ilo->dev, 2, velems, &blitter->ve);
unsigned x, unsigned y,
unsigned width, unsigned height)
{
- unsigned usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_UNSYNCHRONIZED;
- float vertices[3][2];
- struct pipe_box box;
-
/*
* From the Sandy Bridge PRM, volume 2 part 1, page 11:
*
* by the definition of a rectangle. V0=LowerRight, V1=LowerLeft,
* V2=UpperLeft. Implied V3 = V0- V1+V2."
*/
- vertices[0][0] = (float) (x + width);
- vertices[0][1] = (float) (y + height);
- vertices[1][0] = (float) x;
- vertices[1][1] = (float) (y + height);
- vertices[2][0] = (float) x;
- vertices[2][1] = (float) y;
-
- /* buffer is full */
- if (blitter->buffer.offset + sizeof(vertices) > blitter->buffer.size) {
- if (!ilo_buffer_rename_bo(ilo_buffer(blitter->buffer.res)))
- usage &= ~PIPE_TRANSFER_UNSYNCHRONIZED;
-
- blitter->buffer.offset = 0;
- }
-
- u_box_1d(blitter->buffer.offset, sizeof(vertices), &box);
-
- blitter->ilo->base.transfer_inline_write(&blitter->ilo->base,
- blitter->buffer.res, 0, usage, &box, vertices, 0, 0);
-
- blitter->vb.states[0].buffer_offset = blitter->buffer.offset;
- blitter->buffer.offset += sizeof(vertices);
+ blitter->vertices[0][0] = (float) (x + width);
+ blitter->vertices[0][1] = (float) (y + height);
+ blitter->vertices[1][0] = (float) x;
+ blitter->vertices[1][1] = (float) (y + height);
+ blitter->vertices[2][0] = (float) x;
+ blitter->vertices[2][1] = (float) y;
}
static void
struct ilo_builder_writer *writer = &builder->writers[which];
/* all states are at least aligned to 32-bytes */
- assert(alignment % 32 == 0);
+ if (item != ILO_BUILDER_ITEM_BLOB)
+ assert(alignment % 32 == 0);
*dw = (uint32_t *) ((char *) writer->ptr + offset);
}
}
+/* the user vertex buffer must be uploaded with gen6_user_vertex_buffer() */
+static inline void
+gen6_user_3DSTATE_VERTEX_BUFFERS(struct ilo_builder *builder,
+ uint32_t vb_begin, uint32_t vb_end,
+ uint32_t stride)
+{
+ const struct ilo_builder_writer *bat =
+ &builder->writers[ILO_BUILDER_WRITER_BATCH];
+ const uint8_t cmd_len = 1 + 4;
+ uint32_t *dw;
+ unsigned pos;
+
+ ILO_DEV_ASSERT(builder->dev, 6, 7.5);
+
+ pos = ilo_builder_batch_pointer(builder, cmd_len, &dw);
+
+ dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
+ dw++;
+ pos++;
+
+ /* VERTEX_BUFFER_STATE */
+ dw[0] = 0 << GEN6_VB_STATE_DW0_INDEX__SHIFT |
+ GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA |
+ stride << GEN6_VB_STATE_DW0_PITCH__SHIFT;
+ dw[3] = 0;
+
+ ilo_builder_batch_reloc(builder, pos + 1, bat->bo, vb_begin, 0);
+ ilo_builder_batch_reloc(builder, pos + 2, bat->bo, vb_end, 0);
+}
+
static inline void
ve_init_cso_with_components(const struct ilo_dev_info *dev,
int comp0, int comp1, int comp2, int comp3,
return state_offset;
}
+static inline uint32_t
+gen6_user_vertex_buffer(struct ilo_builder *builder,
+ int size, const void *vertices)
+{
+ const int state_align = 8;
+ const int state_len = size / 4;
+
+ ILO_DEV_ASSERT(builder->dev, 6, 7.5);
+
+ assert(size % 4 == 0);
+
+ return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_BLOB,
+ state_align, state_len, vertices);
+}
+
#endif /* ILO_BUILDER_3D_TOP_H */
ilo_render_emit_rectlist(struct ilo_render *render,
const struct ilo_blitter *blitter)
{
+ struct ilo_render_rectlist_session session;
+
ILO_DEV_ASSERT(render->dev, 6, 7.5);
- ilo_render_emit_rectlist_dynamic_states(render, blitter);
- ilo_render_emit_rectlist_commands(render, blitter);
+ memset(&session, 0, sizeof(session));
+ ilo_render_emit_rectlist_dynamic_states(render, blitter, &session);
+ ilo_render_emit_rectlist_commands(render, blitter, &session);
}
int
{
ILO_DEV_ASSERT(render->dev, 6, 7.5);
- return 64;
+ return 96;
}
void
ilo_render_emit_rectlist_dynamic_states(struct ilo_render *render,
- const struct ilo_blitter *blitter)
+ const struct ilo_blitter *blitter,
+ struct ilo_render_rectlist_session *session)
{
const unsigned dynamic_used = ilo_builder_dynamic_used(render->builder);
ILO_DEV_ASSERT(render->dev, 6, 7.5);
+ /* both are inclusive */
+ session->vb_start = gen6_user_vertex_buffer(render->builder,
+ sizeof(blitter->vertices), (const void *) blitter->vertices);
+ session->vb_end = session->vb_start + sizeof(blitter->vertices) - 1;
+
if (blitter->uses & ILO_BLITTER_USE_DSA) {
render->state.DEPTH_STENCIL_STATE =
gen6_DEPTH_STENCIL_STATE(render->builder, &blitter->dsa);
int num_surfaces[PIPE_SHADER_TYPES];
};
+struct ilo_render_rectlist_session {
+ uint32_t vb_start;
+ uint32_t vb_end;
+};
+
int
ilo_render_get_draw_commands_len_gen6(const struct ilo_render *render,
const struct ilo_state_vector *vec);
void
ilo_render_emit_rectlist_commands_gen6(struct ilo_render *r,
- const struct ilo_blitter *blitter);
+ const struct ilo_blitter *blitter,
+ const struct ilo_render_rectlist_session *session);
void
ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
- const struct ilo_blitter *blitter);
+ const struct ilo_blitter *blitter,
+ const struct ilo_render_rectlist_session *session);
static inline void
ilo_render_emit_rectlist_commands(struct ilo_render *render,
- const struct ilo_blitter *blitter)
+ const struct ilo_blitter *blitter,
+ const struct ilo_render_rectlist_session *session)
{
const unsigned batch_used = ilo_builder_batch_used(render->builder);
if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
- ilo_render_emit_rectlist_commands_gen7(render, blitter);
+ ilo_render_emit_rectlist_commands_gen7(render, blitter, session);
else
- ilo_render_emit_rectlist_commands_gen6(render, blitter);
+ ilo_render_emit_rectlist_commands_gen6(render, blitter, session);
assert(ilo_builder_batch_used(render->builder) <= batch_used +
ilo_render_get_rectlist_commands_len(render, blitter));
void
ilo_render_emit_rectlist_dynamic_states(struct ilo_render *render,
- const struct ilo_blitter *blitter);
+ const struct ilo_blitter *blitter,
+ struct ilo_render_rectlist_session *session);
int
ilo_render_get_draw_surface_states_len(const struct ilo_render *render,
void
ilo_render_emit_rectlist_commands_gen6(struct ilo_render *r,
- const struct ilo_blitter *blitter)
+ const struct ilo_blitter *blitter,
+ const struct ilo_render_rectlist_session *session)
{
ILO_DEV_ASSERT(r->dev, 6, 6);
gen6_state_base_address(r->builder, true);
- gen6_3DSTATE_VERTEX_BUFFERS(r->builder,
- &blitter->ve, &blitter->vb);
+ gen6_user_3DSTATE_VERTEX_BUFFERS(r->builder,
+ session->vb_start, session->vb_end,
+ sizeof(blitter->vertices[0]));
gen6_3DSTATE_VERTEX_ELEMENTS(r->builder,
&blitter->ve, false, false);
void
ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
- const struct ilo_blitter *blitter)
+ const struct ilo_blitter *blitter,
+ const struct ilo_render_rectlist_session *session)
{
ILO_DEV_ASSERT(r->dev, 7, 7.5);
gen6_state_base_address(r->builder, true);
- gen6_3DSTATE_VERTEX_BUFFERS(r->builder,
- &blitter->ve, &blitter->vb);
+ gen6_user_3DSTATE_VERTEX_BUFFERS(r->builder,
+ session->vb_start, session->vb_end,
+ sizeof(blitter->vertices[0]));
gen6_3DSTATE_VERTEX_ELEMENTS(r->builder,
&blitter->ve, false, false);