radeonsi: track constant buffer bind history in si_pipe_set_constant_buffer
[mesa.git] / src / gallium / drivers / v3d / v3d_program.c
index 63e6fda5471de72af88c91dabdce21c79d64f384..6c9d5c461ab84221090c9fca640b98d6a17e802f 100644 (file)
@@ -27,6 +27,7 @@
 #include "util/u_memory.h"
 #include "util/ralloc.h"
 #include "util/hash_table.h"
+#include "util/u_upload_mgr.h"
 #include "tgsi/tgsi_dump.h"
 #include "tgsi/tgsi_parse.h"
 #include "compiler/nir/nir.h"
@@ -121,7 +122,7 @@ v3d_set_transform_feedback_outputs(struct v3d_uncompiled_shader *so,
                                  * values at the start.
                                  */
                                 .first_shaded_vertex_value_to_output = vpm_start_offset,
-                                .number_of_consecutive_vertex_values_to_output_as_32_bit_values_minus_1 = write_size - 1,
+                                .number_of_consecutive_vertex_values_to_output_as_32_bit_values = write_size,
                                 .output_buffer_to_write_to = buffer,
                         };
 
@@ -152,6 +153,8 @@ v3d_set_transform_feedback_outputs(struct v3d_uncompiled_shader *so,
                         vpm_start_offset += write_size;
                         vpm_size -= write_size;
                 }
+                so->base.stream_output.stride[buffer] =
+                        stream_output->stride[buffer];
         }
 
         so->num_tf_outputs = slot_count;
@@ -191,9 +194,6 @@ v3d_shader_state_create(struct pipe_context *pctx,
                  */
                 s = cso->ir.nir;
 
-                NIR_PASS_V(s, nir_lower_io, nir_var_all & ~nir_var_uniform,
-                           type_size,
-                           (nir_lower_io_options)0);
                 NIR_PASS_V(s, nir_lower_io, nir_var_uniform,
                            uniforms_type_size,
                            (nir_lower_io_options)0);
@@ -211,6 +211,13 @@ v3d_shader_state_create(struct pipe_context *pctx,
                 so->was_tgsi = true;
         }
 
+        nir_variable_mode lower_mode = nir_var_all & ~nir_var_uniform;
+        if (s->info.stage == MESA_SHADER_VERTEX)
+                lower_mode &= ~(nir_var_shader_in | nir_var_shader_out);
+        NIR_PASS_V(s, nir_lower_io, lower_mode,
+                   type_size,
+                   (nir_lower_io_options)0);
+
         NIR_PASS_V(s, nir_opt_global_to_local);
         NIR_PASS_V(s, nir_lower_regs_to_ssa);
         NIR_PASS_V(s, nir_normalize_cubemap_coords);
@@ -295,9 +302,8 @@ v3d_get_compiled_shader(struct v3d_context *v3d, struct v3d_key *key)
 
         v3d_set_shader_uniform_dirty_flags(shader);
 
-        shader->bo = v3d_bo_alloc(v3d->screen, shader_size, "shader");
-        v3d_bo_map(shader->bo);
-        memcpy(shader->bo->map, qpu_insts, shader_size);
+        u_upload_data(v3d->state_uploader, 0, shader_size, 8,
+                      qpu_insts, &shader->offset, &shader->resource);
 
         free(qpu_insts);
 
@@ -324,6 +330,13 @@ v3d_get_compiled_shader(struct v3d_context *v3d, struct v3d_key *key)
         return shader;
 }
 
+static void
+v3d_free_compiled_shader(struct v3d_compiled_shader *shader)
+{
+        pipe_resource_reference(&shader->resource, NULL);
+        ralloc_free(shader);
+}
+
 static void
 v3d_setup_shared_key(struct v3d_context *v3d, struct v3d_key *key,
                      struct v3d_texture_stateobj *texstate)
@@ -399,21 +412,21 @@ v3d_update_compiled_fs(struct v3d_context *v3d, uint8_t prim_mode)
                             VC5_DIRTY_FRAMEBUFFER |
                             VC5_DIRTY_ZSA |
                             VC5_DIRTY_RASTERIZER |
-                            VC5_DIRTY_SAMPLE_MASK |
+                            VC5_DIRTY_SAMPLE_STATE |
                             VC5_DIRTY_FRAGTEX |
                             VC5_DIRTY_UNCOMPILED_FS))) {
                 return;
         }
 
         memset(key, 0, sizeof(*key));
-        v3d_setup_shared_key(v3d, &key->base, &v3d->fragtex);
+        v3d_setup_shared_key(v3d, &key->base, &v3d->tex[PIPE_SHADER_FRAGMENT]);
         key->base.shader_state = v3d->prog.bind_fs;
         key->is_points = (prim_mode == PIPE_PRIM_POINTS);
         key->is_lines = (prim_mode >= PIPE_PRIM_LINES &&
                          prim_mode <= PIPE_PRIM_LINE_STRIP);
         key->clamp_color = v3d->rasterizer->base.clamp_fragment_color;
-        if (v3d->blend->logicop_enable) {
-                key->logicop_func = v3d->blend->logicop_func;
+        if (v3d->blend->base.logicop_enable) {
+                key->logicop_func = v3d->blend->base.logicop_func;
         } else {
                 key->logicop_func = PIPE_LOGICOP_COPY;
         }
@@ -421,8 +434,8 @@ v3d_update_compiled_fs(struct v3d_context *v3d, uint8_t prim_mode)
                 key->msaa = v3d->rasterizer->base.multisample;
                 key->sample_coverage = (v3d->rasterizer->base.multisample &&
                                         v3d->sample_mask != (1 << VC5_MAX_SAMPLES) - 1);
-                key->sample_alpha_to_coverage = v3d->blend->alpha_to_coverage;
-                key->sample_alpha_to_one = v3d->blend->alpha_to_one;
+                key->sample_alpha_to_coverage = v3d->blend->base.alpha_to_coverage;
+                key->sample_alpha_to_one = v3d->blend->base.alpha_to_one;
         }
 
         key->depth_enabled = (v3d->zsa->base.depth.enabled ||
@@ -483,6 +496,11 @@ v3d_update_compiled_fs(struct v3d_context *v3d, uint8_t prim_mode)
                         v3d->dirty |= VC5_DIRTY_FLAT_SHADE_FLAGS;
                 }
 
+                if (v3d->prog.fs->prog_data.fs->noperspective_flags !=
+                    old_fs->prog_data.fs->noperspective_flags) {
+                        v3d->dirty |= VC5_DIRTY_NOPERSPECTIVE_FLAGS;
+                }
+
                 if (v3d->prog.fs->prog_data.fs->centroid_flags !=
                     old_fs->prog_data.fs->centroid_flags) {
                         v3d->dirty |= VC5_DIRTY_CENTROID_FLAGS;
@@ -512,7 +530,7 @@ v3d_update_compiled_vs(struct v3d_context *v3d, uint8_t prim_mode)
         }
 
         memset(key, 0, sizeof(*key));
-        v3d_setup_shared_key(v3d, &key->base, &v3d->verttex);
+        v3d_setup_shared_key(v3d, &key->base, &v3d->tex[PIPE_SHADER_VERTEX]);
         key->base.shader_state = v3d->prog.bind_vs;
         key->num_fs_inputs = v3d->prog.fs->prog_data.fs->base.num_inputs;
         STATIC_ASSERT(sizeof(key->fs_inputs) ==
@@ -595,12 +613,11 @@ delete_from_cache_if_matches(struct hash_table *ht,
         if (key->shader_state == so) {
                 struct v3d_compiled_shader *shader = entry->data;
                 _mesa_hash_table_remove(ht, entry);
-                v3d_bo_unreference(&shader->bo);
 
                 if (shader == *last_compile)
                         *last_compile = NULL;
 
-                ralloc_free(shader);
+                v3d_free_compiled_shader(shader);
         }
 }
 
@@ -610,7 +627,6 @@ v3d_shader_state_delete(struct pipe_context *pctx, void *hwcso)
         struct v3d_context *v3d = v3d_context(pctx);
         struct v3d_uncompiled_shader *so = hwcso;
 
-        struct hash_entry *entry;
         hash_table_foreach(v3d->fs_cache, entry) {
                 delete_from_cache_if_matches(v3d->fs_cache, &v3d->prog.fs,
                                              entry, so);
@@ -665,18 +681,17 @@ v3d_program_fini(struct pipe_context *pctx)
 {
         struct v3d_context *v3d = v3d_context(pctx);
 
-        struct hash_entry *entry;
         hash_table_foreach(v3d->fs_cache, entry) {
                 struct v3d_compiled_shader *shader = entry->data;
-                v3d_bo_unreference(&shader->bo);
-                ralloc_free(shader);
+                v3d_free_compiled_shader(shader);
                 _mesa_hash_table_remove(v3d->fs_cache, entry);
         }
 
         hash_table_foreach(v3d->vs_cache, entry) {
                 struct v3d_compiled_shader *shader = entry->data;
-                v3d_bo_unreference(&shader->bo);
-                ralloc_free(shader);
+                v3d_free_compiled_shader(shader);
                 _mesa_hash_table_remove(v3d->vs_cache, entry);
         }
+
+        v3d_bo_unreference(&v3d->prog.spill_bo);
 }