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->depth[0] != 1)
+ return NULL;
+
+ mt = CALLOC_STRUCT(nv04_miptree);
+ if (!mt)
+ return NULL;
+
+ mt->base = *pt;
+ mt->base.refcount = 1;
+ mt->base.screen = pscreen;
+ mt->level[0].image_offset = CALLOC(1, sizeof(unsigned));
+
+ pipe_buffer_reference(pscreen, &mt->buffer, pb);
+ return &mt->base;
+}
+
static void
nv04_miptree_release(struct pipe_screen *pscreen, struct pipe_texture **ppt)
{
nv04_screen_init_miptree_functions(struct pipe_screen *pscreen)
{
pscreen->texture_create = nv04_miptree_create;
+ pscreen->texture_blanket = nv04_miptree_blanket;
pscreen->texture_release = nv04_miptree_release;
pscreen->get_tex_surface = nv04_miptree_surface_new;
pscreen->tex_surface_release = nv04_miptree_surface_del;
}
static struct pipe_texture *
+nv10_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt,
+ const unsigned *stride, struct pipe_buffer *pb)
+{
+ struct nv10_miptree *mt;
+
+ /* Only supports 2D, non-mipmapped textures for the moment */
+ if (pt->target != PIPE_TEXTURE_2D || pt->last_level != 0 ||
+ pt->depth[0] != 1)
+ return NULL;
+
+ mt = CALLOC_STRUCT(nv10_miptree);
+ if (!mt)
+ return NULL;
+
+ mt->base = *pt;
+ mt->base.refcount = 1;
+ mt->base.screen = pscreen;
+ mt->level[0].image_offset = CALLOC(1, sizeof(unsigned));
+
+ pipe_buffer_reference(pscreen, &mt->buffer, pb);
+ return &mt->base;
+}
+
+static struct pipe_texture *
nv10_miptree_create(struct pipe_screen *screen, const struct pipe_texture *pt)
{
struct pipe_winsys *ws = screen->winsys;
void nv10_screen_init_miptree_functions(struct pipe_screen *pscreen)
{
pscreen->texture_create = nv10_miptree_create;
+ pscreen->texture_blanket = nv10_miptree_blanket;
pscreen->texture_release = nv10_miptree_release;
pscreen->get_tex_surface = nv10_miptree_surface_get;
pscreen->tex_surface_release = nv10_miptree_surface_release;
}
static struct pipe_texture *
+nv20_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt,
+ const unsigned *stride, struct pipe_buffer *pb)
+{
+ struct nv20_miptree *mt;
+
+ /* Only supports 2D, non-mipmapped textures for the moment */
+ if (pt->target != PIPE_TEXTURE_2D || pt->last_level != 0 ||
+ pt->depth[0] != 1)
+ return NULL;
+
+ mt = CALLOC_STRUCT(nv20_miptree);
+ if (!mt)
+ return NULL;
+
+ mt->base = *pt;
+ mt->base.refcount = 1;
+ mt->base.screen = pscreen;
+ mt->level[0].image_offset = CALLOC(1, sizeof(unsigned));
+
+ pipe_buffer_reference(pscreen, &mt->buffer, pb);
+ return &mt->base;
+}
+
+static struct pipe_texture *
nv20_miptree_create(struct pipe_screen *screen, const struct pipe_texture *pt)
{
struct pipe_winsys *ws = screen->winsys;
void nv20_screen_init_miptree_functions(struct pipe_screen *pscreen)
{
pscreen->texture_create = nv20_miptree_create;
+ pscreen->texture_blanket = nv20_miptree_blanket;
pscreen->texture_release = nv20_miptree_release;
pscreen->get_tex_surface = nv20_miptree_surface_get;
pscreen->tex_surface_release = nv20_miptree_surface_release;
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->depth[0] != 1)
+ return NULL;
+
+ mt = CALLOC_STRUCT(nv30_miptree);
+ if (!mt)
+ return NULL;
+
+ mt->base = *pt;
+ mt->base.refcount = 1;
+ mt->base.screen = pscreen;
+ mt->level[0].image_offset = CALLOC(1, sizeof(unsigned));
+
+ pipe_buffer_reference(pscreen, &mt->buffer, pb);
+ return &mt->base;
+}
+
static void
nv30_miptree_release(struct pipe_screen *pscreen, struct pipe_texture **ppt)
{
nv30_screen_init_miptree_functions(struct pipe_screen *pscreen)
{
pscreen->texture_create = nv30_miptree_create;
+ pscreen->texture_blanket = nv30_miptree_blanket;
pscreen->texture_release = nv30_miptree_release;
pscreen->get_tex_surface = nv30_miptree_surface_new;
pscreen->tex_surface_release = nv30_miptree_surface_del;
return &mt->base;
}
+static struct pipe_texture *
+nv40_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt,
+ const unsigned *stride, struct pipe_buffer *pb)
+{
+ struct nv40_miptree *mt;
+
+ /* Only supports 2D, non-mipmapped textures for the moment */
+ if (pt->target != PIPE_TEXTURE_2D || pt->last_level != 0 ||
+ pt->depth[0] != 1)
+ return NULL;
+
+ mt = CALLOC_STRUCT(nv40_miptree);
+ if (!mt)
+ return NULL;
+
+ mt->base = *pt;
+ mt->base.refcount = 1;
+ mt->base.screen = pscreen;
+ mt->level[0].image_offset = CALLOC(1, sizeof(unsigned));
+
+ pipe_buffer_reference(pscreen, &mt->buffer, pb);
+ return &mt->base;
+}
+
static void
nv40_miptree_release(struct pipe_screen *pscreen, struct pipe_texture **ppt)
{
nv40_screen_init_miptree_functions(struct pipe_screen *pscreen)
{
pscreen->texture_create = nv40_miptree_create;
+ pscreen->texture_blanket = nv40_miptree_blanket;
pscreen->texture_release = nv40_miptree_release;
pscreen->get_tex_surface = nv40_miptree_surface_new;
pscreen->tex_surface_release = nv40_miptree_surface_del;
return &mt->base;
}
+static struct pipe_texture *
+nv50_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt,
+ const unsigned *stride, struct pipe_buffer *pb)
+{
+ struct nv50_miptree *mt;
+
+ /* Only supports 2D, non-mipmapped textures for the moment */
+ if (pt->target != PIPE_TEXTURE_2D || pt->last_level != 0 ||
+ pt->depth[0] != 1)
+ return NULL;
+
+ mt = CALLOC_STRUCT(nv50_miptree);
+ if (!mt)
+ return NULL;
+
+ mt->base = *pt;
+ mt->base.refcount = 1;
+ mt->base.screen = pscreen;
+ mt->image_nr = 1;
+ mt->level[0].image_offset = CALLOC(1, sizeof(unsigned));
+
+ pipe_buffer_reference(pscreen, &mt->buffer, pb);
+ return &mt->base;
+}
+
static INLINE void
mark_dirty(uint32_t *flags, unsigned image)
{
nv50_screen_init_miptree_functions(struct pipe_screen *pscreen)
{
pscreen->texture_create = nv50_miptree_create;
+ pscreen->texture_blanket = nv50_miptree_blanket;
pscreen->texture_release = nv50_miptree_release;
pscreen->get_tex_surface = nv50_miptree_surface_new;
pscreen->tex_surface_release = nv50_miptree_surface_del;
nvdev->lock = sarea_lock;
}
- /*XXX: Hack up a fake region and buffer object for front buffer.
- * This will go away with TTM, replaced with a simple reference
- * of the front buffer handle passed to us by the DDX.
- */
- {
- struct pipe_surface *fb_surf;
- struct nouveau_pipe_buffer *fb_buf;
-
- fb_buf = calloc(1, sizeof(struct nouveau_pipe_buffer));
-
- nouveau_bo_fake(dev, nv_screen->front_offset, NOUVEAU_BO_VRAM,
- nv_screen->front_pitch*nv_screen->front_height,
- NULL, &fb_buf->bo);
-
- fb_surf = calloc(1, sizeof(struct pipe_surface));
- if (nv_screen->front_cpp == 2)
- fb_surf->format = PIPE_FORMAT_R5G6B5_UNORM;
- else
- fb_surf->format = PIPE_FORMAT_A8R8G8B8_UNORM;
- pf_get_block(fb_surf->format, &fb_surf->block);
- fb_surf->width = nv_screen->front_pitch / nv_screen->front_cpp;
- fb_surf->height = nv_screen->front_height;
- fb_surf->stride = fb_surf->width * fb_surf->block.size;
- fb_surf->refcount = 1;
- fb_surf->buffer = &fb_buf->base;
-
- nv->frontbuffer = fb_surf;
- }
-
/* Attempt to share a single channel between multiple contexts from
* a single process.
*/
}
}
- pipe->priv = nv;
+ {
+ struct pipe_texture *fb_tex;
+ struct pipe_surface *fb_surf;
+ struct nouveau_pipe_buffer *fb_buf;
+ enum pipe_format format;
+
+ fb_buf = calloc(1, sizeof(struct nouveau_pipe_buffer));
+ fb_buf->base.refcount = 1;
+ fb_buf->base.usage = PIPE_BUFFER_USAGE_PIXEL;
+
+ nouveau_bo_fake(dev, nv_screen->front_offset, NOUVEAU_BO_VRAM,
+ nv_screen->front_pitch*nv_screen->front_height,
+ NULL, &fb_buf->bo);
+
+ if (nv_screen->front_cpp == 4)
+ format = PIPE_FORMAT_A8R8G8B8_UNORM;
+ else
+ format = PIPE_FORMAT_R5G6B5_UNORM;
+
+ fb_surf = nouveau_surface_buffer_ref(nv, &fb_buf->base, format,
+ nv_screen->front_pitch /
+ nv_screen->front_cpp,
+ nv_screen->front_height,
+ nv_screen->front_pitch,
+ &fb_tex);
+ nv->frontbuffer = fb_surf;
+ nv->frontbuffer_texture = fb_tex;
+ }
+
+ pipe->priv = nv;
return 0;
}
int locked;
struct nouveau_screen *nv_screen;
struct pipe_surface *frontbuffer;
+ struct pipe_texture *frontbuffer_texture;
struct {
int hw_vertex_buffer;
struct pipe_buffer *buf, uint32_t data,
uint32_t flags, uint32_t vor, uint32_t tor)
{
- return nouveau_pushbuf_emit_reloc(nvws->channel, ptr,
- nouveau_buffer(buf)->bo,
+ struct nouveau_bo *bo = ((struct nouveau_pipe_buffer *)buf)->bo;
+
+ return nouveau_pushbuf_emit_reloc(nvws->channel, ptr, bo,
data, flags, vor, tor);
}
static void
nouveau_pipe_bo_del(struct pipe_winsys *ws, struct pipe_buffer *buf)
{
- struct nouveau_pipe_buffer *nvbuf = nouveau_buffer(buf);
+ struct nouveau_pipe_buffer *nvbuf = (void *)buf;
nouveau_bo_ref(NULL, &nvbuf->bo);
FREE(nvbuf);
nouveau_pipe_bo_map(struct pipe_winsys *pws, struct pipe_buffer *buf,
unsigned flags)
{
- struct nouveau_pipe_buffer *nvbuf = nouveau_buffer(buf);
+ struct nouveau_pipe_buffer *nvbuf = (void *)buf;
uint32_t map_flags = 0;
if (flags & PIPE_BUFFER_USAGE_CPU_READ)
static void
nouveau_pipe_bo_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf)
{
- struct nouveau_pipe_buffer *nvbuf = nouveau_buffer(buf);
+ struct nouveau_pipe_buffer *nvbuf = (void *)buf;
nouveau_bo_unmap(nvbuf->bo);
}
return 0;
}
+struct pipe_surface *
+nouveau_surface_buffer_ref(struct nouveau_context *nv, struct pipe_buffer *pb,
+ enum pipe_format format, int w, int h,
+ unsigned pitch, struct pipe_texture **ppt)
+{
+ struct pipe_screen *pscreen = nv->nvc->pscreen;
+ struct pipe_texture tmpl, *pt;
+ struct pipe_surface *ps;
+
+ memset(&tmpl, 0, sizeof(tmpl));
+ tmpl.tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
+ NOUVEAU_TEXTURE_USAGE_LINEAR;
+ tmpl.target = PIPE_TEXTURE_2D;
+ tmpl.width[0] = w;
+ tmpl.height[0] = h;
+ tmpl.depth[0] = 1;
+ tmpl.format = format;
+ pf_get_block(tmpl.format, &tmpl.block);
+ tmpl.nblocksx[0] = pf_get_nblocksx(&tmpl.block, w);
+ tmpl.nblocksy[0] = pf_get_nblocksy(&tmpl.block, h);
+
+ pt = pscreen->texture_blanket(pscreen, &tmpl, &pitch, pb);
+ if (!pt)
+ return NULL;
+
+ ps = pscreen->get_tex_surface(pscreen, pt, 0, 0, 0,
+ PIPE_BUFFER_USAGE_GPU_WRITE);
+
+ *ppt = pt;
+ return ps;
+}
+
static void
nouveau_destroy(struct pipe_winsys *pws)
{
struct nouveau_bo *bo;
};
+/* This is so horrible I should be shot - I promise I'll fix it properly
+ * tomorrow. Just to make the winsys build again however... The TG guys
+ * don't like to make life easy :)
+ */
static inline struct nouveau_pipe_buffer *
-nouveau_buffer(struct pipe_buffer *buf)
+nouveau_buffer(struct pipe_surface *ps)
{
- return (struct nouveau_pipe_buffer *)buf;
+ return *(struct nouveau_pipe_buffer **)
+ ((void *)ps->texture + sizeof(struct pipe_texture));
}
struct nouveau_pipe_winsys {
nouveau_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *surf,
void *context_private);
+struct pipe_surface *
+nouveau_surface_buffer_ref(struct nouveau_context *nv, struct pipe_buffer *pb,
+ enum pipe_format format, int w, int h,
+ unsigned pitch, struct pipe_texture **ppt);
+
#endif
assert(!(w & (w - 1)) && !(h & (h - 1)));
BEGIN_RING(chan, nv->nvc->NvSwzSurf, NV04_SWIZZLED_SURFACE_DMA_IMAGE, 1);
- OUT_RELOCo(chan, nouveau_buffer(dst->buffer)->bo,
+ OUT_RELOCo(chan, nouveau_buffer(dst)->bo,
NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
BEGIN_RING(chan, nv->nvc->NvSwzSurf, NV04_SWIZZLED_SURFACE_FORMAT, 1);
OUT_RING (chan, nv04_surface_format(dst->format) |
log2i(h) << NV04_SWIZZLED_SURFACE_FORMAT_BASE_SIZE_V_SHIFT);
BEGIN_RING(chan, nv->nvc->NvSIFM, NV04_SCALED_IMAGE_FROM_MEMORY_DMA_IMAGE, 1);
- OUT_RELOCo(chan, nouveau_buffer(src->buffer)->bo,
+ OUT_RELOCo(chan, nouveau_buffer(src)->bo,
NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
BEGIN_RING(chan, nv->nvc->NvSIFM, NV04_SCALED_IMAGE_FROM_MEMORY_SURFACE, 1);
OUT_RING (chan, nv->nvc->NvSwzSurf->handle);
for (cy = 0; cy < h; cy += sub_h) {
for (cx = 0; cx < w; cx += sub_w) {
BEGIN_RING(chan, nv->nvc->NvSwzSurf, NV04_SWIZZLED_SURFACE_OFFSET, 1);
- OUT_RELOCl(chan, nouveau_buffer(dst->buffer)->bo,
+ OUT_RELOCl(chan, nouveau_buffer(dst)->bo,
dst->offset + nv04_swizzle_bits(cx, cy) * dst->block.size,
NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
OUT_RING (chan, src->stride |
NV04_SCALED_IMAGE_FROM_MEMORY_FORMAT_ORIGIN_CENTER |
NV04_SCALED_IMAGE_FROM_MEMORY_FORMAT_FILTER_POINT_SAMPLE);
- OUT_RELOCl(chan, nouveau_buffer(src->buffer)->bo,
+ OUT_RELOCl(chan, nouveau_buffer(src)->bo,
src->offset + cy * src->stride + cx * src->block.size,
NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
OUT_RING (chan, 0);
BEGIN_RING(chan, nv->nvc->NvM2MF,
NV04_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8);
- OUT_RELOCl(chan, nouveau_buffer(src->buffer)->bo, src_offset,
+ OUT_RELOCl(chan, nouveau_buffer(src)->bo, src_offset,
NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD);
- OUT_RELOCl(chan, nouveau_buffer(dst->buffer)->bo, dst_offset,
+ OUT_RELOCl(chan, nouveau_buffer(dst)->bo, dst_offset,
NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_WR);
OUT_RING (chan, src->stride);
OUT_RING (chan, dst->stride);
if ((src->offset & 63) || (dst->offset & 63)) {
BEGIN_RING(nv->nvc->channel, nv->nvc->NvM2MF,
NV04_MEMORY_TO_MEMORY_FORMAT_DMA_BUFFER_IN, 2);
- OUT_RELOCo(chan, nouveau_buffer(src->buffer)->bo,
+ OUT_RELOCo(chan, nouveau_buffer(src)->bo,
NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
- OUT_RELOCo(chan, nouveau_buffer(dst->buffer)->bo,
+ OUT_RELOCo(chan, nouveau_buffer(dst)->bo,
NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
nv->surface_copy = nv04_surface_copy_m2mf;
BEGIN_RING(chan, nv->nvc->NvCtxSurf2D,
NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2);
- OUT_RELOCo(chan, nouveau_buffer(src->buffer)->bo,
+ OUT_RELOCo(chan, nouveau_buffer(src)->bo,
NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
- OUT_RELOCo(chan, nouveau_buffer(dst->buffer)->bo,
+ OUT_RELOCo(chan, nouveau_buffer(dst)->bo,
NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
BEGIN_RING(chan, nv->nvc->NvCtxSurf2D,
NV04_CONTEXT_SURFACES_2D_FORMAT, 4);
OUT_RING (chan, format);
OUT_RING (chan, (dst->stride << 16) | src->stride);
- OUT_RELOCl(chan, nouveau_buffer(src->buffer)->bo, src->offset,
+ OUT_RELOCl(chan, nouveau_buffer(src)->bo, src->offset,
NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
- OUT_RELOCl(chan, nouveau_buffer(dst->buffer)->bo, dst->offset,
+ OUT_RELOCl(chan, nouveau_buffer(dst)->bo, dst->offset,
NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
return 0;
}
BEGIN_RING(chan, surf2d, NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2);
- OUT_RELOCo(chan, nouveau_buffer(dst->buffer)->bo,
+ OUT_RELOCo(chan, nouveau_buffer(dst)->bo,
NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- OUT_RELOCo(chan, nouveau_buffer(dst->buffer)->bo,
+ OUT_RELOCo(chan, nouveau_buffer(dst)->bo,
NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
BEGIN_RING(chan, surf2d, NV04_CONTEXT_SURFACES_2D_FORMAT, 4);
OUT_RING (chan, cs2d_format);
OUT_RING (chan, (dst->stride << 16) | dst->stride);
- OUT_RELOCl(chan, nouveau_buffer(dst->buffer)->bo, dst->offset,
+ OUT_RELOCl(chan, nouveau_buffer(dst)->bo, dst->offset,
NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
- OUT_RELOCl(chan, nouveau_buffer(dst->buffer)->bo, dst->offset,
+ OUT_RELOCl(chan, nouveau_buffer(dst)->bo, dst->offset,
NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
BEGIN_RING(chan, rect, NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT, 1);
{
struct nouveau_channel *chan = nv->nvc->channel;
struct nouveau_grobj *eng2d = nv->nvc->Nv2D;
- struct nouveau_bo *bo = nouveau_buffer(surf->buffer)->bo;
+ struct nouveau_bo *bo = nouveau_buffer(surf)->bo;
int surf_format, mthd = dst ? NV50_2D_DST_FORMAT : NV50_2D_SRC_FORMAT;
int flags = NOUVEAU_BO_VRAM | (dst ? NOUVEAU_BO_WR : NOUVEAU_BO_RD);