Merge remote branch 'origin/7.8'
[mesa.git] / src / gallium / drivers / nvfx / nvfx_resource.c
1
2 #include "pipe/p_context.h"
3 #include "nvfx_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 nvfx_resource_is_referenced(struct pipe_context *pipe,
17 struct pipe_resource *resource,
18 unsigned face, unsigned level)
19 {
20 return nouveau_reference_flags(nvfx_resource(resource)->bo);
21 }
22
23 static struct pipe_resource *
24 nvfx_resource_create(struct pipe_screen *screen,
25 const struct pipe_resource *template)
26 {
27 if (template->target == PIPE_BUFFER)
28 return nvfx_buffer_create(screen, template);
29 else
30 return nvfx_miptree_create(screen, template);
31 }
32
33 static struct pipe_resource *
34 nvfx_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 nvfx_miptree_from_handle(screen, template, whandle);
42 }
43
44 void
45 nvfx_init_resource_functions(struct pipe_context *pipe)
46 {
47 pipe->get_transfer = u_get_transfer_vtbl;
48 pipe->transfer_map = u_transfer_map_vtbl;
49 pipe->transfer_flush_region = u_transfer_flush_region_vtbl;
50 pipe->transfer_unmap = u_transfer_unmap_vtbl;
51 pipe->transfer_destroy = u_transfer_destroy_vtbl;
52 pipe->transfer_inline_write = u_transfer_inline_write_vtbl;
53 pipe->is_resource_referenced = nvfx_resource_is_referenced;
54 }
55
56 void
57 nvfx_screen_init_resource_functions(struct pipe_screen *pscreen)
58 {
59 pscreen->resource_create = nvfx_resource_create;
60 pscreen->resource_from_handle = nvfx_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 = nvfx_user_buffer_create;
64
65 pscreen->get_tex_surface = nvfx_miptree_surface_new;
66 pscreen->tex_surface_destroy = nvfx_miptree_surface_del;
67 }