1 #include "drm-uapi/drm_fourcc.h"
3 #include "pipe/p_context.h"
4 #include "nvc0/nvc0_resource.h"
5 #include "nouveau_screen.h"
8 static struct pipe_resource
*
9 nvc0_resource_create(struct pipe_screen
*screen
,
10 const struct pipe_resource
*templ
)
12 const uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
14 switch (templ
->target
) {
16 return nouveau_buffer_create(screen
, templ
);
18 return nvc0_miptree_create(screen
, templ
, &modifier
, 1);
22 static struct pipe_resource
*
23 nvc0_resource_create_with_modifiers(struct pipe_screen
*screen
,
24 const struct pipe_resource
*templ
,
25 const uint64_t *modifiers
, int count
)
27 switch (templ
->target
) {
29 return nouveau_buffer_create(screen
, templ
);
31 return nvc0_miptree_create(screen
, templ
, modifiers
, 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
,
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
,
52 if (max
> ARRAY_SIZE(supported_modifiers
))
53 max
= ARRAY_SIZE(supported_modifiers
);
56 max
= ARRAY_SIZE(supported_modifiers
);
61 for (i
= 0; i
< max
; i
++) {
63 modifiers
[num
] = supported_modifiers
[i
];
66 external_only
[num
] = 0;
74 static struct pipe_resource
*
75 nvc0_resource_from_handle(struct pipe_screen
* screen
,
76 const struct pipe_resource
*templ
,
77 struct winsys_handle
*whandle
,
80 if (templ
->target
== PIPE_BUFFER
) {
83 struct pipe_resource
*res
= nv50_miptree_from_handle(screen
,
86 nv04_resource(res
)->vtbl
= &nvc0_miptree_vtbl
;
91 static struct pipe_surface
*
92 nvc0_surface_create(struct pipe_context
*pipe
,
93 struct pipe_resource
*pres
,
94 const struct pipe_surface
*templ
)
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
);
101 static struct pipe_resource
*
102 nvc0_resource_from_user_memory(struct pipe_screen
*pipe
,
103 const struct pipe_resource
*templ
,
106 ASSERTED
struct nouveau_screen
*screen
= nouveau_screen(pipe
);
108 assert(screen
->has_svm
);
109 assert(templ
->target
== PIPE_BUFFER
);
111 return nouveau_buffer_create_from_user(pipe
, templ
, user_memory
);
115 nvc0_init_resource_functions(struct pipe_context
*pcontext
)
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
;
128 nvc0_screen_init_resource_functions(struct pipe_screen
*pscreen
)
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
;