[Mesa-dev] [PATCH v2 08/13] anv: Add push constant uniforms and lower uniforms

Jason Ekstrand jason at jlekstrand.net
Fri May 27 20:31:47 UTC 2016


On Fri, May 27, 2016 at 11:24 AM, Jordan Justen <jordan.l.justen at intel.com>
wrote:

> This will be important when we start adding a uniform for the CS
> thread local invocation index.
>
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
> ---
>  src/intel/vulkan/anv_pipeline.c | 32 +++++++++++++++++++++++++++++++-
>  1 file changed, 31 insertions(+), 1 deletion(-)
>
> diff --git a/src/intel/vulkan/anv_pipeline.c
> b/src/intel/vulkan/anv_pipeline.c
> index d63e50e..8021348 100644
> --- a/src/intel/vulkan/anv_pipeline.c
> +++ b/src/intel/vulkan/anv_pipeline.c
> @@ -78,6 +78,31 @@ void anv_DestroyShaderModule(
>     anv_free2(&device->alloc, pAllocator, module);
>  }
>
> +static void
> +anv_nir_lower_uniforms(nir_shader *nir, bool is_scalar)
> +{
> +   if (is_scalar) {
> +      nir_assign_var_locations(&nir->uniforms, &nir->num_uniforms,
> +                               type_size_scalar_bytes);
> +      nir_lower_io(nir, nir_var_uniform, type_size_scalar_bytes);
> +   } else {
> +      nir_assign_var_locations(&nir->uniforms, &nir->num_uniforms,
> +                               type_size_vec4_bytes);
> +      nir_lower_io(nir, nir_var_uniform, type_size_vec4_bytes);
> +   }
> +}
> +
> +static void
> +add_nir_push_constant_uniforms(nir_shader *shader)
> +{
> +   for (unsigned i = 0; i < MAX_PUSH_CONSTANTS_SIZE / sizeof(float); i++)
> {
> +      char *name = ralloc_asprintf(shader, "push%02d", i);
> +      nir_variable *var =
> +         nir_variable_create(shader, nir_var_uniform, glsl_uint_type(),
> name);
> +      var->data.location = i;'
>

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. :-/


> +   }
> +}
> +
>  #define SPIR_V_MAGIC_NUMBER 0x07230203
>
>  /* Eventually, this will become part of anv_CreateShader.  Unfortunately,
> @@ -168,7 +193,8 @@ anv_shader_compile_to_nir(struct anv_device *device,
>
>        nir_lower_io_to_temporaries(entry_point->shader, entry_point, true,
> false);
>
> -      nir_lower_system_values(nir);
> +      add_nir_push_constant_uniforms(nir);
> +
>        nir_validate_shader(nir);
>     }
>
> @@ -177,6 +203,10 @@ anv_shader_compile_to_nir(struct anv_device *device,
>
>     nir = brw_preprocess_nir(compiler, nir);
>
> +   nir_lower_system_values(nir);
> +   const bool is_scalar = compiler->scalar_stage[nir->stage];
> +   anv_nir_lower_uniforms(nir, is_scalar);
> +
>     nir_shader_gather_info(nir, entry_point->impl);
>
>     nir_variable_mode indirect_mask = 0;
> --
> 2.8.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160527/e7a57b66/attachment-0001.html>


More information about the mesa-dev mailing list