<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">I hate decorations... 1 and 2 are<br><br></div><div class="gmail_quote">Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div class="gmail_quote"><br>On Mon, Jan 9, 2017 at 7:16 AM, Iago Toral <span dir="ltr"><<a href="mailto:itoral@igalia.com" target="_blank">itoral@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Sun, 2017-01-08 at 21:26 -0800, Kenneth Graunke wrote:<br>
> We need to:<br>
> - handle the extra array level for per-vertex varyings<br>
> - handle the patch qualifier correctly<br>
> - assign varying locations<br>
><br>
> Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
> ---<br>
> src/compiler/spirv/vtn_<wbr>private.h | 1 +<br>
> src/compiler/spirv/vtn_<wbr>variables.c | 56<br>
> ++++++++++++++++++++++++++++++<wbr>++++----<br>
> 2 files changed, 52 insertions(+), 5 deletions(-)<br>
><br>
> diff --git a/src/compiler/spirv/vtn_<wbr>private.h<br>
> b/src/compiler/spirv/vtn_<wbr>private.h<br>
> index 9302611803f..8b450106543 100644<br>
> --- a/src/compiler/spirv/vtn_<wbr>private.h<br>
> +++ b/src/compiler/spirv/vtn_<wbr>private.h<br>
> @@ -280,6 +280,7 @@ struct vtn_variable {<br>
> unsigned descriptor_set;<br>
> unsigned binding;<br>
> unsigned input_attachment_index;<br>
> + bool patch;<br>
> <br>
> nir_variable *var;<br>
> nir_variable **members;<br>
> diff --git a/src/compiler/spirv/vtn_<wbr>variables.c<br>
> b/src/compiler/spirv/vtn_<wbr>variables.c<br>
> index e3845365bdd..dcd0609626b 100644<br>
> --- a/src/compiler/spirv/vtn_<wbr>variables.c<br>
> +++ b/src/compiler/spirv/vtn_<wbr>variables.c<br>
> @@ -935,10 +935,19 @@ vtn_get_builtin_location(<wbr>struct vtn_builder *b,<br>
> unreachable("invalid stage for SpvBuiltInViewportIndex");<br>
> break;<br>
> case SpvBuiltInTessLevelOuter:<br>
> + *location = VARYING_SLOT_TESS_LEVEL_OUTER;<br>
> + break;<br>
> case SpvBuiltInTessLevelInner:<br>
> + *location = VARYING_SLOT_TESS_LEVEL_INNER;<br>
> + break;<br>
> case SpvBuiltInTessCoord:<br>
> + *location = SYSTEM_VALUE_TESS_COORD;<br>
> + set_mode_system_value(<wbr>mode);<br>
> + break;<br>
> case SpvBuiltInPatchVertices:<br>
> - unreachable("no tessellation support");<br>
> + *location = SYSTEM_VALUE_VERTICES_IN;<br>
> + set_mode_system_value(<wbr>mode);<br>
> + break;<br>
> case SpvBuiltInFragCoord:<br>
> *location = VARYING_SLOT_POS;<br>
> assert(*mode == nir_var_shader_in);<br>
> @@ -1052,6 +1061,11 @@ apply_var_decoration(struct vtn_builder *b,<br>
> nir_variable *nir_var,<br>
> vtn_get_builtin_<wbr>location(b, builtin, &nir_var->data.location,<br>
> &mode);<br>
> nir_var->data.mode = mode;<br>
> <br>
> + if (builtin == SpvBuiltInTessLevelOuter ||<br>
> + builtin == SpvBuiltInTessLevelInner) {<br>
> + nir_var->data.<wbr>compact = true;<br>
> + }<br>
> +<br>
<br>
</div></div>This is a nitpick so feel free to ignore it: maybe we we want to put<br>
the two ifs below in a single 'else if' block after this hunk.<br><div class="HOEnZb"><div class="h5"></div></div></blockquote><div><br></div><div>I think I actually like it better the way he wrote it since they're setting unrelated things. :P<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
> if (builtin == SpvBuiltInFragCoord || builtin ==<br>
> SpvBuiltInSamplePosition)<br>
> nir_var->data.<wbr>origin_upper_left = b->origin_upper_left;<br>
> <br>
> @@ -1076,7 +1090,7 @@ apply_var_decoration(struct vtn_builder *b,<br>
> nir_variable *nir_var,<br>
> break; /* Do nothing with these here */<br>
> <br>
> case SpvDecorationPatch:<br>
> - vtn_warn("Tessellation not yet supported");<br>
> + nir_var->data.patch = true;<br>
> break;<br>
> <br>
> case SpvDecorationLocation:<br>
> @@ -1116,6 +1130,15 @@ apply_var_decoration(struct vtn_builder *b,<br>
> nir_variable *nir_var,<br>
> }<br>
> <br>
> static void<br>
> +var_is_patch_cb(struct vtn_builder *b, struct vtn_value *val, int<br>
> member,<br>
> + const struct vtn_decoration *dec, void<br>
> *out_is_patch)<br>
> +{<br>
> + if (dec->decoration == SpvDecorationPatch) {<br>
> + *((bool *) out_is_patch) = true;<br>
> + }<br>
> +}<br>
> +<br>
> +static void<br>
> var_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int<br>
> member,<br>
> const struct vtn_decoration *dec, void *void_var)<br>
> {<br>
> @@ -1132,6 +1155,9 @@ var_decoration_cb(struct vtn_builder *b, struct<br>
> vtn_value *val, int member,<br>
> case SpvDecorationInputAttachmentIn<wbr>dex:<br>
> vtn_var->input_<wbr>attachment_index = dec->literals[0];<br>
> return;<br>
> + case SpvDecorationPatch:<br>
> + vtn_var->patch = true;<br>
> + break;<br>
> default:<br>
> break;<br>
> }<br>
> @@ -1162,7 +1188,7 @@ var_decoration_cb(struct vtn_builder *b, struct<br>
> vtn_value *val, int member,<br>
> } else if (vtn_var->mode == vtn_variable_mode_input ||<br>
> vtn_var-><wbr>mode == vtn_variable_mode_output) {<br>
> is_vertex_input = false;<br>
> - location += VARYING_SLOT_VAR0;<br>
> + location += vtn_var->patch ? VARYING_SLOT_PATCH0 :<br>
> VARYING_SLOT_VAR0;<br>
> } else {<br>
> unreachable("<wbr>Location must be on input or output<br>
> variable");<br>
> }<br>
> @@ -1209,6 +1235,24 @@ var_decoration_cb(struct vtn_builder *b,<br>
> struct vtn_value *val, int member,<br>
> }<br>
> }<br>
> <br>
> +static bool<br>
> +is_per_vertex_inout(const struct vtn_variable *var, gl_shader_stage<br>
> stage)<br>
> +{<br>
> + if (var->patch || !glsl_type_is_array(var->type-<wbr>>type))<br>
> + return false;<br>
> +<br>
> + if (var->mode == vtn_variable_mode_input) {<br>
> + return stage == MESA_SHADER_TESS_CTRL ||<br>
> + stage == MESA_SHADER_TESS_EVAL ||<br>
> + stage == MESA_SHADER_GEOMETRY;<br>
> + }<br>
> +<br>
> + if (var->mode == vtn_variable_mode_output)<br>
> + return stage == MESA_SHADER_TESS_CTRL;<br>
> +<br>
> + return false;<br>
> +}<br>
> +<br>
> void<br>
> vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,<br>
> const uint32_t *w, unsigned count)<br>
> @@ -1308,6 +1352,9 @@ vtn_handle_variables(struct vtn_builder *b,<br>
> SpvOp opcode,<br>
> <br>
> case vtn_variable_mode_input:<br>
> case vtn_variable_mode_output: {<br>
> + var->patch = false;<br>
> + vtn_foreach_<wbr>decoration(b, val, var_is_patch_cb, &var-<br>
> >patch);<br>
> +<br>
> /* For inputs and outputs, we immediately split<br>
> structures. This<br>
> * is for a couple of reasons. For one, builtins may all<br>
> come in<br>
> * a struct and we really want those split out into<br>
> separate<br>
> @@ -1318,8 +1365,7 @@ vtn_handle_variables(struct vtn_builder *b,<br>
> SpvOp opcode,<br>
> <br>
> int array_length = -1;<br>
> struct vtn_type *interface_type = var->type;<br>
> - if (b->shader->stage == MESA_SHADER_GEOMETRY &&<br>
> - glsl_type_is_<wbr>array(var->type->type)) {<br>
> + if (is_per_vertex_inout(var, b->shader->stage)) {<br>
> /* In Geometry shaders (and some tessellation), inputs<br>
> come<br>
> * in per-vertex arrays. However, some builtins come in<br>
> * non-per-vertex, hence the need for the is_array<br>
> check. In<br>
</div></div><div class="HOEnZb"><div class="h5">______________________________<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>
</div></div></blockquote></div><br></div></div>