2014-07-30 15:29:27 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2014 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* Authors:
|
|
|
|
|
* Connor Abbott (cwabbott0@gmail.com)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2023-08-08 12:00:35 -05:00
|
|
|
#include <inttypes.h> /* for PRIx64 macro */
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2016-01-18 10:47:13 +02:00
|
|
|
#include "compiler/shader_enums.h"
|
2018-04-22 01:31:22 +02:00
|
|
|
#include "util/half_float.h"
|
2021-02-05 13:25:03 +02:00
|
|
|
#include "util/memstream.h"
|
2024-05-01 14:36:35 +05:30
|
|
|
#include "util/mesa-blake3.h"
|
2018-12-13 16:50:19 -06:00
|
|
|
#include "vulkan/vulkan_core.h"
|
2023-08-08 12:00:35 -05:00
|
|
|
#include "nir.h"
|
2014-07-30 15:29:27 -07:00
|
|
|
|
|
|
|
|
static void
|
2023-06-09 14:25:04 -07:00
|
|
|
print_indentation(unsigned levels, FILE *fp)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2023-06-09 14:25:04 -07:00
|
|
|
for (unsigned i = 0; i < levels; i++)
|
2023-06-09 14:34:48 -07:00
|
|
|
fprintf(fp, " ");
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp;
|
2015-09-15 18:55:48 -04:00
|
|
|
nir_shader *shader;
|
2014-07-30 15:29:27 -07:00
|
|
|
/** map from nir_variable -> printable name */
|
|
|
|
|
struct hash_table *ht;
|
|
|
|
|
|
|
|
|
|
/** set of names used so far for nir_variables */
|
|
|
|
|
struct set *syms;
|
|
|
|
|
|
|
|
|
|
/* an index used to make new non-conflicting names */
|
|
|
|
|
unsigned index;
|
2016-05-14 15:37:32 -04:00
|
|
|
|
2023-08-12 16:17:15 -04:00
|
|
|
/* Used with nir_gather_types() to identify best representation
|
nir/print: Improve NIR_PRINT=print_consts by using nir_gather_ssa_types()
The two representations are *always* used for `load_const`, but when
inlining the value as SSA source, use just a single terse
representation.
The choice between integer or float is based on the result of
nir_gather_ssa_types(), with a bias for integer when in doubt.
Also remove extra comment `/* */` syntax since the value is already
enclosed by parenthesis.
---
For illustration, here's some instructions from crucible test
func.shader.averageRounded.uint64_t with NIR_DEBUG=print_consts:
BEFORE:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 /*(0xfffffffc = -nan)*/
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 /*(0x00000002 = 0.000000)*/, ssa_25 /*(0x00000024 = 0.000000)*/) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 /*(0x00000002 = 0.000000)*/
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 /*(0x00000007 = 0.000000)*/
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 /*(0x7b000808 = 664776890994587263929995856502063104.000000)*/, ssa_30
```
AFTER:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 (0xfffffffc)
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 (0x2), ssa_25 (0x24)) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 (0x2)
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 (0x7)
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 (0x7b000808), ssa_30
```
and some instructions from crucible test func.gs.basic with NIR_DEBUG=print_consts,
now showing float representation being selected:
BEFORE:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 /*(0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)*/
```
AFTER:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 (0.200000, 0.200000, 0.000000, 0.000000)
```
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23562>
2023-06-09 17:40:58 -07:00
|
|
|
* to print terse inline constant values together with SSA sources.
|
|
|
|
|
* Updated per nir_function_impl being printed.
|
|
|
|
|
*/
|
|
|
|
|
BITSET_WORD *float_types;
|
|
|
|
|
BITSET_WORD *int_types;
|
|
|
|
|
|
2016-05-14 15:37:32 -04:00
|
|
|
/**
|
|
|
|
|
* Optional table of annotations mapping nir object
|
|
|
|
|
* (such as instr or var) to message to print.
|
|
|
|
|
*/
|
|
|
|
|
struct hash_table *annotations;
|
2023-06-09 14:05:58 -07:00
|
|
|
|
|
|
|
|
/* Maximum length for SSA or Reg index in the current impl */
|
|
|
|
|
unsigned max_dest_index;
|
|
|
|
|
|
|
|
|
|
/* Padding for instructions without destination to make
|
|
|
|
|
* them align with the `=` for instructions with destination.
|
|
|
|
|
*/
|
|
|
|
|
unsigned padding_for_no_dest;
|
2015-09-15 18:50:41 -04:00
|
|
|
} print_state;
|
2014-07-30 15:29:27 -07:00
|
|
|
|
2016-05-14 15:37:32 -04:00
|
|
|
static void
|
|
|
|
|
print_annotation(print_state *state, void *obj)
|
|
|
|
|
{
|
2019-10-03 19:09:24 +01:00
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2016-05-14 15:37:32 -04:00
|
|
|
if (!state->annotations)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
struct hash_entry *entry = _mesa_hash_table_search(state->annotations, obj);
|
|
|
|
|
if (!entry)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const char *note = entry->data;
|
|
|
|
|
_mesa_hash_table_remove(state->annotations, entry);
|
|
|
|
|
|
2019-10-03 19:09:24 +01:00
|
|
|
fprintf(fp, "%s\n\n", note);
|
2016-05-14 15:37:32 -04:00
|
|
|
}
|
|
|
|
|
|
2023-06-09 12:12:13 -07:00
|
|
|
/* For 1 element, the size is intentionally omitted. */
|
|
|
|
|
static const char *sizes[] = { "x??", " ", "x2 ", "x3 ", "x4 ",
|
|
|
|
|
"x5 ", "x??", "x??", "x8 ",
|
|
|
|
|
"x??", "x??", "x??", "x??",
|
2023-08-08 12:00:35 -05:00
|
|
|
"x??", "x??", "x??", "x16" };
|
2014-07-30 15:29:27 -07:00
|
|
|
|
2023-02-09 15:18:05 -08:00
|
|
|
static const char *
|
|
|
|
|
divergence_status(print_state *state, bool divergent)
|
|
|
|
|
{
|
|
|
|
|
if (state->shader->info.divergence_analysis_run)
|
|
|
|
|
return divergent ? "div " : "con ";
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-09 14:05:58 -07:00
|
|
|
static unsigned
|
|
|
|
|
count_digits(unsigned n)
|
|
|
|
|
{
|
|
|
|
|
return n ? (unsigned)floor(log10(n)) + 1u : 1u;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
static void
|
2023-08-14 11:50:22 -05:00
|
|
|
print_def(nir_def *def, print_state *state)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
2020-09-09 21:08:49 -07:00
|
|
|
|
2023-08-08 12:00:35 -05:00
|
|
|
const unsigned ssa_padding = state->max_dest_index ? count_digits(state->max_dest_index) - count_digits(def->index) : 0;
|
2023-06-09 14:05:58 -07:00
|
|
|
|
2023-06-15 13:37:35 -07:00
|
|
|
const unsigned padding = (def->bit_size == 1) + 1 + ssa_padding;
|
|
|
|
|
|
|
|
|
|
fprintf(fp, "%s%u%s%*s%%%u",
|
|
|
|
|
divergence_status(state, def->divergent),
|
|
|
|
|
def->bit_size, sizes[def->num_components],
|
|
|
|
|
padding, "", def->index);
|
2023-06-09 14:05:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned
|
|
|
|
|
calculate_padding_for_no_dest(print_state *state)
|
|
|
|
|
{
|
|
|
|
|
const unsigned div = state->shader->info.divergence_analysis_run ? 4 : 0;
|
|
|
|
|
const unsigned ssa_size = 5;
|
|
|
|
|
const unsigned percent = 1;
|
|
|
|
|
const unsigned ssa_index = count_digits(state->max_dest_index);
|
|
|
|
|
const unsigned equals = 1;
|
|
|
|
|
return ssa_size + 1 + div + percent + ssa_index + 1 + equals + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
print_no_dest_padding(print_state *state)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
|
|
|
|
if (state->padding_for_no_dest)
|
|
|
|
|
fprintf(fp, "%*s", state->padding_for_no_dest, "");
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
2021-11-19 15:28:49 +01:00
|
|
|
static void
|
2023-06-12 21:59:34 -07:00
|
|
|
print_hex_padded_const_value(const nir_const_value *value, unsigned bit_size, FILE *fp)
|
2021-11-19 15:28:49 +01:00
|
|
|
{
|
2023-06-12 21:59:34 -07:00
|
|
|
switch (bit_size) {
|
2023-08-08 12:00:35 -05:00
|
|
|
case 64:
|
|
|
|
|
fprintf(fp, "0x%016" PRIx64, value->u64);
|
|
|
|
|
break;
|
|
|
|
|
case 32:
|
|
|
|
|
fprintf(fp, "0x%08x", value->u32);
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
fprintf(fp, "0x%04x", value->u16);
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
|
|
|
|
fprintf(fp, "0x%02x", value->u8);
|
|
|
|
|
break;
|
2023-06-12 21:59:34 -07:00
|
|
|
default:
|
|
|
|
|
unreachable("unhandled bit size");
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-19 15:28:49 +01:00
|
|
|
|
2023-06-12 21:59:34 -07:00
|
|
|
static void
|
|
|
|
|
print_hex_terse_const_value(const nir_const_value *value, unsigned bit_size, FILE *fp)
|
|
|
|
|
{
|
|
|
|
|
switch (bit_size) {
|
2023-08-08 12:00:35 -05:00
|
|
|
case 64:
|
|
|
|
|
fprintf(fp, "0x%" PRIx64, value->u64);
|
|
|
|
|
break;
|
|
|
|
|
case 32:
|
|
|
|
|
fprintf(fp, "0x%x", value->u32);
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
fprintf(fp, "0x%x", value->u16);
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
|
|
|
|
fprintf(fp, "0x%x", value->u8);
|
|
|
|
|
break;
|
2023-06-12 21:59:34 -07:00
|
|
|
default:
|
|
|
|
|
unreachable("unhandled bit size");
|
|
|
|
|
}
|
|
|
|
|
}
|
nir/print: group hex and float vectors together
Vectors are much easier to follow in this format, because developer cares
either about hex or float values, never both.
Before/after:
-vec4 32 ssa_222 = load_const (0x00000000 /* 0.000000 */, 0x00000000 /* 0.000000 */, 0x3f800000 /* 1.000000 */, 0x3f800000 /* 1.000000 */)
+vec4 32 ssa_222 = load_const (0x00000000, 0x00000000, 0x3f800000, 0x3f800000) = (0.000000, 0.000000, 1.000000, 1.000000)
-vec1 32 ssa_174 = load_const (0xbf800000 /* -1.000000 */)
+vec1 32 ssa_174 = load_const (0xbf800000 = -1.000000)
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13880>
2021-11-19 15:35:37 +01:00
|
|
|
|
2023-06-12 21:59:34 -07:00
|
|
|
static void
|
|
|
|
|
print_float_const_value(const nir_const_value *value, unsigned bit_size, FILE *fp)
|
|
|
|
|
{
|
|
|
|
|
switch (bit_size) {
|
2023-08-08 12:00:35 -05:00
|
|
|
case 64:
|
|
|
|
|
fprintf(fp, "%f", value->f64);
|
|
|
|
|
break;
|
|
|
|
|
case 32:
|
|
|
|
|
fprintf(fp, "%f", value->f32);
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
fprintf(fp, "%f", _mesa_half_to_float(value->u16));
|
|
|
|
|
break;
|
2023-06-12 21:59:34 -07:00
|
|
|
default:
|
|
|
|
|
unreachable("unhandled bit size");
|
|
|
|
|
}
|
|
|
|
|
}
|
nir/print: Improve NIR_PRINT=print_consts by using nir_gather_ssa_types()
The two representations are *always* used for `load_const`, but when
inlining the value as SSA source, use just a single terse
representation.
The choice between integer or float is based on the result of
nir_gather_ssa_types(), with a bias for integer when in doubt.
Also remove extra comment `/* */` syntax since the value is already
enclosed by parenthesis.
---
For illustration, here's some instructions from crucible test
func.shader.averageRounded.uint64_t with NIR_DEBUG=print_consts:
BEFORE:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 /*(0xfffffffc = -nan)*/
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 /*(0x00000002 = 0.000000)*/, ssa_25 /*(0x00000024 = 0.000000)*/) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 /*(0x00000002 = 0.000000)*/
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 /*(0x00000007 = 0.000000)*/
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 /*(0x7b000808 = 664776890994587263929995856502063104.000000)*/, ssa_30
```
AFTER:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 (0xfffffffc)
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 (0x2), ssa_25 (0x24)) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 (0x2)
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 (0x7)
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 (0x7b000808), ssa_30
```
and some instructions from crucible test func.gs.basic with NIR_DEBUG=print_consts,
now showing float representation being selected:
BEFORE:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 /*(0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)*/
```
AFTER:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 (0.200000, 0.200000, 0.000000, 0.000000)
```
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23562>
2023-06-09 17:40:58 -07:00
|
|
|
|
2023-06-21 16:58:00 -07:00
|
|
|
static void
|
|
|
|
|
print_int_const_value(const nir_const_value *value, unsigned bit_size, FILE *fp)
|
|
|
|
|
{
|
|
|
|
|
switch (bit_size) {
|
2023-08-08 12:00:35 -05:00
|
|
|
case 64:
|
|
|
|
|
fprintf(fp, "%+" PRIi64, value->i64);
|
|
|
|
|
break;
|
|
|
|
|
case 32:
|
|
|
|
|
fprintf(fp, "%+d", value->i32);
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
fprintf(fp, "%+d", value->i16);
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
|
|
|
|
fprintf(fp, "%+d", value->i8);
|
|
|
|
|
break;
|
2023-06-21 16:58:00 -07:00
|
|
|
default:
|
|
|
|
|
unreachable("unhandled bit size");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
print_uint_const_value(const nir_const_value *value, unsigned bit_size, FILE *fp)
|
|
|
|
|
{
|
|
|
|
|
switch (bit_size) {
|
2023-08-08 12:00:35 -05:00
|
|
|
case 64:
|
|
|
|
|
fprintf(fp, "%" PRIu64, value->u64);
|
|
|
|
|
break;
|
|
|
|
|
case 32:
|
|
|
|
|
fprintf(fp, "%u", value->u32);
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
fprintf(fp, "%u", value->u16);
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
|
|
|
|
fprintf(fp, "%u", value->u8);
|
|
|
|
|
break;
|
2023-06-21 16:58:00 -07:00
|
|
|
default:
|
|
|
|
|
unreachable("unhandled bit size");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-12 21:59:34 -07:00
|
|
|
static void
|
|
|
|
|
print_const_from_load(nir_load_const_instr *instr, print_state *state, nir_alu_type type)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
|
|
|
|
const unsigned bit_size = instr->def.bit_size;
|
|
|
|
|
const unsigned num_components = instr->def.num_components;
|
|
|
|
|
|
2024-03-11 08:55:41 +01:00
|
|
|
type = nir_alu_type_get_base_type(type);
|
|
|
|
|
|
2023-06-12 21:59:34 -07:00
|
|
|
/* There's only one way to print booleans. */
|
2024-03-11 08:55:41 +01:00
|
|
|
if (bit_size == 1 || type == nir_type_bool) {
|
2023-06-12 21:59:34 -07:00
|
|
|
fprintf(fp, "(");
|
|
|
|
|
for (unsigned i = 0; i < num_components; i++) {
|
|
|
|
|
if (i != 0)
|
|
|
|
|
fprintf(fp, ", ");
|
|
|
|
|
fprintf(fp, "%s", instr->value[i].b ? "true" : "false");
|
nir/print: Improve NIR_PRINT=print_consts by using nir_gather_ssa_types()
The two representations are *always* used for `load_const`, but when
inlining the value as SSA source, use just a single terse
representation.
The choice between integer or float is based on the result of
nir_gather_ssa_types(), with a bias for integer when in doubt.
Also remove extra comment `/* */` syntax since the value is already
enclosed by parenthesis.
---
For illustration, here's some instructions from crucible test
func.shader.averageRounded.uint64_t with NIR_DEBUG=print_consts:
BEFORE:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 /*(0xfffffffc = -nan)*/
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 /*(0x00000002 = 0.000000)*/, ssa_25 /*(0x00000024 = 0.000000)*/) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 /*(0x00000002 = 0.000000)*/
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 /*(0x00000007 = 0.000000)*/
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 /*(0x7b000808 = 664776890994587263929995856502063104.000000)*/, ssa_30
```
AFTER:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 (0xfffffffc)
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 (0x2), ssa_25 (0x24)) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 (0x2)
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 (0x7)
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 (0x7b000808), ssa_30
```
and some instructions from crucible test func.gs.basic with NIR_DEBUG=print_consts,
now showing float representation being selected:
BEFORE:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 /*(0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)*/
```
AFTER:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 (0.200000, 0.200000, 0.000000, 0.000000)
```
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23562>
2023-06-09 17:40:58 -07:00
|
|
|
}
|
2023-06-12 21:59:34 -07:00
|
|
|
fprintf(fp, ")");
|
|
|
|
|
return;
|
nir/print: Improve NIR_PRINT=print_consts by using nir_gather_ssa_types()
The two representations are *always* used for `load_const`, but when
inlining the value as SSA source, use just a single terse
representation.
The choice between integer or float is based on the result of
nir_gather_ssa_types(), with a bias for integer when in doubt.
Also remove extra comment `/* */` syntax since the value is already
enclosed by parenthesis.
---
For illustration, here's some instructions from crucible test
func.shader.averageRounded.uint64_t with NIR_DEBUG=print_consts:
BEFORE:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 /*(0xfffffffc = -nan)*/
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 /*(0x00000002 = 0.000000)*/, ssa_25 /*(0x00000024 = 0.000000)*/) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 /*(0x00000002 = 0.000000)*/
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 /*(0x00000007 = 0.000000)*/
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 /*(0x7b000808 = 664776890994587263929995856502063104.000000)*/, ssa_30
```
AFTER:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 (0xfffffffc)
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 (0x2), ssa_25 (0x24)) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 (0x2)
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 (0x7)
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 (0x7b000808), ssa_30
```
and some instructions from crucible test func.gs.basic with NIR_DEBUG=print_consts,
now showing float representation being selected:
BEFORE:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 /*(0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)*/
```
AFTER:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 (0.200000, 0.200000, 0.000000, 0.000000)
```
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23562>
2023-06-09 17:40:58 -07:00
|
|
|
}
|
|
|
|
|
|
2021-11-19 15:47:56 +01:00
|
|
|
fprintf(fp, "(");
|
|
|
|
|
|
2023-06-12 21:59:34 -07:00
|
|
|
if (type != nir_type_invalid) {
|
|
|
|
|
for (unsigned i = 0; i < num_components; i++) {
|
|
|
|
|
const nir_const_value *v = &instr->value[i];
|
nir/print: Improve NIR_PRINT=print_consts by using nir_gather_ssa_types()
The two representations are *always* used for `load_const`, but when
inlining the value as SSA source, use just a single terse
representation.
The choice between integer or float is based on the result of
nir_gather_ssa_types(), with a bias for integer when in doubt.
Also remove extra comment `/* */` syntax since the value is already
enclosed by parenthesis.
---
For illustration, here's some instructions from crucible test
func.shader.averageRounded.uint64_t with NIR_DEBUG=print_consts:
BEFORE:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 /*(0xfffffffc = -nan)*/
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 /*(0x00000002 = 0.000000)*/, ssa_25 /*(0x00000024 = 0.000000)*/) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 /*(0x00000002 = 0.000000)*/
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 /*(0x00000007 = 0.000000)*/
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 /*(0x7b000808 = 664776890994587263929995856502063104.000000)*/, ssa_30
```
AFTER:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 (0xfffffffc)
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 (0x2), ssa_25 (0x24)) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 (0x2)
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 (0x7)
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 (0x7b000808), ssa_30
```
and some instructions from crucible test func.gs.basic with NIR_DEBUG=print_consts,
now showing float representation being selected:
BEFORE:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 /*(0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)*/
```
AFTER:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 (0.200000, 0.200000, 0.000000, 0.000000)
```
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23562>
2023-06-09 17:40:58 -07:00
|
|
|
if (i != 0)
|
|
|
|
|
fprintf(fp, ", ");
|
2023-06-12 21:59:34 -07:00
|
|
|
switch (type) {
|
|
|
|
|
case nir_type_float:
|
|
|
|
|
print_float_const_value(v, bit_size, fp);
|
nir/print: Improve NIR_PRINT=print_consts by using nir_gather_ssa_types()
The two representations are *always* used for `load_const`, but when
inlining the value as SSA source, use just a single terse
representation.
The choice between integer or float is based on the result of
nir_gather_ssa_types(), with a bias for integer when in doubt.
Also remove extra comment `/* */` syntax since the value is already
enclosed by parenthesis.
---
For illustration, here's some instructions from crucible test
func.shader.averageRounded.uint64_t with NIR_DEBUG=print_consts:
BEFORE:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 /*(0xfffffffc = -nan)*/
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 /*(0x00000002 = 0.000000)*/, ssa_25 /*(0x00000024 = 0.000000)*/) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 /*(0x00000002 = 0.000000)*/
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 /*(0x00000007 = 0.000000)*/
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 /*(0x7b000808 = 664776890994587263929995856502063104.000000)*/, ssa_30
```
AFTER:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 (0xfffffffc)
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 (0x2), ssa_25 (0x24)) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 (0x2)
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 (0x7)
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 (0x7b000808), ssa_30
```
and some instructions from crucible test func.gs.basic with NIR_DEBUG=print_consts,
now showing float representation being selected:
BEFORE:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 /*(0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)*/
```
AFTER:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 (0.200000, 0.200000, 0.000000, 0.000000)
```
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23562>
2023-06-09 17:40:58 -07:00
|
|
|
break;
|
2023-06-12 21:59:34 -07:00
|
|
|
case nir_type_int:
|
|
|
|
|
case nir_type_uint:
|
|
|
|
|
print_hex_terse_const_value(v, bit_size, fp);
|
nir/print: Improve NIR_PRINT=print_consts by using nir_gather_ssa_types()
The two representations are *always* used for `load_const`, but when
inlining the value as SSA source, use just a single terse
representation.
The choice between integer or float is based on the result of
nir_gather_ssa_types(), with a bias for integer when in doubt.
Also remove extra comment `/* */` syntax since the value is already
enclosed by parenthesis.
---
For illustration, here's some instructions from crucible test
func.shader.averageRounded.uint64_t with NIR_DEBUG=print_consts:
BEFORE:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 /*(0xfffffffc = -nan)*/
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 /*(0x00000002 = 0.000000)*/, ssa_25 /*(0x00000024 = 0.000000)*/) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 /*(0x00000002 = 0.000000)*/
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 /*(0x00000007 = 0.000000)*/
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 /*(0x7b000808 = 664776890994587263929995856502063104.000000)*/, ssa_30
```
AFTER:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 (0xfffffffc)
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 (0x2), ssa_25 (0x24)) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 (0x2)
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 (0x7)
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 (0x7b000808), ssa_30
```
and some instructions from crucible test func.gs.basic with NIR_DEBUG=print_consts,
now showing float representation being selected:
BEFORE:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 /*(0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)*/
```
AFTER:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 (0.200000, 0.200000, 0.000000, 0.000000)
```
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23562>
2023-06-09 17:40:58 -07:00
|
|
|
break;
|
2023-06-12 21:59:34 -07:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
unreachable("invalid nir alu base type");
|
nir/print: Improve NIR_PRINT=print_consts by using nir_gather_ssa_types()
The two representations are *always* used for `load_const`, but when
inlining the value as SSA source, use just a single terse
representation.
The choice between integer or float is based on the result of
nir_gather_ssa_types(), with a bias for integer when in doubt.
Also remove extra comment `/* */` syntax since the value is already
enclosed by parenthesis.
---
For illustration, here's some instructions from crucible test
func.shader.averageRounded.uint64_t with NIR_DEBUG=print_consts:
BEFORE:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 /*(0xfffffffc = -nan)*/
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 /*(0x00000002 = 0.000000)*/, ssa_25 /*(0x00000024 = 0.000000)*/) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 /*(0x00000002 = 0.000000)*/
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 /*(0x00000007 = 0.000000)*/
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 /*(0x7b000808 = 664776890994587263929995856502063104.000000)*/, ssa_30
```
AFTER:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 (0xfffffffc)
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 (0x2), ssa_25 (0x24)) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 (0x2)
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 (0x7)
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 (0x7b000808), ssa_30
```
and some instructions from crucible test func.gs.basic with NIR_DEBUG=print_consts,
now showing float representation being selected:
BEFORE:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 /*(0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)*/
```
AFTER:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 (0.200000, 0.200000, 0.000000, 0.000000)
```
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23562>
2023-06-09 17:40:58 -07:00
|
|
|
}
|
2021-11-19 15:28:49 +01:00
|
|
|
}
|
2023-06-12 21:59:34 -07:00
|
|
|
} else {
|
2023-08-08 12:00:35 -05:00
|
|
|
#define PRINT_VALUES(F) \
|
|
|
|
|
do { \
|
|
|
|
|
for (unsigned i = 0; i < num_components; i++) { \
|
|
|
|
|
if (i != 0) \
|
|
|
|
|
fprintf(fp, ", "); \
|
|
|
|
|
F(&instr->value[i], bit_size, fp); \
|
|
|
|
|
} \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#define SEPARATOR() \
|
|
|
|
|
if (num_components > 1) \
|
|
|
|
|
fprintf(fp, ") = ("); \
|
|
|
|
|
else \
|
|
|
|
|
fprintf(fp, " = ")
|
2023-06-21 16:58:00 -07:00
|
|
|
|
|
|
|
|
bool needs_float = bit_size > 8;
|
|
|
|
|
bool needs_signed = false;
|
|
|
|
|
bool needs_decimal = false;
|
2023-06-12 21:59:34 -07:00
|
|
|
for (unsigned i = 0; i < num_components; i++) {
|
2023-06-21 16:58:00 -07:00
|
|
|
const nir_const_value *v = &instr->value[i];
|
|
|
|
|
switch (bit_size) {
|
|
|
|
|
case 64:
|
2023-08-08 12:00:35 -05:00
|
|
|
needs_signed |= v->i64 < 0;
|
2023-06-21 16:58:00 -07:00
|
|
|
needs_decimal |= v->u64 >= 10;
|
|
|
|
|
break;
|
|
|
|
|
case 32:
|
2023-08-08 12:00:35 -05:00
|
|
|
needs_signed |= v->i32 < 0;
|
2023-06-21 16:58:00 -07:00
|
|
|
needs_decimal |= v->u32 >= 10;
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
2023-08-08 12:00:35 -05:00
|
|
|
needs_signed |= v->i16 < 0;
|
2023-06-21 16:58:00 -07:00
|
|
|
needs_decimal |= v->u16 >= 10;
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
2023-08-08 12:00:35 -05:00
|
|
|
needs_signed |= v->i8 < 0;
|
2023-06-21 16:58:00 -07:00
|
|
|
needs_decimal |= v->u8 >= 10;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
unreachable("invalid bit size");
|
|
|
|
|
}
|
2023-06-12 21:59:34 -07:00
|
|
|
}
|
nir/print: group hex and float vectors together
Vectors are much easier to follow in this format, because developer cares
either about hex or float values, never both.
Before/after:
-vec4 32 ssa_222 = load_const (0x00000000 /* 0.000000 */, 0x00000000 /* 0.000000 */, 0x3f800000 /* 1.000000 */, 0x3f800000 /* 1.000000 */)
+vec4 32 ssa_222 = load_const (0x00000000, 0x00000000, 0x3f800000, 0x3f800000) = (0.000000, 0.000000, 1.000000, 1.000000)
-vec1 32 ssa_174 = load_const (0xbf800000 /* -1.000000 */)
+vec1 32 ssa_174 = load_const (0xbf800000 = -1.000000)
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13880>
2021-11-19 15:35:37 +01:00
|
|
|
|
2023-06-21 16:58:00 -07:00
|
|
|
if (state->int_types) {
|
|
|
|
|
const unsigned index = instr->def.index;
|
|
|
|
|
const bool inferred_int = BITSET_TEST(state->int_types, index);
|
|
|
|
|
const bool inferred_float = BITSET_TEST(state->float_types, index);
|
2023-06-12 21:59:34 -07:00
|
|
|
|
2023-06-21 16:58:00 -07:00
|
|
|
if (inferred_int && !inferred_float) {
|
|
|
|
|
needs_float = false;
|
|
|
|
|
} else if (inferred_float && !inferred_int) {
|
|
|
|
|
needs_signed = false;
|
|
|
|
|
needs_decimal = false;
|
nir/print: group hex and float vectors together
Vectors are much easier to follow in this format, because developer cares
either about hex or float values, never both.
Before/after:
-vec4 32 ssa_222 = load_const (0x00000000 /* 0.000000 */, 0x00000000 /* 0.000000 */, 0x3f800000 /* 1.000000 */, 0x3f800000 /* 1.000000 */)
+vec4 32 ssa_222 = load_const (0x00000000, 0x00000000, 0x3f800000, 0x3f800000) = (0.000000, 0.000000, 1.000000, 1.000000)
-vec1 32 ssa_174 = load_const (0xbf800000 /* -1.000000 */)
+vec1 32 ssa_174 = load_const (0xbf800000 = -1.000000)
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13880>
2021-11-19 15:35:37 +01:00
|
|
|
}
|
|
|
|
|
}
|
2023-06-21 16:58:00 -07:00
|
|
|
|
|
|
|
|
PRINT_VALUES(print_hex_padded_const_value);
|
|
|
|
|
|
|
|
|
|
if (needs_float) {
|
|
|
|
|
SEPARATOR();
|
|
|
|
|
PRINT_VALUES(print_float_const_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (needs_signed) {
|
|
|
|
|
SEPARATOR();
|
|
|
|
|
PRINT_VALUES(print_int_const_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (needs_decimal) {
|
|
|
|
|
SEPARATOR();
|
|
|
|
|
PRINT_VALUES(print_uint_const_value);
|
|
|
|
|
}
|
nir/print: group hex and float vectors together
Vectors are much easier to follow in this format, because developer cares
either about hex or float values, never both.
Before/after:
-vec4 32 ssa_222 = load_const (0x00000000 /* 0.000000 */, 0x00000000 /* 0.000000 */, 0x3f800000 /* 1.000000 */, 0x3f800000 /* 1.000000 */)
+vec4 32 ssa_222 = load_const (0x00000000, 0x00000000, 0x3f800000, 0x3f800000) = (0.000000, 0.000000, 1.000000, 1.000000)
-vec1 32 ssa_174 = load_const (0xbf800000 /* -1.000000 */)
+vec1 32 ssa_174 = load_const (0xbf800000 = -1.000000)
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13880>
2021-11-19 15:35:37 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-19 15:28:49 +01:00
|
|
|
fprintf(fp, ")");
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 15:47:56 +01:00
|
|
|
static void
|
|
|
|
|
print_load_const_instr(nir_load_const_instr *instr, print_state *state)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2023-08-14 11:50:22 -05:00
|
|
|
print_def(&instr->def, state);
|
2021-11-19 15:47:56 +01:00
|
|
|
|
|
|
|
|
fprintf(fp, " = load_const ");
|
|
|
|
|
|
2023-06-12 21:59:34 -07:00
|
|
|
/* In the definition, print all interpretations of the value. */
|
|
|
|
|
print_const_from_load(instr, state, nir_type_invalid);
|
2021-11-19 15:47:56 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
static void
|
2024-03-18 19:10:07 -05:00
|
|
|
print_src(const nir_src *src, print_state *state, nir_alu_type src_type)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
2024-03-18 19:10:07 -05:00
|
|
|
fprintf(fp, "%%%u", src->ssa->index);
|
|
|
|
|
nir_instr *instr = src->ssa->parent_instr;
|
2023-06-12 21:59:34 -07:00
|
|
|
|
2023-06-09 19:55:49 -07:00
|
|
|
if (instr->type == nir_instr_type_load_const && !NIR_DEBUG(PRINT_NO_INLINE_CONSTS)) {
|
2023-06-12 21:59:34 -07:00
|
|
|
nir_load_const_instr *load_const = nir_instr_as_load_const(instr);
|
nir/print: Improve NIR_PRINT=print_consts by using nir_gather_ssa_types()
The two representations are *always* used for `load_const`, but when
inlining the value as SSA source, use just a single terse
representation.
The choice between integer or float is based on the result of
nir_gather_ssa_types(), with a bias for integer when in doubt.
Also remove extra comment `/* */` syntax since the value is already
enclosed by parenthesis.
---
For illustration, here's some instructions from crucible test
func.shader.averageRounded.uint64_t with NIR_DEBUG=print_consts:
BEFORE:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 /*(0xfffffffc = -nan)*/
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 /*(0x00000002 = 0.000000)*/, ssa_25 /*(0x00000024 = 0.000000)*/) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 /*(0x00000002 = 0.000000)*/
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 /*(0x00000007 = 0.000000)*/
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 /*(0x7b000808 = 664776890994587263929995856502063104.000000)*/, ssa_30
```
AFTER:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 (0xfffffffc)
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 (0x2), ssa_25 (0x24)) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 (0x2)
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 (0x7)
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 (0x7b000808), ssa_30
```
and some instructions from crucible test func.gs.basic with NIR_DEBUG=print_consts,
now showing float representation being selected:
BEFORE:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 /*(0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)*/
```
AFTER:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 (0.200000, 0.200000, 0.000000, 0.000000)
```
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23562>
2023-06-09 17:40:58 -07:00
|
|
|
fprintf(fp, " ");
|
2023-06-12 21:59:34 -07:00
|
|
|
|
|
|
|
|
nir_alu_type type = nir_alu_type_get_base_type(src_type);
|
|
|
|
|
|
|
|
|
|
if (type == nir_type_invalid && state->int_types) {
|
|
|
|
|
const unsigned index = load_const->def.index;
|
|
|
|
|
const bool inferred_int = BITSET_TEST(state->int_types, index);
|
|
|
|
|
const bool inferred_float = BITSET_TEST(state->float_types, index);
|
|
|
|
|
|
|
|
|
|
if (inferred_float && !inferred_int)
|
|
|
|
|
type = nir_type_float;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type == nir_type_invalid)
|
|
|
|
|
type = nir_type_uint;
|
|
|
|
|
|
|
|
|
|
/* For a constant in a source, always pick one interpretation. */
|
|
|
|
|
assert(type != nir_type_invalid);
|
|
|
|
|
print_const_from_load(load_const, state, type);
|
2021-11-19 15:47:56 +01:00
|
|
|
}
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
2019-03-09 17:17:55 +01:00
|
|
|
static const char *
|
|
|
|
|
comp_mask_string(unsigned num_components)
|
|
|
|
|
{
|
|
|
|
|
return (num_components > 4) ? "abcdefghijklmnop" : "xyzw";
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_alu_src(nir_alu_instr *instr, unsigned src, print_state *state)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2023-06-12 21:59:34 -07:00
|
|
|
const nir_op_info *info = &nir_op_infos[instr->op];
|
|
|
|
|
print_src(&instr->src[src].src, state, info->input_types[src]);
|
2014-07-30 15:29:27 -07:00
|
|
|
|
2015-03-23 18:20:21 -07:00
|
|
|
bool print_swizzle = false;
|
2018-07-12 03:40:23 +02:00
|
|
|
nir_component_mask_t used_channels = 0;
|
2015-09-22 10:30:05 -07:00
|
|
|
|
2018-07-12 03:40:23 +02:00
|
|
|
for (unsigned i = 0; i < NIR_MAX_VEC_COMPONENTS; i++) {
|
2015-04-01 16:16:52 -07:00
|
|
|
if (!nir_alu_instr_channel_used(instr, src, i))
|
|
|
|
|
continue;
|
2015-03-23 18:20:21 -07:00
|
|
|
|
2015-09-22 10:30:05 -07:00
|
|
|
used_channels++;
|
|
|
|
|
|
2015-04-01 16:16:52 -07:00
|
|
|
if (instr->src[src].swizzle[i] != i) {
|
2015-03-23 18:20:21 -07:00
|
|
|
print_swizzle = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-15 11:11:12 +10:00
|
|
|
unsigned live_channels = nir_src_num_components(instr->src[src].src);
|
2015-09-22 10:30:05 -07:00
|
|
|
|
|
|
|
|
if (print_swizzle || used_channels != live_channels) {
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, ".");
|
2018-07-12 03:40:23 +02:00
|
|
|
for (unsigned i = 0; i < NIR_MAX_VEC_COMPONENTS; i++) {
|
2015-04-01 16:16:52 -07:00
|
|
|
if (!nir_alu_instr_channel_used(instr, src, i))
|
|
|
|
|
continue;
|
2015-03-23 18:20:21 -07:00
|
|
|
|
2019-03-09 17:17:55 +01:00
|
|
|
fprintf(fp, "%c", comp_mask_string(live_channels)[instr->src[src].swizzle[i]]);
|
2015-03-23 18:20:21 -07:00
|
|
|
}
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_alu_instr(nir_alu_instr *instr, print_state *state)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2023-08-14 11:43:35 -05:00
|
|
|
print_def(&instr->def, state);
|
2014-07-30 15:29:27 -07:00
|
|
|
|
|
|
|
|
fprintf(fp, " = %s", nir_op_infos[instr->op].name);
|
2016-03-17 10:50:27 -07:00
|
|
|
if (instr->exact)
|
|
|
|
|
fprintf(fp, "!");
|
2019-05-17 13:46:38 -07:00
|
|
|
if (instr->no_signed_wrap)
|
|
|
|
|
fprintf(fp, ".nsw");
|
|
|
|
|
if (instr->no_unsigned_wrap)
|
|
|
|
|
fprintf(fp, ".nuw");
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, " ");
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < nir_op_infos[instr->op].num_inputs; i++) {
|
2014-12-18 14:01:37 -08:00
|
|
|
if (i != 0)
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, ", ");
|
|
|
|
|
|
2015-09-15 18:50:41 -04:00
|
|
|
print_alu_src(instr, i, state);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-26 10:26:29 -08:00
|
|
|
static const char *
|
|
|
|
|
get_var_name(nir_variable *var, print_state *state)
|
|
|
|
|
{
|
|
|
|
|
if (state->ht == NULL)
|
2017-06-26 17:07:21 -07:00
|
|
|
return var->name ? var->name : "unnamed";
|
2015-12-26 10:26:29 -08:00
|
|
|
|
|
|
|
|
assert(state->syms);
|
|
|
|
|
|
|
|
|
|
struct hash_entry *entry = _mesa_hash_table_search(state->ht, var);
|
|
|
|
|
if (entry)
|
|
|
|
|
return entry->data;
|
|
|
|
|
|
|
|
|
|
char *name;
|
|
|
|
|
if (var->name == NULL) {
|
2023-06-09 11:45:12 -07:00
|
|
|
name = ralloc_asprintf(state->syms, "#%u", state->index++);
|
2015-12-26 10:26:29 -08:00
|
|
|
} else {
|
|
|
|
|
struct set_entry *set_entry = _mesa_set_search(state->syms, var->name);
|
|
|
|
|
if (set_entry != NULL) {
|
2023-06-09 11:45:12 -07:00
|
|
|
/* we have a collision with another name, append an # + a unique
|
2015-12-26 10:26:29 -08:00
|
|
|
* index */
|
2023-06-09 11:45:12 -07:00
|
|
|
name = ralloc_asprintf(state->syms, "%s#%u", var->name,
|
2015-12-26 10:26:29 -08:00
|
|
|
state->index++);
|
|
|
|
|
} else {
|
|
|
|
|
/* Mark this one as seen */
|
|
|
|
|
_mesa_set_add(state->syms, var->name);
|
|
|
|
|
name = var->name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_mesa_hash_table_insert(state->ht, var, name);
|
|
|
|
|
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-01 10:47:58 -07:00
|
|
|
static const char *
|
|
|
|
|
get_constant_sampler_addressing_mode(enum cl_sampler_addressing_mode mode)
|
|
|
|
|
{
|
|
|
|
|
switch (mode) {
|
2023-08-08 12:00:35 -05:00
|
|
|
case SAMPLER_ADDRESSING_MODE_NONE:
|
|
|
|
|
return "none";
|
|
|
|
|
case SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE:
|
|
|
|
|
return "clamp_to_edge";
|
|
|
|
|
case SAMPLER_ADDRESSING_MODE_CLAMP:
|
|
|
|
|
return "clamp";
|
|
|
|
|
case SAMPLER_ADDRESSING_MODE_REPEAT:
|
|
|
|
|
return "repeat";
|
|
|
|
|
case SAMPLER_ADDRESSING_MODE_REPEAT_MIRRORED:
|
|
|
|
|
return "repeat_mirrored";
|
|
|
|
|
default:
|
|
|
|
|
unreachable("Invalid addressing mode");
|
2020-05-01 10:47:58 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
get_constant_sampler_filter_mode(enum cl_sampler_filter_mode mode)
|
|
|
|
|
{
|
|
|
|
|
switch (mode) {
|
2023-08-08 12:00:35 -05:00
|
|
|
case SAMPLER_FILTER_MODE_NEAREST:
|
|
|
|
|
return "nearest";
|
|
|
|
|
case SAMPLER_FILTER_MODE_LINEAR:
|
|
|
|
|
return "linear";
|
|
|
|
|
default:
|
|
|
|
|
unreachable("Invalid filter mode");
|
2020-05-01 10:47:58 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-22 16:50:23 -05:00
|
|
|
static void
|
|
|
|
|
print_constant(nir_constant *c, const struct glsl_type *type, print_state *state)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp = state->fp;
|
2016-11-29 22:19:28 -08:00
|
|
|
const unsigned rows = glsl_get_vector_elements(type);
|
|
|
|
|
const unsigned cols = glsl_get_matrix_columns(type);
|
2019-06-06 10:51:25 -05:00
|
|
|
unsigned i;
|
2015-12-22 16:50:23 -05:00
|
|
|
|
|
|
|
|
switch (glsl_get_base_type(type)) {
|
2018-10-19 11:14:47 -05:00
|
|
|
case GLSL_TYPE_BOOL:
|
|
|
|
|
/* Only float base types can be matrices. */
|
|
|
|
|
assert(cols == 1);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < rows; i++) {
|
2023-08-08 12:00:35 -05:00
|
|
|
if (i > 0)
|
|
|
|
|
fprintf(fp, ", ");
|
2019-06-06 10:51:25 -05:00
|
|
|
fprintf(fp, "%s", c->values[i].b ? "true" : "false");
|
2018-10-19 11:14:47 -05:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2018-05-10 10:20:47 +02:00
|
|
|
case GLSL_TYPE_UINT8:
|
|
|
|
|
case GLSL_TYPE_INT8:
|
|
|
|
|
/* Only float base types can be matrices. */
|
|
|
|
|
assert(cols == 1);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < rows; i++) {
|
2023-08-08 12:00:35 -05:00
|
|
|
if (i > 0)
|
|
|
|
|
fprintf(fp, ", ");
|
2019-06-06 10:51:25 -05:00
|
|
|
fprintf(fp, "0x%02x", c->values[i].u8);
|
2018-05-10 10:20:47 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GLSL_TYPE_UINT16:
|
|
|
|
|
case GLSL_TYPE_INT16:
|
|
|
|
|
/* Only float base types can be matrices. */
|
|
|
|
|
assert(cols == 1);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < rows; i++) {
|
2023-08-08 12:00:35 -05:00
|
|
|
if (i > 0)
|
|
|
|
|
fprintf(fp, ", ");
|
2019-06-06 10:51:25 -05:00
|
|
|
fprintf(fp, "0x%04x", c->values[i].u16);
|
2018-05-10 10:20:47 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2015-12-22 16:50:23 -05:00
|
|
|
case GLSL_TYPE_UINT:
|
|
|
|
|
case GLSL_TYPE_INT:
|
2016-12-05 11:51:54 -08:00
|
|
|
/* Only float base types can be matrices. */
|
|
|
|
|
assert(cols == 1);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < rows; i++) {
|
2023-08-08 12:00:35 -05:00
|
|
|
if (i > 0)
|
|
|
|
|
fprintf(fp, ", ");
|
2019-06-06 10:51:25 -05:00
|
|
|
fprintf(fp, "0x%08x", c->values[i].u32);
|
2015-12-22 16:50:23 -05:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2018-05-10 10:20:47 +02:00
|
|
|
case GLSL_TYPE_FLOAT16:
|
2015-12-22 16:50:23 -05:00
|
|
|
case GLSL_TYPE_FLOAT:
|
2015-08-14 10:37:18 -07:00
|
|
|
case GLSL_TYPE_DOUBLE:
|
2019-06-06 10:51:25 -05:00
|
|
|
if (cols > 1) {
|
|
|
|
|
for (i = 0; i < cols; i++) {
|
2023-08-08 12:00:35 -05:00
|
|
|
if (i > 0)
|
|
|
|
|
fprintf(fp, ", ");
|
2019-06-06 10:51:25 -05:00
|
|
|
print_constant(c->elements[i], glsl_get_column_type(type), state);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
switch (glsl_get_base_type(type)) {
|
|
|
|
|
case GLSL_TYPE_FLOAT16:
|
|
|
|
|
for (i = 0; i < rows; i++) {
|
2023-08-08 12:00:35 -05:00
|
|
|
if (i > 0)
|
|
|
|
|
fprintf(fp, ", ");
|
2019-06-06 10:51:25 -05:00
|
|
|
fprintf(fp, "%f", _mesa_half_to_float(c->values[i].u16));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GLSL_TYPE_FLOAT:
|
|
|
|
|
for (i = 0; i < rows; i++) {
|
2023-08-08 12:00:35 -05:00
|
|
|
if (i > 0)
|
|
|
|
|
fprintf(fp, ", ");
|
2019-06-06 10:51:25 -05:00
|
|
|
fprintf(fp, "%f", c->values[i].f32);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GLSL_TYPE_DOUBLE:
|
|
|
|
|
for (i = 0; i < rows; i++) {
|
2023-08-08 12:00:35 -05:00
|
|
|
if (i > 0)
|
|
|
|
|
fprintf(fp, ", ");
|
2019-06-06 10:51:25 -05:00
|
|
|
fprintf(fp, "%f", c->values[i].f64);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
unreachable("Cannot get here from the first level switch");
|
2016-11-29 22:19:28 -08:00
|
|
|
}
|
2015-08-14 10:37:18 -07:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2016-09-01 14:17:49 -07:00
|
|
|
case GLSL_TYPE_UINT64:
|
|
|
|
|
case GLSL_TYPE_INT64:
|
|
|
|
|
/* Only float base types can be matrices. */
|
|
|
|
|
assert(cols == 1);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < cols; i++) {
|
2023-08-08 12:00:35 -05:00
|
|
|
if (i > 0)
|
|
|
|
|
fprintf(fp, ", ");
|
2019-06-06 10:51:25 -05:00
|
|
|
fprintf(fp, "0x%08" PRIx64, c->values[i].u64);
|
2016-09-01 14:17:49 -07:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2015-12-22 16:50:23 -05:00
|
|
|
case GLSL_TYPE_STRUCT:
|
2020-07-10 15:58:39 -05:00
|
|
|
case GLSL_TYPE_INTERFACE:
|
2015-12-22 16:50:23 -05:00
|
|
|
for (i = 0; i < c->num_elements; i++) {
|
2023-08-08 12:00:35 -05:00
|
|
|
if (i > 0)
|
|
|
|
|
fprintf(fp, ", ");
|
2015-12-22 16:50:23 -05:00
|
|
|
fprintf(fp, "{ ");
|
|
|
|
|
print_constant(c->elements[i], glsl_get_struct_field(type, i), state);
|
|
|
|
|
fprintf(fp, " }");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GLSL_TYPE_ARRAY:
|
|
|
|
|
for (i = 0; i < c->num_elements; i++) {
|
2023-08-08 12:00:35 -05:00
|
|
|
if (i > 0)
|
|
|
|
|
fprintf(fp, ", ");
|
2015-12-22 16:50:23 -05:00
|
|
|
fprintf(fp, "{ ");
|
|
|
|
|
print_constant(c->elements[i], glsl_get_array_element(type), state);
|
|
|
|
|
fprintf(fp, " }");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
unreachable("not reached");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-15 10:00:05 +02:00
|
|
|
static const char *
|
2018-03-14 21:45:38 -07:00
|
|
|
get_variable_mode_str(nir_variable_mode mode, bool want_local_global_mode)
|
2016-04-15 10:00:05 +02:00
|
|
|
{
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case nir_var_shader_in:
|
|
|
|
|
return "shader_in";
|
|
|
|
|
case nir_var_shader_out:
|
|
|
|
|
return "shader_out";
|
|
|
|
|
case nir_var_uniform:
|
|
|
|
|
return "uniform";
|
2019-01-16 00:09:27 +01:00
|
|
|
case nir_var_mem_ubo:
|
2018-12-14 11:21:50 -06:00
|
|
|
return "ubo";
|
2016-04-15 10:00:05 +02:00
|
|
|
case nir_var_system_value:
|
|
|
|
|
return "system";
|
2019-01-16 00:11:23 +01:00
|
|
|
case nir_var_mem_ssbo:
|
2018-12-14 11:21:50 -06:00
|
|
|
return "ssbo";
|
2019-01-16 00:12:38 +01:00
|
|
|
case nir_var_mem_shared:
|
2016-04-15 10:00:05 +02:00
|
|
|
return "shared";
|
2018-10-23 14:06:16 +02:00
|
|
|
case nir_var_mem_global:
|
|
|
|
|
return "global";
|
2020-05-27 16:51:04 -05:00
|
|
|
case nir_var_mem_push_const:
|
|
|
|
|
return "push_const";
|
2020-08-18 14:02:21 -05:00
|
|
|
case nir_var_mem_constant:
|
|
|
|
|
return "constant";
|
2021-10-15 12:58:22 -05:00
|
|
|
case nir_var_image:
|
2020-01-08 13:54:47 -08:00
|
|
|
return "image";
|
2019-01-15 23:56:29 +01:00
|
|
|
case nir_var_shader_temp:
|
|
|
|
|
return want_local_global_mode ? "shader_temp" : "";
|
2019-01-16 00:05:04 +01:00
|
|
|
case nir_var_function_temp:
|
|
|
|
|
return want_local_global_mode ? "function_temp" : "";
|
2020-07-29 14:00:29 -05:00
|
|
|
case nir_var_shader_call_data:
|
|
|
|
|
return "shader_call_data";
|
|
|
|
|
case nir_var_ray_hit_attrib:
|
|
|
|
|
return "ray_hit_attrib";
|
2022-02-08 02:55:18 +01:00
|
|
|
case nir_var_mem_task_payload:
|
|
|
|
|
return "task_payload";
|
2023-08-01 14:35:21 +02:00
|
|
|
case nir_var_mem_node_payload:
|
|
|
|
|
return "node_payload";
|
|
|
|
|
case nir_var_mem_node_payload_in:
|
|
|
|
|
return "node_payload_in";
|
2016-04-15 10:00:05 +02:00
|
|
|
default:
|
2020-08-15 00:28:55 -05:00
|
|
|
if (mode && (mode & nir_var_mem_generic) == mode)
|
|
|
|
|
return "generic";
|
2016-04-15 10:00:05 +02:00
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 19:32:25 -05:00
|
|
|
static const char *
|
|
|
|
|
get_location_str(unsigned location, gl_shader_stage stage,
|
|
|
|
|
nir_variable_mode mode, char *buf)
|
|
|
|
|
{
|
|
|
|
|
switch (stage) {
|
|
|
|
|
case MESA_SHADER_VERTEX:
|
|
|
|
|
if (mode == nir_var_shader_in)
|
|
|
|
|
return gl_vert_attrib_name(location);
|
|
|
|
|
else if (mode == nir_var_shader_out)
|
|
|
|
|
return gl_varying_slot_name_for_stage(location, stage);
|
|
|
|
|
|
|
|
|
|
break;
|
2023-04-06 14:29:33 -04:00
|
|
|
case MESA_SHADER_TESS_CTRL:
|
|
|
|
|
case MESA_SHADER_TESS_EVAL:
|
2023-02-02 19:32:25 -05:00
|
|
|
case MESA_SHADER_TASK:
|
|
|
|
|
case MESA_SHADER_MESH:
|
|
|
|
|
case MESA_SHADER_GEOMETRY:
|
|
|
|
|
if (mode == nir_var_shader_in || mode == nir_var_shader_out)
|
|
|
|
|
return gl_varying_slot_name_for_stage(location, stage);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MESA_SHADER_FRAGMENT:
|
|
|
|
|
if (mode == nir_var_shader_in)
|
|
|
|
|
return gl_varying_slot_name_for_stage(location, stage);
|
|
|
|
|
else if (mode == nir_var_shader_out)
|
|
|
|
|
return gl_frag_result_name(location);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MESA_SHADER_COMPUTE:
|
|
|
|
|
case MESA_SHADER_KERNEL:
|
|
|
|
|
default:
|
|
|
|
|
/* TODO */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-10 10:47:59 -07:00
|
|
|
if (mode == nir_var_system_value)
|
|
|
|
|
return gl_system_value_name(location);
|
|
|
|
|
|
2023-02-02 19:32:25 -05:00
|
|
|
if (location == ~0) {
|
|
|
|
|
return "~0";
|
|
|
|
|
} else {
|
|
|
|
|
snprintf(buf, 4, "%u", location);
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-20 11:30:06 -04:00
|
|
|
static void
|
|
|
|
|
print_access(enum gl_access_qualifier access, print_state *state, const char *separator)
|
|
|
|
|
{
|
|
|
|
|
if (!access) {
|
|
|
|
|
fputs("none", state->fp);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
|
enum gl_access_qualifier bit;
|
|
|
|
|
const char *name;
|
|
|
|
|
} modes[] = {
|
|
|
|
|
{ ACCESS_COHERENT, "coherent" },
|
|
|
|
|
{ ACCESS_VOLATILE, "volatile" },
|
|
|
|
|
{ ACCESS_RESTRICT, "restrict" },
|
|
|
|
|
{ ACCESS_NON_WRITEABLE, "readonly" },
|
|
|
|
|
{ ACCESS_NON_READABLE, "writeonly" },
|
|
|
|
|
{ ACCESS_CAN_REORDER, "reorderable" },
|
2023-06-30 09:10:56 -04:00
|
|
|
{ ACCESS_CAN_SPECULATE, "speculatable" },
|
2023-08-20 11:30:06 -04:00
|
|
|
{ ACCESS_NON_TEMPORAL, "non-temporal" },
|
|
|
|
|
{ ACCESS_INCLUDE_HELPERS, "include-helpers" },
|
2023-05-31 14:52:31 -04:00
|
|
|
{ ACCESS_CP_GE_COHERENT_AMD, "cp-ge-coherent-amd" },
|
2023-08-20 11:30:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool first = true;
|
|
|
|
|
for (unsigned i = 0; i < ARRAY_SIZE(modes); ++i) {
|
|
|
|
|
if (access & modes[i].bit) {
|
|
|
|
|
fprintf(state->fp, "%s%s", first ? "" : separator, modes[i].name);
|
|
|
|
|
first = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_var_decl(nir_variable *var, print_state *state)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, "decl_var ");
|
|
|
|
|
|
2021-09-14 15:28:24 -04:00
|
|
|
const char *const bindless = (var->data.bindless) ? "bindless " : "";
|
2014-07-30 15:29:27 -07:00
|
|
|
const char *const cent = (var->data.centroid) ? "centroid " : "";
|
|
|
|
|
const char *const samp = (var->data.sample) ? "sample " : "";
|
2015-10-02 00:01:23 -07:00
|
|
|
const char *const patch = (var->data.patch) ? "patch " : "";
|
2014-07-30 15:29:27 -07:00
|
|
|
const char *const inv = (var->data.invariant) ? "invariant " : "";
|
2020-02-11 14:41:05 -08:00
|
|
|
const char *const per_view = (var->data.per_view) ? "per_view " : "";
|
2021-04-29 11:51:57 -07:00
|
|
|
const char *const per_primitive = (var->data.per_primitive) ? "per_primitive " : "";
|
2021-10-20 15:51:43 +03:00
|
|
|
const char *const ray_query = (var->data.ray_query) ? "ray_query " : "";
|
|
|
|
|
fprintf(fp, "%s%s%s%s%s%s%s%s%s %s ",
|
|
|
|
|
bindless, cent, samp, patch, inv, per_view, per_primitive, ray_query,
|
2020-02-11 14:41:05 -08:00
|
|
|
get_variable_mode_str(var->data.mode, false),
|
2016-07-07 02:02:38 -07:00
|
|
|
glsl_interp_mode_name(var->data.interpolation));
|
2014-07-30 15:29:27 -07:00
|
|
|
|
2023-08-20 11:30:06 -04:00
|
|
|
print_access(var->data.access, state, " ");
|
|
|
|
|
fprintf(fp, " ");
|
2016-05-05 13:52:38 +02:00
|
|
|
|
2019-11-07 17:54:13 -05:00
|
|
|
if (glsl_get_base_type(glsl_without_array(var->type)) == GLSL_TYPE_IMAGE) {
|
2020-01-10 14:09:43 -08:00
|
|
|
fprintf(fp, "%s ", util_format_short_name(var->data.image.format));
|
2019-11-07 17:54:13 -05:00
|
|
|
}
|
2018-12-13 11:15:07 -08:00
|
|
|
|
2020-03-04 11:54:26 -08:00
|
|
|
if (var->data.precision) {
|
|
|
|
|
const char *precisions[] = {
|
|
|
|
|
"",
|
|
|
|
|
"highp",
|
|
|
|
|
"mediump",
|
|
|
|
|
"lowp",
|
|
|
|
|
};
|
|
|
|
|
fprintf(fp, "%s ", precisions[var->data.precision]);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 11:58:59 -07:00
|
|
|
fprintf(fp, "%s %s", glsl_get_type_name(var->type),
|
|
|
|
|
get_var_name(var, state));
|
2014-07-30 15:29:27 -07:00
|
|
|
|
2020-01-08 13:54:47 -08:00
|
|
|
if (var->data.mode & (nir_var_shader_in |
|
|
|
|
|
nir_var_shader_out |
|
|
|
|
|
nir_var_uniform |
|
2023-10-10 10:47:59 -07:00
|
|
|
nir_var_system_value |
|
2020-01-08 13:54:47 -08:00
|
|
|
nir_var_mem_ubo |
|
|
|
|
|
nir_var_mem_ssbo |
|
2021-10-15 12:58:22 -05:00
|
|
|
nir_var_image)) {
|
2015-09-15 18:55:48 -04:00
|
|
|
char buf[4];
|
2023-02-02 19:32:25 -05:00
|
|
|
const char *loc = get_location_str(var->data.location,
|
|
|
|
|
state->shader->info.stage,
|
|
|
|
|
var->data.mode, buf);
|
2015-09-15 18:55:48 -04:00
|
|
|
|
2017-10-17 10:41:55 -07:00
|
|
|
/* For shader I/O vars that have been split to components or packed,
|
|
|
|
|
* print the fractional location within the input/output.
|
|
|
|
|
*/
|
|
|
|
|
unsigned int num_components =
|
|
|
|
|
glsl_get_components(glsl_without_array(var->type));
|
2023-10-10 10:47:59 -07:00
|
|
|
const char *components = "";
|
2023-08-08 12:00:35 -05:00
|
|
|
char components_local[18] = { '.' /* the rest is 0-filled */ };
|
2017-10-17 10:41:55 -07:00
|
|
|
switch (var->data.mode) {
|
|
|
|
|
case nir_var_shader_in:
|
|
|
|
|
case nir_var_shader_out:
|
2019-03-09 17:17:55 +01:00
|
|
|
if (num_components < 16 && num_components != 0) {
|
|
|
|
|
const char *xyzw = comp_mask_string(num_components);
|
2017-10-17 10:41:55 -07:00
|
|
|
for (int i = 0; i < num_components; i++)
|
|
|
|
|
components_local[i + 1] = xyzw[i + var->data.location_frac];
|
|
|
|
|
|
|
|
|
|
components = components_local;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-10 10:47:59 -07:00
|
|
|
if (var->data.mode & nir_var_system_value) {
|
|
|
|
|
fprintf(fp, " (%s%s)", loc, components);
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(fp, " (%s%s, %u, %u)%s", loc,
|
|
|
|
|
components,
|
|
|
|
|
var->data.driver_location, var->data.binding,
|
|
|
|
|
var->data.compact ? " compact" : "");
|
|
|
|
|
}
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
2015-12-22 16:50:23 -05:00
|
|
|
if (var->constant_initializer) {
|
2023-05-18 10:31:50 -07:00
|
|
|
if (var->constant_initializer->is_null_constant) {
|
|
|
|
|
fprintf(fp, " = null");
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(fp, " = { ");
|
|
|
|
|
print_constant(var->constant_initializer, var->type, state);
|
|
|
|
|
fprintf(fp, " }");
|
|
|
|
|
}
|
2015-12-22 16:50:23 -05:00
|
|
|
}
|
2020-05-01 10:47:58 -07:00
|
|
|
if (glsl_type_is_sampler(var->type) && var->data.sampler.is_inline_sampler) {
|
|
|
|
|
fprintf(fp, " = { %s, %s, %s }",
|
|
|
|
|
get_constant_sampler_addressing_mode(var->data.sampler.addressing_mode),
|
|
|
|
|
var->data.sampler.normalized_coordinates ? "true" : "false",
|
|
|
|
|
get_constant_sampler_filter_mode(var->data.sampler.filter_mode));
|
|
|
|
|
}
|
2019-12-10 15:37:53 -05:00
|
|
|
if (var->pointer_initializer)
|
|
|
|
|
fprintf(fp, " = &%s", get_var_name(var->pointer_initializer, state));
|
2015-12-22 16:50:23 -05:00
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, "\n");
|
2016-05-14 15:37:32 -04:00
|
|
|
print_annotation(state, var);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
2018-03-14 21:45:38 -07:00
|
|
|
static void
|
2018-12-19 12:13:46 -08:00
|
|
|
print_deref_link(const nir_deref_instr *instr, bool whole_chain, print_state *state)
|
2018-03-14 21:45:38 -07:00
|
|
|
{
|
|
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
|
|
|
|
if (instr->deref_type == nir_deref_type_var) {
|
|
|
|
|
fprintf(fp, "%s", get_var_name(instr->var, state));
|
|
|
|
|
return;
|
|
|
|
|
} else if (instr->deref_type == nir_deref_type_cast) {
|
|
|
|
|
fprintf(fp, "(%s *)", glsl_get_type_name(instr->type));
|
2023-06-12 21:59:34 -07:00
|
|
|
print_src(&instr->parent, state, nir_type_invalid);
|
2018-03-14 21:45:38 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nir_deref_instr *parent =
|
|
|
|
|
nir_instr_as_deref(instr->parent.ssa->parent_instr);
|
|
|
|
|
|
|
|
|
|
/* Is the parent we're going to print a bare cast? */
|
|
|
|
|
const bool is_parent_cast =
|
|
|
|
|
whole_chain && parent->deref_type == nir_deref_type_cast;
|
|
|
|
|
|
|
|
|
|
/* If we're not printing the whole chain, the parent we print will be a SSA
|
|
|
|
|
* value that represents a pointer. The only deref type that naturally
|
|
|
|
|
* gives a pointer is a cast.
|
|
|
|
|
*/
|
|
|
|
|
const bool is_parent_pointer =
|
|
|
|
|
!whole_chain || parent->deref_type == nir_deref_type_cast;
|
|
|
|
|
|
|
|
|
|
/* Struct derefs have a nice syntax that works on pointers, arrays derefs
|
|
|
|
|
* do not.
|
|
|
|
|
*/
|
|
|
|
|
const bool need_deref =
|
|
|
|
|
is_parent_pointer && instr->deref_type != nir_deref_type_struct;
|
|
|
|
|
|
|
|
|
|
/* Cast need extra parens and so * dereferences */
|
|
|
|
|
if (is_parent_cast || need_deref)
|
|
|
|
|
fprintf(fp, "(");
|
|
|
|
|
|
|
|
|
|
if (need_deref)
|
|
|
|
|
fprintf(fp, "*");
|
|
|
|
|
|
|
|
|
|
if (whole_chain) {
|
|
|
|
|
print_deref_link(parent, whole_chain, state);
|
|
|
|
|
} else {
|
2023-06-12 21:59:34 -07:00
|
|
|
print_src(&instr->parent, state, nir_type_invalid);
|
2018-03-14 21:45:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_parent_cast || need_deref)
|
|
|
|
|
fprintf(fp, ")");
|
|
|
|
|
|
|
|
|
|
switch (instr->deref_type) {
|
|
|
|
|
case nir_deref_type_struct:
|
|
|
|
|
fprintf(fp, "%s%s", is_parent_pointer ? "->" : ".",
|
|
|
|
|
glsl_get_struct_elem_name(parent->type, instr->strct.index));
|
|
|
|
|
break;
|
|
|
|
|
|
2018-11-28 12:26:52 -06:00
|
|
|
case nir_deref_type_array:
|
|
|
|
|
case nir_deref_type_ptr_as_array: {
|
2019-04-01 21:36:12 -05:00
|
|
|
if (nir_src_is_const(instr->arr.index)) {
|
2023-08-08 12:00:35 -05:00
|
|
|
fprintf(fp, "[%" PRId64 "]", nir_src_as_int(instr->arr.index));
|
2018-03-14 21:45:38 -07:00
|
|
|
} else {
|
|
|
|
|
fprintf(fp, "[");
|
2023-06-12 21:59:34 -07:00
|
|
|
print_src(&instr->arr.index, state, nir_type_invalid);
|
2018-03-14 21:45:38 -07:00
|
|
|
fprintf(fp, "]");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case nir_deref_type_array_wildcard:
|
|
|
|
|
fprintf(fp, "[*]");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
unreachable("Invalid deref instruction type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
print_deref_instr(nir_deref_instr *instr, print_state *state)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2023-08-14 11:56:00 -05:00
|
|
|
print_def(&instr->def, state);
|
2018-03-14 21:45:38 -07:00
|
|
|
|
|
|
|
|
switch (instr->deref_type) {
|
|
|
|
|
case nir_deref_type_var:
|
|
|
|
|
fprintf(fp, " = deref_var ");
|
|
|
|
|
break;
|
|
|
|
|
case nir_deref_type_array:
|
|
|
|
|
case nir_deref_type_array_wildcard:
|
|
|
|
|
fprintf(fp, " = deref_array ");
|
|
|
|
|
break;
|
|
|
|
|
case nir_deref_type_struct:
|
|
|
|
|
fprintf(fp, " = deref_struct ");
|
|
|
|
|
break;
|
|
|
|
|
case nir_deref_type_cast:
|
|
|
|
|
fprintf(fp, " = deref_cast ");
|
|
|
|
|
break;
|
2018-11-28 12:26:52 -06:00
|
|
|
case nir_deref_type_ptr_as_array:
|
|
|
|
|
fprintf(fp, " = deref_ptr_as_array ");
|
|
|
|
|
break;
|
2018-03-14 21:45:38 -07:00
|
|
|
default:
|
|
|
|
|
unreachable("Invalid deref instruction type");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Only casts naturally return a pointer type */
|
|
|
|
|
if (instr->deref_type != nir_deref_type_cast)
|
|
|
|
|
fprintf(fp, "&");
|
|
|
|
|
|
|
|
|
|
print_deref_link(instr, false, state);
|
|
|
|
|
|
2020-08-15 00:28:55 -05:00
|
|
|
fprintf(fp, " (");
|
|
|
|
|
unsigned modes = instr->modes;
|
|
|
|
|
while (modes) {
|
|
|
|
|
int m = u_bit_scan(&modes);
|
|
|
|
|
fprintf(fp, "%s%s", get_variable_mode_str(1 << m, true),
|
2023-08-08 12:00:35 -05:00
|
|
|
modes ? "|" : "");
|
2020-08-15 00:28:55 -05:00
|
|
|
}
|
2023-04-14 13:07:32 +02:00
|
|
|
fprintf(fp, " %s)", glsl_get_type_name(instr->type));
|
2018-03-14 21:45:38 -07:00
|
|
|
|
2019-07-03 12:10:43 -07:00
|
|
|
if (instr->deref_type == nir_deref_type_cast) {
|
2023-06-09 17:05:59 -07:00
|
|
|
fprintf(fp, " (ptr_stride=%u, align_mul=%u, align_offset=%u)",
|
2020-09-08 12:50:34 -07:00
|
|
|
instr->cast.ptr_stride,
|
|
|
|
|
instr->cast.align_mul, instr->cast.align_offset);
|
2019-07-03 12:10:43 -07:00
|
|
|
}
|
2023-06-09 14:43:38 -07:00
|
|
|
|
|
|
|
|
if (instr->deref_type != nir_deref_type_var &&
|
|
|
|
|
instr->deref_type != nir_deref_type_cast) {
|
|
|
|
|
/* Print the entire chain as a comment */
|
|
|
|
|
fprintf(fp, " // &");
|
|
|
|
|
print_deref_link(instr, true, state);
|
|
|
|
|
}
|
2018-03-14 21:45:38 -07:00
|
|
|
}
|
|
|
|
|
|
2018-12-13 16:50:19 -06:00
|
|
|
static const char *
|
|
|
|
|
vulkan_descriptor_type_name(VkDescriptorType type)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
2023-08-08 12:00:35 -05:00
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
|
|
|
|
return "sampler";
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
|
|
|
|
return "texture+sampler";
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
|
|
|
|
return "texture";
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
|
|
|
|
return "image";
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
|
|
|
|
return "texture-buffer";
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
|
|
|
|
return "image-buffer";
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
|
|
|
|
return "UBO";
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
|
|
|
|
return "SSBO";
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
|
|
|
|
return "UBO";
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
|
|
|
|
return "SSBO";
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
|
|
|
|
|
return "input-att";
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK:
|
|
|
|
|
return "inline-UBO";
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR:
|
|
|
|
|
return "accel-struct";
|
|
|
|
|
default:
|
|
|
|
|
return "unknown";
|
2018-12-13 16:50:19 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-11 09:43:11 -07:00
|
|
|
static void
|
|
|
|
|
print_alu_type(nir_alu_type type, print_state *state)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
unsigned size = nir_alu_type_get_type_size(type);
|
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
|
|
switch (nir_alu_type_get_base_type(type)) {
|
2023-08-08 12:00:35 -05:00
|
|
|
case nir_type_int:
|
|
|
|
|
name = "int";
|
|
|
|
|
break;
|
|
|
|
|
case nir_type_uint:
|
|
|
|
|
name = "uint";
|
|
|
|
|
break;
|
|
|
|
|
case nir_type_bool:
|
|
|
|
|
name = "bool";
|
|
|
|
|
break;
|
|
|
|
|
case nir_type_float:
|
|
|
|
|
name = "float";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
name = "invalid";
|
2020-06-11 09:43:11 -07:00
|
|
|
}
|
|
|
|
|
if (size)
|
|
|
|
|
fprintf(fp, "%s%u", name, size);
|
|
|
|
|
else
|
|
|
|
|
fprintf(fp, "%s", name);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2016-01-13 18:43:14 -05:00
|
|
|
const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];
|
|
|
|
|
unsigned num_srcs = info->num_srcs;
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
2014-07-30 15:29:27 -07:00
|
|
|
|
2016-01-13 18:43:14 -05:00
|
|
|
if (info->has_dest) {
|
2023-08-14 11:56:00 -05:00
|
|
|
print_def(&instr->def, state);
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, " = ");
|
2023-06-09 14:05:58 -07:00
|
|
|
} else {
|
|
|
|
|
print_no_dest_padding(state);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
2024-03-03 17:44:27 -04:00
|
|
|
fprintf(fp, "@%s", info->name);
|
2014-07-30 15:29:27 -07:00
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < num_srcs; i++) {
|
2024-03-03 17:44:27 -04:00
|
|
|
if (i == 0)
|
|
|
|
|
fprintf(fp, " (");
|
|
|
|
|
else
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, ", ");
|
|
|
|
|
|
2023-06-12 21:59:34 -07:00
|
|
|
print_src(&instr->src[i], state, nir_intrinsic_instr_src_type(instr, i));
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
2024-03-03 17:44:27 -04:00
|
|
|
if (num_srcs)
|
|
|
|
|
fprintf(fp, ")");
|
2014-07-30 15:29:27 -07:00
|
|
|
|
2016-01-13 18:43:14 -05:00
|
|
|
for (unsigned i = 0; i < info->num_indices; i++) {
|
2021-10-19 11:27:40 +02:00
|
|
|
unsigned idx = info->indices[i];
|
2024-03-03 17:44:27 -04:00
|
|
|
if (i == 0)
|
|
|
|
|
fprintf(fp, " (");
|
|
|
|
|
else
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, ", ");
|
2019-03-07 11:07:04 -08:00
|
|
|
switch (idx) {
|
2020-11-24 12:51:59 +00:00
|
|
|
case NIR_INTRINSIC_WRITE_MASK: {
|
2016-01-13 18:43:14 -05:00
|
|
|
/* special case wrmask to show it as a writemask.. */
|
|
|
|
|
unsigned wrmask = nir_intrinsic_write_mask(instr);
|
2021-10-19 11:27:40 +02:00
|
|
|
fprintf(fp, "wrmask=");
|
2019-03-09 17:17:55 +01:00
|
|
|
for (unsigned i = 0; i < instr->num_components; i++)
|
2016-01-13 18:43:14 -05:00
|
|
|
if ((wrmask >> i) & 1)
|
2019-03-09 17:17:55 +01:00
|
|
|
fprintf(fp, "%c", comp_mask_string(instr->num_components)[i]);
|
2019-03-07 11:07:04 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NIR_INTRINSIC_REDUCTION_OP: {
|
2017-08-29 20:09:58 -07:00
|
|
|
nir_op reduction_op = nir_intrinsic_reduction_op(instr);
|
2021-10-19 11:27:40 +02:00
|
|
|
fprintf(fp, "reduction_op=%s", nir_op_infos[reduction_op].name);
|
2019-03-07 11:07:04 -08:00
|
|
|
break;
|
|
|
|
|
}
|
nir: Add unified atomics
Currently, we have an atomic intrinsic for each combination of memory type
(global, shared, image, etc) and atomic operation (add, sub, etc). So for m
types of memory supported by the driver and n atomic opcodes, the driver has to
handle O(mn) intrinsics. This makes a total mess in every single backend I've
looked at, without fail.
It would be a lot nicer to unify the intrinsics. There are two obvious ways:
1. Make the memory type a constant index, keep different intrinsics for
different operations. The problem with this is that different memory types
imply different intrinsic signatures (number of sources, etc). As an
example, it doesn't make sense to unify global_atomic_amd with
global_atomic_2x32, as an example. The first takes 3 scalar sources, the
second takes 1 vector and 1 scalar. Also, in any single backend, there are a
lot more operations than there are memory types.
2. Make the opcode a constant index, keep different intrinsics for different
operations. This works well, with one exception: compswap and fcompswap
take an extra argument that other atomics don't, so there's an extra axis of
variation for the intrinsic signatures.
So, the solution is to have 2 intrinsics for each memory type -- for atomics
taking 1 argument and atomics taking 2 respectively. Both of these intrinsics
take an nir_atomic_op enum to describe its operation. We don't use a nir_op for
this purpose, as there are some atomics (cmpxchg, inc_wrap, etc) that don't
cleanly map to any ALU op and it would be weird to force it.
The plan is to transition to these new opcodes gradually. This series adds a
lowering pass producing these opcodes from the existing opcodes, so that
backends can opt-in to the new forms one-by-one. Then we can convert backends
separately without any cross-tree flag day. Once everything is converted, we can
convert the producers and core NIR as a flag day, but we have far fewer
producers than backends so this should be fine. Finally we can drop the old
stuff.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Rob Clark <robclark@freedesktop.org>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22914>
2023-05-08 15:29:31 -04:00
|
|
|
|
|
|
|
|
case NIR_INTRINSIC_ATOMIC_OP: {
|
|
|
|
|
nir_atomic_op atomic_op = nir_intrinsic_atomic_op(instr);
|
|
|
|
|
fprintf(fp, "atomic_op=");
|
|
|
|
|
|
|
|
|
|
switch (atomic_op) {
|
2023-08-08 12:00:35 -05:00
|
|
|
case nir_atomic_op_iadd:
|
|
|
|
|
fprintf(fp, "iadd");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_imin:
|
|
|
|
|
fprintf(fp, "imin");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_umin:
|
|
|
|
|
fprintf(fp, "umin");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_imax:
|
|
|
|
|
fprintf(fp, "imax");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_umax:
|
|
|
|
|
fprintf(fp, "umax");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_iand:
|
|
|
|
|
fprintf(fp, "iand");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_ior:
|
|
|
|
|
fprintf(fp, "ior");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_ixor:
|
|
|
|
|
fprintf(fp, "ixor");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_xchg:
|
|
|
|
|
fprintf(fp, "xchg");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_fadd:
|
|
|
|
|
fprintf(fp, "fadd");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_fmin:
|
|
|
|
|
fprintf(fp, "fmin");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_fmax:
|
|
|
|
|
fprintf(fp, "fmax");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_cmpxchg:
|
|
|
|
|
fprintf(fp, "cmpxchg");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_fcmpxchg:
|
|
|
|
|
fprintf(fp, "fcmpxchg");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_inc_wrap:
|
|
|
|
|
fprintf(fp, "inc_wrap");
|
|
|
|
|
break;
|
|
|
|
|
case nir_atomic_op_dec_wrap:
|
|
|
|
|
fprintf(fp, "dec_wrap");
|
|
|
|
|
break;
|
2024-03-04 05:33:56 -05:00
|
|
|
case nir_atomic_op_ordered_add_gfx12_amd:
|
|
|
|
|
fprintf(fp, "ordered_add");
|
|
|
|
|
break;
|
nir: Add unified atomics
Currently, we have an atomic intrinsic for each combination of memory type
(global, shared, image, etc) and atomic operation (add, sub, etc). So for m
types of memory supported by the driver and n atomic opcodes, the driver has to
handle O(mn) intrinsics. This makes a total mess in every single backend I've
looked at, without fail.
It would be a lot nicer to unify the intrinsics. There are two obvious ways:
1. Make the memory type a constant index, keep different intrinsics for
different operations. The problem with this is that different memory types
imply different intrinsic signatures (number of sources, etc). As an
example, it doesn't make sense to unify global_atomic_amd with
global_atomic_2x32, as an example. The first takes 3 scalar sources, the
second takes 1 vector and 1 scalar. Also, in any single backend, there are a
lot more operations than there are memory types.
2. Make the opcode a constant index, keep different intrinsics for different
operations. This works well, with one exception: compswap and fcompswap
take an extra argument that other atomics don't, so there's an extra axis of
variation for the intrinsic signatures.
So, the solution is to have 2 intrinsics for each memory type -- for atomics
taking 1 argument and atomics taking 2 respectively. Both of these intrinsics
take an nir_atomic_op enum to describe its operation. We don't use a nir_op for
this purpose, as there are some atomics (cmpxchg, inc_wrap, etc) that don't
cleanly map to any ALU op and it would be weird to force it.
The plan is to transition to these new opcodes gradually. This series adds a
lowering pass producing these opcodes from the existing opcodes, so that
backends can opt-in to the new forms one-by-one. Then we can convert backends
separately without any cross-tree flag day. Once everything is converted, we can
convert the producers and core NIR as a flag day, but we have far fewer
producers than backends so this should be fine. Finally we can drop the old
stuff.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Rob Clark <robclark@freedesktop.org>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22914>
2023-05-08 15:29:31 -04:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-03-07 11:07:04 -08:00
|
|
|
|
|
|
|
|
case NIR_INTRINSIC_IMAGE_DIM: {
|
2018-08-16 15:11:44 -05:00
|
|
|
static const char *dim_name[] = {
|
|
|
|
|
[GLSL_SAMPLER_DIM_1D] = "1D",
|
|
|
|
|
[GLSL_SAMPLER_DIM_2D] = "2D",
|
|
|
|
|
[GLSL_SAMPLER_DIM_3D] = "3D",
|
|
|
|
|
[GLSL_SAMPLER_DIM_CUBE] = "Cube",
|
|
|
|
|
[GLSL_SAMPLER_DIM_RECT] = "Rect",
|
|
|
|
|
[GLSL_SAMPLER_DIM_BUF] = "Buf",
|
|
|
|
|
[GLSL_SAMPLER_DIM_MS] = "2D-MSAA",
|
|
|
|
|
[GLSL_SAMPLER_DIM_SUBPASS] = "Subpass",
|
|
|
|
|
[GLSL_SAMPLER_DIM_SUBPASS_MS] = "Subpass-MSAA",
|
|
|
|
|
};
|
|
|
|
|
enum glsl_sampler_dim dim = nir_intrinsic_image_dim(instr);
|
2018-11-26 16:04:30 +01:00
|
|
|
assert(dim < ARRAY_SIZE(dim_name) && dim_name[dim]);
|
2021-10-19 11:27:40 +02:00
|
|
|
fprintf(fp, "image_dim=%s", dim_name[dim]);
|
2019-03-07 11:07:04 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NIR_INTRINSIC_IMAGE_ARRAY: {
|
2019-03-28 23:50:54 +01:00
|
|
|
bool array = nir_intrinsic_image_array(instr);
|
2021-10-19 11:27:40 +02:00
|
|
|
fprintf(fp, "image_array=%s", array ? "true" : "false");
|
2019-03-07 11:07:04 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 12:30:05 -05:00
|
|
|
case NIR_INTRINSIC_FORMAT: {
|
|
|
|
|
enum pipe_format format = nir_intrinsic_format(instr);
|
2021-10-19 11:27:40 +02:00
|
|
|
fprintf(fp, "format=%s", util_format_short_name(format));
|
2020-06-05 12:30:05 -05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-07 11:07:04 -08:00
|
|
|
case NIR_INTRINSIC_DESC_TYPE: {
|
2018-12-13 16:50:19 -06:00
|
|
|
VkDescriptorType desc_type = nir_intrinsic_desc_type(instr);
|
2021-10-19 11:27:40 +02:00
|
|
|
fprintf(fp, "desc_type=%s", vulkan_descriptor_type_name(desc_type));
|
2019-03-07 11:07:04 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 21:20:53 -05:00
|
|
|
case NIR_INTRINSIC_SRC_TYPE: {
|
2021-10-19 11:27:40 +02:00
|
|
|
fprintf(fp, "src_type=");
|
2020-09-30 21:20:53 -05:00
|
|
|
print_alu_type(nir_intrinsic_src_type(instr), state);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NIR_INTRINSIC_DEST_TYPE: {
|
2021-10-19 11:27:40 +02:00
|
|
|
fprintf(fp, "dest_type=");
|
2020-09-30 21:20:53 -05:00
|
|
|
print_alu_type(nir_intrinsic_dest_type(instr), state);
|
2019-03-07 11:07:04 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NIR_INTRINSIC_SWIZZLE_MASK: {
|
2021-10-19 11:27:40 +02:00
|
|
|
fprintf(fp, "swizzle_mask=");
|
2018-05-09 20:37:24 +02:00
|
|
|
unsigned mask = nir_intrinsic_swizzle_mask(instr);
|
|
|
|
|
if (instr->intrinsic == nir_intrinsic_quad_swizzle_amd) {
|
|
|
|
|
for (unsigned i = 0; i < 4; i++)
|
|
|
|
|
fprintf(fp, "%d", (mask >> (i * 2) & 3));
|
|
|
|
|
} else if (instr->intrinsic == nir_intrinsic_masked_swizzle_amd) {
|
|
|
|
|
fprintf(fp, "((id & %d) | %d) ^ %d", mask & 0x1F,
|
2023-08-08 12:00:35 -05:00
|
|
|
(mask >> 5) & 0x1F,
|
|
|
|
|
(mask >> 10) & 0x1F);
|
2018-05-09 20:37:24 +02:00
|
|
|
} else {
|
|
|
|
|
fprintf(fp, "%d", mask);
|
|
|
|
|
}
|
2019-03-07 11:07:04 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-18 16:14:03 -07:00
|
|
|
case NIR_INTRINSIC_MEMORY_SEMANTICS: {
|
|
|
|
|
nir_memory_semantics semantics = nir_intrinsic_memory_semantics(instr);
|
2021-10-19 11:27:40 +02:00
|
|
|
fprintf(fp, "mem_semantics=");
|
2019-07-18 16:14:03 -07:00
|
|
|
switch (semantics & (NIR_MEMORY_ACQUIRE | NIR_MEMORY_RELEASE)) {
|
2023-08-08 12:00:35 -05:00
|
|
|
case 0:
|
|
|
|
|
fprintf(fp, "NONE");
|
|
|
|
|
break;
|
|
|
|
|
case NIR_MEMORY_ACQUIRE:
|
|
|
|
|
fprintf(fp, "ACQ");
|
|
|
|
|
break;
|
|
|
|
|
case NIR_MEMORY_RELEASE:
|
|
|
|
|
fprintf(fp, "REL");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
fprintf(fp, "ACQ|REL");
|
|
|
|
|
break;
|
2019-07-18 16:14:03 -07:00
|
|
|
}
|
2023-08-08 12:00:35 -05:00
|
|
|
if (semantics & (NIR_MEMORY_MAKE_AVAILABLE))
|
|
|
|
|
fprintf(fp, "|AVAILABLE");
|
|
|
|
|
if (semantics & (NIR_MEMORY_MAKE_VISIBLE))
|
|
|
|
|
fprintf(fp, "|VISIBLE");
|
2019-07-18 16:14:03 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NIR_INTRINSIC_MEMORY_MODES: {
|
2021-10-19 11:27:40 +02:00
|
|
|
fprintf(fp, "mem_modes=");
|
2019-07-18 16:14:03 -07:00
|
|
|
unsigned int modes = nir_intrinsic_memory_modes(instr);
|
2023-06-01 11:25:30 -07:00
|
|
|
if (modes == 0)
|
|
|
|
|
fputc('0', fp);
|
2019-07-18 16:14:03 -07:00
|
|
|
while (modes) {
|
|
|
|
|
nir_variable_mode m = u_bit_scan(&modes);
|
|
|
|
|
fprintf(fp, "%s%s", get_variable_mode_str(1 << m, true), modes ? "|" : "");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 09:13:20 +02:00
|
|
|
case NIR_INTRINSIC_EXECUTION_SCOPE:
|
2019-07-18 16:14:03 -07:00
|
|
|
case NIR_INTRINSIC_MEMORY_SCOPE: {
|
2023-05-30 12:05:30 -07:00
|
|
|
mesa_scope scope =
|
2020-06-05 15:26:47 -07:00
|
|
|
idx == NIR_INTRINSIC_MEMORY_SCOPE ? nir_intrinsic_memory_scope(instr)
|
|
|
|
|
: nir_intrinsic_execution_scope(instr);
|
2023-05-30 12:41:23 -07:00
|
|
|
const char *name = mesa_scope_name(scope);
|
|
|
|
|
static const char prefix[] = "SCOPE_";
|
|
|
|
|
if (strncmp(name, prefix, sizeof(prefix) - 1) == 0)
|
|
|
|
|
name += sizeof(prefix) - 1;
|
|
|
|
|
fprintf(fp, "%s=%s", nir_intrinsic_index_names[idx], name);
|
2019-07-18 16:14:03 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 15:29:23 +02:00
|
|
|
case NIR_INTRINSIC_IO_SEMANTICS: {
|
|
|
|
|
struct nir_io_semantics io = nir_intrinsic_io_semantics(instr);
|
2023-02-02 19:33:07 -05:00
|
|
|
|
|
|
|
|
/* Try to figure out the mode so we can interpret the location */
|
|
|
|
|
nir_variable_mode mode = nir_var_mem_generic;
|
|
|
|
|
switch (instr->intrinsic) {
|
|
|
|
|
case nir_intrinsic_load_input:
|
2024-07-06 04:24:31 -04:00
|
|
|
case nir_intrinsic_load_per_primitive_input:
|
2023-02-02 19:33:07 -05:00
|
|
|
case nir_intrinsic_load_interpolated_input:
|
2023-05-27 14:32:46 -04:00
|
|
|
case nir_intrinsic_load_per_vertex_input:
|
2023-05-31 08:42:13 +02:00
|
|
|
case nir_intrinsic_load_input_vertex:
|
2023-08-03 13:33:54 -04:00
|
|
|
case nir_intrinsic_load_coefficients_agx:
|
2023-02-02 19:33:07 -05:00
|
|
|
mode = nir_var_shader_in;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case nir_intrinsic_load_output:
|
|
|
|
|
case nir_intrinsic_store_output:
|
|
|
|
|
case nir_intrinsic_store_per_primitive_output:
|
|
|
|
|
case nir_intrinsic_store_per_vertex_output:
|
|
|
|
|
mode = nir_var_shader_out;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Using that mode, we should be able to name the location */
|
|
|
|
|
char buf[4];
|
|
|
|
|
const char *loc = get_location_str(io.location,
|
|
|
|
|
state->shader->info.stage, mode,
|
|
|
|
|
buf);
|
|
|
|
|
|
|
|
|
|
fprintf(fp, "io location=%s slots=%u", loc, io.num_slots);
|
2021-10-18 15:29:23 +02:00
|
|
|
|
2024-04-11 11:06:35 +02:00
|
|
|
if (io.interp_explicit_strict)
|
|
|
|
|
fprintf(fp, " explicit_strict");
|
|
|
|
|
|
2021-10-18 15:29:23 +02:00
|
|
|
if (io.dual_source_blend_index)
|
|
|
|
|
fprintf(fp, " dualsrc");
|
|
|
|
|
|
|
|
|
|
if (io.fb_fetch_output)
|
|
|
|
|
fprintf(fp, " fbfetch");
|
|
|
|
|
|
|
|
|
|
if (io.per_view)
|
|
|
|
|
fprintf(fp, " perview");
|
|
|
|
|
|
|
|
|
|
if (io.medium_precision)
|
|
|
|
|
fprintf(fp, " mediump");
|
|
|
|
|
|
|
|
|
|
if (io.high_16bits)
|
|
|
|
|
fprintf(fp, " high_16bits");
|
|
|
|
|
|
2024-03-09 12:28:35 -05:00
|
|
|
if (io.invariant)
|
|
|
|
|
fprintf(fp, " invariant");
|
|
|
|
|
|
2023-03-13 00:18:47 -04:00
|
|
|
if (io.high_dvec2)
|
|
|
|
|
fprintf(fp, " high_dvec2");
|
|
|
|
|
|
2022-01-02 19:46:45 -05:00
|
|
|
if (io.no_varying)
|
|
|
|
|
fprintf(fp, " no_varying");
|
|
|
|
|
|
|
|
|
|
if (io.no_sysval_output)
|
|
|
|
|
fprintf(fp, " no_sysval_output");
|
|
|
|
|
|
2021-10-18 15:40:13 +02:00
|
|
|
if (state->shader &&
|
2023-08-08 12:00:35 -05:00
|
|
|
state->shader->info.stage == MESA_SHADER_GEOMETRY &&
|
|
|
|
|
(instr->intrinsic == nir_intrinsic_store_output ||
|
|
|
|
|
instr->intrinsic == nir_intrinsic_store_per_primitive_output ||
|
|
|
|
|
instr->intrinsic == nir_intrinsic_store_per_vertex_output)) {
|
2021-10-18 15:40:13 +02:00
|
|
|
unsigned gs_streams = io.gs_streams;
|
|
|
|
|
fprintf(fp, " gs_streams(");
|
|
|
|
|
for (unsigned i = 0; i < 4; i++) {
|
|
|
|
|
fprintf(fp, "%s%c=%u", i ? " " : "", "xyzw"[i],
|
|
|
|
|
(gs_streams >> (i * 2)) & 0x3);
|
2020-08-14 19:34:27 -04:00
|
|
|
}
|
2021-10-18 15:40:13 +02:00
|
|
|
fprintf(fp, ")");
|
2020-08-14 19:34:27 -04:00
|
|
|
}
|
2021-10-18 15:29:23 +02:00
|
|
|
|
2020-08-14 19:34:27 -04:00
|
|
|
break;
|
2021-10-18 15:29:23 +02:00
|
|
|
}
|
2020-08-14 19:34:27 -04:00
|
|
|
|
2021-12-19 14:20:52 -05:00
|
|
|
case NIR_INTRINSIC_IO_XFB:
|
|
|
|
|
case NIR_INTRINSIC_IO_XFB2: {
|
|
|
|
|
/* This prints both IO_XFB and IO_XFB2. */
|
|
|
|
|
fprintf(fp, "xfb%s(", idx == NIR_INTRINSIC_IO_XFB ? "" : "2");
|
|
|
|
|
bool first = true;
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
unsigned start_comp = (idx == NIR_INTRINSIC_IO_XFB ? 0 : 2) + i;
|
2023-08-08 12:00:35 -05:00
|
|
|
nir_io_xfb xfb = start_comp < 2 ? nir_intrinsic_io_xfb(instr) : nir_intrinsic_io_xfb2(instr);
|
2021-12-19 14:20:52 -05:00
|
|
|
|
|
|
|
|
if (!xfb.out[i].num_components)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!first)
|
|
|
|
|
fprintf(fp, ", ");
|
|
|
|
|
first = false;
|
|
|
|
|
|
|
|
|
|
if (xfb.out[i].num_components > 1) {
|
|
|
|
|
fprintf(fp, "components=%u..%u",
|
|
|
|
|
start_comp, start_comp + xfb.out[i].num_components - 1);
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(fp, "component=%u", start_comp);
|
|
|
|
|
}
|
|
|
|
|
fprintf(fp, " buffer=%u offset=%u",
|
|
|
|
|
xfb.out[i].buffer, (uint32_t)xfb.out[i].offset * 4);
|
|
|
|
|
}
|
|
|
|
|
fprintf(fp, ")");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 15:19:45 -05:00
|
|
|
case NIR_INTRINSIC_ROUNDING_MODE: {
|
2021-10-19 11:27:40 +02:00
|
|
|
fprintf(fp, "rounding_mode=");
|
2020-09-30 15:19:45 -05:00
|
|
|
switch (nir_intrinsic_rounding_mode(instr)) {
|
2023-08-08 12:00:35 -05:00
|
|
|
case nir_rounding_mode_undef:
|
|
|
|
|
fprintf(fp, "undef");
|
|
|
|
|
break;
|
|
|
|
|
case nir_rounding_mode_rtne:
|
|
|
|
|
fprintf(fp, "rtne");
|
|
|
|
|
break;
|
|
|
|
|
case nir_rounding_mode_ru:
|
|
|
|
|
fprintf(fp, "ru");
|
|
|
|
|
break;
|
|
|
|
|
case nir_rounding_mode_rd:
|
|
|
|
|
fprintf(fp, "rd");
|
|
|
|
|
break;
|
|
|
|
|
case nir_rounding_mode_rtz:
|
|
|
|
|
fprintf(fp, "rtz");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
fprintf(fp, "unknown");
|
|
|
|
|
break;
|
2020-09-30 15:19:45 -05:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-10 12:20:00 +02:00
|
|
|
case NIR_INTRINSIC_RAY_QUERY_VALUE: {
|
|
|
|
|
fprintf(fp, "ray_query_value=");
|
|
|
|
|
switch (nir_intrinsic_ray_query_value(instr)) {
|
2023-08-08 12:00:35 -05:00
|
|
|
#define VAL(_name) \
|
|
|
|
|
case nir_ray_query_value_##_name: \
|
|
|
|
|
fprintf(fp, #_name); \
|
|
|
|
|
break
|
|
|
|
|
VAL(intersection_type);
|
|
|
|
|
VAL(intersection_t);
|
|
|
|
|
VAL(intersection_instance_custom_index);
|
|
|
|
|
VAL(intersection_instance_id);
|
|
|
|
|
VAL(intersection_instance_sbt_index);
|
|
|
|
|
VAL(intersection_geometry_index);
|
|
|
|
|
VAL(intersection_primitive_index);
|
|
|
|
|
VAL(intersection_barycentrics);
|
|
|
|
|
VAL(intersection_front_face);
|
|
|
|
|
VAL(intersection_object_ray_direction);
|
|
|
|
|
VAL(intersection_object_ray_origin);
|
|
|
|
|
VAL(intersection_object_to_world);
|
|
|
|
|
VAL(intersection_world_to_object);
|
|
|
|
|
VAL(intersection_candidate_aabb_opaque);
|
|
|
|
|
VAL(tmin);
|
|
|
|
|
VAL(flags);
|
|
|
|
|
VAL(world_ray_direction);
|
|
|
|
|
VAL(world_ray_origin);
|
2022-11-10 12:20:00 +02:00
|
|
|
#undef VAL
|
2023-08-08 12:00:35 -05:00
|
|
|
default:
|
|
|
|
|
fprintf(fp, "unknown");
|
|
|
|
|
break;
|
2022-11-10 12:20:00 +02:00
|
|
|
}
|
2022-12-22 17:27:58 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NIR_INTRINSIC_RESOURCE_ACCESS_INTEL: {
|
|
|
|
|
fprintf(fp, "resource_intel=");
|
|
|
|
|
unsigned int modes = nir_intrinsic_resource_access_intel(instr);
|
2023-06-01 11:25:30 -07:00
|
|
|
if (modes == 0)
|
|
|
|
|
fputc('0', fp);
|
2022-12-22 17:27:58 +02:00
|
|
|
while (modes) {
|
|
|
|
|
nir_resource_data_intel i = 1u << u_bit_scan(&modes);
|
|
|
|
|
switch (i) {
|
2023-08-08 12:00:35 -05:00
|
|
|
case nir_resource_intel_bindless:
|
|
|
|
|
fprintf(fp, "bindless");
|
|
|
|
|
break;
|
|
|
|
|
case nir_resource_intel_pushable:
|
|
|
|
|
fprintf(fp, "pushable");
|
|
|
|
|
break;
|
|
|
|
|
case nir_resource_intel_sampler:
|
|
|
|
|
fprintf(fp, "sampler");
|
|
|
|
|
break;
|
2022-12-22 17:27:58 +02:00
|
|
|
case nir_resource_intel_non_uniform:
|
2023-08-08 12:00:35 -05:00
|
|
|
fprintf(fp, "non-uniform");
|
|
|
|
|
break;
|
2023-03-21 10:36:24 +02:00
|
|
|
case nir_resource_intel_sampler_embedded:
|
|
|
|
|
fprintf(fp, "sampler-embedded");
|
|
|
|
|
break;
|
2023-08-08 12:00:35 -05:00
|
|
|
default:
|
|
|
|
|
fprintf(fp, "unknown");
|
|
|
|
|
break;
|
2022-12-22 17:27:58 +02:00
|
|
|
}
|
|
|
|
|
fprintf(fp, "%s", modes ? "|" : "");
|
|
|
|
|
}
|
2022-11-10 12:20:00 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-20 11:30:06 -04:00
|
|
|
case NIR_INTRINSIC_ACCESS: {
|
|
|
|
|
fprintf(fp, "access=");
|
|
|
|
|
print_access(nir_intrinsic_access(instr), state, "|");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-08 11:02:14 -07:00
|
|
|
case NIR_INTRINSIC_MATRIX_LAYOUT: {
|
|
|
|
|
fprintf(fp, "matrix_layout=");
|
|
|
|
|
switch (nir_intrinsic_matrix_layout(instr)) {
|
|
|
|
|
case GLSL_MATRIX_LAYOUT_ROW_MAJOR:
|
|
|
|
|
fprintf(fp, "row_major");
|
|
|
|
|
break;
|
|
|
|
|
case GLSL_MATRIX_LAYOUT_COLUMN_MAJOR:
|
|
|
|
|
fprintf(fp, "col_major");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
fprintf(fp, "unknown");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NIR_INTRINSIC_CMAT_DESC: {
|
|
|
|
|
struct glsl_cmat_description desc = nir_intrinsic_cmat_desc(instr);
|
|
|
|
|
const struct glsl_type *t = glsl_cmat_type(&desc);
|
|
|
|
|
fprintf(fp, "%s", glsl_get_type_name(t));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NIR_INTRINSIC_CMAT_SIGNED_MASK: {
|
|
|
|
|
fprintf(fp, "cmat_signed=");
|
|
|
|
|
unsigned int mask = nir_intrinsic_cmat_signed_mask(instr);
|
|
|
|
|
if (mask == 0)
|
|
|
|
|
fputc('0', fp);
|
|
|
|
|
while (mask) {
|
|
|
|
|
nir_cmat_signed i = 1u << u_bit_scan(&mask);
|
|
|
|
|
switch (i) {
|
|
|
|
|
case NIR_CMAT_A_SIGNED:
|
|
|
|
|
fputc('A', fp);
|
|
|
|
|
break;
|
|
|
|
|
case NIR_CMAT_B_SIGNED:
|
|
|
|
|
fputc('B', fp);
|
|
|
|
|
break;
|
|
|
|
|
case NIR_CMAT_C_SIGNED:
|
|
|
|
|
fputc('C', fp);
|
|
|
|
|
break;
|
|
|
|
|
case NIR_CMAT_RESULT_SIGNED:
|
|
|
|
|
fprintf(fp, "Result");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
fprintf(fp, "unknown");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
fprintf(fp, "%s", mask ? "|" : "");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NIR_INTRINSIC_ALU_OP: {
|
|
|
|
|
nir_op alu_op = nir_intrinsic_alu_op(instr);
|
|
|
|
|
fprintf(fp, "alu_op=%s", nir_op_infos[alu_op].name);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-07 11:07:04 -08:00
|
|
|
default: {
|
2016-01-13 18:43:14 -05:00
|
|
|
unsigned off = info->index_map[idx] - 1;
|
2021-10-19 11:27:40 +02:00
|
|
|
fprintf(fp, "%s=%d", nir_intrinsic_index_names[idx], instr->const_index[off]);
|
2019-03-07 11:07:04 -08:00
|
|
|
break;
|
|
|
|
|
}
|
2016-01-13 18:43:14 -05:00
|
|
|
}
|
|
|
|
|
}
|
2024-03-03 17:44:27 -04:00
|
|
|
if (info->num_indices)
|
|
|
|
|
fprintf(fp, ")");
|
2016-01-13 18:43:14 -05:00
|
|
|
|
2015-09-17 18:18:45 -04:00
|
|
|
if (!state->shader)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-07-20 16:30:37 -05:00
|
|
|
nir_variable_mode var_mode;
|
2015-09-17 18:18:45 -04:00
|
|
|
switch (instr->intrinsic) {
|
|
|
|
|
case nir_intrinsic_load_uniform:
|
2020-07-20 16:30:37 -05:00
|
|
|
var_mode = nir_var_uniform;
|
2015-09-17 18:18:45 -04:00
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_load_input:
|
2024-07-06 04:24:31 -04:00
|
|
|
case nir_intrinsic_load_per_primitive_input:
|
2019-03-27 11:29:56 -04:00
|
|
|
case nir_intrinsic_load_interpolated_input:
|
2015-10-01 00:46:19 -07:00
|
|
|
case nir_intrinsic_load_per_vertex_input:
|
2020-07-20 16:30:37 -05:00
|
|
|
var_mode = nir_var_shader_in;
|
2015-09-17 18:18:45 -04:00
|
|
|
break;
|
2015-10-19 11:44:28 -07:00
|
|
|
case nir_intrinsic_load_output:
|
2015-09-17 18:18:45 -04:00
|
|
|
case nir_intrinsic_store_output:
|
2015-10-02 00:11:01 -07:00
|
|
|
case nir_intrinsic_store_per_vertex_output:
|
2020-07-20 16:30:37 -05:00
|
|
|
var_mode = nir_var_shader_out;
|
2015-09-17 18:18:45 -04:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-18 10:55:37 -04:00
|
|
|
if (instr->name) {
|
|
|
|
|
fprintf(fp, " // %s", instr->name);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 16:30:37 -05:00
|
|
|
nir_foreach_variable_with_modes(var, state->shader, var_mode) {
|
2024-04-03 12:26:20 -04:00
|
|
|
if (!var->name)
|
|
|
|
|
continue;
|
2024-04-23 10:09:02 +02:00
|
|
|
|
|
|
|
|
bool match;
|
|
|
|
|
if (instr->intrinsic == nir_intrinsic_load_uniform) {
|
|
|
|
|
match = var->data.driver_location == nir_intrinsic_base(instr);
|
|
|
|
|
} else {
|
|
|
|
|
match = nir_intrinsic_component(instr) >= var->data.location_frac &&
|
|
|
|
|
nir_intrinsic_component(instr) <
|
|
|
|
|
(var->data.location_frac + glsl_get_components(var->type));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (match) {
|
2023-06-09 14:43:38 -07:00
|
|
|
fprintf(fp, " // %s", var->name);
|
2015-09-17 18:18:45 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_tex_instr(nir_tex_instr *instr, print_state *state)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2023-08-14 11:56:00 -05:00
|
|
|
print_def(&instr->def, state);
|
2014-07-30 15:29:27 -07:00
|
|
|
|
2020-06-11 09:43:11 -07:00
|
|
|
fprintf(fp, " = (");
|
|
|
|
|
print_alu_type(instr->dest_type, state);
|
|
|
|
|
fprintf(fp, ")");
|
2014-07-30 15:29:27 -07:00
|
|
|
|
|
|
|
|
switch (instr->op) {
|
|
|
|
|
case nir_texop_tex:
|
|
|
|
|
fprintf(fp, "tex ");
|
|
|
|
|
break;
|
|
|
|
|
case nir_texop_txb:
|
|
|
|
|
fprintf(fp, "txb ");
|
|
|
|
|
break;
|
|
|
|
|
case nir_texop_txl:
|
|
|
|
|
fprintf(fp, "txl ");
|
|
|
|
|
break;
|
|
|
|
|
case nir_texop_txd:
|
|
|
|
|
fprintf(fp, "txd ");
|
|
|
|
|
break;
|
|
|
|
|
case nir_texop_txf:
|
|
|
|
|
fprintf(fp, "txf ");
|
|
|
|
|
break;
|
|
|
|
|
case nir_texop_txf_ms:
|
|
|
|
|
fprintf(fp, "txf_ms ");
|
|
|
|
|
break;
|
2019-04-26 10:05:08 -07:00
|
|
|
case nir_texop_txf_ms_fb:
|
|
|
|
|
fprintf(fp, "txf_ms_fb ");
|
|
|
|
|
break;
|
2021-07-07 17:06:46 -05:00
|
|
|
case nir_texop_txf_ms_mcs_intel:
|
|
|
|
|
fprintf(fp, "txf_ms_mcs_intel ");
|
2016-05-02 17:28:38 -07:00
|
|
|
break;
|
2014-07-30 15:29:27 -07:00
|
|
|
case nir_texop_txs:
|
|
|
|
|
fprintf(fp, "txs ");
|
|
|
|
|
break;
|
|
|
|
|
case nir_texop_lod:
|
|
|
|
|
fprintf(fp, "lod ");
|
|
|
|
|
break;
|
|
|
|
|
case nir_texop_tg4:
|
|
|
|
|
fprintf(fp, "tg4 ");
|
|
|
|
|
break;
|
|
|
|
|
case nir_texop_query_levels:
|
|
|
|
|
fprintf(fp, "query_levels ");
|
|
|
|
|
break;
|
2015-08-27 23:05:03 -04:00
|
|
|
case nir_texop_texture_samples:
|
|
|
|
|
fprintf(fp, "texture_samples ");
|
|
|
|
|
break;
|
2015-11-17 17:09:09 -08:00
|
|
|
case nir_texop_samples_identical:
|
|
|
|
|
fprintf(fp, "samples_identical ");
|
|
|
|
|
break;
|
2019-07-10 09:48:21 +02:00
|
|
|
case nir_texop_tex_prefetch:
|
|
|
|
|
fprintf(fp, "tex (pre-dispatchable) ");
|
|
|
|
|
break;
|
2021-08-05 16:19:51 +01:00
|
|
|
case nir_texop_fragment_fetch_amd:
|
|
|
|
|
fprintf(fp, "fragment_fetch_amd ");
|
2020-01-07 08:39:39 +01:00
|
|
|
break;
|
2021-08-05 16:19:51 +01:00
|
|
|
case nir_texop_fragment_mask_fetch_amd:
|
|
|
|
|
fprintf(fp, "fragment_mask_fetch_amd ");
|
2020-01-07 08:39:39 +01:00
|
|
|
break;
|
2022-08-05 16:34:09 +01:00
|
|
|
case nir_texop_descriptor_amd:
|
|
|
|
|
fprintf(fp, "descriptor_amd ");
|
|
|
|
|
break;
|
2022-10-28 08:32:02 -04:00
|
|
|
case nir_texop_sampler_descriptor_amd:
|
|
|
|
|
fprintf(fp, "sampler_descriptor_amd ");
|
|
|
|
|
break;
|
2023-02-12 20:19:41 -05:00
|
|
|
case nir_texop_lod_bias_agx:
|
|
|
|
|
fprintf(fp, "lod_bias_agx ");
|
|
|
|
|
break;
|
2024-04-27 11:34:19 -04:00
|
|
|
case nir_texop_has_custom_border_color_agx:
|
|
|
|
|
fprintf(fp, "has_custom_border_color_agx ");
|
|
|
|
|
break;
|
|
|
|
|
case nir_texop_custom_border_color_agx:
|
|
|
|
|
fprintf(fp, "custom_border_color_agx ");
|
|
|
|
|
break;
|
2023-04-10 17:23:32 -05:00
|
|
|
case nir_texop_hdr_dim_nv:
|
|
|
|
|
fprintf(fp, "hdr_dim_nv ");
|
|
|
|
|
break;
|
|
|
|
|
case nir_texop_tex_type_nv:
|
|
|
|
|
fprintf(fp, "tex_type_nv ");
|
|
|
|
|
break;
|
2014-07-30 15:29:27 -07:00
|
|
|
default:
|
|
|
|
|
unreachable("Invalid texture operation");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-29 23:08:05 -07:00
|
|
|
bool has_texture_deref = false, has_sampler_deref = false;
|
2014-07-30 15:29:27 -07:00
|
|
|
for (unsigned i = 0; i < instr->num_srcs; i++) {
|
2019-05-02 14:48:41 -07:00
|
|
|
if (i > 0) {
|
2019-04-28 08:06:12 -07:00
|
|
|
fprintf(fp, ", ");
|
|
|
|
|
}
|
2014-07-30 15:29:27 -07:00
|
|
|
|
2023-06-12 21:59:34 -07:00
|
|
|
print_src(&instr->src[i].src, state, nir_tex_instr_src_type(instr, i));
|
2019-05-02 14:48:41 -07:00
|
|
|
fprintf(fp, " ");
|
|
|
|
|
|
2023-08-08 12:00:35 -05:00
|
|
|
switch (instr->src[i].src_type) {
|
2021-07-14 16:41:58 -07:00
|
|
|
case nir_tex_src_backend1:
|
|
|
|
|
fprintf(fp, "(backend1)");
|
|
|
|
|
break;
|
|
|
|
|
case nir_tex_src_backend2:
|
|
|
|
|
fprintf(fp, "(backend2)");
|
|
|
|
|
break;
|
2014-07-30 15:29:27 -07:00
|
|
|
case nir_tex_src_coord:
|
|
|
|
|
fprintf(fp, "(coord)");
|
|
|
|
|
break;
|
|
|
|
|
case nir_tex_src_projector:
|
|
|
|
|
fprintf(fp, "(projector)");
|
|
|
|
|
break;
|
2016-12-12 08:32:38 -05:00
|
|
|
case nir_tex_src_comparator:
|
|
|
|
|
fprintf(fp, "(comparator)");
|
2014-07-30 15:29:27 -07:00
|
|
|
break;
|
|
|
|
|
case nir_tex_src_offset:
|
|
|
|
|
fprintf(fp, "(offset)");
|
|
|
|
|
break;
|
|
|
|
|
case nir_tex_src_bias:
|
|
|
|
|
fprintf(fp, "(bias)");
|
|
|
|
|
break;
|
|
|
|
|
case nir_tex_src_lod:
|
|
|
|
|
fprintf(fp, "(lod)");
|
|
|
|
|
break;
|
2018-10-02 21:15:47 -05:00
|
|
|
case nir_tex_src_min_lod:
|
|
|
|
|
fprintf(fp, "(min_lod)");
|
|
|
|
|
break;
|
2014-07-30 15:29:27 -07:00
|
|
|
case nir_tex_src_ms_index:
|
|
|
|
|
fprintf(fp, "(ms_index)");
|
|
|
|
|
break;
|
2021-07-07 17:06:46 -05:00
|
|
|
case nir_tex_src_ms_mcs_intel:
|
|
|
|
|
fprintf(fp, "(ms_mcs_intel)");
|
2016-05-02 17:28:38 -07:00
|
|
|
break;
|
2014-07-30 15:29:27 -07:00
|
|
|
case nir_tex_src_ddx:
|
|
|
|
|
fprintf(fp, "(ddx)");
|
|
|
|
|
break;
|
|
|
|
|
case nir_tex_src_ddy:
|
|
|
|
|
fprintf(fp, "(ddy)");
|
|
|
|
|
break;
|
2024-07-23 13:04:10 +10:00
|
|
|
case nir_tex_src_sampler_deref_intrinsic:
|
|
|
|
|
has_texture_deref = true;
|
|
|
|
|
fprintf(fp, "(sampler_deref_intrinsic)");
|
|
|
|
|
break;
|
|
|
|
|
case nir_tex_src_texture_deref_intrinsic:
|
|
|
|
|
has_texture_deref = true;
|
|
|
|
|
fprintf(fp, "(texture_deref_intrinsic)");
|
|
|
|
|
break;
|
2018-03-19 10:24:59 -07:00
|
|
|
case nir_tex_src_texture_deref:
|
2018-06-29 23:08:05 -07:00
|
|
|
has_texture_deref = true;
|
2018-03-19 10:24:59 -07:00
|
|
|
fprintf(fp, "(texture_deref)");
|
|
|
|
|
break;
|
|
|
|
|
case nir_tex_src_sampler_deref:
|
2018-06-29 23:08:05 -07:00
|
|
|
has_sampler_deref = true;
|
2018-03-19 10:24:59 -07:00
|
|
|
fprintf(fp, "(sampler_deref)");
|
|
|
|
|
break;
|
2016-02-06 09:05:10 -08:00
|
|
|
case nir_tex_src_texture_offset:
|
|
|
|
|
fprintf(fp, "(texture_offset)");
|
2014-07-30 15:29:27 -07:00
|
|
|
break;
|
2015-11-02 17:58:29 -08:00
|
|
|
case nir_tex_src_sampler_offset:
|
|
|
|
|
fprintf(fp, "(sampler_offset)");
|
|
|
|
|
break;
|
2018-10-28 07:52:44 -05:00
|
|
|
case nir_tex_src_texture_handle:
|
|
|
|
|
fprintf(fp, "(texture_handle)");
|
|
|
|
|
break;
|
|
|
|
|
case nir_tex_src_sampler_handle:
|
|
|
|
|
fprintf(fp, "(sampler_handle)");
|
|
|
|
|
break;
|
2016-05-01 21:12:48 -07:00
|
|
|
case nir_tex_src_plane:
|
|
|
|
|
fprintf(fp, "(plane)");
|
|
|
|
|
break;
|
2014-07-30 15:29:27 -07:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
unreachable("Invalid texture source type");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 14:13:35 +01:00
|
|
|
if (instr->is_gather_implicit_lod)
|
|
|
|
|
fprintf(fp, ", implicit lod");
|
|
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
if (instr->op == nir_texop_tg4) {
|
2019-05-02 14:48:41 -07:00
|
|
|
fprintf(fp, ", %u (gather_component)", instr->component);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
2018-06-29 23:08:05 -07:00
|
|
|
|
2019-03-18 21:23:59 +01:00
|
|
|
if (nir_tex_instr_has_explicit_tg4_offsets(instr)) {
|
2019-04-28 08:06:12 -07:00
|
|
|
fprintf(fp, ", { (%i, %i)", instr->tg4_offsets[0][0], instr->tg4_offsets[0][1]);
|
2019-03-18 21:23:59 +01:00
|
|
|
for (unsigned i = 1; i < 4; ++i)
|
|
|
|
|
fprintf(fp, ", (%i, %i)", instr->tg4_offsets[i][0],
|
|
|
|
|
instr->tg4_offsets[i][1]);
|
2019-04-28 08:06:12 -07:00
|
|
|
fprintf(fp, " } (offsets)");
|
2019-03-18 21:23:59 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-30 14:08:38 -04:00
|
|
|
if (instr->op != nir_texop_txf_ms_fb && !has_texture_deref) {
|
|
|
|
|
fprintf(fp, ", %u (texture)", instr->texture_index);
|
|
|
|
|
}
|
2018-06-29 23:08:05 -07:00
|
|
|
|
2023-03-30 14:08:38 -04:00
|
|
|
if (nir_tex_instr_need_sampler(instr) && !has_sampler_deref) {
|
|
|
|
|
fprintf(fp, ", %u (sampler)", instr->sampler_index);
|
2018-06-29 23:08:05 -07:00
|
|
|
}
|
2020-01-01 14:47:14 +01:00
|
|
|
|
|
|
|
|
if (instr->texture_non_uniform) {
|
|
|
|
|
fprintf(fp, ", texture non-uniform");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instr->sampler_non_uniform) {
|
|
|
|
|
fprintf(fp, ", sampler non-uniform");
|
|
|
|
|
}
|
2020-11-20 15:10:42 +00:00
|
|
|
|
|
|
|
|
if (instr->is_sparse) {
|
|
|
|
|
fprintf(fp, ", sparse");
|
|
|
|
|
}
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_call_instr(nir_call_instr *instr, print_state *state)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2023-06-09 14:05:58 -07:00
|
|
|
print_no_dest_padding(state);
|
|
|
|
|
|
2015-12-26 10:00:47 -08:00
|
|
|
fprintf(fp, "call %s ", instr->callee->name);
|
2014-07-30 15:29:27 -07:00
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < instr->num_params; i++) {
|
|
|
|
|
if (i != 0)
|
|
|
|
|
fprintf(fp, ", ");
|
|
|
|
|
|
2023-06-12 21:59:34 -07:00
|
|
|
print_src(&instr->params[i], state, nir_type_invalid);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_jump_instr(nir_jump_instr *instr, print_state *state)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2023-06-09 14:05:58 -07:00
|
|
|
print_no_dest_padding(state);
|
|
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
switch (instr->type) {
|
|
|
|
|
case nir_jump_break:
|
|
|
|
|
fprintf(fp, "break");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case nir_jump_continue:
|
|
|
|
|
fprintf(fp, "continue");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case nir_jump_return:
|
|
|
|
|
fprintf(fp, "return");
|
|
|
|
|
break;
|
2020-07-02 14:32:04 +02:00
|
|
|
|
2020-05-15 15:46:08 -05:00
|
|
|
case nir_jump_halt:
|
|
|
|
|
fprintf(fp, "halt");
|
|
|
|
|
break;
|
|
|
|
|
|
2020-07-02 14:32:04 +02:00
|
|
|
case nir_jump_goto:
|
2023-06-09 11:53:50 -07:00
|
|
|
fprintf(fp, "goto b%u",
|
2020-07-02 14:32:04 +02:00
|
|
|
instr->target ? instr->target->index : -1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case nir_jump_goto_if:
|
2023-06-09 11:53:50 -07:00
|
|
|
fprintf(fp, "goto b%u if ",
|
2020-07-02 14:32:04 +02:00
|
|
|
instr->target ? instr->target->index : -1);
|
2023-06-12 21:59:34 -07:00
|
|
|
print_src(&instr->condition, state, nir_type_invalid);
|
2023-06-09 11:53:50 -07:00
|
|
|
fprintf(fp, " else b%u",
|
2020-07-02 14:32:04 +02:00
|
|
|
instr->else_target ? instr->else_target->index : -1);
|
|
|
|
|
break;
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-08-12 16:17:15 -04:00
|
|
|
print_ssa_undef_instr(nir_undef_instr *instr, print_state *state)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
2023-08-14 11:50:22 -05:00
|
|
|
print_def(&instr->def, state);
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, " = undefined");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_phi_instr(nir_phi_instr *instr, print_state *state)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
2023-08-14 11:56:00 -05:00
|
|
|
print_def(&instr->def, state);
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, " = phi ");
|
2016-04-26 20:16:21 -07:00
|
|
|
nir_foreach_phi_src(src, instr) {
|
2014-12-18 14:01:37 -08:00
|
|
|
if (&src->node != exec_list_get_head(&instr->srcs))
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, ", ");
|
|
|
|
|
|
2023-06-09 11:53:50 -07:00
|
|
|
fprintf(fp, "b%u: ", src->pred->index);
|
2023-06-12 21:59:34 -07:00
|
|
|
print_src(&src->src, state, nir_type_invalid);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-30 21:04:15 -07:00
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_parallel_copy_instr(nir_parallel_copy_instr *instr, print_state *state)
|
2014-10-30 21:04:15 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
2016-04-26 20:21:27 -07:00
|
|
|
nir_foreach_parallel_copy_entry(entry, instr) {
|
2014-12-18 14:01:37 -08:00
|
|
|
if (&entry->node != exec_list_get_head(&instr->entries))
|
2014-10-30 21:04:15 -07:00
|
|
|
fprintf(fp, "; ");
|
|
|
|
|
|
2023-06-09 09:36:22 -04:00
|
|
|
if (entry->dest_is_reg) {
|
|
|
|
|
fprintf(fp, "*");
|
|
|
|
|
print_src(&entry->dest.reg, state, nir_type_invalid);
|
|
|
|
|
} else {
|
2023-08-14 11:56:00 -05:00
|
|
|
print_def(&entry->dest.def, state);
|
2023-06-09 09:36:22 -04:00
|
|
|
}
|
2014-10-30 21:04:15 -07:00
|
|
|
fprintf(fp, " = ");
|
2023-06-09 09:36:22 -04:00
|
|
|
|
|
|
|
|
if (entry->src_is_reg)
|
|
|
|
|
fprintf(fp, "*");
|
2023-06-12 21:59:34 -07:00
|
|
|
print_src(&entry->src, state, nir_type_invalid);
|
2014-10-30 21:04:15 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_instr(const nir_instr *instr, print_state *state, unsigned tabs)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
2023-06-09 14:25:04 -07:00
|
|
|
print_indentation(tabs, fp);
|
2014-07-30 15:29:27 -07:00
|
|
|
|
|
|
|
|
switch (instr->type) {
|
|
|
|
|
case nir_instr_type_alu:
|
2015-09-15 18:50:41 -04:00
|
|
|
print_alu_instr(nir_instr_as_alu(instr), state);
|
2014-07-30 15:29:27 -07:00
|
|
|
break;
|
|
|
|
|
|
2018-03-14 21:45:38 -07:00
|
|
|
case nir_instr_type_deref:
|
|
|
|
|
print_deref_instr(nir_instr_as_deref(instr), state);
|
|
|
|
|
break;
|
|
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
case nir_instr_type_call:
|
2015-09-15 18:50:41 -04:00
|
|
|
print_call_instr(nir_instr_as_call(instr), state);
|
2014-07-30 15:29:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case nir_instr_type_intrinsic:
|
2015-09-15 18:50:41 -04:00
|
|
|
print_intrinsic_instr(nir_instr_as_intrinsic(instr), state);
|
2014-07-30 15:29:27 -07:00
|
|
|
break;
|
|
|
|
|
|
2014-12-05 11:03:06 -08:00
|
|
|
case nir_instr_type_tex:
|
2015-09-15 18:50:41 -04:00
|
|
|
print_tex_instr(nir_instr_as_tex(instr), state);
|
2014-07-30 15:29:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case nir_instr_type_load_const:
|
2015-09-15 18:50:41 -04:00
|
|
|
print_load_const_instr(nir_instr_as_load_const(instr), state);
|
2014-07-30 15:29:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case nir_instr_type_jump:
|
2015-09-15 18:50:41 -04:00
|
|
|
print_jump_instr(nir_instr_as_jump(instr), state);
|
2014-07-30 15:29:27 -07:00
|
|
|
break;
|
|
|
|
|
|
2023-08-15 09:59:06 -05:00
|
|
|
case nir_instr_type_undef:
|
|
|
|
|
print_ssa_undef_instr(nir_instr_as_undef(instr), state);
|
2014-07-30 15:29:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case nir_instr_type_phi:
|
2015-09-15 18:50:41 -04:00
|
|
|
print_phi_instr(nir_instr_as_phi(instr), state);
|
2014-07-30 15:29:27 -07:00
|
|
|
break;
|
|
|
|
|
|
2014-10-30 21:04:15 -07:00
|
|
|
case nir_instr_type_parallel_copy:
|
2015-09-15 18:50:41 -04:00
|
|
|
print_parallel_copy_instr(nir_instr_as_parallel_copy(instr), state);
|
2014-10-30 21:04:15 -07:00
|
|
|
break;
|
|
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
default:
|
|
|
|
|
unreachable("Invalid instruction type");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-07-19 13:55:13 +02:00
|
|
|
|
|
|
|
|
if (NIR_DEBUG(PRINT_PASS_FLAGS) && instr->pass_flags)
|
|
|
|
|
fprintf(fp, " (pass_flags: 0x%x)", instr->pass_flags);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
2023-06-09 14:05:58 -07:00
|
|
|
static bool
|
|
|
|
|
block_has_instruction_with_dest(nir_block *block)
|
|
|
|
|
{
|
|
|
|
|
nir_foreach_instr(instr, block) {
|
|
|
|
|
switch (instr->type) {
|
|
|
|
|
case nir_instr_type_load_const:
|
|
|
|
|
case nir_instr_type_deref:
|
|
|
|
|
case nir_instr_type_alu:
|
|
|
|
|
case nir_instr_type_tex:
|
2023-08-15 09:59:06 -05:00
|
|
|
case nir_instr_type_undef:
|
2023-06-09 14:05:58 -07:00
|
|
|
case nir_instr_type_phi:
|
|
|
|
|
case nir_instr_type_parallel_copy:
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case nir_instr_type_intrinsic: {
|
|
|
|
|
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
|
|
|
|
|
const nir_intrinsic_info *info = &nir_intrinsic_infos[intrin->intrinsic];
|
|
|
|
|
if (info->has_dest)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
/* Doesn't define a new value. */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case nir_instr_type_jump:
|
|
|
|
|
case nir_instr_type_call:
|
|
|
|
|
/* Doesn't define a new value. */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-15 18:50:41 -04:00
|
|
|
static void print_cf_node(nir_cf_node *node, print_state *state,
|
|
|
|
|
unsigned tabs);
|
2014-07-30 15:29:27 -07:00
|
|
|
|
2023-06-13 00:10:27 -07:00
|
|
|
static void
|
|
|
|
|
print_block_preds(nir_block *block, print_state *state)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
nir_block **preds = nir_block_get_predecessors_sorted(block, NULL);
|
|
|
|
|
for (unsigned i = 0; i < block->predecessors->entries; i++) {
|
|
|
|
|
if (i != 0)
|
|
|
|
|
fprintf(fp, " ");
|
|
|
|
|
fprintf(fp, "b%u", preds[i]->index);
|
|
|
|
|
}
|
|
|
|
|
ralloc_free(preds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
print_block_succs(nir_block *block, print_state *state)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
if (block->successors[i]) {
|
|
|
|
|
fprintf(fp, "b%u ", block->successors[i]->index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_block(nir_block *block, print_state *state, unsigned tabs)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2023-06-09 14:05:58 -07:00
|
|
|
if (block_has_instruction_with_dest(block))
|
|
|
|
|
state->padding_for_no_dest = calculate_padding_for_no_dest(state);
|
|
|
|
|
else
|
|
|
|
|
state->padding_for_no_dest = 0;
|
|
|
|
|
|
2023-06-09 14:25:04 -07:00
|
|
|
print_indentation(tabs, fp);
|
2024-06-04 13:54:44 -05:00
|
|
|
fprintf(fp, "%sblock b%u:",
|
|
|
|
|
divergence_status(state, block->divergent),
|
|
|
|
|
block->index);
|
2023-06-13 00:10:27 -07:00
|
|
|
|
|
|
|
|
const bool empty_block = exec_list_is_empty(&block->instr_list);
|
|
|
|
|
if (empty_block) {
|
|
|
|
|
fprintf(fp, " // preds: ");
|
|
|
|
|
print_block_preds(block, state);
|
|
|
|
|
fprintf(fp, ", succs: ");
|
|
|
|
|
print_block_succs(block, state);
|
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-07-30 15:29:27 -07:00
|
|
|
|
2023-06-13 00:10:27 -07:00
|
|
|
const unsigned block_length = 7 + count_digits(block->index) + 1;
|
2023-08-08 12:00:35 -05:00
|
|
|
const unsigned pred_padding = block_length < state->padding_for_no_dest ? state->padding_for_no_dest - block_length : 0;
|
2014-07-30 15:29:27 -07:00
|
|
|
|
2023-06-13 00:10:27 -07:00
|
|
|
fprintf(fp, "%*s// preds: ", pred_padding, "");
|
|
|
|
|
print_block_preds(block, state);
|
2023-06-09 14:43:38 -07:00
|
|
|
fprintf(fp, "\n");
|
2014-07-30 15:29:27 -07:00
|
|
|
|
2016-04-26 18:34:19 -07:00
|
|
|
nir_foreach_instr(instr, block) {
|
2015-09-15 18:50:41 -04:00
|
|
|
print_instr(instr, state, tabs);
|
2014-11-05 15:10:37 -08:00
|
|
|
fprintf(fp, "\n");
|
2016-05-14 15:37:32 -04:00
|
|
|
print_annotation(state, instr);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
2023-06-09 14:25:04 -07:00
|
|
|
print_indentation(tabs, fp);
|
2023-06-13 00:10:27 -07:00
|
|
|
fprintf(fp, "%*s// succs: ", state->padding_for_no_dest, "");
|
|
|
|
|
print_block_succs(block, state);
|
2023-06-09 14:43:38 -07:00
|
|
|
fprintf(fp, "\n");
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_if(nir_if *if_stmt, print_state *state, unsigned tabs)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2023-06-09 14:25:04 -07:00
|
|
|
print_indentation(tabs, fp);
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, "if ");
|
2023-06-12 21:59:34 -07:00
|
|
|
print_src(&if_stmt->condition, state, nir_type_invalid);
|
2022-08-29 17:18:56 +02:00
|
|
|
switch (if_stmt->control) {
|
|
|
|
|
case nir_selection_control_flatten:
|
2023-06-09 14:43:38 -07:00
|
|
|
fprintf(fp, " // flatten");
|
2022-08-29 17:18:56 +02:00
|
|
|
break;
|
|
|
|
|
case nir_selection_control_dont_flatten:
|
2023-06-09 14:43:38 -07:00
|
|
|
fprintf(fp, " // don't flatten");
|
2022-08-29 17:18:56 +02:00
|
|
|
break;
|
2022-10-10 10:44:35 +02:00
|
|
|
case nir_selection_control_divergent_always_taken:
|
2023-06-09 14:43:38 -07:00
|
|
|
fprintf(fp, " // divergent always taken");
|
2022-10-10 10:44:35 +02:00
|
|
|
break;
|
2022-08-29 17:18:56 +02:00
|
|
|
case nir_selection_control_none:
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, " {\n");
|
|
|
|
|
foreach_list_typed(nir_cf_node, node, node, &if_stmt->then_list) {
|
2015-09-15 18:50:41 -04:00
|
|
|
print_cf_node(node, state, tabs + 1);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
2023-06-09 14:25:04 -07:00
|
|
|
print_indentation(tabs, fp);
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, "} else {\n");
|
|
|
|
|
foreach_list_typed(nir_cf_node, node, node, &if_stmt->else_list) {
|
2015-09-15 18:50:41 -04:00
|
|
|
print_cf_node(node, state, tabs + 1);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
2023-06-09 14:25:04 -07:00
|
|
|
print_indentation(tabs, fp);
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, "}\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_loop(nir_loop *loop, print_state *state, unsigned tabs)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2023-06-09 14:25:04 -07:00
|
|
|
print_indentation(tabs, fp);
|
2024-06-04 13:54:44 -05:00
|
|
|
fprintf(fp, "%sloop {\n", divergence_status(state, loop->divergent));
|
2014-07-30 15:29:27 -07:00
|
|
|
foreach_list_typed(nir_cf_node, node, node, &loop->body) {
|
2015-09-15 18:50:41 -04:00
|
|
|
print_cf_node(node, state, tabs + 1);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
2023-06-09 14:25:04 -07:00
|
|
|
print_indentation(tabs, fp);
|
2021-12-01 17:34:48 +01:00
|
|
|
|
|
|
|
|
if (nir_loop_has_continue_construct(loop)) {
|
|
|
|
|
fprintf(fp, "} continue {\n");
|
|
|
|
|
foreach_list_typed(nir_cf_node, node, node, &loop->continue_list) {
|
|
|
|
|
print_cf_node(node, state, tabs + 1);
|
|
|
|
|
}
|
2023-06-09 14:25:04 -07:00
|
|
|
print_indentation(tabs, fp);
|
2021-12-01 17:34:48 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-30 15:29:27 -07:00
|
|
|
fprintf(fp, "}\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_cf_node(nir_cf_node *node, print_state *state, unsigned int tabs)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
|
|
|
|
switch (node->type) {
|
|
|
|
|
case nir_cf_node_block:
|
2015-09-15 18:50:41 -04:00
|
|
|
print_block(nir_cf_node_as_block(node), state, tabs);
|
2014-07-30 15:29:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case nir_cf_node_if:
|
2015-09-15 18:50:41 -04:00
|
|
|
print_if(nir_cf_node_as_if(node), state, tabs);
|
2014-07-30 15:29:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case nir_cf_node_loop:
|
2015-09-15 18:50:41 -04:00
|
|
|
print_loop(nir_cf_node_as_loop(node), state, tabs);
|
2014-07-30 15:29:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
unreachable("Invalid CFG node type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
print_function_impl(nir_function_impl *impl, print_state *state)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2023-08-01 10:53:43 -04:00
|
|
|
state->max_dest_index = impl->ssa_alloc;
|
2023-06-09 14:05:58 -07:00
|
|
|
|
2015-12-26 10:00:47 -08:00
|
|
|
fprintf(fp, "\nimpl %s ", impl->function->name);
|
2014-07-30 15:29:27 -07:00
|
|
|
|
|
|
|
|
fprintf(fp, "{\n");
|
|
|
|
|
|
2021-09-24 18:12:24 +02:00
|
|
|
if (impl->preamble) {
|
2023-06-09 14:25:04 -07:00
|
|
|
print_indentation(1, fp);
|
|
|
|
|
fprintf(fp, "preamble %s\n", impl->preamble->name);
|
2021-09-24 18:12:24 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-09 19:55:49 -07:00
|
|
|
if (!NIR_DEBUG(PRINT_NO_INLINE_CONSTS)) {
|
2023-08-12 16:17:15 -04:00
|
|
|
/* Don't reindex the SSA as suggested by nir_gather_types() because
|
nir/print: Improve NIR_PRINT=print_consts by using nir_gather_ssa_types()
The two representations are *always* used for `load_const`, but when
inlining the value as SSA source, use just a single terse
representation.
The choice between integer or float is based on the result of
nir_gather_ssa_types(), with a bias for integer when in doubt.
Also remove extra comment `/* */` syntax since the value is already
enclosed by parenthesis.
---
For illustration, here's some instructions from crucible test
func.shader.averageRounded.uint64_t with NIR_DEBUG=print_consts:
BEFORE:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 /*(0xfffffffc = -nan)*/
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 /*(0x00000002 = 0.000000)*/, ssa_25 /*(0x00000024 = 0.000000)*/) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 /*(0x00000002 = 0.000000)*/
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 /*(0x00000007 = 0.000000)*/
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 /*(0x7b000808 = 664776890994587263929995856502063104.000000)*/, ssa_30
```
AFTER:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 (0xfffffffc)
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 (0x2), ssa_25 (0x24)) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 (0x2)
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 (0x7)
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 (0x7b000808), ssa_30
```
and some instructions from crucible test func.gs.basic with NIR_DEBUG=print_consts,
now showing float representation being selected:
BEFORE:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 /*(0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)*/
```
AFTER:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 (0.200000, 0.200000, 0.000000, 0.000000)
```
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23562>
2023-06-09 17:40:58 -07:00
|
|
|
* nir_print don't modify the shader. If needed, a limit for ssa_alloc
|
|
|
|
|
* can be added.
|
|
|
|
|
*/
|
|
|
|
|
state->float_types = calloc(BITSET_WORDS(impl->ssa_alloc), sizeof(BITSET_WORD));
|
|
|
|
|
state->int_types = calloc(BITSET_WORDS(impl->ssa_alloc), sizeof(BITSET_WORD));
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_gather_types(impl, state->float_types, state->int_types);
|
nir/print: Improve NIR_PRINT=print_consts by using nir_gather_ssa_types()
The two representations are *always* used for `load_const`, but when
inlining the value as SSA source, use just a single terse
representation.
The choice between integer or float is based on the result of
nir_gather_ssa_types(), with a bias for integer when in doubt.
Also remove extra comment `/* */` syntax since the value is already
enclosed by parenthesis.
---
For illustration, here's some instructions from crucible test
func.shader.averageRounded.uint64_t with NIR_DEBUG=print_consts:
BEFORE:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 /*(0xfffffffc = -nan)*/
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 /*(0x00000002 = 0.000000)*/, ssa_25 /*(0x00000024 = 0.000000)*/) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 /*(0x00000002 = 0.000000)*/
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 /*(0x00000007 = 0.000000)*/
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 /*(0x7b000808 = 664776890994587263929995856502063104.000000)*/, ssa_30
```
AFTER:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 (0xfffffffc)
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 (0x2), ssa_25 (0x24)) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 (0x2)
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 (0x7)
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 (0x7b000808), ssa_30
```
and some instructions from crucible test func.gs.basic with NIR_DEBUG=print_consts,
now showing float representation being selected:
BEFORE:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 /*(0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)*/
```
AFTER:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 (0.200000, 0.200000, 0.000000, 0.000000)
```
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23562>
2023-06-09 17:40:58 -07:00
|
|
|
}
|
|
|
|
|
|
2020-05-20 10:18:14 -05:00
|
|
|
nir_foreach_function_temp_variable(var, impl) {
|
2023-06-09 14:25:04 -07:00
|
|
|
print_indentation(1, fp);
|
2015-09-15 18:50:41 -04:00
|
|
|
print_var_decl(var, state);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nir_index_blocks(impl);
|
|
|
|
|
|
|
|
|
|
foreach_list_typed(nir_cf_node, node, node, &impl->body) {
|
2015-09-15 18:50:41 -04:00
|
|
|
print_cf_node(node, state, 1);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
2023-06-09 14:25:04 -07:00
|
|
|
print_indentation(1, fp);
|
|
|
|
|
fprintf(fp, "block b%u:\n}\n\n", impl->end_block->index);
|
nir/print: Improve NIR_PRINT=print_consts by using nir_gather_ssa_types()
The two representations are *always* used for `load_const`, but when
inlining the value as SSA source, use just a single terse
representation.
The choice between integer or float is based on the result of
nir_gather_ssa_types(), with a bias for integer when in doubt.
Also remove extra comment `/* */` syntax since the value is already
enclosed by parenthesis.
---
For illustration, here's some instructions from crucible test
func.shader.averageRounded.uint64_t with NIR_DEBUG=print_consts:
BEFORE:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 /*(0xfffffffc = -nan)*/
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 /*(0x00000002 = 0.000000)*/, ssa_25 /*(0x00000024 = 0.000000)*/) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 /*(0x00000002 = 0.000000)*/
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 /*(0x00000007 = 0.000000)*/
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 /*(0x7b000808 = 664776890994587263929995856502063104.000000)*/, ssa_30
```
AFTER:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 (0xfffffffc)
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 (0x2), ssa_25 (0x24)) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 (0x2)
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 (0x7)
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 (0x7b000808), ssa_30
```
and some instructions from crucible test func.gs.basic with NIR_DEBUG=print_consts,
now showing float representation being selected:
BEFORE:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 /*(0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)*/
```
AFTER:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 (0.200000, 0.200000, 0.000000, 0.000000)
```
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23562>
2023-06-09 17:40:58 -07:00
|
|
|
|
|
|
|
|
free(state->float_types);
|
|
|
|
|
free(state->int_types);
|
2023-06-09 14:05:58 -07:00
|
|
|
state->max_dest_index = 0;
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-12-26 10:00:47 -08:00
|
|
|
print_function(nir_function *function, print_state *state)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
FILE *fp = state->fp;
|
|
|
|
|
|
2023-10-12 12:03:11 -04:00
|
|
|
/* clang-format off */
|
|
|
|
|
fprintf(fp, "decl_function %s (%d params)%s%s", function->name,
|
|
|
|
|
function->num_params,
|
|
|
|
|
function->dont_inline ? " (noinline)" :
|
|
|
|
|
function->should_inline ? " (inline)" : "",
|
|
|
|
|
function->is_exported ? " (exported)" : "");
|
|
|
|
|
/* clang-format on */
|
2014-07-30 15:29:27 -07:00
|
|
|
|
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
|
|
2015-12-26 10:00:47 -08:00
|
|
|
if (function->impl != NULL) {
|
|
|
|
|
print_function_impl(function->impl, state);
|
2014-07-30 15:29:27 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
init_print_state(print_state *state, nir_shader *shader, FILE *fp)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
state->fp = fp;
|
2015-09-15 18:55:48 -04:00
|
|
|
state->shader = shader;
|
2019-01-11 11:50:53 -08:00
|
|
|
state->ht = _mesa_pointer_hash_table_create(NULL);
|
2020-01-18 01:38:31 -05:00
|
|
|
state->syms = _mesa_set_create(NULL, _mesa_hash_string,
|
2015-01-15 09:31:18 -08:00
|
|
|
_mesa_key_string_equal);
|
2014-07-30 15:29:27 -07:00
|
|
|
state->index = 0;
|
nir/print: Improve NIR_PRINT=print_consts by using nir_gather_ssa_types()
The two representations are *always* used for `load_const`, but when
inlining the value as SSA source, use just a single terse
representation.
The choice between integer or float is based on the result of
nir_gather_ssa_types(), with a bias for integer when in doubt.
Also remove extra comment `/* */` syntax since the value is already
enclosed by parenthesis.
---
For illustration, here's some instructions from crucible test
func.shader.averageRounded.uint64_t with NIR_DEBUG=print_consts:
BEFORE:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 /*(0xfffffffc = -nan)*/
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 /*(0x00000002 = 0.000000)*/, ssa_25 /*(0x00000024 = 0.000000)*/) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 /*(0x00000002 = 0.000000)*/
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 /*(0x00000007 = 0.000000)*/
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 /*(0x7b000808 = 664776890994587263929995856502063104.000000)*/, ssa_30
```
AFTER:
```
vec1 32 con ssa_23 = load_const (0xfffffffc = -nan)
vec1 32 div ssa_24 = iand ssa_13, ssa_23 (0xfffffffc)
vec1 32 con ssa_25 = load_const (0x00000024 = 0.000000)
vec1 32 con ssa_26 = intrinsic load_ubo (ssa_1 (0x2), ssa_25 (0x24)) (access=0, align_mul=1073741824, align_offset=36, range_base=0, range=-1)
vec1 32 con ssa_27 = load_const (0x00000008 = 0.000000)
vec1 32 con ssa_28 = load_const (0x00000007 = 0.000000)
vec1 32 con ssa_29 = iand ssa_4.y, ssa_1 (0x2)
vec1 32 con ssa_30 = ishl ssa_29, ssa_28 (0x7)
vec1 32 con ssa_31 = load_const (0x7b000808 = 664776890994587263929995856502063104.000000)
vec1 32 con ssa_32 = ior ssa_31 (0x7b000808), ssa_30
```
and some instructions from crucible test func.gs.basic with NIR_DEBUG=print_consts,
now showing float representation being selected:
BEFORE:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 /*(0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)*/
```
AFTER:
```
vec4 32 ssa_10 = load_const (0x3e4ccccd, 0x3e4ccccd, 0x00000000, 0x00000000) = (0.200000, 0.200000, 0.000000, 0.000000)
vec4 32 ssa_9 = intrinsic load_deref (ssa_42) (access=0)
vec4 32 ssa_11 = fadd ssa_9, ssa_10 (0.200000, 0.200000, 0.000000, 0.000000)
```
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23562>
2023-06-09 17:40:58 -07:00
|
|
|
state->int_types = NULL;
|
|
|
|
|
state->float_types = NULL;
|
2023-06-09 14:05:58 -07:00
|
|
|
state->max_dest_index = 0;
|
|
|
|
|
state->padding_for_no_dest = 0;
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-09-15 18:50:41 -04:00
|
|
|
destroy_print_state(print_state *state)
|
2014-07-30 15:29:27 -07:00
|
|
|
{
|
|
|
|
|
_mesa_hash_table_destroy(state->ht, NULL);
|
|
|
|
|
_mesa_set_destroy(state->syms, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-17 10:54:44 +02:00
|
|
|
static const char *
|
|
|
|
|
primitive_name(unsigned primitive)
|
|
|
|
|
{
|
2023-08-08 12:00:35 -05:00
|
|
|
#define PRIM(X) \
|
|
|
|
|
case MESA_PRIM_##X: \
|
|
|
|
|
return #X
|
2020-06-17 10:54:44 +02:00
|
|
|
switch (primitive) {
|
2023-08-08 12:00:35 -05:00
|
|
|
PRIM(POINTS);
|
|
|
|
|
PRIM(LINES);
|
|
|
|
|
PRIM(LINE_LOOP);
|
|
|
|
|
PRIM(LINE_STRIP);
|
|
|
|
|
PRIM(TRIANGLES);
|
|
|
|
|
PRIM(TRIANGLE_STRIP);
|
|
|
|
|
PRIM(TRIANGLE_FAN);
|
|
|
|
|
PRIM(QUADS);
|
|
|
|
|
PRIM(QUAD_STRIP);
|
|
|
|
|
PRIM(POLYGON);
|
2023-10-22 19:28:45 -04:00
|
|
|
PRIM(LINES_ADJACENCY);
|
|
|
|
|
PRIM(TRIANGLES_ADJACENCY);
|
2020-06-17 10:54:44 +02:00
|
|
|
default:
|
|
|
|
|
return "UNKNOWN";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 12:07:36 +02:00
|
|
|
static void
|
2022-12-05 16:44:04 +02:00
|
|
|
print_bitset(FILE *fp, const char *label, const unsigned *words, int size)
|
|
|
|
|
{
|
2022-11-14 19:52:37 +02:00
|
|
|
fprintf(fp, "%s: ", label);
|
2022-12-05 16:44:04 +02:00
|
|
|
/* Iterate back-to-front to get proper digit order (most significant first). */
|
|
|
|
|
for (int i = size - 1; i >= 0; --i) {
|
|
|
|
|
fprintf(fp, (i == size - 1) ? "0x%08x" : "'%08x", words[i]);
|
2022-11-02 13:30:16 +02:00
|
|
|
}
|
2022-11-02 13:49:38 +02:00
|
|
|
fprintf(fp, "\n");
|
2022-11-02 13:30:16 +02:00
|
|
|
}
|
2020-06-17 10:54:44 +02:00
|
|
|
|
2022-11-14 19:52:37 +02:00
|
|
|
/* Print bitset, only if some bits are set */
|
|
|
|
|
static void
|
2022-12-05 16:44:04 +02:00
|
|
|
print_nz_bitset(FILE *fp, const char *label, const unsigned *words, int size)
|
|
|
|
|
{
|
2022-11-14 19:52:37 +02:00
|
|
|
bool is_all_zero = true;
|
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
|
if (words[i]) {
|
|
|
|
|
is_all_zero = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_all_zero)
|
|
|
|
|
print_bitset(fp, label, words, size);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 22:12:24 +02:00
|
|
|
/* Print uint64_t value, only if non-zero.
|
|
|
|
|
* The value is printed by enumerating the ranges of bits that are set.
|
|
|
|
|
* E.g. inputs_read: 0,15-17
|
|
|
|
|
*/
|
2022-11-14 19:52:37 +02:00
|
|
|
static void
|
2022-12-05 16:44:04 +02:00
|
|
|
print_nz_x64(FILE *fp, const char *label, uint64_t value)
|
|
|
|
|
{
|
2022-11-23 22:12:24 +02:00
|
|
|
if (value) {
|
2023-08-08 12:00:35 -05:00
|
|
|
char acc[256] = { 0 };
|
2022-11-23 22:12:24 +02:00
|
|
|
char buf[32];
|
|
|
|
|
int start = 0;
|
|
|
|
|
int count = 0;
|
|
|
|
|
while (value) {
|
|
|
|
|
u_bit_scan_consecutive_range64(&value, &start, &count);
|
|
|
|
|
assert(count > 0);
|
|
|
|
|
bool is_first = !acc[0];
|
|
|
|
|
if (count > 1) {
|
|
|
|
|
snprintf(buf, sizeof(buf), is_first ? "%d-%d" : ",%d-%d", start, start + count - 1);
|
|
|
|
|
} else {
|
|
|
|
|
snprintf(buf, sizeof(buf), is_first ? "%d" : ",%d", start);
|
|
|
|
|
}
|
|
|
|
|
assert(strlen(acc) + strlen(buf) + 1 < sizeof(acc));
|
|
|
|
|
strcat(acc, buf);
|
|
|
|
|
}
|
|
|
|
|
fprintf(fp, "%s: %s\n", label, acc);
|
|
|
|
|
}
|
2022-11-14 19:52:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print uint32_t value in hex, only if non-zero */
|
|
|
|
|
static void
|
2022-12-05 16:44:04 +02:00
|
|
|
print_nz_x32(FILE *fp, const char *label, uint32_t value)
|
|
|
|
|
{
|
2022-11-14 19:52:37 +02:00
|
|
|
if (value)
|
|
|
|
|
fprintf(fp, "%s: 0x%08" PRIx32 "\n", label, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print uint16_t value in hex, only if non-zero */
|
|
|
|
|
static void
|
2022-12-05 16:44:04 +02:00
|
|
|
print_nz_x16(FILE *fp, const char *label, uint16_t value)
|
|
|
|
|
{
|
2022-11-14 19:52:37 +02:00
|
|
|
if (value)
|
|
|
|
|
fprintf(fp, "%s: 0x%04x\n", label, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print uint8_t value in hex, only if non-zero */
|
|
|
|
|
static void
|
2022-12-05 16:44:04 +02:00
|
|
|
print_nz_x8(FILE *fp, const char *label, uint8_t value)
|
|
|
|
|
{
|
2022-11-14 19:52:37 +02:00
|
|
|
if (value)
|
|
|
|
|
fprintf(fp, "%s: 0x%02x\n", label, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print unsigned value in decimal, only if non-zero */
|
|
|
|
|
static void
|
2022-12-05 16:44:04 +02:00
|
|
|
print_nz_unsigned(FILE *fp, const char *label, unsigned value)
|
|
|
|
|
{
|
2022-11-14 19:52:37 +02:00
|
|
|
if (value)
|
|
|
|
|
fprintf(fp, "%s: %u\n", label, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print bool only if set */
|
|
|
|
|
static void
|
2022-12-05 16:44:04 +02:00
|
|
|
print_nz_bool(FILE *fp, const char *label, bool value)
|
|
|
|
|
{
|
2022-11-14 19:52:37 +02:00
|
|
|
if (value)
|
2022-11-30 11:45:07 +02:00
|
|
|
fprintf(fp, "%s: true\n", label);
|
2022-11-14 19:52:37 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-02 13:30:16 +02:00
|
|
|
static void
|
2022-12-05 16:44:04 +02:00
|
|
|
print_shader_info(const struct shader_info *info, FILE *fp)
|
|
|
|
|
{
|
2022-11-02 12:07:36 +02:00
|
|
|
fprintf(fp, "shader: %s\n", gl_shader_stage_name(info->stage));
|
2015-09-15 18:55:48 -04:00
|
|
|
|
2024-05-01 14:36:35 +05:30
|
|
|
fprintf(fp, "source_blake3: {");
|
|
|
|
|
_mesa_blake3_print(fp, info->source_blake3);
|
2021-11-18 09:28:17 -05:00
|
|
|
fprintf(fp, "}\n");
|
|
|
|
|
|
2022-11-02 12:07:36 +02:00
|
|
|
if (info->name)
|
|
|
|
|
fprintf(fp, "name: %s\n", info->name);
|
|
|
|
|
|
|
|
|
|
if (info->label)
|
|
|
|
|
fprintf(fp, "label: %s\n", info->label);
|
2015-10-26 13:29:45 -04:00
|
|
|
|
2023-06-20 13:56:05 -07:00
|
|
|
fprintf(fp, "internal: %s\n", info->internal ? "true" : "false");
|
|
|
|
|
|
2022-11-02 12:07:36 +02:00
|
|
|
if (gl_shader_stage_uses_workgroup(info->stage)) {
|
2024-01-27 12:48:54 +01:00
|
|
|
fprintf(fp, "workgroup_size: %u, %u, %u%s\n",
|
2022-11-02 12:07:36 +02:00
|
|
|
info->workgroup_size[0],
|
|
|
|
|
info->workgroup_size[1],
|
|
|
|
|
info->workgroup_size[2],
|
|
|
|
|
info->workgroup_size_variable ? " (variable)" : "");
|
2017-04-06 11:56:23 -04:00
|
|
|
}
|
2022-11-02 13:30:16 +02:00
|
|
|
|
2022-11-14 19:52:37 +02:00
|
|
|
fprintf(fp, "stage: %d\n"
|
|
|
|
|
"next_stage: %d\n",
|
|
|
|
|
info->stage, info->next_stage);
|
2022-11-07 13:30:39 +02:00
|
|
|
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_unsigned(fp, "num_textures", info->num_textures);
|
|
|
|
|
print_nz_unsigned(fp, "num_ubos", info->num_ubos);
|
|
|
|
|
print_nz_unsigned(fp, "num_abos", info->num_abos);
|
|
|
|
|
print_nz_unsigned(fp, "num_ssbos", info->num_ssbos);
|
|
|
|
|
print_nz_unsigned(fp, "num_images", info->num_images);
|
2022-11-02 13:30:16 +02:00
|
|
|
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_x64(fp, "inputs_read", info->inputs_read);
|
2023-09-26 00:10:44 -04:00
|
|
|
print_nz_x64(fp, "dual_slot_inputs", info->dual_slot_inputs);
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_x64(fp, "outputs_written", info->outputs_written);
|
|
|
|
|
print_nz_x64(fp, "outputs_read", info->outputs_read);
|
2022-11-02 13:30:16 +02:00
|
|
|
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_bitset(fp, "system_values_read", info->system_values_read, ARRAY_SIZE(info->system_values_read));
|
|
|
|
|
|
|
|
|
|
print_nz_x64(fp, "per_primitive_inputs", info->per_primitive_inputs);
|
|
|
|
|
print_nz_x64(fp, "per_primitive_outputs", info->per_primitive_outputs);
|
|
|
|
|
print_nz_x64(fp, "per_view_outputs", info->per_view_outputs);
|
|
|
|
|
|
|
|
|
|
print_nz_x16(fp, "inputs_read_16bit", info->inputs_read_16bit);
|
|
|
|
|
print_nz_x16(fp, "outputs_written_16bit", info->outputs_written_16bit);
|
|
|
|
|
print_nz_x16(fp, "outputs_read_16bit", info->outputs_read_16bit);
|
|
|
|
|
print_nz_x16(fp, "inputs_read_indirectly_16bit", info->inputs_read_indirectly_16bit);
|
|
|
|
|
print_nz_x16(fp, "outputs_accessed_indirectly_16bit", info->outputs_accessed_indirectly_16bit);
|
2022-11-07 13:30:39 +02:00
|
|
|
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_x32(fp, "patch_inputs_read", info->patch_inputs_read);
|
|
|
|
|
print_nz_x32(fp, "patch_outputs_written", info->patch_outputs_written);
|
|
|
|
|
print_nz_x32(fp, "patch_outputs_read", info->patch_outputs_read);
|
2022-11-07 13:30:39 +02:00
|
|
|
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_x64(fp, "inputs_read_indirectly", info->inputs_read_indirectly);
|
|
|
|
|
print_nz_x64(fp, "outputs_accessed_indirectly", info->outputs_accessed_indirectly);
|
|
|
|
|
print_nz_x64(fp, "patch_inputs_read_indirectly", info->patch_inputs_read_indirectly);
|
|
|
|
|
print_nz_x64(fp, "patch_outputs_accessed_indirectly", info->patch_outputs_accessed_indirectly);
|
2022-11-07 13:30:39 +02:00
|
|
|
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_bitset(fp, "textures_used", info->textures_used, ARRAY_SIZE(info->textures_used));
|
|
|
|
|
print_nz_bitset(fp, "textures_used_by_txf", info->textures_used_by_txf, ARRAY_SIZE(info->textures_used_by_txf));
|
|
|
|
|
print_nz_bitset(fp, "samplers_used", info->samplers_used, ARRAY_SIZE(info->samplers_used));
|
|
|
|
|
print_nz_bitset(fp, "images_used", info->images_used, ARRAY_SIZE(info->images_used));
|
|
|
|
|
print_nz_bitset(fp, "image_buffers", info->image_buffers, ARRAY_SIZE(info->image_buffers));
|
|
|
|
|
print_nz_bitset(fp, "msaa_images", info->msaa_images, ARRAY_SIZE(info->msaa_images));
|
2022-11-07 13:30:39 +02:00
|
|
|
|
2023-09-20 14:44:28 -04:00
|
|
|
print_nz_x32(fp, "float_controls_execution_mode", info->float_controls_execution_mode);
|
2022-11-07 13:30:39 +02:00
|
|
|
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_unsigned(fp, "shared_size", info->shared_size);
|
2022-11-07 13:30:39 +02:00
|
|
|
|
2022-11-14 19:52:37 +02:00
|
|
|
if (info->stage == MESA_SHADER_MESH || info->stage == MESA_SHADER_TASK) {
|
|
|
|
|
fprintf(fp, "task_payload_size: %u\n", info->task_payload_size);
|
|
|
|
|
}
|
2022-11-07 13:30:39 +02:00
|
|
|
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_unsigned(fp, "ray queries", info->ray_queries);
|
|
|
|
|
|
|
|
|
|
fprintf(fp, "subgroup_size: %u\n", info->subgroup_size);
|
|
|
|
|
|
|
|
|
|
print_nz_bool(fp, "uses_wide_subgroup_intrinsics", info->uses_wide_subgroup_intrinsics);
|
|
|
|
|
|
|
|
|
|
bool has_xfb_stride = info->xfb_stride[0] || info->xfb_stride[1] || info->xfb_stride[2] || info->xfb_stride[3];
|
|
|
|
|
if (has_xfb_stride)
|
|
|
|
|
fprintf(fp, "xfb_stride: {%u, %u, %u, %u}\n",
|
|
|
|
|
info->xfb_stride[0],
|
|
|
|
|
info->xfb_stride[1],
|
|
|
|
|
info->xfb_stride[2],
|
|
|
|
|
info->xfb_stride[3]);
|
|
|
|
|
|
2023-08-08 12:00:35 -05:00
|
|
|
bool has_inlinable_uniform_dw_offsets = info->inlinable_uniform_dw_offsets[0] || info->inlinable_uniform_dw_offsets[1] || info->inlinable_uniform_dw_offsets[2] || info->inlinable_uniform_dw_offsets[3];
|
2022-11-14 19:52:37 +02:00
|
|
|
if (has_inlinable_uniform_dw_offsets)
|
|
|
|
|
fprintf(fp, "inlinable_uniform_dw_offsets: {%u, %u, %u, %u}\n",
|
|
|
|
|
info->inlinable_uniform_dw_offsets[0],
|
|
|
|
|
info->inlinable_uniform_dw_offsets[1],
|
|
|
|
|
info->inlinable_uniform_dw_offsets[2],
|
|
|
|
|
info->inlinable_uniform_dw_offsets[3]);
|
|
|
|
|
|
|
|
|
|
print_nz_unsigned(fp, "num_inlinable_uniforms", info->num_inlinable_uniforms);
|
|
|
|
|
print_nz_unsigned(fp, "clip_distance_array_size", info->clip_distance_array_size);
|
|
|
|
|
print_nz_unsigned(fp, "cull_distance_array_size", info->cull_distance_array_size);
|
|
|
|
|
|
|
|
|
|
print_nz_bool(fp, "uses_texture_gather", info->uses_texture_gather);
|
|
|
|
|
print_nz_bool(fp, "uses_resource_info_query", info->uses_resource_info_query);
|
|
|
|
|
print_nz_bool(fp, "uses_fddx_fddy", info->uses_fddx_fddy);
|
|
|
|
|
print_nz_bool(fp, "divergence_analysis_run", info->divergence_analysis_run);
|
|
|
|
|
|
|
|
|
|
print_nz_x8(fp, "bit_sizes_float", info->bit_sizes_float);
|
|
|
|
|
print_nz_x8(fp, "bit_sizes_int", info->bit_sizes_int);
|
|
|
|
|
|
|
|
|
|
print_nz_bool(fp, "first_ubo_is_default_ubo", info->first_ubo_is_default_ubo);
|
|
|
|
|
print_nz_bool(fp, "separate_shader", info->separate_shader);
|
|
|
|
|
print_nz_bool(fp, "has_transform_feedback_varyings", info->has_transform_feedback_varyings);
|
|
|
|
|
print_nz_bool(fp, "flrp_lowered", info->flrp_lowered);
|
|
|
|
|
print_nz_bool(fp, "io_lowered", info->io_lowered);
|
|
|
|
|
print_nz_bool(fp, "writes_memory", info->writes_memory);
|
2022-11-07 13:30:39 +02:00
|
|
|
|
|
|
|
|
switch (info->stage) {
|
|
|
|
|
case MESA_SHADER_VERTEX:
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_x64(fp, "double_inputs", info->vs.double_inputs);
|
|
|
|
|
print_nz_unsigned(fp, "blit_sgprs_amd", info->vs.blit_sgprs_amd);
|
|
|
|
|
print_nz_bool(fp, "window_space_position", info->vs.window_space_position);
|
|
|
|
|
print_nz_bool(fp, "needs_edge_flag", info->vs.needs_edge_flag);
|
2022-11-07 13:30:39 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MESA_SHADER_TESS_CTRL:
|
|
|
|
|
case MESA_SHADER_TESS_EVAL:
|
|
|
|
|
fprintf(fp, "primitive_mode: %u\n", info->tess._primitive_mode);
|
|
|
|
|
fprintf(fp, "tcs_vertices_out: %u\n", info->tess.tcs_vertices_out);
|
|
|
|
|
fprintf(fp, "spacing: %u\n", info->tess.spacing);
|
2022-11-14 19:52:37 +02:00
|
|
|
|
|
|
|
|
print_nz_bool(fp, "ccw", info->tess.ccw);
|
|
|
|
|
print_nz_bool(fp, "point_mode", info->tess.point_mode);
|
|
|
|
|
print_nz_x64(fp, "tcs_cross_invocation_inputs_read", info->tess.tcs_cross_invocation_inputs_read);
|
|
|
|
|
print_nz_x64(fp, "tcs_cross_invocation_outputs_read", info->tess.tcs_cross_invocation_outputs_read);
|
2022-11-07 13:30:39 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MESA_SHADER_GEOMETRY:
|
|
|
|
|
fprintf(fp, "output_primitive: %s\n", primitive_name(info->gs.output_primitive));
|
|
|
|
|
fprintf(fp, "input_primitive: %s\n", primitive_name(info->gs.input_primitive));
|
|
|
|
|
fprintf(fp, "vertices_out: %u\n", info->gs.vertices_out);
|
2022-11-02 13:30:16 +02:00
|
|
|
fprintf(fp, "invocations: %u\n", info->gs.invocations);
|
2022-11-07 13:30:39 +02:00
|
|
|
fprintf(fp, "vertices_in: %u\n", info->gs.vertices_in);
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_bool(fp, "uses_end_primitive", info->gs.uses_end_primitive);
|
2022-11-07 13:30:39 +02:00
|
|
|
fprintf(fp, "active_stream_mask: 0x%02x\n", info->gs.active_stream_mask);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MESA_SHADER_FRAGMENT:
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_bool(fp, "uses_discard", info->fs.uses_discard);
|
|
|
|
|
print_nz_bool(fp, "uses_fbfetch_output", info->fs.uses_fbfetch_output);
|
|
|
|
|
print_nz_bool(fp, "color_is_dual_source", info->fs.color_is_dual_source);
|
|
|
|
|
|
2023-11-02 15:44:40 +01:00
|
|
|
print_nz_bool(fp, "require_full_quads", info->fs.require_full_quads);
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_bool(fp, "needs_quad_helper_invocations", info->fs.needs_quad_helper_invocations);
|
|
|
|
|
print_nz_bool(fp, "uses_sample_qualifier", info->fs.uses_sample_qualifier);
|
|
|
|
|
print_nz_bool(fp, "uses_sample_shading", info->fs.uses_sample_shading);
|
|
|
|
|
print_nz_bool(fp, "early_fragment_tests", info->fs.early_fragment_tests);
|
|
|
|
|
print_nz_bool(fp, "inner_coverage", info->fs.inner_coverage);
|
|
|
|
|
print_nz_bool(fp, "post_depth_coverage", info->fs.post_depth_coverage);
|
|
|
|
|
|
|
|
|
|
print_nz_bool(fp, "pixel_center_integer", info->fs.pixel_center_integer);
|
|
|
|
|
print_nz_bool(fp, "origin_upper_left", info->fs.origin_upper_left);
|
|
|
|
|
print_nz_bool(fp, "pixel_interlock_ordered", info->fs.pixel_interlock_ordered);
|
|
|
|
|
print_nz_bool(fp, "pixel_interlock_unordered", info->fs.pixel_interlock_unordered);
|
|
|
|
|
print_nz_bool(fp, "sample_interlock_ordered", info->fs.sample_interlock_ordered);
|
|
|
|
|
print_nz_bool(fp, "sample_interlock_unordered", info->fs.sample_interlock_unordered);
|
|
|
|
|
print_nz_bool(fp, "untyped_color_outputs", info->fs.untyped_color_outputs);
|
|
|
|
|
|
|
|
|
|
print_nz_unsigned(fp, "depth_layout", info->fs.depth_layout);
|
|
|
|
|
|
2023-02-02 19:44:26 -05:00
|
|
|
if (info->fs.color0_interp != INTERP_MODE_NONE) {
|
|
|
|
|
fprintf(fp, "color0_interp: %s\n",
|
|
|
|
|
glsl_interp_mode_name(info->fs.color0_interp));
|
|
|
|
|
}
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_bool(fp, "color0_sample", info->fs.color0_sample);
|
|
|
|
|
print_nz_bool(fp, "color0_centroid", info->fs.color0_centroid);
|
2022-11-07 13:30:39 +02:00
|
|
|
|
2023-02-02 19:44:26 -05:00
|
|
|
if (info->fs.color1_interp != INTERP_MODE_NONE) {
|
|
|
|
|
fprintf(fp, "color1_interp: %s\n",
|
|
|
|
|
glsl_interp_mode_name(info->fs.color1_interp));
|
|
|
|
|
}
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_bool(fp, "color1_sample", info->fs.color1_sample);
|
|
|
|
|
print_nz_bool(fp, "color1_centroid", info->fs.color1_centroid);
|
2022-11-07 13:30:39 +02:00
|
|
|
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_x32(fp, "advanced_blend_modes", info->fs.advanced_blend_modes);
|
2022-11-07 13:30:39 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MESA_SHADER_COMPUTE:
|
2023-09-05 17:43:49 -04:00
|
|
|
case MESA_SHADER_KERNEL:
|
2023-08-08 12:00:35 -05:00
|
|
|
if (info->cs.workgroup_size_hint[0] || info->cs.workgroup_size_hint[1] || info->cs.workgroup_size_hint[2])
|
2022-11-14 19:52:37 +02:00
|
|
|
fprintf(fp, "workgroup_size_hint: {%u, %u, %u}\n",
|
|
|
|
|
info->cs.workgroup_size_hint[0],
|
|
|
|
|
info->cs.workgroup_size_hint[1],
|
|
|
|
|
info->cs.workgroup_size_hint[2]);
|
|
|
|
|
print_nz_unsigned(fp, "user_data_components_amd", info->cs.user_data_components_amd);
|
|
|
|
|
print_nz_unsigned(fp, "derivative_group", info->cs.derivative_group);
|
2022-11-07 13:30:39 +02:00
|
|
|
fprintf(fp, "ptr_size: %u\n", info->cs.ptr_size);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MESA_SHADER_MESH:
|
2022-11-23 22:12:24 +02:00
|
|
|
print_nz_x64(fp, "ms_cross_invocation_output_access", info->mesh.ms_cross_invocation_output_access);
|
2022-11-07 13:30:39 +02:00
|
|
|
fprintf(fp, "max_vertices_out: %u\n", info->mesh.max_vertices_out);
|
|
|
|
|
fprintf(fp, "max_primitives_out: %u\n", info->mesh.max_primitives_out);
|
|
|
|
|
fprintf(fp, "primitive_type: %s\n", primitive_name(info->mesh.primitive_type));
|
2022-11-14 19:52:37 +02:00
|
|
|
print_nz_bool(fp, "nv", info->mesh.nv);
|
2022-11-07 13:30:39 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fprintf(fp, "Unhandled stage %d\n", info->stage);
|
2022-11-02 13:30:16 +02:00
|
|
|
}
|
2022-11-02 12:07:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nir_print_shader_annotated(nir_shader *shader, FILE *fp,
|
|
|
|
|
struct hash_table *annotations)
|
|
|
|
|
{
|
|
|
|
|
print_state state;
|
|
|
|
|
init_print_state(&state, shader, fp);
|
|
|
|
|
state.annotations = annotations;
|
|
|
|
|
|
|
|
|
|
print_shader_info(&shader->info, fp);
|
2017-04-06 11:56:23 -04:00
|
|
|
|
2015-11-04 10:05:32 -05:00
|
|
|
fprintf(fp, "inputs: %u\n", shader->num_inputs);
|
|
|
|
|
fprintf(fp, "outputs: %u\n", shader->num_outputs);
|
|
|
|
|
fprintf(fp, "uniforms: %u\n", shader->num_uniforms);
|
2016-12-02 11:36:42 -08:00
|
|
|
if (shader->scratch_size)
|
|
|
|
|
fprintf(fp, "scratch: %u\n", shader->scratch_size);
|
2020-07-07 12:48:09 -07:00
|
|
|
if (shader->constant_data_size)
|
|
|
|
|
fprintf(fp, "constants: %u\n", shader->constant_data_size);
|
2023-07-28 10:26:11 -04:00
|
|
|
for (unsigned i = 0; i < nir_num_variable_modes; i++) {
|
2023-09-01 10:24:50 -04:00
|
|
|
nir_variable_mode mode = BITFIELD_BIT(i);
|
|
|
|
|
if (mode == nir_var_function_temp)
|
2023-07-28 10:26:11 -04:00
|
|
|
continue;
|
2023-09-01 10:24:50 -04:00
|
|
|
|
|
|
|
|
if (mode == nir_var_shader_in || mode == nir_var_shader_out) {
|
|
|
|
|
for (unsigned j = 0; j < 128; j++) {
|
|
|
|
|
nir_variable *vars[NIR_MAX_VEC_COMPONENTS] = {0};
|
|
|
|
|
nir_foreach_variable_with_modes(var, shader, mode) {
|
|
|
|
|
if (var->data.location == j)
|
|
|
|
|
vars[var->data.location_frac] = var;
|
|
|
|
|
}
|
|
|
|
|
for (unsigned j = 0; j < ARRAY_SIZE(vars); j++)
|
|
|
|
|
if (vars[j]) {
|
|
|
|
|
print_var_decl(vars[j], &state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
nir_foreach_variable_with_modes(var, shader, mode)
|
|
|
|
|
print_var_decl(var, &state);
|
|
|
|
|
}
|
2023-07-28 10:26:11 -04:00
|
|
|
}
|
2014-07-30 15:29:27 -07:00
|
|
|
|
|
|
|
|
foreach_list_typed(nir_function, func, node, &shader->functions) {
|
2015-09-15 18:50:41 -04:00
|
|
|
print_function(func, &state);
|
2014-07-30 15:29:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
destroy_print_state(&state);
|
|
|
|
|
}
|
2014-11-05 15:10:37 -08:00
|
|
|
|
2016-05-14 15:37:32 -04:00
|
|
|
void
|
|
|
|
|
nir_print_shader(nir_shader *shader, FILE *fp)
|
|
|
|
|
{
|
|
|
|
|
nir_print_shader_annotated(shader, fp, NULL);
|
2018-11-26 11:29:41 -08:00
|
|
|
fflush(fp);
|
2016-05-14 15:37:32 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 13:25:03 +02:00
|
|
|
char *
|
2021-06-16 11:13:54 -07:00
|
|
|
nir_shader_as_str_annotated(nir_shader *nir, struct hash_table *annotations, void *mem_ctx)
|
2021-02-05 13:25:03 +02:00
|
|
|
{
|
|
|
|
|
char *stream_data = NULL;
|
|
|
|
|
size_t stream_size = 0;
|
|
|
|
|
struct u_memstream mem;
|
|
|
|
|
if (u_memstream_open(&mem, &stream_data, &stream_size)) {
|
|
|
|
|
FILE *const stream = u_memstream_get(&mem);
|
2021-06-16 11:13:54 -07:00
|
|
|
nir_print_shader_annotated(nir, stream, annotations);
|
2021-02-05 13:25:03 +02:00
|
|
|
u_memstream_close(&mem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *str = ralloc_size(mem_ctx, stream_size + 1);
|
|
|
|
|
memcpy(str, stream_data, stream_size);
|
|
|
|
|
str[stream_size] = '\0';
|
|
|
|
|
|
|
|
|
|
free(stream_data);
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-16 11:13:54 -07:00
|
|
|
char *
|
|
|
|
|
nir_shader_as_str(nir_shader *nir, void *mem_ctx)
|
|
|
|
|
{
|
|
|
|
|
return nir_shader_as_str_annotated(nir, NULL, mem_ctx);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-05 15:10:37 -08:00
|
|
|
void
|
2015-02-09 13:42:16 -08:00
|
|
|
nir_print_instr(const nir_instr *instr, FILE *fp)
|
2014-11-05 15:10:37 -08:00
|
|
|
{
|
2015-09-15 18:50:41 -04:00
|
|
|
print_state state = {
|
|
|
|
|
.fp = fp,
|
|
|
|
|
};
|
2020-08-28 12:27:04 -07:00
|
|
|
if (instr->block) {
|
|
|
|
|
nir_function_impl *impl = nir_cf_node_get_function(&instr->block->cf_node);
|
|
|
|
|
state.shader = impl->function->shader;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-15 18:50:41 -04:00
|
|
|
print_instr(instr, &state, 0);
|
2021-10-05 15:32:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
nir_instr_as_str(const nir_instr *instr, void *mem_ctx)
|
|
|
|
|
{
|
|
|
|
|
char *stream_data = NULL;
|
|
|
|
|
size_t stream_size = 0;
|
|
|
|
|
struct u_memstream mem;
|
|
|
|
|
if (u_memstream_open(&mem, &stream_data, &stream_size)) {
|
|
|
|
|
FILE *const stream = u_memstream_get(&mem);
|
|
|
|
|
nir_print_instr(instr, stream);
|
|
|
|
|
u_memstream_close(&mem);
|
|
|
|
|
}
|
2015-09-15 18:50:41 -04:00
|
|
|
|
2021-10-05 15:32:33 -07:00
|
|
|
char *str = ralloc_size(mem_ctx, stream_size + 1);
|
|
|
|
|
memcpy(str, stream_data, stream_size);
|
|
|
|
|
str[stream_size] = '\0';
|
|
|
|
|
|
|
|
|
|
free(stream_data);
|
|
|
|
|
|
|
|
|
|
return str;
|
2014-11-05 15:10:37 -08:00
|
|
|
}
|
2018-12-19 12:13:46 -08:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nir_print_deref(const nir_deref_instr *deref, FILE *fp)
|
|
|
|
|
{
|
|
|
|
|
print_state state = {
|
|
|
|
|
.fp = fp,
|
|
|
|
|
};
|
|
|
|
|
print_deref_link(deref, true, &state);
|
|
|
|
|
}
|
2021-06-16 11:13:54 -07:00
|
|
|
|
2023-08-08 12:00:35 -05:00
|
|
|
void
|
|
|
|
|
nir_log_shader_annotated_tagged(enum mesa_log_level level, const char *tag,
|
|
|
|
|
nir_shader *shader, struct hash_table *annotations)
|
2021-06-16 11:13:54 -07:00
|
|
|
{
|
|
|
|
|
char *str = nir_shader_as_str_annotated(shader, annotations, NULL);
|
|
|
|
|
_mesa_log_multiline(level, tag, str);
|
|
|
|
|
ralloc_free(str);
|
|
|
|
|
}
|