android: freedreno: move a2xx disasm out of gallium
[mesa.git] / src / gallium / winsys / svga / drm / vmw_context.c
index 00c401a01749ffbb2aa3a8f9a079787d4dc8822f..da7506e779702def2bb4304ca86da50c0d9f76bf 100644 (file)
@@ -65,6 +65,7 @@
 #define VMW_MAX_SURF_MEM_FACTOR 2
 
 
+
 struct vmw_buffer_relocation
 {
    struct pb_buffer *buffer;
@@ -95,7 +96,7 @@ struct vmw_svga_winsys_context
    struct svga_winsys_context base;
 
    struct vmw_winsys_screen *vws;
-   struct util_hash_table *hash;
+   struct hash_table *hash;
 
 #ifdef DEBUG
    boolean must_flush;
@@ -161,10 +162,10 @@ vmw_svga_winsys_context(struct svga_winsys_context *swc)
 }
 
 
-static inline unsigned
+static inline enum pb_usage_flags
 vmw_translate_to_pb_flags(unsigned flags)
 {
-   unsigned f = 0;
+   enum pb_usage_flags f = 0;
    if (flags & SVGA_RELOC_READ)
       f |= PB_USAGE_GPU_READ;
 
@@ -196,17 +197,17 @@ vmw_swc_flush(struct svga_winsys_context *swc,
 
    ret = pb_validate_validate(vswc->validate);
    if (ret != PIPE_OK) {
-      pipe_mutex_lock(vws->cs_mutex);
+      mtx_lock(&vws->cs_mutex);
       while (ret == PIPE_ERROR_RETRY) {
          ret = pb_validate_validate(vswc->validate);
          if (ret == PIPE_ERROR_RETRY) {
-            pipe_condvar_wait(vws->cs_cond, vws->cs_mutex);
+            cnd_wait(&vws->cs_cond, &vws->cs_mutex);
          }
       }
       if (ret != PIPE_OK) {
-         pipe_condvar_broadcast(vws->cs_cond);
+         cnd_broadcast(&vws->cs_cond);
       }
-      pipe_mutex_unlock(vws->cs_mutex);
+      mtx_unlock(&vws->cs_mutex);
    }
 
    assert(ret == PIPE_OK);
@@ -236,16 +237,18 @@ vmw_swc_flush(struct svga_winsys_context *swc,
 
       if (vswc->command.used || pfence != NULL)
          vmw_ioctl_command(vws,
-                          vswc->base.cid,
-                          0,
+                           vswc->base.cid,
+                           0,
                            vswc->command.buffer,
                            vswc->command.used,
-                           &fence);
+                           &fence,
+                           vswc->base.imported_fence_fd,
+                           vswc->base.hints);
 
       pb_validate_fence(vswc->validate, fence);
-      pipe_mutex_lock(vws->cs_mutex);
-      pipe_condvar_broadcast(vws->cs_cond);
-      pipe_mutex_unlock(vws->cs_mutex);
+      mtx_lock(&vws->cs_mutex);
+      cnd_broadcast(&vws->cs_cond);
+      mtx_unlock(&vws->cs_mutex);
    }
 
    vswc->command.used = 0;
@@ -258,7 +261,7 @@ vmw_swc_flush(struct svga_winsys_context *swc,
       vmw_svga_winsys_surface_reference(&isurf->vsurf, NULL);
    }
 
-   util_hash_table_clear(vswc->hash);
+   _mesa_hash_table_clear(vswc->hash, NULL);
    vswc->surface.used = 0;
    vswc->surface.reserved = 0;
 
@@ -280,11 +283,17 @@ vmw_swc_flush(struct svga_winsys_context *swc,
    debug_flush_flush(vswc->fctx);
 #endif
    swc->hints &= ~SVGA_HINT_FLAG_CAN_PRE_FLUSH;
+   swc->hints &= ~SVGA_HINT_FLAG_EXPORT_FENCE_FD;
    vswc->preemptive_flush = FALSE;
    vswc->seen_surfaces = 0;
    vswc->seen_regions = 0;
    vswc->seen_mobs = 0;
 
+   if (vswc->base.imported_fence_fd != -1) {
+      close(vswc->base.imported_fence_fd);
+      vswc->base.imported_fence_fd = -1;
+   }
+
    if(pfence)
       vmw_fence_reference(vswc->vws, pfence, fence);
 
@@ -362,24 +371,15 @@ vmw_swc_add_validate_buffer(struct vmw_svga_winsys_context *vswc,
                            struct pb_buffer *pb_buf,
                            unsigned flags)
 {
-   enum pipe_error ret;
+   ASSERTED enum pipe_error ret;
    unsigned translated_flags;
+   boolean already_present;
 
-   /*
-    * TODO: Update pb_validate to provide a similar functionality
-    * (Check buffer already present before adding)
-    */
-   if (util_hash_table_get(vswc->hash, pb_buf) != pb_buf) {
-      translated_flags = vmw_translate_to_pb_flags(flags);
-      ret = pb_validate_add_buffer(vswc->validate, pb_buf, translated_flags);
-      /* TODO: Update pipebuffer to reserve buffers and not fail here */
-      assert(ret == PIPE_OK);
-      (void)ret;
-      (void)util_hash_table_set(vswc->hash, pb_buf, pb_buf);
-      return TRUE;
-   }
-
-   return FALSE;
+   translated_flags = vmw_translate_to_pb_flags(flags);
+   ret = pb_validate_add_buffer(vswc->validate, pb_buf, translated_flags,
+                                vswc->hash, &already_present);
+   assert(ret == PIPE_OK);
+   return !already_present;
 }
 
 static void
@@ -505,12 +505,8 @@ vmw_swc_surface_only_relocation(struct svga_winsys_context *swc,
       isrf = &vswc->surface.items[vswc->surface.used + vswc->surface.staged];
       vmw_svga_winsys_surface_reference(&isrf->vsurf, vsurf);
       isrf->referenced = FALSE;
-      /*
-       * Note that a failure here may just fall back to unhashed behavior
-       * and potentially cause unnecessary flushing, so ignore the
-       * return code.
-       */
-      (void) util_hash_table_set(vswc->hash, vsurf, isrf);
+
+      _mesa_hash_table_insert(vswc->hash, vsurf, isrf);
       ++vswc->surface.staged;
 
       vswc->seen_surfaces += vsurf->size;
@@ -558,7 +554,15 @@ vmw_swc_surface_relocation(struct svga_winsys_context *swc,
 
       mtx_lock(&vsurf->mutex);
       assert(vsurf->buf != NULL);
-      
+
+      /*
+       * An internal reloc means that the surface transfer direction
+       * is opposite to the MOB transfer direction...
+       */
+      if ((flags & SVGA_RELOC_INTERNAL) &&
+          (flags & (SVGA_RELOC_READ | SVGA_RELOC_WRITE)) !=
+          (SVGA_RELOC_READ | SVGA_RELOC_WRITE))
+         flags ^= (SVGA_RELOC_READ | SVGA_RELOC_WRITE);
       vmw_swc_mob_relocation(swc, mobid, NULL, (struct svga_winsys_buffer *)
                              vsurf->buf, 0, flags);
       mtx_unlock(&vsurf->mutex);
@@ -593,12 +597,8 @@ vmw_swc_shader_relocation(struct svga_winsys_context *swc,
          ishader = &vswc->shader.items[vswc->shader.used + vswc->shader.staged];
          vmw_svga_winsys_shader_reference(&ishader->vshader, vshader);
          ishader->referenced = FALSE;
-         /*
-          * Note that a failure here may just fall back to unhashed behavior
-          * and potentially cause unnecessary flushing, so ignore the
-          * return code.
-          */
-         (void) util_hash_table_set(vswc->hash, vshader, ishader);
+
+         _mesa_hash_table_insert(vswc->hash, vshader, ishader);
          ++vswc->shader.staged;
       }
 
@@ -675,7 +675,7 @@ vmw_swc_destroy(struct svga_winsys_context *swc)
       vmw_svga_winsys_shader_reference(&ishader->vshader, NULL);
    }
 
-   util_hash_table_destroy(vswc->hash);
+   _mesa_hash_table_destroy(vswc->hash, NULL);
    pb_validate_destroy(vswc->validate);
    vmw_ioctl_context_destroy(vswc->vws, swc->cid);
 #ifdef DEBUG
@@ -684,17 +684,6 @@ vmw_swc_destroy(struct svga_winsys_context *swc)
    FREE(vswc);
 }
 
-static unsigned vmw_hash_ptr(void *p)
-{
-   return (unsigned)(unsigned long)p;
-}
-
-static int vmw_ptr_compare(void *key1, void *key2)
-{
-   return (key1 == key2) ? 0 : 1;
-}
-
-
 /**
  * vmw_svga_winsys_vgpu10_shader_screate - The winsys shader_crate callback
  *
@@ -713,20 +702,19 @@ vmw_svga_winsys_vgpu10_shader_create(struct svga_winsys_context *swc,
                                      uint32 shaderId,
                                      SVGA3dShaderType shaderType,
                                      const uint32 *bytecode,
-                                     uint32 bytecodeLen)
+                                     uint32 bytecodeLen,
+                                     const SVGA3dDXShaderSignatureHeader *sgnInfo,
+                                     uint32 sgnLen)
 {
    struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc);
    struct vmw_svga_winsys_shader *shader;
-   struct svga_winsys_gb_shader *gb_shader =
-      vmw_svga_winsys_shader_create(&vswc->vws->base, shaderType, bytecode,
-                                    bytecodeLen);
-   if (!gb_shader)
+   shader = vmw_svga_shader_create(&vswc->vws->base, shaderType, bytecode,
+                                   bytecodeLen, sgnInfo, sgnLen);
+   if (!shader)
       return NULL;
 
-   shader = vmw_svga_winsys_shader(gb_shader);
    shader->shid = shaderId;
-
-   return gb_shader;
+   return svga_winsys_shader(shader);
 }
 
 /**
@@ -809,10 +797,10 @@ vmw_svga_winsys_context_create(struct svga_winsys_screen *sws)
    vswc->base.surface_map = vmw_svga_winsys_surface_map;
    vswc->base.surface_unmap = vmw_svga_winsys_surface_unmap;
 
-  vswc->base.shader_create = vmw_svga_winsys_vgpu10_shader_create;
-  vswc->base.shader_destroy = vmw_svga_winsys_vgpu10_shader_destroy;
+   vswc->base.shader_create = vmw_svga_winsys_vgpu10_shader_create;
+   vswc->base.shader_destroy = vmw_svga_winsys_vgpu10_shader_destroy;
 
-  vswc->base.resource_rebind = vmw_svga_winsys_resource_rebind;
+   vswc->base.resource_rebind = vmw_svga_winsys_resource_rebind;
 
    if (sws->have_vgpu10)
       vswc->base.cid = vmw_ioctl_extended_context_create(vws, sws->have_vgpu10);
@@ -822,6 +810,8 @@ vmw_svga_winsys_context_create(struct svga_winsys_screen *sws)
    if (vswc->base.cid == -1)
       goto out_no_context;
 
+   vswc->base.imported_fence_fd = -1;
+
    vswc->base.have_gb_objects = sws->have_gb_objects;
 
    vswc->vws = vws;
@@ -835,7 +825,7 @@ vmw_svga_winsys_context_create(struct svga_winsys_screen *sws)
    if(!vswc->validate)
       goto out_no_validate;
 
-   vswc->hash = util_hash_table_create(vmw_hash_ptr, vmw_ptr_compare);
+   vswc->hash = util_hash_table_create_ptr_keys();
    if (!vswc->hash)
       goto out_no_hash;
 
@@ -843,6 +833,7 @@ vmw_svga_winsys_context_create(struct svga_winsys_screen *sws)
    vswc->fctx = debug_flush_ctx_create(TRUE, VMW_DEBUG_FLUSH_STACK);
 #endif
 
+   vswc->base.force_coherent = vws->force_coherent;
    return &vswc->base;
 
 out_no_hash: