vk: Use push constants for dynamic buffers
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 11 Sep 2015 22:56:19 +0000 (15:56 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 11 Sep 2015 22:56:19 +0000 (15:56 -0700)
src/vulkan/anv_cmd_buffer.c
src/vulkan/anv_compiler.cpp

index c2024e4dd60fd7f5e9c52c8f6558afbe475cbe64..cca5cfae3ef97f2a0ee26dbe2774f1c9c95af3e3 100644 (file)
@@ -326,17 +326,28 @@ void anv_CmdBindDescriptorSets(
       ANV_FROM_HANDLE(anv_descriptor_set, set, pDescriptorSets[i]);
       set_layout = layout->set[firstSet + i].layout;
 
-      cmd_buffer->state.descriptors[firstSet + i].set = set;
+      if (cmd_buffer->state.descriptors[firstSet + i].set != set) {
+         cmd_buffer->state.descriptors[firstSet + i].set = set;
+         cmd_buffer->state.descriptors_dirty |= set_layout->shader_stages;
+      }
+
+      if (set_layout->num_dynamic_buffers > 0) {
+         uint32_t s;
+         for_each_bit(s, set_layout->shader_stages) {
+            anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, s,
+                                                      dynamic_offsets);
+            uint32_t *offsets =
+               cmd_buffer->state.push_constants[s]->dynamic_offsets +
+               layout->set[firstSet + i].dynamic_offset_start;
 
-      assert(set_layout->num_dynamic_buffers <
-             ARRAY_SIZE(cmd_buffer->state.descriptors[0].dynamic_offsets));
-      memcpy(cmd_buffer->state.descriptors[firstSet + i].dynamic_offsets,
-             pDynamicOffsets + dynamic_slot,
-             set_layout->num_dynamic_buffers * sizeof(*pDynamicOffsets));
+            memcpy(offsets, pDynamicOffsets + dynamic_slot,
+                   set_layout->num_dynamic_buffers * sizeof(*pDynamicOffsets));
 
-      cmd_buffer->state.descriptors_dirty |= set_layout->shader_stages;
+         }
+         cmd_buffer->state.push_constants_dirty |= set_layout->shader_stages;
 
-      dynamic_slot += set_layout->num_dynamic_buffers;
+         dynamic_slot += set_layout->num_dynamic_buffers;
+      }
    }
 }
 
@@ -464,21 +475,8 @@ anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
          if (state.map == NULL)
             return VK_ERROR_OUT_OF_DEVICE_MEMORY;
 
-         uint32_t offset;
-         if (surface_slots[b].dynamic_slot >= 0) {
-            uint32_t dynamic_offset =
-               d->dynamic_offsets[surface_slots[b].dynamic_slot];
-
-            offset = view->offset + dynamic_offset;
-            anv_fill_buffer_surface_state(cmd_buffer->device,
-                                          state.map, view->format, offset,
-                                          view->range - dynamic_offset);
-         } else {
-            offset = view->offset;
-            memcpy(state.map, view->surface_state.map, 64);
-         }
-
-         add_surface_state_reloc(cmd_buffer, state, view->bo, offset);
+         memcpy(state.map, view->surface_state.map, 64);
+         add_surface_state_reloc(cmd_buffer, state, view->bo, view->offset);
 
          bt_map[start + b] = state.offset;
       }
index e19486ac95da2fcc1d5cd4fab0a083f2db6d466b..dcd5581f9574003cc3e1e1cd23bd6797c35559d2 100644 (file)
@@ -26,6 +26,7 @@
 #include <fcntl.h>
 
 #include "anv_private.h"
+#include "anv_nir.h"
 
 #include <brw_context.h>
 #include <brw_wm.h> /* brw_new_shader_program is here */
@@ -130,6 +131,9 @@ create_params_array(struct anv_pipeline *pipeline,
       num_params += MAX_PUSH_CONSTANTS_SIZE / sizeof(float);
    }
 
+   if (pipeline->layout && pipeline->layout->stage[stage].has_dynamic_offsets)
+      num_params += MAX_DYNAMIC_BUFFERS;
+
    if (num_params == 0)
       return;
 
@@ -212,6 +216,8 @@ really_do_vs_prog(struct brw_context *brw,
    mem_ctx = ralloc_context(NULL);
 
    create_params_array(pipeline, vs, &prog_data->base.base);
+   anv_nir_apply_dynamic_offsets(pipeline, vs->Program->nir,
+                                 &prog_data->base.base);
 
    GLbitfield64 outputs_written = vp->program.Base.OutputsWritten;
    prog_data->inputs_read = vp->program.Base.InputsRead;
@@ -501,6 +507,7 @@ really_do_wm_prog(struct brw_context *brw,
    prog_data->computed_depth_mode = computed_depth_mode(&fp->program);
 
    create_params_array(pipeline, fs, &prog_data->base);
+   anv_nir_apply_dynamic_offsets(pipeline, fs->Program->nir, &prog_data->base);
 
    prog_data->barycentric_interp_modes =
       brw_compute_barycentric_interp_modes(brw, key->flat_shade,
@@ -607,6 +614,7 @@ brw_codegen_cs_prog(struct brw_context *brw,
    set_binding_table_layout(&prog_data->base, pipeline, VK_SHADER_STAGE_COMPUTE);
 
    create_params_array(pipeline, cs, &prog_data->base);
+   anv_nir_apply_dynamic_offsets(pipeline, cs->Program->nir, &prog_data->base);
 
    program = brw_cs_emit(brw, mem_ctx, key, prog_data,
                          &cp->program, prog, &program_size);