[Mesa-dev] [PATCH 10/92] tgsi, st/mesa: move varying slot to semantic mapping into a helper for VS
Samuel Pitoiset
samuel.pitoiset at gmail.com
Mon Jul 3 15:41:52 UTC 2017
Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
On 06/26/2017 04:09 PM, Nicolai Hähnle wrote:
> From: Nicolai Hähnle <nicolai.haehnle at amd.com>
>
> We will use this helper in radeonsi's NIR path.
> ---
> src/gallium/auxiliary/Makefile.sources | 2 +
> src/gallium/auxiliary/tgsi/tgsi_from_mesa.c | 150 ++++++++++++++++++++++++++++
> src/gallium/auxiliary/tgsi/tgsi_from_mesa.h | 43 ++++++++
> src/mesa/state_tracker/st_program.c | 86 +---------------
> src/mesa/state_tracker/st_program.h | 21 +---
> 5 files changed, 203 insertions(+), 99 deletions(-)
> create mode 100644 src/gallium/auxiliary/tgsi/tgsi_from_mesa.c
> create mode 100644 src/gallium/auxiliary/tgsi/tgsi_from_mesa.h
>
> diff --git a/src/gallium/auxiliary/Makefile.sources b/src/gallium/auxiliary/Makefile.sources
> index 99ab0c0..9ae8e6c 100644
> --- a/src/gallium/auxiliary/Makefile.sources
> +++ b/src/gallium/auxiliary/Makefile.sources
> @@ -140,20 +140,22 @@ C_SOURCES := \
> tgsi/tgsi_aa_point.c \
> tgsi/tgsi_aa_point.h \
> tgsi/tgsi_build.c \
> tgsi/tgsi_build.h \
> tgsi/tgsi_dump.c \
> tgsi/tgsi_dump.h \
> tgsi/tgsi_exec.c \
> tgsi/tgsi_exec.h \
> tgsi/tgsi_emulate.c \
> tgsi/tgsi_emulate.h \
> + tgsi/tgsi_from_mesa.c \
> + tgsi/tgsi_from_mesa.h \
> tgsi/tgsi_info.c \
> tgsi/tgsi_info.h \
> tgsi/tgsi_iterate.c \
> tgsi/tgsi_iterate.h \
> tgsi/tgsi_lowering.c \
> tgsi/tgsi_lowering.h \
> tgsi/tgsi_opcode_tmp.h \
> tgsi/tgsi_parse.c \
> tgsi/tgsi_parse.h \
> tgsi/tgsi_point_sprite.c \
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_from_mesa.c b/src/gallium/auxiliary/tgsi/tgsi_from_mesa.c
> new file mode 100644
> index 0000000..44fae1c
> --- /dev/null
> +++ b/src/gallium/auxiliary/tgsi/tgsi_from_mesa.c
> @@ -0,0 +1,150 @@
> +/*
> + * Copyright 2017 Advanced Micro Devices, Inc.
> + *
> + * 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
> + * on the rights to use, copy, modify, merge, publish, distribute, sub
> + * license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS 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 "tgsi/tgsi_from_mesa.h"
> +
> +#include "pipe/p_compiler.h"
> +
> +/**
> + * Determine the semantic index that is used when the given varying is mapped
> + * to TGSI_SEMANTIC_GENERIC.
> + */
> +unsigned
> +tgsi_get_generic_gl_varying_index(gl_varying_slot attr,
> + bool needs_texcoord_semantic)
> +{
> + if (attr >= VARYING_SLOT_VAR0) {
> + if (needs_texcoord_semantic)
> + return attr - VARYING_SLOT_VAR0;
> + else
> + return 9 + (attr - VARYING_SLOT_VAR0);
> + }
> + if (attr == VARYING_SLOT_PNTC) {
> + assert(!needs_texcoord_semantic);
> + return 8;
> + }
> + if (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7) {
> + assert(!needs_texcoord_semantic);
> + return attr - VARYING_SLOT_TEX0;
> + }
> +
> + assert(0);
> + return 0;
> +}
> +
> +/**
> + * Determine the semantic name and index used for the given varying.
> + */
> +void
> +tgsi_get_gl_varying_semantic(gl_varying_slot attr,
> + bool needs_texcoord_semantic,
> + unsigned *semantic_name,
> + unsigned *semantic_index)
> +{
> + switch (attr) {
> + case VARYING_SLOT_POS:
> + *semantic_name = TGSI_SEMANTIC_POSITION;
> + *semantic_index = 0;
> + break;
> + case VARYING_SLOT_COL0:
> + *semantic_name = TGSI_SEMANTIC_COLOR;
> + *semantic_index = 0;
> + break;
> + case VARYING_SLOT_COL1:
> + *semantic_name = TGSI_SEMANTIC_COLOR;
> + *semantic_index = 1;
> + break;
> + case VARYING_SLOT_BFC0:
> + *semantic_name = TGSI_SEMANTIC_BCOLOR;
> + *semantic_index = 0;
> + break;
> + case VARYING_SLOT_BFC1:
> + *semantic_name = TGSI_SEMANTIC_BCOLOR;
> + *semantic_index = 1;
> + break;
> + case VARYING_SLOT_FOGC:
> + *semantic_name = TGSI_SEMANTIC_FOG;
> + *semantic_index = 0;
> + break;
> + case VARYING_SLOT_PSIZ:
> + *semantic_name = TGSI_SEMANTIC_PSIZE;
> + *semantic_index = 0;
> + break;
> + case VARYING_SLOT_CLIP_DIST0:
> + *semantic_name = TGSI_SEMANTIC_CLIPDIST;
> + *semantic_index = 0;
> + break;
> + case VARYING_SLOT_CLIP_DIST1:
> + *semantic_name = TGSI_SEMANTIC_CLIPDIST;
> + *semantic_index = 1;
> + break;
> + case VARYING_SLOT_CULL_DIST0:
> + case VARYING_SLOT_CULL_DIST1:
> + /* these should have been lowered by GLSL */
> + assert(0);
> + break;
> + case VARYING_SLOT_EDGE:
> + *semantic_name = TGSI_SEMANTIC_EDGEFLAG;
> + *semantic_index = 0;
> + break;
> + case VARYING_SLOT_CLIP_VERTEX:
> + *semantic_name = TGSI_SEMANTIC_CLIPVERTEX;
> + *semantic_index = 0;
> + break;
> + case VARYING_SLOT_LAYER:
> + *semantic_name = TGSI_SEMANTIC_LAYER;
> + *semantic_index = 0;
> + break;
> + case VARYING_SLOT_VIEWPORT:
> + *semantic_name = TGSI_SEMANTIC_VIEWPORT_INDEX;
> + *semantic_index = 0;
> + break;
> + case VARYING_SLOT_PNTC:
> + *semantic_name = TGSI_SEMANTIC_PCOORD;
> + *semantic_index = 0;
> + break;
> +
> + case VARYING_SLOT_TEX0:
> + case VARYING_SLOT_TEX1:
> + case VARYING_SLOT_TEX2:
> + case VARYING_SLOT_TEX3:
> + case VARYING_SLOT_TEX4:
> + case VARYING_SLOT_TEX5:
> + case VARYING_SLOT_TEX6:
> + case VARYING_SLOT_TEX7:
> + if (needs_texcoord_semantic) {
> + *semantic_name = TGSI_SEMANTIC_TEXCOORD;
> + *semantic_index = attr - VARYING_SLOT_TEX0;
> + break;
> + }
> + /* fall through */
> + case VARYING_SLOT_VAR0:
> + default:
> + assert(attr >= VARYING_SLOT_VAR0 ||
> + (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7));
> + *semantic_name = TGSI_SEMANTIC_GENERIC;
> + *semantic_index =
> + tgsi_get_generic_gl_varying_index(attr, needs_texcoord_semantic);
> + break;
> + }
> +}
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_from_mesa.h b/src/gallium/auxiliary/tgsi/tgsi_from_mesa.h
> new file mode 100644
> index 0000000..4c708f4
> --- /dev/null
> +++ b/src/gallium/auxiliary/tgsi/tgsi_from_mesa.h
> @@ -0,0 +1,43 @@
> +/*
> + * Copyright 2017 Advanced Micro Devices, Inc.
> + *
> + * 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
> + * on the rights to use, copy, modify, merge, publish, distribute, sub
> + * license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS 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.
> + */
> +
> +#ifndef TGSI_FROM_MESA_H
> +#define TGSI_FROM_MESA_H
> +
> +#include <stdbool.h>
> +
> +#include "pipe/p_shader_tokens.h"
> +
> +#include "compiler/shader_enums.h"
> +
> +void
> +tgsi_get_gl_varying_semantic(gl_varying_slot attr,
> + bool needs_texcoord_semantic,
> + unsigned *semantic_name,
> + unsigned *semantic_index);
> +
> +unsigned
> +tgsi_get_generic_gl_varying_index(gl_varying_slot attr,
> + bool needs_texcoord_semantic);
> +
> +#endif /* TGSI_FROM_MESA_H */
> diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
> index 6de6174..eb44fc5 100644
> --- a/src/mesa/state_tracker/st_program.c
> +++ b/src/mesa/state_tracker/st_program.c
> @@ -410,101 +410,25 @@ st_translate_vertex_program(struct st_context *st,
> */
> for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
> if ((stvp->Base.info.outputs_written & BITFIELD64_BIT(attr)) == 0) {
> stvp->result_to_output[attr] = ~0;
> }
> else {
> unsigned slot = num_outputs++;
>
> stvp->result_to_output[attr] = slot;
>
> - switch (attr) {
> - case VARYING_SLOT_POS:
> - output_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
> - output_semantic_index[slot] = 0;
> - break;
> - case VARYING_SLOT_COL0:
> - output_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
> - output_semantic_index[slot] = 0;
> - break;
> - case VARYING_SLOT_COL1:
> - output_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
> - output_semantic_index[slot] = 1;
> - break;
> - case VARYING_SLOT_BFC0:
> - output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR;
> - output_semantic_index[slot] = 0;
> - break;
> - case VARYING_SLOT_BFC1:
> - output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR;
> - output_semantic_index[slot] = 1;
> - break;
> - case VARYING_SLOT_FOGC:
> - output_semantic_name[slot] = TGSI_SEMANTIC_FOG;
> - output_semantic_index[slot] = 0;
> - break;
> - case VARYING_SLOT_PSIZ:
> - output_semantic_name[slot] = TGSI_SEMANTIC_PSIZE;
> - output_semantic_index[slot] = 0;
> - break;
> - case VARYING_SLOT_CLIP_DIST0:
> - output_semantic_name[slot] = TGSI_SEMANTIC_CLIPDIST;
> - output_semantic_index[slot] = 0;
> - break;
> - case VARYING_SLOT_CLIP_DIST1:
> - output_semantic_name[slot] = TGSI_SEMANTIC_CLIPDIST;
> - output_semantic_index[slot] = 1;
> - break;
> - case VARYING_SLOT_CULL_DIST0:
> - case VARYING_SLOT_CULL_DIST1:
> - /* these should have been lowered by GLSL */
> - assert(0);
> - break;
> - case VARYING_SLOT_EDGE:
> - assert(0);
> - break;
> - case VARYING_SLOT_CLIP_VERTEX:
> - output_semantic_name[slot] = TGSI_SEMANTIC_CLIPVERTEX;
> - output_semantic_index[slot] = 0;
> - break;
> - case VARYING_SLOT_LAYER:
> - output_semantic_name[slot] = TGSI_SEMANTIC_LAYER;
> - output_semantic_index[slot] = 0;
> - break;
> - case VARYING_SLOT_VIEWPORT:
> - output_semantic_name[slot] = TGSI_SEMANTIC_VIEWPORT_INDEX;
> - output_semantic_index[slot] = 0;
> - break;
> -
> - case VARYING_SLOT_TEX0:
> - case VARYING_SLOT_TEX1:
> - case VARYING_SLOT_TEX2:
> - case VARYING_SLOT_TEX3:
> - case VARYING_SLOT_TEX4:
> - case VARYING_SLOT_TEX5:
> - case VARYING_SLOT_TEX6:
> - case VARYING_SLOT_TEX7:
> - if (st->needs_texcoord_semantic) {
> - output_semantic_name[slot] = TGSI_SEMANTIC_TEXCOORD;
> - output_semantic_index[slot] = attr - VARYING_SLOT_TEX0;
> - break;
> - }
> - /* fall through */
> - case VARYING_SLOT_VAR0:
> - default:
> - assert(attr >= VARYING_SLOT_VAR0 ||
> - (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7));
> - output_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
> - output_semantic_index[slot] =
> - st_get_generic_varying_index(st, attr);
> - break;
> - }
> + unsigned semantic_name, semantic_index;
> + tgsi_get_gl_varying_semantic(attr, st->needs_texcoord_semantic,
> + &semantic_name, &semantic_index);
> + output_semantic_name[slot] = semantic_name;
> + output_semantic_index[slot] = semantic_index;
> }
> }
> /* similar hack to above, presetup potentially unused edgeflag output */
> stvp->result_to_output[VARYING_SLOT_EDGE] = num_outputs;
> output_semantic_name[num_outputs] = TGSI_SEMANTIC_EDGEFLAG;
> output_semantic_index[num_outputs] = 0;
>
> /* ARB_vp: */
> if (!stvp->glsl_to_tgsi && !stvp->shader_program) {
> _mesa_remove_output_reads(&stvp->Base, PROGRAM_OUTPUT);
> diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
> index 3f0cf49..8e9f4c5 100644
> --- a/src/mesa/state_tracker/st_program.h
> +++ b/src/mesa/state_tracker/st_program.h
> @@ -31,25 +31,25 @@
> */
>
>
> #ifndef ST_PROGRAM_H
> #define ST_PROGRAM_H
>
> #include "main/mtypes.h"
> #include "main/atifragshader.h"
> #include "program/program.h"
> #include "pipe/p_state.h"
> +#include "tgsi/tgsi_from_mesa.h"
> #include "st_context.h"
> #include "st_texture.h"
> #include "st_glsl_to_tgsi.h"
>
> -
> #ifdef __cplusplus
> extern "C" {
> #endif
>
> #define ST_DOUBLE_ATTRIB_PLACEHOLDER 0xff
>
> struct st_external_sampler_key
> {
> GLuint lower_nv12; /**< bitmask of 2 plane YUV samplers */
> GLuint lower_iyuv; /**< bitmask of 3 plane YUV samplers */
> @@ -351,37 +351,22 @@ st_reference_compprog(struct st_context *st,
> (struct gl_program **) ptr,
> (struct gl_program *) prog);
> }
>
> /**
> * This defines mapping from Mesa VARYING_SLOTs to TGSI GENERIC slots.
> */
> static inline unsigned
> st_get_generic_varying_index(struct st_context *st, GLuint attr)
> {
> - if (attr >= VARYING_SLOT_VAR0) {
> - if (st->needs_texcoord_semantic)
> - return attr - VARYING_SLOT_VAR0;
> - else
> - return 9 + (attr - VARYING_SLOT_VAR0);
> - }
> - if (attr == VARYING_SLOT_PNTC) {
> - assert(!st->needs_texcoord_semantic);
> - return 8;
> - }
> - if (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7) {
> - assert(!st->needs_texcoord_semantic);
> - return attr - VARYING_SLOT_TEX0;
> - }
> -
> - assert(0);
> - return 0;
> + return tgsi_get_generic_gl_varying_index((gl_varying_slot)attr,
> + st->needs_texcoord_semantic);
> }
>
> extern void
> st_set_prog_affected_state_flags(struct gl_program *prog);
>
> extern struct st_vp_variant *
> st_get_vp_variant(struct st_context *st,
> struct st_vertex_program *stvp,
> const struct st_vp_variant_key *key);
>
>
More information about the mesa-dev
mailing list