freedreno/a6xx: fix hang with large render target
[mesa.git] / src / gallium / drivers / svga / svga_winsys.h
index 376707dbf53afb99a666d3807829a05e0a530e20..55534953d0cb422577a73fe0514947c927405dab 100644 (file)
 /**
  * @file
  * VMware SVGA specific winsys interface.
- * 
+ *
  * @author Jose Fonseca <jfonseca@vmware.com>
- * 
+ *
  * Documentation taken from the VMware SVGA DDK.
  */
 
 #ifndef SVGA_WINSYS_H_
 #define SVGA_WINSYS_H_
 
-
 #include "svga_types.h"
+#include "svga3d_types.h"
 #include "svga_reg.h"
 #include "svga3d_reg.h"
 
@@ -81,13 +81,15 @@ struct winsys_handle;
 #define SVGA_FENCE_FLAG_EXEC      (1 << 0)
 #define SVGA_FENCE_FLAG_QUERY     (1 << 1)
 
-#define SVGA_SURFACE_USAGE_SHARED  (1 << 0)
-#define SVGA_SURFACE_USAGE_SCANOUT (1 << 1)
+#define SVGA_SURFACE_USAGE_SHARED   (1 << 0)
+#define SVGA_SURFACE_USAGE_SCANOUT  (1 << 1)
+#define SVGA_SURFACE_USAGE_COHERENT (1 << 2)
 
 #define SVGA_QUERY_FLAG_SET        (1 << 0)
 #define SVGA_QUERY_FLAG_REF        (1 << 1)
 
