gallium: remove pipe_index_buffer and set_index_buffer
[mesa.git] / src / gallium / drivers / nouveau / nv30 / nv30_resource.c
1 /*
2 * Copyright 2012 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 *
24 */
25
26 #include "util/u_format.h"
27 #include "util/u_inlines.h"
28
29 #include "nv30/nv30_screen.h"
30 #include "nv30/nv30_context.h"
31 #include "nv30/nv30_resource.h"
32 #include "nv30/nv30_transfer.h"
33
34 static void
35 nv30_memory_barrier(struct pipe_context *pipe, unsigned flags)
36 {
37 struct nv30_context *nv30 = nv30_context(pipe);
38 int i;
39
40 if (flags & PIPE_BARRIER_MAPPED_BUFFER) {
41 for (i = 0; i < nv30->num_vtxbufs; ++i) {
42 if (!nv30->vtxbuf[i].buffer.resource)
43 continue;
44 if (nv30->vtxbuf[i].buffer.resource->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)
45 nv30->base.vbo_dirty = true;
46 }
47 }
48 }
49
50 static struct pipe_resource *
51 nv30_resource_create(struct pipe_screen *pscreen,
52 const struct pipe_resource *tmpl)
53 {
54 switch (tmpl->target) {
55 case PIPE_BUFFER:
56 return nouveau_buffer_create(pscreen, tmpl);
57 default:
58 return nv30_miptree_create(pscreen, tmpl);
59 }
60 }
61
62 static struct pipe_resource *
63 nv30_resource_from_handle(struct pipe_screen *pscreen,
64 const struct pipe_resource *tmpl,
65 struct winsys_handle *handle,
66 unsigned usage)
67 {
68 if (tmpl->target == PIPE_BUFFER)
69 return NULL;
70 else
71 return nv30_miptree_from_handle(pscreen, tmpl, handle);
72 }
73
74 void
75 nv30_resource_screen_init(struct pipe_screen *pscreen)
76 {
77 pscreen->resource_create = nv30_resource_create;
78 pscreen->resource_from_handle = nv30_resource_from_handle;
79 pscreen->resource_get_handle = u_resource_get_handle_vtbl;
80 pscreen->resource_destroy = u_resource_destroy_vtbl;
81 }
82
83 void
84 nv30_resource_init(struct pipe_context *pipe)
85 {
86 pipe->transfer_map = u_transfer_map_vtbl;
87 pipe->transfer_flush_region = u_transfer_flush_region_vtbl;
88 pipe->transfer_unmap = u_transfer_unmap_vtbl;
89 pipe->buffer_subdata = u_default_buffer_subdata;
90 pipe->texture_subdata = u_default_texture_subdata;
91 pipe->create_surface = nv30_miptree_surface_new;
92 pipe->surface_destroy = nv30_miptree_surface_del;
93 pipe->resource_copy_region = nv30_resource_copy_region;
94 pipe->blit = nv30_blit;
95 pipe->flush_resource = nv30_flush_resource;
96 pipe->memory_barrier = nv30_memory_barrier;
97 }