1
2 #include "pipe/p_context.h"
3 #include "nvc0/nvc0_resource.h"
4 #include "nouveau_screen.h"
5
6
7 static struct pipe_resource *
nvc0_resource_create(struct pipe_screen * screen,const struct pipe_resource * templ)8 nvc0_resource_create(struct pipe_screen *screen,
9 const struct pipe_resource *templ)
10 {
11 switch (templ->target) {
12 case PIPE_BUFFER:
13 return nouveau_buffer_create(screen, templ);
14 default:
15 return nvc0_miptree_create(screen, templ);
16 }
17 }
18
19 static struct pipe_resource *
nvc0_resource_from_handle(struct pipe_screen * screen,const struct pipe_resource * templ,struct winsys_handle * whandle,unsigned usage)20 nvc0_resource_from_handle(struct pipe_screen * screen,
21 const struct pipe_resource *templ,
22 struct winsys_handle *whandle,
23 unsigned usage)
24 {
25 if (templ->target == PIPE_BUFFER) {
26 return NULL;
27 } else {
28 struct pipe_resource *res = nv50_miptree_from_handle(screen,
29 templ, whandle);
30 if (res)
31 nv04_resource(res)->vtbl = &nvc0_miptree_vtbl;
32 return res;
33 }
34 }
35
36 static struct pipe_surface *
nvc0_surface_create(struct pipe_context * pipe,struct pipe_resource * pres,const struct pipe_surface * templ)37 nvc0_surface_create(struct pipe_context *pipe,
38 struct pipe_resource *pres,
39 const struct pipe_surface *templ)
40 {
41 if (unlikely(pres->target == PIPE_BUFFER))
42 return nv50_surface_from_buffer(pipe, pres, templ);
43 return nvc0_miptree_surface_new(pipe, pres, templ);
44 }
45
46 void
nvc0_init_resource_functions(struct pipe_context * pcontext)47 nvc0_init_resource_functions(struct pipe_context *pcontext)
48 {
49 pcontext->transfer_map = u_transfer_map_vtbl;
50 pcontext->transfer_flush_region = u_transfer_flush_region_vtbl;
51 pcontext->transfer_unmap = u_transfer_unmap_vtbl;
52 pcontext->buffer_subdata = u_default_buffer_subdata;
53 pcontext->texture_subdata = u_default_texture_subdata;
54 pcontext->create_surface = nvc0_surface_create;
55 pcontext->surface_destroy = nv50_surface_destroy;
56 pcontext->invalidate_resource = nv50_invalidate_resource;
57 }
58
59 void
nvc0_screen_init_resource_functions(struct pipe_screen * pscreen)60 nvc0_screen_init_resource_functions(struct pipe_screen *pscreen)
61 {
62 pscreen->resource_create = nvc0_resource_create;
63 pscreen->resource_from_handle = nvc0_resource_from_handle;
64 pscreen->resource_get_handle = u_resource_get_handle_vtbl;
65 pscreen->resource_destroy = u_resource_destroy_vtbl;
66 }
67