gallium/swr: fix corruptions in Unigine Heaven
[mesa.git] / src / gallium / drivers / swr / swr_context.h
index 93e6f056edfba42c0c8cdb778f60786e9ed5fc52..9a19720478a3ffb0026839d439f5844fab1bda06 100644 (file)
@@ -29,6 +29,8 @@
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
 #include "util/u_blitter.h"
+#include "rasterizer/memory/SurfaceState.h"
+#include "rasterizer/memory/InitMemory.h"
 #include "jit_api.h"
 #include "swr_state.h"
 #include <unordered_map>
 #define SWR_NEW_FRAMEBUFFER (1 << 15)
 #define SWR_NEW_CLIP (1 << 16)
 #define SWR_NEW_SO (1 << 17)
+#define SWR_BLOCK_CLIENT_DRAW ( 1 << 18) // Indicates client draw will block
+#define SWR_NEW_TCS (1 << 19)
+#define SWR_NEW_TES (1 << 20)
+#define SWR_NEW_TS (1 << 21)
+#define SWR_NEW_TCSCONSTANTS (1 << 22)
+#define SWR_NEW_TESCONSTANTS (1 << 23)
 
 namespace std
 {
@@ -88,6 +96,10 @@ struct swr_draw_context {
    uint32_t num_constantsFS[PIPE_MAX_CONSTANT_BUFFERS];
    const float *constantGS[PIPE_MAX_CONSTANT_BUFFERS];
    uint32_t num_constantsGS[PIPE_MAX_CONSTANT_BUFFERS];
+   const float *constantTCS[PIPE_MAX_CONSTANT_BUFFERS];
+   uint32_t num_constantsTCS[PIPE_MAX_CONSTANT_BUFFERS];
+   const float *constantTES[PIPE_MAX_CONSTANT_BUFFERS];
+   uint32_t num_constantsTES[PIPE_MAX_CONSTANT_BUFFERS];
 
    swr_jit_texture texturesVS[PIPE_MAX_SHADER_SAMPLER_VIEWS];
    swr_jit_sampler samplersVS[PIPE_MAX_SAMPLERS];
@@ -95,13 +107,21 @@ struct swr_draw_context {
    swr_jit_sampler samplersFS[PIPE_MAX_SAMPLERS];
    swr_jit_texture texturesGS[PIPE_MAX_SHADER_SAMPLER_VIEWS];
    swr_jit_sampler samplersGS[PIPE_MAX_SAMPLERS];
+   swr_jit_texture texturesTCS[PIPE_MAX_SHADER_SAMPLER_VIEWS];
+   swr_jit_sampler samplersTCS[PIPE_MAX_SAMPLERS];
+   swr_jit_texture texturesTES[PIPE_MAX_SHADER_SAMPLER_VIEWS];
+   swr_jit_sampler samplersTES[PIPE_MAX_SAMPLERS];
 
    float userClipPlanes[PIPE_MAX_CLIP_PLANES][4];
 
    uint32_t polyStipple[32];
 
    SWR_SURFACE_STATE renderTargets[SWR_NUM_ATTACHMENTS];
-   void *pStats;
+   struct swr_query_result *pStats; // @llvm_struct
+   SWR_INTERFACE *pAPI; // @llvm_struct - Needed for the swr_memory callbacks
+   SWR_TILE_INTERFACE *pTileAPI; // @llvm_struct - Needed for the swr_memory callbacks
+
+   uint64_t* soPrims; //number of primitives written to StreamOut buffer
 };
 
 /* gen_llvm_types FINI */
@@ -111,6 +131,8 @@ struct swr_context {
 
    HANDLE swrContext;
 
+   SWR_TS_STATE tsState;
+
    /** Constant state objects */
    struct swr_blend_state *blend;
    struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
@@ -120,6 +142,8 @@ struct swr_context {
    struct swr_vertex_shader *vs;
    struct swr_fragment_shader *fs;
    struct swr_geometry_shader *gs;
+   struct swr_tess_control_shader *tcs;
+   struct swr_tess_evaluation_shader *tes;
    struct swr_vertex_element_state *velems;
 
    /** Other rendering state */
@@ -130,12 +154,12 @@ struct swr_context {
       constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
    struct pipe_framebuffer_state framebuffer;
    struct swr_poly_stipple poly_stipple;
-   struct pipe_scissor_state scissor;
-   SWR_RECT swr_scissor;
+   struct pipe_scissor_state scissors[KNOB_NUM_VIEWPORTS_SCISSORS];
+   SWR_RECT swr_scissors[KNOB_NUM_VIEWPORTS_SCISSORS];
    struct pipe_sampler_view *
       sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
 
-   struct pipe_viewport_state viewport;
+   struct pipe_viewport_state viewports[KNOB_NUM_VIEWPORTS_SCISSORS];
    struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
 
    struct blitter_context *blitter;
@@ -143,7 +167,7 @@ struct swr_context {
    /** Conditional query object and mode */
    struct pipe_query *render_cond_query;
    enum pipe_render_cond_flag render_cond_mode;
-   boolean render_cond_cond;
+   bool render_cond_cond;
    unsigned active_queries;
 
    unsigned num_vertex_buffers;
@@ -155,6 +179,7 @@ struct swr_context {
    // streamout
    pipe_stream_output_target *so_targets[MAX_SO_STREAMS];
    uint32_t num_so_targets;
+   uint64_t so_primCounter; // number of primitives written to StreamOut buffer
 
    /* Temp storage for user_buffer constants */
    struct swr_scratch_buffers *scratch;
@@ -169,6 +194,11 @@ struct swr_context {
    struct swr_draw_context swrDC;
 
    unsigned dirty; /**< Mask of SWR_NEW_x flags */
+
+   SWR_INTERFACE api;
+   SWR_TILE_INTERFACE tileApi;
+
+   uint32_t max_draws_in_flight;
 };
 
 static INLINE struct swr_context *
@@ -182,7 +212,7 @@ swr_update_draw_context(struct swr_context *ctx,
       struct swr_query_result *pqr = nullptr)
 {
    swr_draw_context *pDC =
-      (swr_draw_context *)SwrGetPrivateContextState(ctx->swrContext);
+      (swr_draw_context *)ctx->api.pfnSwrGetPrivateContextState(ctx->swrContext);
    if (pqr)
       ctx->swrDC.pStats = pqr;
    memcpy(pDC, &ctx->swrDC, sizeof(swr_draw_context));