nir: add vs_inputs_dual_locations compiler option
authorTimothy Arceri <tarceri@itsqueeze.com>
Sun, 7 Jan 2018 23:37:27 +0000 (10:37 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Mon, 29 Jan 2018 22:08:47 +0000 (09:08 +1100)
Allows nir drivers to either use a single or dual locations for
vs double inputs.

i965 uses dual locations for both OpenGL and Vulkan drivers, for
now gallium OpenGL drivers only use a single location.

The following patch will also make use of this option when
calling nir_shader_gather_info().

Reviewed-by: Karol Herbst <kherbst@redhat.com>
src/amd/vulkan/radv_shader.c
src/compiler/glsl/glsl_to_nir.cpp
src/compiler/nir/nir.h
src/intel/compiler/brw_compiler.c

index 620effe50e6b4e9bc918e2a3c7aeafb5802f7568..af094e6220fb1366fb9ccaac8862e9d6bc158f3d 100644 (file)
@@ -67,6 +67,7 @@ static const struct nir_shader_compiler_options nir_options = {
        .lower_extract_byte = true,
        .lower_extract_word = true,
        .lower_ffma = true,
+       .vs_inputs_dual_locations = true,
        .max_unroll_iterations = 32
 };
 
index 29e32cde53cb5d79356c1f2fcfbcfd64b586add3..1a579f41cd343e1bfd1b6a718e6d3eb31dd38311 100644 (file)
@@ -130,11 +130,15 @@ private:
 } /* end of anonymous namespace */
 
 static void
-nir_remap_attributes(nir_shader *shader)
+nir_remap_attributes(nir_shader *shader,
+                     const nir_shader_compiler_options *options)
 {
-   nir_foreach_variable(var, &shader->inputs) {
-      var->data.location += _mesa_bitcount_64(shader->info.vs.double_inputs &
-                                              BITFIELD64_MASK(var->data.location));
+   if (options->vs_inputs_dual_locations) {
+      nir_foreach_variable(var, &shader->inputs) {
+         var->data.location +=
+            _mesa_bitcount_64(shader->info.vs.double_inputs &
+                              BITFIELD64_MASK(var->data.location));
+      }
    }
 
    /* Once the remap is done, reset double_inputs_read, so later it will have
@@ -164,7 +168,7 @@ glsl_to_nir(const struct gl_shader_program *shader_prog,
     * location 0 and vec4 attr1 in location 1, in NIR attr0 will use
     * locations/slots 0 and 1, and attr1 will use location/slot 2 */
    if (shader->info.stage == MESA_SHADER_VERTEX)
-      nir_remap_attributes(shader);
+      nir_remap_attributes(shader, options);
 
    shader->info.name = ralloc_asprintf(shader, "GLSL%d", shader_prog->Name);
    if (shader_prog->Label)
index 41a07b0b48c16f06963f27b55a4b1cb9e929b14f..4bb96c3c9529a3cd1d2fedd887913232482229e0 100644 (file)
@@ -1892,6 +1892,12 @@ typedef struct nir_shader_compiler_options {
     */
    bool use_interpolated_input_intrinsics;
 
+   /**
+    * Do vertex shader double inputs use two locations? The Vulkan spec
+    * requires two locations to be used, OpenGL allows a single location.
+    */
+   bool vs_inputs_dual_locations;
+
    unsigned max_unroll_iterations;
 } nir_shader_compiler_options;
 
index e89aeacc7d2f3a829f3d105235b3135a91f2e8a5..e515559acb6a7b4e613604840be4be73da290610 100644 (file)
@@ -57,6 +57,7 @@ static const struct nir_shader_compiler_options scalar_nir_options = {
    .lower_unpack_snorm_4x8 = true,
    .lower_unpack_unorm_2x16 = true,
    .lower_unpack_unorm_4x8 = true,
+   .vs_inputs_dual_locations = true,
    .max_unroll_iterations = 32,
 };
 
@@ -78,6 +79,7 @@ static const struct nir_shader_compiler_options vector_nir_options = {
    .lower_unpack_unorm_2x16 = true,
    .lower_extract_byte = true,
    .lower_extract_word = true,
+   .vs_inputs_dual_locations = true,
    .max_unroll_iterations = 32,
 };
 
@@ -96,6 +98,7 @@ static const struct nir_shader_compiler_options vector_nir_options_gen6 = {
    .lower_unpack_unorm_2x16 = true,
    .lower_extract_byte = true,
    .lower_extract_word = true,
+   .vs_inputs_dual_locations = true,
    .max_unroll_iterations = 32,
 };