summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/nv50/nv50_vbo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/drivers/nv50/nv50_vbo.c')
-rw-r--r--src/gallium/drivers/nv50/nv50_vbo.c105
1 files changed, 71 insertions, 34 deletions
diff --git a/src/gallium/drivers/nv50/nv50_vbo.c b/src/gallium/drivers/nv50/nv50_vbo.c
index 0749c90691..422c8c6b5b 100644
--- a/src/gallium/drivers/nv50/nv50_vbo.c
+++ b/src/gallium/drivers/nv50/nv50_vbo.c
@@ -22,6 +22,7 @@
#include "pipe/p_context.h"
#include "pipe/p_state.h"
+#include "pipe/p_inlines.h"
#include "nv50_context.h"
@@ -48,12 +49,63 @@ nv50_prim(unsigned mode)
return NV50TCL_VERTEX_BEGIN_POINTS;
}
+static INLINE unsigned
+nv50_vtxeltfmt(unsigned pf)
+{
+ static const uint8_t vtxelt_32[4] = { 0x90, 0x20, 0x10, 0x08 };
+ static const uint8_t vtxelt_16[4] = { 0xd8, 0x78, 0x28, 0x18 };
+ static const uint8_t vtxelt_08[4] = { 0xe8, 0xc0, 0x98, 0x50 };
+
+ unsigned nf, c = 0;
+
+ switch (pf_type(pf)) {
+ case PIPE_FORMAT_TYPE_FLOAT:
+ nf = NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_FLOAT; break;
+ case PIPE_FORMAT_TYPE_UNORM:
+ nf = NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_UNORM; break;
+ case PIPE_FORMAT_TYPE_SNORM:
+ nf = NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_SNORM; break;
+ case PIPE_FORMAT_TYPE_USCALED:
+ nf = NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_USCALED; break;
+ case PIPE_FORMAT_TYPE_SSCALED:
+ nf = NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_SSCALED; break;
+ default:
+ NOUVEAU_ERR("invalid vbo type %d\n",pf_type(pf));
+ assert(0);
+ nf = NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_FLOAT;
+ break;
+ }
+
+ if (pf_size_y(pf)) c++;
+ if (pf_size_z(pf)) c++;
+ if (pf_size_w(pf)) c++;
+
+ if (pf_exp2(pf) == 3) {
+ switch (pf_size_x(pf)) {
+ case 1: return (nf | (vtxelt_08[c] << 16));
+ case 2: return (nf | (vtxelt_16[c] << 16));
+ case 4: return (nf | (vtxelt_32[c] << 16));
+ default:
+ break;
+ }
+ } else
+ if (pf_exp2(pf) == 6 && pf_size_x(pf) == 1) {
+ NOUVEAU_ERR("unsupported vbo component size 64\n");
+ assert(0);
+ return (nf | 0x08000000);
+ }
+
+ NOUVEAU_ERR("invalid vbo format %s\n",pf_name(pf));
+ assert(0);
+ return (nf | 0x08000000);
+}
+
boolean
nv50_draw_arrays(struct pipe_context *pipe, unsigned mode, unsigned start,
unsigned count)
{
struct nv50_context *nv50 = nv50_context(pipe);
- struct nouveau_channel *chan = nv50->screen->nvws->channel;
+ struct nouveau_channel *chan = nv50->screen->tesla->channel;
struct nouveau_grobj *tesla = nv50->screen->tesla;
nv50_state_validate(nv50);
@@ -83,7 +135,7 @@ static INLINE void
nv50_draw_elements_inline_u08(struct nv50_context *nv50, uint8_t *map,
unsigned start, unsigned count)
{
- struct nouveau_channel *chan = nv50->screen->nvws->channel;
+ struct nouveau_channel *chan = nv50->screen->tesla->channel;
struct nouveau_grobj *tesla = nv50->screen->tesla;
map += start;
@@ -112,7 +164,7 @@ static INLINE void
nv50_draw_elements_inline_u16(struct nv50_context *nv50, uint16_t *map,
unsigned start, unsigned count)
{
- struct nouveau_channel *chan = nv50->screen->nvws->channel;
+ struct nouveau_channel *chan = nv50->screen->tesla->channel;
struct nouveau_grobj *tesla = nv50->screen->tesla;
map += start;
@@ -138,10 +190,10 @@ nv50_draw_elements_inline_u16(struct nv50_context *nv50, uint16_t *map,
}
static INLINE void
-nv50_draw_elements_inline_u32(struct nv50_context *nv50, uint8_t *map,
+nv50_draw_elements_inline_u32(struct nv50_context *nv50, uint32_t *map,
unsigned start, unsigned count)
{
- struct nouveau_channel *chan = nv50->screen->nvws->channel;
+ struct nouveau_channel *chan = nv50->screen->tesla->channel;
struct nouveau_grobj *tesla = nv50->screen->tesla;
map += start;
@@ -163,10 +215,12 @@ nv50_draw_elements(struct pipe_context *pipe,
unsigned mode, unsigned start, unsigned count)
{
struct nv50_context *nv50 = nv50_context(pipe);
- struct nouveau_channel *chan = nv50->screen->nvws->channel;
+ struct nouveau_channel *chan = nv50->screen->tesla->channel;
struct nouveau_grobj *tesla = nv50->screen->tesla;
- struct pipe_winsys *ws = pipe->winsys;
- void *map = ws->buffer_map(ws, indexBuffer, PIPE_BUFFER_USAGE_CPU_READ);
+ struct pipe_screen *pscreen = pipe->screen;
+ void *map;
+
+ map = pipe_buffer_map(pscreen, indexBuffer, PIPE_BUFFER_USAGE_CPU_READ);
nv50_state_validate(nv50);
@@ -193,6 +247,7 @@ nv50_draw_elements(struct pipe_context *pipe,
BEGIN_RING(chan, tesla, NV50TCL_VERTEX_END, 1);
OUT_RING (chan, 0);
+ pipe_buffer_unmap(pscreen, indexBuffer);
pipe->flush(pipe, 0, NULL);
return TRUE;
}
@@ -204,6 +259,10 @@ nv50_vbo_validate(struct nv50_context *nv50)
struct nouveau_stateobj *vtxbuf, *vtxfmt;
int i;
+ /* don't validate if Gallium took away our buffers */
+ if (nv50->vtxbuf_nr == 0)
+ return;
+
vtxbuf = so_new(nv50->vtxelt_nr * 4, nv50->vtxelt_nr * 2);
vtxfmt = so_new(nv50->vtxelt_nr + 1, 0);
so_method(vtxfmt, tesla, 0x1ac0, nv50->vtxelt_nr);
@@ -212,38 +271,16 @@ nv50_vbo_validate(struct nv50_context *nv50)
struct pipe_vertex_element *ve = &nv50->vtxelt[i];
struct pipe_vertex_buffer *vb =
&nv50->vtxbuf[ve->vertex_buffer_index];
+ struct nouveau_bo *bo = nouveau_bo(vb->buffer);
- switch (ve->src_format) {
- case PIPE_FORMAT_R32G32B32A32_FLOAT:
- so_data(vtxfmt, 0x7e080000 | i);
- break;
- case PIPE_FORMAT_R32G32B32_FLOAT:
- so_data(vtxfmt, 0x7e100000 | i);
- break;
- case PIPE_FORMAT_R32G32_FLOAT:
- so_data(vtxfmt, 0x7e200000 | i);
- break;
- case PIPE_FORMAT_R32_FLOAT:
- so_data(vtxfmt, 0x7e900000 | i);
- break;
- case PIPE_FORMAT_R8G8B8A8_UNORM:
- so_data(vtxfmt, 0x24500000 | i);
- break;
- default:
- {
- NOUVEAU_ERR("invalid vbo format %s\n",
- pf_name(ve->src_format));
- assert(0);
- return;
- }
- }
+ so_data(vtxfmt, nv50_vtxeltfmt(ve->src_format) | i);
so_method(vtxbuf, tesla, 0x900 + (i * 16), 3);
so_data (vtxbuf, 0x20000000 | vb->stride);
- so_reloc (vtxbuf, vb->buffer, vb->buffer_offset +
+ so_reloc (vtxbuf, bo, vb->buffer_offset +
ve->src_offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART |
NOUVEAU_BO_RD | NOUVEAU_BO_HIGH, 0, 0);
- so_reloc (vtxbuf, vb->buffer, vb->buffer_offset +
+ so_reloc (vtxbuf, bo, vb->buffer_offset +
ve->src_offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART |
NOUVEAU_BO_RD | NOUVEAU_BO_LOW, 0, 0);
}