Debian Codegraph @

src/gallium/drivers/nouveau/nvc0/nvc0_resource.c

raw
1 #include "drm-uapi/drm_fourcc.h"
2
3 #include "pipe/p_context.h"
4 #include "nvc0/nvc0_resource.h"
5 #include "nouveau_context.h"
6 #include "nouveau_screen.h"
7
8
9 static struct pipe_resource *
10 nvc0_resource_create(struct pipe_screen *screen,
11 const struct pipe_resource *templ)
12 {
13 switch (templ->target) {
14 case PIPE_BUFFER:
15 return nouveau_buffer_create(screen, templ);
16 default:
17 return nvc0_miptree_create(screen, templ, NULL, 0);
18 }
19 }
20
21 static struct pipe_resource *
22 nvc0_resource_create_with_modifiers(struct pipe_screen *screen,
23 const struct pipe_resource *templ,
24 const uint64_t *modifiers, int count)
25 {
26 switch (templ->target) {
27 case PIPE_BUFFER:
28 return nouveau_buffer_create(screen, templ);
29 default:
30 return nvc0_miptree_create(screen, templ, modifiers, count);
31 }
32 }
33
34 static void
35 nvc0_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *res)
36 {
37 if (res->target == PIPE_BUFFER)
38 nouveau_buffer_destroy(pscreen, res);
39 else
40 nv50_miptree_destroy(pscreen, res);
41 }
42
43 static void
44 nvc0_query_dmabuf_modifiers(struct pipe_screen *screen,
45 enum pipe_format format, int max,
46 uint64_t *modifiers, unsigned int *external_only,
47 int *count)
48 {
49 const int s = nouveau_screen(screen)->tegra_sector_layout ? 0 : 1;
50 const uint32_t uc_kind =
51 nvc0_choose_tiled_storage_type(screen, format, 0, false);
52 const uint32_t num_uc = uc_kind ? 6 : 0; /* max block height = 32 GOBs */
53 const int num_supported = num_uc + 1; /* LINEAR is always supported */
54 const uint32_t kind_gen = nvc0_get_kind_generation(screen);
55 int i, num = 0;
56
57 if (max > num_supported)
58 max = num_supported;
59
60 if (!max) {
61 max = num_supported;
62 external_only = NULL;
63 modifiers = NULL;
64 }
65
66 #define NVC0_ADD_MOD(m) do { \
67 if (modifiers) modifiers[num] = m; \
68 if (external_only) external_only[num] = 0; \
69 num++; \
70 } while (0)
71
72 for (i = 0; i < max && i < num_uc; i++)
73 NVC0_ADD_MOD(DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, s, kind_gen,
74 uc_kind, 5 - i));
75
76 if (i < max)
77 NVC0_ADD_MOD(DRM_FORMAT_MOD_LINEAR);
78
79 #undef NVC0_ADD_MOD
80
81 *count = num;
82 }
83
84 static bool
85 nvc0_is_dmabuf_modifier_supported(struct pipe_screen *screen,
86 uint64_t modifier, enum pipe_format format,
87 bool *external_only)
88 {
89 const int s = nouveau_screen(screen)->tegra_sector_layout ? 0 : 1;
90 const uint32_t uc_kind =
91 nvc0_choose_tiled_storage_type(screen, format, 0, false);
92 const uint32_t num_uc = uc_kind ? 6 : 0; /* max block height = 32 GOBs */
93 const uint32_t kind_gen = nvc0_get_kind_generation(screen);
94 int i;
95
96 if (modifier == DRM_FORMAT_MOD_LINEAR) {
97 if (external_only)
98 *external_only = false;
99
100 return true;
101 }
102
103 for (i = 0; i < num_uc; i++) {
104 if (DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, s, kind_gen, uc_kind, i) == modifier) {
105 if (external_only)
106 *external_only = false;
107
108 return true;
109 }
110 }
111
112 return false;
113 }
114
115 static struct pipe_resource *
116 nvc0_resource_from_handle(struct pipe_screen * screen,
117 const struct pipe_resource *templ,
118 struct winsys_handle *whandle,
119 unsigned usage)
120 {
121 if (templ->target == PIPE_BUFFER) {
122 return NULL;
123 } else {
124 struct pipe_resource *res = nv50_miptree_from_handle(screen,
125 templ, whandle);
126 return res;
127 }
128 }
129
130 void
131 nvc0_framebuffer_init(struct pipe_context *pctx,
132 const struct pipe_framebuffer_state *fb,
133 struct pipe_surface **cbufs,
134 struct pipe_surface **zsbuf)
135 {
136 return nv_framebuffer_init(pctx, fb, cbufs, zsbuf,
137 nvc0_miptree_surface_new,
138 nv50_surface_destroy);
139 }
140
141 static struct pipe_resource *
142 nvc0_resource_from_user_memory(struct pipe_screen *pipe,
143 const struct pipe_resource *templ,
144 void *user_memory)
145 {
146 struct nouveau_screen *screen = nouveau_screen(pipe);
147 if (!screen->has_svm || templ->target != PIPE_BUFFER)
148 return NULL;
149 return nouveau_buffer_create_from_user(pipe, templ, user_memory);
150 }
151
152 void
153 nvc0_init_resource_functions(struct pipe_context *pcontext)
154 {
155 pcontext->buffer_map = nouveau_buffer_transfer_map;
156 pcontext->texture_map = nvc0_miptree_transfer_map;
157 pcontext->transfer_flush_region = nouveau_buffer_transfer_flush_region;
158 pcontext->buffer_unmap = nouveau_buffer_transfer_unmap;
159 pcontext->texture_unmap = nvc0_miptree_transfer_unmap;
160 pcontext->buffer_subdata = u_default_buffer_subdata;
161 pcontext->texture_subdata = u_default_texture_subdata;
162 pcontext->invalidate_resource = nv50_invalidate_resource;
163 }
164
165 void
166 nvc0_screen_init_resource_functions(struct pipe_screen *pscreen)
167 {
168 pscreen->resource_create = nvc0_resource_create;
169 pscreen->resource_create_with_modifiers = nvc0_resource_create_with_modifiers;
170 pscreen->query_dmabuf_modifiers = nvc0_query_dmabuf_modifiers;
171 pscreen->is_dmabuf_modifier_supported = nvc0_is_dmabuf_modifier_supported;
172 pscreen->resource_from_handle = nvc0_resource_from_handle;
173 pscreen->resource_get_handle = nvc0_miptree_get_handle;
174 pscreen->resource_destroy = nvc0_resource_destroy;
175 pscreen->resource_from_user_memory = nvc0_resource_from_user_memory;
176
177 pscreen->memobj_create_from_handle = nv50_memobj_create_from_handle;
178 pscreen->resource_from_memobj = nv50_resource_from_memobj;
179 pscreen->memobj_destroy = nv50_memobj_destroy;
180 }