-#define SVGA_HINT_FLAG_CAN_PRE_FLUSH (1 << 0)  /* Can preemptively flush */
+#define SVGA_HINT_FLAG_CAN_PRE_FLUSH   (1 << 0)  /* Can preemptively flush */
+#define SVGA_HINT_FLAG_EXPORT_FENCE_FD (1 << 1)  /* Export a Fence FD */
 
 /**
  * SVGA mks statistics info
@@ -101,6 +103,7 @@ struct svga_winsys_stats_timeframe {
 
 enum svga_stats_count {
    SVGA_STATS_COUNT_BLENDSTATE,
+   SVGA_STATS_COUNT_BLITBLITTERCOPY,
    SVGA_STATS_COUNT_DEPTHSTENCILSTATE,
    SVGA_STATS_COUNT_RASTERIZERSTATE,
    SVGA_STATS_COUNT_SAMPLER,
@@ -112,11 +115,16 @@ enum svga_stats_count {
 };
 
 enum svga_stats_time {
+   SVGA_STATS_TIME_BLIT,
+   SVGA_STATS_TIME_BLITBLITTER,
+   SVGA_STATS_TIME_BLITFALLBACK,
    SVGA_STATS_TIME_BUFFERSFLUSH,
    SVGA_STATS_TIME_BUFFERTRANSFERMAP,
    SVGA_STATS_TIME_BUFFERTRANSFERUNMAP,
    SVGA_STATS_TIME_CONTEXTFINISH,
    SVGA_STATS_TIME_CONTEXTFLUSH,
+   SVGA_STATS_TIME_COPYREGION,
+   SVGA_STATS_TIME_COPYREGIONFALLBACK,
    SVGA_STATS_TIME_CREATEBACKEDSURFACEVIEW,
    SVGA_STATS_TIME_CREATEBUFFER,
    SVGA_STATS_TIME_CREATECONTEXT,
@@ -124,6 +132,8 @@ enum svga_stats_time {
    SVGA_STATS_TIME_CREATEGS,
    SVGA_STATS_TIME_CREATESURFACE,
    SVGA_STATS_TIME_CREATESURFACEVIEW,
+   SVGA_STATS_TIME_CREATETCS,
+   SVGA_STATS_TIME_CREATETES,
    SVGA_STATS_TIME_CREATETEXTURE,
    SVGA_STATS_TIME_CREATEVS,
    SVGA_STATS_TIME_DEFINESHADER,
@@ -133,7 +143,10 @@ enum svga_stats_time {
    SVGA_STATS_TIME_DRAWELEMENTS,
    SVGA_STATS_TIME_EMITFS,
    SVGA_STATS_TIME_EMITGS,
+   SVGA_STATS_TIME_EMITTCS,
+   SVGA_STATS_TIME_EMITTES,
    SVGA_STATS_TIME_EMITVS,
+   SVGA_STATS_TIME_EMULATESURFACEVIEW,
    SVGA_STATS_TIME_FENCEFINISH,
    SVGA_STATS_TIME_GENERATEINDICES,
    SVGA_STATS_TIME_HWTNLDRAWARRAYS,
@@ -165,20 +178,26 @@ enum svga_stats_time {
 
 #define SVGA_STATS_COUNT_NAMES                \
    SVGA_STATS_PREFIX "BlendState",            \
+   SVGA_STATS_PREFIX "BlitBlitterCopy",       \
    SVGA_STATS_PREFIX "DepthStencilState",     \
    SVGA_STATS_PREFIX "RasterizerState",       \
    SVGA_STATS_PREFIX "Sampler",               \
    SVGA_STATS_PREFIX "SamplerView",           \
    SVGA_STATS_PREFIX "SurfaceWriteFlush",     \
    SVGA_STATS_PREFIX "TextureReadback",       \
-   SVGA_STATS_PREFIX "VertexElement"
+   SVGA_STATS_PREFIX "VertexElement"          \
 
 #define SVGA_STATS_TIME_NAMES                       \
+   SVGA_STATS_PREFIX "Blit",                        \
+   SVGA_STATS_PREFIX "BlitBlitter",                 \
+   SVGA_STATS_PREFIX "BlitFallback",                \
    SVGA_STATS_PREFIX "BuffersFlush",                \
    SVGA_STATS_PREFIX "BufferTransferMap",           \
    SVGA_STATS_PREFIX "BufferTransferUnmap",         \
    SVGA_STATS_PREFIX "ContextFinish",               \
    SVGA_STATS_PREFIX "ContextFlush",                \
+   SVGA_STATS_PREFIX "CopyRegion",                  \
+   SVGA_STATS_PREFIX "CopyRegionFallback",          \
    SVGA_STATS_PREFIX "CreateBackedSurfaceView",     \
    SVGA_STATS_PREFIX "CreateBuffer",                \
    SVGA_STATS_PREFIX "CreateContext",               \
@@ -186,6 +205,8 @@ enum svga_stats_time {
    SVGA_STATS_PREFIX "CreateGS",                    \
    SVGA_STATS_PREFIX "CreateSurface",               \
    SVGA_STATS_PREFIX "CreateSurfaceView",           \
+   SVGA_STATS_PREFIX "CreateTCS",                   \
+   SVGA_STATS_PREFIX "CreateTES",                   \
    SVGA_STATS_PREFIX "CreateTexture",               \
    SVGA_STATS_PREFIX "CreateVS",                    \
    SVGA_STATS_PREFIX "DefineShader",                \
@@ -195,7 +216,10 @@ enum svga_stats_time {
    SVGA_STATS_PREFIX "DrawElements",                \
    SVGA_STATS_PREFIX "EmitFS",                      \
    SVGA_STATS_PREFIX "EmitGS",                      \
+   SVGA_STATS_PREFIX "EmitTCS",                     \
+   SVGA_STATS_PREFIX "EmitTES",                     \
    SVGA_STATS_PREFIX "EmitVS",                      \
+   SVGA_STATS_PREFIX "EmulateSurfaceView",          \
    SVGA_STATS_PREFIX "FenceFinish",                 \
    SVGA_STATS_PREFIX "GenerateIndices",             \
    SVGA_STATS_PREFIX "HWtnlDrawArrays",             \
@@ -220,7 +244,7 @@ enum svga_stats_time {
    SVGA_STATS_PREFIX "VbufRenderMapVertices",       \
    SVGA_STATS_PREFIX "VbufRenderUnmapVertices",     \
    SVGA_STATS_PREFIX "VbufSubmitState"
-   
+
 
 /** Opaque surface handle */
 struct svga_winsys_surface;
