v3d: Don't forget to flush writes to UBOs.
[mesa.git] / src / gallium / drivers / v3d / v3d_context.h
index a22e1e76ed2fef300c80fd012c48099c9e8f0248..4db422b5755750d4902432e1db9c1d5c23757fe2 100644 (file)
@@ -81,6 +81,7 @@ void v3d_job_add_bo(struct v3d_job *job, struct v3d_bo *bo);
 #define VC5_DIRTY_STREAMOUT     (1 << 27)
 #define VC5_DIRTY_OQ            (1 << 28)
 #define VC5_DIRTY_CENTROID_FLAGS (1 << 29)
+#define VC5_DIRTY_NOPERSPECTIVE_FLAGS (1 << 30)
 
 #define VC5_MAX_FS_INPUTS 64
 
@@ -142,7 +143,8 @@ struct v3d_uncompiled_shader {
 };
 
 struct v3d_compiled_shader {
-        struct v3d_bo *bo;
+        struct pipe_resource *resource;
+        uint32_t offset;
 
         union {
                 struct v3d_prog_data *base;
@@ -183,12 +185,15 @@ struct v3d_vertex_stateobj {
         struct pipe_vertex_element pipe[VC5_MAX_ATTRIBUTES];
         unsigned num_elements;
 
-        uint8_t attrs[12 * VC5_MAX_ATTRIBUTES];
-        struct v3d_bo *default_attribute_values;
+        uint8_t attrs[16 * VC5_MAX_ATTRIBUTES];
+        struct pipe_resource *defaults;
+        uint32_t defaults_offset;
 };
 
 struct v3d_streamout_stateobj {
         struct pipe_stream_output_target *targets[PIPE_MAX_SO_BUFFERS];
+        /* Number of vertices we've written into the buffer so far. */
+        uint32_t offsets[PIPE_MAX_SO_BUFFERS];
         unsigned num_targets;
 };
 
@@ -277,11 +282,15 @@ struct v3d_job {
         /* Bitmask of PIPE_CLEAR_* of buffers that were cleared before the
          * first rendering.
          */
-        uint32_t cleared;
+        uint32_t clear;
+        /* Bitmask of PIPE_CLEAR_* of buffers that have been read by a draw
+         * call without having been cleared first.
+         */
+        uint32_t load;
         /* Bitmask of PIPE_CLEAR_* of buffers that have been rendered to
-         * (either clears or draws).
+         * (either clears or draws) and should be stored.
          */
-        uint32_t resolve;
+        uint32_t store;
         uint32_t clear_color[4][4];
         float clear_z;
         uint8_t clear_s;
@@ -294,15 +303,7 @@ struct v3d_job {
         bool needs_flush;
 
         /**
-         * Set if there is a nonzero address for OCCLUSION_QUERY_COUNTER.  If
-         * so, we need to disable it and flush before ending the CL, to keep
-         * the next tile from starting with it enabled.
-         */
-        bool oq_enabled;
-
-        /**
-         * Set when a packet enabling TF on all further primitives has been
-         * emitted.
+         * Set if a packet enabling TF has been emitted in the job (V3D 4.x).
          */
         bool tf_enabled;
 
@@ -366,19 +367,25 @@ struct v3d_context {
         /** Maximum index buffer valid for the current shader_rec. */
         uint32_t max_index;
 
-        /** Sync object that our RCL will update as its out_sync. */
+        /** Sync object that our RCL or TFU job will update as its out_sync. */
         uint32_t out_sync;
 
+        /* Stream uploader used by gallium internals.  This could also be used
+         * by driver internals, but we tend to use the v3d_cl.h interfaces
+         * instead.
+         */
         struct u_upload_mgr *uploader;
+        /* State uploader used inside the driver.  This is for packing bits of
+         * long-term state inside buffers.
+         */
+        struct u_upload_mgr *state_uploader;
 
         /** @{ Current pipeline state objects */
         struct pipe_scissor_state scissor;
-        struct pipe_blend_state *blend;
+        struct v3d_blend_state *blend;
         struct v3d_rasterizer_state *rasterizer;
         struct v3d_depth_stencil_alpha_state *zsa;
 
-        struct v3d_texture_stateobj verttex, fragtex;
-
         struct v3d_program_stateobj prog;
 
         struct v3d_vertex_stateobj *vtx;
@@ -415,6 +422,7 @@ struct v3d_context {
         struct pipe_clip_state clip;
         struct pipe_viewport_state viewport;
         struct v3d_constbuf_stateobj constbuf[PIPE_SHADER_TYPES];
+        struct v3d_texture_stateobj tex[PIPE_SHADER_TYPES];
         struct v3d_vertexbuf_stateobj vertexbuf;
         struct v3d_streamout_stateobj streamout;
         struct v3d_bo *current_oq;
@@ -426,16 +434,8 @@ struct v3d_rasterizer_state {
 
         float point_size;
 
-        /**
-         * Half-float (1/8/7 bits) value of polygon offset units for
-         * VC5_PACKET_DEPTH_OFFSET
-         */
-        uint16_t offset_units;
-        /**
-         * Half-float (1/8/7 bits) value of polygon offset scale for
-         * VC5_PACKET_DEPTH_OFFSET
-         */
-        uint16_t offset_factor;
+        uint8_t depth_offset[9];
+        uint8_t depth_offset_z16[9];
 };
 
 struct v3d_depth_stencil_alpha_state {
@@ -447,11 +447,21 @@ struct v3d_depth_stencil_alpha_state {
         uint8_t stencil_back[6];
 };
 
+struct v3d_blend_state {
+        struct pipe_blend_state base;
+
+        /* Per-RT mask of whether blending is enabled. */
+        uint8_t blend_enables;
+};
+
 #define perf_debug(...) do {                            \
         if (unlikely(V3D_DEBUG & V3D_DEBUG_PERF))       \
                 fprintf(stderr, __VA_ARGS__);           \
 } while (0)
 
+#define foreach_bit(b, mask)                                            \
+        for (uint32_t _m = (mask), b; _m && ({(b) = u_bit_scan(&_m); 1;});)
+
 static inline struct v3d_context *
 v3d_context(struct pipe_context *pcontext)
 {
@@ -478,12 +488,8 @@ void v3d_query_init(struct pipe_context *pctx);
 
 void v3d_simulator_init(struct v3d_screen *screen);
 void v3d_simulator_destroy(struct v3d_screen *screen);
-int v3d_simulator_flush(struct v3d_context *v3d,
-                        struct drm_v3d_submit_cl *args,
-                        struct v3d_job *job);
 int v3d_simulator_ioctl(int fd, unsigned long request, void *arg);
-void v3d_simulator_open_from_handle(int fd, uint32_t winsys_stride,
-                                    int handle, uint32_t size);
+void v3d_simulator_open_from_handle(int fd, int handle, uint32_t size);
 
 static inline int
 v3d_ioctl(int fd, unsigned long request, void *arg)
@@ -497,8 +503,7 @@ v3d_ioctl(int fd, unsigned long request, void *arg)
 void v3d_set_shader_uniform_dirty_flags(struct v3d_compiled_shader *shader);
 struct v3d_cl_reloc v3d_write_uniforms(struct v3d_context *v3d,
                                        struct v3d_compiled_shader *shader,
-                                       struct v3d_constbuf_stateobj *cb,
-                                       struct v3d_texture_stateobj *texstate);
+                                       enum pipe_shader_type stage);
 
 void v3d_flush(struct pipe_context *pctx);
 void v3d_job_init(struct v3d_context *v3d);
@@ -532,10 +537,19 @@ void v3d_get_internal_type_bpp_for_output_format(const struct v3d_device_info *d
                                                  uint32_t format,
                                                  uint32_t *type,
                                                  uint32_t *bpp);
+bool v3d_tfu_supports_tex_format(const struct v3d_device_info *devinfo,
+                                 uint32_t tex_format);
 
 void v3d_init_query_functions(struct v3d_context *v3d);
 void v3d_blit(struct pipe_context *pctx, const struct pipe_blit_info *blit_info);
 void v3d_blitter_save(struct v3d_context *v3d);
+boolean v3d_generate_mipmap(struct pipe_context *pctx,
+                            struct pipe_resource *prsc,
+                            enum pipe_format format,
+                            unsigned int base_level,
+                            unsigned int last_level,
+                            unsigned int first_layer,
+                            unsigned int last_layer);
 
 struct v3d_fence *v3d_fence_create(struct v3d_context *v3d);