<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 27, 2016 at 1:31 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Fri, May 27, 2016 at 11:24 AM, Jordan Justen <span dir="ltr"><<a href="mailto:jordan.l.justen@intel.com" target="_blank">jordan.l.justen@intel.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">This will be important when we start adding a uniform for the CS<br>
thread local invocation index.<br>
<br>
Signed-off-by: Jordan Justen <<a href="mailto:jordan.l.justen@intel.com" target="_blank">jordan.l.justen@intel.com</a>><br>
---<br>
src/intel/vulkan/anv_pipeline.c | 32 +++++++++++++++++++++++++++++++-<br>
1 file changed, 31 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c<br>
index d63e50e..8021348 100644<br>
--- a/src/intel/vulkan/anv_pipeline.c<br>
+++ b/src/intel/vulkan/anv_pipeline.c<br>
@@ -78,6 +78,31 @@ void anv_DestroyShaderModule(<br>
anv_free2(&device->alloc, pAllocator, module);<br>
}<br>
<br>
+static void<br>
+anv_nir_lower_uniforms(nir_shader *nir, bool is_scalar)<br>
+{<br>
+ if (is_scalar) {<br>
+ nir_assign_var_locations(&nir->uniforms, &nir->num_uniforms,<br>
+ type_size_scalar_bytes);<br>
+ nir_lower_io(nir, nir_var_uniform, type_size_scalar_bytes);<br>
+ } else {<br>
+ nir_assign_var_locations(&nir->uniforms, &nir->num_uniforms,<br>
+ type_size_vec4_bytes);<br>
+ nir_lower_io(nir, nir_var_uniform, type_size_vec4_bytes);<br>
+ }<br>
+}<br>
+<br>
+static void<br>
+add_nir_push_constant_uniforms(nir_shader *shader)<br>
+{<br>
+ for (unsigned i = 0; i < MAX_PUSH_CONSTANTS_SIZE / sizeof(float); i++) {<br>
+ char *name = ralloc_asprintf(shader, "push%02d", i);<br>
+ nir_variable *var =<br>
+ nir_variable_create(shader, nir_var_uniform, glsl_uint_type(), name);<br></div></div>
+ var->data.location = i;'<br></blockquote><div><br></div><div>This, combined with the code above isn't going to be correct for vec4. The vec4 backend will make each float take a whole vec4. It doesn't actually matter though since it's going to be ignored. :-/<br></div></div></div></div></blockquote><div><br></div><div>I think this patch can actually be avoided all together as follows:<br><br> 1) Make brw_nir_lower_intrinsics take a thread_id_location parameter and use the load_uniform intrinsic directly instead of a variable.<br><br></div><div> 2) In the GL driver, run brw_nir_lower_intrinsics after lower_uniforms and pass nir->num_uniforms in as the thread_id_location.<br><br></div><div> 3) Pass in the right location from the Vulkan driver.<br><br></div><div> 4) Profit?<br><br></div><div>I'm not sure if that's cleaner, but it seems better than magic variables. It may also let us run brw_nir_lower_intrinsics in brw_prepare_nir rather than making each driver call it separately.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ }<br>
+}<br>
+<br>
#define SPIR_V_MAGIC_NUMBER 0x07230203<br>
<br>
/* Eventually, this will become part of anv_CreateShader. Unfortunately,<br>
@@ -168,7 +193,8 @@ anv_shader_compile_to_nir(struct anv_device *device,<br>
<br>
nir_lower_io_to_temporaries(entry_point->shader, entry_point, true, false);<br>
<br>
- nir_lower_system_values(nir);<br>
+ add_nir_push_constant_uniforms(nir);<br>
+<br>
nir_validate_shader(nir);<br>
}<br>
<br>
@@ -177,6 +203,10 @@ anv_shader_compile_to_nir(struct anv_device *device,<br>
<br>
nir = brw_preprocess_nir(compiler, nir);<br>
<br>
+ nir_lower_system_values(nir);<br>
+ const bool is_scalar = compiler->scalar_stage[nir->stage];<br>
+ anv_nir_lower_uniforms(nir, is_scalar);<br>
+<br>
nir_shader_gather_info(nir, entry_point->impl);<br>
<br>
nir_variable_mode indirect_mask = 0;<br>
<span><font color="#888888">--<br>
2.8.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>