@@ -238,10 +262,10 @@ struct svga_winsys_context
    void
    (*destroy)(struct svga_winsys_context *swc);
 
-   void *       
-   (*reserve)(struct svga_winsys_context *swc, 
-             uint32_t nr_bytes, uint32_t nr_relocs );
-   
+   void *
+   (*reserve)(struct svga_winsys_context *swc,
+              uint32_t nr_bytes, uint32_t nr_relocs );
+
    /**
     * Returns current size of command buffer, in bytes.
     */
@@ -250,51 +274,51 @@ struct svga_winsys_context
 
    /**
     * Emit a relocation for a host surface.
-    * 
+    *
     * @param flags bitmask of SVGA_RELOC_* flags
-    * 
+    *
     * NOTE: Order of this call does matter. It should be the same order
     * as relocations appear in the command buffer.
     */
    void
-   (*surface_relocation)(struct svga_winsys_context *swc, 
-                        uint32 *sid,
+   (*surface_relocation)(struct svga_winsys_context *swc,
+                         uint32 *sid,
                          uint32 *mobid,
-                        struct svga_winsys_surface *surface,
-                        unsigned flags);
-   
+                         struct svga_winsys_surface *surface,
+                         unsigned flags);
+
    /**
     * Emit a relocation for a guest memory region.
-    * 
+    *
     * @param flags bitmask of SVGA_RELOC_* flags
-    * 
+    *
     * NOTE: Order of this call does matter. It should be the same order
     * as relocations appear in the command buffer.
     */
    void
-   (*region_relocation)(struct svga_winsys_context *swc, 
-                       struct SVGAGuestPtr *ptr, 
-                       struct svga_winsys_buffer *buffer,
-                       uint32 offset,
+   (*region_relocation)(struct svga_winsys_context *swc,
+                        struct SVGAGuestPtr *ptr,
+                        struct svga_winsys_buffer *buffer,
+                        uint32 offset,
                         unsigned flags);
 
    /**
     * Emit a relocation for a guest-backed shader object.
-    * 
+    *
     * NOTE: Order of this call does matter. It should be the same order
     * as relocations appear in the command buffer.
     */
    void
-   (*shader_relocation)(struct svga_winsys_context *swc, 
-                       uint32 *shid,
-                       uint32 *mobid,
-                       uint32 *offset,
-                       struct svga_winsys_gb_shader *shader,
+   (*shader_relocation)(struct svga_winsys_context *swc,
+                        uint32 *shid,
+                        uint32 *mobid,
+                        uint32 *offset,
+                        struct svga_winsys_gb_shader *shader,
                         unsigned flags);
 
    /**
     * Emit a relocation for a guest-backed context.
-    * 
+    *
     * NOTE: Order of this call does matter. It should be the same order
     * as relocations appear in the command buffer.
     */
@@ -314,11 +338,11 @@ struct svga_winsys_context
     */
    void
    (*mob_relocation)(struct svga_winsys_context *swc,
-                    SVGAMobId *id,
-                    uint32 *offset_into_mob,
-                    struct svga_winsys_buffer *buffer,
-                    uint32 offset,
-                    unsigned flags);
+                     SVGAMobId *id,
+                     uint32 *offset_into_mob,
+                     struct svga_winsys_buffer *buffer,
+                     uint32 offset,
+                     unsigned flags);
 
    /**
     * Emit a relocation for a guest-backed query object.
@@ -328,8 +352,8 @@ struct svga_winsys_context
     */
    void
    (*query_relocation)(struct svga_winsys_context *swc,
-                      SVGAMobId *id,
-                      struct svga_winsys_gb_query *query);
+                       SVGAMobId *id,
+                       struct svga_winsys_gb_query *query);
 
    /**
     * Bind queries to context.
@@ -342,14 +366,14 @@ struct svga_winsys_context
 
    void
    (*commit)(struct svga_winsys_context *swc);
-   
+
    enum pipe_error
-   (*flush)(struct svga_winsys_context *swc, 
-           struct pipe_fence_handle **pfence);
+   (*flush)(struct svga_winsys_context *swc,
+            struct pipe_fence_handle **pfence);
 
-   /** 
+   /**
     * Context ID used to fill in the commands
-    * 
+    *
     * Context IDs are arbitrary small non-negative integers,
     * global to the entire SVGA device.
     */
