[Mesa-dev] [PATCH 31/45] compiler: Mark when input/ouput attribute at VS uses 16-bit
Alejandro PiƱeiro
apinheiro at igalia.com
Thu Jul 13 14:35:35 UTC 2017
From: Jose Maria Casanova Crespo <jmcasanova at igalia.com>
New shader attribute to mark when a location has 16-bit
value. This patch includes support on mesa glsl and nir.
---
src/compiler/glsl_types.h | 24 ++++++++++++++++++++++++
src/compiler/nir/nir_gather_info.c | 23 ++++++++++++++++-------
src/compiler/nir_types.cpp | 6 ++++++
src/compiler/nir_types.h | 1 +
src/compiler/shader_info.h | 2 ++
5 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index 8ebf2f4..89e12c4 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -91,6 +91,13 @@ static inline bool glsl_base_type_is_integer(enum glsl_base_type type)
type == GLSL_TYPE_IMAGE;
}
+static inline bool glsl_base_type_is_16bit(enum glsl_base_type type)
+{
+ return type == GLSL_TYPE_HALF_FLOAT ||
+ type == GLSL_TYPE_UINT16 ||
+ type == GLSL_TYPE_INT16;
+}
+
enum glsl_sampler_dim {
GLSL_SAMPLER_DIM_1D = 0,
GLSL_SAMPLER_DIM_2D,
@@ -551,6 +558,15 @@ struct glsl_type {
return is_64bit() && vector_elements > 2;
}
+
+ /**
+ * Query whether a 16-bit type takes half slots.
+ */
+ bool is_half_slot() const
+ {
+ return is_16bit();
+ }
+
/**
* Query whether or not a type is 64-bit
*/
@@ -560,6 +576,14 @@ struct glsl_type {
}
/**
+ * Query whether or not a type is 16-bit
+ */
+ bool is_16bit() const
+ {
+ return glsl_base_type_is_16bit(base_type);
+ }
+
+ /**
* Query whether or not a type is a non-array boolean type
*/
bool is_boolean() const
diff --git a/src/compiler/nir/nir_gather_info.c b/src/compiler/nir/nir_gather_info.c
index 24ac74e..3ec0126 100644
--- a/src/compiler/nir/nir_gather_info.c
+++ b/src/compiler/nir/nir_gather_info.c
@@ -212,14 +212,22 @@ gather_intrinsic_info(nir_intrinsic_instr *instr, nir_shader *shader)
if (!try_mask_partial_io(shader, instr->variables[0]))
mark_whole_variable(shader, var);
- /* We need to track which input_reads bits correspond to a
- * dvec3/dvec4 input attribute */
+ /* We need to track which input_reads bits correspond to
+ * dvec3/dvec4 or 16-bit input attributes */
if (shader->stage == MESA_SHADER_VERTEX &&
- var->data.mode == nir_var_shader_in &&
- glsl_type_is_dual_slot(glsl_without_array(var->type))) {
- for (uint i = 0; i < glsl_count_attribute_slots(var->type, false); i++) {
- int idx = var->data.location + i;
- shader->info.double_inputs_read |= BITFIELD64_BIT(idx);
+ var->data.mode == nir_var_shader_in) {
+ if (glsl_type_is_dual_slot(glsl_without_array(var->type))) {
+ for (uint i = 0; i < glsl_count_attribute_slots(var->type, false); i++) {
+ int idx = var->data.location + i;
+ shader->info.double_inputs_read |= BITFIELD64_BIT(idx);
+ }
+ } else {
+ if (glsl_type_is_half_slot(glsl_without_array(var->type))) {
+ for (uint i = 0; i < glsl_count_attribute_slots(var->type, false); i++) {
+ int idx = var->data.location + i;
+ shader->info.half_inputs_read |= BITFIELD64_BIT(idx);
+ }
+ }
}
}
}
@@ -311,6 +319,7 @@ nir_shader_gather_info(nir_shader *shader, nir_function_impl *entrypoint)
shader->info.outputs_written = 0;
shader->info.outputs_read = 0;
shader->info.double_inputs_read = 0;
+ shader->info.half_inputs_read = 0;
shader->info.patch_inputs_read = 0;
shader->info.patch_outputs_written = 0;
shader->info.system_values_read = 0;
diff --git a/src/compiler/nir_types.cpp b/src/compiler/nir_types.cpp
index 11524c2..b8b523e 100644
--- a/src/compiler/nir_types.cpp
+++ b/src/compiler/nir_types.cpp
@@ -229,6 +229,12 @@ glsl_type_is_dual_slot(const struct glsl_type *type)
}
bool
+glsl_type_is_half_slot(const struct glsl_type *type)
+{
+ return type->is_half_slot();
+}
+
+bool
glsl_type_is_numeric(const struct glsl_type *type)
{
return type->is_numeric();
diff --git a/src/compiler/nir_types.h b/src/compiler/nir_types.h
index 220b35c..0d578de 100644
--- a/src/compiler/nir_types.h
+++ b/src/compiler/nir_types.h
@@ -121,6 +121,7 @@ bool glsl_type_is_struct(const struct glsl_type *type);
bool glsl_type_is_sampler(const struct glsl_type *type);
bool glsl_type_is_image(const struct glsl_type *type);
bool glsl_type_is_dual_slot(const struct glsl_type *type);
+bool glsl_type_is_half_slot(const struct glsl_type *type);
bool glsl_type_is_numeric(const struct glsl_type *type);
bool glsl_type_is_boolean(const struct glsl_type *type);
bool glsl_sampler_type_is_shadow(const struct glsl_type *type);
diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h
index a670841..dc4ab39 100644
--- a/src/compiler/shader_info.h
+++ b/src/compiler/shader_info.h
@@ -55,6 +55,8 @@ typedef struct shader_info {
uint64_t inputs_read;
/* Which inputs are actually read and are double */
uint64_t double_inputs_read;
+ /* Which inputs are actually read and are half */
+ uint64_t half_inputs_read;
/* Which outputs are actually written */
uint64_t outputs_written;
/* Which outputs are actually read */
--
2.9.3
More information about the mesa-dev
mailing list