1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2017 Advanced Micro Devices, Inc. 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub 8bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom 9bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include "tgsi/tgsi_from_mesa.h" 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include "pipe/p_compiler.h" 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "util/compiler.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci/** 31bf215546Sopenharmony_ci * Determine the semantic index that is used when the given varying is mapped 32bf215546Sopenharmony_ci * to TGSI_SEMANTIC_GENERIC. 33bf215546Sopenharmony_ci */ 34bf215546Sopenharmony_ciunsigned 35bf215546Sopenharmony_citgsi_get_generic_gl_varying_index(gl_varying_slot attr, 36bf215546Sopenharmony_ci bool needs_texcoord_semantic) 37bf215546Sopenharmony_ci{ 38bf215546Sopenharmony_ci if (attr >= VARYING_SLOT_VAR0) { 39bf215546Sopenharmony_ci if (needs_texcoord_semantic) 40bf215546Sopenharmony_ci return attr - VARYING_SLOT_VAR0; 41bf215546Sopenharmony_ci else 42bf215546Sopenharmony_ci return 9 + (attr - VARYING_SLOT_VAR0); 43bf215546Sopenharmony_ci } 44bf215546Sopenharmony_ci if (attr == VARYING_SLOT_PNTC) { 45bf215546Sopenharmony_ci assert(!needs_texcoord_semantic); 46bf215546Sopenharmony_ci return 8; 47bf215546Sopenharmony_ci } 48bf215546Sopenharmony_ci if (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7) { 49bf215546Sopenharmony_ci assert(!needs_texcoord_semantic); 50bf215546Sopenharmony_ci return attr - VARYING_SLOT_TEX0; 51bf215546Sopenharmony_ci } 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_ci assert(0); 54bf215546Sopenharmony_ci return 0; 55bf215546Sopenharmony_ci} 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci/** 58bf215546Sopenharmony_ci * Determine the semantic name and index used for the given varying. 59bf215546Sopenharmony_ci */ 60bf215546Sopenharmony_civoid 61bf215546Sopenharmony_citgsi_get_gl_varying_semantic(gl_varying_slot attr, 62bf215546Sopenharmony_ci bool needs_texcoord_semantic, 63bf215546Sopenharmony_ci unsigned *semantic_name, 64bf215546Sopenharmony_ci unsigned *semantic_index) 65bf215546Sopenharmony_ci{ 66bf215546Sopenharmony_ci switch (attr) { 67bf215546Sopenharmony_ci case VARYING_SLOT_PRIMITIVE_ID: 68bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_PRIMID; 69bf215546Sopenharmony_ci *semantic_index = 0; 70bf215546Sopenharmony_ci break; 71bf215546Sopenharmony_ci case VARYING_SLOT_POS: 72bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_POSITION; 73bf215546Sopenharmony_ci *semantic_index = 0; 74bf215546Sopenharmony_ci break; 75bf215546Sopenharmony_ci case VARYING_SLOT_COL0: 76bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_COLOR; 77bf215546Sopenharmony_ci *semantic_index = 0; 78bf215546Sopenharmony_ci break; 79bf215546Sopenharmony_ci case VARYING_SLOT_COL1: 80bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_COLOR; 81bf215546Sopenharmony_ci *semantic_index = 1; 82bf215546Sopenharmony_ci break; 83bf215546Sopenharmony_ci case VARYING_SLOT_BFC0: 84bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_BCOLOR; 85bf215546Sopenharmony_ci *semantic_index = 0; 86bf215546Sopenharmony_ci break; 87bf215546Sopenharmony_ci case VARYING_SLOT_BFC1: 88bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_BCOLOR; 89bf215546Sopenharmony_ci *semantic_index = 1; 90bf215546Sopenharmony_ci break; 91bf215546Sopenharmony_ci case VARYING_SLOT_FOGC: 92bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_FOG; 93bf215546Sopenharmony_ci *semantic_index = 0; 94bf215546Sopenharmony_ci break; 95bf215546Sopenharmony_ci case VARYING_SLOT_PSIZ: 96bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_PSIZE; 97bf215546Sopenharmony_ci *semantic_index = 0; 98bf215546Sopenharmony_ci break; 99bf215546Sopenharmony_ci case VARYING_SLOT_CLIP_DIST0: 100bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_CLIPDIST; 101bf215546Sopenharmony_ci *semantic_index = 0; 102bf215546Sopenharmony_ci break; 103bf215546Sopenharmony_ci case VARYING_SLOT_CLIP_DIST1: 104bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_CLIPDIST; 105bf215546Sopenharmony_ci *semantic_index = 1; 106bf215546Sopenharmony_ci break; 107bf215546Sopenharmony_ci case VARYING_SLOT_CULL_DIST0: 108bf215546Sopenharmony_ci case VARYING_SLOT_CULL_DIST1: 109bf215546Sopenharmony_ci /* these should have been lowered by GLSL */ 110bf215546Sopenharmony_ci assert(0); 111bf215546Sopenharmony_ci break; 112bf215546Sopenharmony_ci case VARYING_SLOT_EDGE: 113bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_EDGEFLAG; 114bf215546Sopenharmony_ci *semantic_index = 0; 115bf215546Sopenharmony_ci break; 116bf215546Sopenharmony_ci case VARYING_SLOT_CLIP_VERTEX: 117bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_CLIPVERTEX; 118bf215546Sopenharmony_ci *semantic_index = 0; 119bf215546Sopenharmony_ci break; 120bf215546Sopenharmony_ci case VARYING_SLOT_LAYER: 121bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_LAYER; 122bf215546Sopenharmony_ci *semantic_index = 0; 123bf215546Sopenharmony_ci break; 124bf215546Sopenharmony_ci case VARYING_SLOT_VIEWPORT: 125bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_VIEWPORT_INDEX; 126bf215546Sopenharmony_ci *semantic_index = 0; 127bf215546Sopenharmony_ci break; 128bf215546Sopenharmony_ci case VARYING_SLOT_FACE: 129bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_FACE; 130bf215546Sopenharmony_ci *semantic_index = 0; 131bf215546Sopenharmony_ci break; 132bf215546Sopenharmony_ci case VARYING_SLOT_PNTC: 133bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_PCOORD; 134bf215546Sopenharmony_ci *semantic_index = 0; 135bf215546Sopenharmony_ci break; 136bf215546Sopenharmony_ci case VARYING_SLOT_TESS_LEVEL_OUTER: 137bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_TESSOUTER; 138bf215546Sopenharmony_ci *semantic_index = 0; 139bf215546Sopenharmony_ci break; 140bf215546Sopenharmony_ci case VARYING_SLOT_TESS_LEVEL_INNER: 141bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_TESSINNER; 142bf215546Sopenharmony_ci *semantic_index = 0; 143bf215546Sopenharmony_ci break; 144bf215546Sopenharmony_ci case VARYING_SLOT_VIEWPORT_MASK: 145bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_VIEWPORT_MASK; 146bf215546Sopenharmony_ci *semantic_index = 0; 147bf215546Sopenharmony_ci break; 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_ci case VARYING_SLOT_TEX0: 150bf215546Sopenharmony_ci case VARYING_SLOT_TEX1: 151bf215546Sopenharmony_ci case VARYING_SLOT_TEX2: 152bf215546Sopenharmony_ci case VARYING_SLOT_TEX3: 153bf215546Sopenharmony_ci case VARYING_SLOT_TEX4: 154bf215546Sopenharmony_ci case VARYING_SLOT_TEX5: 155bf215546Sopenharmony_ci case VARYING_SLOT_TEX6: 156bf215546Sopenharmony_ci case VARYING_SLOT_TEX7: 157bf215546Sopenharmony_ci if (needs_texcoord_semantic) { 158bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_TEXCOORD; 159bf215546Sopenharmony_ci *semantic_index = attr - VARYING_SLOT_TEX0; 160bf215546Sopenharmony_ci break; 161bf215546Sopenharmony_ci } 162bf215546Sopenharmony_ci FALLTHROUGH; 163bf215546Sopenharmony_ci case VARYING_SLOT_VAR0: 164bf215546Sopenharmony_ci default: 165bf215546Sopenharmony_ci assert(attr >= VARYING_SLOT_VAR0 || 166bf215546Sopenharmony_ci (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7)); 167bf215546Sopenharmony_ci if (attr >= VARYING_SLOT_PATCH0) { 168bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_PATCH; 169bf215546Sopenharmony_ci *semantic_index = attr - VARYING_SLOT_PATCH0; 170bf215546Sopenharmony_ci } else { 171bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_GENERIC; 172bf215546Sopenharmony_ci *semantic_index = 173bf215546Sopenharmony_ci tgsi_get_generic_gl_varying_index(attr, needs_texcoord_semantic); 174bf215546Sopenharmony_ci } 175bf215546Sopenharmony_ci break; 176bf215546Sopenharmony_ci } 177bf215546Sopenharmony_ci} 178bf215546Sopenharmony_ci 179bf215546Sopenharmony_ci/** 180bf215546Sopenharmony_ci * Determine the semantic name and index used for the given fragment shader 181bf215546Sopenharmony_ci * result. 182bf215546Sopenharmony_ci */ 183bf215546Sopenharmony_civoid 184bf215546Sopenharmony_citgsi_get_gl_frag_result_semantic(gl_frag_result frag_result, 185bf215546Sopenharmony_ci unsigned *semantic_name, 186bf215546Sopenharmony_ci unsigned *semantic_index) 187bf215546Sopenharmony_ci{ 188bf215546Sopenharmony_ci if (frag_result >= FRAG_RESULT_DATA0) { 189bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_COLOR; 190bf215546Sopenharmony_ci *semantic_index = frag_result - FRAG_RESULT_DATA0; 191bf215546Sopenharmony_ci return; 192bf215546Sopenharmony_ci } 193bf215546Sopenharmony_ci 194bf215546Sopenharmony_ci *semantic_index = 0; 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_ci switch (frag_result) { 197bf215546Sopenharmony_ci case FRAG_RESULT_DEPTH: 198bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_POSITION; 199bf215546Sopenharmony_ci break; 200bf215546Sopenharmony_ci case FRAG_RESULT_STENCIL: 201bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_STENCIL; 202bf215546Sopenharmony_ci break; 203bf215546Sopenharmony_ci case FRAG_RESULT_COLOR: 204bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_COLOR; 205bf215546Sopenharmony_ci break; 206bf215546Sopenharmony_ci case FRAG_RESULT_SAMPLE_MASK: 207bf215546Sopenharmony_ci *semantic_name = TGSI_SEMANTIC_SAMPLEMASK; 208bf215546Sopenharmony_ci break; 209bf215546Sopenharmony_ci default: 210bf215546Sopenharmony_ci assert(false); 211bf215546Sopenharmony_ci } 212bf215546Sopenharmony_ci} 213bf215546Sopenharmony_ci 214bf215546Sopenharmony_ci/** Map Mesa's SYSTEM_VALUE_x to TGSI_SEMANTIC_x */ 215bf215546Sopenharmony_cienum tgsi_semantic 216bf215546Sopenharmony_citgsi_get_sysval_semantic(unsigned sysval) 217bf215546Sopenharmony_ci{ 218bf215546Sopenharmony_ci switch (sysval) { 219bf215546Sopenharmony_ci /* Vertex shader */ 220bf215546Sopenharmony_ci case SYSTEM_VALUE_VERTEX_ID: 221bf215546Sopenharmony_ci return TGSI_SEMANTIC_VERTEXID; 222bf215546Sopenharmony_ci case SYSTEM_VALUE_INSTANCE_ID: 223bf215546Sopenharmony_ci return TGSI_SEMANTIC_INSTANCEID; 224bf215546Sopenharmony_ci case SYSTEM_VALUE_VERTEX_ID_ZERO_BASE: 225bf215546Sopenharmony_ci return TGSI_SEMANTIC_VERTEXID_NOBASE; 226bf215546Sopenharmony_ci case SYSTEM_VALUE_BASE_VERTEX: 227bf215546Sopenharmony_ci return TGSI_SEMANTIC_BASEVERTEX; 228bf215546Sopenharmony_ci case SYSTEM_VALUE_BASE_INSTANCE: 229bf215546Sopenharmony_ci return TGSI_SEMANTIC_BASEINSTANCE; 230bf215546Sopenharmony_ci case SYSTEM_VALUE_DRAW_ID: 231bf215546Sopenharmony_ci return TGSI_SEMANTIC_DRAWID; 232bf215546Sopenharmony_ci 233bf215546Sopenharmony_ci /* Geometry shader */ 234bf215546Sopenharmony_ci case SYSTEM_VALUE_INVOCATION_ID: 235bf215546Sopenharmony_ci return TGSI_SEMANTIC_INVOCATIONID; 236bf215546Sopenharmony_ci 237bf215546Sopenharmony_ci /* Fragment shader */ 238bf215546Sopenharmony_ci case SYSTEM_VALUE_FRAG_COORD: 239bf215546Sopenharmony_ci return TGSI_SEMANTIC_POSITION; 240bf215546Sopenharmony_ci case SYSTEM_VALUE_POINT_COORD: 241bf215546Sopenharmony_ci return TGSI_SEMANTIC_PCOORD; 242bf215546Sopenharmony_ci case SYSTEM_VALUE_FRONT_FACE: 243bf215546Sopenharmony_ci return TGSI_SEMANTIC_FACE; 244bf215546Sopenharmony_ci case SYSTEM_VALUE_SAMPLE_ID: 245bf215546Sopenharmony_ci return TGSI_SEMANTIC_SAMPLEID; 246bf215546Sopenharmony_ci case SYSTEM_VALUE_SAMPLE_POS: 247bf215546Sopenharmony_ci return TGSI_SEMANTIC_SAMPLEPOS; 248bf215546Sopenharmony_ci case SYSTEM_VALUE_SAMPLE_MASK_IN: 249bf215546Sopenharmony_ci return TGSI_SEMANTIC_SAMPLEMASK; 250bf215546Sopenharmony_ci case SYSTEM_VALUE_HELPER_INVOCATION: 251bf215546Sopenharmony_ci return TGSI_SEMANTIC_HELPER_INVOCATION; 252bf215546Sopenharmony_ci 253bf215546Sopenharmony_ci /* Tessellation shader */ 254bf215546Sopenharmony_ci case SYSTEM_VALUE_TESS_COORD: 255bf215546Sopenharmony_ci return TGSI_SEMANTIC_TESSCOORD; 256bf215546Sopenharmony_ci case SYSTEM_VALUE_VERTICES_IN: 257bf215546Sopenharmony_ci return TGSI_SEMANTIC_VERTICESIN; 258bf215546Sopenharmony_ci case SYSTEM_VALUE_PRIMITIVE_ID: 259bf215546Sopenharmony_ci return TGSI_SEMANTIC_PRIMID; 260bf215546Sopenharmony_ci case SYSTEM_VALUE_TESS_LEVEL_OUTER: 261bf215546Sopenharmony_ci return TGSI_SEMANTIC_TESSOUTER; 262bf215546Sopenharmony_ci case SYSTEM_VALUE_TESS_LEVEL_INNER: 263bf215546Sopenharmony_ci return TGSI_SEMANTIC_TESSINNER; 264bf215546Sopenharmony_ci 265bf215546Sopenharmony_ci /* Compute shader */ 266bf215546Sopenharmony_ci case SYSTEM_VALUE_LOCAL_INVOCATION_ID: 267bf215546Sopenharmony_ci return TGSI_SEMANTIC_THREAD_ID; 268bf215546Sopenharmony_ci case SYSTEM_VALUE_WORKGROUP_ID: 269bf215546Sopenharmony_ci return TGSI_SEMANTIC_BLOCK_ID; 270bf215546Sopenharmony_ci case SYSTEM_VALUE_NUM_WORKGROUPS: 271bf215546Sopenharmony_ci return TGSI_SEMANTIC_GRID_SIZE; 272bf215546Sopenharmony_ci case SYSTEM_VALUE_WORKGROUP_SIZE: 273bf215546Sopenharmony_ci return TGSI_SEMANTIC_BLOCK_SIZE; 274bf215546Sopenharmony_ci 275bf215546Sopenharmony_ci /* ARB_shader_ballot */ 276bf215546Sopenharmony_ci case SYSTEM_VALUE_SUBGROUP_SIZE: 277bf215546Sopenharmony_ci return TGSI_SEMANTIC_SUBGROUP_SIZE; 278bf215546Sopenharmony_ci case SYSTEM_VALUE_SUBGROUP_INVOCATION: 279bf215546Sopenharmony_ci return TGSI_SEMANTIC_SUBGROUP_INVOCATION; 280bf215546Sopenharmony_ci case SYSTEM_VALUE_SUBGROUP_EQ_MASK: 281bf215546Sopenharmony_ci return TGSI_SEMANTIC_SUBGROUP_EQ_MASK; 282bf215546Sopenharmony_ci case SYSTEM_VALUE_SUBGROUP_GE_MASK: 283bf215546Sopenharmony_ci return TGSI_SEMANTIC_SUBGROUP_GE_MASK; 284bf215546Sopenharmony_ci case SYSTEM_VALUE_SUBGROUP_GT_MASK: 285bf215546Sopenharmony_ci return TGSI_SEMANTIC_SUBGROUP_GT_MASK; 286bf215546Sopenharmony_ci case SYSTEM_VALUE_SUBGROUP_LE_MASK: 287bf215546Sopenharmony_ci return TGSI_SEMANTIC_SUBGROUP_LE_MASK; 288bf215546Sopenharmony_ci case SYSTEM_VALUE_SUBGROUP_LT_MASK: 289bf215546Sopenharmony_ci return TGSI_SEMANTIC_SUBGROUP_LT_MASK; 290bf215546Sopenharmony_ci 291bf215546Sopenharmony_ci default: 292bf215546Sopenharmony_ci unreachable("Unexpected system value to TGSI"); 293bf215546Sopenharmony_ci } 294bf215546Sopenharmony_ci} 295bf215546Sopenharmony_ci 296bf215546Sopenharmony_cienum tgsi_interpolate_mode 297bf215546Sopenharmony_citgsi_get_interp_mode(enum glsl_interp_mode mode, bool color) 298bf215546Sopenharmony_ci{ 299bf215546Sopenharmony_ci switch (mode) { 300bf215546Sopenharmony_ci case INTERP_MODE_NONE: 301bf215546Sopenharmony_ci return color ? TGSI_INTERPOLATE_COLOR : TGSI_INTERPOLATE_PERSPECTIVE; 302bf215546Sopenharmony_ci case INTERP_MODE_FLAT: 303bf215546Sopenharmony_ci return TGSI_INTERPOLATE_CONSTANT; 304bf215546Sopenharmony_ci case INTERP_MODE_NOPERSPECTIVE: 305bf215546Sopenharmony_ci return TGSI_INTERPOLATE_LINEAR; 306bf215546Sopenharmony_ci case INTERP_MODE_SMOOTH: 307bf215546Sopenharmony_ci return TGSI_INTERPOLATE_PERSPECTIVE; 308bf215546Sopenharmony_ci default: 309bf215546Sopenharmony_ci unreachable("unknown interpolation mode"); 310bf215546Sopenharmony_ci } 311bf215546Sopenharmony_ci} 312