summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2014-06-27 16:32:03 +0100
committerEric Anholt <[email protected]>2014-08-08 18:59:46 -0700
commit7108c24fd02a76f3efef4ba5d9aefdf0704ab0d8 (patch)
tree5d8483a00bb195aa6b410dca1dd42f0a8af66d54 /src
parent427f934f9e75deafdc40348aad0426ea2b31515c (diff)
vc4: Use the user's actual first vertex attribute.
This is hardcoded to read it as RGBA32F so far, but starts to get more tests working.
Diffstat (limited to 'src')
-rw-r--r--src/gallium/drivers/vc4/vc4_context.c10
-rw-r--r--src/gallium/drivers/vc4/vc4_context.h2
-rw-r--r--src/gallium/drivers/vc4/vc4_draw.c90
-rw-r--r--src/gallium/drivers/vc4/vc4_packet.h3
4 files changed, 70 insertions, 35 deletions
diff --git a/src/gallium/drivers/vc4/vc4_context.c b/src/gallium/drivers/vc4/vc4_context.c
index 51018d1cc94..66cba1f33e0 100644
--- a/src/gallium/drivers/vc4/vc4_context.c
+++ b/src/gallium/drivers/vc4/vc4_context.c
@@ -29,6 +29,7 @@
#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_blitter.h"
+#include "indices/u_primconvert.h"
#include "pipe/p_screen.h"
#define __user
@@ -142,6 +143,10 @@ vc4_context_destroy(struct pipe_context *pctx)
if (vc4->blitter)
util_blitter_destroy(vc4->blitter);
+
+ if (vc4->primconvert)
+ util_primconvert_destroy(vc4->primconvert);
+
util_slab_destroy(&vc4->transfer_pool);
free(vc4);
@@ -184,6 +189,11 @@ vc4_context_create(struct pipe_screen *pscreen, void *priv)
if (!vc4->blitter)
goto fail;
+ vc4->primconvert = util_primconvert_create(pctx,
+ !((1 << PIPE_PRIM_QUADS) - 1));
+ if (!vc4->primconvert)
+ goto fail;
+
return &vc4->base;
fail:
diff --git a/src/gallium/drivers/vc4/vc4_context.h b/src/gallium/drivers/vc4/vc4_context.h
index 36ad1bd2c8d..2aba99248c6 100644
--- a/src/gallium/drivers/vc4/vc4_context.h
+++ b/src/gallium/drivers/vc4/vc4_context.h
@@ -133,6 +133,8 @@ struct vc4_context {
*/
bool needs_flush;
+ struct primconvert_context *primconvert;
+
/** @{ Current pipeline state objects */
struct pipe_scissor_state scissor;
struct pipe_blend_state *blend;
diff --git a/src/gallium/drivers/vc4/vc4_draw.c b/src/gallium/drivers/vc4/vc4_draw.c
index f3283cda432..7b8fb0c5787 100644
--- a/src/gallium/drivers/vc4/vc4_draw.c
+++ b/src/gallium/drivers/vc4/vc4_draw.c
@@ -24,30 +24,12 @@
#include <stdio.h>
+#include "util/u_format.h"
+#include "indices/u_primconvert.h"
+
#include "vc4_context.h"
#include "vc4_resource.h"
-static struct vc4_bo *
-get_vbo(struct vc4_context *vc4, uint32_t width, uint32_t height)
-{
- struct {
- float x, y, z, w;
- } verts[] = {
- { -1, -1, 1, 1 },
- { 1, -1, 1, 1 },
- { -1, 1, 1, 1 },
- };
-
- return vc4_bo_alloc_mem(vc4->screen, verts, sizeof(verts), "verts");
-}
-static struct vc4_bo *
-get_ibo(struct vc4_context *vc4)
-{
- static const uint8_t indices[] = { 0, 1, 2 };
-
- return vc4_bo_alloc_mem(vc4->screen, indices, sizeof(indices), "indices");
-}
-
static void
vc4_rcl_tile_calls(struct vc4_context *vc4,
uint32_t xtiles, uint32_t ytiles,
@@ -79,6 +61,14 @@ static void
vc4_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
{
struct vc4_context *vc4 = vc4_context(pctx);
+
+ if (info->mode >= PIPE_PRIM_QUADS) {
+ util_primconvert_save_index_buffer(vc4->primconvert, &vc4->indexbuf);
+ util_primconvert_save_rasterizer_state(vc4->primconvert, &vc4->rasterizer->base);
+ util_primconvert_draw_vbo(vc4->primconvert, info);
+ return;
+ }
+
uint32_t width = vc4->framebuffer.width;
uint32_t height = vc4->framebuffer.height;
uint32_t tilew = align(width, 64) / 64;
@@ -87,9 +77,6 @@ vc4_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
32 * tilew * tileh, "tilea");
struct vc4_bo *tile_state = vc4_bo_alloc(vc4->screen,
48 * tilew * tileh, "tilestate");
- struct vc4_bo *ibo = get_ibo(vc4);
-
- struct vc4_bo *vbo = get_vbo(vc4, width, height);
vc4->needs_flush = true;
@@ -121,12 +108,31 @@ vc4_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
(nr_attributes & 0x7));
#endif
- cl_start_reloc(&vc4->bcl, 1);
- cl_u8(&vc4->bcl, VC4_PACKET_GL_INDEXED_PRIMITIVE);
- cl_u8(&vc4->bcl, 0x04); // 8bit index, trinagles
- cl_u32(&vc4->bcl, 3); // Length
- cl_reloc(vc4, &vc4->bcl, ibo, 0);
- cl_u32(&vc4->bcl, 2); // Maximum index
+ /* Note that the primitive type fields match with OpenGL/gallium
+ * definitions, up to but not including QUADS.
+ */
+ if (info->indexed) {
+ struct vc4_resource *rsc = vc4_resource(vc4->indexbuf.buffer);
+
+ assert(vc4->indexbuf.index_size == 1 ||
+ vc4->indexbuf.index_size == 2);
+
+ cl_start_reloc(&vc4->bcl, 1);
+ cl_u8(&vc4->bcl, VC4_PACKET_GL_INDEXED_PRIMITIVE);
+ cl_u8(&vc4->bcl,
+ info->mode |
+ (vc4->indexbuf.index_size == 2 ?
+ VC4_INDEX_BUFFER_U16:
+ VC4_INDEX_BUFFER_U8));
+ cl_u32(&vc4->bcl, info->count);
+ cl_reloc(vc4, &vc4->bcl, rsc->bo, vc4->indexbuf.offset);
+ cl_u32(&vc4->bcl, info->max_index);
+ } else {
+ cl_u8(&vc4->bcl, VC4_PACKET_GL_ARRAY_PRIMITIVE);
+ cl_u8(&vc4->bcl, info->mode);
+ cl_u32(&vc4->bcl, info->count);
+ cl_u32(&vc4->bcl, info->start);
+ }
cl_u8(&vc4->bcl, VC4_PACKET_FLUSH_ALL);
cl_u8(&vc4->bcl, VC4_PACKET_NOP);
@@ -166,11 +172,25 @@ vc4_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
vc4->prog.vs->coord_shader_offset);
cl_reloc(vc4, &vc4->shader_rec, cs_ubo, cs_ubo_offset);
- cl_reloc(vc4, &vc4->shader_rec, vbo, 0);
- cl_u8(&vc4->shader_rec, 15); /* bytes - 1 in the attribute*/
- cl_u8(&vc4->shader_rec, 16); /* attribute stride */
- cl_u8(&vc4->shader_rec, 0); /* VS VPM offset */
- cl_u8(&vc4->shader_rec, 0); /* CS VPM offset */
+ struct vc4_vertex_stateobj *vtx = vc4->vtx;
+ struct vc4_vertexbuf_stateobj *vertexbuf = &vc4->vertexbuf;
+ for (int i = 0; i < vtx->num_elements; i++) {
+ struct pipe_vertex_element *elem = &vtx->pipe[i];
+ struct pipe_vertex_buffer *vb =
+ &vertexbuf->vb[elem->vertex_buffer_index];
+ struct vc4_resource *rsc = vc4_resource(vb->buffer);
+
+ cl_reloc(vc4, &vc4->shader_rec, rsc->bo,
+ vb->buffer_offset + elem->src_offset);
+ cl_u8(&vc4->shader_rec,
+ util_format_get_blocksize(elem->src_format) - 1);
+ cl_u8(&vc4->shader_rec, vb->stride);
+ cl_u8(&vc4->shader_rec, 0); /* VS VPM offset */
+ cl_u8(&vc4->shader_rec, 0); /* CS VPM offset */
+
+ break; /* XXX: just the 1 for now. */
+ }
+
vc4->shader_rec_count++;
diff --git a/src/gallium/drivers/vc4/vc4_packet.h b/src/gallium/drivers/vc4/vc4_packet.h
index e7c334c5556..e74411a6a21 100644
--- a/src/gallium/drivers/vc4/vc4_packet.h
+++ b/src/gallium/drivers/vc4/vc4_packet.h
@@ -114,6 +114,9 @@ enum vc4_packet {
#define VC4_STORE_TILE_BUFFER_FULL (5 << 0)
/** @} */
+#define VC4_INDEX_BUFFER_U8 (0 << 4)
+#define VC4_INDEX_BUFFER_U16 (1 << 4)
+
/* This flag is only present in NV shader state. */
#define VC4_SHADER_FLAG_SHADED_CLIP_COORDS (1 << 3)
#define VC4_SHADER_FLAG_ENABLE_CLIPPING (1 << 2)