Commit f83c91db authored by Keith Whitwell's avatar Keith Whitwell

Merge commit 'origin/gallium-sampler-view' into gallium-resources

Conflicts:
	src/gallium/drivers/nv40/nv40_transfer.c
	src/gallium/drivers/nvfx/nvfx_transfer.c
	src/gallium/drivers/trace/tr_drm.c
parents c1d47741 42910ebe
......@@ -1360,7 +1360,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 nv30 nv40 nv50"
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50"
fi
dnl
......
......@@ -4,7 +4,6 @@ include $(TOP)/configs/current
LIBNAME = nouveau
C_SOURCES = nouveau_screen.c \
nouveau_context.c \
nv04_surface_2d.c
nouveau_context.c
include ../../Makefile.template
......@@ -33,7 +33,7 @@ nouveau_vbuf_split(unsigned remaining, unsigned overhead, unsigned vpp,
max = max - (max % 3);
break;
case PIPE_PRIM_QUADS:
max = max & 3;
max = max & ~3;
break;
case PIPE_PRIM_LINE_LOOP:
case PIPE_PRIM_LINE_STRIP:
......
......@@ -27,10 +27,7 @@
#define NOUVEAU_BUFFER_USAGE_NO_RENDER (1 << 19)
extern struct pipe_screen *
nv30_screen_create(struct pipe_winsys *ws, struct nouveau_device *);
extern struct pipe_screen *
nv40_screen_create(struct pipe_winsys *ws, struct nouveau_device *);
nvfx_screen_create(struct pipe_winsys *ws, struct nouveau_device *);
extern struct pipe_screen *
nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *);
......
TOP = ../../../..
include $(TOP)/configs/current
LIBNAME = nv30
C_SOURCES = \
nv30_clear.c \
nv30_context.c \
nv30_draw.c \
nv30_fragprog.c \
nv30_fragtex.c \
nv30_miptree.c \
nv30_query.c \
nv30_screen.c \
nv30_state.c \
nv30_state_blend.c \
nv30_state_emit.c \
nv30_state_fb.c \
nv30_state_rasterizer.c \
nv30_state_scissor.c \
nv30_state_stipple.c \
nv30_state_viewport.c \
nv30_state_zsa.c \
nv30_surface.c \
nv30_transfer.c \
nv30_vbo.c \
nv30_vertprog.c
include ../../Makefile.template
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
#include "util/u_clear.h"
#include "nv30_context.h"
void
nv30_clear(struct pipe_context *pipe, unsigned buffers,
const float *rgba, double depth, unsigned stencil)
{
util_clear(pipe, &nv30_context(pipe)->framebuffer, buffers, rgba, depth,
stencil);
}
#include "draw/draw_context.h"
#include "pipe/p_defines.h"
#include "nv30_context.h"
#include "nv30_screen.h"
static void
nv30_flush(struct pipe_context *pipe, unsigned flags,
struct pipe_fence_handle **fence)
{
struct nv30_context *nv30 = nv30_context(pipe);
struct nv30_screen *screen = nv30->screen;
struct nouveau_channel *chan = screen->base.channel;
struct nouveau_grobj *rankine = screen->rankine;
if (flags & PIPE_FLUSH_TEXTURE_CACHE) {
BEGIN_RING(chan, rankine, 0x1fd8, 1);
OUT_RING (chan, 2);
BEGIN_RING(chan, rankine, 0x1fd8, 1);
OUT_RING (chan, 1);
}
FIRE_RING(chan);
if (fence)
*fence = NULL;
}
static void
nv30_destroy(struct pipe_context *pipe)
{
struct nv30_context *nv30 = nv30_context(pipe);
unsigned i;
for (i = 0; i < NV30_STATE_MAX; i++) {
if (nv30->state.hw[i])
so_ref(NULL, &nv30->state.hw[i]);
}
if (nv30->draw)
draw_destroy(nv30->draw);
FREE(nv30);
}
struct pipe_context *
nv30_create(struct pipe_screen *pscreen, void *priv)
{
struct nv30_screen *screen = nv30_screen(pscreen);
struct pipe_winsys *ws = pscreen->winsys;
struct nv30_context *nv30;
struct nouveau_winsys *nvws = screen->nvws;
nv30 = CALLOC(1, sizeof(struct nv30_context));
if (!nv30)
return NULL;
nv30->screen = screen;
nv30->nvws = nvws;
nv30->pipe.winsys = ws;
nv30->pipe.screen = pscreen;
nv30->pipe.priv = priv;
nv30->pipe.destroy = nv30_destroy;
nv30->pipe.draw_arrays = nv30_draw_arrays;
nv30->pipe.draw_elements = nv30_draw_elements;
nv30->pipe.clear = nv30_clear;
nv30->pipe.flush = nv30_flush;
nv30->pipe.is_texture_referenced = nouveau_is_texture_referenced;
nv30->pipe.is_buffer_referenced = nouveau_is_buffer_referenced;
screen->base.channel->user_private = nv30;
screen->base.channel->flush_notify = nv30_state_flush_notify;
nv30_init_query_functions(nv30);
nv30_init_surface_functions(nv30);
nv30_init_state_functions(nv30);
nv30_init_transfer_functions(nv30);
/* Create, configure, and install fallback swtnl path */
nv30->draw = draw_create();
draw_wide_point_threshold(nv30->draw, 9999999.0);
draw_wide_line_threshold(nv30->draw, 9999999.0);
draw_enable_line_stipple(nv30->draw, FALSE);
draw_enable_point_sprites(nv30->draw, FALSE);
draw_set_rasterize_stage(nv30->draw, nv30_draw_render_stage(nv30));
return &nv30->pipe;
}
#ifndef __NV30_CONTEXT_H__
#define __NV30_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 "nouveau/nouveau_stateobj.h"
#include "nv30_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);
enum nv30_state_index {
NV30_STATE_FB = 0,
NV30_STATE_VIEWPORT = 1,
NV30_STATE_BLEND = 2,
NV30_STATE_RAST = 3,
NV30_STATE_ZSA = 4,
NV30_STATE_BCOL = 5,
NV30_STATE_CLIP = 6,
NV30_STATE_SCISSOR = 7,
NV30_STATE_STIPPLE = 8,
NV30_STATE_FRAGPROG = 9,
NV30_STATE_VERTPROG = 10,
NV30_STATE_FRAGTEX0 = 11,
NV30_STATE_FRAGTEX1 = 12,
NV30_STATE_FRAGTEX2 = 13,
NV30_STATE_FRAGTEX3 = 14,
NV30_STATE_FRAGTEX4 = 15,
NV30_STATE_FRAGTEX5 = 16,
NV30_STATE_FRAGTEX6 = 17,
NV30_STATE_FRAGTEX7 = 18,
NV30_STATE_FRAGTEX8 = 19,
NV30_STATE_FRAGTEX9 = 20,
NV30_STATE_FRAGTEX10 = 21,
NV30_STATE_FRAGTEX11 = 22,
NV30_STATE_FRAGTEX12 = 23,
NV30_STATE_FRAGTEX13 = 24,
NV30_STATE_FRAGTEX14 = 25,
NV30_STATE_FRAGTEX15 = 26,
NV30_STATE_VERTTEX0 = 27,
NV30_STATE_VERTTEX1 = 28,
NV30_STATE_VERTTEX2 = 29,
NV30_STATE_VERTTEX3 = 30,
NV30_STATE_VTXBUF = 31,
NV30_STATE_VTXFMT = 32,
NV30_STATE_VTXATTR = 33,
NV30_STATE_SR = 34,
NV30_STATE_MAX = 35
};
#include "nv30_screen.h"
#define NV30_NEW_BLEND (1 << 0)
#define NV30_NEW_RAST (1 << 1)
#define NV30_NEW_ZSA (1 << 2)
#define NV30_NEW_SAMPLER (1 << 3)
#define NV30_NEW_FB (1 << 4)
#define NV30_NEW_STIPPLE (1 << 5)
#define NV30_NEW_SCISSOR (1 << 6)
#define NV30_NEW_VIEWPORT (1 << 7)
#define NV30_NEW_BCOL (1 << 8)
#define NV30_NEW_VERTPROG (1 << 9)
#define NV30_NEW_FRAGPROG (1 << 10)
#define NV30_NEW_ARRAYS (1 << 11)
#define NV30_NEW_UCP (1 << 12)
#define NV30_NEW_SR (1 << 13)
struct nv30_rasterizer_state {
struct pipe_rasterizer_state pipe;
struct nouveau_stateobj *so;
};
struct nv30_zsa_state {
struct pipe_depth_stencil_alpha_state pipe;
struct nouveau_stateobj *so;
};
struct nv30_blend_state {
struct pipe_blend_state pipe;
struct nouveau_stateobj *so;
};
struct nv30_state {
unsigned scissor_enabled;
unsigned stipple_enabled;
unsigned fp_samplers;
uint64_t dirty;
struct nouveau_stateobj *hw[NV30_STATE_MAX];
};
struct nv30_vtxelt_state {
struct pipe_vertex_element pipe[16];
unsigned num_elements;
};
struct nv30_context {
struct pipe_context pipe;
struct nouveau_winsys *nvws;
struct nv30_screen *screen;
struct draw_context *draw;
/* HW state derived from pipe states */
struct nv30_state state;
/* Context state */
unsigned dirty;
struct pipe_scissor_state scissor;
unsigned stipple[32];
struct nv30_vertex_program *vertprog;
struct nv30_fragment_program *fragprog;
struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
unsigned constbuf_nr[PIPE_SHADER_TYPES];
struct nv30_rasterizer_state *rasterizer;
struct nv30_zsa_state *zsa;
struct nv30_blend_state *blend;
struct pipe_blend_color blend_colour;
struct pipe_stencil_ref stencil_ref;
struct pipe_viewport_state viewport;
struct pipe_framebuffer_state framebuffer;
struct pipe_buffer *idxbuf;
unsigned idxbuf_format;
struct nv30_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
struct nv30_miptree *tex_miptree[PIPE_MAX_SAMPLERS];
struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
unsigned nr_samplers;
unsigned nr_textures;
unsigned dirty_samplers;
struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
unsigned vtxbuf_nr;
struct nv30_vtxelt_state *vtxelt;
};
static INLINE struct nv30_context *
nv30_context(struct pipe_context *pipe)
{
return (struct nv30_context *)pipe;
}
struct nv30_state_entry {
boolean (*validate)(struct nv30_context *nv30);
struct {
unsigned pipe;
unsigned hw;
} dirty;
};
extern void nv30_init_state_functions(struct nv30_context *nv30);
extern void nv30_init_surface_functions(struct nv30_context *nv30);
extern void nv30_init_query_functions(struct nv30_context *nv30);
extern void nv30_init_transfer_functions(struct nv30_context *nv30);
extern void nv30_screen_init_miptree_functions(struct pipe_screen *pscreen);
/* nv30_draw.c */
extern struct draw_stage *nv30_draw_render_stage(struct nv30_context *nv30);
/* nv30_vertprog.c */
extern void nv30_vertprog_destroy(struct nv30_context *,
struct nv30_vertex_program *);
/* nv30_fragprog.c */
extern void nv30_fragprog_destroy(struct nv30_context *,
struct nv30_fragment_program *);
/* nv30_fragtex.c */
extern void nv30_fragtex_bind(struct nv30_context *);
/* nv30_state.c and friends */
extern boolean nv30_state_validate(struct nv30_context *nv30);
extern void nv30_state_emit(struct nv30_context *nv30);
extern void nv30_state_flush_notify(struct nouveau_channel *chan);
extern struct nv30_state_entry nv30_state_rasterizer;
extern struct nv30_state_entry nv30_state_scissor;
extern struct nv30_state_entry nv30_state_stipple;
extern struct nv30_state_entry nv30_state_fragprog;
extern struct nv30_state_entry nv30_state_vertprog;
extern struct nv30_state_entry nv30_state_blend;
extern struct nv30_state_entry nv30_state_blend_colour;
extern struct nv30_state_entry nv30_state_zsa;
extern struct nv30_state_entry nv30_state_viewport;
extern struct nv30_state_entry nv30_state_framebuffer;
extern struct nv30_state_entry nv30_state_fragtex;
extern struct nv30_state_entry nv30_state_vbo;
extern struct nv30_state_entry nv30_state_sr;
/* nv30_vbo.c */
extern void nv30_draw_arrays(struct pipe_context *, unsigned mode,
unsigned start, unsigned count);
extern void nv30_draw_elements(struct pipe_context *pipe,
struct pipe_buffer *indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start,
unsigned count);
/* nv30_clear.c */
extern void nv30_clear(struct pipe_context *pipe, unsigned buffers,
const float *rgba, double depth, unsigned stencil);
/* nv30_context.c */
struct pipe_context *
nv30_create(struct pipe_screen *pscreen, void *priv);
#endif
#include "draw/draw_pipe.h"
#include "nv30_context.h"
struct nv30_draw_stage {
struct draw_stage draw;
struct nv30_context *nv30;
};
static void
nv30_draw_point(struct draw_stage *draw, struct prim_header *prim)
{
NOUVEAU_ERR("\n");
}
static void
nv30_draw_line(struct draw_stage *draw, struct prim_header *prim)
{
NOUVEAU_ERR("\n");
}
static void
nv30_draw_tri(struct draw_stage *draw, struct prim_header *prim)
{
NOUVEAU_ERR("\n");
}
static void
nv30_draw_flush(struct draw_stage *draw, unsigned flags)
{
}
static void
nv30_draw_reset_stipple_counter(struct draw_stage *draw)
{
NOUVEAU_ERR("\n");
}
static void
nv30_draw_destroy(struct draw_stage *draw)
{
FREE(draw);
}
struct draw_stage *
nv30_draw_render_stage(struct nv30_context *nv30)
{
struct nv30_draw_stage *nv30draw = CALLOC_STRUCT(nv30_draw_stage);
nv30draw->nv30 = nv30;
nv30draw->draw.draw = nv30->draw;
nv30draw->draw.point = nv30_draw_point;
nv30draw->draw.line = nv30_draw_line;
nv30draw->draw.tri = nv30_draw_tri;
nv30draw->draw.flush = nv30_draw_flush;
nv30draw->draw.reset_stipple_counter = nv30_draw_reset_stipple_counter;
nv30draw->draw.destroy = nv30_draw_destroy;
return &nv30draw->draw;
}
This diff is collapsed.
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_math.h"
#include "nv30_context.h"
#include "../nouveau/nv04_surface_2d.h"
static void
nv30_miptree_layout(struct nv30_miptree *nv30mt)
{
struct pipe_texture *pt = &nv30mt->base;
uint width = pt->width0;
uint offset = 0;
int nr_faces, l, f;
uint wide_pitch = pt->tex_usage & (PIPE_TEXTURE_USAGE_SAMPLER |
PIPE_TEXTURE_USAGE_DEPTH_STENCIL |
PIPE_TEXTURE_USAGE_RENDER_TARGET |
PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
PIPE_TEXTURE_USAGE_SCANOUT);
if (pt->target == PIPE_TEXTURE_CUBE) {
nr_faces = 6;
} else
if (pt->target == PIPE_TEXTURE_3D) {
nr_faces = pt->depth0;
} else {
nr_faces = 1;
}
for (l = 0; l <= pt->last_level; l++) {
if (wide_pitch && (pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR))
nv30mt->level[l].pitch = align(util_format_get_stride(pt->format, pt->width0), 64);
else
nv30mt->level[l].pitch = util_format_get_stride(pt->format, width);
nv30mt->level[l].image_offset =
CALLOC(nr_faces, sizeof(unsigned));
width = u_minify(width, 1);
}
for (f = 0; f < nr_faces; f++) {
for (l = 0; l < pt->last_level; l++) {
nv30mt->level[l].image_offset[f] = offset;
if (!(pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR) &&
u_minify(pt->width0, l + 1) > 1 && u_minify(pt->height0, l + 1) > 1)
offset += align(nv30mt->level[l].pitch * u_minify(pt->height0, l), 64);
else
offset += nv30mt->level[l].pitch * u_minify(pt->height0, l);
}
nv30mt->level[l].image_offset[f] = offset;
offset += nv30mt->level[l].pitch * u_minify(pt->height0, l);
}
nv30mt->total_size = offset;
}
static struct pipe_texture *
nv30_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt)
{
struct nv30_miptree *mt;
unsigned buf_usage = PIPE_BUFFER_USAGE_PIXEL |
NOUVEAU_BUFFER_USAGE_TEXTURE;
mt = MALLOC(sizeof(struct nv30_miptree));
if (!mt)
return NULL;
mt->base = *pt;
pipe_reference_init(&mt->base.reference, 1);
mt->base.screen = pscreen;
/* Swizzled textures must be POT */
if (pt->width0 & (pt->width0 - 1) ||
pt->height0 & (pt->height0 - 1))
mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
else
if (pt->tex_usage & (PIPE_TEXTURE_USAGE_SCANOUT |
PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
PIPE_TEXTURE_USAGE_DEPTH_STENCIL))
mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
else
if (pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC)
mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
else {
switch (pt->format) {
/* TODO: Figure out which formats can be swizzled */
case PIPE_FORMAT_B8G8R8A8_UNORM:
case PIPE_FORMAT_B8G8R8X8_UNORM:
case PIPE_FORMAT_R16_SNORM:
case PIPE_FORMAT_B5G6R5_UNORM:
case PIPE_FORMAT_L8A8_UNORM:
case PIPE_FORMAT_A8_UNORM:
case PIPE_FORMAT_L8_UNORM:
case PIPE_FORMAT_I8_UNORM:
{
if (debug_get_bool_option("NOUVEAU_NO_SWIZZLE", FALSE))
mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
break;
}
default:
mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
}
}
if (pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC)
buf_usage |= PIPE_BUFFER_USAGE_CPU_READ_WRITE;
/* apparently we can't render to swizzled surfaces smaller than 64 bytes, so make them linear.
* If the user did not ask for a render target, they can still render to it, but it will cost them an extra copy.
* This also happens for small mipmaps of large textures. */
if (pt->tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET && util_format_get_stride(pt->format, pt->width0) < 64)
mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
nv30_miptree_layout(mt);
mt->buffer = pscreen->buffer_create(pscreen, 256, buf_usage,
mt->total_size);
if (!mt->buffer) {
FREE(mt);
return NULL;
}
mt->bo = nouveau_bo(mt->buffer);
return &mt->base;
}
static struct pipe_texture *
nv30_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt,
const unsigned *stride, struct pipe_buffer *pb)
{
struct nv30_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(nv30_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));
/* Assume whoever created this buffer expects it to be linear for now */
mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
pipe_buffer_reference(&mt->buffer, pb);
mt->bo = nouveau_bo(mt->buffer);
return &mt->base;
}
static void
nv30_miptree_destroy(struct pipe_texture *pt)
{
struct nv30_miptree *mt = (struct nv30_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 *
nv30_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
unsigned face, unsigned level, unsigned zslice,
unsigned flags)
{
struct nv30_miptree *nv30mt = (struct nv30_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 = nv30mt->level[level].pitch;
if (pt->target == PIPE_TEXTURE_CUBE) {
ns->base.offset = nv30mt->level[level].image_offset[face];
} else
if (pt->target == PIPE_TEXTURE_3D) {
ns->base.offset = nv30mt->level[level].image_offset[zslice];
} else {
ns->base.offset = nv30mt->level[level].image_offset[0];
}
/* create a linear temporary that we can render into if necessary.
* Note that ns->pitch is always a multiple of 64 for linear surfaces and swizzled surfaces are POT, so
* ns->pitch & 63 is equivalent to (ns->pitch < 64 && swizzled)*/