2 * Copyright © 2019 Collabora Ltd
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 #include "nir_builder.h"
27 /** nir_lower_point_size_mov.c
29 * This pass lowers glPointSize into gl_PointSize, by adding a uniform
30 * and a move from that uniform to VARYING_SLOT_PSIZ. This is useful for
31 * OpenGL ES level hardware that lack constant point-size hardware state.
35 lower_impl(nir_function_impl
*impl
,
36 const gl_state_index16
*pointsize_state_tokens
)
38 nir_shader
*shader
= impl
->function
->shader
;
40 nir_variable
*in
, *out
;
42 nir_builder_init(&b
, impl
);
43 b
.cursor
= nir_before_cf_list(&impl
->body
);
45 in
= nir_variable_create(shader
, nir_var_uniform
,
46 glsl_float_type(), "gl_PointSizeClampedMESA");
47 in
->num_state_slots
= 1;
48 in
->state_slots
= ralloc_array(in
, nir_state_slot
, 1);
49 memcpy(in
->state_slots
[0].tokens
,
50 pointsize_state_tokens
,
51 sizeof(in
->state_slots
[0].tokens
));
53 out
= nir_variable_create(shader
, nir_var_shader_out
,
54 glsl_float_type(), "gl_PointSize");
55 out
->data
.location
= VARYING_SLOT_PSIZ
;
57 nir_copy_var(&b
, out
, in
);
59 nir_metadata_preserve(impl
, nir_metadata_block_index
|
60 nir_metadata_dominance
);
65 nir_lower_point_size_mov(nir_shader
*shader
,
66 const gl_state_index16
*pointsize_state_tokens
)
68 lower_impl(nir_shader_get_entrypoint(shader
), pointsize_state_tokens
);