mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2024-12-01 06:04:12 +08:00
nir/lower_point_size: Use shader_instructions_pass
Sleepy code deletion mood. Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com> Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21750>
This commit is contained in:
parent
933b5c76f6
commit
2ba48eea88
@ -32,31 +32,11 @@
|
||||
* the driver must clamp the point size written by the shader manually to a
|
||||
* valid range.
|
||||
*/
|
||||
|
||||
static void
|
||||
lower_point_size_instr(nir_builder *b, nir_instr *psiz_instr,
|
||||
float min, float max)
|
||||
{
|
||||
b->cursor = nir_before_instr(psiz_instr);
|
||||
|
||||
nir_intrinsic_instr *instr = nir_instr_as_intrinsic(psiz_instr);
|
||||
|
||||
assert(instr->src[1].is_ssa);
|
||||
assert(instr->src[1].ssa->num_components == 1);
|
||||
nir_ssa_def *psiz = instr->src[1].ssa;
|
||||
|
||||
if (min > 0.0f)
|
||||
psiz = nir_fmax(b, psiz, nir_imm_float(b, min));
|
||||
|
||||
if (max > 0.0f)
|
||||
psiz = nir_fmin(b, psiz, nir_imm_float(b, max));
|
||||
|
||||
nir_instr_rewrite_src(&instr->instr, &instr->src[1], nir_src_for_ssa(psiz));
|
||||
}
|
||||
|
||||
static bool
|
||||
instr_is_point_size(const nir_instr *instr)
|
||||
lower_point_size_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
{
|
||||
float *minmax = (float *)data;
|
||||
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
@ -69,6 +49,20 @@ instr_is_point_size(const nir_instr *instr)
|
||||
if (var->data.location != VARYING_SLOT_PSIZ)
|
||||
return false;
|
||||
|
||||
b->cursor = nir_before_instr(instr);
|
||||
|
||||
assert(intr->src[1].is_ssa);
|
||||
assert(intr->src[1].ssa->num_components == 1);
|
||||
nir_ssa_def *psiz = intr->src[1].ssa;
|
||||
|
||||
if (minmax[0] > 0.0f)
|
||||
psiz = nir_fmax(b, psiz, nir_imm_float(b, minmax[0]));
|
||||
|
||||
if (minmax[1] > 0.0f)
|
||||
psiz = nir_fmin(b, psiz, nir_imm_float(b, minmax[1]));
|
||||
|
||||
nir_instr_rewrite_src(instr, &intr->src[1], nir_src_for_ssa(psiz));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -85,29 +79,8 @@ nir_lower_point_size(nir_shader *s, float min, float max)
|
||||
assert(min > 0.0f || max > 0.0f);
|
||||
assert(min <= 0.0f || max <= 0.0f || min <= max);
|
||||
|
||||
bool progress = false;
|
||||
nir_foreach_function(function, s) {
|
||||
if (!function->impl)
|
||||
continue;
|
||||
|
||||
nir_builder b;
|
||||
nir_builder_init(&b, function->impl);
|
||||
|
||||
nir_foreach_block(block, function->impl) {
|
||||
nir_foreach_instr_safe(instr, block) {
|
||||
if (instr_is_point_size(instr)) {
|
||||
lower_point_size_instr(&b, instr, min, max);
|
||||
progress = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
nir_metadata_preserve(function->impl,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance);
|
||||
}
|
||||
}
|
||||
|
||||
return progress;
|
||||
float minmax[] = {min, max};
|
||||
return nir_shader_instructions_pass(s, lower_point_size_instr,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance, minmax);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user