2016-03-25 10:23:25 -07:00
|
|
|
/*
|
|
|
|
* Copyright © 2015 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nir.h"
|
2018-04-08 13:13:08 -04:00
|
|
|
#include "main/menums.h"
|
2016-03-25 10:23:25 -07:00
|
|
|
|
2016-10-27 12:21:52 +11:00
|
|
|
static void
|
2017-11-14 15:10:44 +10:00
|
|
|
set_io_mask(nir_shader *shader, nir_variable *var, int offset, int len,
|
|
|
|
bool is_output_read)
|
2016-10-27 12:21:52 +11:00
|
|
|
{
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
assert(var->data.location != -1);
|
|
|
|
|
|
|
|
int idx = var->data.location + offset + i;
|
|
|
|
bool is_patch_generic = var->data.patch &&
|
|
|
|
idx != VARYING_SLOT_TESS_LEVEL_INNER &&
|
|
|
|
idx != VARYING_SLOT_TESS_LEVEL_OUTER &&
|
|
|
|
idx != VARYING_SLOT_BOUNDING_BOX0 &&
|
|
|
|
idx != VARYING_SLOT_BOUNDING_BOX1;
|
|
|
|
uint64_t bitfield;
|
|
|
|
|
|
|
|
if (is_patch_generic) {
|
|
|
|
assert(idx >= VARYING_SLOT_PATCH0 && idx < VARYING_SLOT_TESS_MAX);
|
|
|
|
bitfield = BITFIELD64_BIT(idx - VARYING_SLOT_PATCH0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(idx < VARYING_SLOT_MAX);
|
|
|
|
bitfield = BITFIELD64_BIT(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var->data.mode == nir_var_shader_in) {
|
|
|
|
if (is_patch_generic)
|
2017-05-08 09:20:21 -07:00
|
|
|
shader->info.patch_inputs_read |= bitfield;
|
2016-10-27 12:21:52 +11:00
|
|
|
else
|
2017-05-08 09:20:21 -07:00
|
|
|
shader->info.inputs_read |= bitfield;
|
2016-10-27 12:21:52 +11:00
|
|
|
|
2017-09-14 19:52:38 -07:00
|
|
|
if (shader->info.stage == MESA_SHADER_FRAGMENT) {
|
2017-05-08 09:20:21 -07:00
|
|
|
shader->info.fs.uses_sample_qualifier |= var->data.sample;
|
2016-10-27 12:21:52 +11:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
assert(var->data.mode == nir_var_shader_out);
|
2017-11-14 15:10:44 +10:00
|
|
|
if (is_output_read) {
|
|
|
|
if (is_patch_generic) {
|
|
|
|
shader->info.patch_outputs_read |= bitfield;
|
|
|
|
} else {
|
|
|
|
shader->info.outputs_read |= bitfield;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (is_patch_generic) {
|
|
|
|
shader->info.patch_outputs_written |= bitfield;
|
|
|
|
} else if (!var->data.read_only) {
|
|
|
|
shader->info.outputs_written |= bitfield;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-27 12:21:52 +11:00
|
|
|
|
|
|
|
if (var->data.fb_fetch_output)
|
2017-05-08 09:20:21 -07:00
|
|
|
shader->info.outputs_read |= bitfield;
|
2016-10-27 12:21:52 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark an entire variable as used. Caller must ensure that the variable
|
|
|
|
* represents a shader input or output.
|
|
|
|
*/
|
|
|
|
static void
|
2017-11-14 15:10:44 +10:00
|
|
|
mark_whole_variable(nir_shader *shader, nir_variable *var, bool is_output_read)
|
2016-10-27 12:21:52 +11:00
|
|
|
{
|
|
|
|
const struct glsl_type *type = var->type;
|
|
|
|
|
2017-09-14 19:52:38 -07:00
|
|
|
if (nir_is_per_vertex_io(var, shader->info.stage)) {
|
2016-10-27 12:21:52 +11:00
|
|
|
assert(glsl_type_is_array(type));
|
|
|
|
type = glsl_get_array_element(type);
|
|
|
|
}
|
|
|
|
|
2016-10-03 20:32:22 -07:00
|
|
|
const unsigned slots =
|
|
|
|
var->data.compact ? DIV_ROUND_UP(glsl_get_length(type), 4)
|
2018-08-31 07:35:17 -05:00
|
|
|
: glsl_count_attribute_slots(type, false);
|
2016-10-03 20:32:22 -07:00
|
|
|
|
2017-11-14 15:10:44 +10:00
|
|
|
set_io_mask(shader, var, 0, slots, is_output_read);
|
2016-10-27 12:21:52 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned
|
2018-03-26 15:53:17 -07:00
|
|
|
get_io_offset(nir_deref_instr *deref, bool is_vertex_input)
|
2016-10-27 12:21:52 +11:00
|
|
|
{
|
|
|
|
unsigned offset = 0;
|
|
|
|
|
2018-03-26 15:53:17 -07:00
|
|
|
for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) {
|
|
|
|
if (d->deref_type == nir_deref_type_array) {
|
2018-10-20 09:10:02 -05:00
|
|
|
if (!nir_src_is_const(d->arr.index))
|
2016-10-27 12:21:52 +11:00
|
|
|
return -1;
|
|
|
|
|
2018-03-26 15:53:17 -07:00
|
|
|
offset += glsl_count_attribute_slots(d->type, is_vertex_input) *
|
2018-10-20 09:10:02 -05:00
|
|
|
nir_src_as_uint(d->arr.index);
|
2016-10-27 12:21:52 +11:00
|
|
|
}
|
|
|
|
/* TODO: we can get the offset for structs here see nir_lower_io() */
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to mark a portion of the given varying as used. Caller must ensure
|
|
|
|
* that the variable represents a shader input or output.
|
|
|
|
*
|
|
|
|
* If the index can't be interpreted as a constant, or some other problem
|
|
|
|
* occurs, then nothing will be marked and false will be returned.
|
|
|
|
*/
|
|
|
|
static bool
|
2018-03-26 15:53:17 -07:00
|
|
|
try_mask_partial_io(nir_shader *shader, nir_variable *var,
|
|
|
|
nir_deref_instr *deref, bool is_output_read)
|
2016-10-27 12:21:52 +11:00
|
|
|
{
|
|
|
|
const struct glsl_type *type = var->type;
|
|
|
|
|
2017-09-14 19:52:38 -07:00
|
|
|
if (nir_is_per_vertex_io(var, shader->info.stage)) {
|
2016-10-27 12:21:52 +11:00
|
|
|
assert(glsl_type_is_array(type));
|
|
|
|
type = glsl_get_array_element(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The code below only handles:
|
|
|
|
*
|
|
|
|
* - Indexing into matrices
|
|
|
|
* - Indexing into arrays of (arrays, matrices, vectors, or scalars)
|
|
|
|
*
|
|
|
|
* For now, we just give up if we see varying structs and arrays of structs
|
|
|
|
* here marking the entire variable as used.
|
|
|
|
*/
|
|
|
|
if (!(glsl_type_is_matrix(type) ||
|
2016-10-03 20:32:22 -07:00
|
|
|
(glsl_type_is_array(type) && !var->data.compact &&
|
2016-10-27 12:21:52 +11:00
|
|
|
(glsl_type_is_numeric(glsl_without_array(type)) ||
|
|
|
|
glsl_type_is_boolean(glsl_without_array(type)))))) {
|
|
|
|
|
|
|
|
/* If we don't know how to handle this case, give up and let the
|
|
|
|
* caller mark the whole variable as used.
|
|
|
|
*/
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-31 07:35:17 -05:00
|
|
|
unsigned offset = get_io_offset(deref, false);
|
2016-10-27 12:21:52 +11:00
|
|
|
if (offset == -1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned num_elems;
|
|
|
|
unsigned elem_width = 1;
|
|
|
|
unsigned mat_cols = 1;
|
|
|
|
if (glsl_type_is_array(type)) {
|
|
|
|
num_elems = glsl_get_aoa_size(type);
|
|
|
|
if (glsl_type_is_matrix(glsl_without_array(type)))
|
|
|
|
mat_cols = glsl_get_matrix_columns(glsl_without_array(type));
|
|
|
|
} else {
|
|
|
|
num_elems = glsl_get_matrix_columns(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* double element width for double types that takes two slots */
|
2018-08-31 07:35:17 -05:00
|
|
|
if (glsl_type_is_dual_slot(glsl_without_array(type)))
|
2016-10-27 12:21:52 +11:00
|
|
|
elem_width *= 2;
|
|
|
|
|
|
|
|
if (offset >= num_elems * elem_width * mat_cols) {
|
|
|
|
/* Constant index outside the bounds of the matrix/array. This could
|
|
|
|
* arise as a result of constant folding of a legal GLSL program.
|
|
|
|
*
|
|
|
|
* Even though the spec says that indexing outside the bounds of a
|
|
|
|
* matrix/array results in undefined behaviour, we don't want to pass
|
|
|
|
* out-of-range values to set_io_mask() (since this could result in
|
|
|
|
* slots that don't exist being marked as used), so just let the caller
|
|
|
|
* mark the whole variable as used.
|
|
|
|
*/
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-14 15:10:44 +10:00
|
|
|
set_io_mask(shader, var, offset, elem_width, is_output_read);
|
2016-10-27 12:21:52 +11:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-25 10:23:25 -07:00
|
|
|
static void
|
2018-03-17 21:09:14 -07:00
|
|
|
gather_intrinsic_info(nir_intrinsic_instr *instr, nir_shader *shader,
|
|
|
|
void *dead_ctx)
|
2016-03-25 10:23:25 -07:00
|
|
|
{
|
|
|
|
switch (instr->intrinsic) {
|
|
|
|
case nir_intrinsic_discard:
|
|
|
|
case nir_intrinsic_discard_if:
|
2017-09-14 19:52:38 -07:00
|
|
|
assert(shader->info.stage == MESA_SHADER_FRAGMENT);
|
2017-05-08 09:20:21 -07:00
|
|
|
shader->info.fs.uses_discard = true;
|
2016-03-25 10:23:25 -07:00
|
|
|
break;
|
|
|
|
|
2018-03-17 21:09:14 -07:00
|
|
|
case nir_intrinsic_interp_deref_at_centroid:
|
|
|
|
case nir_intrinsic_interp_deref_at_sample:
|
|
|
|
case nir_intrinsic_interp_deref_at_offset:
|
|
|
|
case nir_intrinsic_load_deref:
|
2018-03-26 15:53:17 -07:00
|
|
|
case nir_intrinsic_store_deref:{
|
|
|
|
nir_deref_instr *deref = nir_src_as_deref(instr->src[0]);
|
2018-11-19 13:51:48 +10:00
|
|
|
if (deref->mode == nir_var_shader_in ||
|
|
|
|
deref->mode == nir_var_shader_out) {
|
|
|
|
nir_variable *var = nir_deref_instr_get_variable(deref);
|
2017-11-14 15:10:44 +10:00
|
|
|
bool is_output_read = false;
|
|
|
|
if (var->data.mode == nir_var_shader_out &&
|
2018-03-26 15:53:17 -07:00
|
|
|
instr->intrinsic == nir_intrinsic_load_deref)
|
2017-11-14 15:10:44 +10:00
|
|
|
is_output_read = true;
|
|
|
|
|
2018-03-26 15:53:17 -07:00
|
|
|
if (!try_mask_partial_io(shader, var, deref, is_output_read))
|
2017-11-14 15:10:44 +10:00
|
|
|
mark_whole_variable(shader, var, is_output_read);
|
nir/i965: use two slots from inputs_read for dvec3/dvec4 vertex input attributes
So far, input_reads was a bitmap tracking which vertex input locations
were being used.
In OpenGL, an attribute bigger than a vec4 (like a dvec3 or dvec4)
consumes just one location, any other small attribute. So we mark the
proper bit in inputs_read, and also the same bit in double_inputs_read
if the attribute is a dvec3/dvec4.
But in Vulkan, this is slightly different: a dvec3/dvec4 attribute
consumes two locations, not just one. And hence two bits would be marked
in inputs_read for the same vertex input attribute.
To avoid handling two different situations in NIR, we just choose the
latest one: in OpenGL, when creating NIR from GLSL/IR, any dvec3/dvec4
vertex input attribute is marked with two bits in the inputs_read bitmap
(and also in the double_inputs_read), and following attributes are
adjusted accordingly.
As example, if in our GLSL/IR shader we have three attributes:
layout(location = 0) vec3 attr0;
layout(location = 1) dvec4 attr1;
layout(location = 2) dvec3 attr2;
then in our NIR shader we put attr0 in location 0, attr1 in locations 1
and 2, and attr2 in location 3 and 4.
Checking carefully, basically we are using slots rather than locations
in NIR.
When emitting the vertices, we do a inverse map to know the
corresponding location for each slot.
v2 (Jason):
- use two slots from inputs_read for dvec3/dvec4 NIR from GLSL/IR.
v3 (Jason):
- Fix commit log error.
- Use ladder ifs and fix braces.
- elements_double is divisible by 2, don't need DIV_ROUND_UP().
- Use if ladder instead of a switch.
- Add comment about hardware restriction in 64bit vertex attributes.
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2016-12-16 10:24:43 +01:00
|
|
|
|
|
|
|
/* We need to track which input_reads bits correspond to a
|
|
|
|
* dvec3/dvec4 input attribute */
|
2017-09-14 19:52:38 -07:00
|
|
|
if (shader->info.stage == MESA_SHADER_VERTEX &&
|
nir/i965: use two slots from inputs_read for dvec3/dvec4 vertex input attributes
So far, input_reads was a bitmap tracking which vertex input locations
were being used.
In OpenGL, an attribute bigger than a vec4 (like a dvec3 or dvec4)
consumes just one location, any other small attribute. So we mark the
proper bit in inputs_read, and also the same bit in double_inputs_read
if the attribute is a dvec3/dvec4.
But in Vulkan, this is slightly different: a dvec3/dvec4 attribute
consumes two locations, not just one. And hence two bits would be marked
in inputs_read for the same vertex input attribute.
To avoid handling two different situations in NIR, we just choose the
latest one: in OpenGL, when creating NIR from GLSL/IR, any dvec3/dvec4
vertex input attribute is marked with two bits in the inputs_read bitmap
(and also in the double_inputs_read), and following attributes are
adjusted accordingly.
As example, if in our GLSL/IR shader we have three attributes:
layout(location = 0) vec3 attr0;
layout(location = 1) dvec4 attr1;
layout(location = 2) dvec3 attr2;
then in our NIR shader we put attr0 in location 0, attr1 in locations 1
and 2, and attr2 in location 3 and 4.
Checking carefully, basically we are using slots rather than locations
in NIR.
When emitting the vertices, we do a inverse map to know the
corresponding location for each slot.
v2 (Jason):
- use two slots from inputs_read for dvec3/dvec4 NIR from GLSL/IR.
v3 (Jason):
- Fix commit log error.
- Use ladder ifs and fix braces.
- elements_double is divisible by 2, don't need DIV_ROUND_UP().
- Use if ladder instead of a switch.
- Add comment about hardware restriction in 64bit vertex attributes.
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2016-12-16 10:24:43 +01:00
|
|
|
var->data.mode == nir_var_shader_in &&
|
|
|
|
glsl_type_is_dual_slot(glsl_without_array(var->type))) {
|
2018-03-29 22:02:37 -06:00
|
|
|
for (unsigned i = 0; i < glsl_count_attribute_slots(var->type, false); i++) {
|
nir/i965: use two slots from inputs_read for dvec3/dvec4 vertex input attributes
So far, input_reads was a bitmap tracking which vertex input locations
were being used.
In OpenGL, an attribute bigger than a vec4 (like a dvec3 or dvec4)
consumes just one location, any other small attribute. So we mark the
proper bit in inputs_read, and also the same bit in double_inputs_read
if the attribute is a dvec3/dvec4.
But in Vulkan, this is slightly different: a dvec3/dvec4 attribute
consumes two locations, not just one. And hence two bits would be marked
in inputs_read for the same vertex input attribute.
To avoid handling two different situations in NIR, we just choose the
latest one: in OpenGL, when creating NIR from GLSL/IR, any dvec3/dvec4
vertex input attribute is marked with two bits in the inputs_read bitmap
(and also in the double_inputs_read), and following attributes are
adjusted accordingly.
As example, if in our GLSL/IR shader we have three attributes:
layout(location = 0) vec3 attr0;
layout(location = 1) dvec4 attr1;
layout(location = 2) dvec3 attr2;
then in our NIR shader we put attr0 in location 0, attr1 in locations 1
and 2, and attr2 in location 3 and 4.
Checking carefully, basically we are using slots rather than locations
in NIR.
When emitting the vertices, we do a inverse map to know the
corresponding location for each slot.
v2 (Jason):
- use two slots from inputs_read for dvec3/dvec4 NIR from GLSL/IR.
v3 (Jason):
- Fix commit log error.
- Use ladder ifs and fix braces.
- elements_double is divisible by 2, don't need DIV_ROUND_UP().
- Use if ladder instead of a switch.
- Add comment about hardware restriction in 64bit vertex attributes.
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2016-12-16 10:24:43 +01:00
|
|
|
int idx = var->data.location + i;
|
2017-12-16 14:06:23 +11:00
|
|
|
shader->info.vs.double_inputs |= BITFIELD64_BIT(idx);
|
nir/i965: use two slots from inputs_read for dvec3/dvec4 vertex input attributes
So far, input_reads was a bitmap tracking which vertex input locations
were being used.
In OpenGL, an attribute bigger than a vec4 (like a dvec3 or dvec4)
consumes just one location, any other small attribute. So we mark the
proper bit in inputs_read, and also the same bit in double_inputs_read
if the attribute is a dvec3/dvec4.
But in Vulkan, this is slightly different: a dvec3/dvec4 attribute
consumes two locations, not just one. And hence two bits would be marked
in inputs_read for the same vertex input attribute.
To avoid handling two different situations in NIR, we just choose the
latest one: in OpenGL, when creating NIR from GLSL/IR, any dvec3/dvec4
vertex input attribute is marked with two bits in the inputs_read bitmap
(and also in the double_inputs_read), and following attributes are
adjusted accordingly.
As example, if in our GLSL/IR shader we have three attributes:
layout(location = 0) vec3 attr0;
layout(location = 1) dvec4 attr1;
layout(location = 2) dvec3 attr2;
then in our NIR shader we put attr0 in location 0, attr1 in locations 1
and 2, and attr2 in location 3 and 4.
Checking carefully, basically we are using slots rather than locations
in NIR.
When emitting the vertices, we do a inverse map to know the
corresponding location for each slot.
v2 (Jason):
- use two slots from inputs_read for dvec3/dvec4 NIR from GLSL/IR.
v3 (Jason):
- Fix commit log error.
- Use ladder ifs and fix braces.
- elements_double is divisible by 2, don't need DIV_ROUND_UP().
- Use if ladder instead of a switch.
- Add comment about hardware restriction in 64bit vertex attributes.
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2016-12-16 10:24:43 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-27 12:21:52 +11:00
|
|
|
}
|
|
|
|
break;
|
nir/i965: use two slots from inputs_read for dvec3/dvec4 vertex input attributes
So far, input_reads was a bitmap tracking which vertex input locations
were being used.
In OpenGL, an attribute bigger than a vec4 (like a dvec3 or dvec4)
consumes just one location, any other small attribute. So we mark the
proper bit in inputs_read, and also the same bit in double_inputs_read
if the attribute is a dvec3/dvec4.
But in Vulkan, this is slightly different: a dvec3/dvec4 attribute
consumes two locations, not just one. And hence two bits would be marked
in inputs_read for the same vertex input attribute.
To avoid handling two different situations in NIR, we just choose the
latest one: in OpenGL, when creating NIR from GLSL/IR, any dvec3/dvec4
vertex input attribute is marked with two bits in the inputs_read bitmap
(and also in the double_inputs_read), and following attributes are
adjusted accordingly.
As example, if in our GLSL/IR shader we have three attributes:
layout(location = 0) vec3 attr0;
layout(location = 1) dvec4 attr1;
layout(location = 2) dvec3 attr2;
then in our NIR shader we put attr0 in location 0, attr1 in locations 1
and 2, and attr2 in location 3 and 4.
Checking carefully, basically we are using slots rather than locations
in NIR.
When emitting the vertices, we do a inverse map to know the
corresponding location for each slot.
v2 (Jason):
- use two slots from inputs_read for dvec3/dvec4 NIR from GLSL/IR.
v3 (Jason):
- Fix commit log error.
- Use ladder ifs and fix braces.
- elements_double is divisible by 2, don't need DIV_ROUND_UP().
- Use if ladder instead of a switch.
- Add comment about hardware restriction in 64bit vertex attributes.
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2016-12-16 10:24:43 +01:00
|
|
|
}
|
2016-10-27 12:21:52 +11:00
|
|
|
|
|
|
|
case nir_intrinsic_load_draw_id:
|
2017-07-04 10:34:02 +02:00
|
|
|
case nir_intrinsic_load_frag_coord:
|
2016-03-25 10:23:25 -07:00
|
|
|
case nir_intrinsic_load_front_face:
|
|
|
|
case nir_intrinsic_load_vertex_id:
|
|
|
|
case nir_intrinsic_load_vertex_id_zero_base:
|
|
|
|
case nir_intrinsic_load_base_vertex:
|
2018-01-25 19:15:38 +01:00
|
|
|
case nir_intrinsic_load_first_vertex:
|
2018-04-28 14:09:18 +02:00
|
|
|
case nir_intrinsic_load_is_indexed_draw:
|
2016-10-27 12:21:52 +11:00
|
|
|
case nir_intrinsic_load_base_instance:
|
2016-03-25 10:23:25 -07:00
|
|
|
case nir_intrinsic_load_instance_id:
|
|
|
|
case nir_intrinsic_load_sample_id:
|
|
|
|
case nir_intrinsic_load_sample_pos:
|
|
|
|
case nir_intrinsic_load_sample_mask_in:
|
|
|
|
case nir_intrinsic_load_primitive_id:
|
|
|
|
case nir_intrinsic_load_invocation_id:
|
|
|
|
case nir_intrinsic_load_local_invocation_id:
|
2016-05-22 15:54:48 -07:00
|
|
|
case nir_intrinsic_load_local_invocation_index:
|
2016-03-25 10:23:25 -07:00
|
|
|
case nir_intrinsic_load_work_group_id:
|
|
|
|
case nir_intrinsic_load_num_work_groups:
|
2016-10-27 12:21:52 +11:00
|
|
|
case nir_intrinsic_load_tess_coord:
|
|
|
|
case nir_intrinsic_load_tess_level_outer:
|
|
|
|
case nir_intrinsic_load_tess_level_inner:
|
2017-11-16 08:53:07 +01:00
|
|
|
case nir_intrinsic_load_patch_vertices_in:
|
2017-05-08 09:20:21 -07:00
|
|
|
shader->info.system_values_read |=
|
2017-01-26 13:18:36 +00:00
|
|
|
(1ull << nir_system_value_from_intrinsic(instr->intrinsic));
|
2016-03-25 10:23:25 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nir_intrinsic_end_primitive:
|
|
|
|
case nir_intrinsic_end_primitive_with_counter:
|
2017-09-14 19:52:38 -07:00
|
|
|
assert(shader->info.stage == MESA_SHADER_GEOMETRY);
|
2017-05-08 09:20:21 -07:00
|
|
|
shader->info.gs.uses_end_primitive = 1;
|
2018-08-02 10:04:51 +10:00
|
|
|
/* fall through */
|
2018-01-17 16:37:35 +01:00
|
|
|
|
|
|
|
case nir_intrinsic_emit_vertex:
|
|
|
|
if (nir_intrinsic_stream_id(instr) > 0)
|
|
|
|
shader->info.gs.uses_streams = true;
|
|
|
|
|
2016-03-25 10:23:25 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gather_tex_info(nir_tex_instr *instr, nir_shader *shader)
|
|
|
|
{
|
2017-09-09 00:19:57 -07:00
|
|
|
switch (instr->op) {
|
|
|
|
case nir_texop_tg4:
|
2017-05-08 09:20:21 -07:00
|
|
|
shader->info.uses_texture_gather = true;
|
2017-09-09 00:19:57 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-03-25 10:23:25 -07:00
|
|
|
}
|
|
|
|
|
2017-10-26 15:19:25 -07:00
|
|
|
static void
|
|
|
|
gather_alu_info(nir_alu_instr *instr, nir_shader *shader)
|
|
|
|
{
|
|
|
|
switch (instr->op) {
|
|
|
|
case nir_op_fddx:
|
|
|
|
case nir_op_fddy:
|
|
|
|
shader->info.uses_fddx_fddy = true;
|
|
|
|
break;
|
|
|
|
default:
|
2018-12-10 11:01:39 -08:00
|
|
|
shader->info.uses_64bit |= instr->dest.dest.ssa.bit_size == 64;
|
|
|
|
unsigned num_srcs = nir_op_infos[instr->op].num_inputs;
|
|
|
|
for (unsigned i = 0; i < num_srcs; i++) {
|
|
|
|
shader->info.uses_64bit |= nir_src_bit_size(instr->src[i].src) == 64;
|
|
|
|
}
|
2017-10-26 15:19:25 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-13 16:26:39 -07:00
|
|
|
static void
|
2018-03-17 21:09:14 -07:00
|
|
|
gather_info_block(nir_block *block, nir_shader *shader, void *dead_ctx)
|
2016-03-25 10:23:25 -07:00
|
|
|
{
|
2016-04-26 18:34:19 -07:00
|
|
|
nir_foreach_instr(instr, block) {
|
2016-03-25 10:23:25 -07:00
|
|
|
switch (instr->type) {
|
2017-10-26 15:19:25 -07:00
|
|
|
case nir_instr_type_alu:
|
|
|
|
gather_alu_info(nir_instr_as_alu(instr), shader);
|
|
|
|
break;
|
2016-03-25 10:23:25 -07:00
|
|
|
case nir_instr_type_intrinsic:
|
2018-03-17 21:09:14 -07:00
|
|
|
gather_intrinsic_info(nir_instr_as_intrinsic(instr), shader, dead_ctx);
|
2016-03-25 10:23:25 -07:00
|
|
|
break;
|
|
|
|
case nir_instr_type_tex:
|
|
|
|
gather_tex_info(nir_instr_as_tex(instr), shader);
|
|
|
|
break;
|
|
|
|
case nir_instr_type_call:
|
|
|
|
assert(!"nir_shader_gather_info only works if functions are inlined");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-30 16:04:34 -07:00
|
|
|
static unsigned
|
|
|
|
glsl_type_get_sampler_count(const struct glsl_type *type)
|
|
|
|
{
|
|
|
|
if (glsl_type_is_array(type)) {
|
|
|
|
return (glsl_get_aoa_size(type) *
|
|
|
|
glsl_type_get_sampler_count(glsl_without_array(type)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glsl_type_is_struct(type)) {
|
|
|
|
unsigned count = 0;
|
|
|
|
for (int i = 0; i < glsl_get_length(type); i++)
|
|
|
|
count += glsl_type_get_sampler_count(glsl_get_struct_field(type, i));
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glsl_type_is_sampler(type))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned
|
|
|
|
glsl_type_get_image_count(const struct glsl_type *type)
|
|
|
|
{
|
|
|
|
if (glsl_type_is_array(type)) {
|
|
|
|
return (glsl_get_aoa_size(type) *
|
|
|
|
glsl_type_get_image_count(glsl_without_array(type)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glsl_type_is_struct(type)) {
|
|
|
|
unsigned count = 0;
|
|
|
|
for (int i = 0; i < glsl_get_length(type); i++)
|
|
|
|
count += glsl_type_get_image_count(glsl_get_struct_field(type, i));
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glsl_type_is_image(type))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-25 10:23:25 -07:00
|
|
|
void
|
|
|
|
nir_shader_gather_info(nir_shader *shader, nir_function_impl *entrypoint)
|
|
|
|
{
|
2017-05-08 09:20:21 -07:00
|
|
|
shader->info.num_textures = 0;
|
|
|
|
shader->info.num_images = 0;
|
2016-03-25 10:23:25 -07:00
|
|
|
nir_foreach_variable(var, &shader->uniforms) {
|
2018-03-30 16:04:34 -07:00
|
|
|
shader->info.num_textures += glsl_type_get_sampler_count(var->type);
|
|
|
|
shader->info.num_images += glsl_type_get_image_count(var->type);
|
2016-03-25 10:23:25 -07:00
|
|
|
}
|
|
|
|
|
2017-05-08 09:20:21 -07:00
|
|
|
shader->info.inputs_read = 0;
|
|
|
|
shader->info.outputs_written = 0;
|
|
|
|
shader->info.outputs_read = 0;
|
2017-11-14 15:10:44 +10:00
|
|
|
shader->info.patch_outputs_read = 0;
|
2017-05-08 09:20:21 -07:00
|
|
|
shader->info.patch_inputs_read = 0;
|
|
|
|
shader->info.patch_outputs_written = 0;
|
|
|
|
shader->info.system_values_read = 0;
|
2017-12-16 14:06:23 +11:00
|
|
|
if (shader->info.stage == MESA_SHADER_VERTEX) {
|
|
|
|
shader->info.vs.double_inputs = 0;
|
|
|
|
}
|
2017-09-14 19:52:38 -07:00
|
|
|
if (shader->info.stage == MESA_SHADER_FRAGMENT) {
|
2017-05-08 09:20:21 -07:00
|
|
|
shader->info.fs.uses_sample_qualifier = false;
|
2016-10-27 12:21:52 +11:00
|
|
|
}
|
2018-03-17 21:09:14 -07:00
|
|
|
|
|
|
|
void *dead_ctx = ralloc_context(NULL);
|
2016-04-13 16:26:39 -07:00
|
|
|
nir_foreach_block(block, entrypoint) {
|
2018-03-17 21:09:14 -07:00
|
|
|
gather_info_block(block, shader, dead_ctx);
|
2016-04-13 16:26:39 -07:00
|
|
|
}
|
2018-03-17 21:09:14 -07:00
|
|
|
ralloc_free(dead_ctx);
|
2016-03-25 10:23:25 -07:00
|
|
|
}
|