llvmpipe/fs: switch to using tgsi->nir instead of handling tgsi

This just swaps, lots of cleanup after this.

Reviewed-by: Brian Paul <brianp@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24817>
This commit is contained in:
Dave Airlie 2023-08-02 14:42:44 +10:00 committed by Marge Bot
parent 17f7ffcb36
commit d2c4b8b32a
3 changed files with 20 additions and 62 deletions

View file

@ -103,12 +103,8 @@ lp_fs_linear_run(const struct lp_rast_state *state,
/* XXX: Per statechange: /* XXX: Per statechange:
*/ */
int nr_consts; // in floats, not float[4] int nr_consts = state->jit_resources.constants[0].num_elements;
if (variant->shader->base.type == PIPE_SHADER_IR_TGSI) {
nr_consts = (info->base.file_max[TGSI_FILE_CONSTANT] + 1) * 4;
} else {
nr_consts = state->jit_resources.constants[0].num_elements;
}
for (int i = 0; i < nr_consts; i++){ for (int i = 0; i < nr_consts; i++){
float val = state->jit_resources.constants[0].f[i]; float val = state->jit_resources.constants[0].f[i];
if (val < 0.0f || val > 1.0f) { if (val < 0.0f || val > 1.0f) {

View file

@ -70,9 +70,7 @@
#include "util/os_time.h" #include "util/os_time.h"
#include "pipe/p_shader_tokens.h" #include "pipe/p_shader_tokens.h"
#include "draw/draw_context.h" #include "draw/draw_context.h"
#include "tgsi/tgsi_dump.h" #include "nir/tgsi_to_nir.h"
#include "tgsi/tgsi_scan.h"
#include "tgsi/tgsi_parse.h"
#include "gallivm/lp_bld_type.h" #include "gallivm/lp_bld_type.h"
#include "gallivm/lp_bld_const.h" #include "gallivm/lp_bld_const.h"
#include "gallivm/lp_bld_conv.h" #include "gallivm/lp_bld_conv.h"
@ -659,7 +657,6 @@ generate_fs_loop(struct gallivm_state *gallivm,
LLVMTypeRef thread_data_type, LLVMTypeRef thread_data_type,
LLVMValueRef thread_data_ptr) LLVMValueRef thread_data_ptr)
{ {
const struct tgsi_token *tokens = shader->base.tokens;
struct lp_type int_type = lp_int_type(type); struct lp_type int_type = lp_int_type(type);
LLVMValueRef mask_ptr = NULL, mask_val = NULL; LLVMValueRef mask_ptr = NULL, mask_val = NULL;
LLVMValueRef z; LLVMValueRef z;
@ -669,6 +666,7 @@ generate_fs_loop(struct gallivm_state *gallivm,
LLVMValueRef z_out = NULL, s_out = NULL; LLVMValueRef z_out = NULL, s_out = NULL;
struct lp_build_for_loop_state loop_state, sample_loop_state = {0}; struct lp_build_for_loop_state loop_state, sample_loop_state = {0};
struct lp_build_mask_context mask; struct lp_build_mask_context mask;
struct nir_shader *nir = shader->base.ir.nir;
/* /*
* TODO: figure out if simple_shader optimization is really worthwile to * TODO: figure out if simple_shader optimization is really worthwile to
* keep. Disabled because it may hide some real bugs in the (depth/stencil) * keep. Disabled because it may hide some real bugs in the (depth/stencil)
@ -1068,12 +1066,7 @@ generate_fs_loop(struct gallivm_state *gallivm,
params.aniso_filter_table = lp_jit_resources_aniso_filter_table(gallivm, resources_type, resources_ptr); params.aniso_filter_table = lp_jit_resources_aniso_filter_table(gallivm, resources_type, resources_ptr);
/* Build the actual shader */ /* Build the actual shader */
if (shader->base.type == PIPE_SHADER_IR_TGSI) lp_build_nir_soa(gallivm, nir, &params, outputs);
lp_build_tgsi_soa(gallivm, tokens, &params,
outputs);
else
lp_build_nir_soa(gallivm, shader->base.ir.nir, &params,
outputs);
/* Alpha test */ /* Alpha test */
if (key->alpha.enabled) { if (key->alpha.enabled) {
@ -3687,10 +3680,7 @@ lp_debug_fs_variant(struct lp_fragment_shader_variant *variant)
{ {
debug_printf("llvmpipe: Fragment shader #%u variant #%u:\n", debug_printf("llvmpipe: Fragment shader #%u variant #%u:\n",
variant->shader->no, variant->no); variant->shader->no, variant->no);
if (variant->shader->base.type == PIPE_SHADER_IR_TGSI) nir_print_shader(variant->shader->base.ir.nir, stderr);
tgsi_dump(variant->shader->base.tokens, 0);
else
nir_print_shader(variant->shader->base.ir.nir, stderr);
dump_fs_variant_key(&variant->key); dump_fs_variant_key(&variant->key);
debug_printf("variant->opaque = %u\n", variant->opaque); debug_printf("variant->opaque = %u\n", variant->opaque);
debug_printf("variant->potentially_opaque = %u\n", variant->potentially_opaque); debug_printf("variant->potentially_opaque = %u\n", variant->potentially_opaque);
@ -3967,8 +3957,6 @@ static void *
llvmpipe_create_fs_state(struct pipe_context *pipe, llvmpipe_create_fs_state(struct pipe_context *pipe,
const struct pipe_shader_state *templ) const struct pipe_shader_state *templ)
{ {
llvmpipe_register_shader(pipe, templ, false);
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
struct lp_fragment_shader *shader = CALLOC_STRUCT(lp_fragment_shader); struct lp_fragment_shader *shader = CALLOC_STRUCT(lp_fragment_shader);
@ -3979,27 +3967,25 @@ llvmpipe_create_fs_state(struct pipe_context *pipe,
shader->no = fs_no++; shader->no = fs_no++;
list_inithead(&shader->variants.list); list_inithead(&shader->variants.list);
shader->base.type = templ->type; shader->base.type = PIPE_SHADER_IR_NIR;
if (templ->type == PIPE_SHADER_IR_TGSI) {
/* get/save the summary info for this shader */
lp_build_tgsi_info(templ->tokens, &shader->info);
/* we need to keep a local copy of the tokens */ if (templ->type == PIPE_SHADER_IR_TGSI) {
shader->base.tokens = tgsi_dup_tokens(templ->tokens); shader->base.ir.nir = tgsi_to_nir(templ->tokens, pipe->screen, false);
} else { } else {
shader->base.ir.nir = templ->ir.nir; shader->base.ir.nir = templ->ir.nir;
/* lower FRAG_RESULT_COLOR -> DATA[0-7] to correctly handle unused attachments */
nir_shader *nir = shader->base.ir.nir;
NIR_PASS_V(nir, nir_lower_fragcolor, nir->info.fs.color_is_dual_source ? 1 : 8);
nir_tgsi_scan_shader(nir, &shader->info.base, true);
shader->info.num_texs = shader->info.base.opcode_count[TGSI_OPCODE_TEX];
} }
/* lower FRAG_RESULT_COLOR -> DATA[0-7] to correctly handle unused attachments */
nir_shader *nir = shader->base.ir.nir;
NIR_PASS_V(nir, nir_lower_fragcolor, nir->info.fs.color_is_dual_source ? 1 : 8);
nir_tgsi_scan_shader(nir, &shader->info.base, true);
shader->info.num_texs = shader->info.base.opcode_count[TGSI_OPCODE_TEX];
llvmpipe_register_shader(pipe, &shader->base, false);
shader->draw_data = draw_create_fragment_shader(llvmpipe->draw, templ); shader->draw_data = draw_create_fragment_shader(llvmpipe->draw, templ);
if (shader->draw_data == NULL) { if (shader->draw_data == NULL) {
FREE((void *) shader->base.tokens);
FREE(shader); FREE(shader);
return NULL; return NULL;
} }
@ -4051,28 +4037,7 @@ llvmpipe_create_fs_state(struct pipe_context *pipe,
shader->inputs[i].src_index = i+1; shader->inputs[i].src_index = i+1;
} }
if (LP_DEBUG & DEBUG_TGSI && templ->type == PIPE_SHADER_IR_TGSI) { llvmpipe_fs_analyse_nir(shader);
debug_printf("llvmpipe: Create fragment shader #%u %p:\n",
shader->no, (void *) shader);
tgsi_dump(templ->tokens, 0);
debug_printf("usage masks:\n");
for (unsigned attrib = 0; attrib < shader->info.base.num_inputs; ++attrib) {
unsigned usage_mask = shader->info.base.input_usage_mask[attrib];
debug_printf(" IN[%u].%s%s%s%s\n",
attrib,
usage_mask & TGSI_WRITEMASK_X ? "x" : "",
usage_mask & TGSI_WRITEMASK_Y ? "y" : "",
usage_mask & TGSI_WRITEMASK_Z ? "z" : "",
usage_mask & TGSI_WRITEMASK_W ? "w" : "");
}
debug_printf("\n");
}
/* This will put a derived copy of the tokens into shader->base.tokens */
if (templ->type == PIPE_SHADER_IR_TGSI)
llvmpipe_fs_analyse(shader, templ->tokens);
else
llvmpipe_fs_analyse_nir(shader);
return shader; return shader;
} }
@ -4144,10 +4109,8 @@ llvmpipe_destroy_fs(struct llvmpipe_context *llvmpipe,
llvmpipe_register_shader(&llvmpipe->pipe, &shader->base, true); llvmpipe_register_shader(&llvmpipe->pipe, &shader->base, true);
if (shader->base.ir.nir) ralloc_free(shader->base.ir.nir);
ralloc_free(shader->base.ir.nir);
assert(shader->variants_cached == 0); assert(shader->variants_cached == 0);
FREE((void *) shader->base.tokens);
FREE(shader); FREE(shader);
} }

View file

@ -40,7 +40,6 @@
#include "util/u_inlines.h" #include "util/u_inlines.h"
#include "lp_jit.h" #include "lp_jit.h"
struct tgsi_token;
struct lp_fragment_shader; struct lp_fragment_shader;