mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-17 16:08:06 +02:00
Via the Coccinelle patch at the end of the commit message, followed by
sed -ie 's/progress = progress | /progress |=/g' $(git grep -l 'progress = prog')
ninja -C ~/mesa/build clang-format
cd ~/mesa/src/compiler/nir && clang-format -i *.c
agxfmt
@@
identifier prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
-return prog;
+return nir_progress(prog, impl, metadata);
@@
expression prog_expr, impl, metadata;
@@
-if (prog_expr) {
-nir_metadata_preserve(impl, metadata);
-return true;
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-return false;
-}
+bool progress = prog_expr;
+return nir_progress(progress, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-nir_metadata_preserve(impl, prog ? (metadata) : nir_metadata_all);
-return prog;
+return nir_progress(prog, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-nir_metadata_preserve(impl, prog ? (metadata) : nir_metadata_all);
+nir_progress(prog, impl, metadata);
@@
expression impl, metadata;
@@
-nir_metadata_preserve(impl, metadata);
-return true;
+return nir_progress(true, impl, metadata);
@@
expression impl;
@@
-nir_metadata_preserve(impl, nir_metadata_all);
-return false;
+return nir_no_progress(impl);
@@
identifier other_prog, prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
-other_prog |= prog;
+other_prog = other_prog | nir_progress(prog, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+nir_progress(prog, impl, metadata);
@@
identifier other_prog, prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-other_prog = true;
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+other_prog = other_prog | nir_progress(prog, impl, metadata);
@@
expression prog_expr, impl, metadata;
identifier prog;
@@
-if (prog_expr) {
-nir_metadata_preserve(impl, metadata);
-prog = true;
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+bool impl_progress = prog_expr;
+prog = prog | nir_progress(impl_progress, impl, metadata);
@@
identifier other_prog, prog;
expression impl, metadata;
@@
-if (prog) {
-other_prog = true;
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+other_prog = other_prog | nir_progress(prog, impl, metadata);
@@
expression prog_expr, impl, metadata;
identifier prog;
@@
-if (prog_expr) {
-prog = true;
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+bool impl_progress = prog_expr;
+prog = prog | nir_progress(impl_progress, impl, metadata);
@@
expression prog_expr, impl, metadata;
@@
-if (prog_expr) {
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+bool impl_progress = prog_expr;
+nir_progress(impl_progress, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-nir_metadata_preserve(impl, metadata);
-prog = true;
+prog = nir_progress(true, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-}
-return prog;
+return nir_progress(prog, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-}
+nir_progress(prog, impl, metadata);
@@
expression impl;
@@
-nir_metadata_preserve(impl, nir_metadata_all);
+nir_no_progress(impl);
@@
expression impl, metadata;
@@
-nir_metadata_preserve(impl, metadata);
+nir_progress(true, impl, metadata);
squashme! sed -ie 's/progress = progress | /progress |=/g' $(git grep -l 'progress = prog')
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33722>
121 lines
4.4 KiB
C
121 lines
4.4 KiB
C
/*
|
|
* Copyright © 2015 Red Hat
|
|
*
|
|
* 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"
|
|
|
|
/* Lower glBitmap().
|
|
*
|
|
* This is based on the logic in st_get_bitmap_shader() in TGSI compiler.
|
|
* From st_cb_bitmap.c:
|
|
*
|
|
* glBitmaps are drawn as textured quads. The user's bitmap pattern
|
|
* is stored in a texture image. An alpha8 texture format is used.
|
|
* The fragment shader samples a bit (texel) from the texture, then
|
|
* discards the fragment if the bit is off.
|
|
*
|
|
* Note that we actually store the inverse image of the bitmap to
|
|
* simplify the fragment program. An "on" bit gets stored as texel=0x0
|
|
* and an "off" bit is stored as texel=0xff. Then we kill the
|
|
* fragment if the negated texel value is less than zero.
|
|
*
|
|
* Note that the texture format will be, according to what driver supports,
|
|
* in order of preference (with swizzle):
|
|
*
|
|
* I8_UNORM - .xxxx
|
|
* A8_UNORM - .000x
|
|
* L8_UNORM - .xxx1
|
|
*
|
|
* If L8_UNORM, options->swizzle_xxxx is true. Otherwise we can just use
|
|
* the .w comp.
|
|
*/
|
|
|
|
static void
|
|
lower_bitmap(nir_shader *shader, nir_builder *b,
|
|
const nir_lower_bitmap_options *options)
|
|
{
|
|
nir_def *texcoord;
|
|
nir_tex_instr *tex;
|
|
nir_def *cond;
|
|
|
|
nir_def *baryc =
|
|
nir_load_barycentric_pixel(b, 32, .interp_mode = INTERP_MODE_SMOOTH);
|
|
texcoord = nir_load_interpolated_input(b, 4, 32, baryc, nir_imm_int(b, 0),
|
|
.io_semantics.location = VARYING_SLOT_TEX0);
|
|
|
|
const struct glsl_type *sampler2D =
|
|
glsl_sampler_type(GLSL_SAMPLER_DIM_2D, false, false, GLSL_TYPE_FLOAT);
|
|
|
|
nir_variable *tex_var =
|
|
nir_variable_create(shader, nir_var_uniform, sampler2D, "bitmap_tex");
|
|
tex_var->data.binding = options->sampler;
|
|
tex_var->data.explicit_binding = true;
|
|
tex_var->data.how_declared = nir_var_hidden;
|
|
|
|
nir_deref_instr *tex_deref = nir_build_deref_var(b, tex_var);
|
|
|
|
tex = nir_tex_instr_create(shader, 3);
|
|
tex->op = nir_texop_tex;
|
|
tex->sampler_dim = GLSL_SAMPLER_DIM_2D;
|
|
tex->coord_components = 2;
|
|
tex->dest_type = nir_type_float32;
|
|
tex->src[0] = nir_tex_src_for_ssa(nir_tex_src_texture_deref,
|
|
&tex_deref->def);
|
|
tex->src[1] = nir_tex_src_for_ssa(nir_tex_src_sampler_deref,
|
|
&tex_deref->def);
|
|
tex->src[2] = nir_tex_src_for_ssa(nir_tex_src_coord,
|
|
nir_trim_vector(b, texcoord, tex->coord_components));
|
|
|
|
nir_def_init(&tex->instr, &tex->def, 4, 32);
|
|
nir_builder_instr_insert(b, &tex->instr);
|
|
|
|
/* kill if tex != 0.0.. take .x or .w channel according to format: */
|
|
cond = nir_fneu_imm(b, nir_channel(b, &tex->def, options->swizzle_xxxx ? 0 : 3),
|
|
0.0);
|
|
|
|
nir_discard_if(b, cond);
|
|
|
|
shader->info.fs.uses_discard = true;
|
|
}
|
|
|
|
static void
|
|
lower_bitmap_impl(nir_function_impl *impl,
|
|
const nir_lower_bitmap_options *options)
|
|
{
|
|
nir_builder b = nir_builder_at(nir_before_impl(impl));
|
|
|
|
lower_bitmap(impl->function->shader, &b, options);
|
|
|
|
nir_progress(true, impl, nir_metadata_control_flow);
|
|
}
|
|
|
|
bool
|
|
nir_lower_bitmap(nir_shader *shader,
|
|
const nir_lower_bitmap_options *options)
|
|
{
|
|
assert(shader->info.stage == MESA_SHADER_FRAGMENT);
|
|
assert(shader->info.io_lowered);
|
|
|
|
lower_bitmap_impl(nir_shader_get_entrypoint(shader), options);
|
|
return true;
|
|
}
|