nv50, nvc0: initialize ctx->sample_mask to ~0
[mesa.git] / src / gallium / drivers / nouveau / nouveau_screen.c
index 7437779997754590230b5739c8898f0c47270f78..21b31e04f0a79b912494962a2d20254f1ad77744 100644 (file)
@@ -8,10 +8,14 @@
 #include "util/u_format_s3tc.h"
 #include "util/u_string.h"
 
+#include "os/os_time.h"
+
 #include <stdio.h>
 #include <errno.h>
 #include <stdlib.h>
 
+#include <libdrm/nouveau_drm.h>
+
 #include "nouveau_winsys.h"
 #include "nouveau_screen.h"
 #include "nouveau_fence.h"
@@ -39,6 +43,16 @@ nouveau_screen_get_vendor(struct pipe_screen *pscreen)
        return "nouveau";
 }
 
+static uint64_t
+nouveau_screen_get_timestamp(struct pipe_screen *pscreen)
+{
+       int64_t cpu_time = os_time_get() * 1000;
+
+        /* getparam of PTIMER_TIME takes about x10 as long (several usecs) */
+
+       return cpu_time + nouveau_screen(pscreen)->cpu_gpu_time_delta;
+}
+
 static void
 nouveau_screen_fence_ref(struct pipe_screen *pscreen,
                         struct pipe_fence_handle **ptr,
@@ -71,8 +85,19 @@ nouveau_screen_bo_from_handle(struct pipe_screen *pscreen,
        struct nouveau_device *dev = nouveau_screen(pscreen)->device;
        struct nouveau_bo *bo = 0;
        int ret;
-       ret = nouveau_bo_name_ref(dev, whandle->handle, &bo);
+
+       if (whandle->type != DRM_API_HANDLE_TYPE_SHARED &&
+           whandle->type != DRM_API_HANDLE_TYPE_FD) {
+               debug_printf("%s: attempt to import unsupported handle type %d\n",
+                            __FUNCTION__, whandle->type);
+               return NULL;
+       }
+
+       if (whandle->type == DRM_API_HANDLE_TYPE_SHARED)
+               ret = nouveau_bo_name_ref(dev, whandle->handle, &bo);
+       else
+               ret = nouveau_bo_prime_handle_ref(dev, whandle->handle, &bo);
+
        if (ret) {
                debug_printf("%s: ref name 0x%08x failed with %d\n",
                             __FUNCTION__, whandle->handle, ret);
@@ -92,11 +117,13 @@ nouveau_screen_bo_get_handle(struct pipe_screen *pscreen,
 {
        whandle->stride = stride;
 
-       if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { 
+       if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) {
                return nouveau_bo_name_get(bo, &whandle->handle) == 0;
        } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) {
                whandle->handle = bo->handle;
                return TRUE;
+       } else if (whandle->type == DRM_API_HANDLE_TYPE_FD) {
+               return nouveau_bo_set_prime(bo, &whandle->handle) == 0;
        } else {
                return FALSE;
        }
@@ -108,6 +135,7 @@ nouveau_screen_init(struct nouveau_screen *screen, struct nouveau_device *dev)
        struct pipe_screen *pscreen = &screen->base;
        struct nv04_fifo nv04_data = { .vram = 0xbeef0201, .gart = 0xbeef0202 };
        struct nvc0_fifo nvc0_data = { };
+       uint64_t time;
        int size, ret;
        void *data;
        union nouveau_bo_config mm_config;
@@ -139,15 +167,34 @@ nouveau_screen_init(struct nouveau_screen *screen, struct nouveau_device *dev)
        if (ret)
                return ret;
 
+        /* getting CPU time first appears to be more accurate */
+        screen->cpu_gpu_time_delta = os_time_get();
+
+        ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_PTIMER_TIME, &time);
+        if (!ret)
+           screen->cpu_gpu_time_delta = time - screen->cpu_gpu_time_delta * 1000;
+
        pscreen->get_name = nouveau_screen_get_name;
        pscreen->get_vendor = nouveau_screen_get_vendor;
 
+       pscreen->get_timestamp = nouveau_screen_get_timestamp;
+
        pscreen->fence_reference = nouveau_screen_fence_ref;
        pscreen->fence_signalled = nouveau_screen_fence_signalled;
        pscreen->fence_finish = nouveau_screen_fence_finish;
 
        util_format_s3tc_init();
 
+       screen->lowmem_bindings = PIPE_BIND_GLOBAL; /* gallium limit */
+       screen->vidmem_bindings =
+               PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL |
+               PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_SCANOUT | PIPE_BIND_CURSOR |
+               PIPE_BIND_SAMPLER_VIEW |
+               PIPE_BIND_SHADER_RESOURCE | PIPE_BIND_COMPUTE_RESOURCE |
+               PIPE_BIND_GLOBAL;
+       screen->sysmem_bindings =
+               PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_STREAM_OUTPUT;
+
        memset(&mm_config, 0, sizeof(mm_config));
 
        screen->mm_GART = nouveau_mm_create(dev,