pb_buffer: inline 'base' sub-struct
[mesa.git] / src / gallium / winsys / svga / drm / vmw_context.c
index 90ffc4868f7b429caa8cca34c3b2c25f3aba5987..633ef385a69f274dc08cc4bafbac1404b15491f3 100644 (file)
@@ -103,6 +103,9 @@ struct vmw_svga_winsys_context
     * referred.
     */
    boolean preemptive_flush;
+
+   boolean throttle_set;
+   uint32_t throttle_us;
 };
 
 
@@ -114,6 +117,19 @@ vmw_svga_winsys_context(struct svga_winsys_context *swc)
 }
 
 
+static INLINE unsigned
+vmw_translate_to_pb_flags(unsigned flags)
+{
+   unsigned f = 0;
+   if (flags & SVGA_RELOC_READ)
+      f |= PB_USAGE_GPU_READ;
+
+   if (flags & SVGA_RELOC_WRITE)
+      f |= PB_USAGE_GPU_WRITE;
+
+   return f;
+}
+
 static enum pipe_error
 vmw_swc_flush(struct svga_winsys_context *swc,
               struct pipe_fence_handle **pfence)
@@ -122,6 +138,7 @@ vmw_swc_flush(struct svga_winsys_context *swc,
    struct pipe_fence_handle *fence = NULL;
    unsigned i;
    enum pipe_error ret;
+   uint32_t throttle_us;
 
    ret = pb_validate_validate(vswc->validate);
    assert(ret == PIPE_OK);
@@ -140,8 +157,13 @@ vmw_swc_flush(struct svga_winsys_context *swc,
          *reloc->where = ptr;
       }
 
+      throttle_us = vswc->throttle_set ?
+        vswc->throttle_us : vswc->vws->default_throttle_us;
+
       if (vswc->command.used)
          vmw_ioctl_command(vswc->vws,
+                          vswc->base.cid,
+                          throttle_us,
                            vswc->command.buffer,
                            vswc->command.used,
                            &vswc->last_fence);
@@ -264,6 +286,7 @@ vmw_swc_region_relocation(struct svga_winsys_context *swc,
 {
    struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc);
    struct vmw_region_relocation *reloc;
+   unsigned translated_flags;
    enum pipe_error ret;
    
    assert(vswc->region.staged < vswc->region.reserved);
@@ -275,7 +298,8 @@ vmw_swc_region_relocation(struct svga_winsys_context *swc,
 
    ++vswc->region.staged;
 
-   ret = pb_validate_add_buffer(vswc->validate, reloc->buffer, flags);
+   translated_flags = vmw_translate_to_pb_flags(flags);
+   ret = pb_validate_add_buffer(vswc->validate, reloc->buffer, translated_flags);
    /* TODO: Update pipebuffer to reserve buffers and not fail here */
    assert(ret == PIPE_OK);
 
@@ -295,8 +319,8 @@ vmw_swc_region_relocation(struct svga_winsys_context *swc,
     * SVGA virtual device it's not a performance issue since flushing commands
     * to the FIFO won't cause flushing in the host.
     */
-   vswc->seen_regions += reloc->buffer->base.size;
-   if(vswc->seen_regions >= VMW_GMR_POOL_SIZE/2)
+   vswc->seen_regions += reloc->buffer->size;
+   if(vswc->seen_regions >= VMW_GMR_POOL_SIZE/3)
       vswc->preemptive_flush = TRUE;
 }
 
@@ -380,3 +404,13 @@ vmw_svga_winsys_context_create(struct svga_winsys_screen *sws)
 }
 
 
+void
+vmw_svga_context_set_throttling(struct pipe_context *pipe,
+                               uint32_t throttle_us)
+{
+   struct svga_winsys_context *swc = svga_winsys_context(pipe);
+   struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc);
+
+   vswc->throttle_us = throttle_us;
+   vswc->throttle_set = TRUE;
+}