@@ -360,15 +384,25 @@ struct svga_winsys_context
     */
    uint32 hints;
 
+   /**
+    * File descriptor for imported fence
+    */
+   int32 imported_fence_fd;
+
    /**
     ** BEGIN new functions for guest-backed surfaces.
     **/
 
    boolean have_gb_objects;
+   boolean force_coherent;
 
    /**
     * Map a guest-backed surface.
+    * \param swc The winsys context
+    * \param surface The surface to map
     * \param flags  bitmaks of PIPE_TRANSFER_x flags
+    * \param retry Whether to flush and retry the map
+    * \param rebind Whether to issue an immediate rebind and flush.
     *
     * The surface_map() member is allowed to fail due to a
     * shortage of command buffer space, if the
@@ -379,7 +413,8 @@ struct svga_winsys_context
    void *
    (*surface_map)(struct svga_winsys_context *swc,
                   struct svga_winsys_surface *surface,
-                  unsigned flags, boolean *retry);
+                  unsigned flags, boolean *retry,
+                  boolean *rebind);
 
    /**
     * Unmap a guest-backed surface.
@@ -391,13 +426,6 @@ struct svga_winsys_context
                     struct svga_winsys_surface *surface,
                     boolean *rebind);
 
-   /**
-    * Invalidate the content of this surface
-    */
-   void
-   (*surface_invalidate)(struct svga_winsys_context *swc,
-                         struct svga_winsys_surface *surface);
-
    /**
     * Create and define a DX GB shader that resides in the device COTable.
     * Caller of this function will issue the DXDefineShader command.
@@ -407,7 +435,9 @@ struct svga_winsys_context
                     uint32 shaderId,
                     SVGA3dShaderType shaderType,
                     const uint32 *bytecode,
-                    uint32 bytecodeLen);
+                    uint32 bytecodeLen,
+                    const SVGA3dDXShaderSignatureHeader *sgnInfo,
+                    uint32 sgnLen);
 
    /**
     * Destroy a DX GB shader.
@@ -429,11 +459,21 @@ struct svga_winsys_context
                       struct svga_winsys_gb_shader *shader,
                       unsigned flags);
 
-   /** To report perf/conformance/etc issues to the state tracker */
+   /** To report perf/conformance/etc issues to the gallium frontend */
    struct pipe_debug_callback *debug_callback;
 
    /** The more recent command issued to command buffer */
    SVGAFifo3dCmdId last_command;
+
+   /** For HUD queries */
+   uint64_t num_commands;
+   uint64_t num_command_buffers;
+   uint64_t num_draw_commands;
+   uint64_t num_shader_reloc;
+   uint64_t num_surf_reloc;
+
+   /* Whether we are in retry processing */
+   unsigned int in_retry;
 };
 
 
@@ -444,7 +484,7 @@ struct svga_winsys_screen
 {
    void
    (*destroy)(struct svga_winsys_screen *sws);
-   
+
    SVGA3dHardwareVersion
    (*get_hw_version)(struct svga_winsys_screen *sws);
 
@@ -452,7 +492,7 @@ struct svga_winsys_screen
    (*get_cap)(struct svga_winsys_screen *sws,
               SVGA3dDevCapIndex index,
               SVGA3dDevCapResult *result);
-   
+
    /**
     * Create a new context.
     *
@@ -465,8 +505,7 @@ struct svga_winsys_screen
     */
    struct svga_winsys_context *
    (*context_create)(struct svga_winsys_screen *sws);
-   
-   
+
    /**
     * This creates a "surface" object in the SVGA3D device.
     *
@@ -507,7 +546,7 @@ struct svga_winsys_screen
     */
    struct svga_winsys_surface *
    (*surface_create)(struct svga_winsys_screen *sws,
-                     SVGA3dSurfaceFlags flags,
+                     SVGA3dSurfaceAllFlags flags,
                      SVGA3dSurfaceFormat format,
                      unsigned usage,
                      SVGA3dSize size,
@@ -545,10 +584,10 @@ struct svga_winsys_screen
     * Reference a SVGA3D surface object. This allows sharing of a
     * surface between different objects.
     */
-   void 
+   void
    (*surface_reference)(struct svga_winsys_screen *sws,
-                       struct svga_winsys_surface **pdst,
-                       struct svga_winsys_surface *src);
+                        struct svga_winsys_surface **pdst,
+                        struct svga_winsys_surface *src);
 
    /**
     * Check if a resource (texture, buffer) of the given size
@@ -560,7 +599,13 @@ struct svga_winsys_screen
                          SVGA3dSurfaceFormat format,
                          SVGA3dSize size,
                          uint32 numLayers,
-                         uint32 numMipLevels);
+                         uint32 numMipLevels,
+                         uint32 numSamples);
+
+   void
+   (*surface_init)(struct svga_winsys_screen *sws,
+                   struct svga_winsys_surface *surface,
+                   unsigned surf_size, SVGA3dSurfaceAllFlags flags);
 
    /**
     * Buffer management. Buffer attributes are mostly fixed over its lifetime.
@@ -571,27 +616,27 @@ struct svga_winsys_screen
     * SSE instructions.
     */
    struct svga_winsys_buffer *
-   (*buffer_create)( struct svga_winsys_screen *sws, 
-                    unsigned alignment, 
-                    unsigned usage,
-                    unsigned size );
+   (*buffer_create)( struct svga_winsys_screen *sws,
+                     unsigned alignment,
+                     unsigned usage,
+                     unsigned size );
 
-   /** 
+   /**
     * Map the entire data store of a buffer object into the client's address.
     * usage is a bitmask of PIPE_TRANSFER_*
     */
    void *
-   (*buffer_map)( struct svga_winsys_screen *sws, 
-                 struct svga_winsys_buffer *buf,
-                 unsigned usage );
-   
-   void 
-   (*buffer_unmap)( struct svga_winsys_screen *sws, 
+   (*buffer_map)( struct svga_winsys_screen *sws,
+                  struct svga_winsys_buffer *buf,
+                  unsigned usage );
+
+   void
+   (*buffer_unmap)( struct svga_winsys_screen *sws,
                     struct svga_winsys_buffer *buf );
 
-   void 
+   void
    (*buffer_destroy)( struct svga_winsys_screen *sws,
-                     struct svga_winsys_buffer *buf );
+                      struct svga_winsys_buffer *buf );
 
 
    /**
@@ -613,13 +658,41 @@ struct svga_winsys_screen
 
    /**
     * Wait for the fence to finish.
+    * \param timeout in nanoseconds (may be PIPE_TIMEOUT_INFINITE).
+    *                0 to return immediately, if the API suports it.
     * \param flags  driver-specific meaning
     * \return zero on success.
     */
    int (*fence_finish)( struct svga_winsys_screen *sws,
                         struct pipe_fence_handle *fence,
+                        uint64_t timeout,
                         unsigned flag );
 
+   /**
+    * Get the file descriptor associated with the fence
+    * \param duplicate duplicate the fd before returning it
+    * \return zero on success.
+    */
+   int (*fence_get_fd)( struct svga_winsys_screen *sws,
+                        struct pipe_fence_handle *fence,
+                        boolean duplicate );
+
+   /**
+    * Create a fence using the given file descriptor
+    * \return zero on success.
+    */
+   void (*fence_create_fd)( struct svga_winsys_screen *sws,
+                            struct pipe_fence_handle **fence,
+                            int32_t fd );
+
+   /**
+    * Accumulates fence FD from other devices into the current context
+    * \param context_fd FD the context will be waiting on
+    * \return zero on success
+    */
+   int (*fence_server_sync)( struct svga_winsys_screen *sws,
+                             int32_t *context_fd,
+                             struct pipe_fence_handle *fence );
 
    /**
     ** BEGIN new functions for guest-backed surfaces.
@@ -631,14 +704,16 @@ struct svga_winsys_screen
    /** Can we do DMA with guest-backed objects enabled? */
    bool have_gb_dma;
 
+   /** Do we support coherent surface memory? */
+   bool have_coherent;
    /**
     * Create and define a GB shader.
     */
    struct svga_winsys_gb_shader *
    (*shader_create)(struct svga_winsys_screen *sws,
-                   SVGA3dShaderType shaderType,
-                   const uint32 *bytecode,
-                   uint32 bytecodeLen);
+                    SVGA3dShaderType shaderType,
+                    const uint32 *bytecode,
+                    uint32 bytecodeLen);
 
    /**
     * Destroy a GB shader. It's safe to call this function even
@@ -646,7 +721,7 @@ struct svga_winsys_screen
     */
    void
    (*shader_destroy)(struct svga_winsys_screen *sws,
-                    struct svga_winsys_gb_shader *shader);
+                     struct svga_winsys_gb_shader *shader);
 
    /**
     * Create and define a GB query.
@@ -659,7 +734,7 @@ struct svga_winsys_screen
     */
    void
    (*query_destroy)(struct svga_winsys_screen *sws,
-                   struct svga_winsys_gb_query *query);
+                    struct svga_winsys_gb_query *query);
 
    /**
     * Initialize the query state of the query that resides in the slot
@@ -686,7 +761,7 @@ struct svga_winsys_screen
    /**
     * Increment a statistic counter
     */
-   void 
+   void
    (*stats_inc)(enum svga_stats_count);
 
    /**
@@ -701,16 +776,30 @@ struct svga_winsys_screen
    void
    (*stats_time_pop)();
 
+   /**
+    * Send a host log message
+    */
+   void
+   (*host_log)(struct svga_winsys_screen *sws, const char *message);
 
    /** Have VGPU v10 hardware? */
    boolean have_vgpu10;
 
+   /** Have SM4_1 hardware? */
+   boolean have_sm4_1;
+
+   /** Have SM5 hardware? */
+   boolean have_sm5;
+
    /** To rebind resources at the beginnning of a new command buffer */
    boolean need_to_rebind_resources;
 
    boolean have_generate_mipmap_cmd;
    boolean have_set_predication_cmd;
    boolean have_transfer_from_buffer_cmd;
+   boolean have_fence_fd;
+   boolean have_intra_surface_copy;
+   boolean have_constant_buffer_offset_cmd;
 };
 
 
@@ -722,8 +811,8 @@ svga_winsys_context(struct pipe_context *context);
 
 struct pipe_resource *
 svga_screen_buffer_wrap_surface(struct pipe_screen *screen,
-                               enum SVGA3dSurfaceFormat format,
-                               struct svga_winsys_surface *srf);
+                                enum SVGA3dSurfaceFormat format,
+                                struct svga_winsys_surface *srf);
 
 struct svga_winsys_surface *
 svga_screen_buffer_get_winsys_surface(struct pipe_resource *buffer);