Commit b4fdefdb authored by Erik Faye-Lund 's avatar Erik Faye-Lund

HACK: st/mesa: add support for lowering point-size

parent 6757882c
......@@ -149,6 +149,7 @@ files_libnir = files(
'nir_lower_passthrough_edgeflags.c',
'nir_lower_patch_vertices.c',
'nir_lower_phis_to_scalar.c',
'nir_lower_point_size.c',
'nir_lower_regs_to_ssa.c',
'nir_lower_returns.c',
'nir_lower_scratch.c',
......
......@@ -3716,6 +3716,9 @@ bool nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables,
bool nir_lower_clip_fs(nir_shader *shader, unsigned ucp_enables);
bool nir_lower_clip_cull_distance_arrays(nir_shader *nir);
void nir_lower_point_size(nir_shader *shader,
const gl_state_index16 *pointsize_state_tokens);
bool nir_lower_frexp(nir_shader *nir);
void nir_lower_two_sided_color(nir_shader *shader);
......
/*
* Copyright © 2019 Collabora Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "nir.h"
#include "nir_builder.h"
static bool
lower_impl(nir_function_impl *impl,
const gl_state_index16 *pointsize_state_tokens)
{
nir_shader *shader = impl->function->shader;
nir_builder b;
nir_variable *in, *out;
nir_builder_init(&b, impl);
b.cursor = nir_before_cf_list(&impl->body);
in = nir_variable_create(shader, nir_var_uniform,
glsl_float_type(), "gl_PointSizeClampedMESA");
in->num_state_slots = 1;
in->state_slots = ralloc_array(in, nir_state_slot, 1);
memcpy(in->state_slots[0].tokens,
pointsize_state_tokens,
sizeof(in->state_slots[0].tokens));
in->data.location = VERT_ATTRIB_EDGEFLAG;
out = nir_variable_create(shader, nir_var_shader_out,
glsl_float_type(), "gl_PointSize");
out->data.location = VARYING_SLOT_PSIZ;
nir_copy_var(&b, out, in);
nir_metadata_preserve(impl, nir_metadata_block_index |
nir_metadata_dominance);
return true;
}
void
nir_lower_point_size(nir_shader *shader,
const gl_state_index16 *pointsize_state_tokens)
{
lower_impl(nir_shader_get_entrypoint(shader), pointsize_state_tokens);
}
......@@ -336,6 +336,7 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen,
case PIPE_CAP_LOWER_FLATSHADE:
case PIPE_CAP_LOWER_ALPHA_TEST:
case PIPE_CAP_LOWER_UCP:
case PIPE_CAP_LOWER_POINT_SIZE:
return 0;
case PIPE_CAP_MAX_GS_INVOCATIONS:
......
......@@ -893,6 +893,7 @@ enum pipe_cap
PIPE_CAP_LOWER_FLATSHADE,
PIPE_CAP_LOWER_ALPHA_TEST,
PIPE_CAP_LOWER_UCP,
PIPE_CAP_LOWER_POINT_SIZE,
};
/**
......
......@@ -205,6 +205,10 @@ st_update_vp( struct st_context *st )
/* _NEW_TRANSFORM */
key.lower_ucp = st->lower_ucp && st_user_clip_planes_enabled(st->ctx);
/* _NEW_POINT */
key.lower_point_size = st->lower_point_size &&
!st_point_size_per_vertex(st->ctx);
st->vp_variant = st_get_vp_variant(st, stvp, &key);
}
......
......@@ -665,6 +665,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
screen->get_param(screen, PIPE_CAP_LOWER_ALPHA_TEST);
st->lower_ucp =
screen->get_param(screen, PIPE_CAP_LOWER_UCP);
st->lower_point_size =
screen->get_param(screen, PIPE_CAP_LOWER_POINT_SIZE);
st->has_hw_atomics =
screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
......
......@@ -148,6 +148,7 @@ struct st_context
boolean lower_flatshade;
boolean lower_alpha_test;
boolean lower_ucp;
boolean lower_point_size;
/**
* If a shader can be created when we get its source.
......
......@@ -643,6 +643,8 @@ st_create_vp_variant(struct st_context *st,
static const gl_state_index16 clipplane_state[STATE_LENGTH] =
{ STATE_INTERNAL, STATE_CLIP_INTERNAL, 0 };
static const gl_state_index16 point_size_state[STATE_LENGTH] =
{ STATE_INTERNAL, STATE_POINT_SIZE_CLAMPED, 0 };
struct gl_program_parameter_list *params = stvp->Base.Parameters;
vpv->key = *key;
......@@ -678,6 +680,11 @@ st_create_vp_variant(struct st_context *st,
nir_shader_get_entrypoint(vpv->tgsi.ir.nir), true, false);
}
if (key->lower_point_size) {
_mesa_add_state_reference(params, point_size_state);
NIR_PASS_V(vpv->tgsi.ir.nir, nir_lower_point_size, point_size_state);
}
st_finalize_nir(st, &stvp->Base, stvp->shader_program,
vpv->tgsi.ir.nir);
......
......@@ -169,6 +169,9 @@ struct st_vp_variant_key
/** for ARB_color_buffer_float */
boolean clamp_color;
/** lower glPointSize to gl_PointSize */
boolean lower_point_size;
/* for user-defined clip-planes */
uint8_t lower_ucp;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment