From e25967d6b81b9ac9dccfe92cc92dc8d977eab592 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 13 Jan 2020 15:30:07 -0800 Subject: [PATCH] mesa/st: Move the SYSTEM_VALUE -> TGSI_SEMANTIC map to tgsi_from_mesa. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This will let us reuse the table from nir-to-tgsi. Reviewed-by: Marek Olšák Reviewed-by: Kristian H. Kristensen Reviewed-by: Karol Herbst Part-of: --- src/gallium/auxiliary/tgsi/tgsi_from_mesa.c | 82 ++++++++++++++++++ src/gallium/auxiliary/tgsi/tgsi_from_mesa.h | 3 + src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 93 +-------------------- src/mesa/state_tracker/st_mesa_to_tgsi.c | 3 +- 4 files changed, 88 insertions(+), 93 deletions(-) diff --git a/src/gallium/auxiliary/tgsi/tgsi_from_mesa.c b/src/gallium/auxiliary/tgsi/tgsi_from_mesa.c index 19384cf4b27..72fd5c91c52 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_from_mesa.c +++ b/src/gallium/auxiliary/tgsi/tgsi_from_mesa.c @@ -204,3 +204,85 @@ tgsi_get_gl_frag_result_semantic(gl_frag_result frag_result, assert(false); } } + +/** Map Mesa's SYSTEM_VALUE_x to TGSI_SEMANTIC_x */ +enum tgsi_semantic +tgsi_get_sysval_semantic(unsigned sysval) +{ + switch (sysval) { + /* Vertex shader */ + case SYSTEM_VALUE_VERTEX_ID: + return TGSI_SEMANTIC_VERTEXID; + case SYSTEM_VALUE_INSTANCE_ID: + return TGSI_SEMANTIC_INSTANCEID; + case SYSTEM_VALUE_VERTEX_ID_ZERO_BASE: + return TGSI_SEMANTIC_VERTEXID_NOBASE; + case SYSTEM_VALUE_BASE_VERTEX: + return TGSI_SEMANTIC_BASEVERTEX; + case SYSTEM_VALUE_BASE_INSTANCE: + return TGSI_SEMANTIC_BASEINSTANCE; + case SYSTEM_VALUE_DRAW_ID: + return TGSI_SEMANTIC_DRAWID; + + /* Geometry shader */ + case SYSTEM_VALUE_INVOCATION_ID: + return TGSI_SEMANTIC_INVOCATIONID; + + /* Fragment shader */ + case SYSTEM_VALUE_FRAG_COORD: + return TGSI_SEMANTIC_POSITION; + case SYSTEM_VALUE_POINT_COORD: + return TGSI_SEMANTIC_PCOORD; + case SYSTEM_VALUE_FRONT_FACE: + return TGSI_SEMANTIC_FACE; + case SYSTEM_VALUE_SAMPLE_ID: + return TGSI_SEMANTIC_SAMPLEID; + case SYSTEM_VALUE_SAMPLE_POS: + return TGSI_SEMANTIC_SAMPLEPOS; + case SYSTEM_VALUE_SAMPLE_MASK_IN: + return TGSI_SEMANTIC_SAMPLEMASK; + case SYSTEM_VALUE_HELPER_INVOCATION: + return TGSI_SEMANTIC_HELPER_INVOCATION; + + /* Tessellation shader */ + case SYSTEM_VALUE_TESS_COORD: + return TGSI_SEMANTIC_TESSCOORD; + case SYSTEM_VALUE_VERTICES_IN: + return TGSI_SEMANTIC_VERTICESIN; + case SYSTEM_VALUE_PRIMITIVE_ID: + return TGSI_SEMANTIC_PRIMID; + case SYSTEM_VALUE_TESS_LEVEL_OUTER: + return TGSI_SEMANTIC_TESSOUTER; + case SYSTEM_VALUE_TESS_LEVEL_INNER: + return TGSI_SEMANTIC_TESSINNER; + + /* Compute shader */ + case SYSTEM_VALUE_LOCAL_INVOCATION_ID: + return TGSI_SEMANTIC_THREAD_ID; + case SYSTEM_VALUE_WORK_GROUP_ID: + return TGSI_SEMANTIC_BLOCK_ID; + case SYSTEM_VALUE_NUM_WORK_GROUPS: + return TGSI_SEMANTIC_GRID_SIZE; + case SYSTEM_VALUE_LOCAL_GROUP_SIZE: + return TGSI_SEMANTIC_BLOCK_SIZE; + + /* ARB_shader_ballot */ + case SYSTEM_VALUE_SUBGROUP_SIZE: + return TGSI_SEMANTIC_SUBGROUP_SIZE; + case SYSTEM_VALUE_SUBGROUP_INVOCATION: + return TGSI_SEMANTIC_SUBGROUP_INVOCATION; + case SYSTEM_VALUE_SUBGROUP_EQ_MASK: + return TGSI_SEMANTIC_SUBGROUP_EQ_MASK; + case SYSTEM_VALUE_SUBGROUP_GE_MASK: + return TGSI_SEMANTIC_SUBGROUP_GE_MASK; + case SYSTEM_VALUE_SUBGROUP_GT_MASK: + return TGSI_SEMANTIC_SUBGROUP_GT_MASK; + case SYSTEM_VALUE_SUBGROUP_LE_MASK: + return TGSI_SEMANTIC_SUBGROUP_LE_MASK; + case SYSTEM_VALUE_SUBGROUP_LT_MASK: + return TGSI_SEMANTIC_SUBGROUP_LT_MASK; + + default: + unreachable("Unexpected system value to TGSI"); + } +} diff --git a/src/gallium/auxiliary/tgsi/tgsi_from_mesa.h b/src/gallium/auxiliary/tgsi/tgsi_from_mesa.h index b75f37fed2e..92f08e2211a 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_from_mesa.h +++ b/src/gallium/auxiliary/tgsi/tgsi_from_mesa.h @@ -52,6 +52,9 @@ tgsi_get_gl_frag_result_semantic(gl_frag_result frag_result, unsigned *semantic_name, unsigned *semantic_index); +enum tgsi_semantic +tgsi_get_sysval_semantic(unsigned sysval); + static inline enum pipe_shader_type pipe_shader_type_from_mesa(gl_shader_stage stage) { diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 7d63aac716b..ae20092c498 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -5797,97 +5797,6 @@ struct st_translate { bool tg4_component_in_swizzle; }; -/** Map Mesa's SYSTEM_VALUE_x to TGSI_SEMANTIC_x */ -enum tgsi_semantic -_mesa_sysval_to_semantic(unsigned sysval) -{ - switch (sysval) { - /* Vertex shader */ - case SYSTEM_VALUE_VERTEX_ID: - return TGSI_SEMANTIC_VERTEXID; - case SYSTEM_VALUE_INSTANCE_ID: - return TGSI_SEMANTIC_INSTANCEID; - case SYSTEM_VALUE_VERTEX_ID_ZERO_BASE: - return TGSI_SEMANTIC_VERTEXID_NOBASE; - case SYSTEM_VALUE_BASE_VERTEX: - return TGSI_SEMANTIC_BASEVERTEX; - case SYSTEM_VALUE_BASE_INSTANCE: - return TGSI_SEMANTIC_BASEINSTANCE; - case SYSTEM_VALUE_DRAW_ID: - return TGSI_SEMANTIC_DRAWID; - - /* Geometry shader */ - case SYSTEM_VALUE_INVOCATION_ID: - return TGSI_SEMANTIC_INVOCATIONID; - - /* Fragment shader */ - case SYSTEM_VALUE_FRAG_COORD: - return TGSI_SEMANTIC_POSITION; - case SYSTEM_VALUE_POINT_COORD: - return TGSI_SEMANTIC_PCOORD; - case SYSTEM_VALUE_FRONT_FACE: - return TGSI_SEMANTIC_FACE; - case SYSTEM_VALUE_SAMPLE_ID: - return TGSI_SEMANTIC_SAMPLEID; - case SYSTEM_VALUE_SAMPLE_POS: - return TGSI_SEMANTIC_SAMPLEPOS; - case SYSTEM_VALUE_SAMPLE_MASK_IN: - return TGSI_SEMANTIC_SAMPLEMASK; - case SYSTEM_VALUE_HELPER_INVOCATION: - return TGSI_SEMANTIC_HELPER_INVOCATION; - - /* Tessellation shader */ - case SYSTEM_VALUE_TESS_COORD: - return TGSI_SEMANTIC_TESSCOORD; - case SYSTEM_VALUE_VERTICES_IN: - return TGSI_SEMANTIC_VERTICESIN; - case SYSTEM_VALUE_PRIMITIVE_ID: - return TGSI_SEMANTIC_PRIMID; - case SYSTEM_VALUE_TESS_LEVEL_OUTER: - return TGSI_SEMANTIC_TESSOUTER; - case SYSTEM_VALUE_TESS_LEVEL_INNER: - return TGSI_SEMANTIC_TESSINNER; - - /* Compute shader */ - case SYSTEM_VALUE_LOCAL_INVOCATION_ID: - return TGSI_SEMANTIC_THREAD_ID; - case SYSTEM_VALUE_WORK_GROUP_ID: - return TGSI_SEMANTIC_BLOCK_ID; - case SYSTEM_VALUE_NUM_WORK_GROUPS: - return TGSI_SEMANTIC_GRID_SIZE; - case SYSTEM_VALUE_LOCAL_GROUP_SIZE: - return TGSI_SEMANTIC_BLOCK_SIZE; - - /* ARB_shader_ballot */ - case SYSTEM_VALUE_SUBGROUP_SIZE: - return TGSI_SEMANTIC_SUBGROUP_SIZE; - case SYSTEM_VALUE_SUBGROUP_INVOCATION: - return TGSI_SEMANTIC_SUBGROUP_INVOCATION; - case SYSTEM_VALUE_SUBGROUP_EQ_MASK: - return TGSI_SEMANTIC_SUBGROUP_EQ_MASK; - case SYSTEM_VALUE_SUBGROUP_GE_MASK: - return TGSI_SEMANTIC_SUBGROUP_GE_MASK; - case SYSTEM_VALUE_SUBGROUP_GT_MASK: - return TGSI_SEMANTIC_SUBGROUP_GT_MASK; - case SYSTEM_VALUE_SUBGROUP_LE_MASK: - return TGSI_SEMANTIC_SUBGROUP_LE_MASK; - case SYSTEM_VALUE_SUBGROUP_LT_MASK: - return TGSI_SEMANTIC_SUBGROUP_LT_MASK; - - /* Unhandled */ - case SYSTEM_VALUE_LOCAL_INVOCATION_INDEX: - case SYSTEM_VALUE_GLOBAL_INVOCATION_ID: - case SYSTEM_VALUE_VERTEX_CNT: - case SYSTEM_VALUE_BARYCENTRIC_PERSP_PIXEL: - case SYSTEM_VALUE_BARYCENTRIC_PERSP_SAMPLE: - case SYSTEM_VALUE_BARYCENTRIC_PERSP_CENTROID: - case SYSTEM_VALUE_BARYCENTRIC_PERSP_SIZE: - default: - assert(!"Unexpected SYSTEM_VALUE_ enum"); - return TGSI_SEMANTIC_COUNT; - } -} - /** * Map a glsl_to_tgsi constant/immediate to a TGSI immediate. */ @@ -6923,7 +6832,7 @@ st_translate_program( for (i = 0; sysInputs; i++) { if (sysInputs & (1ull << i)) { - enum tgsi_semantic semName = _mesa_sysval_to_semantic(i); + enum tgsi_semantic semName = tgsi_get_sysval_semantic(i); t->systemValues[i] = ureg_DECL_system_value(ureg, semName, 0); diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c index 03a2dee6778..1f5a3cd077e 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -37,6 +37,7 @@ #include "pipe/p_shader_tokens.h" #include "pipe/p_state.h" #include "tgsi/tgsi_ureg.h" +#include "tgsi/tgsi_from_mesa.h" #include "st_mesa_to_tgsi.h" #include "st_context.h" #include "program/prog_instruction.h" @@ -954,7 +955,7 @@ st_translate_mesa_program(struct gl_context *ctx, GLbitfield64 sysInputs = program->info.system_values_read; for (i = 0; sysInputs; i++) { if (sysInputs & (1ull << i)) { - unsigned semName = _mesa_sysval_to_semantic(i); + unsigned semName = tgsi_get_sysval_semantic(i); t->systemValues[i] = ureg_DECL_system_value(ureg, semName, 0); -- 2.30.2