diff options
author | Louis-Francis Ratté-Boulianne <[email protected]> | 2019-10-12 01:13:54 -0400 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-03-03 12:28:23 +0000 |
commit | 82dc149254a791de1835e2402ed9a73511f42fdf (patch) | |
tree | 8d5d4c9e1cea109c4a54e8c5cba5ecb9ee7c1c3b /src/compiler | |
parent | 4a329bea44fca8607a3e4538b18fd93864d99c18 (diff) |
glsl/linker: add xfb workaround for modified built-in variables
Some lowering passes modify the value of built-in variables in
order for drivers to work properly. However, modifying such values
will also break transform feedback as the captured value won't
match what's expected.
For example, on some hardware, the vertex shaders are expected to
output gl_Position in screen space. However, the transform
feedback captured value is still supposed to be the world-space
coordinates (see nir_lower_viewport_transform).
To fix that, we create a new variable that contains the
pre-transformation value and use it for transform feedback instead
of the built-in one.
Signed-off-by: Louis-Francis Ratté-Boulianne <[email protected]>
Reviewed-by: Alyssa Rosenzweig <[email protected]>
Acked-by: Daniel Stone <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2433>
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/glsl/link_varyings.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp index 4757825c244..5219294ad7b 100644 --- a/src/compiler/glsl/link_varyings.cpp +++ b/src/compiler/glsl/link_varyings.cpp @@ -2794,15 +2794,26 @@ assign_varying_locations(struct gl_context *ctx, return false; } - /* A new output varying is needed, and the matched candidate should be - * replaced, if varying packing is disabled for xfb and the current - * declaration is not aligned within the top level varying - * (e.g. vec3_arr[1]). + /* There are two situations where a new output varying is needed: + * + * - If varying packing is disabled for xfb and the current declaration + * is not aligned within the top level varying (e.g. vec3_arr[1]). + * + * - If a builtin variable needs to be copied to a new variable + * before its content is modified by another lowering pass (e.g. + * \c gl_Position is transformed by \c nir_lower_viewport_transform). */ const unsigned dmul = matched_candidate->type->without_array()->is_64bit() ? 2 : 1; - if (disable_xfb_packing && - !tfeedback_decls[i].is_aligned(dmul, matched_candidate->offset)) { + const bool lowered = + (disable_xfb_packing && + !tfeedback_decls[i].is_aligned(dmul, matched_candidate->offset)) || + (matched_candidate->toplevel_var->data.explicit_location && + matched_candidate->toplevel_var->data.location < VARYING_SLOT_VAR0 && + (ctx->Const.ShaderCompilerOptions[producer->Stage].LowerBuiltinVariablesXfb & + BITFIELD_BIT(matched_candidate->toplevel_var->data.location))); + + if (lowered) { ir_variable *new_var; tfeedback_candidate *new_candidate = NULL; |