From: Marek Olšák Date: Sat, 15 Aug 2020 07:09:34 +0000 (-0400) Subject: radeonsi: replace TGSI_SEMANTIC with VARYING_SLOT and FRAG_RESULT X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6ecb8b689976d21868e56a4f59f1354ea256d23d;p=mesa.git radeonsi: replace TGSI_SEMANTIC with VARYING_SLOT and FRAG_RESULT Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- diff --git a/src/gallium/drivers/radeonsi/gfx10_shader_ngg.c b/src/gallium/drivers/radeonsi/gfx10_shader_ngg.c index f9415bde279..cc3ff50e8e0 100644 --- a/src/gallium/drivers/radeonsi/gfx10_shader_ngg.c +++ b/src/gallium/drivers/radeonsi/gfx10_shader_ngg.c @@ -232,8 +232,7 @@ static void build_streamout_vertex(struct si_shader_context *ctx, LLVMValueRef * unsigned reg = so->output[i].register_index; struct si_shader_output_values out; - out.semantic_name = info->output_semantic_name[reg]; - out.semantic_index = info->output_semantic_index[reg]; + out.semantic = info->output_semantic[reg]; for (unsigned comp = 0; comp < 4; comp++) { tmp = ac_build_gep0(&ctx->ac, vertexptr, LLVMConstInt(ctx->ac.i32, 4 * reg + comp, false)); @@ -737,8 +736,8 @@ void gfx10_emit_ngg_culling_epilogue(struct ac_shader_abi *abi, unsigned max_out LLVMValueRef position[4] = {}; for (unsigned i = 0; i < info->num_outputs; i++) { - switch (info->output_semantic_name[i]) { - case TGSI_SEMANTIC_POSITION: + switch (info->output_semantic[i]) { + case VARYING_SLOT_POS: for (unsigned j = 0; j < 4; j++) { position[j] = LLVMBuildLoad(ctx->ac.builder, addrs[4 * i + j], ""); } @@ -1201,8 +1200,7 @@ void gfx10_emit_ngg_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, LL vertex_ptr = ngg_nogs_vertex_ptr(ctx, get_thread_id_in_tg(ctx)); for (unsigned i = 0; i < info->num_outputs; i++) { - outputs[i].semantic_name = info->output_semantic_name[i]; - outputs[i].semantic_index = info->output_semantic_index[i]; + outputs[i].semantic = info->output_semantic[i]; for (unsigned j = 0; j < 4; j++) { outputs[i].vertex_stream[j] = (info->output_streams[i] >> (2 * j)) & 3; @@ -1219,7 +1217,7 @@ void gfx10_emit_ngg_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, LL } /* Store the edgeflag at the end (if streamout is enabled) */ - if (info->output_semantic_name[i] == TGSI_SEMANTIC_EDGEFLAG && sel->info.writes_edgeflag) { + if (info->output_semantic[i] == VARYING_SLOT_EDGE && sel->info.writes_edgeflag) { LLVMValueRef edgeflag = LLVMBuildLoad(builder, addrs[4 * i], ""); /* The output is a float, but the hw expects a 1-bit integer. */ edgeflag = LLVMBuildFPToUI(ctx->ac.builder, edgeflag, ctx->ac.i32, ""); @@ -1377,7 +1375,7 @@ void gfx10_emit_ngg_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, LL * use the position from the current shader part. Instead, * load it from LDS. */ - if (info->output_semantic_name[i] == TGSI_SEMANTIC_POSITION && + if (info->output_semantic[i] == VARYING_SLOT_POS && ctx->shader->key.opt.ngg_culling) { vertex_ptr = ngg_nogs_vertex_ptr(ctx, ac_get_arg(&ctx->ac, ctx->ngg_old_thread_id)); @@ -1395,8 +1393,7 @@ void gfx10_emit_ngg_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, LL } if (ctx->shader->key.mono.u.vs_export_prim_id) { - outputs[i].semantic_name = TGSI_SEMANTIC_PRIMID; - outputs[i].semantic_index = 0; + outputs[i].semantic = VARYING_SLOT_PRIMITIVE_ID; if (ctx->stage == MESA_SHADER_VERTEX) { /* Wait for GS stores to finish. */ @@ -1862,8 +1859,7 @@ void gfx10_ngg_gs_emit_epilogue(struct si_shader_context *ctx) unsigned out_idx = 0; for (unsigned i = 0; i < info->num_outputs; i++) { - outputs[i].semantic_name = info->output_semantic_name[i]; - outputs[i].semantic_index = info->output_semantic_index[i]; + outputs[i].semantic = info->output_semantic[i]; for (unsigned j = 0; j < 4; j++, out_idx++) { tmp = ngg_gs_get_emit_output_ptr(ctx, vertexptr, out_idx); diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index d02227cd0f6..823ec198714 100644 --- a/src/gallium/drivers/radeonsi/si_shader.c +++ b/src/gallium/drivers/radeonsi/si_shader.c @@ -61,19 +61,18 @@ bool si_is_merged_shader(struct si_shader *shader) * must be less than 32, so that a 32-bit bitmask of used inputs or outputs * can be calculated. */ -unsigned si_shader_io_get_unique_index_patch(unsigned semantic_name, unsigned index) +unsigned si_shader_io_get_unique_index_patch(unsigned semantic) { - switch (semantic_name) { - case TGSI_SEMANTIC_TESSOUTER: + switch (semantic) { + case VARYING_SLOT_TESS_LEVEL_OUTER: return 0; - case TGSI_SEMANTIC_TESSINNER: + case VARYING_SLOT_TESS_LEVEL_INNER: return 1; - case TGSI_SEMANTIC_PATCH: - assert(index < 30); - return 2 + index; - default: - assert(!"invalid semantic name"); + if (semantic >= VARYING_SLOT_PATCH0 && semantic < VARYING_SLOT_PATCH0 + 30) + return 2 + (semantic - VARYING_SLOT_PATCH0); + + assert(!"invalid semantic"); return 0; } } @@ -83,59 +82,68 @@ unsigned si_shader_io_get_unique_index_patch(unsigned semantic_name, unsigned in * less than 64, so that a 64-bit bitmask of used inputs or outputs can be * calculated. */ -unsigned si_shader_io_get_unique_index(unsigned semantic_name, unsigned index, unsigned is_varying) +unsigned si_shader_io_get_unique_index(unsigned semantic, bool is_varying) { - switch (semantic_name) { - case TGSI_SEMANTIC_POSITION: + switch (semantic) { + case VARYING_SLOT_POS: return 0; - case TGSI_SEMANTIC_GENERIC: + default: /* Since some shader stages use the the highest used IO index * to determine the size to allocate for inputs/outputs * (in LDS, tess and GS rings). GENERIC should be placed right * after POSITION to make that size as small as possible. */ - if (index < SI_MAX_IO_GENERIC) - return 1 + index; + if (semantic >= VARYING_SLOT_VAR0 && + semantic < VARYING_SLOT_VAR0 + SI_MAX_IO_GENERIC) + return 1 + (semantic - VARYING_SLOT_VAR0); assert(!"invalid generic index"); return 0; - case TGSI_SEMANTIC_FOG: + case VARYING_SLOT_FOGC: return SI_MAX_IO_GENERIC + 1; - case TGSI_SEMANTIC_COLOR: - assert(index < 2); - return SI_MAX_IO_GENERIC + 2 + index; - case TGSI_SEMANTIC_BCOLOR: - assert(index < 2); + case VARYING_SLOT_COL0: + return SI_MAX_IO_GENERIC + 2; + case VARYING_SLOT_COL1: + return SI_MAX_IO_GENERIC + 3; + case VARYING_SLOT_BFC0: /* If it's a varying, COLOR and BCOLOR alias. */ if (is_varying) - return SI_MAX_IO_GENERIC + 2 + index; + return SI_MAX_IO_GENERIC + 2; else - return SI_MAX_IO_GENERIC + 4 + index; - case TGSI_SEMANTIC_TEXCOORD: - assert(index < 8); - return SI_MAX_IO_GENERIC + 6 + index; + return SI_MAX_IO_GENERIC + 4; + case VARYING_SLOT_BFC1: + if (is_varying) + return SI_MAX_IO_GENERIC + 3; + else + return SI_MAX_IO_GENERIC + 5; + 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: + return SI_MAX_IO_GENERIC + 6 + (semantic - VARYING_SLOT_TEX0); /* These are rarely used between LS and HS or ES and GS. */ - case TGSI_SEMANTIC_CLIPDIST: - assert(index < 2); - return SI_MAX_IO_GENERIC + 6 + 8 + index; - case TGSI_SEMANTIC_CLIPVERTEX: + case VARYING_SLOT_CLIP_DIST0: + return SI_MAX_IO_GENERIC + 6 + 8; + case VARYING_SLOT_CLIP_DIST1: + return SI_MAX_IO_GENERIC + 6 + 8 + 1; + case VARYING_SLOT_CLIP_VERTEX: return SI_MAX_IO_GENERIC + 6 + 8 + 2; - case TGSI_SEMANTIC_PSIZE: + case VARYING_SLOT_PSIZ: return SI_MAX_IO_GENERIC + 6 + 8 + 3; /* These can't be written by LS, HS, and ES. */ - case TGSI_SEMANTIC_LAYER: + case VARYING_SLOT_LAYER: return SI_MAX_IO_GENERIC + 6 + 8 + 4; - case TGSI_SEMANTIC_VIEWPORT_INDEX: + case VARYING_SLOT_VIEWPORT: return SI_MAX_IO_GENERIC + 6 + 8 + 5; - case TGSI_SEMANTIC_PRIMID: + case VARYING_SLOT_PRIMITIVE_ID: STATIC_ASSERT(SI_MAX_IO_GENERIC + 6 + 8 + 6 <= 63); return SI_MAX_IO_GENERIC + 6 + 8 + 6; - default: - fprintf(stderr, "invalid semantic name = %u\n", semantic_name); - assert(!"invalid semantic name"); - return 0; } } @@ -1303,8 +1311,9 @@ static void si_optimize_vs_outputs(struct si_shader_context *ctx) /* Optimizing these outputs is not possible, since they might be overriden * at runtime with S_028644_PT_SPRITE_TEX. */ for (int i = 0; i < info->num_outputs; i++) { - if (info->output_semantic_name[i] == TGSI_SEMANTIC_PCOORD || - info->output_semantic_name[i] == TGSI_SEMANTIC_TEXCOORD) { + if (info->output_semantic[i] == VARYING_SLOT_PNTC || + (info->output_semantic[i] >= VARYING_SLOT_TEX0 && + info->output_semantic[i] <= VARYING_SLOT_TEX7)) { skip_vs_optim_mask |= 1u << shader->info.vs_output_param_offset[i]; } } diff --git a/src/gallium/drivers/radeonsi/si_shader.h b/src/gallium/drivers/radeonsi/si_shader.h index 838fc9f823e..7ad282a651f 100644 --- a/src/gallium/drivers/radeonsi/si_shader.h +++ b/src/gallium/drivers/radeonsi/si_shader.h @@ -152,7 +152,7 @@ struct si_context; #define SI_MAX_ATTRIBS 16 #define SI_MAX_VS_OUTPUTS 40 -/* Shader IO unique indices are supported for TGSI_SEMANTIC_GENERIC with an +/* Shader IO unique indices are supported for VARYING_SLOT_VARn with an * index smaller than this. */ #define SI_MAX_IO_GENERIC 32 @@ -323,12 +323,10 @@ struct si_shader_info { ubyte num_inputs; ubyte num_outputs; - ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; /**< TGSI_SEMANTIC_x */ - ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS]; + ubyte input_semantic[PIPE_MAX_SHADER_INPUTS]; ubyte input_interpolate[PIPE_MAX_SHADER_INPUTS]; ubyte input_usage_mask[PIPE_MAX_SHADER_INPUTS]; - ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; /**< TGSI_SEMANTIC_x */ - ubyte output_semantic_index[PIPE_MAX_SHADER_OUTPUTS]; + ubyte output_semantic[PIPE_MAX_SHADER_OUTPUTS]; ubyte output_usagemask[PIPE_MAX_SHADER_OUTPUTS]; ubyte output_readmask[PIPE_MAX_SHADER_OUTPUTS]; ubyte output_streams[PIPE_MAX_SHADER_OUTPUTS]; @@ -842,8 +840,8 @@ bool si_compile_shader(struct si_screen *sscreen, struct ac_llvm_compiler *compi bool si_create_shader_variant(struct si_screen *sscreen, struct ac_llvm_compiler *compiler, struct si_shader *shader, struct pipe_debug_callback *debug); void si_shader_destroy(struct si_shader *shader); -unsigned si_shader_io_get_unique_index_patch(unsigned semantic_name, unsigned index); -unsigned si_shader_io_get_unique_index(unsigned semantic_name, unsigned index, unsigned is_varying); +unsigned si_shader_io_get_unique_index_patch(unsigned semantic); +unsigned si_shader_io_get_unique_index(unsigned semantic, bool is_varying); bool si_shader_binary_upload(struct si_screen *sscreen, struct si_shader *shader, uint64_t scratch_va); void si_shader_dump(struct si_screen *sscreen, struct si_shader *shader, diff --git a/src/gallium/drivers/radeonsi/si_shader_internal.h b/src/gallium/drivers/radeonsi/si_shader_internal.h index 86ea04df644..5e3a46cf836 100644 --- a/src/gallium/drivers/radeonsi/si_shader_internal.h +++ b/src/gallium/drivers/radeonsi/si_shader_internal.h @@ -39,9 +39,8 @@ struct pipe_debug_callback; struct si_shader_output_values { LLVMValueRef values[4]; - unsigned semantic_name; - unsigned semantic_index; ubyte vertex_stream[4]; + ubyte semantic; }; struct si_shader_context { diff --git a/src/gallium/drivers/radeonsi/si_shader_llvm_gs.c b/src/gallium/drivers/radeonsi/si_shader_llvm_gs.c index da6115a55ea..553720eba7f 100644 --- a/src/gallium/drivers/radeonsi/si_shader_llvm_gs.c +++ b/src/gallium/drivers/radeonsi/si_shader_llvm_gs.c @@ -49,12 +49,10 @@ static LLVMValueRef si_llvm_load_input_gs(struct ac_shader_abi *abi, unsigned in struct si_shader *shader = ctx->shader; LLVMValueRef vtx_offset, soffset; struct si_shader_info *info = &shader->selector->info; - unsigned semantic_name = info->input_semantic_name[input_index]; - unsigned semantic_index = info->input_semantic_index[input_index]; unsigned param; LLVMValueRef value; - param = si_shader_io_get_unique_index(semantic_name, semantic_index, false); + param = si_shader_io_get_unique_index(info->input_semantic[input_index], false); /* GFX9 has the ESGS ring in LDS. */ if (ctx->screen->info.chip_class >= GFX9) { @@ -200,12 +198,11 @@ void si_llvm_emit_es_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, L for (i = 0; i < info->num_outputs; i++) { int param; - if (info->output_semantic_name[i] == TGSI_SEMANTIC_VIEWPORT_INDEX || - info->output_semantic_name[i] == TGSI_SEMANTIC_LAYER) + if (info->output_semantic[i] == VARYING_SLOT_VIEWPORT || + info->output_semantic[i] == VARYING_SLOT_LAYER) continue; - param = si_shader_io_get_unique_index(info->output_semantic_name[i], - info->output_semantic_index[i], false); + param = si_shader_io_get_unique_index(info->output_semantic[i], false); for (chan = 0; chan < 4; chan++) { if (!(info->output_usagemask[i] & (1 << chan))) @@ -500,8 +497,7 @@ struct si_shader *si_generate_gs_copy_shader(struct si_screen *sscreen, /* Fill in output information. */ for (i = 0; i < gsinfo->num_outputs; ++i) { - outputs[i].semantic_name = gsinfo->output_semantic_name[i]; - outputs[i].semantic_index = gsinfo->output_semantic_index[i]; + outputs[i].semantic = gsinfo->output_semantic[i]; for (int chan = 0; chan < 4; chan++) { outputs[i].vertex_stream[chan] = (gsinfo->output_streams[i] >> (2 * chan)) & 3; diff --git a/src/gallium/drivers/radeonsi/si_shader_llvm_ps.c b/src/gallium/drivers/radeonsi/si_shader_llvm_ps.c index c5d2cd56f79..78cdadb269b 100644 --- a/src/gallium/drivers/radeonsi/si_shader_llvm_ps.c +++ b/src/gallium/drivers/radeonsi/si_shader_llvm_ps.c @@ -131,7 +131,6 @@ static LLVMValueRef si_build_fs_interp(struct si_shader_context *ctx, unsigned a * * @param ctx context * @param input_index index of the input in hardware - * @param semantic_name TGSI_SEMANTIC_* * @param semantic_index semantic index * @param num_interp_inputs number of all interpolated inputs (= BCOLOR offset) * @param colors_read_mask color components read (4 bits for each color, 8 bits in total) @@ -475,29 +474,31 @@ static void si_llvm_return_fs_outputs(struct ac_shader_abi *abi, unsigned max_ou /* Read the output values. */ for (i = 0; i < info->num_outputs; i++) { - unsigned semantic_name = info->output_semantic_name[i]; - unsigned semantic_index = info->output_semantic_index[i]; - - switch (semantic_name) { - case TGSI_SEMANTIC_COLOR: - assert(semantic_index < 8); - for (j = 0; j < 4; j++) { - LLVMValueRef ptr = addrs[4 * i + j]; - LLVMValueRef result = LLVMBuildLoad(builder, ptr, ""); - color[semantic_index][j] = result; - } - break; - case TGSI_SEMANTIC_POSITION: + unsigned semantic = info->output_semantic[i]; + + switch (semantic) { + case FRAG_RESULT_DEPTH: depth = LLVMBuildLoad(builder, addrs[4 * i + 0], ""); break; - case TGSI_SEMANTIC_STENCIL: + case FRAG_RESULT_STENCIL: stencil = LLVMBuildLoad(builder, addrs[4 * i + 0], ""); break; - case TGSI_SEMANTIC_SAMPLEMASK: + case FRAG_RESULT_SAMPLE_MASK: samplemask = LLVMBuildLoad(builder, addrs[4 * i + 0], ""); break; default: - fprintf(stderr, "Warning: GFX6 unhandled fs output type:%d\n", semantic_name); + if (semantic >= FRAG_RESULT_DATA0 && semantic <= FRAG_RESULT_DATA7) { + unsigned index = semantic - FRAG_RESULT_DATA0; + + for (j = 0; j < 4; j++) { + LLVMValueRef ptr = addrs[4 * i + j]; + LLVMValueRef result = LLVMBuildLoad(builder, ptr, ""); + color[index][j] = result; + } + } else { + fprintf(stderr, "Warning: Unhandled fs output type:%d\n", semantic); + } + break; } } diff --git a/src/gallium/drivers/radeonsi/si_shader_llvm_tess.c b/src/gallium/drivers/radeonsi/si_shader_llvm_tess.c index e0c5142edf0..6794f2cbb5b 100644 --- a/src/gallium/drivers/radeonsi/si_shader_llvm_tess.c +++ b/src/gallium/drivers/radeonsi/si_shader_llvm_tess.c @@ -173,7 +173,7 @@ static LLVMValueRef get_tcs_in_vertex_dw_stride(struct si_shader_context *ctx) static LLVMValueRef get_dw_address_from_generic_indices(struct si_shader_context *ctx, LLVMValueRef vertex_dw_stride, LLVMValueRef base_addr, LLVMValueRef vertex_index, - LLVMValueRef param_index, ubyte name, ubyte index) + LLVMValueRef param_index, ubyte name) { if (vertex_dw_stride) { base_addr = ac_build_imad(&ctx->ac, vertex_index, vertex_dw_stride, base_addr); @@ -183,10 +183,11 @@ get_dw_address_from_generic_indices(struct si_shader_context *ctx, LLVMValueRef base_addr = ac_build_imad(&ctx->ac, param_index, LLVMConstInt(ctx->ac.i32, 4, 0), base_addr); } - int param = name == TGSI_SEMANTIC_PATCH || name == TGSI_SEMANTIC_TESSINNER || - name == TGSI_SEMANTIC_TESSOUTER - ? si_shader_io_get_unique_index_patch(name, index) - : si_shader_io_get_unique_index(name, index, false); + int param = name >= VARYING_SLOT_PATCH0 || + name == VARYING_SLOT_TESS_LEVEL_INNER || + name == VARYING_SLOT_TESS_LEVEL_OUTER + ? si_shader_io_get_unique_index_patch(name) + : si_shader_io_get_unique_index(name, false); /* Add the base address of the element. */ return LLVMBuildAdd(ctx->ac.builder, base_addr, LLVMConstInt(ctx->ac.i32, param * 4, 0), ""); @@ -244,14 +245,15 @@ static LLVMValueRef get_tcs_tes_buffer_address(struct si_shader_context *ctx, static LLVMValueRef get_tcs_tes_buffer_address_from_generic_indices(struct si_shader_context *ctx, LLVMValueRef vertex_index, LLVMValueRef param_index, - ubyte name, ubyte index) + ubyte name) { unsigned param_index_base; - param_index_base = name == TGSI_SEMANTIC_PATCH || name == TGSI_SEMANTIC_TESSINNER || - name == TGSI_SEMANTIC_TESSOUTER - ? si_shader_io_get_unique_index_patch(name, index) - : si_shader_io_get_unique_index(name, index, false); + param_index_base = name >= VARYING_SLOT_PATCH0 || + name == VARYING_SLOT_TESS_LEVEL_INNER || + name == VARYING_SLOT_TESS_LEVEL_OUTER + ? si_shader_io_get_unique_index_patch(name) + : si_shader_io_get_unique_index(name, false); if (param_index) { param_index = LLVMBuildAdd(ctx->ac.builder, param_index, @@ -405,21 +407,20 @@ static LLVMValueRef si_nir_load_tcs_varyings(struct ac_shader_abi *abi, LLVMType struct si_shader_context *ctx = si_shader_context_from_abi(abi); struct si_shader_info *info = &ctx->shader->selector->info; LLVMValueRef dw_addr, stride; - ubyte name, index; + ubyte semantic; driver_location = driver_location / 4; if (load_input) { - name = info->input_semantic_name[driver_location]; - index = info->input_semantic_index[driver_location]; + semantic = info->input_semantic[driver_location]; } else { - name = info->output_semantic_name[driver_location]; - index = info->output_semantic_index[driver_location]; + semantic = info->output_semantic[driver_location]; } bool is_patch = vertex_index == NULL; - assert((name == TGSI_SEMANTIC_PATCH || name == TGSI_SEMANTIC_TESSINNER || - name == TGSI_SEMANTIC_TESSOUTER) == is_patch); + assert((semantic >= VARYING_SLOT_PATCH0 || + semantic == VARYING_SLOT_TESS_LEVEL_INNER || + semantic == VARYING_SLOT_TESS_LEVEL_OUTER) == is_patch); if (load_input) { stride = get_tcs_in_vertex_dw_stride(ctx); @@ -439,7 +440,7 @@ static LLVMValueRef si_nir_load_tcs_varyings(struct ac_shader_abi *abi, LLVMType } dw_addr = get_dw_address_from_generic_indices(ctx, stride, dw_addr, vertex_index, param_index, - name, index); + semantic); LLVMValueRef value[4]; for (unsigned i = 0; i < num_components; i++) { @@ -466,11 +467,11 @@ static LLVMValueRef si_nir_load_input_tes(struct ac_shader_abi *abi, LLVMTypeRef LLVMValueRef base, addr; driver_location = driver_location / 4; - ubyte name = info->input_semantic_name[driver_location]; - ubyte index = info->input_semantic_index[driver_location]; + ubyte semantic = info->input_semantic[driver_location]; - assert((name == TGSI_SEMANTIC_PATCH || name == TGSI_SEMANTIC_TESSINNER || - name == TGSI_SEMANTIC_TESSOUTER) == (vertex_index == NULL)); + assert((semantic >= VARYING_SLOT_PATCH0 || + semantic == VARYING_SLOT_TESS_LEVEL_INNER || + semantic == VARYING_SLOT_TESS_LEVEL_OUTER) == (vertex_index == NULL)); base = ac_get_arg(&ctx->ac, ctx->tcs_offchip_offset); @@ -479,7 +480,7 @@ static LLVMValueRef si_nir_load_input_tes(struct ac_shader_abi *abi, LLVMTypeRef } addr = - get_tcs_tes_buffer_address_from_generic_indices(ctx, vertex_index, param_index, name, index); + get_tcs_tes_buffer_address_from_generic_indices(ctx, vertex_index, param_index, semantic); /* TODO: This will generate rather ordinary llvm code, although it * should be easy for the optimiser to fix up. In future we might want @@ -491,10 +492,9 @@ static LLVMValueRef si_nir_load_input_tes(struct ac_shader_abi *abi, LLVMTypeRef if (ac_get_type_size(type) == 8) { offset *= 2; if (offset == 4) { - ubyte name = info->input_semantic_name[driver_location + 1]; - ubyte index = info->input_semantic_index[driver_location + 1]; + ubyte semantic = info->input_semantic[driver_location + 1]; addr = get_tcs_tes_buffer_address_from_generic_indices(ctx, vertex_index, param_index, - name, index); + semantic); } offset = offset % 4; @@ -521,8 +521,7 @@ static void si_nir_store_output_tcs(struct ac_shader_abi *abi, const struct nir_ bool is_tess_factor = false, is_tess_inner = false; driver_location = driver_location / 4; - ubyte name = info->output_semantic_name[driver_location]; - ubyte index = info->output_semantic_index[driver_location]; + ubyte semantic = info->output_semantic[driver_location]; bool is_const = !param_index; if (!param_index) @@ -531,27 +530,28 @@ static void si_nir_store_output_tcs(struct ac_shader_abi *abi, const struct nir_ const bool is_patch = vertex_index == NULL; /* Invalid SPIR-V can cause this. */ - if ((name == TGSI_SEMANTIC_PATCH || name == TGSI_SEMANTIC_TESSINNER || - name == TGSI_SEMANTIC_TESSOUTER) != is_patch) + if ((semantic >= VARYING_SLOT_PATCH0 || semantic == VARYING_SLOT_TESS_LEVEL_INNER || + semantic == VARYING_SLOT_TESS_LEVEL_OUTER) != is_patch) return; if (!is_patch) { stride = get_tcs_out_vertex_dw_stride(ctx); dw_addr = get_tcs_out_current_patch_offset(ctx); dw_addr = get_dw_address_from_generic_indices(ctx, stride, dw_addr, vertex_index, param_index, - name, index); + semantic); } else { dw_addr = get_tcs_out_current_patch_data_offset(ctx); dw_addr = get_dw_address_from_generic_indices(ctx, NULL, dw_addr, vertex_index, param_index, - name, index); + semantic); if (is_const && const_index == 0) { - int name = info->output_semantic_name[driver_location]; + int semantic = info->output_semantic[driver_location]; /* Always write tess factors into LDS for the TCS epilog. */ - if (name == TGSI_SEMANTIC_TESSINNER || name == TGSI_SEMANTIC_TESSOUTER) { + if (semantic == VARYING_SLOT_TESS_LEVEL_INNER || + semantic == VARYING_SLOT_TESS_LEVEL_OUTER) { is_tess_factor = true; - is_tess_inner = name == TGSI_SEMANTIC_TESSINNER; + is_tess_inner = semantic == VARYING_SLOT_TESS_LEVEL_INNER; } } } @@ -561,7 +561,7 @@ static void si_nir_store_output_tcs(struct ac_shader_abi *abi, const struct nir_ base = ac_get_arg(&ctx->ac, ctx->tcs_offchip_offset); addr = - get_tcs_tes_buffer_address_from_generic_indices(ctx, vertex_index, param_index, name, index); + get_tcs_tes_buffer_address_from_generic_indices(ctx, vertex_index, param_index, semantic); for (unsigned chan = component; chan < 8; chan++) { if (!(writemask & (1 << chan))) @@ -570,10 +570,9 @@ static void si_nir_store_output_tcs(struct ac_shader_abi *abi, const struct nir_ unsigned buffer_store_offset = chan % 4; if (chan == 4) { - ubyte name = info->output_semantic_name[driver_location + 1]; - ubyte index = info->output_semantic_index[driver_location + 1]; + ubyte semantic = info->output_semantic[driver_location + 1]; addr = get_tcs_tes_buffer_address_from_generic_indices(ctx, vertex_index, param_index, - name, index); + semantic); } /* Skip LDS stores if there is no LDS read of this output. */ @@ -623,11 +622,11 @@ static LLVMValueRef si_load_tess_coord(struct ac_shader_abi *abi) return ac_build_gather_values(&ctx->ac, coord, 4); } -static LLVMValueRef load_tess_level(struct si_shader_context *ctx, unsigned semantic_name) +static LLVMValueRef load_tess_level(struct si_shader_context *ctx, unsigned semantic) { LLVMValueRef base, addr; - int param = si_shader_io_get_unique_index_patch(semantic_name, 0); + int param = si_shader_io_get_unique_index_patch(semantic); base = ac_get_arg(&ctx->ac, ctx->tcs_offchip_offset); addr = get_tcs_tes_buffer_address(ctx, get_rel_patch_id(ctx), NULL, @@ -636,7 +635,7 @@ static LLVMValueRef load_tess_level(struct si_shader_context *ctx, unsigned sema return buffer_load(ctx, ctx->ac.f32, ~0, ctx->tess_offchip_ring, base, addr, true); } -static LLVMValueRef load_tess_level_default(struct si_shader_context *ctx, unsigned semantic_name) +static LLVMValueRef load_tess_level_default(struct si_shader_context *ctx, unsigned sysval) { LLVMValueRef buf, slot, val[4]; int i, offset; @@ -644,7 +643,7 @@ static LLVMValueRef load_tess_level_default(struct si_shader_context *ctx, unsig slot = LLVMConstInt(ctx->ac.i32, SI_HS_CONST_DEFAULT_TESS_LEVELS, 0); buf = ac_get_arg(&ctx->ac, ctx->rw_buffers); buf = ac_build_load_to_sgpr(&ctx->ac, buf, slot); - offset = semantic_name == TGSI_SEMANTIC_TESS_DEFAULT_INNER_LEVEL ? 4 : 0; + offset = sysval == SYSTEM_VALUE_TESS_LEVEL_INNER_DEFAULT ? 4 : 0; for (i = 0; i < 4; i++) val[i] = si_buffer_load_const(ctx, buf, LLVMConstInt(ctx->ac.i32, (offset + i) * 4, 0)); @@ -655,34 +654,34 @@ static LLVMValueRef si_load_tess_level(struct ac_shader_abi *abi, unsigned varyi bool load_default_state) { struct si_shader_context *ctx = si_shader_context_from_abi(abi); - unsigned semantic_name; + unsigned semantic; if (load_default_state) { switch (varying_id) { case VARYING_SLOT_TESS_LEVEL_INNER: - semantic_name = TGSI_SEMANTIC_TESS_DEFAULT_INNER_LEVEL; + semantic = SYSTEM_VALUE_TESS_LEVEL_INNER_DEFAULT; break; case VARYING_SLOT_TESS_LEVEL_OUTER: - semantic_name = TGSI_SEMANTIC_TESS_DEFAULT_OUTER_LEVEL; + semantic = SYSTEM_VALUE_TESS_LEVEL_OUTER_DEFAULT; break; default: unreachable("unknown tess level"); } - return load_tess_level_default(ctx, semantic_name); + return load_tess_level_default(ctx, semantic); } switch (varying_id) { case VARYING_SLOT_TESS_LEVEL_INNER: - semantic_name = TGSI_SEMANTIC_TESSINNER; + semantic = VARYING_SLOT_TESS_LEVEL_INNER; break; case VARYING_SLOT_TESS_LEVEL_OUTER: - semantic_name = TGSI_SEMANTIC_TESSOUTER; + semantic = VARYING_SLOT_TESS_LEVEL_OUTER; break; default: unreachable("unknown tess level"); } - return load_tess_level(ctx, semantic_name); + return load_tess_level(ctx, semantic); } static LLVMValueRef si_load_patch_vertices_in(struct ac_shader_abi *abi) @@ -693,7 +692,7 @@ static LLVMValueRef si_load_patch_vertices_in(struct ac_shader_abi *abi) else if (ctx->stage == MESA_SHADER_TESS_EVAL) return get_num_tcs_out_vertices(ctx); else - unreachable("invalid shader stage for TGSI_SEMANTIC_VERTICESIN"); + unreachable("invalid shader stage for VERTICESIN"); } /** @@ -792,8 +791,8 @@ static void si_write_tess_factors(struct si_shader_context *ctx, LLVMValueRef re /* Load tess_inner and tess_outer from LDS. * Any invocation can write them, so we can't get them from a temporary. */ - tess_inner_index = si_shader_io_get_unique_index_patch(TGSI_SEMANTIC_TESSINNER, 0); - tess_outer_index = si_shader_io_get_unique_index_patch(TGSI_SEMANTIC_TESSOUTER, 0); + tess_inner_index = si_shader_io_get_unique_index_patch(VARYING_SLOT_TESS_LEVEL_INNER); + tess_outer_index = si_shader_io_get_unique_index_patch(VARYING_SLOT_TESS_LEVEL_OUTER); lds_base = tcs_out_current_patch_data_offset; lds_inner = LLVMBuildAdd(ctx->ac.builder, lds_base, @@ -863,7 +862,7 @@ static void si_write_tess_factors(struct si_shader_context *ctx, LLVMValueRef re buf = get_tess_ring_descriptor(ctx, TESS_OFFCHIP_RING_TCS); base = ac_get_arg(&ctx->ac, ctx->tcs_offchip_offset); - param_outer = si_shader_io_get_unique_index_patch(TGSI_SEMANTIC_TESSOUTER, 0); + param_outer = si_shader_io_get_unique_index_patch(VARYING_SLOT_TESS_LEVEL_OUTER); tf_outer_offset = get_tcs_tes_buffer_address(ctx, rel_patch_id, NULL, LLVMConstInt(ctx->ac.i32, param_outer, 0)); @@ -875,7 +874,7 @@ static void si_write_tess_factors(struct si_shader_context *ctx, LLVMValueRef re ac_build_buffer_store_dword(&ctx->ac, buf, outer_vec, outer_comps, tf_outer_offset, base, 0, ac_glc); if (inner_comps) { - param_inner = si_shader_io_get_unique_index_patch(TGSI_SEMANTIC_TESSINNER, 0); + param_inner = si_shader_io_get_unique_index_patch(VARYING_SLOT_TESS_LEVEL_INNER); tf_inner_offset = get_tcs_tes_buffer_address(ctx, rel_patch_id, NULL, LLVMConstInt(ctx->ac.i32, param_inner, 0)); @@ -1015,8 +1014,7 @@ void si_llvm_emit_ls_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, L /* Write outputs to LDS. The next shader (TCS aka HS) will read * its inputs from it. */ for (i = 0; i < info->num_outputs; i++) { - unsigned name = info->output_semantic_name[i]; - unsigned index = info->output_semantic_index[i]; + unsigned semantic = info->output_semantic[i]; /* The ARB_shader_viewport_layer_array spec contains the * following issue: @@ -1033,10 +1031,10 @@ void si_llvm_emit_ls_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, L * * So writes to those outputs in VS-as-LS are simply ignored. */ - if (name == TGSI_SEMANTIC_LAYER || name == TGSI_SEMANTIC_VIEWPORT_INDEX) + if (semantic == VARYING_SLOT_LAYER || semantic == VARYING_SLOT_VIEWPORT) continue; - int param = si_shader_io_get_unique_index(name, index, false); + int param = si_shader_io_get_unique_index(semantic, false); LLVMValueRef dw_addr = LLVMBuildAdd(ctx->ac.builder, base_dw_addr, LLVMConstInt(ctx->ac.i32, param * 4, 0), ""); diff --git a/src/gallium/drivers/radeonsi/si_shader_llvm_vs.c b/src/gallium/drivers/radeonsi/si_shader_llvm_vs.c index 76ea7e76c36..83bea6cf499 100644 --- a/src/gallium/drivers/radeonsi/si_shader_llvm_vs.c +++ b/src/gallium/drivers/radeonsi/si_shader_llvm_vs.c @@ -425,31 +425,35 @@ static void si_build_param_exports(struct si_shader_context *ctx, unsigned param_count = 0; for (unsigned i = 0; i < noutput; i++) { - unsigned semantic_name = outputs[i].semantic_name; - unsigned semantic_index = outputs[i].semantic_index; + unsigned semantic = outputs[i].semantic; if (outputs[i].vertex_stream[0] != 0 && outputs[i].vertex_stream[1] != 0 && outputs[i].vertex_stream[2] != 0 && outputs[i].vertex_stream[3] != 0) continue; - switch (semantic_name) { - case TGSI_SEMANTIC_LAYER: - case TGSI_SEMANTIC_VIEWPORT_INDEX: - case TGSI_SEMANTIC_CLIPDIST: - case TGSI_SEMANTIC_COLOR: - case TGSI_SEMANTIC_BCOLOR: - case TGSI_SEMANTIC_PRIMID: - case TGSI_SEMANTIC_FOG: - case TGSI_SEMANTIC_TEXCOORD: - case TGSI_SEMANTIC_GENERIC: + switch (semantic) { + case VARYING_SLOT_LAYER: + case VARYING_SLOT_VIEWPORT: + case VARYING_SLOT_CLIP_DIST0: + case VARYING_SLOT_CLIP_DIST1: + case VARYING_SLOT_COL0: + case VARYING_SLOT_COL1: + case VARYING_SLOT_BFC0: + case VARYING_SLOT_BFC1: + case VARYING_SLOT_PRIMITIVE_ID: + case VARYING_SLOT_FOGC: break; default: - continue; + if ((semantic >= VARYING_SLOT_TEX0 && semantic <= VARYING_SLOT_TEX7) || + semantic >= VARYING_SLOT_VAR0) + break; + else + continue; } - if ((semantic_name != TGSI_SEMANTIC_GENERIC || semantic_index < SI_MAX_IO_GENERIC) && + if (semantic < VARYING_SLOT_VAR0 + SI_MAX_IO_GENERIC && shader->key.opt.kill_outputs & - (1ull << si_shader_io_get_unique_index(semantic_name, semantic_index, true))) + (1ull << si_shader_io_get_unique_index(semantic, true))) continue; si_export_param(ctx, param_count, outputs[i].values); @@ -476,8 +480,10 @@ static void si_vertex_color_clamping(struct si_shader_context *ctx, /* Store original colors to alloca variables. */ for (unsigned i = 0; i < noutput; i++) { - if (outputs[i].semantic_name != TGSI_SEMANTIC_COLOR && - outputs[i].semantic_name != TGSI_SEMANTIC_BCOLOR) + if (outputs[i].semantic != VARYING_SLOT_COL0 && + outputs[i].semantic != VARYING_SLOT_COL1 && + outputs[i].semantic != VARYING_SLOT_BFC0 && + outputs[i].semantic != VARYING_SLOT_BFC1) continue; for (unsigned j = 0; j < 4; j++) { @@ -498,8 +504,10 @@ static void si_vertex_color_clamping(struct si_shader_context *ctx, /* Store clamped colors to alloca variables within the conditional block. */ for (unsigned i = 0; i < noutput; i++) { - if (outputs[i].semantic_name != TGSI_SEMANTIC_COLOR && - outputs[i].semantic_name != TGSI_SEMANTIC_BCOLOR) + if (outputs[i].semantic != VARYING_SLOT_COL0 && + outputs[i].semantic != VARYING_SLOT_COL1 && + outputs[i].semantic != VARYING_SLOT_BFC0 && + outputs[i].semantic != VARYING_SLOT_BFC1) continue; for (unsigned j = 0; j < 4; j++) { @@ -511,8 +519,10 @@ static void si_vertex_color_clamping(struct si_shader_context *ctx, /* Load clamped colors */ for (unsigned i = 0; i < noutput; i++) { - if (outputs[i].semantic_name != TGSI_SEMANTIC_COLOR && - outputs[i].semantic_name != TGSI_SEMANTIC_BCOLOR) + if (outputs[i].semantic != VARYING_SLOT_COL0 && + outputs[i].semantic != VARYING_SLOT_COL1 && + outputs[i].semantic != VARYING_SLOT_BFC0 && + outputs[i].semantic != VARYING_SLOT_BFC1) continue; for (unsigned j = 0; j < 4; j++) { @@ -538,30 +548,31 @@ void si_llvm_build_vs_exports(struct si_shader_context *ctx, /* Build position exports. */ for (i = 0; i < noutput; i++) { - switch (outputs[i].semantic_name) { - case TGSI_SEMANTIC_POSITION: + switch (outputs[i].semantic) { + case VARYING_SLOT_POS: si_llvm_init_vs_export_args(ctx, outputs[i].values, V_008DFC_SQ_EXP_POS, &pos_args[0]); break; - case TGSI_SEMANTIC_PSIZE: + case VARYING_SLOT_PSIZ: psize_value = outputs[i].values[0]; break; - case TGSI_SEMANTIC_LAYER: + case VARYING_SLOT_LAYER: layer_value = outputs[i].values[0]; break; - case TGSI_SEMANTIC_VIEWPORT_INDEX: + case VARYING_SLOT_VIEWPORT: viewport_index_value = outputs[i].values[0]; break; - case TGSI_SEMANTIC_EDGEFLAG: + case VARYING_SLOT_EDGE: edgeflag_value = outputs[i].values[0]; break; - case TGSI_SEMANTIC_CLIPDIST: + case VARYING_SLOT_CLIP_DIST0: + case VARYING_SLOT_CLIP_DIST1: if (!shader->key.opt.clip_disable) { - unsigned index = 2 + outputs[i].semantic_index; + unsigned index = 2 + (outputs[i].semantic - VARYING_SLOT_CLIP_DIST0); si_llvm_init_vs_export_args(ctx, outputs[i].values, V_008DFC_SQ_EXP_POS + index, &pos_args[index]); } break; - case TGSI_SEMANTIC_CLIPVERTEX: + case VARYING_SLOT_CLIP_VERTEX: if (!shader->key.opt.clip_disable) { si_llvm_emit_clipvertex(ctx, pos_args, outputs[i].values); } @@ -682,8 +693,7 @@ void si_llvm_emit_vs_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, L outputs = MALLOC((info->num_outputs + 1) * sizeof(outputs[0])); for (i = 0; i < info->num_outputs; i++) { - outputs[i].semantic_name = info->output_semantic_name[i]; - outputs[i].semantic_index = info->output_semantic_index[i]; + outputs[i].semantic = info->output_semantic[i]; for (j = 0; j < 4; j++) { outputs[i].values[j] = LLVMBuildLoad(ctx->ac.builder, addrs[4 * i + j], ""); @@ -696,8 +706,7 @@ void si_llvm_emit_vs_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, L /* Export PrimitiveID. */ if (ctx->shader->key.mono.u.vs_export_prim_id) { - outputs[i].semantic_name = TGSI_SEMANTIC_PRIMID; - outputs[i].semantic_index = 0; + outputs[i].semantic = VARYING_SLOT_PRIMITIVE_ID; outputs[i].values[0] = ac_to_float(&ctx->ac, si_get_primitive_id(ctx, 0)); for (j = 1; j < 4; j++) outputs[i].values[j] = LLVMConstReal(ctx->ac.f32, 0); @@ -720,7 +729,7 @@ static void si_llvm_emit_prim_discard_cs_epilogue(struct ac_shader_abi *abi, uns assert(info->num_outputs <= max_outputs); for (unsigned i = 0; i < info->num_outputs; i++) { - if (info->output_semantic_name[i] != TGSI_SEMANTIC_POSITION) + if (info->output_semantic[i] != VARYING_SLOT_POS) continue; for (unsigned chan = 0; chan < 4; chan++) diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c index 5b47753d3cc..1cf3f591248 100644 --- a/src/gallium/drivers/radeonsi/si_shader_nir.c +++ b/src/gallium/drivers/radeonsi/si_shader_nir.c @@ -100,27 +100,25 @@ static void scan_io_usage(struct si_shader_info *info, nir_intrinsic_instr *intr mask <<= nir_intrinsic_component(intr); - unsigned name, index; - if (info->stage == MESA_SHADER_VERTEX && is_input) { - /* VS doesn't have semantics. */ - name = 0; - index = 0; - } else if (info->stage == MESA_SHADER_FRAGMENT && !is_input) { - tgsi_get_gl_frag_result_semantic(nir_intrinsic_io_semantics(intr).location, - &name, &index); - /* Adjust for dual source blending. */ - if (nir_intrinsic_io_semantics(intr).dual_source_blend_index) - index++; - } else { - tgsi_get_gl_varying_semantic(nir_intrinsic_io_semantics(intr).location, - true, &name, &index); - } - nir_src offset = *nir_get_io_offset_src(intr); bool indirect = !nir_src_is_const(offset); if (!indirect) assert(nir_src_as_uint(offset) == 0); + unsigned semantic = 0; + /* VS doesn't have semantics. */ + if (info->stage != MESA_SHADER_VERTEX || !is_input) + semantic = nir_intrinsic_io_semantics(intr).location; + + if (info->stage == MESA_SHADER_FRAGMENT && !is_input) { + /* Never use FRAG_RESULT_COLOR directly. */ + if (semantic == FRAG_RESULT_COLOR) { + semantic = FRAG_RESULT_DATA0; + info->properties[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS] = true; + } + semantic += nir_intrinsic_io_semantics(intr).dual_source_blend_index; + } + unsigned driver_location = nir_intrinsic_base(intr); unsigned num_slots = indirect ? nir_intrinsic_io_semantics(intr).num_slots : (1 + dual_slot); @@ -131,15 +129,14 @@ static void scan_io_usage(struct si_shader_info *info, nir_intrinsic_instr *intr unsigned loc = driver_location + i; unsigned slot_mask = (dual_slot && i % 2 ? mask >> 4 : mask) & 0xf; - info->input_semantic_name[loc] = name; - info->input_semantic_index[loc] = index + i; + info->input_semantic[loc] = semantic + i; info->input_interpolate[loc] = interp; if (slot_mask) { info->input_usage_mask[loc] |= slot_mask; info->num_inputs = MAX2(info->num_inputs, loc + 1); - if (name == TGSI_SEMANTIC_PRIMID) + if (semantic == VARYING_SLOT_PRIMITIVE_ID) info->uses_primid = true; } } @@ -151,8 +148,7 @@ static void scan_io_usage(struct si_shader_info *info, nir_intrinsic_instr *intr unsigned loc = driver_location + i; unsigned slot_mask = (dual_slot && i % 2 ? mask >> 4 : mask) & 0xf; - info->output_semantic_name[loc] = name; - info->output_semantic_index[loc] = index + i; + info->output_semantic[loc] = semantic + i; if (is_output_load) { /* Output loads have only a few things that we need to track. */ @@ -181,44 +177,48 @@ static void scan_io_usage(struct si_shader_info *info, nir_intrinsic_instr *intr info->output_usagemask[loc] |= slot_mask; info->num_outputs = MAX2(info->num_outputs, loc + 1); - switch (name) { - case TGSI_SEMANTIC_PRIMID: - info->writes_primid = true; - break; - case TGSI_SEMANTIC_VIEWPORT_INDEX: - info->writes_viewport_index = true; - break; - case TGSI_SEMANTIC_LAYER: - info->writes_layer = true; - break; - case TGSI_SEMANTIC_PSIZE: - info->writes_psize = true; - break; - case TGSI_SEMANTIC_CLIPVERTEX: - info->writes_clipvertex = true; - break; - case TGSI_SEMANTIC_COLOR: - info->colors_written |= 1 << (index + i); - - if (info->stage == MESA_SHADER_FRAGMENT && - nir_intrinsic_io_semantics(intr).location == FRAG_RESULT_COLOR) - info->properties[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS] = true; - break; - case TGSI_SEMANTIC_STENCIL: - info->writes_stencil = true; - break; - case TGSI_SEMANTIC_SAMPLEMASK: - info->writes_samplemask = true; - break; - case TGSI_SEMANTIC_EDGEFLAG: - info->writes_edgeflag = true; - break; - case TGSI_SEMANTIC_POSITION: - if (info->stage == MESA_SHADER_FRAGMENT) + if (info->stage == MESA_SHADER_FRAGMENT) { + switch (semantic) { + case FRAG_RESULT_DEPTH: info->writes_z = true; - else + break; + case FRAG_RESULT_STENCIL: + info->writes_stencil = true; + break; + case FRAG_RESULT_SAMPLE_MASK: + info->writes_samplemask = true; + break; + default: + if (semantic >= FRAG_RESULT_DATA0 && semantic <= FRAG_RESULT_DATA7) { + unsigned index = semantic - FRAG_RESULT_DATA0; + info->colors_written |= 1 << (index + i); + } + break; + } + } else { + switch (semantic) { + case VARYING_SLOT_PRIMITIVE_ID: + info->writes_primid = true; + break; + case VARYING_SLOT_VIEWPORT: + info->writes_viewport_index = true; + break; + case VARYING_SLOT_LAYER: + info->writes_layer = true; + break; + case VARYING_SLOT_PSIZ: + info->writes_psize = true; + break; + case VARYING_SLOT_CLIP_VERTEX: + info->writes_clipvertex = true; + break; + case VARYING_SLOT_EDGE: + info->writes_edgeflag = true; + break; + case VARYING_SLOT_POS: info->writes_position = true; - break; + break; + } } } } @@ -566,8 +566,7 @@ void si_nir_scan_shader(const struct nir_shader *nir, struct si_shader_info *inf if (nir->info.stage == MESA_SHADER_FRAGMENT) { for (unsigned i = 0; i < 2; i++) { if ((info->colors_read >> (i * 4)) & 0xf) { - info->input_semantic_name[info->num_inputs] = TGSI_SEMANTIC_COLOR; - info->input_semantic_index[info->num_inputs] = i; + info->input_semantic[info->num_inputs] = VARYING_SLOT_COL0 + i; info->input_interpolate[info->num_inputs] = info->color_interpolate[i]; info->input_usage_mask[info->num_inputs] = info->colors_read >> (i * 4); info->num_inputs++; diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c index b7189e1435d..3e72e1fc37c 100644 --- a/src/gallium/drivers/radeonsi/si_state_shaders.c +++ b/src/gallium/drivers/radeonsi/si_state_shaders.c @@ -1769,9 +1769,9 @@ static void si_shader_selector_key_hw_vs(struct si_context *sctx, struct si_shad uint64_t inputs_read = 0; /* Ignore outputs that are not passed from VS to PS. */ - outputs_written &= ~((1ull << si_shader_io_get_unique_index(TGSI_SEMANTIC_POSITION, 0, true)) | - (1ull << si_shader_io_get_unique_index(TGSI_SEMANTIC_PSIZE, 0, true)) | - (1ull << si_shader_io_get_unique_index(TGSI_SEMANTIC_CLIPVERTEX, 0, true))); + outputs_written &= ~((1ull << si_shader_io_get_unique_index(VARYING_SLOT_POS, true)) | + (1ull << si_shader_io_get_unique_index(VARYING_SLOT_PSIZ, true)) | + (1ull << si_shader_io_get_unique_index(VARYING_SLOT_CLIP_VERTEX, true))); if (!ps_disabled) { inputs_read = ps->inputs_read; @@ -2472,25 +2472,16 @@ static void si_init_shader_selector_async(void *job, int thread_index) if (offset <= AC_EXP_PARAM_OFFSET_31) continue; - unsigned name = sel->info.output_semantic_name[i]; - unsigned index = sel->info.output_semantic_index[i]; + unsigned semantic = sel->info.output_semantic[i]; unsigned id; - switch (name) { - case TGSI_SEMANTIC_GENERIC: - /* don't process indices the function can't handle */ - if (index >= SI_MAX_IO_GENERIC) - break; - /* fall through */ - default: - id = si_shader_io_get_unique_index(name, index, true); + if (semantic < VARYING_SLOT_MAX && + semantic != VARYING_SLOT_POS && + semantic != VARYING_SLOT_PSIZ && + semantic != VARYING_SLOT_CLIP_VERTEX && + semantic != VARYING_SLOT_EDGE) { + id = si_shader_io_get_unique_index(semantic, true); sel->outputs_written_before_ps &= ~(1ull << id); - break; - case TGSI_SEMANTIC_POSITION: /* ignore these */ - case TGSI_SEMANTIC_PSIZE: - case TGSI_SEMANTIC_CLIPVERTEX: - case TGSI_SEMANTIC_EDGEFLAG: - break; } } } @@ -2670,34 +2661,23 @@ static void *si_create_shader_selector(struct pipe_context *ctx, case MESA_SHADER_TESS_CTRL: /* Always reserve space for these. */ sel->patch_outputs_written |= - (1ull << si_shader_io_get_unique_index_patch(TGSI_SEMANTIC_TESSINNER, 0)) | - (1ull << si_shader_io_get_unique_index_patch(TGSI_SEMANTIC_TESSOUTER, 0)); + (1ull << si_shader_io_get_unique_index_patch(VARYING_SLOT_TESS_LEVEL_INNER)) | + (1ull << si_shader_io_get_unique_index_patch(VARYING_SLOT_TESS_LEVEL_OUTER)); /* fall through */ case MESA_SHADER_VERTEX: case MESA_SHADER_TESS_EVAL: for (i = 0; i < sel->info.num_outputs; i++) { - unsigned name = sel->info.output_semantic_name[i]; - unsigned index = sel->info.output_semantic_index[i]; - - switch (name) { - case TGSI_SEMANTIC_TESSINNER: - case TGSI_SEMANTIC_TESSOUTER: - case TGSI_SEMANTIC_PATCH: - sel->patch_outputs_written |= 1ull << si_shader_io_get_unique_index_patch(name, index); - break; - - case TGSI_SEMANTIC_GENERIC: - /* don't process indices the function can't handle */ - if (index >= SI_MAX_IO_GENERIC) - break; - /* fall through */ - default: - sel->outputs_written |= 1ull << si_shader_io_get_unique_index(name, index, false); + unsigned semantic = sel->info.output_semantic[i]; + + if (semantic == VARYING_SLOT_TESS_LEVEL_INNER || + semantic == VARYING_SLOT_TESS_LEVEL_OUTER || + (semantic >= VARYING_SLOT_PATCH0 && semantic < VARYING_SLOT_TESS_MAX)) { + sel->patch_outputs_written |= 1ull << si_shader_io_get_unique_index_patch(semantic); + } else if (semantic < VARYING_SLOT_MAX && + semantic != VARYING_SLOT_EDGE) { + sel->outputs_written |= 1ull << si_shader_io_get_unique_index(semantic, false); sel->outputs_written_before_ps |= 1ull - << si_shader_io_get_unique_index(name, index, true); - break; - case TGSI_SEMANTIC_EDGEFLAG: - break; + << si_shader_io_get_unique_index(semantic, true); } } sel->esgs_itemsize = util_last_bit64(sel->outputs_written) * 16; @@ -2728,20 +2708,11 @@ static void *si_create_shader_selector(struct pipe_context *ctx, case MESA_SHADER_FRAGMENT: for (i = 0; i < sel->info.num_inputs; i++) { - unsigned name = sel->info.input_semantic_name[i]; - unsigned index = sel->info.input_semantic_index[i]; - - switch (name) { - case TGSI_SEMANTIC_GENERIC: - /* don't process indices the function can't handle */ - if (index >= SI_MAX_IO_GENERIC) - break; - /* fall through */ - default: - sel->inputs_read |= 1ull << si_shader_io_get_unique_index(name, index, true); - break; - case TGSI_SEMANTIC_PCOORD: /* ignore this */ - break; + unsigned semantic = sel->info.input_semantic[i]; + + if (semantic < VARYING_SLOT_MAX && + semantic != VARYING_SLOT_PNTC) { + sel->inputs_read |= 1ull << si_shader_io_get_unique_index(semantic, true); } } @@ -2750,10 +2721,10 @@ static void *si_create_shader_selector(struct pipe_context *ctx, sel->colors_written_4bit |= 0xf << (4 * i); for (i = 0; i < sel->info.num_inputs; i++) { - if (sel->info.input_semantic_name[i] == TGSI_SEMANTIC_COLOR) { - int index = sel->info.input_semantic_index[i]; - sel->color_attr_index[index] = i; - } + if (sel->info.input_semantic[i] == VARYING_SLOT_COL0) + sel->color_attr_index[0] = i; + else if (sel->info.input_semantic[i] == VARYING_SLOT_COL1) + sel->color_attr_index[1] = i; } break; default:; @@ -3196,23 +3167,26 @@ static void si_delete_shader_selector(struct pipe_context *ctx, void *state) si_shader_selector_reference(sctx, &sel, NULL); } -static unsigned si_get_ps_input_cntl(struct si_context *sctx, struct si_shader *vs, unsigned name, - unsigned index, enum glsl_interp_mode interpolate) +static unsigned si_get_ps_input_cntl(struct si_context *sctx, struct si_shader *vs, + unsigned semantic, enum glsl_interp_mode interpolate) { struct si_shader_info *vsinfo = &vs->selector->info; unsigned j, offset, ps_input_cntl = 0; if (interpolate == INTERP_MODE_FLAT || - (interpolate == INTERP_MODE_COLOR && sctx->flatshade) || name == TGSI_SEMANTIC_PRIMID) + (interpolate == INTERP_MODE_COLOR && sctx->flatshade) || + semantic == VARYING_SLOT_PRIMITIVE_ID) ps_input_cntl |= S_028644_FLAT_SHADE(1); - if (name == TGSI_SEMANTIC_PCOORD || - (name == TGSI_SEMANTIC_TEXCOORD && sctx->sprite_coord_enable & (1 << index))) { + if (semantic == VARYING_SLOT_PNTC || + (semantic >= VARYING_SLOT_TEX0 && semantic <= VARYING_SLOT_TEX7 && + sctx->sprite_coord_enable & (1 << (semantic - VARYING_SLOT_TEX0)))) { ps_input_cntl |= S_028644_PT_SPRITE_TEX(1); } + /* TODO: This search can be removed if we add a lookup table from semantic to index. */ for (j = 0; j < vsinfo->num_outputs; j++) { - if (name == vsinfo->output_semantic_name[j] && index == vsinfo->output_semantic_index[j]) { + if (semantic == vsinfo->output_semantic[j]) { offset = vs->info.vs_output_param_offset[j]; if (offset <= AC_EXP_PARAM_OFFSET_31) { @@ -3235,7 +3209,7 @@ static unsigned si_get_ps_input_cntl(struct si_context *sctx, struct si_shader * } } - if (j == vsinfo->num_outputs && name == TGSI_SEMANTIC_PRIMID) + if (j == vsinfo->num_outputs && semantic == VARYING_SLOT_PRIMITIVE_ID) /* PrimID is written after the last output when HW VS is used. */ ps_input_cntl |= S_028644_OFFSET(vs->info.vs_output_param_offset[vsinfo->num_outputs]); else if (j == vsinfo->num_outputs && !G_028644_PT_SPRITE_TEX(ps_input_cntl)) { @@ -3244,7 +3218,7 @@ static unsigned si_get_ps_input_cntl(struct si_context *sctx, struct si_shader * * (FLAT_SHADE=1 completely changes behavior) */ ps_input_cntl = S_028644_OFFSET(0x20); /* D3D 9 behaviour. GL is undefined */ - if (name == TGSI_SEMANTIC_COLOR && index == 0) + if (semantic == VARYING_SLOT_COL0) ps_input_cntl |= S_028644_DEFAULT_VAL(3); } return ps_input_cntl; @@ -3265,21 +3239,19 @@ static void si_emit_spi_map(struct si_context *sctx) assert(num_interp > 0); for (i = 0; i < psinfo->num_inputs; i++) { - unsigned name = psinfo->input_semantic_name[i]; - unsigned index = psinfo->input_semantic_index[i]; + unsigned semantic = psinfo->input_semantic[i]; unsigned interpolate = psinfo->input_interpolate[i]; - spi_ps_input_cntl[num_written++] = si_get_ps_input_cntl(sctx, vs, name, index, interpolate); + spi_ps_input_cntl[num_written++] = si_get_ps_input_cntl(sctx, vs, semantic, interpolate); } if (ps->key.part.ps.prolog.color_two_side) { - unsigned bcol = TGSI_SEMANTIC_BCOLOR; - for (i = 0; i < 2; i++) { if (!(psinfo->colors_read & (0xf << (i * 4)))) continue; - spi_ps_input_cntl[num_written++] = si_get_ps_input_cntl(sctx, vs, bcol, i, + unsigned semantic = VARYING_SLOT_BFC0 + i; + spi_ps_input_cntl[num_written++] = si_get_ps_input_cntl(sctx, vs, semantic, psinfo->color_interpolate[i]); } }