r600g: fix invalid ref count handling in r600_set_constant_buffer
[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 level, int layer)
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 pcontext->create_surface = nv50_miptree_surface_new;
56 pcontext->surface_destroy = nv50_miptree_surface_del;
57 }
58
59 void
60 nv50_screen_init_resource_functions(struct pipe_screen *pscreen)
61 {
62 pscreen->resource_create = nv50_resource_create;
63 pscreen->resource_from_handle = nv50_resource_from_handle;
64 pscreen->resource_get_handle = u_resource_get_handle_vtbl;
65 pscreen->resource_destroy = u_resource_destroy_vtbl;
66 pscreen->user_buffer_create = nv50_user_buffer_create;
67 }