14c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
24c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "pipe/p_context.h"
34c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nvc0_resource.h"
44c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nouveau/nouveau_screen.h"
54c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
64c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
74c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic struct pipe_resource *
84c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_resource_create(struct pipe_screen *screen,
94c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_resource *templ)
104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   switch (templ->target) {
124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_BUFFER:
134826cd0f6125b071530026143ffd8205d84b3d5eBen Skeggs      return nouveau_buffer_create(screen, templ);
144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   default:
154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      return nvc0_miptree_create(screen, templ);
164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic struct pipe_resource *
204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_resource_from_handle(struct pipe_screen * screen,
214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          const struct pipe_resource *templ,
224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          struct winsys_handle *whandle)
234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
24cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller   if (templ->target == PIPE_BUFFER) {
254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      return NULL;
26cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller   } else {
27cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller      struct pipe_resource *res = nv50_miptree_from_handle(screen,
28cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller                                                           templ, whandle);
29cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller      nv04_resource(res)->vtbl = &nvc0_miptree_vtbl;
30cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller      return res;
31cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller   }
324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3428271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumillerstatic struct pipe_surface *
3528271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumillernvc0_surface_create(struct pipe_context *pipe,
3628271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller                    struct pipe_resource *pres,
3728271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller                    const struct pipe_surface *templ)
3828271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller{
3928271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller   if (unlikely(pres->target == PIPE_BUFFER))
4028271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller      return nv50_surface_from_buffer(pipe, pres, templ);
4128271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller   return nvc0_miptree_surface_new(pipe, pres, templ);
4228271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller}
4328271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller
444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillervoid
454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_init_resource_functions(struct pipe_context *pcontext)
464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pcontext->get_transfer = u_get_transfer_vtbl;
484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pcontext->transfer_map = u_transfer_map_vtbl;
494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pcontext->transfer_flush_region = u_transfer_flush_region_vtbl;
504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pcontext->transfer_unmap = u_transfer_unmap_vtbl;
514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pcontext->transfer_destroy = u_transfer_destroy_vtbl;
524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pcontext->transfer_inline_write = u_transfer_inline_write_vtbl;
5328271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller   pcontext->create_surface = nvc0_surface_create;
5428271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller   pcontext->surface_destroy = nv50_surface_destroy;
554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillervoid
584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_screen_init_resource_functions(struct pipe_screen *pscreen)
594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pscreen->resource_create = nvc0_resource_create;
614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pscreen->resource_from_handle = nvc0_resource_from_handle;
624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pscreen->resource_get_handle = u_resource_get_handle_vtbl;
634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pscreen->resource_destroy = u_resource_destroy_vtbl;
644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
65