glsl2: Add and use new variable mode ir_var_temporary
[mesa/nouveau-pmpeg.git] / src / gallium / drivers / nv50 / nv50_buffer.c
blobdacfee9799c89f8993ab7a0ecd61560fb96aba84
2 #include "util/u_inlines.h"
3 #include "util/u_memory.h"
4 #include "util/u_math.h"
6 #include "nouveau/nouveau_screen.h"
7 #include "nouveau/nouveau_winsys.h"
8 #include "nv50_resource.h"
12 static void nv50_buffer_destroy(struct pipe_screen *pscreen,
13 struct pipe_resource *presource)
15 struct nv50_resource *buffer = nv50_resource(presource);
17 nouveau_screen_bo_release(pscreen, buffer->bo);
18 FREE(buffer);
24 /* Utility functions for transfer create/destroy are hooked in and
25 * just record the arguments to those functions.
27 static void *
28 nv50_buffer_transfer_map( struct pipe_context *pipe,
29 struct pipe_transfer *transfer )
31 struct nv50_resource *buffer = nv50_resource(transfer->resource);
32 uint8_t *map;
34 map = nouveau_screen_bo_map_range( pipe->screen,
35 buffer->bo,
36 transfer->box.x,
37 transfer->box.width,
38 nouveau_screen_transfer_flags(transfer->usage) );
39 if (map == NULL)
40 return NULL;
42 return map + transfer->box.x;
47 static void nv50_buffer_transfer_flush_region( struct pipe_context *pipe,
48 struct pipe_transfer *transfer,
49 const struct pipe_box *box)
51 struct nv50_resource *buffer = nv50_resource(transfer->resource);
53 nouveau_screen_bo_map_flush_range(pipe->screen,
54 buffer->bo,
55 transfer->box.x + box->x,
56 box->width);
59 static void nv50_buffer_transfer_unmap( struct pipe_context *pipe,
60 struct pipe_transfer *transfer )
62 struct nv50_resource *buffer = nv50_resource(transfer->resource);
64 nouveau_screen_bo_unmap(pipe->screen, buffer->bo);
70 const struct u_resource_vtbl nv50_buffer_vtbl =
72 u_default_resource_get_handle, /* get_handle */
73 nv50_buffer_destroy, /* resource_destroy */
74 NULL, /* is_resource_referenced */
75 u_default_get_transfer, /* get_transfer */
76 u_default_transfer_destroy, /* transfer_destroy */
77 nv50_buffer_transfer_map, /* transfer_map */
78 nv50_buffer_transfer_flush_region, /* transfer_flush_region */
79 nv50_buffer_transfer_unmap, /* transfer_unmap */
80 u_default_transfer_inline_write /* transfer_inline_write */
86 struct pipe_resource *
87 nv50_buffer_create(struct pipe_screen *pscreen,
88 const struct pipe_resource *template)
90 struct nv50_resource *buffer;
92 buffer = CALLOC_STRUCT(nv50_resource);
93 if (!buffer)
94 return NULL;
96 buffer->base = *template;
97 buffer->vtbl = &nv50_buffer_vtbl;
98 pipe_reference_init(&buffer->base.reference, 1);
99 buffer->base.screen = pscreen;
101 buffer->bo = nouveau_screen_bo_new(pscreen,
103 buffer->base.usage,
104 buffer->base.bind,
105 buffer->base.width0);
107 if (buffer->bo == NULL)
108 goto fail;
110 return &buffer->base;
112 fail:
113 FREE(buffer);
114 return NULL;
118 struct pipe_resource *
119 nv50_user_buffer_create(struct pipe_screen *pscreen,
120 void *ptr,
121 unsigned bytes,
122 unsigned bind)
124 struct nv50_resource *buffer;
126 buffer = CALLOC_STRUCT(nv50_resource);
127 if (!buffer)
128 return NULL;
130 pipe_reference_init(&buffer->base.reference, 1);
131 buffer->vtbl = &nv50_buffer_vtbl;
132 buffer->base.screen = pscreen;
133 buffer->base.format = PIPE_FORMAT_R8_UNORM;
134 buffer->base.usage = PIPE_USAGE_IMMUTABLE;
135 buffer->base.bind = bind;
136 buffer->base.width0 = bytes;
137 buffer->base.height0 = 1;
138 buffer->base.depth0 = 1;
140 buffer->bo = nouveau_screen_bo_user(pscreen, ptr, bytes);
141 if (!buffer->bo)
142 goto fail;
144 return &buffer->base;
146 fail:
147 FREE(buffer);
148 return NULL;