Debian Codegraph @

src/gallium/drivers/nouveau/nv50/nv50_resource.c

raw
1
2 #include "pipe/p_context.h"
3 #include "util/u_inlines.h"
4 #include "util/format/u_format.h"
5
6 #include "nouveau_context.h"
7 #include "nouveau_screen.h"
8
9 #include "nv50/nv50_resource.h"
10
11 static struct pipe_resource *
12 nv50_resource_create(struct pipe_screen *screen,
13 const struct pipe_resource *templ)
14 {
15 switch (templ->target) {
16 case PIPE_BUFFER:
17 return nouveau_buffer_create(screen, templ);
18 default:
19 return nv50_miptree_create(screen, templ);
20 }
21 }
22
23 static void
24 nv50_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *res)
25 {
26 if (res->target == PIPE_BUFFER)
27 nouveau_buffer_destroy(pscreen, res);
28 else
29 nv50_miptree_destroy(pscreen, res);
30 }
31
32 static struct pipe_resource *
33 nv50_resource_from_handle(struct pipe_screen * screen,
34 const struct pipe_resource *templ,
35 struct winsys_handle *whandle,
36 unsigned usage)
37 {
38 if (templ->target == PIPE_BUFFER)
39 return NULL;
40 else
41 return nv50_miptree_from_handle(screen, templ, whandle);
42 }
43
44 void
45 nv50_surface_destroy(struct pipe_context *pipe, struct pipe_surface *ps)
46 {
47 struct nv50_surface *s = nv50_surface(ps);
48
49 pipe_resource_reference(&ps->texture, NULL);
50
51 FREE(s);
52 }
53
54 void
55 nv50_framebuffer_init(struct pipe_context *pctx,
56 const struct pipe_framebuffer_state *fb,
57 struct pipe_surface **cbufs,
58 struct pipe_surface **zsbuf)
59 {
60 return nv_framebuffer_init(pctx, fb, cbufs, zsbuf,
61 nv50_miptree_surface_new,
62 nv50_surface_destroy);
63 }
64
65 void
66 nv50_invalidate_resource(struct pipe_context *pipe, struct pipe_resource *res)
67 {
68 if (res->target == PIPE_BUFFER)
69 nouveau_buffer_invalidate(pipe, res);
70 }
71
72 struct pipe_memory_object *
73 nv50_memobj_create_from_handle(struct pipe_screen *screen,
74 struct winsys_handle *handle,
75 bool dedicated)
76 {
77 struct nv50_memobj *memobj = CALLOC_STRUCT(nv50_memobj);
78
79 memobj->bo = nouveau_screen_bo_from_handle(screen, handle, &memobj->stride);
80 if (memobj->bo == NULL) {
81 FREE(memobj);
82 return NULL;
83 }
84 memobj->handle = handle;
85 memobj->b.dedicated = dedicated;
86
87 return &memobj->b;
88 }
89
90 void
91 nv50_memobj_destroy(struct pipe_screen *screen,
92 struct pipe_memory_object *pmemobj)
93 {
94 struct nv50_memobj *memobj = (struct nv50_memobj *)pmemobj;
95
96 free(memobj->handle);
97 free(memobj->bo);
98 free(memobj);
99 }
100
101 struct pipe_resource *
102 nv50_resource_from_memobj(struct pipe_screen *screen,
103 const struct pipe_resource *templ,
104 struct pipe_memory_object *pmemobj,
105 uint64_t offset)
106 {
107 struct nv50_miptree *mt;
108 struct nv50_memobj *memobj = (struct nv50_memobj *)pmemobj;
109
110 /* only supports 2D, non-mipmapped textures for the moment */
111 if ((templ->target != PIPE_TEXTURE_2D &&
112 templ->target != PIPE_TEXTURE_RECT) ||
113 templ->last_level != 0 ||
114 templ->depth0 != 1 ||
115 templ->array_size > 1)
116 return NULL;
117
118 mt = CALLOC_STRUCT(nv50_miptree);
119 if (!mt)
120 return NULL;
121
122 mt->base.bo = memobj->bo;
123
124 mt->base.domain = mt->base.bo->flags & NOUVEAU_BO_APER;
125 mt->base.address = mt->base.bo->offset;
126
127 mt->base.base = *templ;
128 pipe_reference_init(&mt->base.base.reference, 1);
129 mt->base.base.screen = screen;
130 mt->level[0].offset = 0;
131 mt->level[0].tile_mode = mt->base.bo->config.nv50.tile_mode;
132
133 NOUVEAU_DRV_STAT(nouveau_screen(screen), tex_obj_current_count, 1);
134
135 /* no need to adjust bo reference count */
136 return &mt->base.base;
137 }
138
139 void
140 nv50_init_resource_functions(struct pipe_context *pcontext)
141 {
142 pcontext->buffer_map = nouveau_buffer_transfer_map;
143 pcontext->texture_map = nv50_miptree_transfer_map;
144 pcontext->transfer_flush_region = nouveau_buffer_transfer_flush_region;
145 pcontext->buffer_unmap = nouveau_buffer_transfer_unmap;
146 pcontext->texture_unmap = nv50_miptree_transfer_unmap;
147 pcontext->buffer_subdata = u_default_buffer_subdata;
148 pcontext->texture_subdata = u_default_texture_subdata;
149 pcontext->surface_destroy = nv50_surface_destroy;
150 pcontext->invalidate_resource = nv50_invalidate_resource;
151 }
152
153 void
154 nv50_screen_init_resource_functions(struct pipe_screen *pscreen)
155 {
156 pscreen->resource_create = nv50_resource_create;
157 pscreen->resource_from_handle = nv50_resource_from_handle;
158 pscreen->resource_get_handle = nv50_miptree_get_handle;
159 pscreen->resource_destroy = nv50_resource_destroy;
160
161 pscreen->memobj_create_from_handle = nv50_memobj_create_from_handle;
162 pscreen->resource_from_memobj = nv50_resource_from_memobj;
163 pscreen->memobj_destroy = nv50_memobj_destroy;
164 }