• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "drm-uapi/drm_fourcc.h"
2 
3 #include "pipe/p_context.h"
4 #include "nvc0/nvc0_resource.h"
5 #include "nouveau_screen.h"
6 
7 
8 static struct pipe_resource *
nvc0_resource_create(struct pipe_screen * screen,const struct pipe_resource * templ)9 nvc0_resource_create(struct pipe_screen *screen,
10                      const struct pipe_resource *templ)
11 {
12    const uint64_t modifier = DRM_FORMAT_MOD_INVALID;
13 
14    switch (templ->target) {
15    case PIPE_BUFFER:
16       return nouveau_buffer_create(screen, templ);
17    default:
18       return nvc0_miptree_create(screen, templ, &modifier, 1);
19    }
20 }
21 
22 static struct pipe_resource *
nvc0_resource_create_with_modifiers(struct pipe_screen * screen,const struct pipe_resource * templ,const uint64_t * modifiers,int count)23 nvc0_resource_create_with_modifiers(struct pipe_screen *screen,
24                                     const struct pipe_resource *templ,
25                                     const uint64_t *modifiers, int count)
26 {
27    switch (templ->target) {
28    case PIPE_BUFFER:
29       return nouveau_buffer_create(screen, templ);
30    default:
31       return nvc0_miptree_create(screen, templ, modifiers, count);
32    }
33 }
34 
35 static void
nvc0_query_dmabuf_modifiers(struct pipe_screen * screen,enum pipe_format format,int max,uint64_t * modifiers,unsigned int * external_only,int * count)36 nvc0_query_dmabuf_modifiers(struct pipe_screen *screen,
37                             enum pipe_format format, int max,
38                             uint64_t *modifiers, unsigned int *external_only,
39                             int *count)
40 {
41    static const uint64_t supported_modifiers[] = {
42       DRM_FORMAT_MOD_LINEAR,
43       DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_ONE_GOB,
44       DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_TWO_GOB,
45       DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_FOUR_GOB,
46       DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_EIGHT_GOB,
47       DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_SIXTEEN_GOB,
48       DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_THIRTYTWO_GOB,
49    };
50    int i, num = 0;
51 
52    if (max > ARRAY_SIZE(supported_modifiers))
53       max = ARRAY_SIZE(supported_modifiers);
54 
55    if (!max) {
56       max = ARRAY_SIZE(supported_modifiers);
57       external_only = NULL;
58       modifiers = NULL;
59    }
60 
61    for (i = 0; i < max; i++) {
62       if (modifiers)
63          modifiers[num] = supported_modifiers[i];
64 
65       if (external_only)
66          external_only[num] = 0;
67 
68       num++;
69    }
70 
71    *count = num;
72 }
73 
74 static struct pipe_resource *
nvc0_resource_from_handle(struct pipe_screen * screen,const struct pipe_resource * templ,struct winsys_handle * whandle,unsigned usage)75 nvc0_resource_from_handle(struct pipe_screen * screen,
76                           const struct pipe_resource *templ,
77                           struct winsys_handle *whandle,
78                           unsigned usage)
79 {
80    if (templ->target == PIPE_BUFFER) {
81       return NULL;
82    } else {
83       struct pipe_resource *res = nv50_miptree_from_handle(screen,
84                                                            templ, whandle);
85       if (res)
86          nv04_resource(res)->vtbl = &nvc0_miptree_vtbl;
87       return res;
88    }
89 }
90 
91 static struct pipe_surface *
nvc0_surface_create(struct pipe_context * pipe,struct pipe_resource * pres,const struct pipe_surface * templ)92 nvc0_surface_create(struct pipe_context *pipe,
93                     struct pipe_resource *pres,
94                     const struct pipe_surface *templ)
95 {
96    if (unlikely(pres->target == PIPE_BUFFER))
97       return nv50_surface_from_buffer(pipe, pres, templ);
98    return nvc0_miptree_surface_new(pipe, pres, templ);
99 }
100 
101 static struct pipe_resource *
nvc0_resource_from_user_memory(struct pipe_screen * pipe,const struct pipe_resource * templ,void * user_memory)102 nvc0_resource_from_user_memory(struct pipe_screen *pipe,
103                                const struct pipe_resource *templ,
104                                void *user_memory)
105 {
106    ASSERTED struct nouveau_screen *screen = nouveau_screen(pipe);
107 
108    assert(screen->has_svm);
109    assert(templ->target == PIPE_BUFFER);
110 
111    return nouveau_buffer_create_from_user(pipe, templ, user_memory);
112 }
113 
114 void
nvc0_init_resource_functions(struct pipe_context * pcontext)115 nvc0_init_resource_functions(struct pipe_context *pcontext)
116 {
117    pcontext->transfer_map = u_transfer_map_vtbl;
118    pcontext->transfer_flush_region = u_transfer_flush_region_vtbl;
119    pcontext->transfer_unmap = u_transfer_unmap_vtbl;
120    pcontext->buffer_subdata = u_default_buffer_subdata;
121    pcontext->texture_subdata = u_default_texture_subdata;
122    pcontext->create_surface = nvc0_surface_create;
123    pcontext->surface_destroy = nv50_surface_destroy;
124    pcontext->invalidate_resource = nv50_invalidate_resource;
125 }
126 
127 void
nvc0_screen_init_resource_functions(struct pipe_screen * pscreen)128 nvc0_screen_init_resource_functions(struct pipe_screen *pscreen)
129 {
130    pscreen->resource_create = nvc0_resource_create;
131    pscreen->resource_create_with_modifiers = nvc0_resource_create_with_modifiers;
132    pscreen->query_dmabuf_modifiers = nvc0_query_dmabuf_modifiers;
133    pscreen->resource_from_handle = nvc0_resource_from_handle;
134    pscreen->resource_get_handle = u_resource_get_handle_vtbl;
135    pscreen->resource_destroy = u_resource_destroy_vtbl;
136    pscreen->resource_from_user_memory = nvc0_resource_from_user_memory;
137 }
138