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
);
24 /* Utility functions for transfer create/destroy are hooked in and
25 * just record the arguments to those functions.
28 nv50_buffer_transfer_map( struct pipe_context
*pipe
,
29 struct pipe_transfer
*transfer
)
31 struct nv50_resource
*buffer
= nv50_resource(transfer
->resource
);
34 map
= nouveau_screen_bo_map_range( pipe
->screen
,
38 nouveau_screen_transfer_flags(transfer
->usage
) );
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
,
55 transfer
->box
.x
+ box
->x
,
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
);
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
,
105 buffer
->base
.width0
);
107 if (buffer
->bo
== NULL
)
110 return &buffer
->base
;
118 struct pipe_resource
*
119 nv50_user_buffer_create(struct pipe_screen
*pscreen
,
124 struct nv50_resource
*buffer
;
126 buffer
= CALLOC_STRUCT(nv50_resource
);
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
);
144 return &buffer
->base
;