Re: [Mesa-dev] [RFC PATCH 21/65] mesa: associate uniform storage to bindless samplers/images

2017-05-24 Thread Nicolai Hähnle

Patch 3, 4, 7-21:

Reviewed-by: Nicolai Hähnle 


On 19.05.2017 18:52, Samuel Pitoiset wrote:

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 of a pointer to the data.

Signed-off-by: Samuel Pitoiset 
---
  src/mesa/program/ir_to_mesa.cpp | 25 +
  1 file changed, 25 insertions(+)

diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 5e6304036d..0c3ffd2e22 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2541,6 +2541,7 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
  bool propagate_to_storage)
  {
 struct gl_program_parameter_list *params = prog->Parameters;
+   gl_shader_stage shader_type = prog->info.stage;
  
 /* After adding each uniform to the parameter list, connect the storage for

  * the parameter with the tracking structure used by the API for the
@@ -2623,6 +2624,30 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
   format,
   >ParameterValues[i]);
  
+ /* 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 =
+ >ParameterValues[i] + j;
+   } else if (storage->type->without_array()->is_image()) {
+  assert(unit >= 0 && unit < prog->sh.NumBindlessImages);
+  prog->sh.BindlessImages[unit].data =
+ >ParameterValues[i] + 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.




--
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [RFC PATCH 21/65] mesa: associate uniform storage to bindless samplers/images

2017-05-19 Thread Samuel Pitoiset
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 of a pointer to the data.

Signed-off-by: Samuel Pitoiset 
---
 src/mesa/program/ir_to_mesa.cpp | 25 +
 1 file changed, 25 insertions(+)

diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 5e6304036d..0c3ffd2e22 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2541,6 +2541,7 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
 bool propagate_to_storage)
 {
struct gl_program_parameter_list *params = prog->Parameters;
+   gl_shader_stage shader_type = prog->info.stage;
 
/* After adding each uniform to the parameter list, connect the storage for
 * the parameter with the tracking structure used by the API for the
@@ -2623,6 +2624,30 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
  format,
  >ParameterValues[i]);
 
+ /* 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 =
+ >ParameterValues[i] + j;
+   } else if (storage->type->without_array()->is_image()) {
+  assert(unit >= 0 && unit < prog->sh.NumBindlessImages);
+  prog->sh.BindlessImages[unit].data =
+ >ParameterValues[i] + 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.
-- 
2.13.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev