nir: Add a nir_sysvals_to_varyings() helper
Allow backends to turn some sysvals into input varyings so the frontend (in our case spirv_to_nir()) doesn't have to bother selecting which one is expected. Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13017>
This commit is contained in:
parent
b71bdc3404
commit
56251f924d
|
@ -207,6 +207,7 @@ files_libnir = files(
|
|||
'nir_lower_bit_size.c',
|
||||
'nir_lower_ubo_vec4.c',
|
||||
'nir_lower_uniforms_to_ubo.c',
|
||||
'nir_lower_sysvals_to_varyings.c',
|
||||
'nir_metadata.c',
|
||||
'nir_move_vec_src_uses_to_dest.c',
|
||||
'nir_normalize_cubemap_coords.c',
|
||||
|
|
|
@ -5048,6 +5048,16 @@ typedef struct nir_lower_compute_system_values_options {
|
|||
bool nir_lower_compute_system_values(nir_shader *shader,
|
||||
const nir_lower_compute_system_values_options *options);
|
||||
|
||||
struct nir_lower_sysvals_to_varyings_options {
|
||||
bool frag_coord:1;
|
||||
bool front_face:1;
|
||||
bool point_coord:1;
|
||||
};
|
||||
|
||||
bool
|
||||
nir_lower_sysvals_to_varyings(nir_shader *shader,
|
||||
const struct nir_lower_sysvals_to_varyings_options *options);
|
||||
|
||||
enum PACKED nir_lower_tex_packing {
|
||||
/** No packing */
|
||||
nir_lower_tex_packing_none = 0,
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright © 2021 Collabora Ltd.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "nir.h"
|
||||
#include "nir_builder.h"
|
||||
|
||||
/*
|
||||
* spirv_to_nir() creates system values for some builtin inputs, but
|
||||
* backends might want to have those inputs exposed as varyings. This
|
||||
* lowering pass allows backends to convert system values to input
|
||||
* varyings and should be called just after spirv_to_nir() when needed.
|
||||
*/
|
||||
|
||||
bool
|
||||
nir_lower_sysvals_to_varyings(nir_shader *shader,
|
||||
const struct nir_lower_sysvals_to_varyings_options *options)
|
||||
{
|
||||
bool progress = false;
|
||||
|
||||
nir_foreach_variable_with_modes(var, shader, nir_var_system_value) {
|
||||
switch (var->data.location) {
|
||||
#define SYSVAL_TO_VARYING(opt, sysval, varying) \
|
||||
case SYSTEM_VALUE_ ## sysval: \
|
||||
if (options->opt) { \
|
||||
var->data.mode = nir_var_shader_in; \
|
||||
var->data.location = VARYING_SLOT_ ## varying; \
|
||||
progress = true; \
|
||||
} \
|
||||
break
|
||||
|
||||
SYSVAL_TO_VARYING(frag_coord, FRAG_COORD, POS);
|
||||
SYSVAL_TO_VARYING(point_coord, POINT_COORD, PNTC);
|
||||
SYSVAL_TO_VARYING(front_face, FRONT_FACE, FACE);
|
||||
|
||||
#undef SYSVAL_TO_VARYING
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (progress)
|
||||
nir_fixup_deref_modes(shader);
|
||||
|
||||
/* Nothing this does actually changes anything tracked by metadata.
|
||||
* If we ever made this pass more complicated, we might need to care
|
||||
* more about metadata.
|
||||
*/
|
||||
nir_shader_preserve_all_metadata(shader);
|
||||
|
||||
return progress;
|
||||
}
|
Loading…
Reference in New Issue