v3d: Include commands to run the BCL and RCL in CLIF dumps.
[mesa.git] / src / gallium / drivers / tegra / tegra_screen.c
index 41bf2052f94536617017b19d9a9bd640af48736c..138060a249d006746244cb2702f2b24d6040f9d6 100644 (file)
@@ -228,7 +228,7 @@ static int tegra_screen_import_resource(struct tegra_screen *screen,
 
    memset(&handle, 0, sizeof(handle));
    handle.modifier = DRM_FORMAT_MOD_INVALID;
-   handle.type = DRM_API_HANDLE_TYPE_FD;
+   handle.type = WINSYS_HANDLE_TYPE_FD;
 
    status = screen->gpu->resource_get_handle(screen->gpu, NULL, resource->gpu,
                                              &handle, usage);
@@ -260,6 +260,7 @@ tegra_screen_resource_create(struct pipe_screen *pscreen,
                              const struct pipe_resource *template)
 {
    struct tegra_screen *screen = to_tegra_screen(pscreen);
+   uint64_t modifier = DRM_FORMAT_MOD_INVALID;
    struct tegra_resource *resource;
    int err;
 
@@ -267,7 +268,23 @@ tegra_screen_resource_create(struct pipe_screen *pscreen,
    if (!resource)
       return NULL;
 
-   resource->gpu = screen->gpu->resource_create(screen->gpu, template);
+   /*
+    * Applications that create scanout resources without modifiers are very
+    * unlikely to support modifiers at all. In that case the resources need
+    * to be created with a pitch-linear layout so that they can be properly
+    * shared with scanout hardware.
+    *
+    * Technically it is possible for applications to create resources without
+    * specifying a modifier but still query the modifier associated with the
+    * resource (e.g. using gbm_bo_get_modifier()) before handing it to the
+    * framebuffer creation API (such as the DRM_IOCTL_MODE_ADDFB2 IOCTL).
+    */
+   if (template->bind & PIPE_BIND_SCANOUT)
+      modifier = DRM_FORMAT_MOD_LINEAR;
+
+   resource->gpu = screen->gpu->resource_create_with_modifiers(screen->gpu,
+                                                               template,
+                                                               &modifier, 1);
    if (!resource->gpu)
       goto free;
 
@@ -369,7 +386,7 @@ tegra_screen_resource_get_handle(struct pipe_screen *pscreen,
     * to pass buffers into Tegra DRM for display. In all other cases, return
     * the Nouveau handle, assuming they will be used for sharing in DRI2/3.
     */
-   if (handle->type == DRM_API_HANDLE_TYPE_KMS &&
+   if (handle->type == WINSYS_HANDLE_TYPE_KMS &&
        presource->bind & PIPE_BIND_SCANOUT) {
       handle->modifier = resource->modifier;
       handle->handle = resource->handle;
@@ -498,6 +515,7 @@ tegra_screen_resource_create_with_modifiers(struct pipe_screen *pscreen,
                                             int count)
 {
    struct tegra_screen *screen = to_tegra_screen(pscreen);
+   struct pipe_resource tmpl = *template;
    struct tegra_resource *resource;
    int err;
 
@@ -505,8 +523,18 @@ tegra_screen_resource_create_with_modifiers(struct pipe_screen *pscreen,
    if (!resource)
       return NULL;
 
+   /*
+    * Assume that resources created with modifiers will always be used for
+    * scanout. This is necessary because some of the APIs that are used to
+    * create resources with modifiers (e.g. gbm_bo_create_with_modifiers())
+    * can't pass along usage information. Adding that capability might be
+    * worth adding to remove this ambiguity. Not all future use-cases that
+    * involve modifiers may always be targetting scanout hardware.
+    */
+   tmpl.bind |= PIPE_BIND_SCANOUT;
+
    resource->gpu = screen->gpu->resource_create_with_modifiers(screen->gpu,
-                                                               template,
+                                                               &tmpl,
                                                                modifiers,
                                                                count);
    if (!resource->gpu)