<div dir="ltr"><div>Can you give me an exact CI test name?  I ran exactly this branch through our CI prior to sending it out and everything passed which is really weird given that this is happening at a fairly high level in NIR.  I think I have some notion of where this bug is coming from but I need to poke at it in an actual test.</div><div><br></div><div>--Jason<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 1, 2018 at 3:48 AM, Bas Nieuwenhuizen <span dir="ltr"><<a href="mailto:bas@basnieuwenhuizen.nl" target="_blank">bas@basnieuwenhuizen.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The casts are not lowered away in some of the CTS tests for radv:<br>
<br>
shader: MESA_SHADER_COMPUTE<br>
local-size: 1, 1, 1<br>
shared-size: 1<br>
inputs: 0<br>
outputs: 0<br>
uniforms: 0<br>
shared: 0<br>
decl_var uniform INTERP_MODE_NONE sampler2D @0 (0, 0, 0)<br>
decl_var uniform INTERP_MODE_NONE sampler2D @1 (0, 0, 1)<br>
decl_var uniform INTERP_MODE_NONE sampler @2 (0, 0, 0)<br>
decl_var uniform INTERP_MODE_NONE sampler @3 (0, 0, 1)<br>
decl_var system INTERP_MODE_NONE uvec3 @4<br>
decl_function (null) (3 params)<br>
<br>
impl (null) {<br>
block block_0:<br>
/* preds: */<br>
vec1 32 ssa_9 = load_const (0x00000008 /* 0.000000 */)<br>
vec1 32 ssa_7 = load_const (0x00000008 /* 0.000000 */)<br>
vec1 32 ssa_0 = intrinsic load_param () (0) /* param_idx=0 */<br>
vec1 32 ssa_1 = deref_cast (uint *)ssa_0 (local uint)<br>
vec1 32 ssa_2 = intrinsic load_deref (ssa_1) ()<br>
vec1 32 ssa_3 = intrinsic load_param () (1) /* param_idx=1 */<br>
vec1 32 ssa_4 = deref_cast (sampler2D *)ssa_3 (local sampler2D)<br>
vec1 32 ssa_8 = umod ssa_2, ssa_7<br>
vec1 32 ssa_10 = udiv ssa_2, ssa_9<br>
vec2 32 ssa_11 = vec2 ssa_8, ssa_10<br>
vec2 32 ssa_15 = imov ssa_11<br>
vec4 32 ssa_16 = txf ssa_4 (texture_deref), ssa_15 (coord),<br>
vec1 32 ssa_17 = load_const (0x00000000 /* 0.000000 */)<br>
vec1 32 ssa_18 = intrinsic vulkan_resource_index (ssa_17) (0, 2) /*<br>
desc-set=0 */ /* binding=2 */<br>
vec1 32 ssa_19 = load_const (0x00000000 /* 0.000000 */)<br>
vec1 32 ssa_20 = load_const (0x00000000 /* 0.000000 */)<br>
vec1 32 ssa_21 = iadd ssa_19, ssa_20<br>
vec1 32 ssa_22 = load_const (0x00000010 /* 0.000000 */)<br>
vec1 32 ssa_23 = imul ssa_2, ssa_22<br>
vec1 32 ssa_24 = iadd ssa_21, ssa_23<br>
intrinsic store_ssbo (ssa_16, ssa_18, ssa_24) (15) /* wrmask=xyzw */<br>
return<br>
/* succs: block_0 */<br>
block block_0:<br>
}<br>
<br>
decl_function main (0 params)<br>
<br>
impl main {<br>
decl_var  INTERP_MODE_NONE uint @5<br>
decl_var  INTERP_MODE_NONE uint arg_tmp<br>
block block_0:<br>
/* preds: */<br>
vec1 32 ssa_0 = deref_var &@4 (system uvec3)<br>
vec3 32 ssa_3 = intrinsic load_deref (ssa_0) ()<br>
vec1 32 ssa_4 = fmov ssa_3.x<br>
vec1 32 ssa_5 = deref_var &@5 (local uint)<br>
intrinsic store_deref (ssa_5, ssa_4) (1) /* wrmask=x */<br>
vec1 32 ssa_6 = deref_var &@4 (system uvec3)<br>
vec3 32 ssa_9 = intrinsic load_deref (ssa_6) ()<br>
vec1 32 ssa_10 = fmov ssa_9.x<br>
vec1 32 ssa_11 = deref_var &arg_tmp (local uint)<br>
intrinsic store_deref (ssa_11, ssa_10) (1) /* wrmask=x */<br>
vec1 32 ssa_12 = deref_var &@1 (uniform sampler2D)<br>
vec1 32 ssa_13 = deref_var &@2 (uniform sampler)<br>
call (null) ssa_11, ssa_12, ssa_13<br>
return<br>
/* succs: block_0 */<br>
block block_0:<br>
}<br>
<br>
The cast of the sampler to the local address space is obviously<br>
invalid as the underlying storage is uniform.<br>
<br>
(Also besides, do we really want to support casts & things not easily<br>
derivable from a var for textures/samplers?)<br>
<div><div class="h5"><br>
On Fri, Jun 1, 2018 at 7:03 AM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
> This commit completely reworks function calls in NIR.  Instead of having<br>
> a set of variables for the parameters and return value, nir_call_instr<br>
> now has simply has a number of sources which get mapped to load_param<br>
> intrinsics inside the functions.  It's up to the client API to build an<br>
> ABI on top of that.  In SPIR-V, out parameters are handled by passing<br>
> the result of a deref through as an SSA value and storing to it.<br>
><br>
> This virtue of this approach can be seen by how much it allows us to<br>
> delete from core NIR.  In particular, nir_inline_functions gets halved<br>
> and goes from a fairly difficult pass to understand in detail to almost<br>
> trivial.  It also simplifies spirv_to_nir somewhat because NIR functions<br>
> never were a good fit for SPIR-V.<br>
><br>
> Unfortunately, there is no good way to do this without a mega-commit.<br>
> Core NIR and SPIR-V have to be changed at the same time.  This also<br>
> requires changes to anv and radv because nir_inline_functions couldn't<br>
> handle deref instructions before this change and can't work without them<br>
> after this change.<br>
> ---<br>
>  src/amd/vulkan/radv_shader.c                 |   5 +-<br>
>  src/compiler/glsl/glsl_to_nir.<wbr>cpp            |   1 -<br>
>  src/compiler/nir/nir.c                       |  55 +++----<br>
>  src/compiler/nir/nir.h                       |  35 ++---<br>
>  src/compiler/nir/nir_builder.h               |  16 ++<br>
>  src/compiler/nir/nir_clone.c                 |  15 +-<br>
>  src/compiler/nir/nir_inline_<wbr>functions.c      | 193 ++++-------------------<br>
>  src/compiler/nir/nir_<wbr>intrinsics.py           |   4 +<br>
>  src/compiler/nir/nir_print.c                 |  63 +-------<br>
>  src/compiler/nir/nir_remove_<wbr>dead_variables.c |  20 +--<br>
>  src/compiler/nir/nir_<wbr>serialize.c             |  44 ++----<br>
>  src/compiler/nir/nir_sweep.c                 |   4 -<br>
>  src/compiler/nir/nir_validate.<wbr>c              |  38 ++---<br>
>  src/compiler/spirv/spirv_to_<wbr>nir.c            |  64 ++++----<br>
>  src/compiler/spirv/vtn_cfg.c                 | 221 +++++++++++++--------------<br>
>  src/compiler/spirv/vtn_<wbr>private.h             |   3 -<br>
>  src/compiler/spirv/vtn_<wbr>variables.c           |   9 --<br>
>  src/intel/vulkan/anv_pipeline.<wbr>c              |   5 +-<br>
>  18 files changed, 257 insertions(+), 538 deletions(-)<br>
><br>
> diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c<br>
> index 5c6c2a2..5897b2a 100644<br>
> --- a/src/amd/vulkan/radv_shader.c<br>
> +++ b/src/amd/vulkan/radv_shader.c<br>
> @@ -235,8 +235,6 @@ radv_shader_compile_to_nir(<wbr>struct radv_device *device,<br>
><br>
>                 free(spec_entries);<br>
><br>
> -               NIR_PASS_V(nir, nir_lower_deref_instrs, ~0);<br>
> -<br>
>                 /* We have to lower away local constant initializers right before we<br>
>                  * inline functions.  That way they get properly initialized at the top<br>
>                  * of the function and not at the top of its caller.<br>
> @@ -244,6 +242,7 @@ radv_shader_compile_to_nir(<wbr>struct radv_device *device,<br>
>                 NIR_PASS_V(nir, nir_lower_constant_<wbr>initializers, nir_var_local);<br>
>                 NIR_PASS_V(nir, nir_lower_returns);<br>
>                 NIR_PASS_V(nir, nir_inline_functions);<br>
> +               NIR_PASS_V(nir, nir_copy_prop);<br>
><br>
>                 /* Pick off the single entrypoint that we want */<br>
>                 foreach_list_typed_safe(nir_<wbr>function, func, node, &nir->functions) {<br>
> @@ -253,6 +252,8 @@ radv_shader_compile_to_nir(<wbr>struct radv_device *device,<br>
>                 assert(exec_list_length(&nir-><wbr>functions) == 1);<br>
>                 entry_point->name = ralloc_strdup(entry_point, "main");<br>
><br>
> +               NIR_PASS_V(nir, nir_lower_deref_instrs, ~0);<br>
> +<br>
>                 /* Make sure we lower constant initializers on output variables so that<br>
>                  * nir_remove_dead_variables below sees the corresponding stores<br>
>                  */<br>
> diff --git a/src/compiler/glsl/glsl_to_<wbr>nir.cpp b/src/compiler/glsl/glsl_to_<wbr>nir.cpp<br>
> index 79af4ce..b2602ea 100644<br>
> --- a/src/compiler/glsl/glsl_to_<wbr>nir.cpp<br>
> +++ b/src/compiler/glsl/glsl_to_<wbr>nir.cpp<br>
> @@ -516,7 +516,6 @@ nir_visitor::visit(ir_<wbr>function_signature *ir)<br>
><br>
>        assert(strcmp(func->name, "main") == 0);<br>
>        assert(ir->parameters.is_<wbr>empty());<br>
> -      assert(func->return_type == glsl_type::void_type);<br>
><br>
>        this->is_global = false;<br>
><br>
> diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c<br>
> index df8214d..801e569 100644<br>
> --- a/src/compiler/nir/nir.c<br>
> +++ b/src/compiler/nir/nir.c<br>
> @@ -127,10 +127,6 @@ nir_shader_add_variable(nir_<wbr>shader *shader, nir_variable *var)<br>
>        assert(!"nir_shader_add_<wbr>variable cannot be used for local variables");<br>
>        break;<br>
><br>
> -   case nir_var_param:<br>
> -      assert(!"nir_shader_add_<wbr>variable cannot be used for function parameters");<br>
> -      break;<br>
> -<br>
>     case nir_var_global:<br>
>        exec_list_push_tail(&shader-><wbr>globals, &var->node);<br>
>        break;<br>
> @@ -207,7 +203,6 @@ nir_function_create(nir_shader *shader, const char *name)<br>
>     func->shader = shader;<br>
>     func->num_params = 0;<br>
>     func->params = NULL;<br>
> -   func->return_type = glsl_void_type();<br>
>     func->impl = NULL;<br>
><br>
>     return func;<br>
> @@ -291,9 +286,6 @@ nir_function_impl_create_bare(<wbr>nir_shader *shader)<br>
>     exec_list_make_empty(&impl-><wbr>body);<br>
>     exec_list_make_empty(&impl-><wbr>registers);<br>
>     exec_list_make_empty(&impl-><wbr>locals);<br>
> -   impl->num_params = 0;<br>
> -   impl->params = NULL;<br>
> -   impl->return_var = NULL;<br>
>     impl->reg_alloc = 0;<br>
>     impl->ssa_alloc = 0;<br>
>     impl->valid_metadata = nir_metadata_none;<br>
> @@ -322,26 +314,6 @@ nir_function_impl_create(nir_<wbr>function *function)<br>
>     function->impl = impl;<br>
>     impl->function = function;<br>
><br>
> -   impl->num_params = function->num_params;<br>
> -   impl->params = ralloc_array(function->shader,<br>
> -                               nir_variable *, impl->num_params);<br>
> -<br>
> -   for (unsigned i = 0; i < impl->num_params; i++) {<br>
> -      impl->params[i] = rzalloc(function->shader, nir_variable);<br>
> -      impl->params[i]->type = function->params[i].type;<br>
> -      impl->params[i]->data.mode = nir_var_param;<br>
> -      impl->params[i]->data.location = i;<br>
> -   }<br>
> -<br>
> -   if (!glsl_type_is_void(function-><wbr>return_type)) {<br>
> -      impl->return_var = rzalloc(function->shader, nir_variable);<br>
> -      impl->return_var->type = function->return_type;<br>
> -      impl->return_var->data.mode = nir_var_param;<br>
> -      impl->return_var->data.<wbr>location = -1;<br>
> -   } else {<br>
> -      impl->return_var = NULL;<br>
> -   }<br>
> -<br>
>     return impl;<br>
>  }<br>
><br>
> @@ -539,13 +511,16 @@ nir_intrinsic_instr_create(<wbr>nir_shader *shader, nir_intrinsic_op op)<br>
>  nir_call_instr *<br>
>  nir_call_instr_create(nir_<wbr>shader *shader, nir_function *callee)<br>
>  {<br>
> -   nir_call_instr *instr = ralloc(shader, nir_call_instr);<br>
> -   instr_init(&instr->instr, nir_instr_type_call);<br>
> +   const unsigned num_params = callee->num_params;<br>
> +   nir_call_instr *instr =<br>
> +      rzalloc_size(shader, sizeof(*instr) +<br>
> +                   num_params * sizeof(instr->params[0]));<br>
><br>
> +   instr_init(&instr->instr, nir_instr_type_call);<br>
>     instr->callee = callee;<br>
> -   instr->num_params = callee->num_params;<br>
> -   instr->params = ralloc_array(instr, nir_deref_var *, instr->num_params);<br>
> -   instr->return_deref = NULL;<br>
> +   instr->num_params = num_params;<br>
> +   for (unsigned i = 0; i < num_params; i++)<br>
> +      src_init(&instr->params[i]);<br>
><br>
>     return instr;<br>
>  }<br>
> @@ -1441,6 +1416,17 @@ visit_intrinsic_src(nir_<wbr>intrinsic_instr *instr, nir_foreach_src_cb cb,<br>
>  }<br>
><br>
>  static bool<br>
> +visit_call_src(nir_call_instr *instr, nir_foreach_src_cb cb, void *state)<br>
> +{<br>
> +   for (unsigned i = 0; i < instr->num_params; i++) {<br>
> +      if (!visit_src(&instr->params[i], cb, state))<br>
> +         return false;<br>
> +   }<br>
> +<br>
> +   return true;<br>
> +}<br>
> +<br>
> +static bool<br>
>  visit_phi_src(nir_phi_instr *instr, nir_foreach_src_cb cb, void *state)<br>
>  {<br>
>     nir_foreach_phi_src(src, instr) {<br>
> @@ -1500,7 +1486,8 @@ nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state)<br>
>           return false;<br>
>        break;<br>
>     case nir_instr_type_call:<br>
> -      /* Call instructions have no regular sources */<br>
> +      if (!visit_call_src(nir_instr_as_<wbr>call(instr), cb, state))<br>
> +         return false;<br>
>        break;<br>
>     case nir_instr_type_load_const:<br>
>        /* Constant load instructions have no regular sources */<br>
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
> index c139dce..96c1a84 100644<br>
> --- a/src/compiler/nir/nir.h<br>
> +++ b/src/compiler/nir/nir.h<br>
> @@ -99,7 +99,6 @@ typedef enum {<br>
>     nir_var_uniform         = (1 << 4),<br>
>     nir_var_shader_storage  = (1 << 5),<br>
>     nir_var_system_value    = (1 << 6),<br>
> -   nir_var_param           = (1 << 7),<br>
>     nir_var_shared          = (1 << 8),<br>
>     nir_var_all             = ~0,<br>
>  } nir_variable_mode;<br>
> @@ -387,7 +386,7 @@ typedef struct nir_variable {<br>
>  static inline bool<br>
>  nir_variable_is_global(const nir_variable *var)<br>
>  {<br>
> -   return var->data.mode != nir_var_local && var->data.mode != nir_var_param;<br>
> +   return var->data.mode != nir_var_local;<br>
>  }<br>
><br>
>  typedef struct nir_register {<br>
> @@ -1041,11 +1040,10 @@ nir_deref_instr_to_deref(nir_<wbr>deref_instr *instr, void *mem_ctx);<br>
>  typedef struct {<br>
>     nir_instr instr;<br>
><br>
> -   unsigned num_params;<br>
> -   nir_deref_var **params;<br>
> -   nir_deref_var *return_deref;<br>
> -<br>
>     struct nir_function *callee;<br>
> +<br>
> +   unsigned num_params;<br>
> +   nir_src params[];<br>
>  } nir_call_instr;<br>
><br>
>  #include "nir_intrinsics.h"<br>
> @@ -1189,6 +1187,11 @@ typedef enum {<br>
>      */<br>
>     NIR_INTRINSIC_CLUSTER_SIZE = 11,<br>
><br>
> +   /**<br>
> +    * Parameter index for a load_param intrinsic<br>
> +    */<br>
> +   NIR_INTRINSIC_PARAM_IDX = 12,<br>
> +<br>
>     NIR_INTRINSIC_NUM_INDEX_FLAGS,<br>
><br>
>  } nir_intrinsic_index_flag;<br>
> @@ -1281,6 +1284,7 @@ INTRINSIC_IDX_ACCESSORS(<wbr>component, COMPONENT, unsigned)<br>
>  INTRINSIC_IDX_ACCESSORS(<wbr>interp_mode, INTERP_MODE, unsigned)<br>
>  INTRINSIC_IDX_ACCESSORS(<wbr>reduction_op, REDUCTION_OP, unsigned)<br>
>  INTRINSIC_IDX_ACCESSORS(<wbr>cluster_size, CLUSTER_SIZE, unsigned)<br>
> +INTRINSIC_IDX_ACCESSORS(<wbr>param_idx, PARAM_IDX, unsigned)<br>
><br>
>  /**<br>
>   * \group texture information<br>
> @@ -1812,13 +1816,6 @@ typedef struct {<br>
>     /** list for all local variables in the function */<br>
>     struct exec_list locals;<br>
><br>
> -   /** array of variables used as parameters */<br>
> -   unsigned num_params;<br>
> -   nir_variable **params;<br>
> -<br>
> -   /** variable used to hold the result of the function */<br>
> -   nir_variable *return_var;<br>
> -<br>
>     /** list of local registers in the function */<br>
>     struct exec_list registers;<br>
><br>
> @@ -1929,15 +1926,9 @@ nir_loop_last_block(nir_loop *loop)<br>
>     return nir_cf_node_as_block(exec_<wbr>node_data(nir_cf_node, tail, node));<br>
>  }<br>
><br>
> -typedef enum {<br>
> -   nir_parameter_in,<br>
> -   nir_parameter_out,<br>
> -   nir_parameter_inout,<br>
> -} nir_parameter_type;<br>
> -<br>
>  typedef struct {<br>
> -   nir_parameter_type param_type;<br>
> -   const struct glsl_type *type;<br>
> +   uint8_t num_components;<br>
> +   uint8_t bit_size;<br>
>  } nir_parameter;<br>
><br>
>  typedef struct nir_function {<br>
> @@ -1948,7 +1939,6 @@ typedef struct nir_function {<br>
><br>
>     unsigned num_params;<br>
>     nir_parameter *params;<br>
> -   const struct glsl_type *return_type;<br>
><br>
>     /** The implementation of this function.<br>
>      *<br>
> @@ -2111,7 +2101,6 @@ nir_shader_get_entrypoint(nir_<wbr>shader *shader)<br>
>     assert(exec_list_length(&<wbr>shader->functions) == 1);<br>
>     struct exec_node *func_node = exec_list_get_head(&shader-><wbr>functions);<br>
>     nir_function *func = exec_node_data(nir_function, func_node, node);<br>
> -   assert(func->return_type == glsl_void_type());<br>
>     assert(func->num_params == 0);<br>
>     assert(func->impl);<br>
>     return func->impl;<br>
> diff --git a/src/compiler/nir/nir_<wbr>builder.h b/src/compiler/nir/nir_<wbr>builder.h<br>
> index da7a501..6a40e84 100644<br>
> --- a/src/compiler/nir/nir_<wbr>builder.h<br>
> +++ b/src/compiler/nir/nir_<wbr>builder.h<br>
> @@ -843,6 +843,22 @@ nir_copy_var(nir_builder *build, nir_variable *dest, nir_variable *src)<br>
>     nir_builder_instr_insert(<wbr>build, &copy->instr);<br>
>  }<br>
><br>
> +static inline nir_ssa_def *<br>
> +nir_load_param(nir_builder *build, uint32_t param_idx)<br>
> +{<br>
> +   assert(param_idx < build->impl->function->num_<wbr>params);<br>
> +   nir_parameter *param = &build->impl->function-><wbr>params[param_idx];<br>
> +<br>
> +   nir_intrinsic_instr *load =<br>
> +      nir_intrinsic_instr_create(<wbr>build->shader, nir_intrinsic_load_param);<br>
> +   nir_intrinsic_set_param_idx(<wbr>load, param_idx);<br>
> +   load->num_components = param->num_components;<br>
> +   nir_ssa_dest_init(&load-><wbr>instr, &load->dest,<br>
> +                     param->num_components, param->bit_size, NULL);<br>
> +   nir_builder_instr_insert(<wbr>build, &load->instr);<br>
> +   return &load->dest.ssa;<br>
> +}<br>
> +<br>
>  #include "nir_builder_opcodes.h"<br>
><br>
>  static inline nir_ssa_def *<br>
> diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c<br>
> index 76121d0..4769fbd 100644<br>
> --- a/src/compiler/nir/nir_clone.c<br>
> +++ b/src/compiler/nir/nir_clone.c<br>
> @@ -536,10 +536,7 @@ clone_call(clone_state *state, const nir_call_instr *call)<br>
>     nir_call_instr *ncall = nir_call_instr_create(state-><wbr>ns, ncallee);<br>
><br>
>     for (unsigned i = 0; i < ncall->num_params; i++)<br>
> -      ncall->params[i] = clone_deref_var(state, call->params[i], &ncall->instr);<br>
> -<br>
> -   ncall->return_deref = clone_deref_var(state, call->return_deref,<br>
> -                                         &ncall->instr);<br>
> +      __clone_src(state, ncall, &ncall->params[i], &call->params[i]);<br>
><br>
>     return ncall;<br>
>  }<br>
> @@ -721,14 +718,6 @@ clone_function_impl(clone_<wbr>state *state, const nir_function_impl *fi)<br>
>     clone_reg_list(state, &nfi->registers, &fi->registers);<br>
>     nfi->reg_alloc = fi->reg_alloc;<br>
><br>
> -   nfi->num_params = fi->num_params;<br>
> -   nfi->params = ralloc_array(state->ns, nir_variable *, fi->num_params);<br>
> -   for (unsigned i = 0; i < fi->num_params; i++) {<br>
> -      nfi->params[i] = clone_variable(state, fi->params[i]);<br>
> -   }<br>
> -   if (fi->return_var)<br>
> -      nfi->return_var = clone_variable(state, fi->return_var);<br>
> -<br>
>     assert(list_empty(&state->phi_<wbr>srcs));<br>
><br>
>     clone_cf_list(state, &nfi->body, &fi->body);<br>
> @@ -770,8 +759,6 @@ clone_function(clone_state *state, const nir_function *fxn, nir_shader *ns)<br>
>     nfxn->params = ralloc_array(state->ns, nir_parameter, fxn->num_params);<br>
>     memcpy(nfxn->params, fxn->params, sizeof(nir_parameter) * fxn->num_params);<br>
><br>
> -   nfxn->return_type = fxn->return_type;<br>
> -<br>
>     /* At first glance, it looks like we should clone the function_impl here.<br>
>      * However, call instructions need to be able to reference at least the<br>
>      * function and those will get processed as we clone the function_impls.<br>
> diff --git a/src/compiler/nir/nir_inline_<wbr>functions.c b/src/compiler/nir/nir_inline_<wbr>functions.c<br>
> index b91e7bc..06c90d9 100644<br>
> --- a/src/compiler/nir/nir_inline_<wbr>functions.c<br>
> +++ b/src/compiler/nir/nir_inline_<wbr>functions.c<br>
> @@ -24,126 +24,10 @@<br>
>  #include "nir.h"<br>
>  #include "nir_builder.h"<br>
>  #include "nir_control_flow.h"<br>
> +#include "nir_vla.h"<br>
><br>
>  static bool inline_function_impl(nir_<wbr>function_impl *impl, struct set *inlined);<br>
><br>
> -static void<br>
> -convert_deref_to_param_deref(<wbr>nir_instr *instr, nir_deref_var **deref,<br>
> -                             nir_call_instr *call)<br>
> -{<br>
> -   /* This isn't a parameter, just return the deref */<br>
> -   if ((*deref)->var->data.mode != nir_var_param)<br>
> -      return;<br>
> -<br>
> -   int param_idx = (*deref)->var->data.location;<br>
> -<br>
> -   nir_deref_var *call_deref;<br>
> -   if (param_idx >= 0) {<br>
> -      assert(param_idx < call->callee->num_params);<br>
> -      call_deref = call->params[param_idx];<br>
> -   } else {<br>
> -      call_deref = call->return_deref;<br>
> -   }<br>
> -   assert(call_deref);<br>
> -<br>
> -   /* Now we make a new deref by concatenating the deref in the call's<br>
> -    * parameter with the deref we were given.<br>
> -    */<br>
> -   nir_deref_var *new_deref = nir_deref_var_clone(call_<wbr>deref, instr);<br>
> -   nir_deref *new_tail = nir_deref_tail(&new_deref-><wbr>deref);<br>
> -   new_tail->child = (*deref)->deref.child;<br>
> -   ralloc_steal(new_tail, new_tail->child);<br>
> -   *deref = new_deref;<br>
> -}<br>
> -<br>
> -static void<br>
> -rewrite_param_derefs(nir_<wbr>instr *instr, nir_call_instr *call)<br>
> -{<br>
> -   switch (instr->type) {<br>
> -   case nir_instr_type_intrinsic: {<br>
> -      nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);<br>
> -<br>
> -      for (unsigned i = 0;<br>
> -           i < nir_intrinsic_infos[intrin-><wbr>intrinsic].num_variables; i++) {<br>
> -         convert_deref_to_param_deref(<wbr>instr, &intrin->variables[i], call);<br>
> -      }<br>
> -      break;<br>
> -   }<br>
> -<br>
> -   case nir_instr_type_tex: {<br>
> -      nir_tex_instr *tex = nir_instr_as_tex(instr);<br>
> -      if (tex->texture)<br>
> -         convert_deref_to_param_deref(&<wbr>tex->instr, &tex->texture, call);<br>
> -      if (tex->sampler)<br>
> -         convert_deref_to_param_deref(&<wbr>tex->instr, &tex->sampler, call);<br>
> -      break;<br>
> -   }<br>
> -<br>
> -   default:<br>
> -      break; /* Nothing else has derefs */<br>
> -   }<br>
> -}<br>
> -<br>
> -static void<br>
> -lower_param_to_local(nir_<wbr>variable *param, nir_function_impl *impl, bool write)<br>
> -{<br>
> -   if (param->data.mode != nir_var_param)<br>
> -      return;<br>
> -<br>
> -   nir_parameter_type param_type;<br>
> -   if (param->data.location >= 0) {<br>
> -      assert(param->data.location < impl->num_params);<br>
> -      param_type = impl->function->params[param-><wbr>data.location].param_type;<br>
> -   } else {<br>
> -      /* Return variable */<br>
> -      param_type = nir_parameter_out;<br>
> -   }<br>
> -<br>
> -   if ((write && param_type == nir_parameter_in) ||<br>
> -       (!write && param_type == nir_parameter_out)) {<br>
> -      /* In this case, we need a shadow copy.  Turn it into a local */<br>
> -      param->data.mode = nir_var_local;<br>
> -      exec_list_push_tail(&impl-><wbr>locals, &param->node);<br>
> -   }<br>
> -}<br>
> -<br>
> -static bool<br>
> -lower_params_to_locals_block(<wbr>nir_block *block, nir_function_impl *impl)<br>
> -{<br>
> -   nir_foreach_instr(instr, block) {<br>
> -      if (instr->type != nir_instr_type_intrinsic)<br>
> -         continue;<br>
> -<br>
> -      nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);<br>
> -<br>
> -      switch (intrin->intrinsic) {<br>
> -      case nir_intrinsic_store_var:<br>
> -         lower_param_to_local(intrin-><wbr>variables[0]->var, impl, true);<br>
> -         break;<br>
> -<br>
> -      case nir_intrinsic_copy_var:<br>
> -         lower_param_to_local(intrin-><wbr>variables[0]->var, impl, true);<br>
> -         lower_param_to_local(intrin-><wbr>variables[1]->var, impl, false);<br>
> -         break;<br>
> -<br>
> -      case nir_intrinsic_load_var:<br>
> -         /* All other intrinsics which access variables (image_load_store)<br>
> -          * do so in a read-only fasion.<br>
> -          */<br>
> -         for (unsigned i = 0;<br>
> -              i < nir_intrinsic_infos[intrin-><wbr>intrinsic].num_variables; i++) {<br>
> -            lower_param_to_local(intrin-><wbr>variables[i]->var, impl, false);<br>
> -         }<br>
> -         break;<br>
> -<br>
> -      default:<br>
> -         continue;<br>
> -      }<br>
> -   }<br>
> -<br>
> -   return true;<br>
> -}<br>
> -<br>
>  static bool<br>
>  inline_functions_block(nir_<wbr>block *block, nir_builder *b,<br>
>                         struct set *inlined)<br>
> @@ -171,42 +55,43 @@ inline_functions_block(nir_<wbr>block *block, nir_builder *b,<br>
>           nir_function_impl_clone(call-><wbr>callee->impl);<br>
>        callee_copy->function = call->callee;<br>
><br>
> -      /* Add copies of all in parameters */<br>
> -      assert(call->num_params == callee_copy->num_params);<br>
> -<br>
>        exec_list_append(&b->impl-><wbr>locals, &callee_copy->locals);<br>
>        exec_list_append(&b->impl-><wbr>registers, &callee_copy->registers);<br>
><br>
>        b->cursor = nir_before_instr(&call->instr)<wbr>;<br>
><br>
> -      /* We now need to tie the two functions together using the<br>
> -       * parameters.  There are two ways we do this: One is to turn the<br>
> -       * parameter into a local variable and do a shadow-copy.  The other<br>
> -       * is to treat the parameter as a "proxy" and rewrite derefs to use<br>
> -       * the actual variable that comes from the call instruction.  We<br>
> -       * implement both schemes.  The first is needed in the case where we<br>
> -       * have an in parameter that we write or similar.  The second case is<br>
> -       * needed for handling things such as images and uniforms properly.<br>
> +      /* Rewrite all of the uses of the callee's parameters to use the call<br>
> +       * instructions sources.  In order to ensure that the "load" happens<br>
> +       * here and not later (for register sources), we make sure to convert it<br>
> +       * to an SSA value first.<br>
>         */<br>
> -<br>
> -      /* Figure out when we need to lower to a shadow local */<br>
> -      nir_foreach_block(block, callee_copy) {<br>
> -         lower_params_to_locals_block(<wbr>block, callee_copy);<br>
> -      }<br>
> -<br>
> -      for (unsigned i = 0; i < callee_copy->num_params; i++) {<br>
> -         nir_variable *param = callee_copy->params[i];<br>
> -<br>
> -         if (param->data.mode == nir_var_local &&<br>
> -             call->callee->params[i].param_<wbr>type != nir_parameter_out) {<br>
> -            nir_copy_deref_var(b, nir_deref_var_create(b-><wbr>shader, param),<br>
> -                                  call->params[i]);<br>
> -         }<br>
> +      const unsigned num_params = call->num_params;<br>
> +      NIR_VLA(nir_ssa_def *, params, num_params);<br>
> +      for (unsigned i = 0; i < num_params; i++) {<br>
> +         params[i] = nir_ssa_for_src(b, call->params[i],<br>
> +                                     call->callee->params[i].num_<wbr>components);<br>
>        }<br>
><br>
>        nir_foreach_block(block, callee_copy) {<br>
> -         nir_foreach_instr(instr, block)<br>
> -            rewrite_param_derefs(instr, call);<br>
> +         nir_foreach_instr_safe(instr, block) {<br>
> +            if (instr->type != nir_instr_type_intrinsic)<br>
> +               continue;<br>
> +<br>
> +            nir_intrinsic_instr *load = nir_instr_as_intrinsic(instr);<br>
> +            if (load->intrinsic != nir_intrinsic_load_param)<br>
> +               continue;<br>
> +<br>
> +            unsigned param_idx = nir_intrinsic_param_idx(load);<br>
> +            assert(param_idx < num_params);<br>
> +            assert(load->dest.is_ssa);<br>
> +            nir_ssa_def_rewrite_uses(&<wbr>load->dest.ssa,<br>
> +                                     nir_src_for_ssa(params[param_<wbr>idx]));<br>
> +<br>
> +            /* Remove any left-over load_param intrinsics because they're soon<br>
> +             * to be in another function and therefore no longer valid.<br>
> +             */<br>
> +            nir_instr_remove(&load->instr)<wbr>;<br>
> +         }<br>
>        }<br>
><br>
>        /* Pluck the body out of the function and place it here */<br>
> @@ -214,26 +99,6 @@ inline_functions_block(nir_<wbr>block *block, nir_builder *b,<br>
>        nir_cf_list_extract(&body, &callee_copy->body);<br>
>        nir_cf_reinsert(&body, b->cursor);<br>
><br>
> -      b->cursor = nir_before_instr(&call->instr)<wbr>;<br>
> -<br>
> -      /* Add copies of all out parameters and the return */<br>
> -      assert(call->num_params == callee_copy->num_params);<br>
> -      for (unsigned i = 0; i < callee_copy->num_params; i++) {<br>
> -         nir_variable *param = callee_copy->params[i];<br>
> -<br>
> -         if (param->data.mode == nir_var_local &&<br>
> -             call->callee->params[i].param_<wbr>type != nir_parameter_in) {<br>
> -            nir_copy_deref_var(b, call->params[i],<br>
> -                                  nir_deref_var_create(b-><wbr>shader, param));<br>
> -         }<br>
> -      }<br>
> -      if (!glsl_type_is_void(call-><wbr>callee->return_type) &&<br>
> -          callee_copy->return_var->data.<wbr>mode == nir_var_local) {<br>
> -         nir_copy_deref_var(b, call->return_deref,<br>
> -                               nir_deref_var_create(b-><wbr>shader,<br>
> -                                                    callee_copy->return_var));<br>
> -      }<br>
> -<br>
>        nir_instr_remove(&call->instr)<wbr>;<br>
>     }<br>
><br>
> diff --git a/src/compiler/nir/nir_<wbr>intrinsics.py b/src/compiler/nir/nir_<wbr>intrinsics.py<br>
> index 758bdf5..1dec88b 100644<br>
> --- a/src/compiler/nir/nir_<wbr>intrinsics.py<br>
> +++ b/src/compiler/nir/nir_<wbr>intrinsics.py<br>
> @@ -102,6 +102,8 @@ INTERP_MODE = "NIR_INTRINSIC_INTERP_MODE"<br>
>  REDUCTION_OP = "NIR_INTRINSIC_REDUCTION_OP"<br>
>  # Cluster size for reduction operations<br>
>  CLUSTER_SIZE = "NIR_INTRINSIC_CLUSTER_SIZE"<br>
> +# Parameter index for a load_param intrinsic<br>
> +PARAM_IDX = "NIR_INTRINSIC_PARAM_IDX"<br>
><br>
>  #<br>
>  # Possible flags:<br>
> @@ -120,6 +122,8 @@ def intrinsic(name, src_comp=[], dest_comp=-1, num_vars=0, indices=[],<br>
><br>
>  intrinsic("nop", flags=[CAN_ELIMINATE])<br>
><br>
> +intrinsic("load_param", dest_comp=0, indices=[PARAM_IDX], flags=[CAN_ELIMINATE])<br>
> +<br>
>  intrinsic("load_var", dest_comp=0, num_vars=1, flags=[CAN_ELIMINATE])<br>
>  intrinsic("store_var", src_comp=[0], num_vars=1, indices=[WRMASK])<br>
>  intrinsic("copy_var", num_vars=2)<br>
> diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c<br>
> index dede585..bc39b63 100644<br>
> --- a/src/compiler/nir/nir_print.c<br>
> +++ b/src/compiler/nir/nir_print.c<br>
> @@ -410,7 +410,6 @@ get_variable_mode_str(nir_<wbr>variable_mode mode, bool want_local_global_mode)<br>
>        return "system";<br>
>     case nir_var_shared:<br>
>        return "shared";<br>
> -   case nir_var_param:<br>
>     case nir_var_global:<br>
>        return want_local_global_mode ? "global" : "";<br>
>     case nir_var_local:<br>
> @@ -651,14 +650,6 @@ print_var(nir_variable *var, print_state *state)<br>
>  }<br>
><br>
>  static void<br>
> -print_arg(nir_variable *var, print_state *state)<br>
> -{<br>
> -   FILE *fp = state->fp;<br>
> -   fprintf(fp, "%s %s", glsl_get_type_name(var->type),<br>
> -           get_var_name(var, state));<br>
> -}<br>
> -<br>
> -static void<br>
>  print_deref_var(nir_deref_var *deref, print_state *state)<br>
>  {<br>
>     print_var(deref->var, state);<br>
> @@ -779,6 +770,7 @@ print_intrinsic_instr(nir_<wbr>intrinsic_instr *instr, print_state *state)<br>
>        [NIR_INTRINSIC_INTERP_MODE] = "interp_mode",<br>
>        [NIR_INTRINSIC_REDUCTION_OP] = "reduction_op",<br>
>        [NIR_INTRINSIC_CLUSTER_SIZE] = "cluster_size",<br>
> +      [NIR_INTRINSIC_PARAM_IDX] = "param_idx",<br>
>     };<br>
>     for (unsigned idx = 1; idx < NIR_INTRINSIC_NUM_INDEX_FLAGS; idx++) {<br>
>        if (!info->index_map[idx])<br>
> @@ -978,14 +970,7 @@ print_call_instr(nir_call_<wbr>instr *instr, print_state *state)<br>
>        if (i != 0)<br>
>           fprintf(fp, ", ");<br>
><br>
> -      print_deref(instr->params[i], state);<br>
> -   }<br>
> -<br>
> -   if (instr->return_deref != NULL) {<br>
> -      if (instr->num_params != 0)<br>
> -         fprintf(fp, ", ");<br>
> -      fprintf(fp, "returning ");<br>
> -      print_deref(instr->return_<wbr>deref, state);<br>
> +      print_src(&instr->params[i], state);<br>
>     }<br>
>  }<br>
><br>
> @@ -1260,20 +1245,6 @@ print_function_impl(nir_<wbr>function_impl *impl, print_state *state)<br>
><br>
>     fprintf(fp, "\nimpl %s ", impl->function->name);<br>
><br>
> -   for (unsigned i = 0; i < impl->num_params; i++) {<br>
> -      if (i != 0)<br>
> -         fprintf(fp, ", ");<br>
> -<br>
> -      print_arg(impl->params[i], state);<br>
> -   }<br>
> -<br>
> -   if (impl->return_var != NULL) {<br>
> -      if (impl->num_params != 0)<br>
> -         fprintf(fp, ", ");<br>
> -      fprintf(fp, "returning ");<br>
> -      print_arg(impl->return_var, state);<br>
> -   }<br>
> -<br>
>     fprintf(fp, "{\n");<br>
><br>
>     nir_foreach_variable(var, &impl->locals) {<br>
> @@ -1300,34 +1271,8 @@ print_function(nir_function *function, print_state *state)<br>
>  {<br>
>     FILE *fp = state->fp;<br>
><br>
> -   fprintf(fp, "decl_function %s ", function->name);<br>
> -<br>
> -   for (unsigned i = 0; i < function->num_params; i++) {<br>
> -      if (i != 0)<br>
> -         fprintf(fp, ", ");<br>
> -<br>
> -      switch (function->params[i].param_<wbr>type) {<br>
> -      case nir_parameter_in:<br>
> -         fprintf(fp, "in ");<br>
> -         break;<br>
> -      case nir_parameter_out:<br>
> -         fprintf(fp, "out ");<br>
> -         break;<br>
> -      case nir_parameter_inout:<br>
> -         fprintf(fp, "inout ");<br>
> -         break;<br>
> -      default:<br>
> -         unreachable("Invalid parameter type");<br>
> -      }<br>
> -<br>
> -      fprintf(fp, "%s", glsl_get_type_name(function-><wbr>params[i].type));<br>
> -   }<br>
> -<br>
> -   if (function->return_type != NULL) {<br>
> -      if (function->num_params != 0)<br>
> -         fprintf(fp, ", ");<br>
> -      fprintf(fp, "returning %s", glsl_get_type_name(function-><wbr>return_type));<br>
> -   }<br>
> +   fprintf(fp, "decl_function %s (%d params)", function->name,<br>
> +           function->num_params);<br>
><br>
>     fprintf(fp, "\n");<br>
><br>
> diff --git a/src/compiler/nir/nir_remove_<wbr>dead_variables.c b/src/compiler/nir/nir_remove_<wbr>dead_variables.c<br>
> index 89e544f..41dddd9 100644<br>
> --- a/src/compiler/nir/nir_remove_<wbr>dead_variables.c<br>
> +++ b/src/compiler/nir/nir_remove_<wbr>dead_variables.c<br>
> @@ -52,7 +52,7 @@ deref_used_for_not_store(nir_<wbr>deref_instr *deref)<br>
><br>
>        default:<br>
>           /* If it's used by any other instruction type (most likely a texture<br>
> -          * instruction), consider it used.<br>
> +          * or call instruction), consider it used.<br>
>            */<br>
>           return true;<br>
>        }<br>
> @@ -114,20 +114,6 @@ add_var_use_intrinsic(nir_<wbr>intrinsic_instr *instr, struct set *live,<br>
>  }<br>
><br>
>  static void<br>
> -add_var_use_call(nir_call_<wbr>instr *instr, struct set *live)<br>
> -{<br>
> -   if (instr->return_deref != NULL) {<br>
> -      nir_variable *var = instr->return_deref->var;<br>
> -      _mesa_set_add(live, var);<br>
> -   }<br>
> -<br>
> -   for (unsigned i = 0; i < instr->num_params; i++) {<br>
> -      nir_variable *var = instr->params[i]->var;<br>
> -      _mesa_set_add(live, var);<br>
> -   }<br>
> -}<br>
> -<br>
> -static void<br>
>  add_var_use_tex(nir_tex_instr *instr, struct set *live)<br>
>  {<br>
>     if (instr->texture != NULL) {<br>
> @@ -158,10 +144,6 @@ add_var_use_shader(nir_shader *shader, struct set *live, nir_variable_mode modes<br>
>                                          modes);<br>
>                    break;<br>
><br>
> -               case nir_instr_type_call:<br>
> -                  add_var_use_call(nir_instr_as_<wbr>call(instr), live);<br>
> -                  break;<br>
> -<br>
>                 case nir_instr_type_tex:<br>
>                    add_var_use_tex(nir_instr_as_<wbr>tex(instr), live);<br>
>                    break;<br>
> diff --git a/src/compiler/nir/nir_<wbr>serialize.c b/src/compiler/nir/nir_<wbr>serialize.c<br>
> index 39f6d82..3769910 100644<br>
> --- a/src/compiler/nir/nir_<wbr>serialize.c<br>
> +++ b/src/compiler/nir/nir_<wbr>serialize.c<br>
> @@ -863,9 +863,7 @@ write_call(write_ctx *ctx, const nir_call_instr *call)<br>
>     blob_write_intptr(ctx->blob, write_lookup_object(ctx, call->callee));<br>
><br>
>     for (unsigned i = 0; i < call->num_params; i++)<br>
> -      write_deref_chain(ctx, call->params[i]);<br>
> -<br>
> -   write_deref_chain(ctx, call->return_deref);<br>
> +      write_src(ctx, &call->params[i]);<br>
>  }<br>
><br>
>  static nir_call_instr *<br>
> @@ -875,9 +873,7 @@ read_call(read_ctx *ctx)<br>
>     nir_call_instr *call = nir_call_instr_create(ctx-><wbr>nir, callee);<br>
><br>
>     for (unsigned i = 0; i < call->num_params; i++)<br>
> -      call->params[i] = read_deref_chain(ctx, &call->instr);<br>
> -<br>
> -   call->return_deref = read_deref_chain(ctx, &call->instr);<br>
> +      read_src(ctx, &call->params[i], call);<br>
><br>
>     return call;<br>
>  }<br>
> @@ -1102,15 +1098,6 @@ write_function_impl(write_ctx *ctx, const nir_function_impl *fi)<br>
>     write_reg_list(ctx, &fi->registers);<br>
>     blob_write_uint32(ctx->blob, fi->reg_alloc);<br>
><br>
> -   blob_write_uint32(ctx->blob, fi->num_params);<br>
> -   for (unsigned i = 0; i < fi->num_params; i++) {<br>
> -      write_variable(ctx, fi->params[i]);<br>
> -   }<br>
> -<br>
> -   blob_write_uint32(ctx->blob, !!(fi->return_var));<br>
> -   if (fi->return_var)<br>
> -      write_variable(ctx, fi->return_var);<br>
> -<br>
>     write_cf_list(ctx, &fi->body);<br>
>     write_fixup_phis(ctx);<br>
>  }<br>
> @@ -1125,17 +1112,6 @@ read_function_impl(read_ctx *ctx, nir_function *fxn)<br>
>     read_reg_list(ctx, &fi->registers);<br>
>     fi->reg_alloc = blob_read_uint32(ctx->blob);<br>
><br>
> -   fi->num_params = blob_read_uint32(ctx->blob);<br>
> -   for (unsigned i = 0; i < fi->num_params; i++) {<br>
> -      fi->params[i] = read_variable(ctx);<br>
> -   }<br>
> -<br>
> -   bool has_return = blob_read_uint32(ctx->blob);<br>
> -   if (has_return)<br>
> -      fi->return_var = read_variable(ctx);<br>
> -   else<br>
> -      fi->return_var = NULL;<br>
> -<br>
>     read_cf_list(ctx, &fi->body);<br>
>     read_fixup_phis(ctx);<br>
><br>
> @@ -1155,12 +1131,12 @@ write_function(write_ctx *ctx, const nir_function *fxn)<br>
><br>
>     blob_write_uint32(ctx->blob, fxn->num_params);<br>
>     for (unsigned i = 0; i < fxn->num_params; i++) {<br>
> -      blob_write_uint32(ctx->blob, fxn->params[i].param_type);<br>
> -      encode_type_to_blob(ctx->blob, fxn->params[i].type);<br>
> +      uint32_t val =<br>
> +         ((uint32_t)fxn->params[i].num_<wbr>components) |<br>
> +         ((uint32_t)fxn->params[i].bit_<wbr>size) << 8;<br>
> +      blob_write_uint32(ctx->blob, val);<br>
>     }<br>
><br>
> -   encode_type_to_blob(ctx->blob, fxn->return_type);<br>
> -<br>
>     /* At first glance, it looks like we should write the function_impl here.<br>
>      * However, call instructions need to be able to reference at least the<br>
>      * function and those will get processed as we write the function_impls.<br>
> @@ -1179,12 +1155,12 @@ read_function(read_ctx *ctx)<br>
>     read_add_object(ctx, fxn);<br>
><br>
>     fxn->num_params = blob_read_uint32(ctx->blob);<br>
> +   fxn->params = ralloc_array(fxn, nir_parameter, fxn->num_params);<br>
>     for (unsigned i = 0; i < fxn->num_params; i++) {<br>
> -      fxn->params[i].param_type = blob_read_uint32(ctx->blob);<br>
> -      fxn->params[i].type = decode_type_from_blob(ctx-><wbr>blob);<br>
> +      uint32_t val = blob_read_uint32(ctx->blob);<br>
> +      fxn->params[i].num_components = val & 0xff;<br>
> +      fxn->params[i].bit_size = (val >> 8) & 0xff;<br>
>     }<br>
> -<br>
> -   fxn->return_type = decode_type_from_blob(ctx-><wbr>blob);<br>
>  }<br>
><br>
>  void<br>
> diff --git a/src/compiler/nir/nir_sweep.c b/src/compiler/nir/nir_sweep.c<br>
> index 0f1debc..b14bf13 100644<br>
> --- a/src/compiler/nir/nir_sweep.c<br>
> +++ b/src/compiler/nir/nir_sweep.c<br>
> @@ -118,10 +118,6 @@ sweep_impl(nir_shader *nir, nir_function_impl *impl)<br>
>  {<br>
>     ralloc_steal(nir, impl);<br>
><br>
> -   ralloc_steal(nir, impl->params);<br>
> -   for (unsigned i = 0; i < impl->num_params; i++)<br>
> -      ralloc_steal(nir, impl->params[i]);<br>
> -   ralloc_steal(nir, impl->return_var);<br>
>     steal_list(nir, nir_variable, &impl->locals);<br>
>     steal_list(nir, nir_register, &impl->registers);<br>
><br>
> diff --git a/src/compiler/nir/nir_<wbr>validate.c b/src/compiler/nir/nir_<wbr>validate.c<br>
> index 224a316..51f78e9 100644<br>
> --- a/src/compiler/nir/nir_<wbr>validate.c<br>
> +++ b/src/compiler/nir/nir_<wbr>validate.c<br>
> @@ -555,6 +555,15 @@ validate_intrinsic_instr(nir_<wbr>intrinsic_instr *instr, validate_state *state)<br>
>     unsigned dest_bit_size = 0;<br>
>     unsigned src_bit_sizes[NIR_INTRINSIC_<wbr>MAX_INPUTS] = { 0, };<br>
>     switch (instr->intrinsic) {<br>
> +   case nir_intrinsic_load_param: {<br>
> +      unsigned param_idx = nir_intrinsic_param_idx(instr)<wbr>;<br>
> +      validate_assert(state, param_idx < state->impl->function->num_<wbr>params);<br>
> +      nir_parameter *param = &state->impl->function-><wbr>params[param_idx];<br>
> +      validate_assert(state, instr->num_components == param->num_components);<br>
> +      dest_bit_size = param->bit_size;<br>
> +      break;<br>
> +   }<br>
> +<br>
>     case nir_intrinsic_load_deref: {<br>
>        nir_deref_instr *src = nir_src_as_deref(instr->src[0]<wbr>);<br>
>        validate_assert(state, glsl_type_is_vector_or_scalar(<wbr>src->type) ||<br>
> @@ -677,18 +686,12 @@ validate_tex_instr(nir_tex_<wbr>instr *instr, validate_state *state)<br>
>  static void<br>
>  validate_call_instr(nir_call_<wbr>instr *instr, validate_state *state)<br>
>  {<br>
> -   if (instr->return_deref == NULL) {<br>
> -      validate_assert(state, glsl_type_is_void(instr-><wbr>callee->return_type));<br>
> -   } else {<br>
> -      validate_assert(state, instr->return_deref->deref.<wbr>type == instr->callee->return_type);<br>
> -      validate_deref_var(instr, instr->return_deref, state);<br>
> -   }<br>
> -<br>
>     validate_assert(state, instr->num_params == instr->callee->num_params);<br>
><br>
>     for (unsigned i = 0; i < instr->num_params; i++) {<br>
> -      validate_assert(state, instr->callee->params[i].type == instr->params[i]->deref.type);<br>
> -      validate_deref_var(instr, instr->params[i], state);<br>
> +      validate_src(&instr->params[i]<wbr>, state,<br>
> +                   instr->callee->params[i].bit_<wbr>size,<br>
> +                   instr->callee->params[i].num_<wbr>components);<br>
>     }<br>
>  }<br>
><br>
> @@ -1175,23 +1178,6 @@ validate_function_impl(nir_<wbr>function_impl *impl, validate_state *state)<br>
>     validate_assert(state, impl->function->impl == impl);<br>
>     validate_assert(state, impl->cf_node.parent == NULL);<br>
><br>
> -   validate_assert(state, impl->num_params == impl->function->num_params);<br>
> -   for (unsigned i = 0; i < impl->num_params; i++) {<br>
> -      validate_assert(state, impl->params[i]->type == impl->function->params[i].<wbr>type);<br>
> -      validate_assert(state, impl->params[i]->data.mode == nir_var_param);<br>
> -      validate_assert(state, impl->params[i]->data.location == i);<br>
> -      validate_var_decl(impl-><wbr>params[i], false, state);<br>
> -   }<br>
> -<br>
> -   if (glsl_type_is_void(impl-><wbr>function->return_type)) {<br>
> -      validate_assert(state, impl->return_var == NULL);<br>
> -   } else {<br>
> -      validate_assert(state, impl->return_var->type == impl->function->return_type);<br>
> -      validate_assert(state, impl->return_var->data.mode == nir_var_param);<br>
> -      validate_assert(state, impl->return_var->data.<wbr>location == -1);<br>
> -      validate_var_decl(impl-><wbr>return_var, false, state);<br>
> -   }<br>
> -<br>
>     validate_assert(state, exec_list_is_empty(&impl->end_<wbr>block->instr_list));<br>
>     validate_assert(state, impl->end_block->successors[0] == NULL);<br>
>     validate_assert(state, impl->end_block->successors[1] == NULL);<br>
> diff --git a/src/compiler/spirv/spirv_to_<wbr>nir.c b/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
> index 135c967..c424b61 100644<br>
> --- a/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
> +++ b/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
> @@ -1783,42 +1783,54 @@ vtn_handle_function_call(<wbr>struct vtn_builder *b, SpvOp opcode,<br>
>     vtn_callee->referenced = true;<br>
><br>
>     nir_call_instr *call = nir_call_instr_create(b->nb.<wbr>shader, callee);<br>
> -   for (unsigned i = 0; i < call->num_params; i++) {<br>
> -      unsigned arg_id = w[4 + i];<br>
> -      struct vtn_value *arg = vtn_untyped_value(b, arg_id);<br>
> -      if (arg->value_type == vtn_value_type_pointer &&<br>
> -          arg->pointer->ptr_type->type == NULL) {<br>
> -         nir_deref_var *d = vtn_pointer_to_deref_var(b, arg->pointer);<br>
> -         call->params[i] = nir_deref_var_clone(d, call);<br>
> -      } else {<br>
> -         struct vtn_ssa_value *arg_ssa = vtn_ssa_value(b, arg_id);<br>
><br>
> -         /* Make a temporary to store the argument in */<br>
> -         nir_variable *tmp =<br>
> -            nir_local_variable_create(b-><wbr>nb.impl, arg_ssa->type, "arg_tmp");<br>
> -         call->params[i] = nir_deref_var_create(call, tmp);<br>
> +   unsigned param_idx = 0;<br>
><br>
> -         vtn_local_store(b, arg_ssa,<br>
> -                         nir_build_deref_for_chain(&b-><wbr>nb, call->params[i]));<br>
> -      }<br>
> +   nir_deref_instr *ret_deref = NULL;<br>
> +   struct vtn_type *ret_type = vtn_callee->type->return_type;<br>
> +   if (ret_type->base_type != vtn_base_type_void) {<br>
> +      nir_variable *ret_tmp =<br>
> +         nir_local_variable_create(b-><wbr>nb.impl, ret_type->type, "return_tmp");<br>
> +      ret_deref = nir_build_deref_var(&b->nb, ret_tmp);<br>
> +      call->params[param_idx++] = nir_src_for_ssa(&ret_deref-><wbr>dest.ssa);<br>
>     }<br>
><br>
> -   nir_variable *out_tmp = NULL;<br>
> -   vtn_assert(res_type->type == callee->return_type);<br>
> -   if (!glsl_type_is_void(callee-><wbr>return_type)) {<br>
> -      out_tmp = nir_local_variable_create(b-><wbr>nb.impl, callee->return_type,<br>
> -                                          "out_tmp");<br>
> -      call->return_deref = nir_deref_var_create(call, out_tmp);<br>
> +   for (unsigned i = 0; i < vtn_callee->type->length; i++) {<br>
> +      struct vtn_type *arg_type = vtn_callee->type->params[i];<br>
> +      unsigned arg_id = w[4 + i];<br>
> +<br>
> +      if (arg_type->base_type == vtn_base_type_sampled_image) {<br>
> +         struct vtn_sampled_image *sampled_image =<br>
> +            vtn_value(b, arg_id, vtn_value_type_sampled_image)-<wbr>>sampled_image;<br>
> +<br>
> +         call->params[param_idx++] =<br>
> +            nir_src_for_ssa(&sampled_<wbr>image->image->deref->dest.ssa)<wbr>;<br>
> +         call->params[param_idx++] =<br>
> +            nir_src_for_ssa(&sampled_<wbr>image->sampler->deref->dest.<wbr>ssa);<br>
> +      } else if (arg_type->base_type == vtn_base_type_pointer ||<br>
> +                 arg_type->base_type == vtn_base_type_image ||<br>
> +                 arg_type->base_type == vtn_base_type_sampler) {<br>
> +         struct vtn_pointer *pointer =<br>
> +            vtn_value(b, arg_id, vtn_value_type_pointer)-><wbr>pointer;<br>
> +         call->params[param_idx++] =<br>
> +            nir_src_for_ssa(vtn_pointer_<wbr>to_ssa(b, pointer));<br>
> +      } else {<br>
> +         /* This is a regular SSA value and we need a temporary */<br>
> +         nir_variable *tmp =<br>
> +            nir_local_variable_create(b-><wbr>nb.impl, arg_type->type, "arg_tmp");<br>
> +         nir_deref_instr *tmp_deref = nir_build_deref_var(&b->nb, tmp);<br>
> +         vtn_local_store(b, vtn_ssa_value(b, arg_id), tmp_deref);<br>
> +         call->params[param_idx++] = nir_src_for_ssa(&tmp_deref-><wbr>dest.ssa);<br>
> +      }<br>
>     }<br>
> +   assert(param_idx == call->num_params);<br>
><br>
>     nir_builder_instr_insert(&b-><wbr>nb, &call->instr);<br>
><br>
> -   if (glsl_type_is_void(callee-><wbr>return_type)) {<br>
> +   if (ret_type->base_type == vtn_base_type_void) {<br>
>        vtn_push_value(b, w[2], vtn_value_type_undef);<br>
>     } else {<br>
> -      nir_deref_instr *return_deref =<br>
> -         nir_build_deref_for_chain(&b-><wbr>nb, call->return_deref);<br>
> -      vtn_push_ssa(b, w[2], res_type, vtn_local_load(b, return_deref));<br>
> +      vtn_push_ssa(b, w[2], res_type, vtn_local_load(b, ret_deref));<br>
>     }<br>
>  }<br>
><br>
> diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c<br>
> index 6c1fccf..6c411c8 100644<br>
> --- a/src/compiler/spirv/vtn_cfg.c<br>
> +++ b/src/compiler/spirv/vtn_cfg.c<br>
> @@ -25,18 +25,21 @@<br>
>  #include "nir/nir_vla.h"<br>
><br>
>  static struct vtn_pointer *<br>
> -vtn_pointer_for_image_or_<wbr>sampler_variable(struct vtn_builder *b,<br>
> -                                          struct vtn_variable *var)<br>
> +vtn_load_param_pointer(struct vtn_builder *b,<br>
> +                       struct vtn_type *param_type,<br>
> +                       uint32_t param_idx)<br>
>  {<br>
> -   assert(var->type->base_type == vtn_base_type_image ||<br>
> -          var->type->base_type == vtn_base_type_sampler);<br>
> -<br>
> -   struct vtn_type *ptr_type = rzalloc(b, struct vtn_type);<br>
> -   ptr_type->base_type = vtn_base_type_pointer;<br>
> -   ptr_type->storage_class = SpvStorageClassUniformConstant<wbr>;<br>
> -   ptr_type->deref = var->type;<br>
> +   struct vtn_type *ptr_type = param_type;<br>
> +   if (param_type->base_type != vtn_base_type_pointer) {<br>
> +      assert(param_type->base_type == vtn_base_type_image ||<br>
> +             param_type->base_type == vtn_base_type_sampler);<br>
> +      ptr_type = rzalloc(b, struct vtn_type);<br>
> +      ptr_type->base_type = vtn_base_type_pointer;<br>
> +      ptr_type->deref = param_type;<br>
> +      ptr_type->storage_class = SpvStorageClassFunction;<br>
> +   }<br>
><br>
> -   return vtn_pointer_for_variable(b, var, ptr_type);<br>
> +   return vtn_pointer_from_ssa(b, nir_load_param(&b->nb, param_idx), ptr_type);<br>
>  }<br>
><br>
>  static bool<br>
> @@ -64,41 +67,64 @@ vtn_cfg_handle_prepass_<wbr>instruction(struct vtn_builder *b, SpvOp opcode,<br>
>        nir_function *func =<br>
>           nir_function_create(b->shader, ralloc_strdup(b->shader, val->name));<br>
><br>
> -      func->num_params = func_type->length;<br>
> -      func->params = ralloc_array(b->shader, nir_parameter, func->num_params);<br>
> -      unsigned np = 0;<br>
> +      unsigned num_params = func_type->length;<br>
> +      for (unsigned i = 0; i < func_type->length; i++) {<br>
> +         /* Sampled images are actually two parameters */<br>
> +         if (func_type->params[i]->base_<wbr>type == vtn_base_type_sampled_image)<br>
> +            num_params++;<br>
> +      }<br>
> +<br>
> +      /* Add one parameter for the function return value */<br>
> +      if (func_type->return_type->base_<wbr>type != vtn_base_type_void)<br>
> +         num_params++;<br>
> +<br>
> +      func->num_params = num_params;<br>
> +      func->params = ralloc_array(b->shader, nir_parameter, num_params);<br>
> +<br>
> +      unsigned idx = 0;<br>
> +      if (func_type->return_type->base_<wbr>type != vtn_base_type_void) {<br>
> +         /* The return value is a regular pointer */<br>
> +         func->params[idx++] = (nir_parameter) {<br>
> +            .num_components = 1, .bit_size = 32,<br>
> +         };<br>
> +      }<br>
> +<br>
>        for (unsigned i = 0; i < func_type->length; i++) {<br>
> -         if (func_type->params[i]->base_<wbr>type == vtn_base_type_pointer &&<br>
> -             func_type->params[i]->type == NULL) {<br>
> -            func->params[np].type = func_type->params[i]->deref-><wbr>type;<br>
> -            func->params[np].param_type = nir_parameter_inout;<br>
> -            np++;<br>
> -         } else if (func_type->params[i]->base_<wbr>type ==<br>
> -                    vtn_base_type_sampled_image) {<br>
> -            /* Sampled images are actually two parameters */<br>
> -            func->params = reralloc(b->shader, func->params,<br>
> -                                    nir_parameter, func->num_params++);<br>
> -            func->params[np].type = func_type->params[i]->type;<br>
> -            func->params[np].param_type = nir_parameter_in;<br>
> -            np++;<br>
> -            func->params[np].type = glsl_bare_sampler_type();<br>
> -            func->params[np].param_type = nir_parameter_in;<br>
> -            np++;<br>
> +         if (func_type->params[i]->base_<wbr>type == vtn_base_type_sampled_image) {<br>
> +            /* Sampled images are two pointer parameters */<br>
> +            func->params[idx++] = (nir_parameter) {<br>
> +               .num_components = 1, .bit_size = 32,<br>
> +            };<br>
> +            func->params[idx++] = (nir_parameter) {<br>
> +               .num_components = 1, .bit_size = 32,<br>
> +            };<br>
> +         } else if (func_type->params[i]->base_<wbr>type == vtn_base_type_pointer &&<br>
> +                    func_type->params[i]->type != NULL) {<br>
> +            /* Pointers with as storage class get passed by-value */<br>
> +            assert(glsl_type_is_vector_or_<wbr>scalar(func_type->params[i]-><wbr>type));<br>
> +            func->params[idx++] = (nir_parameter) {<br>
> +               .num_components =<br>
> +                  glsl_get_vector_elements(func_<wbr>type->params[i]->type),<br>
> +               .bit_size = glsl_get_bit_size(func_type-><wbr>params[i]->type),<br>
> +            };<br>
>           } else {<br>
> -            func->params[np].type = func_type->params[i]->type;<br>
> -            func->params[np].param_type = nir_parameter_in;<br>
> -            np++;<br>
> +            /* Everything else is a regular pointer */<br>
> +            func->params[idx++] = (nir_parameter) {<br>
> +               .num_components = 1, .bit_size = 32,<br>
> +            };<br>
>           }<br>
>        }<br>
> -      assert(np == func->num_params);<br>
> -<br>
> -      func->return_type = func_type->return_type->type;<br>
> +      assert(idx == num_params);<br>
><br>
>        b->func->impl = nir_function_impl_create(func)<wbr>;<br>
>        nir_builder_init(&b->nb, func->impl);<br>
>        b->nb.cursor = nir_before_cf_list(&b->func-><wbr>impl->body);<br>
><br>
>        b->func_param_idx = 0;<br>
> +<br>
> +      /* The return value is the first parameter */<br>
> +      if (func_type->return_type->base_<wbr>type != vtn_base_type_void)<br>
> +         b->func_param_idx++;<br>
>        break;<br>
>     }<br>
><br>
> @@ -110,92 +136,46 @@ vtn_cfg_handle_prepass_<wbr>instruction(struct vtn_builder *b, SpvOp opcode,<br>
>     case SpvOpFunctionParameter: {<br>
>        struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;<br>
><br>
> -      vtn_assert(b->func_param_idx < b->func->impl->num_params);<br>
> -      nir_variable *param = b->func->impl->params[b->func_<wbr>param_idx++];<br>
> -<br>
> -      if (type->base_type == vtn_base_type_pointer && type->type == NULL) {<br>
> -         struct vtn_variable *vtn_var = rzalloc(b, struct vtn_variable);<br>
> -         vtn_var->type = type->deref;<br>
> -         vtn_var->var = param;<br>
> -<br>
> -         vtn_assert(vtn_var->type->type == param->type);<br>
> -<br>
> -         struct vtn_type *without_array = vtn_var->type;<br>
> -         while(glsl_type_is_array(<wbr>without_array->type))<br>
> -            without_array = without_array->array_element;<br>
> -<br>
> -         if (glsl_type_is_image(without_<wbr>array->type)) {<br>
> -            vtn_var->mode = vtn_variable_mode_image;<br>
> -            param->interface_type = without_array->type;<br>
> -         } else if (glsl_type_is_sampler(without_<wbr>array->type)) {<br>
> -            vtn_var->mode = vtn_variable_mode_sampler;<br>
> -            param->interface_type = without_array->type;<br>
> -         } else {<br>
> -            vtn_var->mode = vtn_variable_mode_param;<br>
> -         }<br>
> +      vtn_assert(b->func_param_idx < b->func->impl->function->num_<wbr>params);<br>
><br>
> +      if (type->base_type == vtn_base_type_sampled_image) {<br>
> +         /* Sampled images are actually two parameters.  The first is the<br>
> +          * image and the second is the sampler.<br>
> +          */<br>
> +         struct vtn_value *val =<br>
> +            vtn_push_value(b, w[2], vtn_value_type_sampled_image);<br>
> +<br>
> +         val->sampled_image = ralloc(b, struct vtn_sampled_image);<br>
> +         val->sampled_image->type = type;<br>
> +<br>
> +         struct vtn_type *sampler_type = rzalloc(b, struct vtn_type);<br>
> +         sampler_type->base_type = vtn_base_type_sampler;<br>
> +         sampler_type->type = glsl_bare_sampler_type();<br>
> +<br>
> +         val->sampled_image->image =<br>
> +            vtn_load_param_pointer(b, type, b->func_param_idx++);<br>
> +         val->sampled_image->sampler =<br>
> +            vtn_load_param_pointer(b, sampler_type, b->func_param_idx++);<br>
> +      } else if (type->base_type == vtn_base_type_pointer &&<br>
> +                 type->type != NULL) {<br>
> +         /* This is a pointer with an actual storage type */<br>
>           struct vtn_value *val =<br>
>              vtn_push_value(b, w[2], vtn_value_type_pointer);<br>
> -<br>
> -         /* Name the parameter so it shows up nicely in NIR */<br>
> -         param->name = ralloc_strdup(param, val->name);<br>
> -<br>
> -         val->pointer = vtn_pointer_for_variable(b, vtn_var, type);<br>
> -      } else if (type->base_type == vtn_base_type_image ||<br>
> -                 type->base_type == vtn_base_type_sampler ||<br>
> -                 type->base_type == vtn_base_type_sampled_image) {<br>
> -         struct vtn_variable *vtn_var = rzalloc(b, struct vtn_variable);<br>
> -         vtn_var->type = type;<br>
> -         vtn_var->var = param;<br>
> -         param->interface_type = param->type;<br>
> -<br>
> -         if (type->base_type == vtn_base_type_sampled_image) {<br>
> -            /* Sampled images are actually two parameters.  The first is the<br>
> -             * image and the second is the sampler.<br>
> -             */<br>
> -            struct vtn_value *val =<br>
> -               vtn_push_value(b, w[2], vtn_value_type_sampled_image);<br>
> -<br>
> -            /* Name the parameter so it shows up nicely in NIR */<br>
> -            param->name = ralloc_strdup(param, val->name);<br>
> -<br>
> -            /* Adjust the type of the image variable to the image type */<br>
> -            vtn_var->type = type->image;<br>
> -<br>
> -            /* Now get the sampler parameter and set up its variable */<br>
> -            param = b->func->impl->params[b->func_<wbr>param_idx++];<br>
> -            struct vtn_variable *sampler_var = rzalloc(b, struct vtn_variable);<br>
> -            sampler_var->type = rzalloc(b, struct vtn_type);<br>
> -            sampler_var->type->base_type = vtn_base_type_sampler;<br>
> -            sampler_var->type->type = glsl_bare_sampler_type();<br>
> -            sampler_var->var = param;<br>
> -            param->interface_type = param->type;<br>
> -            param->name = ralloc_strdup(param, val->name);<br>
> -<br>
> -            val->sampled_image = ralloc(b, struct vtn_sampled_image);<br>
> -            val->sampled_image->type = type;<br>
> -            val->sampled_image->image =<br>
> -               vtn_pointer_for_image_or_<wbr>sampler_variable(b, vtn_var);<br>
> -            val->sampled_image->sampler =<br>
> -               vtn_pointer_for_image_or_<wbr>sampler_variable(b, sampler_var);<br>
> -         } else {<br>
> -            struct vtn_value *val =<br>
> -               vtn_push_value(b, w[2], vtn_value_type_pointer);<br>
> -<br>
> -            /* Name the parameter so it shows up nicely in NIR */<br>
> -            param->name = ralloc_strdup(param, val->name);<br>
> -<br>
> -            val->pointer =<br>
> -               vtn_pointer_for_image_or_<wbr>sampler_variable(b, vtn_var);<br>
> -         }<br>
> +         nir_ssa_def *ssa_ptr = nir_load_param(&b->nb, b->func_param_idx++);<br>
> +         val->pointer = vtn_pointer_from_ssa(b, ssa_ptr, type);<br>
> +      } else if (type->base_type == vtn_base_type_pointer ||<br>
> +                 type->base_type == vtn_base_type_image ||<br>
> +                 type->base_type == vtn_base_type_sampler) {<br>
> +         struct vtn_value *val =<br>
> +            vtn_push_value(b, w[2], vtn_value_type_pointer);<br>
> +         val->pointer =<br>
> +            vtn_load_param_pointer(b, type, b->func_param_idx++);<br>
>        } else {<br>
>           /* We're a regular SSA value. */<br>
> -         struct vtn_ssa_value *param_ssa =<br>
> -            vtn_local_load(b, nir_build_deref_var(&b->nb, param));<br>
> -         struct vtn_value *val = vtn_push_ssa(b, w[2], type, param_ssa);<br>
> -<br>
> -         /* Name the parameter so it shows up nicely in NIR */<br>
> -         param->name = ralloc_strdup(param, val->name);<br>
> +         nir_ssa_def *param_val = nir_load_param(&b->nb, b->func_param_idx++);<br>
> +         nir_deref_instr *deref =<br>
> +            nir_build_deref_cast(&b->nb, param_val, nir_var_local, type->type);<br>
> +         vtn_push_ssa(b, w[2], type, vtn_local_load(b, deref));<br>
>        }<br>
>        break;<br>
>     }<br>
> @@ -729,9 +709,14 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list,<br>
>           nir_builder_instr_insert(&b-><wbr>nb, &block->end_nop->instr);<br>
><br>
>           if ((*block->branch & SpvOpCodeMask) == SpvOpReturnValue) {<br>
> +            vtn_fail_if(b->func->type-><wbr>return_type->base_type ==<br>
> +                        vtn_base_type_void,<br>
> +                        "Return with a value from a function returning void");<br>
>              struct vtn_ssa_value *src = vtn_ssa_value(b, block->branch[1]);<br>
> -            vtn_local_store(b, src,<br>
> -                            nir_build_deref_var(&b->nb, b->nb.impl->return_var));<br>
> +            nir_deref_instr *ret_deref =<br>
> +               nir_build_deref_cast(&b->nb, nir_load_param(&b->nb, 0),<br>
> +                                    nir_var_local, src->type);<br>
> +            vtn_local_store(b, src, ret_deref);<br>
>           }<br>
><br>
>           if (block->branch_type != vtn_branch_type_none) {<br>
> diff --git a/src/compiler/spirv/vtn_<wbr>private.h b/src/compiler/spirv/vtn_<wbr>private.h<br>
> index 6f2fcc7..42b1b30 100644<br>
> --- a/src/compiler/spirv/vtn_<wbr>private.h<br>
> +++ b/src/compiler/spirv/vtn_<wbr>private.h<br>
> @@ -403,7 +403,6 @@ struct vtn_access_chain {<br>
>  enum vtn_variable_mode {<br>
>     vtn_variable_mode_local,<br>
>     vtn_variable_mode_global,<br>
> -   vtn_variable_mode_param,<br>
>     vtn_variable_mode_ubo,<br>
>     vtn_variable_mode_ssbo,<br>
>     vtn_variable_mode_push_<wbr>constant,<br>
> @@ -678,8 +677,6 @@ struct vtn_pointer *vtn_pointer_for_variable(<wbr>struct vtn_builder *b,<br>
>                                               struct vtn_variable *var,<br>
>                                               struct vtn_type *ptr_type);<br>
><br>
> -nir_deref_var *vtn_pointer_to_deref_var(<wbr>struct vtn_builder *b,<br>
> -                                        struct vtn_pointer *ptr);<br>
>  nir_deref_instr *vtn_pointer_to_deref(struct vtn_builder *b,<br>
>                                        struct vtn_pointer *ptr);<br>
>  nir_ssa_def *<br>
> diff --git a/src/compiler/spirv/vtn_<wbr>variables.c b/src/compiler/spirv/vtn_<wbr>variables.c<br>
> index b15a4cf..4489d76 100644<br>
> --- a/src/compiler/spirv/vtn_<wbr>variables.c<br>
> +++ b/src/compiler/spirv/vtn_<wbr>variables.c<br>
> @@ -416,12 +416,6 @@ vtn_pointer_to_deref(struct vtn_builder *b, struct vtn_pointer *ptr)<br>
>     return tail;<br>
>  }<br>
><br>
> -nir_deref_var *<br>
> -vtn_pointer_to_deref_var(<wbr>struct vtn_builder *b, struct vtn_pointer *ptr)<br>
> -{<br>
> -   return nir_deref_instr_to_deref(vtn_<wbr>pointer_to_deref(b, ptr), b);<br>
> -}<br>
> -<br>
>  static void<br>
>  _vtn_local_load_store(struct vtn_builder *b, bool load, nir_deref_instr *deref,<br>
>                        struct vtn_ssa_value *inout)<br>
> @@ -1743,9 +1737,6 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,<br>
>        break;<br>
>     }<br>
><br>
> -   case vtn_variable_mode_param:<br>
> -      vtn_fail("Not created through OpVariable");<br>
> -<br>
>     case vtn_variable_mode_ubo:<br>
>     case vtn_variable_mode_ssbo:<br>
>     case vtn_variable_mode_push_<wbr>constant:<br>
> diff --git a/src/intel/vulkan/anv_<wbr>pipeline.c b/src/intel/vulkan/anv_<wbr>pipeline.c<br>
> index 20b0804..ee576f3 100644<br>
> --- a/src/intel/vulkan/anv_<wbr>pipeline.c<br>
> +++ b/src/intel/vulkan/anv_<wbr>pipeline.c<br>
> @@ -172,8 +172,6 @@ anv_shader_compile_to_nir(<wbr>struct anv_pipeline *pipeline,<br>
>        nir_print_shader(nir, stderr);<br>
>     }<br>
><br>
> -   NIR_PASS_V(nir, nir_lower_deref_instrs, ~0);<br>
> -<br>
>     /* We have to lower away local constant initializers right before we<br>
>      * inline functions.  That way they get properly initialized at the top<br>
>      * of the function and not at the top of its caller.<br>
> @@ -181,6 +179,7 @@ anv_shader_compile_to_nir(<wbr>struct anv_pipeline *pipeline,<br>
>     NIR_PASS_V(nir, nir_lower_constant_<wbr>initializers, nir_var_local);<br>
>     NIR_PASS_V(nir, nir_lower_returns);<br>
>     NIR_PASS_V(nir, nir_inline_functions);<br>
> +   NIR_PASS_V(nir, nir_copy_prop);<br>
><br>
>     /* Pick off the single entrypoint that we want */<br>
>     foreach_list_typed_safe(nir_<wbr>function, func, node, &nir->functions) {<br>
> @@ -190,6 +189,8 @@ anv_shader_compile_to_nir(<wbr>struct anv_pipeline *pipeline,<br>
>     assert(exec_list_length(&nir-><wbr>functions) == 1);<br>
>     entry_point->name = ralloc_strdup(entry_point, "main");<br>
><br>
> +   NIR_PASS_V(nir, nir_lower_deref_instrs, ~0);<br>
> +<br>
>     /* Now that we've deleted all but the main function, we can go ahead and<br>
>      * lower the rest of the constant initializers.  We do this here so that<br>
>      * nir_remove_dead_variables and split_per_member_structs below see the<br>
> --<br>
> 2.5.0.400.gff86faf<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">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/<wbr>mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br></div>