- /* After attaching the driver's storage to the uniform, propagate any
- * data from the linker's backing store. This will cause values from
- * initializers in the source code to be copied over.
- */
- _mesa_propagate_uniforms_to_driver_storage(storage,
- 0,
- MAX2(1, storage->array_elements));
+ /* When a bindless sampler/image is bound to a texture/image unit, we
+ * have to overwrite the constant value by the resident handle
+ * directly in the constant buffer before the next draw. One solution
+ * is to keep track a pointer to the base of the data.
+ */
+ if (storage->is_bindless && (prog->sh.NumBindlessSamplers ||
+ prog->sh.NumBindlessImages)) {
+ unsigned array_elements = MAX2(1, storage->array_elements);
+
+ for (unsigned j = 0; j < array_elements; ++j) {
+ unsigned unit = storage->opaque[shader_type].index + j;
+
+ if (storage->type->without_array()->is_sampler()) {
+ assert(unit >= 0 && unit < prog->sh.NumBindlessSamplers);
+ prog->sh.BindlessSamplers[unit].data =
+ ¶ms->ParameterValues[pvo] + 4 * j;
+ } else if (storage->type->without_array()->is_image()) {
+ assert(unit >= 0 && unit < prog->sh.NumBindlessImages);
+ prog->sh.BindlessImages[unit].data =
+ ¶ms->ParameterValues[pvo] + 4 * j;
+ }
+ }
+ }
+
+ /* After attaching the driver's storage to the uniform, propagate any
+ * data from the linker's backing store. This will cause values from
+ * initializers in the source code to be copied over.
+ */
+ unsigned array_elements = MAX2(1, storage->array_elements);
+ if (ctx->Const.PackedDriverUniformStorage && !prog->is_arb_asm &&
+ (storage->is_bindless || !storage->type->contains_opaque())) {
+ const int dmul = storage->type->is_64bit() ? 2 : 1;
+ const unsigned components =
+ storage->type->vector_elements *
+ storage->type->matrix_columns;
+
+ for (unsigned s = 0; s < storage->num_driver_storage; s++) {
+ gl_constant_value *uni_storage = (gl_constant_value *)
+ storage->driver_storage[s].data;
+ memcpy(uni_storage, storage->storage,
+ sizeof(storage->storage[0]) * components *
+ array_elements * dmul);
+ }
+ } else {
+ _mesa_propagate_uniforms_to_driver_storage(storage, 0,
+ array_elements);
+ }