nv50: fixes after rebase + commits note on the code that was just pushed.
[mesa.git] / src / gallium / drivers / nv50 / nv50_miptree.c
1 #include "pipe/p_state.h"
2 #include "pipe/p_defines.h"
3 #include "pipe/p_util.h"
4 #include "pipe/p_inlines.h"
5
6 #include "nv50_context.h"
7
8 static struct pipe_texture *
9 nv50_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt)
10 {
11 struct pipe_winsys *ws = pscreen->winsys;
12 struct nv50_miptree *mt = CALLOC_STRUCT(nv50_miptree);
13 unsigned usage, pitch;
14
15 mt->base = *pt;
16 mt->base.refcount = 1;
17 mt->base.screen = pscreen;
18
19 usage = PIPE_BUFFER_USAGE_PIXEL;
20 switch (pt->format) {
21 case PIPE_FORMAT_Z24S8_UNORM:
22 case PIPE_FORMAT_Z16_UNORM:
23 usage |= NOUVEAU_BUFFER_USAGE_ZETA;
24 break;
25 default:
26 break;
27 }
28
29 pitch = ((pt->width[0] + 63) & ~63) * pt->block.size;
30
31 mt->buffer = ws->buffer_create(ws, 256, usage, pitch * pt->height[0]);
32 if (!mt->buffer) {
33 FREE(mt);
34 return NULL;
35 }
36
37 return &mt->base;
38 }
39
40 static void
41 nv50_miptree_release(struct pipe_screen *pscreen, struct pipe_texture **ppt)
42 {
43 struct pipe_winsys *ws = pscreen->winsys;
44 struct pipe_texture *pt = *ppt;
45
46 *ppt = NULL;
47
48 if (--pt->refcount <= 0) {
49 struct nv50_miptree *mt = nv50_miptree(pt);
50
51 pipe_buffer_reference(ws, &mt->buffer, NULL);
52 FREE(mt);
53 }
54 }
55
56 static struct pipe_surface *
57 nv50_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
58 unsigned face, unsigned level, unsigned zslice,
59 unsigned flags)
60 {
61 struct pipe_winsys *ws = pscreen->winsys;
62 struct nv50_miptree *mt = nv50_miptree(pt);
63 struct pipe_surface *ps;
64
65 ps = CALLOC_STRUCT(pipe_surface);
66 ps->refcount = 1;
67 ps->winsys = ws;
68 ps->format = pt->format;
69 ps->width = pt->width[level];
70 ps->height = pt->height[level];
71 ps->block = pt->block;
72 ps->nblocksx = pt->nblocksx[level];
73 ps->nblocksy = pt->nblocksy[level];
74 ps->stride = ps->width * ps->block.size;
75 ps->offset = 0;
76 ps->usage = flags;
77 ps->status = PIPE_SURFACE_STATUS_DEFINED;
78
79 pipe_texture_reference(&ps->texture, pt);
80 pipe_buffer_reference(ws, &ps->buffer, mt->buffer);
81
82 return ps;
83 }
84
85 static void
86 nv50_miptree_surface_del(struct pipe_screen *pscreen,
87 struct pipe_surface **psurface)
88 {
89 struct pipe_winsys *ws = pscreen->winsys;
90 struct pipe_surface *surf = *psurface;
91
92 *psurface = NULL;
93
94 if (--surf->refcount <= 0) {
95 pipe_texture_reference(&surf->texture, NULL);
96 pipe_buffer_reference(ws, &surf->buffer, NULL);
97 FREE(surf);
98 }
99 }
100
101 void
102 nv50_screen_init_miptree_functions(struct pipe_screen *pscreen)
103 {
104 pscreen->texture_create = nv50_miptree_create;
105 pscreen->texture_release = nv50_miptree_release;
106 pscreen->get_tex_surface = nv50_miptree_surface_new;
107 pscreen->tex_surface_release = nv50_miptree_surface_del;
108 }
109