Squashed commit of the following:
[profile/ivi/mesa.git] / src / gallium / drivers / nv50 / nv50_resource.c
1
2 #include "pipe/p_context.h"
3 #include "nv50_resource.h"
4 #include "nouveau/nouveau_screen.h"
5
6
7 /* This doesn't look quite right - this query is supposed to ask
8  * whether the particular context has references to the resource in
9  * any unflushed rendering command buffer, and hence requires a
10  * pipe->flush() for serializing some modification to that resource.
11  *
12  * This seems to be answering the question of whether the resource is
13  * currently on hardware.
14  */
15 static unsigned int
16 nv50_resource_is_referenced(struct pipe_context *pipe,
17                             struct pipe_resource *resource,
18                             unsigned face, unsigned level)
19 {
20         return nouveau_reference_flags(nv50_resource(resource)->bo);
21 }
22
23 static struct pipe_resource *
24 nv50_resource_create(struct pipe_screen *screen,
25                      const struct pipe_resource *template)
26 {
27         if (template->target == PIPE_BUFFER)
28                 return nv50_buffer_create(screen, template);
29         else
30                 return nv50_miptree_create(screen, template);
31 }
32
33 static struct pipe_resource *
34 nv50_resource_from_handle(struct pipe_screen * screen,
35                           const struct pipe_resource *template,
36                           struct winsys_handle *whandle)
37 {
38         if (template->target == PIPE_BUFFER)
39                 return NULL;
40         else
41                 return nv50_miptree_from_handle(screen, template, whandle);
42 }
43
44 void
45 nv50_init_resource_functions(struct pipe_context *pcontext)
46 {
47         pcontext->get_transfer = u_get_transfer_vtbl;
48         pcontext->transfer_map = u_transfer_map_vtbl;
49         pcontext->transfer_flush_region = u_transfer_flush_region_vtbl;
50         pcontext->transfer_unmap = u_transfer_unmap_vtbl;
51         pcontext->transfer_destroy = u_transfer_destroy_vtbl;
52         pcontext->transfer_inline_write = u_transfer_inline_write_vtbl;
53         pcontext->is_resource_referenced = nv50_resource_is_referenced;
54 }
55
56 void
57 nv50_screen_init_resource_functions(struct pipe_screen *pscreen)
58 {
59         pscreen->resource_create = nv50_resource_create;
60         pscreen->resource_from_handle = nv50_resource_from_handle;
61         pscreen->resource_get_handle = u_resource_get_handle_vtbl;
62         pscreen->resource_destroy = u_resource_destroy_vtbl;
63         pscreen->user_buffer_create = nv50_user_buffer_create;
64    
65         pscreen->get_tex_surface = nv50_miptree_surface_new;
66         pscreen->tex_surface_destroy = nv50_miptree_surface_del;
67 }