Commit c036d13d authored by Keith Whitwell's avatar Keith Whitwell

Merge commit 'fj/mesa-next'

parents 69f20294 5b6b67eb
......@@ -1324,7 +1324,7 @@ AC_ARG_ENABLE([gallium-nouveau],
[enable_gallium_nouveau=no])
if test "x$enable_gallium_nouveau" = xyes; then
GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS nouveau"
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nv04 nv10 nv20 nv30 nv40 nv50"
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nv30 nv40 nv50"
fi
dnl
......
......@@ -31,21 +31,6 @@ Wrapper driver.
LLVM Softpipe
^^^^^^^^^^^^^
nVidia nv04
^^^^^^^^^^^
Deprecated.
nVidia nv10
^^^^^^^^^^^
Deprecated.
nVidia nv20
^^^^^^^^^^^
Deprecated.
nVidia nv30
^^^^^^^^^^^
......
......@@ -4,6 +4,7 @@ include $(TOP)/configs/current
LIBNAME = nouveau
C_SOURCES = nouveau_screen.c \
nouveau_context.c
nouveau_context.c \
nv04_surface_2d.c
include ../../Makefile.template
......@@ -26,24 +26,6 @@
/* use along with GPU_WRITE for 2D-only writes */
#define NOUVEAU_BUFFER_USAGE_NO_RENDER (1 << 19)
extern struct pipe_screen *
nv04_screen_create(struct pipe_winsys *ws, struct nouveau_device *);
extern struct pipe_context *
nv04_create(struct pipe_screen *, unsigned pctx_id);
extern struct pipe_screen *
nv10_screen_create(struct pipe_winsys *ws, struct nouveau_device *);
extern struct pipe_context *
nv10_create(struct pipe_screen *, unsigned pctx_id);
extern struct pipe_screen *
nv20_screen_create(struct pipe_winsys *ws, struct nouveau_device *);
extern struct pipe_context *
nv20_create(struct pipe_screen *, unsigned pctx_id);
extern struct pipe_screen *
nv30_screen_create(struct pipe_winsys *ws, struct nouveau_device *);
......
TOP = ../../../..
include $(TOP)/configs/current
LIBNAME = nv04
C_SOURCES = \
nv04_surface_2d.c \
nv04_clear.c \
nv04_context.c \
nv04_fragprog.c \
nv04_fragtex.c \
nv04_miptree.c \
nv04_prim_vbuf.c \
nv04_screen.c \
nv04_state.c \
nv04_state_emit.c \
nv04_surface.c \
nv04_transfer.c \
nv04_vbo.c
include ../../Makefile.template
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
#include "nv04_context.h"
void
nv04_clear(struct pipe_context *pipe, struct pipe_surface *ps,
unsigned clearValue)
{
pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue);
}
#include "draw/draw_context.h"
#include "pipe/p_defines.h"
#include "util/u_simple_screen.h"
#include "nv04_context.h"
#include "nv04_screen.h"
static void
nv04_flush(struct pipe_context *pipe, unsigned flags,
struct pipe_fence_handle **fence)
{
struct nv04_context *nv04 = nv04_context(pipe);
struct nv04_screen *screen = nv04->screen;
struct nouveau_channel *chan = screen->base.channel;
draw_flush(nv04->draw);
FIRE_RING(chan);
if (fence)
*fence = NULL;
}
static void
nv04_destroy(struct pipe_context *pipe)
{
struct nv04_context *nv04 = nv04_context(pipe);
if (nv04->draw)
draw_destroy(nv04->draw);
FREE(nv04);
}
static boolean
nv04_init_hwctx(struct nv04_context *nv04)
{
struct nv04_screen *screen = nv04->screen;
struct nouveau_channel *chan = screen->base.channel;
struct nouveau_grobj *fahrenheit = screen->fahrenheit;
// requires a valid handle
// BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_NOTIFY, 1);
// OUT_RING(0);
BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_NOP, 1);
OUT_RING(chan, 0);
BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_CONTROL, 1);
OUT_RING(chan, 0x40182800);
// OUT_RING(1<<20/*no cull*/);
BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_BLEND, 1);
// OUT_RING(0x24|(1<<6)|(1<<8));
OUT_RING(chan, 0x120001a4);
BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_FORMAT, 1);
OUT_RING(chan, 0x332213a1);
BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_FILTER, 1);
OUT_RING(chan, 0x11001010);
BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_COLORKEY, 1);
OUT_RING(chan, 0x0);
// BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_OFFSET, 1);
// OUT_RING(SCREEN_OFFSET);
BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_FOGCOLOR, 1);
OUT_RING(chan, 0xff000000);
FIRE_RING (chan);
return TRUE;
}
struct pipe_context *
nv04_create(struct pipe_screen *pscreen, unsigned pctx_id)
{
struct nv04_screen *screen = nv04_screen(pscreen);
struct pipe_winsys *ws = pscreen->winsys;
struct nv04_context *nv04;
struct nouveau_winsys *nvws = screen->nvws;
nv04 = CALLOC(1, sizeof(struct nv04_context));
if (!nv04)
return NULL;
nv04->screen = screen;
nv04->pctx_id = pctx_id;
nv04->nvws = nvws;
nv04->pipe.winsys = ws;
nv04->pipe.screen = pscreen;
nv04->pipe.destroy = nv04_destroy;
nv04->pipe.draw_arrays = nv04_draw_arrays;
nv04->pipe.draw_elements = nv04_draw_elements;
nv04->pipe.clear = nv04_clear;
nv04->pipe.flush = nv04_flush;
nv04->pipe.is_texture_referenced = nouveau_is_texture_referenced;
nv04->pipe.is_buffer_referenced = nouveau_is_buffer_referenced;
nv04_init_surface_functions(nv04);
nv04_init_state_functions(nv04);
nv04->draw = draw_create();
assert(nv04->draw);
draw_wide_point_threshold(nv04->draw, 0.0);
draw_wide_line_threshold(nv04->draw, 0.0);
draw_enable_line_stipple(nv04->draw, FALSE);
draw_enable_point_sprites(nv04->draw, FALSE);
draw_set_rasterize_stage(nv04->draw, nv04_draw_vbuf_stage(nv04));
nv04_init_hwctx(nv04);
return &nv04->pipe;
}
#ifndef __NV04_CONTEXT_H__
#define __NV04_CONTEXT_H__
#include <stdio.h>
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
#include "pipe/p_compiler.h"
#include "util/u_memory.h"
#include "util/u_math.h"
#include "util/u_inlines.h"
#include "draw/draw_vertex.h"
#include "nouveau/nouveau_winsys.h"
#include "nouveau/nouveau_gldefs.h"
#include "nouveau/nouveau_context.h"
#include "nv04_state.h"
#define NOUVEAU_ERR(fmt, args...) \
fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
#define NOUVEAU_MSG(fmt, args...) \
fprintf(stderr, "nouveau: "fmt, ##args);
#include "nv04_screen.h"
#define NV04_NEW_VERTPROG (1 << 1)
#define NV04_NEW_FRAGPROG (1 << 2)
#define NV04_NEW_BLEND (1 << 3)
#define NV04_NEW_RAST (1 << 4)
#define NV04_NEW_CONTROL (1 << 5)
#define NV04_NEW_VIEWPORT (1 << 6)
#define NV04_NEW_SAMPLER (1 << 7)
#define NV04_NEW_FRAMEBUFFER (1 << 8)
#define NV04_NEW_VTXARRAYS (1 << 9)
struct nv04_context {
struct pipe_context pipe;
struct nouveau_winsys *nvws;
struct nv04_screen *screen;
unsigned pctx_id;
struct draw_context *draw;
int chipset;
struct nouveau_notifier *sync;
uint32_t dirty;
struct nv04_blend_state *blend;
struct nv04_sampler_state *sampler[PIPE_MAX_SAMPLERS];
struct nv04_fragtex_state fragtex;
struct nv04_rasterizer_state *rast;
struct nv04_depth_stencil_alpha_state *dsa;
struct nv04_miptree *tex_miptree[PIPE_MAX_SAMPLERS];
unsigned dirty_samplers;
unsigned fp_samplers;
unsigned vp_samplers;
uint32_t rt_enable;
struct pipe_framebuffer_state *framebuffer;
struct pipe_surface *rt;
struct pipe_surface *zeta;
struct {
struct pipe_buffer *buffer;
uint32_t format;
} tex[16];
unsigned vb_enable;
struct {
struct pipe_buffer *buffer;
unsigned delta;
} vb[16];
float *constbuf[PIPE_SHADER_TYPES][32][4];
unsigned constbuf_nr[PIPE_SHADER_TYPES];
struct vertex_info vertex_info;
struct {
struct nouveau_resource *exec_heap;
struct nouveau_resource *data_heap;
struct nv04_vertex_program *active;
struct nv04_vertex_program *current;
struct pipe_buffer *constant_buf;
} vertprog;
struct {
struct nv04_fragment_program *active;
struct nv04_fragment_program *current;
struct pipe_buffer *constant_buf;
} fragprog;
struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
struct pipe_vertex_element vtxelt[PIPE_MAX_ATTRIBS];
struct pipe_viewport_state viewport;
};
static INLINE struct nv04_context *
nv04_context(struct pipe_context *pipe)
{
return (struct nv04_context *)pipe;
}
extern void nv04_init_state_functions(struct nv04_context *nv04);
extern void nv04_init_surface_functions(struct nv04_context *nv04);
extern void nv04_screen_init_miptree_functions(struct pipe_screen *screen);
/* nv04_clear.c */
extern void nv04_clear(struct pipe_context *pipe, struct pipe_surface *ps,
unsigned clearValue);
/* nv04_draw.c */
extern struct draw_stage *nv04_draw_render_stage(struct nv04_context *nv04);
/* nv04_fragprog.c */
extern void nv04_fragprog_bind(struct nv04_context *,
struct nv04_fragment_program *);
extern void nv04_fragprog_destroy(struct nv04_context *,
struct nv04_fragment_program *);
/* nv04_fragtex.c */
extern void nv04_fragtex_bind(struct nv04_context *);
/* nv04_prim_vbuf.c */
struct draw_stage *nv04_draw_vbuf_stage( struct nv04_context *nv04 );
/* nv04_state.c and friends */
extern void nv04_emit_hw_state(struct nv04_context *nv04);
extern void nv04_state_tex_update(struct nv04_context *nv04);
/* nv04_vbo.c */
extern void nv04_draw_arrays(struct pipe_context *, unsigned mode,
unsigned start, unsigned count);
extern void nv04_draw_elements( struct pipe_context *pipe,
struct pipe_buffer *indexBuffer,
unsigned indexSize,
unsigned prim, unsigned start, unsigned count);
#endif
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
#include "pipe/p_shader_tokens.h"
#include "tgsi/tgsi_parse.h"
#include "tgsi/tgsi_util.h"
#include "nv04_context.h"
void
nv04_fragprog_bind(struct nv04_context *nv04, struct nv04_fragment_program *fp)
{
}
void
nv04_fragprog_destroy(struct nv04_context *nv04,
struct nv04_fragment_program *fp)
{
}
#include "nv04_context.h"
#include "nouveau/nouveau_util.h"
#define _(m,tf) \
{ \
PIPE_FORMAT_##m, \
NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_##tf, \
}
struct nv04_texture_format {
uint pipe;
int format;
};
static struct nv04_texture_format
nv04_texture_formats[] = {
_(A8R8G8B8_UNORM, A8R8G8B8),
_(X8R8G8B8_UNORM, X8R8G8B8),
_(A1R5G5B5_UNORM, A1R5G5B5),
_(A4R4G4B4_UNORM, A4R4G4B4),
_(L8_UNORM, Y8 ),
_(A8_UNORM, Y8 ),
};
static uint32_t
nv04_fragtex_format(uint pipe_format)
{
struct nv04_texture_format *tf = nv04_texture_formats;
int i;
for (i=0; i< sizeof(nv04_texture_formats)/sizeof(nv04_texture_formats[0]); i++) {
if (tf->pipe == pipe_format)
return tf->format;
tf++;
}
NOUVEAU_ERR("unknown texture format %s\n", pf_name(pipe_format));
return 0;
}
static void
nv04_fragtex_build(struct nv04_context *nv04, int unit)
{
struct nv04_miptree *nv04mt = nv04->tex_miptree[unit];
struct pipe_texture *pt = &nv04mt->base;
switch (pt->target) {
case PIPE_TEXTURE_2D:
break;
default:
NOUVEAU_ERR("Unknown target %d\n", pt->target);
return;
}
nv04->fragtex.format = NV04_TEXTURED_TRIANGLE_FORMAT_ORIGIN_ZOH_CORNER
| NV04_TEXTURED_TRIANGLE_FORMAT_ORIGIN_FOH_CORNER
| nv04_fragtex_format(pt->format)
| ( (pt->last_level + 1) << NV04_TEXTURED_TRIANGLE_FORMAT_MIPMAP_LEVELS_SHIFT )
| ( log2i(pt->width0) << NV04_TEXTURED_TRIANGLE_FORMAT_BASE_SIZE_U_SHIFT )
| ( log2i(pt->height0) << NV04_TEXTURED_TRIANGLE_FORMAT_BASE_SIZE_V_SHIFT )
| NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_CLAMP_TO_EDGE
| NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSV_CLAMP_TO_EDGE
;
}
void
nv04_fragtex_bind(struct nv04_context *nv04)
{
nv04_fragtex_build(nv04, 0);
}
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
#include "util/u_inlines.h"
#include "util/u_math.h"
#include "nv04_context.h"
#include "nv04_screen.h"
static void
nv04_miptree_layout(struct nv04_miptree *nv04mt)
{
struct pipe_texture *pt = &nv04mt->base;
uint offset = 0;
int nr_faces, l;
nr_faces = 1;
for (l = 0; l <= pt->last_level; l++) {
nv04mt->level[l].pitch = pt->width0;
nv04mt->level[l].pitch = (nv04mt->level[l].pitch + 63) & ~63;
}
for (l = 0; l <= pt->last_level; l++) {
nv04mt->level[l].image_offset =
CALLOC(nr_faces, sizeof(unsigned));
/* XXX guess was obviously missing */
nv04mt->level[l].image_offset[0] = offset;
offset += nv04mt->level[l].pitch * u_minify(pt->height0, l);
}
nv04mt->total_size = offset;
}
static struct pipe_texture *
nv04_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt)
{
struct nv04_miptree *mt;
mt = MALLOC(sizeof(struct nv04_miptree));
if (!mt)
return NULL;
mt->base = *pt;
pipe_reference_init(&mt->base.reference, 1);
mt->base.screen = pscreen;
//mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
nv04_miptree_layout(mt);
mt->buffer = pscreen->buffer_create(pscreen, 256, PIPE_BUFFER_USAGE_PIXEL |
NOUVEAU_BUFFER_USAGE_TEXTURE,
mt->total_size);
if (!mt->buffer) {
printf("failed %d byte alloc\n",mt->total_size);
FREE(mt);
return NULL;
}
mt->bo = nouveau_bo(mt->buffer);
return &mt->base;
}
static struct pipe_texture *
nv04_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt,
const unsigned *stride, struct pipe_buffer *pb)
{
struct nv04_miptree *mt;
/* Only supports 2D, non-mipmapped textures for the moment */
if (pt->target != PIPE_TEXTURE_2D || pt->last_level != 0 ||
pt->depth0 != 1)
return NULL;
mt = CALLOC_STRUCT(nv04_miptree);
if (!mt)
return NULL;
mt->base = *pt;
pipe_reference_init(&mt->base.reference, 1);
mt->base.screen = pscreen;
mt->level[0].pitch = stride[0];
mt->level[0].image_offset = CALLOC(1, sizeof(unsigned));
pipe_buffer_reference(&mt->buffer, pb);
mt->bo = nouveau_bo(mt->buffer);
return &mt->base;
}
static void
nv04_miptree_destroy(struct pipe_texture *pt)
{
struct nv04_miptree *mt = (struct nv04_miptree *)pt;
int l;
pipe_buffer_reference(&mt->buffer, NULL);
for (l = 0; l <= pt->last_level; l++) {
if (mt->level[l].image_offset)
FREE(mt->level[l].image_offset);
}
FREE(mt);
}
static struct pipe_surface *
nv04_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
unsigned face, unsigned level, unsigned zslice,
unsigned flags)
{
struct nv04_miptree *nv04mt = (struct nv04_miptree *)pt;
struct nv04_surface *ns;
ns = CALLOC_STRUCT(nv04_surface);
if (!ns)
return NULL;
pipe_texture_reference(&ns->base.texture, pt);
ns->base.format = pt->format;
ns->base.width = u_minify(pt->width0, level);
ns->base.height = u_minify(pt->height0, level);
ns->base.usage = flags;
pipe_reference_init(&ns->base.reference, 1);
ns->base.face = face;
ns->base.level = level;
ns->base.zslice = zslice;
ns->pitch = nv04mt->level[level].pitch;
ns->base.offset = nv04mt->level[level].image_offset[0];
return &ns->base;
}
static void
nv04_miptree_surface_del(struct pipe_surface *ps)
{
pipe_texture_reference(&ps->texture, NULL);
FREE(ps);
}
void
nv04_screen_init_miptree_functions(struct pipe_screen *pscreen)
{
pscreen->texture_create = nv04_miptree_create;
pscreen->texture_blanket = nv04_miptree_blanket;
pscreen->texture_destroy = nv04_miptree_destroy;
pscreen->get_tex_surface = nv04_miptree_surface_new;
pscreen->tex_surface_destroy = nv04_miptree_surface_del;
}
#include "util/u_debug.h"
#include "util/u_inlines.h"
#include "util/u_simple_screen.h"
#include "pipe/p_compiler.h"
#include "draw/draw_vbuf.h"
#include "nv04_context.h"
#include "nv04_state.h"
#define VERTEX_SIZE 40
#define VERTEX_BUFFER_SIZE (4096*VERTEX_SIZE) // 4096 vertices of 40 bytes each
/**
* Primitive renderer for nv04.
*/
struct nv04_vbuf_render {
struct vbuf_render base;
struct nv04_context *nv04;
/** Vertex buffer */
unsigned char* buffer;
/** Vertex size in bytes */
unsigned vertex_size;
/** Current primitive */
unsigned prim;
};
/**
* Basically a cast wrapper.
*/
static INLINE struct nv04_vbuf_render *
nv04_vbuf_render( struct vbuf_render *render )
{
assert(render);
return (struct nv04_vbuf_render *)render;
}
static const struct vertex_info *
nv04_vbuf_render_get_vertex_info( struct vbuf_render *render )
{
struct nv04_vbuf_render *nv04_render = nv04_vbuf_render(render);
struct nv04_context *nv04 = nv04_render->nv04;
return &nv04->vertex_info;
}
static boolean
nv04_vbuf_render_allocate_vertices( struct vbuf_render *render,
ushort vertex_size,
ushort nr_vertices )
{
struct nv04_vbuf_render *nv04_render = nv04_vbuf_render(render);
nv04_render->buffer = (unsigned char*) MALLOC(VERTEX_BUFFER_SIZE);
assert(!nv04_render->buffer);