diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 76518146813..b644a9d5f8a 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -3140,14 +3140,13 @@ generate_fragment(struct llvmpipe_context *lp, /* Adjust color input interpolation according to flatshade state: */ - memcpy(inputs, shader->inputs, - shader->info.base.num_inputs * sizeof inputs[0]); - for (unsigned i = 0; i < shader->info.base.num_inputs; i++) { - if (inputs[i].interp == LP_INTERP_COLOR) { - if (key->flatshade) - inputs[i].interp = LP_INTERP_CONSTANT; - else - inputs[i].interp = LP_INTERP_PERSPECTIVE; + nir_foreach_shader_in_variable(var, nir) { + unsigned idx = var->data.driver_location; + unsigned slots = nir_variable_count_slots(var, var->type); + memcpy(&inputs[idx], &shader->inputs[idx], (sizeof inputs[0] * slots)); + for (unsigned s = 0; s < slots; s++) { + if (inputs[idx + s].interp == LP_INTERP_COLOR) + inputs[idx + s].interp = key->flatshade ? LP_INTERP_CONSTANT : LP_INTERP_PERSPECTIVE; } } @@ -3339,7 +3338,7 @@ generate_fragment(struct llvmpipe_context *lp, */ lp_build_interp_soa_init(&interp, gallivm, - shader->info.base.num_inputs, + nir->num_inputs, inputs, pixel_center_integer, key->coverage_samples, @@ -4001,42 +4000,55 @@ llvmpipe_create_fs_state(struct pipe_context *pipe, nr_sampler_views), nr_images); - for (int i = 0; i < shader->info.base.num_inputs; i++) { - shader->inputs[i].usage_mask = shader->info.base.input_usage_mask[i]; - shader->inputs[i].location = shader->info.base.input_interpolate_loc[i]; + nir_foreach_shader_in_variable(var, nir) { + unsigned idx = var->data.driver_location; + unsigned slots = nir_variable_count_slots(var, var->type); - switch (shader->info.base.input_interpolate[i]) { - case TGSI_INTERPOLATE_CONSTANT: - shader->inputs[i].interp = LP_INTERP_CONSTANT; - break; - case TGSI_INTERPOLATE_LINEAR: - shader->inputs[i].interp = LP_INTERP_LINEAR; - break; - case TGSI_INTERPOLATE_PERSPECTIVE: - shader->inputs[i].interp = LP_INTERP_PERSPECTIVE; - break; - case TGSI_INTERPOLATE_COLOR: - shader->inputs[i].interp = LP_INTERP_COLOR; - break; - default: - assert(0); - break; - } + if (var->data.centroid) + shader->inputs[idx].location = TGSI_INTERPOLATE_LOC_CENTROID; + if (var->data.sample) + shader->inputs[idx].location = TGSI_INTERPOLATE_LOC_SAMPLE; - switch (shader->info.base.input_semantic_name[i]) { - case TGSI_SEMANTIC_FACE: - shader->inputs[i].interp = LP_INTERP_FACING; + enum glsl_base_type base_type = + glsl_get_base_type(glsl_without_array(var->type)); + switch (var->data.interpolation) { + case INTERP_MODE_NONE: + if (glsl_base_type_is_integer(base_type) || var->data.per_primitive) { + shader->inputs[idx].interp = LP_INTERP_CONSTANT; + break; + } + if (var->data.location == VARYING_SLOT_COL0 || + var->data.location == VARYING_SLOT_COL1) { + shader->inputs[idx].interp = LP_INTERP_COLOR; + break; + } + FALLTHROUGH; + case INTERP_MODE_SMOOTH: + shader->inputs[idx].interp = LP_INTERP_PERSPECTIVE; + break; + case INTERP_MODE_NOPERSPECTIVE: + shader->inputs[idx].interp = LP_INTERP_LINEAR; + break; + case INTERP_MODE_FLAT: + shader->inputs[idx].interp = LP_INTERP_CONSTANT; break; - case TGSI_SEMANTIC_POSITION: - /* Position was already emitted above - */ - shader->inputs[i].interp = LP_INTERP_POSITION; - shader->inputs[i].src_index = 0; - continue; } /* XXX this is a completely pointless index map... */ - shader->inputs[i].src_index = i+1; + shader->inputs[idx].src_index = idx + 1; + if (var->data.location == VARYING_SLOT_FACE) + shader->inputs[idx].interp = LP_INTERP_FACING; + else if (var->data.location == VARYING_SLOT_POS) { + shader->inputs[idx].src_index = 0; + shader->inputs[idx].interp = LP_INTERP_POSITION; + } + + shader->inputs[idx].usage_mask = shader->info.base.input_usage_mask[idx]; + for (unsigned s = 1; s < slots; s++) { + shader->inputs[idx + s] = shader->inputs[idx]; + shader->inputs[idx + s].src_index = idx + s + 1; + shader->inputs[idx + s].usage_mask = shader->info.base.input_usage_mask[idx + s]; + } } llvmpipe_fs_analyse_nir(shader); diff --git a/src/gallium/drivers/llvmpipe/lp_state_setup.c b/src/gallium/drivers/llvmpipe/lp_state_setup.c index a4900e6d714..2f4bbdf7a88 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_state_setup.c @@ -48,6 +48,7 @@ #include "lp_state_fs.h" #include "lp_state_setup.h" +#include "nir.h" /** Setup shader number (for debugging) */ static unsigned setup_no = 0; @@ -765,10 +766,11 @@ lp_make_setup_variant_key(const struct llvmpipe_context *lp, struct lp_setup_variant_key *key) { const struct lp_fragment_shader *fs = lp->fs; + struct nir_shader *nir = fs->base.ir.nir; assert(sizeof key->inputs[0] == sizeof(uint)); - key->num_inputs = fs->info.base.num_inputs; + key->num_inputs = nir->num_inputs; key->flatshade_first = lp->rasterizer->flatshade_first; key->pixel_center_half = lp->rasterizer->half_pixel_center; key->multisample = lp->rasterizer->multisample;